Adapt response for the create method to gxRest.
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/resource-management/resource-manager@162900 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
3650407264
commit
9654a44e67
|
@ -62,6 +62,14 @@ public class ResponseFromResourceRegistry {
|
|||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* The {@link ErrorCode} occurred when preparing the response.
|
||||
* @return the error code or null
|
||||
*/
|
||||
public Optional<ErrorCode> getErrorCode() {
|
||||
return Optional.ofNullable(success? null: this.code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a response from an error code.
|
||||
* @param e
|
||||
|
|
|
@ -16,7 +16,6 @@ import static org.gcube.resourcemanagement.manager.io.rs.RMContextPath.*;
|
|||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.resourcemanagement.manager.io.rs.RMContextDoesNotExistException;
|
||||
import org.gcube.resourcemanagement.manager.webapp.ResourceInitializer;
|
||||
import org.gcube.resourcemanagement.manager.webapp.context.CreateRequest;
|
||||
import org.gcube.resourcemanagement.manager.webapp.context.DeleteRequest;
|
||||
|
@ -47,9 +46,6 @@ public class RMContext {
|
|||
logger.info("Force URL: " + rrURL);
|
||||
ContextHolder holder = new ContextHolder(json);
|
||||
ResponseFromResourceRegistry returned = CreateRequest.fromHolder(holder).forceURL(rrURL).submit();
|
||||
/* if (!returned.wasSuccessful()) {
|
||||
throw new WebCodeException(new RMContextDoesNotExistException("too bad"));
|
||||
}*/
|
||||
return this.buildResponse(returned,Status.CREATED,"Context successfully created.","Failed to create the context.");
|
||||
}
|
||||
|
||||
|
@ -64,9 +60,6 @@ public class RMContext {
|
|||
logger.info("Requested to delete context with id {}", uuid);
|
||||
logger.info("Force URL: " + rrURL);
|
||||
ResponseFromResourceRegistry returned = DeleteRequest.fromUUID(UUID.fromString(uuid)).forceURL(rrURL).submit();
|
||||
/* if (!returned.wasSuccessful()) {
|
||||
throw new WebCodeException(new RMContextDoesNotExistException());
|
||||
}*/
|
||||
return this.buildResponse(returned,Status.OK,"Context successfully deleted.","Failed to delete the context.");
|
||||
}
|
||||
|
||||
|
@ -85,25 +78,8 @@ public class RMContext {
|
|||
} else {
|
||||
if (returned.getException().isPresent())
|
||||
GXErrorResponse.throwException(returned.getException().get());
|
||||
return Response.status(Status.BAD_REQUEST)
|
||||
.entity(returned.getMessage().map(m -> m).orElse(failedMessage)).build();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Builds a response for the client.
|
||||
* @param returned
|
||||
* @param successMessage
|
||||
* @param failedMessage
|
||||
* @return the response
|
||||
*/
|
||||
private Response buildResponseWithException(ResponseFromResourceRegistry returned, Status successStatus, String successMessage, String failedMessage) {
|
||||
if (returned.wasSuccessful()) {
|
||||
return Response.status(successStatus)
|
||||
.entity(returned.getMessage().map(m -> m).orElse(successMessage))
|
||||
.type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8).build();
|
||||
} else {
|
||||
if (returned.getException().isPresent())
|
||||
GXErrorResponse.throwException(returned.getException().get());
|
||||
else if (returned.getErrorCode().isPresent())
|
||||
GXErrorResponse.returnErrorCode(returned.getErrorCode().get());
|
||||
return Response.status(Status.BAD_REQUEST)
|
||||
.entity(returned.getMessage().map(m -> m).orElse(failedMessage)).build();
|
||||
}
|
||||
|
|
Reference in New Issue