@SuppressWarnings( "unchecked" )
@Override
public void process( CloneWorkspaceRequest request ) {
if (!creatingWorkspacesAllowed) {
String msg = JpaConnectorI18n.unableToCreateWorkspaces.text(getSourceName());
request.setError(new InvalidRequestException(msg));
}
Set<String> existingNames = workspaces.getWorkspaceNames();
String name = request.desiredNameOfTargetWorkspace();
int counter = 0;
while (existingNames.contains(name)) {
switch (request.targetConflictBehavior()) {
case CREATE_WITH_ADJUSTED_NAME:
name = request.desiredNameOfTargetWorkspace() + ++counter;
break;
case DO_NOT_CREATE:
default:
String msg = JpaConnectorI18n.workspaceAlreadyExists.text(getSourceName(), name);
request.setError(new InvalidWorkspaceException(msg));
return;
}
}
String fromWorkspaceName = request.nameOfWorkspaceToBeCloned();
WorkspaceEntity fromWorkspace = workspaces.get(fromWorkspaceName, false);
if (fromWorkspace == null) {
switch (request.cloneConflictBehavior()) {
case SKIP_CLONE:
break;
case DO_NOT_CLONE:
default:
String msg = JpaConnectorI18n.workspaceDoesNotExist.text(getSourceName(), fromWorkspaceName);
request.setError(new InvalidRequestException(msg));
return;
}
}
// Create the workspace ...