/** {@inheritDoc} */ public RemoteNodeDefinition[] getDeclaredChildNodeDefs() throws RemoteException { return getRemoteNodeDefArray(type.getDeclaredChildNodeDefinitions()); }
Collection<NodeDefinition> internalGetChildDefinitions() { // TODO distinguish between additive and overriding node definitions. See 3.7.6.8 Item Definitions in Subtypes Collection<NodeDefinition> definitions = new ArrayList<NodeDefinition>(); definitions.addAll(Arrays.asList(getDeclaredChildNodeDefinitions())); for (NodeType type : getSupertypes()) { definitions.addAll(Arrays.asList(type.getDeclaredChildNodeDefinitions())); } return definitions; }
Collection<NodeDefinition> internalGetChildDefinitions() { // TODO distinguish between additive and overriding node definitions. See 3.7.6.8 Item Definitions in Subtypes Collection<NodeDefinition> definitions = new ArrayList<NodeDefinition>(); definitions.addAll(Arrays.asList(getDeclaredChildNodeDefinitions())); for (NodeType type : getSupertypes()) { definitions.addAll(Arrays.asList(type.getDeclaredChildNodeDefinitions())); } return definitions; }
Collection<NodeDefinition> internalGetChildDefinitions() { // TODO distinguish between additive and overriding node definitions. See 3.7.6.8 Item Definitions in Subtypes Collection<NodeDefinition> definitions = new ArrayList<NodeDefinition>(); definitions.addAll(Arrays.asList(getDeclaredChildNodeDefinitions())); for (NodeType type : getSupertypes()) { definitions.addAll(Arrays.asList(type.getDeclaredChildNodeDefinitions())); } return definitions; }
private boolean allowsSNS(final String nodeType) throws RepositoryException { final NodeType nt = ntm.getNodeType(nodeType); for (final NodeDefinition nd : nt.getDeclaredChildNodeDefinitions()) { if (nd.allowsSameNameSiblings()) { return true; } } return false; }
/** * Return a {@link NodeTypeDefinition} list where the metaData child node definition has been removed. */ @Override public List<NodeTypeDefinition> getNodeTypesToRegister(NodeTypeManager nodeTypeManager) { List<NodeTypeDefinition> list = new ArrayList<NodeTypeDefinition>(); try { NodeTypeIterator iterator = nodeTypeManager.getAllNodeTypes(); while (iterator.hasNext()) { NodeType nodeType = iterator.nextNodeType(); if (nodeType.getDeclaredChildNodeDefinitions() != null) { // check if this type define metaData as child List<NodeDefinition> childNodeDefinition = Arrays.asList(nodeType.getDeclaredChildNodeDefinitions()); for (NodeDefinition nodeDefinition : childNodeDefinition) { if (nodeDefinition.getDefaultPrimaryType() != null && NodeTypes.MetaData.NAME.equals(nodeDefinition.getDefaultPrimaryType().getName())) { NodeTypeTemplate newNodeType = createNodeTypeWithoutMetaData(nodeTypeManager, nodeType, nodeDefinition); log.info("Add the following NodeType '{}' that currently defined a metaData nodeType as child node to the list.", newNodeType.getName()); list.add(newNodeType); break; } } } } } catch (RepositoryException e) { log.error("Could not create a List of existing NodeTpe declaring metaData as childNodeDefinition", e); } return list; }
/** * 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; } }
private void checkIfMetaDataIsDefineAsChildNode(NodeType nodeType) { List<NodeDefinition> childNode = Arrays.asList(nodeType.getDeclaredChildNodeDefinitions()); for (NodeDefinition nodeDefinition : childNode) { assertFalse("MetaData".equals(nodeDefinition.getName())); if (StringUtils.isNotBlank(nodeDefinition.getDefaultPrimaryTypeName())) { assertFalse(NodeTypes.MetaData.NAME.equals(nodeDefinition.getDefaultPrimaryTypeName())); } } }
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)); }
public void testIndexedChildDefinition() throws Exception { String ntPath = NodeTypeConstants.NODE_TYPES_PATH + '/' + NodeTypeConstants.NT_VERSIONHISTORY; assertTrue(superuser.nodeExists(ntPath + "/jcr:childNodeDefinition")); assertTrue(superuser.nodeExists(ntPath + "/jcr:childNodeDefinition[1]")); Node cdNode = superuser.getNode(ntPath + "/jcr:childNodeDefinition[1]"); assertEquals(ntPath + "/jcr:childNodeDefinition", cdNode.getPath()); List<String> defNames = new ArrayList(); NodeType nt = superuser.getWorkspace().getNodeTypeManager().getNodeType(NodeTypeConstants.NT_VERSIONHISTORY); for (NodeDefinition nd : nt.getDeclaredChildNodeDefinitions()) { defNames.add(nd.getName()); } Node ntNode = superuser.getNode(ntPath); NodeIterator it = ntNode.getNodes("jcr:childNodeDefinition*"); 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(); NodeDefinition declaredDefs[] = type.getDeclaredChildNodeDefinitions(); NodeDefinition defs[] = type.getChildNodeDefinitions();
assertEquals(2, nodeTypeContent.getDeclaredChildNodeDefinitions().length);
@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); }
@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 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 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")); }
@Override @Before public void setUp() throws Exception { // Register 4.5 node type ComponentsTestUtil.setImplementation(ProviderImpl.class, TestProviderImpl.class); super.setUp(); // Init install context final ModuleRegistryImpl moduleRegistry = new ModuleRegistryImpl(); installContext = new InstallContextImpl(moduleRegistry); // Check Session configSession = MgnlContext.getJCRSession(RepositoryConstants.CONFIG); nodeTypeManager = configSession.getWorkspace().getNodeTypeManager(); // Register mixIn type (not present in 4.5 nodeType definition) Register50NodeTypeTaskTest.registerSimpleMixInType(installContext, nodeTypeManager); // 4.5.x node types 'mgnl:content' contains a mgnl:metadata child node NodeType nodeTypeContentNode = nodeTypeManager.getNodeType(NodeTypes.ContentNode.NAME); assertNotNull(nodeTypeContentNode); assertEquals(2, nodeTypeContentNode.getDeclaredChildNodeDefinitions().length); }
@Override @Before public void setUp() throws Exception { // Simplest way a configure a repo with specific node types ComponentsTestUtil.setImplementation(ProviderImpl.class, TestProviderImpl.class); super.setUp(); final ModuleRegistryImpl moduleRegistry = new ModuleRegistryImpl(); installContext = new InstallContextImpl(moduleRegistry); // Check Session configSession = MgnlContext.getJCRSession(RepositoryConstants.CONFIG); nodeTypeManager = configSession.getWorkspace().getNodeTypeManager(); // 4.5.x node types 'mgnl:content' contains a mgnl:metadata child node NodeType nodeTypeContent = nodeTypeManager.getNodeType(NodeTypes.Content.NAME); assertNotNull(nodeTypeContent); assertEquals(2, nodeTypeContent.getDeclaredChildNodeDefinitions().length); // 4.5.x do not have a 'mgnl:created' definition try { nodeTypeManager.getNodeType(NodeTypes.Created.NAME); fail("nodeTypeManager should throw a NoSuchNodeTypeException as 4.5 NodeTypeDefinition do not define a 'mgnl:created'"); } catch (NoSuchNodeTypeException ne) { } }
@Override @Before public void setUp() throws Exception { // Simplest way a configure a repo with specific node types ComponentsTestUtil.setImplementation(ProviderImpl.class, TestProviderImpl.class); super.setUp(); final ModuleRegistryImpl moduleRegistry = new ModuleRegistryImpl(); installContext = new InstallContextImpl(moduleRegistry); // Check Session configSession = MgnlContext.getJCRSession(RepositoryConstants.CONFIG); nodeTypeManager = configSession.getWorkspace().getNodeTypeManager(); // 4.5.x node types 'mgnl:content' contains a mgnl:metadata child node NodeType nodeTypeContent = nodeTypeManager.getNodeType(NodeTypes.Content.NAME); assertNotNull(nodeTypeContent); assertEquals(2, nodeTypeContent.getDeclaredChildNodeDefinitions().length); // 4.5.x do not have a 'mgnl:lastModified' definition try { nodeTypeManager.getNodeType(NodeTypes.Created.NAME); assertTrue("nodeTypeManager should throw a NoSuchNodeTypeException as 4.5 NodeTypeDefinition do not define a 'mgnl:created'", false); } catch (NoSuchNodeTypeException ne) { } }
@Override @Before public void setUp() throws Exception { // Simplest way a configure a repo with specific node types ComponentsTestUtil.setImplementation(ProviderImpl.class, TestProviderImpl.class); super.setUp(); final ModuleRegistryImpl moduleRegistry = new ModuleRegistryImpl(); installContext = new InstallContextImpl(moduleRegistry); // Check Session configSession = MgnlContext.getJCRSession(RepositoryConstants.CONFIG); nodeTypeManager = configSession.getWorkspace().getNodeTypeManager(); // 4.5.x node types 'mgnl:content' contains a mgnl:metadata child node NodeType nodeTypeContent = nodeTypeManager.getNodeType(NodeTypes.Content.NAME); assertNotNull(nodeTypeContent); assertEquals(2, nodeTypeContent.getDeclaredChildNodeDefinitions().length); // 4.5.x do not have a 'mgnl:created' definition try { nodeTypeManager.getNodeType(NodeTypes.Created.NAME); fail("nodeTypeManager should throw a NoSuchNodeTypeException as 4.5 NodeTypeDefinition do not define a 'mgnl:created'"); } catch (NoSuchNodeTypeException ne) { } registerSimpleMixInType(installContext, nodeTypeManager); }