Creating service skeleton
This commit is contained in:
parent
f55865eff6
commit
cf43846c73
4
pom.xml
4
pom.xml
|
@ -29,7 +29,7 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-smartgears-bom</artifactId>
|
||||
<version>2.2.0</version>
|
||||
<version>2.3.0-SNAPSHOT</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
@ -60,7 +60,7 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-utils</artifactId>
|
||||
<version>[2.0.0, 3.0.0-SNAPSHOT)</version>
|
||||
<version>[2.1.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.gcube.grsf.publisher;
|
|||
|
||||
import javax.ws.rs.ApplicationPath;
|
||||
|
||||
import org.gcube.grsf.publisher.rest.BaseRESTAPIs;
|
||||
import org.gcube.smartgears.annotations.ManagedBy;
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
|
||||
|
@ -13,7 +14,7 @@ import org.glassfish.jersey.server.ResourceConfig;
|
|||
public class ResourceInitializer extends ResourceConfig {
|
||||
|
||||
public ResourceInitializer() {
|
||||
|
||||
packages(BaseRESTAPIs.class.getPackage().toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
package org.gcube.grsf.publisher.enums;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
/**
|
||||
* Source Group and sub groups (for both StockRESTAPIs and FisheryRESTAPIs) -> look at "Database Source"
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public enum Source {
|
||||
|
||||
FIRMS("FIRMS","firms"),
|
||||
RAM("RAM","ram"),
|
||||
FISHSOURCE("FishSource", "fishsource"),
|
||||
GRSF("GRSF", "grsf"),
|
||||
SDG("FAO SDG 14.4.1 Questionnaire","sdg");
|
||||
|
||||
private String sourceName;
|
||||
private String urlPath;
|
||||
|
||||
private Source(String sourceName, String urlPath) {
|
||||
this.sourceName = sourceName;
|
||||
this.urlPath = urlPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the original name
|
||||
* @return
|
||||
*/
|
||||
public String getSourceName(){
|
||||
return sourceName;
|
||||
}
|
||||
|
||||
@JsonValue
|
||||
public String onSerialize(){
|
||||
return urlPath;
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
public static Source onDeserialize(String sourceString) {
|
||||
if(sourceString != null) {
|
||||
for(Source source : Source.values()) {
|
||||
if (source.urlPath.equalsIgnoreCase(sourceString.trim())) {
|
||||
return source;
|
||||
}
|
||||
if (source.sourceName.equalsIgnoreCase(sourceString.trim())) {
|
||||
return source;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getURLPath() {
|
||||
return urlPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return urlPath;
|
||||
}
|
||||
|
||||
public static String getJsonArrayAsString(){
|
||||
return "[" + FIRMS.urlPath + "," +
|
||||
RAM.urlPath + "," +
|
||||
FISHSOURCE.urlPath + "," +
|
||||
GRSF.urlPath + "," +
|
||||
SDG.urlPath + "," + "]";
|
||||
}
|
||||
|
||||
public static List<String> listNames(){
|
||||
|
||||
List<String> valuesString = new ArrayList<String>(Source.values().length);
|
||||
for(Source source : Source.values()) {
|
||||
valuesString.add(source.getSourceName());
|
||||
}
|
||||
|
||||
return valuesString;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package org.gcube.grsf.publisher.record;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class Fishery extends Record {
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package org.gcube.grsf.publisher.record;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class Record {
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package org.gcube.grsf.publisher.record;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class Stock extends Record {
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package org.gcube.grsf.publisher.rest;
|
||||
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.ws.rs.core.Response.ResponseBuilder;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.CalledMethodProvider;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
||||
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@RequestHeaders ({
|
||||
@RequestHeader( name = "Authorization", description = "Bearer token, see <a href=\"https://dev.d4science.org/how-to-access-resources\">https://dev.d4science.org/how-to-access-resources</a>")
|
||||
})
|
||||
public class BaseRESTAPIs {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Context
|
||||
protected HttpHeaders httpHeaders;
|
||||
|
||||
@Context
|
||||
protected UriInfo uriInfo;
|
||||
|
||||
protected static final String LOCATION_HEADER = "Location";
|
||||
|
||||
protected void setCalledMethod(String method) {
|
||||
CalledMethodProvider.instance.set(method);
|
||||
logger.info("{}", uriInfo.getAbsolutePath());
|
||||
}
|
||||
|
||||
protected ResponseBuilder addLocation(ResponseBuilder responseBuilder, String id) {
|
||||
return responseBuilder.header(LOCATION_HEADER,
|
||||
String.format("%s/%s", uriInfo.getAbsolutePath().toString(), id));
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package org.gcube.grsf.publisher.rest;
|
||||
|
||||
import javax.ws.rs.Path;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@Path("{source:firms|FIRMS|grsf|GRSF|FishSource|fishsource|sdg|SDG}/fishery/")
|
||||
public class FisheryRESTAPIs extends BaseRESTAPIs {
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package org.gcube.grsf.publisher.rest;
|
||||
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@Provider
|
||||
public class GRSFExceptionMapper implements ExceptionMapper<Exception> {
|
||||
|
||||
@Override
|
||||
public Response toResponse(Exception exception) {
|
||||
|
||||
Status status = Status.INTERNAL_SERVER_ERROR;
|
||||
String exceptionMessage = exception.getMessage();
|
||||
try {
|
||||
if(exception.getCause() != null) {
|
||||
exceptionMessage = exception.getCause().getMessage();
|
||||
}
|
||||
} catch(Exception e) {
|
||||
exceptionMessage = exception.getMessage();
|
||||
}
|
||||
MediaType mediaType = MediaType.TEXT_PLAIN_TYPE;
|
||||
|
||||
if(WebApplicationException.class.isAssignableFrom(exception.getClass())) {
|
||||
Response gotResponse = ((WebApplicationException) exception).getResponse();
|
||||
status = Status.fromStatusCode(gotResponse.getStatusInfo().getStatusCode());
|
||||
}
|
||||
|
||||
return Response.status(status).entity(exceptionMessage).type(mediaType).build();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package org.gcube.grsf.publisher.rest;
|
||||
|
||||
import javax.ws.rs.Path;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@Path("{source:firms|FIRMS|ram|RAM|grsf|GRSF|FishSource|fishsource|sdg|SDG}/stock/")
|
||||
public class StockRESTAPIs extends BaseRESTAPIs {
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package org.gcube.grsf.publisher.rest;
|
||||
|
||||
import javax.ws.rs.Path;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@Path("{source:grsf|GRSF}/traceability-unit/")
|
||||
public class TraceabilityUnitRESTAPIs {
|
||||
|
||||
}
|
Loading…
Reference in New Issue