1 Reply Latest reply on Oct 30, 2018 3:08 PM by Rustam Usmanov

    Registering custom property and using the same

    Vijay Marappan Newbie

      In my project, it is internal document repo.

      root--|

               |--division--|

                                 |--- file 1.0. 1.1(versions)

      I want to add custom properties to the folder node and file node.

      I tried to register custom properties and not successful.

       

      public void registerCustomProperties() throws RepositoryException {

      Session session = null;

      try {

      logger.info("Registeration started...............................");

      session = repository.login(credentials);

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

      NamespaceRegistry nsRegistry = session.getWorkspace().getNamespaceRegistry();

      nsRegistry.registerNamespace("cv", "www.cv.in");

      NodeTypeTemplate nodeTypeTemplate = manager.createNodeTypeTemplate();

      nodeTypeTemplate.setName("cv:NodeType");

      PropertyDefinitionTemplate ownedByProperty = manager.createPropertyDefinitionTemplate();

      ownedByProperty.setName("cv:ownedby");

      ownedByProperty.setRequiredType(PropertyType.STRING);

      PropertyDefinitionTemplate modifiedByProperty = manager.createPropertyDefinitionTemplate();

      modifiedByProperty.setName("cv:modifiedby");

      modifiedByProperty.setRequiredType(PropertyType.STRING);

      PropertyDefinitionTemplate tagsProperty = manager.createPropertyDefinitionTemplate();

      tagsProperty.setName("cv:tags");

      tagsProperty.setRequiredType(PropertyType.STRING);

      PropertyDefinitionTemplate commentProperty = manager.createPropertyDefinitionTemplate();

      commentProperty.setName("cv:comments");

      commentProperty.setRequiredType(PropertyType.STRING);

      PropertyDefinitionTemplate restoreProperty = manager.createPropertyDefinitionTemplate();

      restoreProperty.setName("cv:restorepath");

      restoreProperty.setRequiredType(PropertyType.STRING);

       

       

      // Add property to node type

      nodeTypeTemplate.getPropertyDefinitionTemplates().add(ownedByProperty);

      nodeTypeTemplate.getPropertyDefinitionTemplates().add(modifiedByProperty);

      nodeTypeTemplate.getPropertyDefinitionTemplates().add(tagsProperty);

      nodeTypeTemplate.getPropertyDefinitionTemplates().add(commentProperty);

      nodeTypeTemplate.getPropertyDefinitionTemplates().add(restoreProperty);

       

       

      /* Register node type */

      manager.registerNodeType(nodeTypeTemplate, true);

      session.save();

      } finally {

      if (session != null) {

      session.logout();

      }

      }

      }

       

      node = parentNode.addNode(fileName, "nt:file");

      node.setProperty("cv:ownedby","abc"); -->I am getting error.

      node.addMixin("mix:versionable");

      Node contentNode = node.addNode("jcr:content", "nt:resource");

       

      Please help me to resolve the same.

      Thanks