/** * {@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)); }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.ChangeRequest#changes(java.lang.String, org.modeshape.graph.property.Path) */ @Override public boolean changes( String workspace, Path path ) { if (this.into() != null) { return this.workspaceName.equals(workspace) && (into.hasPath() && into.getPath().isAtOrBelow(path) || from.hasPath() && from.getPath().isAtOrBelow(path)); } // into or before must be non-null assert before() != null; return this.workspaceName.equals(workspace) && (before.hasPath() && before.getPath().getParent().isAtOrBelow(path) || from.hasPath() && from.getPath().isAtOrBelow(path)); }
@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())); }
if (request.into() != null) { newParent = txn.getNode(workspace, request.into()); // this will fail if there is no node newLocation = txn.addChild(workspace, newParent, node, null, request.desiredName()); } else { if (newParent == null) { request.setError(new PathNotFoundException(request.into(), pathFactory.createRootPath(), GraphI18n.nodeDoesNotExist.text("parent of root"))); return;
if (request.into() != null) { newParentPath = request.into().getPath(); } else { if (newParent == null) { Path lowestExisting = workspace.getLowestExistingPath(newParentPath); request.setError(new PathNotFoundException(request.into(), lowestExisting, GraphI18n.nodeDoesNotExist.text(newParentPath))); return;
/** * {@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); }
if (request.into() != null) { newParentPath = request.into().getPath(); } else { if (newParent == null) { Path lowestExisting = workspace.getLowestExistingPath(newParentPath); request.setError(new PathNotFoundException(request.into(), lowestExisting, GraphI18n.nodeDoesNotExist.text(newParentPath))); return;
@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); }