Working on Task #12970 - The "Analytics" resolver
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@174597 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
30dea49fb2
commit
7056224a95
|
@ -4,6 +4,9 @@
|
||||||
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
||||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
||||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
|
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
|
||||||
|
<dependent-module archiveName="dataminer-invocation-model-0.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/dataminer-invocation-model/dataminer-invocation-model">
|
||||||
|
<dependency-type>uses</dependency-type>
|
||||||
|
</dependent-module>
|
||||||
<property name="context-root" value="uri-resolver"/>
|
<property name="context-root" value="uri-resolver"/>
|
||||||
<property name="java-output-path" value="/uri-resolver/target/classes"/>
|
<property name="java-output-path" value="/uri-resolver/target/classes"/>
|
||||||
</wb-module>
|
</wb-module>
|
||||||
|
|
6
pom.xml
6
pom.xml
|
@ -72,6 +72,12 @@
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.data.analysis</groupId>
|
||||||
|
<artifactId>dataminer-invocation-model</artifactId>
|
||||||
|
<version>[0.0.1-SNAPSHOT,1.0.0-SNAPSHOT)</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.core</groupId>
|
<groupId>org.gcube.core</groupId>
|
||||||
<artifactId>common-encryption</artifactId>
|
<artifactId>common-encryption</artifactId>
|
||||||
|
|
|
@ -24,7 +24,7 @@ import lombok.ToString;
|
||||||
@ToString
|
@ToString
|
||||||
public class DataMinerRequest {
|
public class DataMinerRequest {
|
||||||
|
|
||||||
private String scope;
|
//private String scope;
|
||||||
private String operatorId;
|
private String operatorId;
|
||||||
private Map<String,String> parameters;
|
private Map<String,String> parameters;
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,12 @@ public class TokenSetter implements ContainerRequestFilter, ContainerResponseFil
|
||||||
@Override
|
@Override
|
||||||
public void filter(ContainerRequestContext ctx) throws IOException {
|
public void filter(ContainerRequestContext ctx) throws IOException {
|
||||||
log.info("TokenSetter Request called");
|
log.info("TokenSetter Request called");
|
||||||
SecurityTokenProvider.instance.set(context.getInitParameter("root-app-token"));
|
|
||||||
ScopeProvider.instance.set(context.getInitParameter("root-scope"));
|
if(SecurityTokenProvider.instance.get()==null)
|
||||||
|
SecurityTokenProvider.instance.set(context.getInitParameter("root-app-token"));
|
||||||
|
|
||||||
|
if(ScopeProvider.instance.get()==null)
|
||||||
|
ScopeProvider.instance.set(context.getInitParameter("root-scope"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,172 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.datatransfer.resolver.services;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.Context;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.xml.bind.JAXBException;
|
||||||
|
|
||||||
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
import org.gcube.common.scope.impl.ScopeBean;
|
||||||
|
import org.gcube.common.scope.impl.ScopeBean.Type;
|
||||||
|
import org.gcube.data.analysis.dminvocation.ActionType;
|
||||||
|
import org.gcube.data.analysis.dminvocation.DataMinerInvocationManager;
|
||||||
|
import org.gcube.data.analysis.dminvocation.model.DataMinerInputParams;
|
||||||
|
import org.gcube.data.analysis.dminvocation.model.DataMinerInvocation;
|
||||||
|
import org.gcube.data.analysis.dminvocation.model.DataMinerParam;
|
||||||
|
import org.gcube.data.analysis.dminvocation.model.DataMinerParameters;
|
||||||
|
import org.gcube.datatransfer.resolver.dataminer.DataMinerRequest;
|
||||||
|
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||||
|
import org.gcube.datatransfer.resolver.util.Util;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class DataMinerResolver.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
|
* Nov 28, 2018
|
||||||
|
*/
|
||||||
|
@Path("/analytics")
|
||||||
|
public class AnalyticsCreateResolver {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final String UTF_8 = "UTF-8";
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(AnalyticsCreateResolver.class);
|
||||||
|
private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post catalogue.
|
||||||
|
*
|
||||||
|
* @param req the req
|
||||||
|
* @param jsonRequest the json request
|
||||||
|
* @return the response
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("/create")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.TEXT_PLAIN)
|
||||||
|
public Response postCatalogue(@Context HttpServletRequest req, DataMinerRequest jsonRequest) {
|
||||||
|
logger.info(this.getClass().getSimpleName()+" POST starts...");
|
||||||
|
|
||||||
|
logger.info("The body contains the request: "+jsonRequest.toString());
|
||||||
|
|
||||||
|
String scope = ScopeProvider.instance.get();
|
||||||
|
String operatorID = jsonRequest.getOperatorId();
|
||||||
|
|
||||||
|
if(scope==null || scope.isEmpty()){
|
||||||
|
logger.error("The parameter 'scope' not found or empty in the JSON object");
|
||||||
|
ExceptionManager.throwBadRequestException(req, "Mandatory body parameter 'scope' not found or empty in the JSON object", this.getClass(), helpURI);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(operatorID==null || operatorID.isEmpty()){
|
||||||
|
logger.error("The parameter 'operatorId' not found or empty in the JSON object");
|
||||||
|
ExceptionManager.throwBadRequestException(req, "Mandatory body parameter 'operatorId' not found or empty in the JSON object", this.getClass(), helpURI);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopeBean scopeBean = new ScopeBean(scope);
|
||||||
|
String publicLinkToDMInvFile = "";
|
||||||
|
|
||||||
|
if(scopeBean.is(Type.VRE)){
|
||||||
|
String vreName = scopeBean.name();
|
||||||
|
try {
|
||||||
|
|
||||||
|
String dataminerResolverURL = String.format("%s/%s", Util.getServerURL(req), "dataminer/get");
|
||||||
|
|
||||||
|
//Creating DM invocation file
|
||||||
|
DataMinerInvocation dmInvocation = new DataMinerInvocation();
|
||||||
|
dmInvocation.setOperatorId(operatorID);
|
||||||
|
dmInvocation.setActionType(ActionType.RUN);
|
||||||
|
|
||||||
|
DataMinerInputParams inputParams = new DataMinerInputParams();
|
||||||
|
List<DataMinerParam> listParam = new ArrayList<DataMinerParam>();
|
||||||
|
Map<String, String> parameters = jsonRequest.getParameters();
|
||||||
|
for (String param : parameters.keySet()) {
|
||||||
|
listParam.add(new DataMinerParam(param, parameters.get(param)));
|
||||||
|
}
|
||||||
|
|
||||||
|
inputParams.setListParam(listParam);
|
||||||
|
dmInvocation.setParameters(new DataMinerParameters(inputParams, null));
|
||||||
|
File tempInvocationFile = null;
|
||||||
|
try {
|
||||||
|
|
||||||
|
ByteArrayOutputStream xmlByteArray = DataMinerInvocationManager.marshaling(dmInvocation, org.gcube.data.analysis.dminvocation.MediaType.ApplicationXML);
|
||||||
|
tempInvocationFile = createTempFile(operatorID+UUID.randomUUID(), ".xml", xmlByteArray.toByteArray());
|
||||||
|
|
||||||
|
//CREATE THE FILE ON STORAGE HUB
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (IOException | JAXBException e) {
|
||||||
|
logger.error("Error on creating you request with "+dmInvocation+"", e);
|
||||||
|
ExceptionManager.throwBadRequestException(req, "Error on creating you request with "+dmInvocation, this.getClass(), helpURI);
|
||||||
|
}finally{
|
||||||
|
//DELETING THE TEMP FILE
|
||||||
|
// if(tempInvocationFile!=null && tempInvocationFile.exists())
|
||||||
|
// tempInvocationFile.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String dataMinerURL = String.format("%s/%s?%s=%s", dataminerResolverURL, vreName, "di", URLEncoder.encode(publicLinkToDMInvFile, UTF_8));
|
||||||
|
logger.info("Returning Analytics URL: "+dataMinerURL);
|
||||||
|
return Response.ok(dataMinerURL).header("Location", dataMinerURL).build();
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (UnsupportedEncodingException e) {
|
||||||
|
logger.error("Encoding error for "+publicLinkToDMInvFile+"", e);
|
||||||
|
ExceptionManager.throwBadRequestException(req, "Error on encoding the public link "+publicLinkToDMInvFile, this.getClass(), helpURI);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}else{
|
||||||
|
logger.error("The input scope "+scope+" is not a VRE");
|
||||||
|
ExceptionManager.throwBadRequestException(req, "Working in the "+scope+" scope that is not a VRE. Use a token of VRE", this.getClass(), helpURI);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the temp file.
|
||||||
|
*
|
||||||
|
* @param fileName the file name
|
||||||
|
* @param extension the extension
|
||||||
|
* @param data the data
|
||||||
|
* @return the file
|
||||||
|
* @throws IOException Signals that an I/O exception has occurred.
|
||||||
|
*/
|
||||||
|
private static File createTempFile(String fileName, String extension, byte[] data) throws IOException {
|
||||||
|
// Since Java 1.7 Files and Path API simplify operations on files
|
||||||
|
java.nio.file.Path path = Files.createTempFile(fileName, extension);
|
||||||
|
File file = path.toFile();
|
||||||
|
// writing sample data
|
||||||
|
Files.write(path, data);
|
||||||
|
logger.info("Created the temfile: "+file.getAbsolutePath());
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,88 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.datatransfer.resolver.services;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.core.Context;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
import org.gcube.datatransfer.resolver.caches.LoadingVREsScopeCache;
|
||||||
|
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class DataMinerResolver.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
|
* Nov 28, 2018
|
||||||
|
*/
|
||||||
|
@Path("/analytics")
|
||||||
|
public class AnalyticsGetResolver {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final String UTF_8 = "UTF-8";
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(AnalyticsGetResolver.class);
|
||||||
|
private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the data miner.
|
||||||
|
*
|
||||||
|
* @param req the req
|
||||||
|
* @param provider the provider
|
||||||
|
* @param path the path
|
||||||
|
* @param remainPath the remain path
|
||||||
|
* @return the data miner
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("/get/{vreName}")
|
||||||
|
public Response getDataMiner(@Context HttpServletRequest req, @PathParam("vreName") String vreName) {
|
||||||
|
logger.info(this.getClass().getSimpleName()+" GET starts...");
|
||||||
|
try {
|
||||||
|
|
||||||
|
if(vreName==null || vreName.isEmpty()){
|
||||||
|
logger.error("The path parameter 'vreName' not found or empty in the path");
|
||||||
|
ExceptionManager.throwBadRequestException(req, "Mandatory path parameter 'vreName' not found or empty", this.getClass(), helpURI);
|
||||||
|
}
|
||||||
|
|
||||||
|
try{
|
||||||
|
String fullScope = LoadingVREsScopeCache.getCache().get(vreName);
|
||||||
|
|
||||||
|
//READ THE DATAMINER URL PORTLET FROM APPLICATION PROFRILE IN THE SCOPE fullScope
|
||||||
|
String dataminerEndPoint = "https://pre.d4science.org/group/prevre/dataminer-manager";
|
||||||
|
|
||||||
|
String queryString = "";
|
||||||
|
if(req.getQueryString()!=null && !req.getQueryString().isEmpty()){
|
||||||
|
queryString+="&"+req.getQueryString();
|
||||||
|
}
|
||||||
|
|
||||||
|
String dataMinerResolveURL = String.format("%s?%s", dataminerEndPoint, queryString);
|
||||||
|
logger.info("Resolving the request as DataMinerURL: "+dataMinerResolveURL);
|
||||||
|
return Response.seeOther(new URI(dataMinerResolveURL)).build();
|
||||||
|
|
||||||
|
}catch (ExecutionException e) {
|
||||||
|
logger.error("The input VRE Name "+vreName+" not found", e);
|
||||||
|
ExceptionManager.throwBadRequestException(req, "The input 'VRE Name' "+"+vreName+"+ "not found on Informatiion System. Is it a valid VRE?", this.getClass(), helpURI);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}catch (Exception e) {
|
||||||
|
logger.error("error resolving catalogue link",e);
|
||||||
|
ExceptionManager.throwInternalErrorException(req, "Error occurred resolving catalogue link", this.getClass(), helpURI);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,181 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.gcube.datatransfer.resolver.services;
|
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.ws.rs.Consumes;
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.POST;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
import javax.ws.rs.core.Context;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
|
|
||||||
import org.gcube.common.scope.impl.ScopeBean;
|
|
||||||
import org.gcube.common.scope.impl.ScopeBean.Type;
|
|
||||||
import org.gcube.datatransfer.resolver.caches.LoadingVREsScopeCache;
|
|
||||||
import org.gcube.datatransfer.resolver.dataminer.DataMinerRequest;
|
|
||||||
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
|
||||||
import org.gcube.datatransfer.resolver.util.Util;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Class DataMinerResolver.
|
|
||||||
*
|
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
||||||
* Nov 28, 2018
|
|
||||||
*/
|
|
||||||
@Path("/dataminer")
|
|
||||||
public class DataMinerResolver {
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final String UTF_8 = "UTF-8";
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(CatalogueResolver.class);
|
|
||||||
private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver";
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the data miner.
|
|
||||||
*
|
|
||||||
* @param req the req
|
|
||||||
* @param provider the provider
|
|
||||||
* @param path the path
|
|
||||||
* @param remainPath the remain path
|
|
||||||
* @return the data miner
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("/{vreName}/{operatorId}")
|
|
||||||
public Response getDataMiner(@Context HttpServletRequest req, @PathParam("vreName") String vreName, @PathParam("operatorId") String operatorId) {
|
|
||||||
logger.info(this.getClass().getSimpleName()+" GET starts...");
|
|
||||||
try {
|
|
||||||
|
|
||||||
if(vreName==null || vreName.isEmpty()){
|
|
||||||
logger.error("The path parameter 'vreName' not found or empty in the path");
|
|
||||||
ExceptionManager.throwBadRequestException(req, "Mandatory path parameter 'vreName' not found or empty", this.getClass(), helpURI);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(operatorId==null || operatorId.isEmpty()){
|
|
||||||
logger.error("The path parameter 'operatorId' not found or empty in the JSON object");
|
|
||||||
ExceptionManager.throwBadRequestException(req, "Mandatory path parameter 'operatorId' not found or empty", this.getClass(), helpURI);
|
|
||||||
}
|
|
||||||
|
|
||||||
try{
|
|
||||||
String fullScope = LoadingVREsScopeCache.getCache().get(vreName);
|
|
||||||
|
|
||||||
//READ THE DATAMINER URL PORTLET FROM APPLICATION PROFRILE IN THE SCOPE fullScope
|
|
||||||
String dataminerEndPoint = "https://pre.d4science.org/group/prevre/dataminer-manager";
|
|
||||||
|
|
||||||
String queryString = "OperatorId="+URLEncoder.encode(operatorId, UTF_8);
|
|
||||||
if(req.getQueryString()!=null && !req.getQueryString().isEmpty()){
|
|
||||||
queryString+="&"+req.getQueryString();
|
|
||||||
}
|
|
||||||
|
|
||||||
String dataMinerResolveURL = String.format("%s?%s", dataminerEndPoint, queryString);
|
|
||||||
logger.info("Resolving the request as DataMinerURL: "+dataMinerResolveURL);
|
|
||||||
return Response.seeOther(new URI(dataMinerResolveURL)).build();
|
|
||||||
|
|
||||||
}catch (ExecutionException e) {
|
|
||||||
logger.error("The input VRE Name "+vreName+" not found", e);
|
|
||||||
ExceptionManager.throwBadRequestException(req, "The input 'VRE Name' "+"+vreName+"+ "not found on Informatiion System. Is it a valid VRE?", this.getClass(), helpURI);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}catch (Exception e) {
|
|
||||||
logger.error("error resolving catalogue link",e);
|
|
||||||
ExceptionManager.throwInternalErrorException(req, "Error occurred resolving catalogue link", this.getClass(), helpURI);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Post catalogue.
|
|
||||||
*
|
|
||||||
* @param req the req
|
|
||||||
* @param jsonRequest the json request
|
|
||||||
* @return the response
|
|
||||||
*/
|
|
||||||
@POST
|
|
||||||
@Path("")
|
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
|
||||||
@Produces(MediaType.TEXT_PLAIN)
|
|
||||||
public Response postCatalogue(@Context HttpServletRequest req, DataMinerRequest jsonRequest) {
|
|
||||||
logger.info(this.getClass().getSimpleName()+" POST starts...");
|
|
||||||
|
|
||||||
logger.info("The body contains the request: "+jsonRequest.toString());
|
|
||||||
|
|
||||||
String scope = jsonRequest.getScope();
|
|
||||||
String operatorID = jsonRequest.getOperatorId();
|
|
||||||
|
|
||||||
if(scope==null || scope.isEmpty()){
|
|
||||||
logger.error("The parameter 'scope' not found or empty in the JSON object");
|
|
||||||
ExceptionManager.throwBadRequestException(req, "Mandatory body parameter 'scope' not found or empty in the JSON object", this.getClass(), helpURI);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(operatorID==null || operatorID.isEmpty()){
|
|
||||||
logger.error("The parameter 'operatorId' not found or empty in the JSON object");
|
|
||||||
ExceptionManager.throwBadRequestException(req, "Mandatory body parameter 'operatorId' not found or empty in the JSON object", this.getClass(), helpURI);
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopeBean scopeBean = new ScopeBean(scope);
|
|
||||||
|
|
||||||
if(scopeBean.is(Type.VRE)){
|
|
||||||
String vreName = scopeBean.name();
|
|
||||||
try {
|
|
||||||
//CHECK IF IT IS A VALID SCOPE
|
|
||||||
LoadingVREsScopeCache.getCache().get(vreName);
|
|
||||||
String dataminerResolverURL = String.format("%s/%s", Util.getServerURL(req), "dataminer");
|
|
||||||
String theOperator = "";
|
|
||||||
String queryString = "";
|
|
||||||
try {
|
|
||||||
theOperator = URLEncoder.encode(operatorID, UTF_8);
|
|
||||||
Map<String, String> parameters = jsonRequest.getParameters();
|
|
||||||
for (String param : parameters.keySet()) {
|
|
||||||
String value = parameters.get(param);
|
|
||||||
if(value!=null)
|
|
||||||
queryString+=String.format(param+"=%s", URLEncoder.encode(parameters.get(param), UTF_8))+"&";
|
|
||||||
}
|
|
||||||
queryString = Util.removeLastChar(queryString);
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (UnsupportedEncodingException e) {
|
|
||||||
logger.error("Encoding error: ",e);
|
|
||||||
ExceptionManager.throwBadRequestException(req, "Encoding error: "+e.getMessage(), this.getClass(), helpURI);
|
|
||||||
}
|
|
||||||
|
|
||||||
String dataMinerURL = String.format("%s/%s/%s?%s", dataminerResolverURL, vreName, theOperator, queryString);
|
|
||||||
logger.info("Returning DataMinerURL: "+dataMinerURL);
|
|
||||||
return Response.ok(dataMinerURL).header("Location", dataMinerURL).build();
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (ExecutionException e) {
|
|
||||||
logger.error("The input scope "+scope+" not found", e);
|
|
||||||
ExceptionManager.throwBadRequestException(req, "The input 'scope' "+"+scope+"+ "not found on Informatiion System. Is it a valid VRE?", this.getClass(), helpURI);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}else{
|
|
||||||
logger.error("The input scope "+scope+" is not a VRE");
|
|
||||||
ExceptionManager.throwBadRequestException(req, "The input 'scope' "+"+scope+"+ "is not a VRE", this.getClass(), helpURI);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory;
|
||||||
*
|
*
|
||||||
* Oct 19, 2018
|
* Oct 19, 2018
|
||||||
*/
|
*/
|
||||||
@Path("/")
|
@Path("storage")
|
||||||
public class StorageIDResolver {
|
public class StorageIDResolver {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,7 +1,18 @@
|
||||||
<application mode='online'>
|
<application mode='online'>
|
||||||
<name>URIResolver</name>
|
<name>URIResolver</name>
|
||||||
<group>DataTransfer</group>
|
<group>DataTransfer</group>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<description>URIResolver RESTful</description>
|
<description>URIResolver RESTful</description>
|
||||||
<exclude handlers='request-validation context-retriever'>/*</exclude>
|
<exclude handlers='request-validation context-retriever'>/smp</exclude>
|
||||||
|
<exclude handlers='request-validation context-retriever'>/id</exclude>
|
||||||
|
<exclude handlers='request-validation context-retriever'>/gis</exclude>
|
||||||
|
<exclude handlers='request-validation context-retriever'>/storage*</exclude>
|
||||||
|
<exclude handlers='request-validation context-retriever'>/ctlg*</exclude>
|
||||||
|
<exclude handlers='request-validation context-retriever'>/catalogue</exclude>
|
||||||
|
<exclude handlers='request-validation context-retriever'>/geonetwork</exclude>
|
||||||
|
<exclude handlers='request-validation context-retriever'>/shub</exclude>
|
||||||
|
<exclude handlers='request-validation context-retriever'>/parthenos_registry</exclude>
|
||||||
|
<exclude handlers='request-validation context-retriever'>/analytics/get</exclude>
|
||||||
|
<exclude handlers='request-validation context-retriever'>/knime/get</exclude>
|
||||||
|
|
||||||
</application>
|
</application>
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<dataminer-invocation>
|
||||||
|
<operator-id>THE_OPERATOR_ID</operator-id>
|
||||||
|
<parameters>
|
||||||
|
<input>
|
||||||
|
<param>
|
||||||
|
<key>key1</key>
|
||||||
|
<value>value1</value>
|
||||||
|
</param>
|
||||||
|
<param>
|
||||||
|
<key>key2</key>
|
||||||
|
<value>value2</value>
|
||||||
|
</param>
|
||||||
|
</input>
|
||||||
|
<output/>
|
||||||
|
</parameters>
|
||||||
|
</dataminer-invocation>
|
Loading…
Reference in New Issue