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()); }
/** * Tests if restoring the <code>Version</code> of an existing node throws an * <code>ItemExistsException</code> if removeExisting is set to FALSE. */ @SuppressWarnings("deprecation") public void testWorkspaceRestoreWithUUIDConflict() throws RepositoryException, NotExecutableException { try { // Verify that nodes used for the test are indeed versionable NodeDefinition nd = wVersionableNode.getDefinition(); if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) { throw new NotExecutableException("Nodes must be versionable in order to run this test."); } Version v = wVersionableNode.checkin(); wVersionableNode.checkout(); wSuperuser.move(wVersionableChildNode.getPath(), wVersionableNode2.getPath() + "/" + wVersionableChildNode.getName()); wSuperuser.save(); wSuperuser.getWorkspace().restore(new Version[]{v}, false); fail("Node.restore( Version, boolean ): An ItemExistsException must be thrown if the node to be restored already exsits and removeExisting was set to false."); } catch (ItemExistsException e) { // success } }
/** * Tests if restoring the <code>Version</code> of an existing node throws an * <code>ItemExistsException</code> if removeExisting is set to FALSE. */ public void testRestoreWithUUIDConflictJcr2_2() throws RepositoryException, NotExecutableException { try { Node naa = createVersionableNode(versionableNode, nodeName4, versionableNodeType); // Verify that nodes used for the test have proper opv behaviour NodeDefinition nd = naa.getDefinition(); if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) { throw new NotExecutableException("Child nodes must have OPV COPY or VERSION in order to be able to test Node.restore with uuid conflict."); } Version v = versionManager.checkin(versionableNode.getPath()); versionManager.checkout(versionableNode.getPath()); superuser.move(naa.getPath(), versionableNode2.getPath() + "/" + naa.getName()); superuser.save(); versionManager.restore(v, false); fail("Node.restore( Version, boolean ): An ItemExistsException must be thrown if the node to be restored already exsits and removeExisting was set to false."); } catch (ItemExistsException e) { // success } }
private boolean isIgnoreOnOPV() throws CommitFailedException { if (this.parent != null) { try { NodeDefinition definition = this.vMgr.getNodeTypeManager().getDefinition(TreeFactory.createTree(parent.node), this.name); return definition.getOnParentVersion() == OnParentVersionAction.IGNORE; } catch (Exception e) { throw new CommitFailedException(CommitFailedException.VERSION, VersionExceptionCode.UNEXPECTED_REPOSITORY_EXCEPTION.ordinal(), e.getMessage()); } } return false; }
private boolean isIgnoreOnOPV() throws CommitFailedException { if (this.parent != null) { try { NodeDefinition definition = this.vMgr.getNodeTypeManager().getDefinition(TreeFactory.createTree(parent.node), this.name); return definition.getOnParentVersion() == OnParentVersionAction.IGNORE; } catch (Exception e) { throw new CommitFailedException(CommitFailedException.VERSION, VersionExceptionCode.UNEXPECTED_REPOSITORY_EXCEPTION.ordinal(), e.getMessage()); } } return false; }
private boolean isIgnoreOnOPV() throws CommitFailedException { if (this.parent != null) { try { NodeDefinition definition = this.vMgr.getNodeTypeManager().getDefinition(TreeFactory.createTree(parent.node), this.name); return definition.getOnParentVersion() == OnParentVersionAction.IGNORE; } catch (Exception e) { throw new CommitFailedException(CommitFailedException.VERSION, VersionExceptionCode.UNEXPECTED_REPOSITORY_EXCEPTION.ordinal(), e.getMessage()); } } return false; }
@Override protected void setUp() throws Exception { super.setUp(); Node n1 = testRootNode.addNode(nodeName1, NT_FILE); Node content = n1.addNode(JCR_CONTENT, NT_RESOURCE); content.setProperty(JCR_DATA, "val"); assertEquals(OnParentVersionAction.VERSION, n1.getDefinition().getOnParentVersion()); assertEquals(OnParentVersionAction.COPY, content.getDefinition().getOnParentVersion()); testRootNode.addMixin(MIX_VERSIONABLE); superuser.save(); versionManager = superuser.getWorkspace().getVersionManager(); frozen = versionManager.checkpoint(testRoot).getFrozenNode(); }
public void testChildInSubTree() throws Exception { Node n = testRootNode.addNode(nodeName1).addNode(nodeName2); n.addMixin("OpvAbortTest"); Node child = n.addNode("child", NodeTypeConstants.NT_OAK_UNSTRUCTURED); superuser.save(); assertEquals(OnParentVersionAction.ABORT, child.getDefinition().getOnParentVersion()); try { vMgr.checkpoint(testRootNode.getPath()); fail(); } catch (VersionException e) { // success } finally { superuser.refresh(false); } } }
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); }
public void testDirectChild() throws Exception { testRootNode.addMixin("OpvAbortTest"); Node n = testRootNode.addNode("child", NodeTypeConstants.NT_OAK_UNSTRUCTURED); assertEquals(OnParentVersionAction.ABORT, n.getDefinition().getOnParentVersion()); superuser.save(); try { vMgr.checkpoint(testRootNode.getPath()); fail(); } catch (VersionException e) { // success } finally { superuser.refresh(false); } }
@Override protected void setUp() throws Exception { super.setUp(); Node n1 = testRootNode.addNode(nodeName1, NodeTypeConstants.NT_OAK_UNSTRUCTURED); Node n2 = n1.addNode(nodeName2, NodeTypeConstants.NT_OAK_UNSTRUCTURED); Node n3 = n1.addNode(nodeName3, NodeTypeConstants.NT_OAK_UNSTRUCTURED); siblingName = nodeName1 + 'b'; Node n1b = testRootNode.addNode(siblingName, NodeTypeConstants.NT_OAK_UNSTRUCTURED); assertEquals(OnParentVersionAction.VERSION, n1.getDefinition().getOnParentVersion()); assertEquals(OnParentVersionAction.VERSION, n2.getDefinition().getOnParentVersion()); assertEquals(OnParentVersionAction.VERSION, n3.getDefinition().getOnParentVersion()); assertEquals(OnParentVersionAction.VERSION, n1b.getDefinition().getOnParentVersion()); testRootNode.addMixin(MIX_VERSIONABLE); n1b.addMixin(MIX_VERSIONABLE); n2.addMixin(MIX_VERSIONABLE); superuser.save(); versionManager = superuser.getWorkspace().getVersionManager(); frozen = versionManager.checkpoint(testRoot).getFrozenNode(); }
private int getOPV(NodeBuilder parent, NodeBuilder child, String childName) throws RepositoryException { // ignore hidden tree if (childName.startsWith(":")) { return IGNORE; } ImmutableTree parentTree = new ImmutableTree(parent.getNodeState()); NodeState childState; if (NT_FROZENNODE.equals(child.getName(JCR_PRIMARYTYPE))) { // need to translate into a regular node to get proper OPV value NodeBuilder builder = new MemoryNodeBuilder(EmptyNodeState.EMPTY_NODE); builder.setProperty(JCR_PRIMARYTYPE, child.getName(JCR_FROZENPRIMARYTYPE), Type.NAME); builder.setProperty(JCR_MIXINTYPES, child.getNames(JCR_MIXINTYPES), Type.NAMES); childState = builder.getNodeState(); } else { childState = child.getNodeState(); } ImmutableTree childTree = new ImmutableTree(parentTree, childName, childState); return ntMgr.getDefinition(parentTree, childTree).getOnParentVersion(); }
private int getOPV(NodeBuilder parent, NodeBuilder child, String childName) throws RepositoryException { // ignore hidden tree if (childName.startsWith(":")) { return IGNORE; } ImmutableTree parentTree = new ImmutableTree(parent.getNodeState()); NodeState childState; if (NT_FROZENNODE.equals(child.getName(JCR_PRIMARYTYPE))) { // need to translate into a regular node to get proper OPV value NodeBuilder builder = new MemoryNodeBuilder(EmptyNodeState.EMPTY_NODE); builder.setProperty(JCR_PRIMARYTYPE, child.getName(JCR_FROZENPRIMARYTYPE), Type.NAME); builder.setProperty(JCR_MIXINTYPES, child.getNames(JCR_MIXINTYPES), Type.NAMES); childState = builder.getNodeState(); } else { childState = child.getNodeState(); } ImmutableTree childTree = new ImmutableTree(parentTree, childName, childState); return ntMgr.getDefinition(parentTree, childTree).getOnParentVersion(); }
private void addIgnoredChild(@NotNull Node node) throws Exception { AccessControlManager acMgr = superuser.getAccessControlManager(); JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, node.getPath()); acl.addAccessControlEntry(EveryonePrincipal.getInstance(), AccessControlUtils.privilegesFromNames(acMgr, Privilege.JCR_READ)); acMgr.setPolicy(acl.getPath(), acl); superuser.save(); Node c = node.getNode(AccessControlConstants.REP_POLICY); assertEquals(OnParentVersionAction.IGNORE, c.getDefinition().getOnParentVersion()); }
private int getOPV(NodeBuilder parent, NodeBuilder child, String childName) throws RepositoryException { // ignore hidden tree if (childName.startsWith(":")) { return IGNORE; } ImmutableTree parentTree = new ImmutableTree(parent.getNodeState()); NodeState childState; if (NT_FROZENNODE.equals(child.getName(JCR_PRIMARYTYPE))) { // need to translate into a regular node to get proper OPV value NodeBuilder builder = new MemoryNodeBuilder(EmptyNodeState.EMPTY_NODE); builder.setProperty(JCR_PRIMARYTYPE, child.getName(JCR_FROZENPRIMARYTYPE), Type.NAME); builder.setProperty(JCR_MIXINTYPES, child.getNames(JCR_MIXINTYPES), Type.NAMES); childState = builder.getNodeState(); } else { childState = child.getNodeState(); } ImmutableTree childTree = new ImmutableTree(parentTree, childName, childState); return ntMgr.getDefinition(parentTree, childTree).getOnParentVersion(); }
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)); } }
@Override public boolean isCheckedOut() throws RepositoryException { AbstractJcrNode node = this; SessionCache cache = sessionCache(); ValueFactory<Boolean> booleanFactory = session.context().getValueFactories().getBooleanFactory(); while (node != null) { // If the node has an OPV of 'ignore' ... NodeDefinition defn = node.getDefinition(); if (defn.getOnParentVersion() == OnParentVersionAction.IGNORE) { // This node is not or cannot be checked in ... return true; } if (node.isNodeType(JcrMixLexicon.VERSIONABLE)) { Property prop = node.node().getProperty(JcrLexicon.IS_CHECKED_OUT, cache); // This prop can only be null if the node has not been saved since it was made versionable. return prop == null || booleanFactory.create(prop.getFirstValue()); } if (node.isRoot()) break; node = node.getParent(); } return true; }
/** * 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()); }