final TomcatClientResponder responder = new TomcatClientResponder(
response);
response.setHeader("Access-Control-Allow-Origin",
this.config.getHeaderAccessControl());
CreateResponse createResponse = new CreateResponse();
FormItemList formItemList = null;
try {
formItemList = FormItemList.extractFormItems(request, FACTORY);
} catch (final FileUploadException e) {
responder.error(500,
"errors encountered while processing the request");
return;
}
if (formItemList != null) {
final CreateRequest createRequest = CreateRequest.checkRequest(
formItemList, createResponse);
boolean commandStacked = false;
if (createRequest != null) {
switch (createRequest.getType()) {
// create a user
case USER:
final CreateUserResponse createUserResponse = new CreateUserResponse();
final CreateUserRequest createUserRequest = CreateUserRequest
.checkRequest(formItemList, createRequest,
createUserResponse);
createResponse = createUserResponse;
if (createUserRequest != null) {
// create user
final CreateUser createUserCommand = new CreateUser(
this, createUserResponse, createUserRequest);
this.commandQueue.add(createUserCommand);
commandStacked = true;
}
break;
// create a follow edge
case FOLLOW:
final CreateFollowResponse createFollowResponse = new CreateFollowResponse();
final CreateFollowRequest createFollowRequest = CreateFollowRequest
.checkRequest(formItemList, createRequest,
createFollowResponse);
createResponse = createFollowResponse;
if (createFollowRequest != null) {
// create follow edge
final CreateFollow createFollowCommand = new CreateFollow(
this, createFollowResponse, createFollowRequest);
this.commandQueue.add(createFollowCommand);
commandStacked = true;
}
break;
// create a status update
default:
final CreateStatusUpdateResponse createStatusUpdateResponse = new CreateStatusUpdateResponse();
final CreateStatusUpdateRequest createStatusUpdateRequest = CreateStatusUpdateRequest
.checkRequest(formItemList, createRequest,
createStatusUpdateResponse);
createResponse = createStatusUpdateResponse;
if (createStatusUpdateRequest != null) {
try {
this.writeFiles(createStatusUpdateRequest
.getStatusUpdateTemplate(), formItemList);
// create a new status update of the type specified
final StatusUpdate statusUpdate = StatusUpdateManager
.instantiateStatusUpdate(
createStatusUpdateRequest
.getStatusUpdateTemplate()
.getName(), formItemList);
statusUpdate.setId(createStatusUpdateRequest
.getStatusUpdateId());
createStatusUpdateRequest
.setStatusUpdate(statusUpdate);
// create status update
final CreateStatusUpdate createStatusUpdateCommand = new CreateStatusUpdate(
this, createStatusUpdateResponse,
createStatusUpdateRequest);
this.commandQueue.add(createStatusUpdateCommand);
commandStacked = true;
} catch (final StatusUpdateInstantiationFailedException e) {
// remove the files
FormFile fileItem;
File file;
for (String fileIdentifier : formItemList
.getFileIdentifiers()) {
fileItem = formItemList.getFile(fileIdentifier);
file = fileItem.getFile();
if (file != null) {
file.delete();
}