protected AbstractJcrNode addAclNode( String relPath, String primaryNodeTypeName ) throws ItemExistsException, PathNotFoundException, NoSuchNodeTypeException, LockException, VersionException, ConstraintViolationException, RepositoryException { checkSession(); return addNode(relPath, primaryNodeTypeName, null, true); }
/** * Get the absolute and normalized identifier path for this node, regardless of whether this node is referenceable. * * @return the node's identifier path; never null * @throws RepositoryException if there is an error accessing the identifier of this node */ final String identifierPath() throws RepositoryException { return "[" + getIdentifier() + "]"; }
Set<AbstractJcrNode> sourceNodesPresentInBoth = new LinkedHashSet<AbstractJcrNode>(); for (NodeIterator iter = targetNode.getNodesInternal(); iter.hasNext();) { AbstractJcrNode targetChild = (AbstractJcrNode)iter.nextNode(); try { Path srcPath = targetChild.correspondingNodePath(sourceWorkspaceName); AbstractJcrNode sourceChild = sourceSession.node(srcPath); targetNodesPresentInBoth.add(targetChild); for (NodeIterator iter = sourceNode.getNodesInternal(); iter.hasNext();) { AbstractJcrNode sourceChild = (AbstractJcrNode)iter.nextNode(); if (!sourceNodesPresentInBoth.contains(sourceChild)) { node.internalRemove(true); node.getPath(), targetNode.getPath() + "/" + node.getName(), false, true); if (isShallow && node.isNodeType(JcrMixLexicon.VERSIONABLE)) continue; doMerge(node);
@Override public boolean hasNodes() throws RepositoryException { checkSession(); // this should check permissions via the resolver return getNodes().hasNext(); }
@Override public NodeIterator getNodes( String namePattern ) throws RepositoryException { CheckArg.isNotNull(namePattern, "namePattern"); checkSession(); if (namePattern.length() == 0) return JcrEmptyNodeIterator.INSTANCE; if ("*".equals(namePattern)) return getNodes(); return getNodes(patternStringToGlobArray(namePattern)); }
checkSession(); checkForLock(); checkForCheckedOut(); session.checkPermission(this, ModeShapePermissions.SET_PROPERTY); if (getDefinition().isProtected()) { throw new ConstraintViolationException(JcrI18n.cannotRemoveFromProtectedNode.text(getPath())); Name removedMixinName = nameFrom(mixinName); if (!isNodeType(mixinName)) { throw new NoSuchNodeTypeException(JcrI18n.invalidMixinTypeForNode.text(mixinName, location())); if (JcrMixLexicon.SHAREABLE.equals(removedMixinName) && isShareable()) { NodeIterator shared = getSharedSet(); long numShared = shared.getSize(); if (numShared > 1L) { String msg = JcrI18n.cannotRemoveShareableMixinThatIsShared.text(location(), numShared, paths); throw new ConstraintViolationException(msg); Lock lock = getLockIfExists(); if (lock != null) { unlock(); SessionCache cache = sessionCache(); CachedNode cachedNode = node(); Name primaryTypeName = cachedNode.getPrimaryType(cache);
onParentVersion = OnParentVersionAction.COPY; } else { onParentVersion = node.getDefinition().getOnParentVersion(); case OnParentVersionAction.ABORT: throw new VersionException(JcrI18n.cannotCheckinNodeWithAbortChildNode.text(nodeName, node.getParent().getName())); case OnParentVersionAction.VERSION: if (node.isNodeType(JcrMixLexicon.VERSIONABLE)) { JcrVersionHistoryNode history = node.getVersionHistory(); org.modeshape.jcr.value.Property primaryType = propertyFactory().create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.VERSIONED_CHILD); if (node.isShared()) { props.add(factory.create(JcrLexicon.FROZEN_UUID, node.getIdentifier())); props.add(factory.create(JcrLexicon.UUID, key)); parentInVersionHistory.createChild(versionHistoryCache, key, nodeName, props); Name primaryTypeName = node.getPrimaryTypeName(); Set<Name> mixinTypeNames = node.getMixinTypeNames(); props.add(factory.create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.FROZEN_NODE)); props.add(factory.create(JcrLexicon.FROZEN_PRIMARY_TYPE, primaryTypeName)); props.add(factory.create(JcrLexicon.FROZEN_MIXIN_TYPES, mixinTypeNames)); props.add(factory.create(JcrLexicon.FROZEN_UUID, node.getIdentifier())); props.add(factory.create(JcrLexicon.UUID, key)); addVersionedPropertiesFor(node, forceCopy, props);
if (work.getSelectedPath().equals(work.getOutputPath())) { outputNode = selectedNode.getName().equals(JcrConstants.JCR_CONTENT) ? selectedNode.getParent() : selectedNode; primaryType = selectedNode.getPrimaryNodeType().getName(); } else { if (parentOfOutput.isNew() && parentOfOutput.getName().equals(outputNodeName)) { if (TRACE) { LOGGER.trace("Creating output node '{0}' under parent '{1}' for {2}", outputNodeName, parentOfOutput.getPath(), logMsg); outputNode = parentOfOutput.addNode(outputNodeName, JcrConstants.NT_UNSTRUCTURED); outputNode.addMixin(DERIVED_NODE_TYPE_NAME); outputNode.setProperty(DERIVED_FROM_PROPERTY_NAME, work.getSelectedPath()); if (selectedNode == outputNode && !selectedNode.getPrimaryNodeType().getName().equals(primaryType)) { String msg = RepositoryI18n.sequencersMayNotChangeThePrimaryTypeOfTheSelectedNode.text(); throw new RepositoryException(msg); payload.put("sequencerName", sequencer.getClass().getName()); payload.put("sequencedPath", changedProperty.getPath()); payload.put("outputPath", outputNode.getPath()); stats.recordDuration(DurationMetric.SEQUENCER_EXECUTION_TIME, durationInNanos, TimeUnit.NANOSECONDS, payload);
NodeTypes nodeTypes = session().nodeTypes(); if (defn == null || nodeTypes.getVersion() > defn.nodeTypesVersion) { assert !this.isRoot(); CachedNode parent = getParent().node(); SessionCache cache = sessionCache(); Name nodeName = name(); Name primaryType = node().getPrimaryType(cache); Name parentPrimaryType = parent.getPrimaryType(cache); Set<Name> parentMixins = parent.getMixinTypes(cache); siblingCounter); if (childDefn == null) { throw new ConstraintViolationException(JcrI18n.noChildNodeDefinition.text(nodeName, getParent().location(), readable(parentPrimaryType), readable(parentMixins))); setNodeDefinitionId(id, nodeTypes.getVersion()); return id;
private void fireSequencingEvent( AbstractJcrNode sequencedNode, List<AbstractJcrNode> outputNodes, JcrSession outputSession, String sequencerName ) throws RepositoryException { final ExecutionContext context = outputSession.context(); RecordingChanges sequencingChanges = new RecordingChanges(outputSession.sessionId(), context.getProcessId(), outputSession.getRepository().repositoryKey(), outputSession.workspaceName(), outputSession.getRepository() .journalId()); Name primaryType = sequencedNode.getPrimaryTypeName(); Set<Name> mixinTypes = sequencedNode.getMixinTypeNames(); for (AbstractJcrNode outputNode : outputNodes) { sequencingChanges.nodeSequenced(sequencedNode.key(), sequencedNode.path(), primaryType, mixinTypes, outputNode.key(), outputNode.path(), work.getOutputPath(), work.getUserId(), work.getSelectedPath(), sequencerName); } sequencingChanges.freeze(outputSession.getUserID(), null, context.getValueFactories().getDateFactory().create()); repository.changeBus().notify(sequencingChanges); }
@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; }
protected final Path correspondingNodePath( String workspaceName ) throws NoSuchWorkspaceException, ItemNotFoundException, RepositoryException { assert workspaceName != null; NamespaceRegistry namespaces = this.context().getNamespaceRegistry(); // Find the closest ancestor (including this node) that is referenceable ... AbstractJcrNode referenceableRoot = this; while (!referenceableRoot.isNodeType(JcrMixLexicon.REFERENCEABLE.getString(namespaces))) { referenceableRoot = referenceableRoot.getParent(); } // Find the relative path from the nearest referenceable node to this node (or null if this node is referenceable) ... Path relativePath = path().equals(referenceableRoot.path()) ? null : path().relativeTo(referenceableRoot.path()); NodeKey key = referenceableRoot.key(); // if the we're looking for a system node, we need to use the system ws name, which is repository-wide String systemWsKey = session.getRepository().systemWorkspaceKey(); String workspaceKey = systemWsKey.equals(key.getWorkspaceKey()) ? systemWsKey : NodeKey.keyForWorkspaceName(workspaceName); NodeKey nodeKey = new NodeKey(key.getSourceKey(), workspaceKey, key.getIdentifier()); return session.getPathForCorrespondingNode(workspaceName, nodeKey, relativePath); }
/** * Get the property definition ID. * * @return the cached property definition ID; never null * @throws ItemNotFoundException if the node that contains this property doesn't exist anymore * @throws ConstraintViolationException if no valid property definition could be found * @throws InvalidItemStateException if the node has been removed in this session's transient state */ final PropertyDefinitionId propertyDefinitionId() throws ItemNotFoundException, ConstraintViolationException, InvalidItemStateException { CachedDefinition defn = cachedDefn; NodeTypes nodeTypes = session.nodeTypes(); if (defn == null || nodeTypes.getVersion() > defn.nodeTypesVersion) { Name primaryType = node.getPrimaryTypeName(); Set<Name> mixinTypes = node.getMixinTypeNames(); PropertyDefinitionId id = node.propertyDefinitionFor(property(), primaryType, mixinTypes, nodeTypes).getId(); setPropertyDefinitionId(id, nodeTypes.getVersion()); return id; } return defn.propDefnId; }
@Override public void restore( Version version, boolean removeExisting ) throws VersionException, ItemExistsException, InvalidItemStateException, UnsupportedRepositoryOperationException, LockException, RepositoryException { try { checkNotProtected(); } catch (ConstraintViolationException cve) { throw new UnsupportedRepositoryOperationException(cve); } versionManager().restoreAtAbsPath(getPath(), version, removeExisting, false); }
@Override public void removeSharedSet() throws VersionException, LockException, ConstraintViolationException, RepositoryException { if (isShareable()) { SharedSet sharedSet = sharedSet(); if (sharedSet.getSize() != 1) { AbstractJcrNode parent = nodeInSharedSet.getParent(); parent.checkForLock(); session.checkPermission(nodeInSharedSet, ModeShapePermissions.REMOVE); nodeInSharedSet.doRemove(); doRemove();
String primaryNodeTypeName ) throws RepositoryException { CheckArg.isNotEmpty(relPath, relPath); checkSession(); path = session().pathFactory().create(relPath); } catch (org.modeshape.jcr.value.ValueFormatException e) { return false; try { AbstractJcrNode other = session.node(node(), parentPath); return other.canAddNode(primaryNodeTypeName); } catch (RepositoryException e) { return false; return this.canAddNode(primaryNodeTypeName);
@Override public void createProjection( String absNodePath, String sourceName, String externalPath, String alias ) throws RepositoryException { AbstractJcrNode node = session.getNode(absNodePath); if (session.nodeTypeManager().nodeTypes().isUnorderedCollection(node.getPrimaryTypeName(), node.getMixinTypeNames())) { throw new ConstraintViolationException(JcrI18n.operationNotSupportedForUnorderedCollections.text("create projection")); } NodeKey parentNodeToBecomeFederatedKey = node.key(); String projectionAlias = !StringUtil.isBlank(alias) ? alias : externalPath; if (projectionAlias.endsWith("/")) { projectionAlias = projectionAlias.substring(0, projectionAlias.length() - 1); } if (projectionAlias.contains("/")) { projectionAlias = projectionAlias.substring(projectionAlias.lastIndexOf("/") + 1); } if (StringUtil.isBlank(projectionAlias)) { // we cannot create an external projection without a valid alias return; } SessionCache sessionCache = this.session.spawnSessionCache(false); SessionCache systemSession = session.repository.createSystemSession(session.context(), false); String externalNodeKey = documentStore.createExternalProjection(parentNodeToBecomeFederatedKey.toString(), sourceName, externalPath, projectionAlias, systemSession); MutableCachedNode mutable = sessionCache.mutable(parentNodeToBecomeFederatedKey); mutable.addFederatedSegment(externalNodeKey, projectionAlias); systemSession.save(sessionCache, null); }
@Test public void shouldReturnFalseFromIsSameIfTheWorkspaceNameIsDifferent() throws Exception { // Use the same id and location; use 'Toyota Prius' String priusUuid2 = prius2.getIdentifier(); String priusUuid = prius.getIdentifier(); assertThat(priusUuid, is(priusUuid2)); assertThat(prius2.isSame(prius), is(false)); // Check the properties ... javax.jcr.Property model = prius.getProperty("car:model"); javax.jcr.Property model2 = prius2.getProperty("car:model"); assertThat(model.isSame(model2), is(false)); }
@Test @FixFor( "MODE-2424" ) public void shouldAllowAddingMixinOnLockedNodeForLockOwner() throws Exception { final AbstractJcrNode testNode = session.getRootNode().addNode("test"); final String path = testNode.getPath(); testNode.addMixin("mix:lockable"); session.save(); session.getWorkspace().getLockManager().lock(path, false, true, Long.MAX_VALUE, session.getUserID()); testNode.addMixin("mix:created"); session.save(); }
/** * @param version the version for which the frozen node should be returned * @return the frozen node for the given version * @throws RepositoryException if an error occurs accessing the repository */ AbstractJcrNode frozenNodeFor( Version version ) throws RepositoryException { return ((AbstractJcrNode)version).getNode(JcrLexicon.FROZEN_NODE); }