@Override public boolean apply(NodeDefinition nodeDefinition) { return nodeDefinition.isAutoCreated(); } });
@Override public boolean apply(NodeDefinition nodeDefinition) { return nodeDefinition.isAutoCreated(); } });
@Override public boolean apply(NodeDefinition nodeDefinition) { return nodeDefinition.isAutoCreated(); } });
private void clone(Node node, Node parent) throws RepositoryException { if (node.getDefinition().isAutoCreated()) { Node destination = parent.getNode(node.getName()); this.removeProperties(destination); this.updateProperties(node, destination); } else { final String parentPath = parent.getPath(); final String srcWorkspaceLogicalName = node.getSession().getWorkspace().getName(); final String srcWorkspacePhysicalName = repositoryManager.getWorkspaceMapping(srcWorkspaceLogicalName).getPhysicalWorkspaceName(); final Workspace targetWorkspace = parent.getSession().getWorkspace(); final String srcPath = node.getPath(); final String targetPath = parentPath + (parentPath != null && parentPath.endsWith("/") ? "" : "/") + node.getName(); log.debug("workspace level clone from {}:{} to {}:{}", srcWorkspaceLogicalName, srcPath, targetWorkspace.getName(), parentPath); targetWorkspace.clone(srcWorkspacePhysicalName, srcPath, targetPath, true); } }
private void processChildNodeDefinition( Node nodeTypeNode, NodeDefinition childNodeDefinition ) throws RepositoryException { Node childNode = nodeTypeNode.addNode(CHILD_NODE_DEFINITION, CHILD_NODE_DEFINITION); if (!RESIDUAL_ITEM_NAME.equals(childNodeDefinition.getName())) { childNode.setProperty(NAME, childNodeDefinition.getName()); } childNode.setProperty(AUTO_CREATED, childNodeDefinition.isAutoCreated()); childNode.setProperty(MANDATORY, childNodeDefinition.isMandatory()); childNode.setProperty(ON_PARENT_VERSION, OnParentVersionAction.nameFromValue(childNodeDefinition.getOnParentVersion())); childNode.setProperty(PROTECTED, childNodeDefinition.isProtected()); String[] requiredPrimaryTypeNames = childNodeDefinition.getRequiredPrimaryTypeNames(); childNode.setProperty(REQUIRED_PRIMARY_TYPES, requiredPrimaryTypeNames != null ? requiredPrimaryTypeNames : new String[0]); childNode.setProperty(SAME_NAME_SIBLINGS, childNodeDefinition.allowsSameNameSiblings()); childNode.setProperty(DEFAULT_PRIMARY_TYPE, childNodeDefinition.getDefaultPrimaryTypeName()); }
private void processChildNodeDefinition( Node nodeTypeNode, NodeDefinition childNodeDefinition ) throws RepositoryException { Node childNode = nodeTypeNode.addNode(CHILD_NODE_DEFINITION, CHILD_NODE_DEFINITION); if (!RESIDUAL_ITEM_NAME.equals(childNodeDefinition.getName())) { childNode.setProperty(NAME, childNodeDefinition.getName()); } childNode.setProperty(AUTO_CREATED, childNodeDefinition.isAutoCreated()); childNode.setProperty(MANDATORY, childNodeDefinition.isMandatory()); childNode.setProperty(ON_PARENT_VERSION, OnParentVersionAction.nameFromValue(childNodeDefinition.getOnParentVersion())); childNode.setProperty(PROTECTED, childNodeDefinition.isProtected()); String[] requiredPrimaryTypeNames = childNodeDefinition.getRequiredPrimaryTypeNames(); childNode.setProperty(REQUIRED_PRIMARY_TYPES, requiredPrimaryTypeNames != null ? requiredPrimaryTypeNames : new String[0]); childNode.setProperty(SAME_NAME_SIBLINGS, childNodeDefinition.allowsSameNameSiblings()); childNode.setProperty(DEFAULT_PRIMARY_TYPE, childNodeDefinition.getDefaultPrimaryTypeName()); }
private static boolean isAutoCreatedNode(final String childName, Node parent) throws RepositoryException { for (NodeDefinition nodeDefinition : parent.getPrimaryNodeType().getChildNodeDefinitions()) { if (childName.equals(nodeDefinition.getName())) { if (nodeDefinition.isAutoCreated()) { return true; } } } for (NodeType nodeType : parent.getMixinNodeTypes()) { for (NodeDefinition nodeDefinition : nodeType.getChildNodeDefinitions()) { if (childName.equals(nodeDefinition.getName())) { if (nodeDefinition.isAutoCreated()) { return true; } } } } return false; }
/** * Tests if auto create nodes are not a residual set definition (getName() * does not return "*") */ public void testIsAutoCreate() throws RepositoryException { NodeTypeIterator types = manager.getAllNodeTypes(); // loop all node types while (types.hasNext()) { NodeType type = types.nextNodeType(); NodeDefinition defs[] = type.getChildNodeDefinitions(); for (int i = 0; i < defs.length; i++) { if (defs[i].isAutoCreated()) { assertFalse("An auto create node must not be a " + "residual set definition.", defs[i].getName().equals("*")); } } } }
private static void clear(Node node) throws RepositoryException { for (Node child : new NodeIterable(node.getNodes())) { if (child.getDefinition().isAutoCreated()) { clear(child); } else { child.remove(); } } for (Property property : new PropertyIterable(node.getProperties())) { if (property.getName().startsWith("jcr:") || property.getDefinition().isProtected() || immune.contains(property.getName())) { continue; } property.remove(); } }
/** * Recursively removes all child nodes from node using specified filter. */ private void removeNonExistingChildNodes(Node source, Node destination, Predicate filter) throws RepositoryException { // collect all uuids from the source node hierarchy using the given filter NodeIterator children = new FilteringNodeIterator(destination.getNodes(), filter); while (children.hasNext()) { Node child = children.nextNode(); // check if this child exist in source, if not remove it if (child.getDefinition().isAutoCreated()) { continue; } try { source.getSession().getNodeByIdentifier(child.getIdentifier()); // if exist its ok, recursively remove all sub nodes this.removeNonExistingChildNodes(source, child, filter); } catch (ItemNotFoundException e) { PropertyIterator referencedProperties = child.getReferences(); if (referencedProperties.getSize() > 0) { // remove all referenced properties, its safe since source workspace cannot have these // properties if node with this UUID does not exist while (referencedProperties.hasNext()) { referencedProperties.nextProperty().remove(); } } child.remove(); } } }
@Override public void startNode(final NodeInfo nodeInfo) throws RepositoryException { if (getCurrent() != null) { final NodeDefinition definition = nodeInfo.getApplicableChildNodeDef(getCurrentNodeTypes()); if (definition != null && !definition.isProtected()) { final Node childDest; if (definition.isAutoCreated() && nodeInfo.getIndex() == 1 && getCurrent().hasNode(nodeInfo.getName())) { childDest = getCurrent().getNode(nodeInfo.getName()); } else { childDest = getCurrent().addNode(nodeInfo.getName(), nodeInfo.getNodeTypeName()); } for (String nodeTypeName : nodeInfo.getMixinNames()) { childDest.addMixin(nodeTypeName); } setCurrent(childDest); return; } throw new IllegalArgumentException("No applicable child node definition"); } throw new IllegalStateException("No current copy target node"); }
private JcrNodeDefinition childNodeDefinitionFrom( NodeDefinition childNodeDefn ) { Name childNodeName = nameFactory.create(childNodeDefn.getName()); Name defaultPrimaryTypeName = nameFactory.create(childNodeDefn.getDefaultPrimaryTypeName()); int onParentVersion = childNodeDefn.getOnParentVersion(); boolean mandatory = childNodeDefn.isMandatory(); boolean allowsSns = childNodeDefn.allowsSameNameSiblings(); boolean autoCreated = childNodeDefn.isAutoCreated(); boolean isProtected = childNodeDefn.isProtected(); Name[] requiredTypes; String[] requiredTypeNames = childNodeDefn.getRequiredPrimaryTypeNames(); if (requiredTypeNames != null) { List<Name> names = new ArrayList<Name>(requiredTypeNames.length); for (String typeName : requiredTypeNames) { names.add(nameFactory.create(typeName)); } requiredTypes = names.toArray(new Name[names.size()]); } else { requiredTypes = new Name[0]; } NodeKey prototypeKey = repository.repositoryCache().getSystemKey(); return new JcrNodeDefinition(this.context, null, prototypeKey, childNodeName, onParentVersion, autoCreated, mandatory, isProtected, allowsSns, defaultPrimaryTypeName, requiredTypes); }
private JcrNodeDefinition childNodeDefinitionFrom( NodeDefinition childNodeDefn ) { Name childNodeName = nameFactory.create(childNodeDefn.getName()); Name defaultPrimaryTypeName = nameFactory.create(childNodeDefn.getDefaultPrimaryTypeName()); int onParentVersion = childNodeDefn.getOnParentVersion(); boolean mandatory = childNodeDefn.isMandatory(); boolean allowsSns = childNodeDefn.allowsSameNameSiblings(); boolean autoCreated = childNodeDefn.isAutoCreated(); boolean isProtected = childNodeDefn.isProtected(); Name[] requiredTypes; String[] requiredTypeNames = childNodeDefn.getRequiredPrimaryTypeNames(); if (requiredTypeNames != null) { List<Name> names = new ArrayList<Name>(requiredTypeNames.length); for (String typeName : requiredTypeNames) { names.add(nameFactory.create(typeName)); } requiredTypes = names.toArray(new Name[names.size()]); } else { requiredTypes = new Name[0]; } NodeKey prototypeKey = repository.repositoryCache().getSystemKey(); return new JcrNodeDefinition(this.context, null, prototypeKey, childNodeName, onParentVersion, autoCreated, mandatory, isProtected, allowsSns, defaultPrimaryTypeName, requiredTypes); }
protected void assertChild( String nodeTypeName, String childName, String[] requiredTypes, String defaultPrimaryType, ChildOptions[] childOptions, OnParentVersion onParentVersioning ) { Set<ChildOptions> options = new HashSet<ChildOptions>(); for (ChildOptions option : childOptions) options.add(option); NodeTypeDefinition defn = defn(nodeTypeName); NodeDefinition childDefn = childDefn(defn, childName); assertThat(childDefn.getName(), is(childName)); assertThat(childDefn.getDefaultPrimaryTypeName(), is(defaultPrimaryType)); assertThat(childDefn.isMandatory(), is(options.contains(ChildOptions.Mandatory))); assertThat(childDefn.isAutoCreated(), is(options.contains(ChildOptions.Autocreated))); assertThat(childDefn.isProtected(), is(options.contains(ChildOptions.Protected))); assertThat(childDefn.allowsSameNameSiblings(), is(options.contains(ChildOptions.Sns))); assertThat(childDefn.getOnParentVersion(), is(opv(onParentVersioning))); assertThat(childDefn.getRequiredPrimaryTypeNames(), is(requiredTypes)); } }
private void loadChildNodeDefinitions(NodeType nodeType, EffectiveNodeTypeImpl ent) throws RepositoryException { for (NodeDefinition nd : nodeType.getChildNodeDefinitions()) { EffectiveNodeTypeChildImpl child = // ensure child definition declaring type is also loaded new EffectiveNodeTypeChildImpl(nd.getName(), loadEffectiveNodeType(nd.getDeclaringNodeType()).getName()); for (NodeType childType : nd.getRequiredPrimaryTypes()) { // ensure all possible child types are also loaded child.getRequiredPrimaryTypes().add(loadEffectiveNodeType(childType).getName()); } if (nd.getDefaultPrimaryType() != null) { // ensure possible primary type is also loaded child.setDefaultPrimaryType(loadEffectiveNodeType(nd.getDefaultPrimaryType()).getName()); } child.setMandatory(nd.isMandatory()); child.setAutoCreated(nd.isAutoCreated()); child.setMultiple(nd.allowsSameNameSiblings()); child.setProtected(nd.isProtected()); // each child definition is maintained in a list by name List<EffectiveNodeTypeChild> childList = ent.getChildren().get(child.getName()); if (childList == null) { childList = new ArrayList<EffectiveNodeTypeChild>(); ent.getChildren().put(child.getName(), childList); } childList.add(child); } }
private static void assertAutoCreatedItems(@NotNull Tree authorizableTree, @NotNull String ntName, @NotNull Root root) throws Exception { NodeType repUser = ReadOnlyNodeTypeManager.getInstance(root, NamePathMapper.DEFAULT).getNodeType(ntName); for (NodeDefinition cnd : repUser.getChildNodeDefinitions()) { if (cnd.isAutoCreated()) { assertTrue(authorizableTree.hasChild(cnd.getName())); } } for (PropertyDefinition pd : repUser.getPropertyDefinitions()) { if (pd.isAutoCreated()) { assertTrue(authorizableTree.hasProperty(pd.getName())); } } } }
/** * Creates a new node definition based on a JCR <code>NodeDefinition</code>. * * @param nodeDef the node definition. * @param resolver the name/path resolver of the session that provided the * node definition * @throws NameException if <code>nodeDef</code> contains an illegal * name. * @throws NamespaceException if <code>nodeDef</code> contains a name with * an namespace prefix that is unknown to * <code>resolver</code>. */ public QNodeDefinitionImpl(NodeDefinition nodeDef, NamePathResolver resolver) throws NameException, NamespaceException { this(nodeDef.getName().equals(NameConstants.ANY_NAME.getLocalName()) ? NameConstants.ANY_NAME : resolver.getQName(nodeDef.getName()), nodeDef.getDeclaringNodeType() != null ? resolver.getQName(nodeDef.getDeclaringNodeType().getName()) : null, nodeDef.isAutoCreated(), nodeDef.isMandatory(), nodeDef.getOnParentVersion(), nodeDef.isProtected(), nodeDef.getDefaultPrimaryType() != null ? resolver.getQName(nodeDef.getDefaultPrimaryType().getName()) : null, getNodeTypeNames(nodeDef.getRequiredPrimaryTypes(), resolver), nodeDef.allowsSameNameSiblings()); }
/** * Creates a new node definition based on a JCR <code>NodeDefinition</code>. * * @param nodeDef the node definition. * @param resolver the name/path resolver of the session that provided the * node definition * @throws NameException if <code>nodeDef</code> contains an illegal * name. * @throws NamespaceException if <code>nodeDef</code> contains a name with * an namespace prefix that is unknown to * <code>resolver</code>. */ public QNodeDefinitionImpl(NodeDefinition nodeDef, NamePathResolver resolver) throws NameException, NamespaceException { this(nodeDef.getName().equals(NameConstants.ANY_NAME.getLocalName()) ? NameConstants.ANY_NAME : resolver.getQName(nodeDef.getName()), nodeDef.getDeclaringNodeType() != null ? resolver.getQName(nodeDef.getDeclaringNodeType().getName()) : null, nodeDef.isAutoCreated(), nodeDef.isMandatory(), nodeDef.getOnParentVersion(), nodeDef.isProtected(), nodeDef.getDefaultPrimaryType() != null ? resolver.getQName(nodeDef.getDefaultPrimaryType().getName()) : null, getNodeTypeNames(nodeDef.getRequiredPrimaryTypes(), resolver), nodeDef.allowsSameNameSiblings()); }
@Test public void testCreateSimpleMixinNodeTypeLastModified() throws RepositoryException { // GIVEN String name = NodeTypes.Content.NAME; List<String> superTypes = new ArrayList<String>(); superTypes.add(NodeTypes.Created.NAME); superTypes.add(NodeTypes.Activatable.NAME); superTypes.add(NodeTypes.LastModified.NAME); superTypes.add(NodeTypes.Renderable.NAME); superTypes.add(NodeTypes.Versionable.NAME); // WHEN NodeTypeTemplate nodeTypeTemplate = NodeTypeTemplateUtil.createSimpleNodeType(nodeTypeManager, name, superTypes); // THEN assertNotNull(nodeTypeTemplate); assertEquals(NodeTypes.Content.NAME, nodeTypeTemplate.getName()); assertFalse(nodeTypeTemplate.isMixin()); assertEquals(5, nodeTypeTemplate.getDeclaredSupertypeNames().length); assertEquals(2, nodeTypeTemplate.getPropertyDefinitionTemplates().size()); assertEquals(1, nodeTypeTemplate.getDeclaredChildNodeDefinitions().length); NodeDefinition child = nodeTypeTemplate.getDeclaredChildNodeDefinitions()[0]; assertEquals("*", child.getName()); assertFalse(child.isAutoCreated()); assertFalse(child.isMandatory()); assertFalse(child.allowsSameNameSiblings()); assertEquals(OnParentVersionAction.COPY, child.getOnParentVersion()); }
@Override protected void setUp() throws Exception { super.setUp(); NodeType nt = superuser.getWorkspace().getNodeTypeManager().getNodeType(testNodeType); NodeDefinition[] ndefs = nt.getChildNodeDefinitions(); for (int i = 0; i < ndefs.length; i++) { if (ndefs[i].isMandatory() && !ndefs[i].isProtected() && !ndefs[i].isAutoCreated()) { childNodeDef = ndefs[i]; break; } } PropertyDefinition[] pdefs = nt.getPropertyDefinitions(); for (int i = 0; i < pdefs.length; i++) { if (pdefs[i].isMandatory() && !pdefs[i].isProtected() && !pdefs[i].isAutoCreated()) { childPropDef = pdefs[i]; break; } } if (childPropDef == null && childNodeDef == null) { cleanUp(); throw new NotExecutableException(); } }