/** * {@inheritDoc} * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("read ").append(printable(from())).append(" (in "); if (inWorkspace() != null) { sb.append('\'').append(inWorkspace()).append('\''); } else { sb.append("default"); } sb.append(" workspace) "); if (desiredName() != null) { sb.append("with name '").append(desiredName()).append("' "); } else { sb.append("into "); } if (into() != null) { sb.append("into ").append(printable(into())); } else { sb.append("before ").append(printable(before())); } return sb.toString(); }
/** * {@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)) { MoveBranchRequest that = (MoveBranchRequest)obj; if (!this.from().isSame(that.from())) return false; if (!this.into().isSame(that.into())) return false; if (!this.conflictBehavior().equals(that.conflictBehavior())) return false; if (!this.workspaceName.equals(that.workspaceName)) return false; return true; } return false; }
protected void assertNextRequestIsMove( Location from, Location to ) { Request request = executedRequests.poll(); assertThat(request, is(instanceOf(MoveBranchRequest.class))); MoveBranchRequest move = (MoveBranchRequest)request; assertThat(move.from(), is(from)); assertThat(move.into(), is(to)); }
@Test public void shouldCreateValidRequestWithValidFromLocationAndValidToLocation() { request = new MoveBranchRequest(validPathLocation1, validPathLocation2, workspace1); assertThat(request.from(), is(sameInstance(validPathLocation1))); assertThat(request.into(), is(sameInstance(validPathLocation2))); assertThat(request.inWorkspace(), is(sameInstance(workspace1))); assertThat(request.hasError(), is(false)); assertThat(request.getError(), is(nullValue())); }
@Test public void shouldCreateValidRequestWithValidFromLocationAndValidToLocationAndValidBeforeLocation() { Name newName = new BasicName("", "newName"); request = new MoveBranchRequest(validPathLocation1, validPathLocation2, validPathLocation, workspace1, newName, NodeConflictBehavior.DO_NOT_REPLACE); assertThat(request.from(), is(sameInstance(validPathLocation1))); assertThat(request.into(), is(sameInstance(validPathLocation2))); assertThat(request.before(), is(sameInstance(validPathLocation))); assertThat(request.inWorkspace(), is(sameInstance(workspace1))); assertThat(request.hasError(), is(false)); assertThat(request.getError(), is(nullValue())); }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.MoveBranchRequest) */ @Override public void process( MoveBranchRequest request ) { ProjectedRequest projected = federatedRequest.getFirstProjectedRequest(); // Check the projection first ... if (checkErrorOrCancel(request, federatedRequest)) return; MoveBranchRequest source = (MoveBranchRequest)projected.getRequest(); if (checkErrorOrCancel(request, source)) return; Location locationBefore = source.getActualLocationBefore(); Location locationAfter = source.getActualLocationAfter(); locationBefore = projectToFederated(request.from(), projected.getProjection(), locationBefore, request); Projection afterProjection = projected.getSecondProjection(); if (afterProjection == null) projected.getProjection(); locationAfter = projectToFederated(request.into(), afterProjection, locationAfter, request); request.setActualLocations(locationBefore, locationAfter); }
MapNode node = getTargetNode(workspace, request, request.from()); if (node == null) return; if (request.hasError()) return; // if beforeNode could not be found assert node.getParent().equals(newParent); Path newPath = getExecutionContext().getValueFactories().getPathFactory().create(newParentPath, node.getName()); Location oldLocation = getActualLocation(request.from(), node); Location newLocation = Location.create(newPath, node.getUuid()); request.setActualLocations(oldLocation, newLocation);
@Override public void process( MoveBranchRequest request ) { // Just update the actual location ... Name newName = request.desiredName(); if (newName == null && request.from().hasPath()) newName = request.from().getPath().getLastSegment().getName(); if (newName == null) newName = context.getValueFactories().getNameFactory().create("d"); // Figure out the new name and path (if needed)... Path newPath = null; if (request.into().hasPath()) { newPath = context.getValueFactories().getPathFactory().create(request.into().getPath(), newName); } else if (request.from().hasPath()) { newPath = context.getValueFactories().getPathFactory().create("/a/b/c"); newPath = context.getValueFactories().getPathFactory().create(newPath, newName); } else { newPath = context.getValueFactories().getPathFactory().create("/a/b/c"); newPath = context.getValueFactories().getPathFactory().create(newPath, newName); } // Figure out the old name and path ... Path oldPath = null; if (request.from().hasPath()) { oldPath = request.from().getPath(); } else { oldPath = context.getValueFactories().getPathFactory().create("/x/y/z"); oldPath = context.getValueFactories().getPathFactory().create(oldPath, newName); } Location fromLocation = request.from().hasIdProperties() ? Location.create(oldPath, request.from().getIdProperties()) : Location.create(oldPath); Location intoLocation = request.into().hasIdProperties() ? Location.create(newPath, request.into().getIdProperties()) : Location.create(newPath); request.setActualLocations(fromLocation, intoLocation); }
PathNode node = getTargetNode(workspace, request, request.from()); if (node == null) return; if (request.hasError()) return; // if beforeNode could not be found assert node.getPath().getParent().equals(newParent.getPath()); Location oldLocation = Location.create(request.from().getPath()); Location newLocation = Location.create(node.getPath(), node.getUuid()); request.setActualLocations(oldLocation, newLocation);
public void process( MoveBranchRequest request ) { ProjectedNode projectedFromNode = project(request.from(), request.inWorkspace(), request, true); if (projectedFromNode == null) { submit(new FederatedRequest(request)); String msg = GraphI18n.moveLimitedToBeWithinSingleSource.text(readable(request.from()), request.inWorkspace(), readable(request.into()),