/** * {@inheritDoc} * * @see java.lang.Object#toString() */ @Override public String toString() { if (desiredName != null) { return "clone " + printable(from()) + " (in '" + fromWorkspace + "' workspace) into " + printable(into()) + " with name '" + desiredName + "' (in '" + intoWorkspace + "' workspace)"; } return "clone " + printable(from()) + " (in '" + fromWorkspace + "' workspace) into " + printable(into()) + " (in '" + intoWorkspace + "' workspace) as child '" + desiredSegment() + "'"; }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.CloneBranchRequest) */ @Override public void process( CloneBranchRequest request ) { CloneBranchRequest source = (CloneBranchRequest)federatedRequest.getFirstProjectedRequest().getRequest(); if (checkErrorOrCancel(request, source)) return; request.setActualLocations(source.getActualLocationBefore(), source.getActualLocationAfter()); request.setRemovedNodes(source.getRemovedNodes()); }
/** * {@inheritDoc} * <p> * This method does not clone the results. * </p> * * @see org.modeshape.graph.request.ChangeRequest#clone() */ @Override public CloneBranchRequest clone() { CloneBranchRequest result = new CloneBranchRequest(actualFromLocation != null ? actualFromLocation : from, fromWorkspace, actualIntoLocation != null ? actualIntoLocation : into, intoWorkspace, desiredName, desiredSegment, removeExisting); result.setRemovedNodes(removedExistingNodes); result.setActualLocations(actualFromLocation, actualIntoLocation); return result; }
if (!updatesAllowed(request)) return; WorkspaceType workspace = getWorkspace(request, request.fromWorkspace()); WorkspaceType newWorkspace = getWorkspace(request, request.intoWorkspace()); if (workspace == null || newWorkspace == null) return; NodeType node = getTargetNode(workspace, request, request.from()); if (node == null) return; Path newParentPath = request.into().getPath(); NodeType newParent = txn.getNode(newWorkspace, request.into()); Set<Location> removedExistingNodes = new HashSet<Location>(); NodeType newNode = txn.cloneNode(workspace, newWorkspace, newParent, request.desiredName(), request.desiredSegment(), request.removeExisting(), removedExistingNodes); Path newPath = getExecutionContext().getValueFactories().getPathFactory().create(newParentPath, newNode.getName()); Location oldLocation = getActualLocation(workspace, request.from(), node); Location newLocation = Location.create(newPath, newNode.getUuid()); request.setActualLocations(oldLocation, newLocation); request.setRemovedNodes(Collections.unmodifiableSet(removedExistingNodes)); recordChange(request);
public void process( CloneBranchRequest request ) { ProjectedNode projectedFromNode = project(request.from(), request.fromWorkspace(), request, false); if (projectedFromNode == null) { submit(new FederatedRequest(request)); return; ProjectedNode projectedIntoNode = project(request.into(), request.intoWorkspace(), request, true); if (projectedIntoNode == null) { submit(new FederatedRequest(request)); String msg = GraphI18n.cloneLimitedToBeWithinSingleSource.text(readable(request.from()), request.fromWorkspace(), readable(request.into()), request.intoWorkspace(), getSourceName()); request.setError(new UnsupportedRequestException(msg)); return; CloneBranchRequest pushDown = new CloneBranchRequest(fromProxy.location(), fromProxy.workspaceName(), intoProxy.location(), intoProxy.workspaceName(), request.desiredName(), request.desiredSegment(), request.removeExisting());
@Override public void process( CloneBranchRequest request ) { if (!updatesAllowed(request)) return; PathWorkspace workspace = getWorkspace(request, request.fromWorkspace()); PathWorkspace intoWorkspace = getWorkspace(request, request.intoWorkspace()); if (workspace == null || intoWorkspace == null) return; PathNode node = getTargetNode(workspace, request, request.from()); if (node == null) return; if (!(intoWorkspace instanceof WritablePathWorkspace)) { I18n msg = GraphI18n.workspaceIsReadOnly; request.setError(new InvalidRequestException(msg.text(repository.getSourceName(), intoWorkspace.getName()))); return; } WritablePathWorkspace newWorkspace = (WritablePathWorkspace)intoWorkspace; // Look up the new parent, which must exist ... Path newParentPath = request.into().getPath(); PathNode newParent = newWorkspace.getNode(newParentPath); Set<Location> removedExistingNodes = new HashSet<Location>(); Name desiredName = request.desiredName(); PathNode newNode = newWorkspace.copyNode(getExecutionContext(), node, workspace, newParent, desiredName, true); Location oldLocation = Location.create(node.getPath(), node.getUuid()); Location newLocation = Location.create(newNode.getPath(), newNode.getUuid()); request.setActualLocations(oldLocation, newLocation); request.setRemovedNodes(Collections.unmodifiableSet(removedExistingNodes)); recordChange(request); }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.CloneBranchRequest) */ @Override public void process( CloneBranchRequest request ) { ProjectedRequest projected = federatedRequest.getFirstProjectedRequest(); // Check the projection first ... if (checkErrorOrCancel(request, federatedRequest)) return; CloneBranchRequest source = (CloneBranchRequest)projected.getRequest(); if (checkErrorOrCancel(request, source)) return; Location locationBefore = source.getActualLocationBefore(); Location locationAfter = source.getActualLocationBefore(); locationBefore = projectToFederated(request.from(), projected.getProjection(), locationBefore, request); locationAfter = projectToFederated(request.into(), projected.getSecondProjection(), locationAfter, request); request.setActualLocations(locationBefore, locationAfter); if (source.removeExisting()) { Set<Location> removed = new HashSet<Location>(); for (Location location : request.getRemovedNodes()) { removed.add(projectToFederated(projected.getSecondProjection(), location, request)); } request.setRemovedNodes(Collections.unmodifiableSet(removed)); } }
@Override public void process( CloneBranchRequest request ) { // Create a child under the new parent ... if (request.into().hasPath()) { Name childName = request.desiredName(); if (childName == null) childName = request.desiredSegment().getName(); Path childPath = context.getValueFactories().getPathFactory().create(request.into().getPath(), childName); Location newChild = actualLocationOf(Location.create(childPath)); // Just update the actual location request.setActualLocations(actualLocationOf(request.from()), newChild); } else { // Just update the actual location request.setActualLocations(actualLocationOf(request.from()), actualLocationOf(request.into())); } }
/** * {@inheritDoc} * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals( Object obj ) { if (obj == this) return true; if (this.getClass().isInstance(obj)) { CloneBranchRequest that = (CloneBranchRequest)obj; if (!this.from().isSame(that.from())) return false; if (!this.into().isSame(that.into())) return false; if (!this.fromWorkspace.equals(that.fromWorkspace)) return false; if (!this.intoWorkspace.equals(that.intoWorkspace)) return false; return true; } return false; }
Location locationOfCopy = request.getActualLocationAfter(); for (Location removed : request.getRemovedNodes()) { Path path = removed.getPath(); if (isBelow(path, removedAlready)) {
/** * Add a request to clone a branch to another. * * @param from the location of the top node in the existing branch that is to be cloned * @param fromWorkspace the name of the workspace where the <code>from</code> node exists * @param into the location of the existing node into which the clone should be placed * @param intoWorkspace the name of the workspace where the <code>into</code> node is to be cloned * @param nameForClone the desired name for the node that results from the clone, or null if the name of the original should * be used * @param exactSegmentForClone the exact {@link Path.Segment segment} at which the cloned tree should be rooted. * @param removeExisting whether any nodes in the intoWorkspace with the same UUIDs as a node in the source branch should be * removed (if true) or a {@link UuidAlreadyExistsException} should be thrown. * @return this builder for method chaining; never null * @throws IllegalArgumentException if any of the parameters are null except for {@code nameForClone} or * {@code exactSegmentForClone}. Exactly one of {@code nameForClone} and {@code exactSegmentForClone} must be null. */ public BatchRequestBuilder cloneBranch( Location from, String fromWorkspace, Location into, String intoWorkspace, Name nameForClone, Path.Segment exactSegmentForClone, boolean removeExisting ) { return add(new CloneBranchRequest(from, fromWorkspace, into, intoWorkspace, nameForClone, exactSegmentForClone, removeExisting)); }
checkNotFrozen(); CheckArg.isNotNull(fromLocation, "intoLocation"); CheckArg.isNotNull(intoLocation, "intoLocation");
if (!updatesAllowed(request)) return; MapWorkspace workspace = getWorkspace(request, request.fromWorkspace()); MapWorkspace newWorkspace = getWorkspace(request, request.intoWorkspace()); if (workspace == null || newWorkspace == null) return; MapNode node = getTargetNode(workspace, request, request.from()); if (node == null) return; Path newParentPath = request.into().getPath(); MapNode newParent = newWorkspace.getNode(newParentPath); Set<Location> removedExistingNodes = new HashSet<Location>(); newWorkspace, newParent, request.desiredName(), request.desiredSegment(), request.removeExisting(), removedExistingNodes); Path newPath = getExecutionContext().getValueFactories().getPathFactory().create(newParentPath, newNode.getName()); Location oldLocation = getActualLocation(request.from(), node); Location newLocation = Location.create(newPath, newNode.getUuid()); request.setActualLocations(oldLocation, newLocation); request.setRemovedNodes(Collections.unmodifiableSet(removedExistingNodes)); recordChange(request);
/** * Add a request to clone a branch to another. * * @param from the location of the top node in the existing branch that is to be cloned * @param fromWorkspace the name of the workspace where the <code>from</code> node exists * @param into the location of the existing node into which the clone should be placed * @param intoWorkspace the name of the workspace where the <code>into</code> node is to be cloned * @param nameForClone the desired name for the node that results from the clone, or null if the name of the original should * be used * @param exactSegmentForClone the exact {@link Path.Segment segment} at which the cloned tree should be rooted. * @param removeExisting whether any nodes in the intoWorkspace with the same UUIDs as a node in the source branch should be * removed (if true) or a {@link UuidAlreadyExistsException} should be thrown. * @return the request; never null * @throws IllegalArgumentException if any of the parameters are null except for {@code nameForClone} or * {@code exactSegmentForClone}. Exactly one of {@code nameForClone} and {@code exactSegmentForClone} must be null. */ public CloneBranchRequest cloneBranch( Location from, String fromWorkspace, Location into, String intoWorkspace, Name nameForClone, Path.Segment exactSegmentForClone, boolean removeExisting ) { return process(new CloneBranchRequest(from, fromWorkspace, into, intoWorkspace, nameForClone, exactSegmentForClone, removeExisting)); }