Hi Jorge

I am glad, that you were able to clean it up without using special workarounds.
That's good to know.

Kind regards
Angela
________________________________
From: jorgeeflorez . <[email protected]>
Sent: Tuesday, June 23, 2020 5:07 PM
To: [email protected] <[email protected]>
Subject: Re: Multiple property definition for same property

Hi Angela,

I am not too familiar with the node type registration but I would assume
> that the nodes storing node type definitions are protected and you won't be
> able to remove them using JCR API calls. So, you probably need to resort to
> some low level operations like e.g. the tools in oak-run.
>

well, I used the following code (I simplified it a little bit) and it seems
I could delete all the duplicates.
        NodeTypeManager nodeTypeManager =
session.getWorkspace().getNodeTypeManager();
        String duplicateDefinitionName = "testProperty";
        NodeType repositoryType = nodeTypeManager.getNodeType("oak8961");
        NodeTypeTemplate repositoryTypeTemplate =
nodeTypeManager.createNodeTypeTemplate(repositoryType);
        boolean definitionFound = false;
        List<Object> duplicates = new ArrayList<>();
        for(Object obj :
repositoryTypeTemplate.getPropertyDefinitionTemplates()){
            PropertyDefinitionTemplate definitionTemplate =
(PropertyDefinitionTemplate) obj;


if(definitionTemplate.getName().equals(duplicateDefinitionName)){
                if(!definitionFound){
                    definitionFound = true;
                }
                else{
                    duplicates.add(obj);
                }
            }
        }

        for(Object obj : duplicates){

repositoryTypeTemplate.getPropertyDefinitionTemplates().remove(obj);
        }

        nodeTypeManager.registerNodeType(repositoryTypeTemplate, true);
        session.save();

Is there any chance you could provide a patch to fix the bug you reported?
> That might help getting it addressed.
>

I will try to look at the source code, in case I find a solution I will let
you know.

Regards.

Jorge

El mar., 23 jun. 2020 a las 1:43, Angela Schreiber
(<[email protected]>) escribió:

> Hi Jorge
>
> I am not too familiar with the node type registration but I would assume
> that the nodes storing node type definitions are protected and you won't be
> able to remove them using JCR API calls. So, you probably need to resort to
> some low level operations like e.g. the tools in oak-run.
>
> Is there any chance you could provide a patch to fix the bug you reported?
> That might help getting it addressed.
>
> wdyt?
>
> Kind regards
> Angela
> ________________________________
> From: jorgeeflorez . <[email protected]>
> Sent: Friday, June 19, 2020 2:30 AM
> To: [email protected] <[email protected]>
> Subject: Re: Multiple property definition for same property
>
> Hi all,
> I just created a maven project, used Oak version 1.30.0 and tested the
> problem I reported on OAK-8961
> <https://issues.apache.org/jira/browse/OAK-8961>. It still happens. I will
> see if I am able to delete the duplicate jcr:propertyDefinition nodes, any
> ideas are welcome :)
>
> Regards.
>
> Jorge
>
> El mié., 18 mar. 2020 a las 11:19, jorgeeflorez . (<
> [email protected]>) escribió:
>
> > Hi Angela,
> > thank you for your help. I created
> > https://issues.apache.org/jira/browse/OAK-8961.
> >
> > Regards.
> >
> > Jorge
> >
> > El mié., 18 mar. 2020 a las 10:09, Angela Schreiber
> > (<[email protected]>) escribió:
> >
> >> Hi Jorge
> >>
> >> That sounds like a bug to me... after all you will not be able to set
> >> multiple properties that have exactly the same PropertyDefinition and as
> >> far as I remember it should not even be possible to create multiple
> >> properties with the same name.
> >>
> >> Can you create a bug for this in JIRA? As usual detailed steps to
> >> reproduce, test cases or even a patch are very much welcome.
> >>
> >> Kind regards
> >> Angela
> >> ________________________________
> >> From: jorgeeflorez . <[email protected]>
> >> Sent: Wednesday, March 18, 2020 3:57 PM
> >> To: [email protected] <[email protected]>
> >> Subject: Multiple property definition for same property
> >>
> >> Hi all,
> >> using the following code, I am able to update an existing node type by
> >> inserting a new property:
> >>
> >> NodeTypeManager nodeTypeManager =
> >> session.getWorkspace().getNodeTypeManager();
> >>
> >> NodeType repositoryType = nodeTypeManager.getNodeType("testType");
> >> NodeTypeTemplate repositoryTypeTemplate =
> >> nodeTypeManager.createNodeTypeTemplate(repositoryType);
> >> PropertyDefinitionTemplate testProperty =
> >> nodeTypeManager.createPropertyDefinitionTemplate();
> >> testProperty.setName("testProperty");
> >> testProperty.setRequiredType(PropertyType.STRING);
> >> testProperty.setMandatory(false);
> >> testProperty.setMultiple(false);
> >> testProperty.setDefaultValues(new Value[0]);
> >> testProperty.setValueConstraints(new String[0]);
> >>
> repositoryTypeTemplate.getPropertyDefinitionTemplates().add(testProperty);
> >>
> >> nodeTypeManager.registerNodeType(repositoryTypeTemplate, true);
> >> session.save();
> >>
> >> I prefer this way, instead using CND
> >> <https://jackrabbit.apache.org/jcr/node-type-notation.html> because I
> >> understand it better and is cleaner, compared to having everything
> inside
> >> a
> >> String (am I doing it correctly?).
> >>
> >> Because of a bug I was tracking, I found out that, if you invoke this
> code
> >> several times, it will insert a new property definition each time, so in
> >> the repository you could end up with this (I removed a lot of stuff to
> >> keep
> >> it small):
> >> {
> >>     "node": "testType",
> >>     "path": "/jcr:system/jcr:nodeTypes/testType",
> >>     "children": [
> >>         {
> >>             "node": "jcr:propertyDefinition",
> >>             "path":
> >> "/jcr:system/jcr:nodeTypes/testType/jcr:propertyDefinition",
> >>             "properties": [
> >>                 *"jcr:name = testProperty"*
> >>             ]
> >>         },
> >>         {
> >>             "node": "jcr:propertyDefinition[10]",
> >>             "path":
> >> "/jcr:system/jcr:nodeTypes/testType/jcr:propertyDefinition[10]",
> >>             "mixins": [],
> >>             "children": [],
> >>             "properties": [
> >>                 *"jcr:name = testProperty"*
> >>             ]
> >>         },
> >>         {
> >>             "node": "jcr:propertyDefinition[2]",
> >>             "path":
> >> "/jcr:system/jcr:nodeTypes/testType/jcr:propertyDefinition[2]",
> >>             "mixins": [],
> >>             "children": [],
> >>             "properties": [
> >>                 *"jcr:name = testProperty"*
> >>             ]
> >>         },
> >>         {
> >>             "node": "jcr:propertyDefinition[3]",
> >>             "path":
> >> "/jcr:system/jcr:nodeTypes/testType/jcr:propertyDefinition[3]",
> >>             "mixins": [],
> >>             "children": [],
> >>             "properties": [
> >>                 *"jcr:name = testProperty"*
> >>             ]
> >>         },
> >>         {
> >>             "node": "jcr:propertyDefinition[4]",
> >>             "path":
> >> "/jcr:system/jcr:nodeTypes/testType/jcr:propertyDefinition[4]",
> >>             "mixins": [],
> >>             "children": [],
> >>             "properties": [
> >>                 *"jcr:name = testProperty"*
> >>             ]
> >>         },
> >>         {
> >>             "node": "jcr:propertyDefinition[5]",
> >>             "path":
> >> "/jcr:system/jcr:nodeTypes/testType/jcr:propertyDefinition[5]",
> >>             "mixins": [],
> >>             "children": [],
> >>             "properties": [
> >>                 *"jcr:name = testProperty"*
> >>             ]
> >>         },
> >>         {
> >>             "node": "jcr:propertyDefinition[6]",
> >>             "path":
> >> "/jcr:system/jcr:nodeTypes/testType/jcr:propertyDefinition[6]",
> >>             "mixins": [],
> >>             "children": [],
> >>             "properties": [
> >>                 *"jcr:name = testProperty"*
> >>             ]
> >>         },
> >>         {
> >>             "node": "jcr:propertyDefinition[7]",
> >>             "path":
> >> "/jcr:system/jcr:nodeTypes/testType/jcr:propertyDefinition[7]",
> >>             "mixins": [],
> >>             "children": [],
> >>             "properties": [
> >>                 *"jcr:name = testProperty"*
> >>             ]
> >>         },
> >>         {
> >>             "node": "jcr:propertyDefinition[8]",
> >>             "path":
> >> "/jcr:system/jcr:nodeTypes/testType/jcr:propertyDefinition[8]",
> >>             "mixins": [],
> >>             "children": [],
> >>             "properties": [
> >>                 *"jcr:name = testProperty"*
> >>             ]
> >>         },
> >>         {
> >>             "node": "jcr:propertyDefinition[9]",
> >>             "path":
> >> "/jcr:system/jcr:nodeTypes/testType/jcr:propertyDefinition[9]",
> >>             "mixins": [],
> >>             "children": [],
> >>             "properties": [
> >>                 *"jcr:name = testProperty"*
> >>             ]
> >>         },
> >>         {
> >>             "node": "rep:namedPropertyDefinitions",
> >>             "path":
> >> "/jcr:system/jcr:nodeTypes/testType/rep:namedPropertyDefinitions",
> >>             "children": [
> >>                 {
> >>                     "node": "jcr:created",
> >>                     "path":
> >>
> >>
> "/jcr:system/jcr:nodeTypes/testType/rep:namedPropertyDefinitions/jcr:created",
> >>                 },
> >>                 {
> >>                     "node": "jcr:createdBy",
> >>                     "path":
> >>
> >>
> "/jcr:system/jcr:nodeTypes/testType/rep:namedPropertyDefinitions/jcr:createdBy",
> >>                 },
> >>                 {
> >>                     "node": "rep:mixinTypes",
> >>                     "path":
> >>
> >>
> "/jcr:system/jcr:nodeTypes/testType/rep:namedPropertyDefinitions/rep:mixinTypes",
> >>                 },
> >>                 {
> >>                     "node": "rep:primaryType",
> >>                     "path":
> >>
> >>
> "/jcr:system/jcr:nodeTypes/testType/rep:namedPropertyDefinitions/rep:primaryType",
> >>                 },
> >>                 {
> >>                     "node": "testProperty",
> >>                     "path":
> >>
> >>
> "/jcr:system/jcr:nodeTypes/testType/rep:namedPropertyDefinitions/testProperty",
> >>                         "properties": [
> >>                             *"jcr:name = testProperty"*
> >>                         ]
> >>                     }],
> >>                     "properties": ["jcr:primaryType =
> >> rep:PropertyDefinitions"]
> >>                 }
> >>             ],
> >>             "properties": ["jcr:primaryType =
> >> rep:NamedPropertyDefinitions"]
> >>         },
> >>         {
> >>             "node": "rep:residualChildNodeDefinitions",
> >>             "path":
> >> "/jcr:system/jcr:nodeTypes/testType/rep:residualChildNodeDefinitions",
> >>             "children": [{
> >>                 "node": "nt:hierarchyNode",
> >>                 "path":
> >>
> >>
> "/jcr:system/jcr:nodeTypes/testType/rep:residualChildNodeDefinitions/nt:hierarchyNode",
> >>             }],
> >>             "properties": ["jcr:primaryType = rep:ChildNodeDefinitions"]
> >>         }
> >>     ],
> >>     "properties": [
> >>         "jcr:nodeTypeName = testType",
> >>         "rep:hasProtectedResidualChildNodes = false",
> >>         "jcr:isAbstract = false",
> >>         "jcr:hasOrderableChildNodes = false",
> >>         "rep:supertypes =
> nt:folder,nt:hierarchyNode,nt:base,mix:created",
> >>         "jcr:isMixin = false",
> >>         "rep:hasProtectedResidualProperties = false",
> >>         "rep:primarySubtypes = ",
> >>         "jcr:isQueryable = true",
> >>         "rep:mandatoryProperties = jcr:primaryType",
> >>         "rep:protectedChildNodes = ",
> >>         "jcr:supertypes = nt:folder",
> >>         "rep:mandatoryChildNodes = ",
> >>         "rep:protectedProperties =
> >> jcr:primaryType,jcr:mixinTypes,jcr:created,jcr:createdBy",
> >>         "jcr:primaryType = rep:NodeType",
> >>         "rep:namedSingleValuedProperties =
> >> testProperty,jcr:primaryType,jcr:created,jcr:createdBy"
> >>     ]
> >> }
> >>
> >> I am not sure if I am doing something wrong, or whether there should be
> a
> >> validation when inserting property definitions having a name that
> already
> >> exists...
> >>
> >> Any comment is appreciated as always :)
> >>
> >> Jorge
> >>
> >
>

Reply via email to