Uploaded image for project: 'ModeShape'
  1. ModeShape
  2. MODE-1954

Removing property definition from registered node type using templates results in exception

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 3.3.0.Final
    • 3.2.0.Final
    • JCR
    • None
    • Hide

      Define a node type and register it, then modify it by adding a property definition:

      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);
      

      Then later create a template of the registered node type, iterate over the existing property definitions, and remove one of them:

      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);
      

      Registering the modified template (last line in the previous code fragment) results in an exception:

      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)
      
      Show
      Define a node type and register it, then modify it by adding a property definition: 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 ); Then later create a template of the registered node type, iterate over the existing property definitions, and remove one of them: 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 ); Registering the modified template (last line in the previous code fragment) results in an exception: 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)

      Removing a previously-defined property definition from a registered node type using the node type templates mechanism results in an exception:

      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)
      

              rhauch Randall Hauch (Inactive)
              rhauch Randall Hauch (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: