diff --git a/src/main/java/org/gcube/common/software/service/rest/Software.java b/src/main/java/org/gcube/common/software/service/rest/Software.java index 4edb053..c905944 100644 --- a/src/main/java/org/gcube/common/software/service/rest/Software.java +++ b/src/main/java/org/gcube/common/software/service/rest/Software.java @@ -1,5 +1,56 @@ package org.gcube.common.software.service.rest; -public class Software { +import javax.ws.rs.Consumes; +import javax.ws.rs.InternalServerErrorException; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import org.gcube.common.software.analyser.Analyser; +import org.gcube.common.software.analyser.AnalyserFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.webcohesion.enunciate.metadata.rs.ResponseCode; +import com.webcohesion.enunciate.metadata.rs.StatusCodes; + +/** + * @author Luca Frosini (ISTI - CNR) + */ +@Path("software") +public class Software { + + private final Logger logger = LoggerFactory.getLogger(Software.class); + + public static final String APPLICATION_JSON_CHARSET_UTF_8 = "application/json;charset=UTF-8"; + + @POST + @Consumes(APPLICATION_JSON_CHARSET_UTF_8) + @Produces(APPLICATION_JSON_CHARSET_UTF_8) + @StatusCodes ({ + @ResponseCode ( code = 202, condition = "The provided json is formally correct.") + }) + public Response create(String json) { + try { + Analyser analyser = AnalyserFactory.getAnalyser(json); + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + try { + analyser.analyse(); + } catch (Exception e) { + logger.error("Error while analysing\n{}", json); + } + } + }); + thread.start(); + return Response.status(Status.ACCEPTED).build(); + }catch (Exception e) { + throw new InternalServerErrorException(e); + } + } + + } diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index eb0dc61..c3d9dc8 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -2,7 +2,7 @@ - org.gcube.gcat.ResourceInitializer + org.gcube.common.software.service.ResourceInitializer 2 default @@ -13,7 +13,7 @@ 3 /api-docs/* 4 - org.gcube.gcat.ResourceInitializer + org.gcube.common.software.service.ResourceInitializer /* \ No newline at end of file