@Override protected Request createRequest() { return new CopyBranchRequest(validPathLocation1, workspace1, validPathLocation2, workspace2); }
/** * {@inheritDoc} * * @see java.lang.Object#toString() */ @Override public String toString() { if (fromWorkspace.equals(intoWorkspace)) { if (desiredNameForCopy != null) { return "copy " + printable(from()) + " (in '" + fromWorkspace + "' workspace) into " + printable(into()) + "' with name '" + desiredNameForCopy + "'"; } return "copy " + printable(from()) + " (in '" + fromWorkspace + "' workspace) into " + printable(into()); } if (desiredNameForCopy != null) { return "copy " + printable(from()) + " (in '" + fromWorkspace + "' workspace) into " + printable(into()) + " with name '" + desiredNameForCopy + "' (in '" + intoWorkspace + "' workspace)"; } return "copy " + printable(from()) + " (in '" + fromWorkspace + "' workspace) into " + printable(into()) + " (in '" + intoWorkspace + "' workspace)"; }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.ChangeRequest#changedWorkspace() */ @Override public String changedWorkspace() { return intoWorkspace(); }
/** * {@inheritDoc} * <p> * This method does not clone the results. * </p> * * @see org.modeshape.graph.request.ChangeRequest#clone() */ @Override public CopyBranchRequest clone() { CopyBranchRequest result = new CopyBranchRequest(actualFromLocation != null ? actualFromLocation : from, fromWorkspace, actualIntoLocation != null ? actualIntoLocation : into, intoWorkspace, desiredNameForCopy, nodeConflictBehavior); result.setActualLocations(actualFromLocation, actualIntoLocation); return result; }
/** * {@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)) { CopyBranchRequest that = (CopyBranchRequest)obj; if (!this.from().isSame(that.from())) return false; if (!this.into().isSame(that.into())) return false; if (!this.nodeConflictBehavior().equals(that.nodeConflictBehavior())) return false; if (!this.fromWorkspace.equals(that.fromWorkspace)) return false; if (!this.intoWorkspace.equals(that.intoWorkspace)) return false; return true; } return false; }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.CopyBranchRequest) */ @Override public void process( CopyBranchRequest request ) { 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; // Look up the new parent, which must exist ... Path newParentPath = request.into().getPath(); Name desiredName = request.desiredName(); NodeType newParent = getTargetNode(newWorkspace, request, request.into()); if (newParent == null) return; NodeType newNode = txn.copyNode(workspace, node, newWorkspace, newParent, desiredName, true); 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); recordChange(request); }
public void process( CopyBranchRequest 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.copyLimitedToBeWithinSingleSource.text(readable(request.from()), request.fromWorkspace(), readable(request.into()), request.intoWorkspace(), getSourceName()); request.setError(new UnsupportedRequestException(msg)); return; CopyBranchRequest pushDown = new CopyBranchRequest(fromProxy.location(), fromProxy.workspaceName(), intoProxy.location(), intoProxy.workspaceName(), request.desiredName(), request.nodeConflictBehavior());
@Test public void shouldCreateValidRequestWithValidFromLocationAndValidToLocation() { request = new CopyBranchRequest(validPathLocation1, workspace1, validPathLocation2, workspace2); assertThat(request.from(), is(sameInstance(validPathLocation1))); assertThat(request.into(), is(sameInstance(validPathLocation2))); assertThat(request.fromWorkspace(), is(sameInstance(workspace1))); assertThat(request.intoWorkspace(), is(sameInstance(workspace2))); assertThat(request.hasError(), is(false)); assertThat(request.getError(), is(nullValue())); }
@Override public void process( CopyBranchRequest request ) { // Create a child under the new parent ... if (request.into().hasPath()) { Name childName = request.desiredName(); if (childName == null) childName = createName("child"); 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 org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.CopyBranchRequest) */ @Override public void process( CopyBranchRequest request ) { ProjectedRequest projected = federatedRequest.getFirstProjectedRequest(); // Check the projection first ... if (checkErrorOrCancel(request, federatedRequest)) return; CopyBranchRequest source = (CopyBranchRequest)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); }
protected void assertNextRequestIsCopy( String fromWorkspace, Location from, Location to ) { Request request = executedRequests.poll(); assertThat(request, is(instanceOf(CopyBranchRequest.class))); CopyBranchRequest copy = (CopyBranchRequest)request; assertThat(copy.fromWorkspace(), is(fromWorkspace)); assertThat(copy.from(), is(from)); assertThat(copy.into(), is(to)); }
@Test public void shouldConsiderNotEqualTwoRequestsWithDifferentFromWorkspaceName() { request = new CopyBranchRequest(validPathLocation1, workspace1 + "a", validPathLocation2, workspace2); CopyBranchRequest request2 = new CopyBranchRequest(validPathLocation1, workspace1, validPathLocation2, workspace2); assertThat(request.equals(request2), is(false)); }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.CopyBranchRequest) */ @Override public void process( CopyBranchRequest request ) { CopyBranchRequest source = (CopyBranchRequest)federatedRequest.getFirstProjectedRequest().getRequest(); if (checkErrorOrCancel(request, source)) return; request.setActualLocations(source.getActualLocationBefore(), source.getActualLocationAfter()); }
@Test public void shouldConsiderRequestsToNotBeInSameWorkspaceIfFromAndToWorkspaceNamesDoNotMatch() { request = new CopyBranchRequest(validPathLocation1, workspace1, validPathLocation2, workspace2); assertThat(request.isSameWorkspace(), is(false)); }
/** * Sets the actual and complete location of the node being renamed and its new location. This method must be called when * processing the request, and the actual location must have a {@link Location#getPath() path}. * * @param fromLocation the actual location of the node being copied * @param intoLocation the actual location of the new copy of the node * @throws IllegalArgumentException if the either location is null; or if the either location does not have a path * @throws IllegalStateException if the request is frozen */ public void setActualLocations( Location fromLocation, Location intoLocation ) { checkNotFrozen(); CheckArg.isNotNull(fromLocation, "intoLocation"); CheckArg.isNotNull(intoLocation, "intoLocation"); if (!fromLocation.hasPath()) { throw new IllegalArgumentException(GraphI18n.actualOldLocationMustHavePath.text(fromLocation)); } if (!intoLocation.hasPath()) { throw new IllegalArgumentException(GraphI18n.actualNewLocationMustHavePath.text(intoLocation)); } this.actualFromLocation = fromLocation; this.actualIntoLocation = intoLocation; }
Location locationOfCopy = request.getActualLocationAfter();
/** * {@inheritDoc} * * @see org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.CopyBranchRequest) */ @Override public void process( CopyBranchRequest request ) { 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; // Look up the new parent, which must exist ... Path newParentPath = request.into().getPath(); Name desiredName = request.desiredName(); MapNode newParent = newWorkspace.getNode(newParentPath); MapNode newNode = workspace.copyNode(getExecutionContext(), node, newWorkspace, newParent, desiredName, true); 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); recordChange(request); }
@Test public void shouldConsiderNotEqualTwoRequestsWithDifferentLocations() { request = new CopyBranchRequest(validPathLocation1, workspace1, validPathLocation2, workspace2); CopyBranchRequest request2 = new CopyBranchRequest(validPathLocation2, workspace1, validPathLocation1, workspace2); assertThat(request.equals(request2), is(false)); }
@Test public void shouldConsiderRequestsToBeInSameWorkspaceIfFromAndToWorkspaceNamesMatch() { request = new CopyBranchRequest(validPathLocation1, workspace1, validPathLocation2, new String(workspace1)); assertThat(request.isSameWorkspace(), is(true)); }
@Override public void process( CopyBranchRequest 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(); Name desiredName = request.desiredName(); PathNode newParent = newWorkspace.getNode(newParentPath); 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); recordChange(request); }