/** * Add a request to delete a branch. * * @param at the location of the top node in the existing branch that is to be deleted * @param workspaceName the name of the workspace containing the parent * @return the request; never null * @throws IllegalArgumentException if the location or workspace name is null */ public DeleteBranchRequest deleteBranch( Location at, String workspaceName ) { return process(new DeleteBranchRequest(at, workspaceName)); }
/** * {@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)) { DeleteBranchRequest that = (DeleteBranchRequest)obj; if (!this.at().isSame(that.at())) return false; if (!this.inWorkspace().equals(that.inWorkspace())) return false; return true; } return false; }
/** * {@inheritDoc} * <p> * This method does not clone the results. * </p> * * @see org.modeshape.graph.request.ChangeRequest#clone() */ @Override public DeleteBranchRequest clone() { DeleteBranchRequest request = new DeleteBranchRequest(actualLocation != null ? actualLocation : at, workspaceName); request.setActualLocationOfNode(actualLocation); return request; }
@Test public void shouldCreateValidRequestWithValidLocation() { request = new DeleteBranchRequest(validPathLocation1, workspace1); assertThat(request.at(), is(sameInstance(validPathLocation1))); 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.DeleteBranchRequest) */ @Override public void process( DeleteBranchRequest request ) { if (!updatesAllowed(request)) return; WorkspaceType workspace = getWorkspace(request, request.inWorkspace()); if (workspace == null) return; NodeType node = getTargetNode(workspace, request, request.at()); if (node == null) return; Location actualLocation = txn.removeNode(workspace, node); request.setActualLocationOfNode(actualLocation); recordChange(request); }
@Override public void process( DeleteBranchRequest request ) { if (!updatesAllowed(request)) return; PathWorkspace workspace = getWorkspace(request, request.inWorkspace()); if (workspace == null) return; PathNode node = getTargetNode(workspace, request, request.at()); if (node == null) return; if (!(workspace instanceof WritablePathWorkspace)) { I18n msg = GraphI18n.workspaceIsReadOnly; request.setError(new InvalidRequestException(msg.text(repository.getSourceName(), workspace.getName()))); return; } WritablePathWorkspace newWorkspace = (WritablePathWorkspace)workspace; newWorkspace.removeNode(getExecutionContext(), node.getPath()); request.setActualLocationOfNode(Location.create(node.getPath(), node.getUuid())); recordChange(request); }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.DeleteBranchRequest) */ @Override public void process( DeleteBranchRequest request ) { // Figure out where this request is projected ... ProjectedNode projectedNode = project(request.at(), request.inWorkspace(), request, true); // Create the federated request ... FederatedRequest federatedRequest = new FederatedRequest(request); if (projectedNode == null) { submit(federatedRequest); return; } // A delete should be executed against any ProxyNode that applies ... FederatedWorkspace workspace = getWorkspace(request, request.inWorkspace()); boolean submit = deleteBranch(federatedRequest, projectedNode, workspace, getExecutionContext(), true); if (submit) { // Submit the requests for processing and then STOP ... submit(federatedRequest); } else { // Unable to perform this delete ... String msg = GraphI18n.unableToDeletePlaceholder.text(readable(request.at()), request.inWorkspace(), getSourceName()); request.setError(new UnsupportedRequestException(msg)); } }
if (RequestType.DELETE_BRANCH == sourceRequest.getType()) { DeleteBranchRequest source = (DeleteBranchRequest)projected.getRequest(); actual = source.getActualLocationOfNode(); } else { DeleteChildrenRequest source = (DeleteChildrenRequest)projected.getRequest(); actual = projectToFederated(request.at(), projected.getProjection(), actual, request); request.setActualLocationOfNode(highest);
@Override public void process( DeleteBranchRequest request ) { // Just update the actual location request.setActualLocationOfNode(actualLocationOf(request.at())); }
@Test public void shouldConsiderNotEqualTwoRequestsWithDifferentWorkspaceNames() { request = new DeleteBranchRequest(validPathLocation1, workspace1); DeleteBranchRequest request2 = new DeleteBranchRequest(validPathLocation1, workspace2); assertThat(request.equals(request2), is(false)); } }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.DeleteBranchRequest) */ @Override public void process( DeleteBranchRequest request ) { DeleteBranchRequest source = (DeleteBranchRequest)federatedRequest.getFirstProjectedRequest().getRequest(); if (checkErrorOrCancel(request, source)) return; request.setActualLocationOfNode(source.getActualLocationOfNode()); }
protected void assertNextRequestIsDelete( Location at ) { Request request = executedRequests.poll(); assertThat(request, is(instanceOf(DeleteBranchRequest.class))); DeleteBranchRequest delete = (DeleteBranchRequest)request; assertThat(delete.at(), is(at)); }
/** * Sets the actual and complete location of the node being deleted. This method must be called when processing the request, * and the actual location must have a {@link Location#getPath() path}. * * @param actual the actual location of the node being deleted, or null if the {@link #at() current location} should be used * @throws IllegalArgumentException if the actual location is null or does not have a path. * @throws IllegalStateException if the request is frozen */ public void setActualLocationOfNode( Location actual ) { checkNotFrozen(); CheckArg.isNotNull(actual, "actual"); if (!actual.hasPath()) { throw new IllegalArgumentException(GraphI18n.actualLocationMustHavePath.text(actual)); } this.actualLocation = actual; }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.DeleteBranchRequest) */ @Override public void process( DeleteBranchRequest request ) { if (!updatesAllowed(request)) return; MapWorkspace workspace = getWorkspace(request, request.inWorkspace()); if (workspace == null) return; MapNode node = getTargetNode(workspace, request, request.at()); if (node == null) return; workspace.removeNode(getExecutionContext(), node); Location actualLocation = getActualLocation(request.at(), node); request.setActualLocationOfNode(actualLocation); recordChange(request); }
@Test public void shouldConsiderNotEqualTwoRequestsWithDifferentLocations() { request = new DeleteBranchRequest(validPathLocation1, workspace1); DeleteBranchRequest request2 = new DeleteBranchRequest(validPathLocation2, workspace1); assertThat(request.equals(request2), is(false)); }
/** * Add a request to delete a branch. * * @param at the location of the top node in the existing branch that is to be deleted * @param workspaceName the name of the workspace containing the parent * @return this builder for method chaining; never null * @throws IllegalArgumentException if the location or workspace name is null */ public BatchRequestBuilder deleteBranch( Location at, String workspaceName ) { return add(new DeleteBranchRequest(at, workspaceName)); }
} else { DeleteBranchRequest pushDownRequest = new DeleteBranchRequest(proxy.location(), proxy.workspaceName()); federatedRequest.add(pushDownRequest, proxy.isSameLocationAsOriginal(), false, proxy.projection()); DeleteBranchRequest delete = new DeleteBranchRequest(placeholder.location(), workspace.getName()); delete.setActualLocationOfNode(placeholder.location()); federatedRequest.add(delete, true, true, null);
@Override protected Request createRequest() { return new DeleteBranchRequest(validPathLocation1, workspace1); }
@Test( expected = IllegalArgumentException.class ) public void shouldNotAllowCreatingRequestWithNullWorkspaceName() { new DeleteBranchRequest(validPathLocation1, null); }