Create a failure response when the new context already exists.
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/resource-management/resource-manager@160691 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
eb160612be
commit
4b98621cc8
|
@ -4,6 +4,7 @@ import java.util.Objects;
|
|||
|
||||
import org.gcube.informationsystem.model.entity.Context;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextAlreadyPresentException;
|
||||
|
||||
/**
|
||||
* Actions that can be performed on the context.
|
||||
|
@ -45,7 +46,11 @@ public final class CreateRequest extends RequestToResourceRegistry {
|
|||
Context created = resourceRegistryContextClient.create(context);
|
||||
if (Objects.nonNull(created)) {
|
||||
|
||||
} else {
|
||||
return ResponseFromResourceRegistry.newFailureResponse("Invalid response from the RR (null?)");
|
||||
}
|
||||
} catch (ContextAlreadyPresentException cape) {
|
||||
return ResponseFromResourceRegistry.fromException(cape);
|
||||
} catch (ResourceRegistryException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -22,7 +22,7 @@ public abstract class RequestToResourceRegistry {
|
|||
* @param forceURL
|
||||
*/
|
||||
public RequestToResourceRegistry forceURL(String forceURL) {
|
||||
this.resourceRegistryContextClient = new ResourceRegistryContextClientImpl(forceURL);
|
||||
this.resourceRegistryContextClient = new ResourceRegistryContextClientImpl(forceURL);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -48,11 +48,12 @@ public abstract class RequestToResourceRegistry {
|
|||
|
||||
/**
|
||||
* Gives a chance to sub-classes to validate the response.
|
||||
*
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
protected ResponseFromResourceRegistry validateResponse(ResponseFromResourceRegistry response) {
|
||||
//by default, returns the response as it is
|
||||
// by default, returns the response as it is
|
||||
return response;
|
||||
}
|
||||
|
||||
|
|
|
@ -70,6 +70,17 @@ public class ResponseFromResourceRegistry {
|
|||
response.success = true;
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a failure response
|
||||
* @return the response
|
||||
*/
|
||||
public static ResponseFromResourceRegistry newFailureResponse(String reason) {
|
||||
ResponseFromResourceRegistry response = new ResponseFromResourceRegistry();
|
||||
response.success = false;
|
||||
response.setMessage(reason);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a success response with an associated message.
|
||||
|
|
Loading…
Reference in New Issue