2 Replies Latest reply on Jun 6, 2013 2:35 AM by nl

    Issue on (programmatically) removing a property definition using ModeShape 3.2

    nl

      Hi,

       

      I am stuck on removing a property definition which was just added to a mixin before.

      I have a mixing called "dmsmix:filecontent" and create a "dmsmix:owner" property using:

       

      {code}

      NodeTypeManager ntmgr = session.getWorkspace().getNodeTypeManager();

      NodeType nodeType = ntmgr.getNodeType("dmsmix:filecontent");

      NodeTypeTemplate nodeTypeTemplate = ntmgr.createNodeTypeTemplate(nodeType);

      PropertyDefinitionTemplate tp = ntmgr.createPropertyDefinitionTemplate();

      tp.setName("dmsmix:owner");

      // set other type and other properties

      ...

      nodeTypeTemplate.getPropertyDefinitionTemplates().add(tp);

      ntmgr.registerNodeType(nodeTypeTemplate, true);

      {code}

       

      Afterwards I try to remove it via

       

      {code}

      NodeTypeManager ntmgr = session.getWorkspace().getNodeTypeManager();

      NodeType nodeType = ntmgr.getNodeType("dmsmix:filecontent");

      NodeTypeTemplate nodeTypeTemplate = ntmgr.createNodeTypeTemplate(nodeType);

      List<PropertyDefinitionTemplate> pts = nodeTypeTemplate.getPropertyDefinitionTemplates();

      Iterator<PropertyDefinitionTemplate> pit = pts.iterator();

      while (pit.hasNext()) {

        PropertyDefinitionTemplate pi = pit.next();

        if (pi.getName().equals("dmsmix:owner")) {

          pit.remove();

        }

      }

      ntmgr.registerNodeType(nodeTypeTemplate, true);

      {code}

       

      and the following exception is thrown

       

      {code}

      org.modeshape.jcr.cache.NodeNotFoundInParentException: Cannot locate child node: 7d98ad9317f1e7/jcr:system/jcr:nodeTypes/{http???www.mycompany.com?dms?mix?1.0}filecontent/{http???www.mycompany.com?dms?mix?1.0}removeMe/String/1 within parent: 7d98ad9317f1e7/jcr:system/jcr:nodeTypes/{http???www.mycompany.com?dms?mix?1.0}filecontent

          at org.modeshape.jcr.cache.document.SessionNode.getSegment(SessionNode.java:417)

          at org.modeshape.jcr.cache.document.SessionNode.getPath(SessionNode.java:449)

          at org.modeshape.jcr.cache.PathCache.getPath(PathCache.java:49)

          at org.modeshape.jcr.cache.document.WritableSessionCache.persistChanges(WritableSessionCache.java:852)

          at org.modeshape.jcr.cache.document.WritableSessionCache.save(WritableSessionCache.java:382)

          at org.modeshape.jcr.cache.document.WritableSessionCache.save(WritableSessionCache.java:347)

          at org.modeshape.jcr.SystemContent.save(SystemContent.java:112)

          at org.modeshape.jcr.RepositoryNodeTypeManager.registerNodeTypes(RepositoryNodeTypeManager.java:523)

          at org.modeshape.jcr.RepositoryNodeTypeManager.registerNodeType(RepositoryNodeTypeManager.java:377)

          at org.modeshape.jcr.JcrNodeTypeManager.registerNodeType(JcrNodeTypeManager.java:489)

          ...

      {code}

       

      I have no clue what causes this exception. Can anyone "enlight" me?

       

      Thanks, Niels

        • 1. Re: Issue on (programmatically) removing a property definition using ModeShape 3.2
          rhauch

          I was able to replicate your exception and identify the problem. I've logged it as MODE-1954, and I've already got a fix waiting for review. Thanks for reporting this! It will be fixed in the 3.3 release, due out later this week.

           

          BTW, the exception was indeed very arcane. I'm not sure that a better message (like "Unable to register the node type") would be of any help. In short, that error should never have been exposed since your code did nothing wrong. Apologies.

           

          If you're interested in what the exception actually meant: the code that is persisting the new node type (in the "/jcr:system/jcr:nodeTypes" area of the repository, which is where we persist all node type definitions) was essentially orphaning the node that represented the removed property definition and was not removing the node. Because of this, the internal "save()" logic attempted to modify the node but couldn't find the parent to which the node belonged, and hence the (very cryptic) exception.

          1 of 1 people found this helpful
          • 2. Re: Issue on (programmatically) removing a property definition using ModeShape 3.2
            nl

            Thanks Randall.