/** * {@inheritDoc} * <p> * This method does not clone the results. * </p> * * @see org.modeshape.graph.request.ChangeRequest#clone() */ @Override public DestroyWorkspaceRequest clone() { return new DestroyWorkspaceRequest(workspaceName); }
/** * {@inheritDoc} * * @see java.lang.Object#toString() */ @Override public String toString() { String workspaceName = workspaceName() != null ? "'" + workspaceName() + "'" : "default"; return "destroy workspace " + workspaceName; }
/** * Set the actual location of the root node in the new workspace. * * @param actualLocationOfRoot the actual location of the workspace's root node. * @throws IllegalStateException if the request is frozen */ public void setActualRootLocation( Location actualLocationOfRoot ) { checkNotFrozen(); this.actualLocationOfRoot = actualLocationOfRoot; }
@Test public void shouldCreateValidRequestWithValidLocation() { request = new DestroyWorkspaceRequest(workspace1); assertThat(request.workspaceName(), is(workspace1)); assertThat(request.hasError(), is(false)); assertThat(request.getError(), is(nullValue())); }
@Override public void process( DestroyWorkspaceRequest request ) { if (!updatesAllowed(request)) return; PathWorkspace workspace = repository.getWorkspace(request.workspaceName()); if (workspace != null) { request.setActualRootLocation(Location.create(pathFactory.createRootPath(), repository.getRootNodeUuid())); recordChange(request); } else { String msg = GraphI18n.workspaceDoesNotExistInRepository.text(request.workspaceName(), repository.getSourceName()); request.setError(new InvalidWorkspaceException(msg)); } }
@Test public void shouldConsiderNotEqualTwoRequestsWithDifferentWorkspaceNames() { request = new DestroyWorkspaceRequest(workspace1); DestroyWorkspaceRequest request2 = new DestroyWorkspaceRequest(workspace2); assertThat(request.equals(request2), is(false)); } }
/** * {@inheritDoc} * * @see org.modeshape.graph.Graph.DestroyWorkspace#named(java.lang.String) */ public boolean named( String workspaceName ) { CheckArg.isNotNull(workspaceName, "workspaceName"); if (getCurrentWorkspaceName().equals(workspaceName)) { String msg = GraphI18n.currentWorkspaceCannotBeDeleted.text(workspaceName, getSourceName()); throw new InvalidWorkspaceException(msg); } DestroyWorkspaceRequest request = requests.destroyWorkspace(workspaceName); if (request.hasError()) return false; return true; } };
/** * {@inheritDoc} * * @see org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.DestroyWorkspaceRequest) */ @Override public void process( DestroyWorkspaceRequest request ) { String msg = GraphI18n.federatedSourceDoesNotSupportDestroyingWorkspaces.text(getSourceName()); request.setError(new InvalidRequestException(msg)); }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.DestroyWorkspaceRequest) */ @Override public void process( DestroyWorkspaceRequest request ) { if (!updatesAllowed(request)) return; WorkspaceType workspace = repository.getWorkspace(txn, request.workspaceName()); if (workspace != null) { Node root = txn.getRootNode(workspace); try { txn.destroyWorkspace(workspace); request.setActualRootLocation(Location.create(pathFactory.createRootPath(), root.getUuid())); recordChange(request); } catch (RuntimeException e) { request.setError(e); } } else { String msg = GraphI18n.workspaceDoesNotExistInRepository.text(request.workspaceName(), repository.getSourceName()); request.setError(new InvalidWorkspaceException(msg)); } }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.DestroyWorkspaceRequest) */ @Override public void process( DestroyWorkspaceRequest request ) { if (!updatesAllowed(request)) return; MapWorkspace workspace = repository.getWorkspace(request.workspaceName()); if (workspace != null) { MapNode root = workspace.getRoot(); request.setActualRootLocation(Location.create(pathFactory.createRootPath(), root.getUuid())); recordChange(request); } else { String msg = GraphI18n.workspaceDoesNotExistInRepository.text(request.workspaceName(), repository.getSourceName()); request.setError(new InvalidWorkspaceException(msg)); } }
/** * Add a request to destroy an existing workspace. * * @param workspaceName the name of the workspace that is to be destroyed * @return the request; never null * @throws IllegalArgumentException if the workspace name is null */ public DestroyWorkspaceRequest destroyWorkspace( String workspaceName ) { return process(new DestroyWorkspaceRequest(workspaceName)); }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.ChangeRequest#changes(java.lang.String, org.modeshape.graph.property.Path) */ @Override public boolean changes( String workspace, Path path ) { return workspaceName().equals(workspace); }
/** * Add a request to destroy an existing workspace. * * @param workspaceName the name of the workspace that is to be destroyed * @return this builder for method chaining; never null * @throws IllegalArgumentException if the workspace name is null */ public BatchRequestBuilder destroyWorkspace( String workspaceName ) { return add(new DestroyWorkspaceRequest(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)) { DestroyWorkspaceRequest that = (DestroyWorkspaceRequest)obj; if (!this.workspaceName.equals(that.workspaceName())) return false; return true; } return false; }
@Override protected Request createRequest() { return new DestroyWorkspaceRequest(workspace1); }
@Test public void shouldConsiderEqualTwoRequestsWithSameLocations() { request = new DestroyWorkspaceRequest(workspace1); DestroyWorkspaceRequest request2 = new DestroyWorkspaceRequest(workspace1); assertThat(request, is(request2)); }
@Test( expected = IllegalArgumentException.class ) public void shouldNotAllowCreatingRequestWithNullWorkspaceName() { new DestroyWorkspaceRequest(null); }