/** {@inheritDoc} */ public RemotePropertyDefinition[] getDeclaredPropertyDefs() throws RemoteException { PropertyDefinition[] defs = type.getDeclaredPropertyDefinitions(); return getRemotePropertyDefArray(defs); }
Collection<PropertyDefinition> internalGetPropertyDefinitions() { // TODO distinguish between additive and overriding property definitions. See 3.7.6.8 Item Definitions in Subtypes Collection<PropertyDefinition> definitions = new ArrayList<PropertyDefinition>(); definitions.addAll(Arrays.asList(getDeclaredPropertyDefinitions())); for (NodeType type : getSupertypes()) { definitions.addAll(Arrays.asList(type.getDeclaredPropertyDefinitions())); } return definitions; }
Collection<PropertyDefinition> internalGetPropertyDefinitions() { // TODO distinguish between additive and overriding property definitions. See 3.7.6.8 Item Definitions in Subtypes Collection<PropertyDefinition> definitions = new ArrayList<PropertyDefinition>(); definitions.addAll(Arrays.asList(getDeclaredPropertyDefinitions())); for (NodeType type : getSupertypes()) { definitions.addAll(Arrays.asList(type.getDeclaredPropertyDefinitions())); } return definitions; }
Collection<PropertyDefinition> internalGetPropertyDefinitions() { // TODO distinguish between additive and overriding property definitions. See 3.7.6.8 Item Definitions in Subtypes Collection<PropertyDefinition> definitions = new ArrayList<PropertyDefinition>(); definitions.addAll(Arrays.asList(getDeclaredPropertyDefinitions())); for (NodeType type : getSupertypes()) { definitions.addAll(Arrays.asList(type.getDeclaredPropertyDefinitions())); } return definitions; }
writer.print(getChildNodeDefSpec(nodes[i])); PropertyDefinition[] properties = type.getDeclaredPropertyDefinitions(); Arrays.sort(properties, PROPERTY_DEF_COMPARATOR); for (int i = 0; i < properties.length; i++) {
PropertyDefinition[] pd = superuser.getWorkspace().getNodeTypeManager().getNodeType(ntBase).getDeclaredPropertyDefinitions();
while (it.hasNext()) { NodeType nt = it.nextNodeType(); PropertyDefinition[] defs = nt.getDeclaredPropertyDefinitions(); for (PropertyDefinition def : defs) { String pn = def.getName();
while (it.hasNext()) { NodeType nt = it.nextNodeType(); PropertyDefinition[] defs = nt.getDeclaredPropertyDefinitions(); for (PropertyDefinition def : defs) { String pn = def.getName();
/** * Create a new {@link NodeTypeTemplate} copy of the 'nodeType', but without <br> * metaData defined as 'childNodeDefinition'. */ private NodeTypeTemplate createNodeTypeWithoutMetaData(NodeTypeManager nodeTypeManager, NodeType nodeType, NodeDefinition metaDataNode) throws RepositoryException { NodeTypeTemplate ntt = nodeTypeManager.createNodeTypeTemplate(); ntt.setDeclaredSuperTypeNames(nodeType.getDeclaredSupertypeNames()); ntt.setMixin(nodeType.isMixin()); ntt.setName(nodeType.getName()); ntt.setOrderableChildNodes(nodeType.hasOrderableChildNodes()); ntt.setPrimaryItemName(nodeType.getPrimaryItemName()); ntt.setQueryable(nodeType.isQueryable()); ntt.getPropertyDefinitionTemplates().addAll(Arrays.asList(nodeType.getDeclaredPropertyDefinitions())); List<NodeDefinition> childNodeDefinition = new ArrayList<NodeDefinition>(); childNodeDefinition.addAll(Arrays.asList(nodeType.getDeclaredChildNodeDefinitions())); childNodeDefinition.remove(metaDataNode); ntt.getNodeDefinitionTemplates().addAll(childNodeDefinition); return ntt; } }
final Node prototypeNode = getPrototypeNode(type.getName(), node.getSession()); for (PropertyDefinition propertyDefinition : type.getDeclaredPropertyDefinitions()) { if (propertyDefinition.isMandatory() && !propertyDefinition.isProtected() && !"*".equals(propertyDefinition.getName())){ log.debug("Add the mandatory property '{}' of '{}' to the node '{}'",
/** * Creates a new rest node type. * * @param nodeType the {@code non-null} JCR {@link NodeType}. * @param baseUrl the {@code non-null} root url, which is used to construct urls to the children and properties of the node type */ public RestNodeType( NodeType nodeType, String baseUrl ) { this.name = nodeType.getName(); this.isMixin = nodeType.isMixin(); this.isAbstract = nodeType.isAbstract(); this.isQueryable = nodeType.isQueryable(); this.hasOrderableChildNodes = nodeType.hasOrderableChildNodes(); this.superTypesLinks = new TreeSet<String>(); for (NodeType superType : nodeType.getDeclaredSupertypes()) { String superTypeLink = RestHelper.urlFrom(baseUrl, RestHelper.NODE_TYPES_METHOD_NAME, RestHelper.URL_ENCODER.encode(superType.getName())); this.superTypesLinks.add(superTypeLink); } this.subTypesLinks = new TreeSet<String>(); for (NodeTypeIterator subTypeIterator = nodeType.getDeclaredSubtypes(); subTypeIterator.hasNext(); ) { String subTypeLink = RestHelper.urlFrom(baseUrl, RestHelper.NODE_TYPES_METHOD_NAME, RestHelper.URL_ENCODER.encode(subTypeIterator.nextNodeType().getName())); this.subTypesLinks.add(subTypeLink); } this.propertyTypes = new ArrayList<RestPropertyType>(); for (PropertyDefinition propertyDefinition : nodeType.getDeclaredPropertyDefinitions()) { this.propertyTypes.add(new RestPropertyType(propertyDefinition)); } }
public void testIndexedPropertyDefinition() throws Exception { String ntPath = NodeTypeConstants.NODE_TYPES_PATH + '/' + NodeTypeConstants.NT_VERSION; assertTrue(superuser.nodeExists(ntPath + "/jcr:propertyDefinition")); assertTrue(superuser.nodeExists(ntPath + "/jcr:propertyDefinition[1]")); Node pdNode = superuser.getNode(ntPath + "/jcr:propertyDefinition[1]"); assertEquals(ntPath + "/jcr:propertyDefinition", pdNode.getPath()); List<String> defNames = new ArrayList(); NodeType nt = superuser.getWorkspace().getNodeTypeManager().getNodeType(NodeTypeConstants.NT_VERSION); for (PropertyDefinition nd : nt.getDeclaredPropertyDefinitions()) { defNames.add(nd.getName()); } Node ntNode = superuser.getNode(ntPath); NodeIterator it = ntNode.getNodes("jcr:propertyDefinition*"); while (it.hasNext()) { Node def = it.nextNode(); int index = getIndex(def); String name = (def.hasProperty(NodeTypeConstants.JCR_NAME)) ? def.getProperty(NodeTypeConstants.JCR_NAME).getString() : NodeTypeConstants.RESIDUAL_NAME; assertEquals(name, defNames.get(index-1)); } }
NodeType type = types.nextNodeType(); PropertyDefinition declaredDefs[] = type.getDeclaredPropertyDefinitions(); PropertyDefinition defs[] = type.getPropertyDefinitions();
NodeTypeManager ntmgr = session.getWorkspace().getNodeTypeManager(); NodeType nt = ntmgr.getNodeType("inf:patient"); PropertyDefinition uriPropDefn = nt.getDeclaredPropertyDefinitions()[0]; assertThat(uriPropDefn.getName(), is("inf:masterId")); assertThat(uriPropDefn.getRequiredType(), is(PropertyType.STRING));
@SuppressWarnings( "unchecked" ) public static void compareTemplateToNodeType( NodeTypeTemplate template, NodeType nodeType ) { compareNodeTypeDefinitions(template, nodeType); PropertyDefinition[] propertyDefs = nodeType.getDeclaredPropertyDefinitions(); List<PropertyDefinitionTemplate> propertyTemplates = template.getPropertyDefinitionTemplates(); comparePropertyDefinitions(propertyDefs, propertyTemplates); NodeDefinition[] childNodeDefs = nodeType.getDeclaredChildNodeDefinitions(); List<NodeDefinitionTemplate> childNodeTemplates = template.getNodeDefinitionTemplates(); compareChildNodeDefinitions(childNodeDefs, childNodeTemplates); }
@Test @FixFor( "MODE-1722" ) public void shouldRegisterNodeTypeWithUriPropertyType() throws Exception { startRepository(); registerNodeTypes("cnd/nodetype-with-uri-property.cnd"); NodeTypeManager ntmgr = session.getWorkspace().getNodeTypeManager(); NodeType nt = ntmgr.getNodeType("ex:myNodeType"); PropertyDefinition uriPropDefn = nt.getDeclaredPropertyDefinitions()[0]; assertLocalNameAndNamespace(nt, "myNodeType", "ex"); assertThat(uriPropDefn.getName(), is("ex:path")); assertThat(uriPropDefn.getRequiredType(), is(PropertyType.URI)); }
@Test public void shouldRegisterValidTypesFromCndFile() throws Exception { nodeTypeManager.registerNodeTypes(resourceAsUrl("cnd/validType.cnd"), true); NodeType nodeType = assertNodeType("modetest:testType"); assertThat(nodeType, is(notNullValue())); assertThat(nodeType.isMixin(), is(true)); assertThat(nodeType.hasOrderableChildNodes(), is(true)); assertThat(nodeType.getDeclaredSupertypes().length, is(2)); assertThat(nodeType.getDeclaredChildNodeDefinitions().length, is(1)); JcrNodeDefinition childNode = (JcrNodeDefinition)nodeType.getDeclaredChildNodeDefinitions()[0]; assertThat(childNode.getName(), is("modetest:namespace")); assertThat(childNode.getDefaultPrimaryType().getName(), is("mode:namespace")); assertThat(childNode.getRequiredPrimaryTypes().length, is(1)); assertThat(childNode.getRequiredPrimaryTypes()[0].getName(), is("mode:namespace")); assertThat(childNode.allowsSameNameSiblings(), is(false)); assertThat(childNode.isMandatory(), is(false)); assertThat(nodeType.getDeclaredPropertyDefinitions().length, is(1)); JcrPropertyDefinition property = (JcrPropertyDefinition)nodeType.getDeclaredPropertyDefinitions()[0]; assertThat(property.getName(), is("*")); assertThat(property.getRequiredType(), is(PropertyType.STRING)); assertThat(property.getValueConstraints().length, is(3)); assertThat(property.getValueConstraints()[0], is("foo")); assertThat(property.getValueConstraints()[1], is("bar")); assertThat(property.getValueConstraints()[2], is("baz")); assertThat(property.getDefaultValues().length, is(1)); assertThat(property.getDefaultValues()[0].getString(), is("foo")); }
public static void checkNodeType(String nodeTypeName, List<String> superTypes, NodeTypeManager nodeTypeManager) throws NoSuchNodeTypeException, RepositoryException { NodeType nodeTypeContent = nodeTypeManager.getNodeType(nodeTypeName); assertNotNull(nodeTypeContent); assertEquals("Should have only one generic child", 1, nodeTypeContent.getDeclaredChildNodeDefinitions().length); assertEquals("*", nodeTypeContent.getDeclaredChildNodeDefinitions()[0].getName()); assertEquals(false, nodeTypeContent.getDeclaredChildNodeDefinitions()[0].allowsSameNameSiblings()); assertEquals("Should have " + superTypes.size() + " supertype defined", superTypes.size(), nodeTypeContent.getDeclaredSupertypeNames().length); assertEquals("Should have 2 propertyDefinition defined", 2, nodeTypeContent.getDeclaredPropertyDefinitions().length); assertTrue("Should have all supertype declared", containsAllSupertypes(nodeTypeContent, superTypes)); }
@Test public void nodeTypeRegistersMultipleElements() throws LoginException, RepositoryException, TaskExecutionException { // GIVEN LinkedList<NodeTypeDefinition> nodeTypeToUpdate = new LinkedList<NodeTypeDefinition>(); // mgnl:created HashMap<String, Integer> propertyNameTypeMap = new HashMap<String, Integer>(); propertyNameTypeMap.put(NodeTypes.Created.CREATED, PropertyType.DATE); propertyNameTypeMap.put(NodeTypes.Created.CREATED_BY, PropertyType.STRING); NodeTypeTemplate nodeTypelastCreated = NodeTypeTemplateUtil.createSimpleMixinNodeType(nodeTypeManager, NodeTypes.Created.NAME, NodeType.NT_RESOURCE, propertyNameTypeMap); nodeTypeToUpdate.add(nodeTypelastCreated); // mgnl:content NodeTypeDefinition typeDefinitionContent = NodeTypeTemplateUtil.createSimpleNodeType(nodeTypeManager, NodeTypes.Content.NAME, Arrays.asList(NodeType.NT_HIERARCHY_NODE, NodeType.MIX_REFERENCEABLE, NodeTypes.Created.NAME)); nodeTypeToUpdate.add(typeDefinitionContent); TestNodeTypeRegistrationTask task = new TestNodeTypeRegistrationTask("name", "description", RepositoryConstants.CONFIG, nodeTypeToUpdate, null); // WHEN task.execute(installContext); // THEN NodeType nodeTypeContent = nodeTypeManager.getNodeType(NodeTypes.Content.NAME); assertNotNull(nodeTypeContent); assertEquals("Should have only one generic child", 1, nodeTypeContent.getDeclaredChildNodeDefinitions().length); assertEquals("*", nodeTypeContent.getDeclaredChildNodeDefinitions()[0].getName()); assertEquals("Should have 3 supertype defined", 3, nodeTypeContent.getDeclaredSupertypeNames().length); assertEquals("Should have 2 propertyDefinition defined", 2, nodeTypeContent.getDeclaredPropertyDefinitions().length); // mgnl:created must also be present. nodeTypeContent = nodeTypeManager.getNodeType(NodeTypes.Created.NAME); assertNotNull(nodeTypeContent); assertEquals("Should have 1 supertype defined", 1, nodeTypeContent.getDeclaredSupertypeNames().length); assertEquals("nt:resource", nodeTypeContent.getDeclaredSupertypeNames()[0]); }
@Test public void nodeTypeRegistersSingleElement() throws LoginException, RepositoryException, TaskExecutionException { // GIVEN LinkedList<NodeTypeDefinition> nodeTypeToUpdate = new LinkedList<NodeTypeDefinition>(); // Create mgnl:content NodeTypeDefinition String name = NodeTypes.Content.NAME; NodeTypeDefinition typeDefinitionContent = NodeTypeTemplateUtil.createSimpleNodeType(nodeTypeManager, name, Arrays.asList(NodeType.NT_HIERARCHY_NODE, NodeType.MIX_REFERENCEABLE, NodeTypes.Deleted.NAME)); nodeTypeToUpdate.add(typeDefinitionContent); TestNodeTypeRegistrationTask task = new TestNodeTypeRegistrationTask("name", "description", RepositoryConstants.CONFIG, nodeTypeToUpdate, null); // WHEN task.execute(installContext); // THEN NodeType nodeTypeContent = nodeTypeManager.getNodeType(NodeTypes.Content.NAME); assertNotNull(nodeTypeContent); assertEquals("Should have only one generic child", 1, nodeTypeContent.getDeclaredChildNodeDefinitions().length); assertEquals("*", nodeTypeContent.getDeclaredChildNodeDefinitions()[0].getName()); assertEquals("Should have 3 supertype defined", 3, nodeTypeContent.getDeclaredSupertypeNames().length); assertEquals("Should have 2 propertyDefinition defined", 2, nodeTypeContent.getDeclaredPropertyDefinitions().length); // Check website workspace. NodeType should also have been updated. // As NodeTypes are available for the repository name="magnolia", that defines: config, website, ..., workspaces. Session websiteSession = MgnlContext.getJCRSession(RepositoryConstants.WEBSITE); NodeTypeManager websiteNodeTypeManager = websiteSession.getWorkspace().getNodeTypeManager(); nodeTypeContent = websiteNodeTypeManager.getNodeType(NodeTypes.Content.NAME); assertNotNull(nodeTypeContent); assertEquals("Should have only one generic child", 1, nodeTypeContent.getDeclaredChildNodeDefinitions().length); assertEquals("*", nodeTypeContent.getDeclaredChildNodeDefinitions()[0].getName()); assertEquals("Should have 3 supertype defined", 3, nodeTypeContent.getDeclaredSupertypeNames().length); }