2 Replies Latest reply on Mar 8, 2019 10:38 AM by sapozhko

    Issue on (programmatically) removing a property definition using ModeShape 3.7.1.FINAL

    nimit.agrawal

      Hi,

       

      I am stuck on removing a property definition which is already added in the template.

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

       

      NodeTypeManager ntmgr = session.getWorkspace().getNodeTypeManager();
      NodeType nodeType = ntmgr.getNodeType("nv:lccommon"); 
      NodeTypeTemplate nodeTypeTemplate = ntmgr.createNodeTypeTemplate(nodeType); 
      PropertyDefinitionTemplate tp = ntmgr.createPropertyDefinitionTemplate(); 
      tp.setName("PROPERTY_NAME"); // set other type and other properties ... 
      nodeTypeTemplate.getPropertyDefinitionTemplates().add(tp); 
      ntmgr.registerNodeType(nodeTypeTemplate, true); 
      //session.save()//tried this as well
      

       

       

      Afterwards I try to remove it via

      NodeTypeManager ntmgr = session.getWorkspace().getNodeTypeManager(); 
      NodeType nodeType = ntmgr.getNodeType("nv:lccommon"); 
      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("PROPERTY_NAME")) {     
           pit.remove();   
      } } 
      ntmgr.registerNodeType(nodeTypeTemplate, true); 
      

       

      This removal method goes successfully.

      However after this when i try to fetch any node of type "nv:lccommon"

      Node node = session.getRootNode().getNode("lccommon\defaultSetting");
      PropertyIterator properties = node.getProperties();
      

       

      Then I get below exception :

       

      Caused by: java.lang.IllegalStateException: javax.jcr.RepositoryException: No valid property definition on node '/lccommon/nv_default' with primary type 'nv:lccommon' and mixin types [] for the property: PLAY_FOR_FUN_INIT_BALANCE="5000"

        at com.nv.multiplayer.configuration.service.node.ConfigRepositoryManager.getConfigNode(ConfigRepositoryManager.java:75) [configuration-service-1.12.0-SNAPSHOT.jar:1.12.0-SNAPSHOT]

        at sun.reflect.GeneratedMethodAccessor413.invoke(Unknown Source) [:1.7.0_45]

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_45]

        at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_45]

        at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52) [jboss-as-ee-7.4.0.Final-redhat-19.jar:7.4.0.Final-redhat-19]

        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.2.Final-redhat-1.jar:1.1.2.Final-redhat-1]

        at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.2.Final-redhat-1.jar:1.1.2.Final-redhat-1]

        at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63) [jboss-as-ee-7.4.0.Final-redhat-19.jar:7.4.0.Final-redhat-19]

        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.2.Final-redhat-1.jar:1.1.2.Final-redhat-1]

        at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:374) [jboss-invocation-1.1.2.Final-redhat-1.jar:1.1.2.Final-redhat-1]

        at org.jboss.as.weld.ejb.DelegatingInterceptorInvocationContext.proceed(DelegatingInterceptorInvocationContext.java:81) [jboss-as-weld-7.4.0.Final-redhat-19.jar:7.4.0.Final-redhat-19]

        at com.nv.multiplayer.common.jmx.statistics.CallStatisticsInterceptor.callStats(CallStatisticsInterceptor.java:30) [common-management-1.12.0-SNAPSHOT.jar:1.12.0-SNAPSHOT]

        ... 156 more

      Caused by: javax.jcr.RepositoryException: No valid property definition on node '/lccommon/nv_default' with primary type 'nv:lccommon' and mixin types [] for the property: PLAY_FOR_FUN_INIT_BALANCE="5000"

        at org.modeshape.jcr.AbstractJcrNode.findJcrProperties(AbstractJcrNode.java:2106) [modeshape-jcr-3.7.1.Final.jar:3.7.1.Final]

        at org.modeshape.jcr.AbstractJcrNode.getProperties(AbstractJcrNode.java:2114) [modeshape-jcr-3.7.1.Final.jar:3.7.1.Final]

        at com.nv.multiplayer.configuration.service.node.ConfigRepositoryManager.createConfigObject(ConfigRepositoryManager.java:83) [configuration-service-1.12.0-SNAPSHOT.jar:1.12.0-SNAPSHOT]

        at com.nv.multiplayer.configuration.service.node.ConfigRepositoryManager.getConfigNode(ConfigRepositoryManager.java:68) [configuration-service-1.12.0-SNAPSHOT.jar:1.12.0-SNAPSHOT]

        ... 167 more

      Caused by: javax.jcr.nodetype.ConstraintViolationException: No valid property definition on node '/lccommon/nv_default' with primary type 'nv:lccommon' and mixin types [] for the property: PLAY_FOR_FUN_INIT_BALANCE="5000"

        at org.modeshape.jcr.AbstractJcrNode.propertyDefinitionFor(AbstractJcrNode.java:478) [modeshape-jcr-3.7.1.Final.jar:3.7.1.Final]

        at org.modeshape.jcr.AbstractJcrNode.createJcrProperty(AbstractJcrNode.java:394) [modeshape-jcr-3.7.1.Final.jar:3.7.1.Final]

        at org.modeshape.jcr.AbstractJcrNode.getProperty(AbstractJcrNode.java:358) [modeshape-jcr-3.7.1.Final.jar:3.7.1.Final]

        at org.modeshape.jcr.AbstractJcrNode.findJcrProperties(AbstractJcrNode.java:2099) [modeshape-jcr-3.7.1.Final.jar:3.7.1.Final]

        ... 170 more

       

      After googling found some issues but not really sure if they are related or not :

      Can't get the Indexmanager to work

       

      Please tell me what am I doing wrong.

      Thanks in advance