/** * Create a request to move a branch from one location into another. * * @param from the location of the top node in the existing branch that is to be moved * @param into the location of the existing node into which the branch should be moved * @param workspaceName the name of the workspace * @return the request; never null * @throws IllegalArgumentException if any of the parameters are null */ public MoveBranchRequest moveBranch( Location from, Location into, String workspaceName ) { return process(new MoveBranchRequest(from, into, workspaceName, MoveBranchRequest.DEFAULT_CONFLICT_BEHAVIOR)); }
/** * Create a request to move a branch from one location into another. * * @param from the location of the top node in the existing branch that is to be moved * @param into the location of the existing node into which the branch should be moved * @param workspaceName the name of the workspace * @return this builder for method chaining; never null * @throws IllegalArgumentException if any of the parameters are null */ public BatchRequestBuilder moveBranch( Location from, Location into, String workspaceName ) { return add(new MoveBranchRequest(from, into, workspaceName, MoveBranchRequest.DEFAULT_CONFLICT_BEHAVIOR)); }
@Override protected Request createRequest() { return new MoveBranchRequest(validPathLocation1, validPathLocation2, workspace2); }
/** * {@inheritDoc} * <p> * This method does not clone the results. * </p> * * @see org.modeshape.graph.request.ChangeRequest#clone() */ @Override public MoveBranchRequest clone() { MoveBranchRequest request = new MoveBranchRequest(actualOldLocation != null ? actualOldLocation : from, into, before, workspaceName, desiredNameForNode, conflictBehavior); request.setActualLocations(actualOldLocation, actualNewLocation); return request; }
/** * Create a request to move a branch from one location into another. * * @param from the location of the top node in the existing branch that is to be moved * @param into the location of the existing node into which the branch should be moved * @param workspaceName the name of the workspace * @param conflictBehavior the expected behavior if an equivalently-named child already exists at the <code>into</code> * location * @return this builder for method chaining; never null * @throws IllegalArgumentException if any of the parameters are null */ public BatchRequestBuilder moveBranch( Location from, Location into, String workspaceName, NodeConflictBehavior conflictBehavior ) { if (conflictBehavior == null) conflictBehavior = MoveBranchRequest.DEFAULT_CONFLICT_BEHAVIOR; return add(new MoveBranchRequest(from, into, workspaceName, conflictBehavior)); }
/** * Create a request to move a branch from one location into another. * * @param from the location of the top node in the existing branch that is to be moved * @param into the location of the existing node into which the branch should be moved * @param workspaceName the name of the workspace * @param newNameForNode the new name for the node being moved, or null if the name of the original should be used * @return the request; never null * @throws IllegalArgumentException if any of the parameters are null */ public MoveBranchRequest moveBranch( Location from, Location into, String workspaceName, Name newNameForNode ) { return process(new MoveBranchRequest(from, into, null, workspaceName, newNameForNode, MoveBranchRequest.DEFAULT_CONFLICT_BEHAVIOR)); }
/** * Create a request to move a branch from one location into another. * * @param from the location of the top node in the existing branch that is to be moved * @param into the location of the existing node into which the branch should be moved * @param workspaceName the name of the workspace * @param newNameForNode the new name for the node being moved, or null if the name of the original should be used * @return this builder for method chaining; never null * @throws IllegalArgumentException if any of the parameters are null */ public BatchRequestBuilder moveBranch( Location from, Location into, String workspaceName, Name newNameForNode ) { return add(new MoveBranchRequest(from, into, null, workspaceName, newNameForNode, MoveBranchRequest.DEFAULT_CONFLICT_BEHAVIOR)); }
/** * Create a request to move a branch from one location into another. * * @param from the location of the top node in the existing branch that is to be moved * @param into the location of the existing node into which the branch should be moved * @param before the location of the node before which the branch should be moved; may be null * @param workspaceName the name of the workspace * @param newNameForNode the new name for the node being moved, or null if the name of the original should be used * @return this builder for method chaining; never null * @throws IllegalArgumentException if any of the parameters are null */ public BatchRequestBuilder moveBranch( Location from, Location into, Location before, String workspaceName, Name newNameForNode ) { return add(new MoveBranchRequest(from, into, before, workspaceName, newNameForNode, MoveBranchRequest.DEFAULT_CONFLICT_BEHAVIOR)); }
/** * Create a request to move a branch from one location into another. * * @param from the location of the top node in the existing branch that is to be moved * @param into the location of the existing node into which the branch should be moved * @param workspaceName the name of the workspace * @param conflictBehavior the expected behavior if an equivalently-named child already exists at the <code>into</code> * location * @return the request; never null * @throws IllegalArgumentException if any of the parameters are null */ public MoveBranchRequest moveBranch( Location from, Location into, String workspaceName, NodeConflictBehavior conflictBehavior ) { if (conflictBehavior == null) conflictBehavior = MoveBranchRequest.DEFAULT_CONFLICT_BEHAVIOR; return process(new MoveBranchRequest(from, into, workspaceName, conflictBehavior)); }
/** * Create a request to move a branch from one location into another. * * @param from the location of the top node in the existing branch that is to be moved * @param into the location of the existing node into which the branch should be moved * @param workspaceName the name of the workspace * @param newNameForNode the new name for the node being moved, or null if the name of the original should be used * @param conflictBehavior the expected behavior if an equivalently-named child already exists at the <code>into</code> * location * @return the request; never null * @throws IllegalArgumentException if any of the parameters are null */ public MoveBranchRequest moveBranch( Location from, Location into, String workspaceName, Name newNameForNode, NodeConflictBehavior conflictBehavior ) { if (conflictBehavior == null) conflictBehavior = MoveBranchRequest.DEFAULT_CONFLICT_BEHAVIOR; return process(new MoveBranchRequest(from, into, null, workspaceName, newNameForNode, conflictBehavior)); }
/** * Create a request to move a branch from one location into another before the given child node of the new location. * * @param from the location of the top node in the existing branch that is to be moved * @param into the location of the existing node into which the branch should be moved * @param before the location of the node before which the branch should be moved; may be null * @param workspaceName the name of the workspace * @param newNameForNode the new name for the node being moved, or null if the name of the original should be used * @return the request; never null * @throws IllegalArgumentException if any of the parameters are null */ public MoveBranchRequest moveBranch( Location from, Location into, Location before, String workspaceName, Name newNameForNode ) { return process(new MoveBranchRequest(from, into, before, workspaceName, newNameForNode, MoveBranchRequest.DEFAULT_CONFLICT_BEHAVIOR)); }
@Test public void shouldConsiderEqualTwoRequestsWithSameLocations() { request = new MoveBranchRequest(validPathLocation1, validPathLocation2, workspace2); MoveBranchRequest request2 = new MoveBranchRequest(validPathLocation1, validPathLocation2, workspace2); assertThat(request, is(request2)); }
@Test( expected = IllegalArgumentException.class ) public void shouldNotAllowCreatingRequestWithNullFromLocation() { new MoveBranchRequest(null, validPathLocation2, workspace2); }
@Test public void shouldAllowCreatingRequestWithNullToLocation() { new MoveBranchRequest(validPathLocation1, null, workspace2); }
@Test( expected = IllegalArgumentException.class ) public void shouldNotAllowCreatingRequestWithNullWorkspaceName() { new MoveBranchRequest(validPathLocation1, validPathLocation2, null); }
@Test public void shouldConsiderNotEqualTwoRequestsWithDifferentLocations() { request = new MoveBranchRequest(validPathLocation1, validPathLocation2, workspace2); MoveBranchRequest request2 = new MoveBranchRequest(validPathLocation2, validPathLocation1, workspace2); assertThat(request.equals(request2), is(false)); } }
@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())); }
/** * Process a request to rename a node specified location into a different location. * <p> * This method does nothing if the request is null. Unless overridden, this method converts the rename into a * {@link MoveBranchRequest move}. However, this only works if the <code>request</code> has a {@link Location#hasPath() path} * for its {@link RenameNodeRequest#at() location}. (If not, this method throws an {@link UnsupportedOperationException} and * must be overridden.) * </p> * * @param request the rename request */ public void process( RenameNodeRequest request ) { if (request == null) return; Location from = request.at(); if (!from.hasPath()) { throw new UnsupportedOperationException(); } Path newPath = getExecutionContext().getValueFactories().getPathFactory().create(from.getPath(), request.toName()); Location to = Location.create(newPath); MoveBranchRequest move = new MoveBranchRequest(from, to, request.inWorkspace()); process(move); // Set the actual locations ... request.setActualLocations(move.getActualLocationBefore(), move.getActualLocationAfter()); }
MoveBranchRequest pushDown = new MoveBranchRequest(fromProxy.location(), intoProxy.location(), beforeProxyLocation, intoProxy.workspaceName(), request.desiredName(), request.conflictBehavior()); ProxyNode beforeProxy = request.before() != null ? projectedBeforeNode.asProxy() : null; Location beforeProxyLocation = beforeProxy != null ? beforeProxy.location() : null; MoveBranchRequest pushDown = new MoveBranchRequest(fromProxy.location(), null, beforeProxyLocation, fromProxy.workspaceName(), request.desiredName(), request.conflictBehavior());