/** {@inheritDoc} */ public String[] getDeclaredSupertypeNames() { return type.getDeclaredSupertypeNames(); }
public static boolean containsAllSupertypes(NodeType nodeTypeContent, List<String> superTypes) { boolean res = true; String[] declaredSuperTypes = nodeTypeContent.getDeclaredSupertypeNames(); List<String> declaredSuperTypesList = Arrays.asList(declaredSuperTypes); for (String supertype : superTypes) { res &= declaredSuperTypesList.contains(supertype); } return res; }
private SerializationKind getSerializationKind(String nodeType, NodeTypeRegistry nodeTypeRegistry) { if (Repository.NT_FILE.equals(nodeType)) { return SerializationKind.FILE; } if (Repository.NT_RESOURCE.equals(nodeType)) { return SerializationKind.FILE; } if (Repository.NT_FOLDER.equals(nodeType)) { return SerializationKind.FOLDER; } if ("rep:accessControl".equals(nodeType) || "rep:Policy".equals(nodeType) || "cq:Widget".equals(nodeType) || "cq:EditConfig".equals(nodeType) || "cq:WorkflowModel".equals(nodeType) || "vlt:FullCoverage".equals(nodeType) || "mix:language".equals(nodeType) || "sling:OsgiConfig".equals(nodeType)) { return SerializationKind.METADATA_FULL; } String[] parents = nodeTypeRegistry.getNodeType(nodeType).getDeclaredSupertypeNames(); if (parents == null) return null; for (String parent : parents) { SerializationKind parentSerializationKind = getSerializationKind(parent, nodeTypeRegistry); if (parentSerializationKind != null) { return parentSerializationKind; } } return null; }
/** * Test if all node types returned by getDeclaredSupertypes() are also * returned by getSupertypes(). All existing node types are tested. */ public void testGetDeclaredSupertypes() throws RepositoryException { for (NodeTypeIterator types = manager.getAllNodeTypes(); types.hasNext(); ) { NodeType type = types.nextNodeType(); Set<String> declaredSupertypeNames = asSetOfNames(type.getDeclaredSupertypes()); Set<String> supertypeNames = asSetOfNames(type.getSupertypes()); assertTrue("all declared supertypes must be supertypes: " + (new HashSet<String>(declaredSupertypeNames).removeAll(supertypeNames)), supertypeNames.containsAll(declaredSupertypeNames)); assertEquals("getDeclaredSuperTypes and getDeclaredSuperTypeNames must be consistent", declaredSupertypeNames, new HashSet<String>(Arrays.asList(type.getDeclaredSupertypeNames()))); } }
if (directOnly) { for (String name : nt.getDeclaredSupertypeNames()) { if (name.equals(thisName)) { result.add(nt);
if (directOnly) { for (String name : nt.getDeclaredSupertypeNames()) { if (name.equals(thisName)) { result.add(nt);
/** * 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; } }
@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]); }
List<String> supertypeNames = Arrays.asList(ntResource.getDeclaredSupertypeNames()); assertThat(supertypeNames, hasItem(NT_BASE)); supertypeNames = Arrays.asList(ntResource.getDeclaredSupertypeNames()); assertThat(supertypeNames, hasItem(NT_BASE));
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)); }
@Override protected NodeTypeTemplate configureNodeType() throws RepositoryException { NodeDefinitionTemplate ndt = getNodeTypeManager().createNodeDefinitionTemplate(); ndt.setAutoCreated(true); ndt.setDefaultPrimaryTypeName("mgnl:metaData"); ndt.setMandatory(true); ndt.setName("MetaData"); ndt.setOnParentVersion(OnParentVersionAction.COPY); ndt.setProtected(false); ndt.setSameNameSiblings(false); ndt.setRequiredPrimaryTypeNames(new String[] { "mgnl:metaData" }); NodeTypeTemplate ntt = getNodeTypeManager().createNodeTypeTemplate(); ntt.setName(getOriginalNodeType().getName()); ntt.setMixin(getOriginalNodeType().isMixin()); ntt.setOrderableChildNodes(getOriginalNodeType().hasOrderableChildNodes()); ntt.setDeclaredSuperTypeNames(getOriginalNodeType().getDeclaredSupertypeNames()); ntt.getNodeDefinitionTemplates().add(ndt); return ntt; }
@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); }