Integrate CodeExceptions in the webapp.
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/resource-management/resource-manager@161909 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
0743f01692
commit
36dd483b04
|
@ -3,6 +3,8 @@
|
|||
<classpathentry kind="src" path="webapp/src/main/java"/>
|
||||
<classpathentry kind="src" path="io/src/main/java"/>
|
||||
<classpathentry kind="src" path="webapp/src/test/java"/>
|
||||
<classpathentry kind="src" path="webapp/src/test/resources"/>
|
||||
<classpathentry kind="src" path="io/src/test/java"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
|
|
|
@ -5,6 +5,8 @@ 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;
|
||||
import org.gcube.resourcemanagement.manager.io.exceptions.CodeException;
|
||||
import org.gcube.resourcemanagement.manager.io.exceptions.RMCode;
|
||||
|
||||
/**
|
||||
* Actions that can be performed on the context.
|
||||
|
@ -50,10 +52,9 @@ public final class CreateRequest extends RequestToResourceRegistry {
|
|||
return ResponseFromResourceRegistry.newFailureResponse("Invalid response from the RR (null?)");
|
||||
}
|
||||
} catch (ContextAlreadyPresentException cape) {
|
||||
return ResponseFromResourceRegistry.fromException(cape);
|
||||
return ResponseFromResourceRegistry.fromException(new CodeException(RMCode.CONTEXT_ALREADY_EXIST));
|
||||
} catch (ResourceRegistryException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
return ResponseFromResourceRegistry.fromException(new CodeException(RMCode.GENERIC_ERROR_FROM_RR));
|
||||
}
|
||||
return ResponseFromResourceRegistry.newSuccessResponseWithMessage("Context successfully created.");
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import java.util.Objects;
|
|||
import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClient;
|
||||
import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClientFactory;
|
||||
import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClientImpl;
|
||||
import org.gcube.resourcemanagement.manager.io.exceptions.CodeException;
|
||||
import org.gcube.resourcemanagement.manager.io.exceptions.RMCode;
|
||||
|
||||
/**
|
||||
* Base request to an operation exposed by the Resource Registry.
|
||||
|
@ -37,8 +39,8 @@ public abstract class RequestToResourceRegistry {
|
|||
try {
|
||||
this.validate();
|
||||
} catch (Exception e) {
|
||||
ResponseFromResourceRegistry response = ResponseFromResourceRegistry.fromException(e).setMessage(
|
||||
"Failed to validate the request. The request was not submitted to the Resource Registry.");
|
||||
ResponseFromResourceRegistry response = ResponseFromResourceRegistry.
|
||||
fromException(new CodeException(RMCode.INVALID_REQUEST));
|
||||
return response;
|
||||
}
|
||||
if (Objects.isNull(this.resourceRegistryContextClient))
|
||||
|
|
|
@ -5,6 +5,8 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.gcube.resourcemanagement.manager.io.exceptions.CodeException;
|
||||
|
||||
/**
|
||||
* The response to a {@link RequestToResourceRegistry}.
|
||||
*
|
||||
|
@ -17,7 +19,7 @@ public class ResponseFromResourceRegistry {
|
|||
|
||||
private String message;
|
||||
|
||||
private List<? extends Exception> exceptions = new ArrayList<>();
|
||||
private List<? extends CodeException> exceptions = new ArrayList<>();
|
||||
|
||||
protected ResponseFromResourceRegistry() {}
|
||||
|
||||
|
@ -44,7 +46,7 @@ public class ResponseFromResourceRegistry {
|
|||
* The {@link Exception} returned by the RR.
|
||||
* @return the exception
|
||||
*/
|
||||
public Optional<? extends Exception> getException() {
|
||||
public Optional<? extends CodeException> getException() {
|
||||
return Optional.ofNullable(success? null: this.exceptions.get(0));
|
||||
}
|
||||
|
||||
|
@ -53,10 +55,9 @@ public class ResponseFromResourceRegistry {
|
|||
* @param e
|
||||
* @return the response
|
||||
*/
|
||||
public static <E extends Exception> ResponseFromResourceRegistry fromException(E e) {
|
||||
public static <E extends CodeException> ResponseFromResourceRegistry fromException(E e) {
|
||||
ResponseFromResourceRegistry response = new ResponseFromResourceRegistry();
|
||||
response.success = false;
|
||||
response.message = e.getMessage();
|
||||
response.exceptions = Collections.singletonList(e);
|
||||
return response;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ import javax.ws.rs.core.Response.Status;
|
|||
|
||||
import org.gcube.informationsystem.model.entity.Context;
|
||||
import static org.gcube.resourcemanagement.manager.io.rs.RMContextPath.*;
|
||||
|
||||
import org.gcube.resourcemanagement.manager.io.exceptions.CodeException;
|
||||
import org.gcube.resourcemanagement.manager.webapp.ResourceInitializer;
|
||||
import org.gcube.resourcemanagement.manager.webapp.context.CreateRequest;
|
||||
import org.gcube.resourcemanagement.manager.webapp.context.ResponseFromResourceRegistry;
|
||||
|
@ -32,17 +34,20 @@ public class RMContext {
|
|||
*/
|
||||
@POST
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public Response create(String json, @QueryParam(FORCE_RRURL_PARAM) String rrURL) {
|
||||
public Response create(String json, @QueryParam(FORCE_RRURL_PARAM) String rrURL) throws CodeException {
|
||||
logger.info("Requested to create context {} with json {}", Context.NAME, json);
|
||||
logger.info("Force URL: " + rrURL);
|
||||
Response response;
|
||||
ContextHolder holder = new ContextHolder(json);
|
||||
ResponseFromResourceRegistry returned = CreateRequest.fromHolder(holder).forceURL(rrURL).submit();
|
||||
logger.debug("Returned " + returned.wasSuccessful());
|
||||
if (returned.wasSuccessful()) {
|
||||
response = Response.status(Status.CREATED)
|
||||
.entity(returned.getMessage().map(m -> m).orElse("Context successfully created."))
|
||||
.type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8).build();
|
||||
} else {
|
||||
if (returned.getException().isPresent())
|
||||
throw returned.getException().get();
|
||||
response = Response.status(Status.BAD_REQUEST)
|
||||
.entity(returned.getMessage().map(m -> m).orElse("Failed to create the context.")).build();
|
||||
}
|
||||
|
|
|
@ -41,14 +41,14 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class RMContextTest extends JerseyTest {
|
||||
|
||||
private final static String contextName = "firstContext";
|
||||
private final static String contextName = "firstContext4";
|
||||
|
||||
private final static String RR = "";
|
||||
private final static String RR = "http://manuele-registry.dev.d4science.org/resource-registry";
|
||||
|
||||
public static final String DEFAULT_TEST_SCOPE ="71b9ef86-76ba-4346-b16e-9a1af203f6db-98187548";
|
||||
|
||||
private static boolean skipTest = false;
|
||||
|
||||
public static final String DEFAULT_TEST_SCOPE = "";
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
setContext(DEFAULT_TEST_SCOPE);
|
||||
|
|
Loading…
Reference in New Issue