fixing documentation
This commit is contained in:
parent
fd9a10be6c
commit
2881f76ed0
2
pom.xml
2
pom.xml
|
@ -11,7 +11,7 @@
|
||||||
<artifactId>uri-resolver</artifactId>
|
<artifactId>uri-resolver</artifactId>
|
||||||
<version>2.7.1-SNAPSHOT</version>
|
<version>2.7.1-SNAPSHOT</version>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
<description>The URI Resolver is an HTTP URI resolver implemented as an REST service which gives access trough HTTP to different gcube Resolvers and gCube Applications.</description>
|
<description>The URI Resolver is an HTTP URI resolver implemented as a REST service which gives access trough HTTP to different gcube Resolvers and gCube Applications.</description>
|
||||||
|
|
||||||
<scm>
|
<scm>
|
||||||
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
|
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package org.gcube.datatransfer.resolver.catalogue;
|
package org.gcube.datatransfer.resolver.catalogue;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class CatalogueRequest.
|
* The Class CatalogueRequest.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
* Nov 6, 2018
|
|
||||||
*
|
*
|
||||||
* Binding Catalogue Request as a JSON
|
* Mar 24, 2022
|
||||||
|
*
|
||||||
|
* Binding Catalogue Request as a JSON
|
||||||
*/
|
*/
|
||||||
public class CatalogueRequest {
|
public class CatalogueRequest {
|
||||||
|
|
||||||
|
@ -42,7 +42,14 @@ public class CatalogueRequest {
|
||||||
return entity_name;
|
return entity_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/**
|
||||||
|
* To string.
|
||||||
|
*
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see java.lang.Object#toString()
|
* @see java.lang.Object#toString()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -11,20 +11,41 @@ import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Instantiates a new parthenos request.
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
||||||
* Nov 26, 2018
|
|
||||||
*/
|
*/
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new parthenos request.
|
||||||
|
*
|
||||||
|
* @param entity_name the entity name
|
||||||
|
*/
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the entity name.
|
||||||
|
*
|
||||||
|
* @return the entity name
|
||||||
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the entity name.
|
||||||
|
*
|
||||||
|
* @param entity_name the new entity name
|
||||||
|
*/
|
||||||
@Setter
|
@Setter
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To string.
|
||||||
|
*
|
||||||
|
* @return the java.lang. string
|
||||||
|
*/
|
||||||
@ToString
|
@ToString
|
||||||
public class ParthenosRequest {
|
public class ParthenosRequest {
|
||||||
|
|
||||||
@JsonProperty(value="entity_name", required=true)
|
@JsonProperty(value = "entity_name", required = true)
|
||||||
private String entity_name;
|
private String entity_name;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ import org.xml.sax.SAXException;
|
||||||
* The Class AnalyticsCreateResolver.
|
* The Class AnalyticsCreateResolver.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||||
* Dec 12, 2018
|
* Dec 12, 2018
|
||||||
*/
|
*/
|
||||||
@Path("analytics")
|
@Path("analytics")
|
||||||
public class AnalyticsCreateResolver {
|
public class AnalyticsCreateResolver {
|
||||||
|
@ -77,11 +77,10 @@ public class AnalyticsCreateResolver {
|
||||||
private static Logger logger = LoggerFactory.getLogger(AnalyticsCreateResolver.class);
|
private static Logger logger = LoggerFactory.getLogger(AnalyticsCreateResolver.class);
|
||||||
private static String helpURI = "https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Analytics_Resolver";
|
private static String helpURI = "https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Analytics_Resolver";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the analytics url.
|
* Creates the analytics url.
|
||||||
*
|
*
|
||||||
* @param req the req
|
* @param req the req
|
||||||
* @param body the body
|
* @param body the body
|
||||||
* @return the response
|
* @return the response
|
||||||
* @throws WebApplicationException the web application exception
|
* @throws WebApplicationException the web application exception
|
||||||
|
@ -90,58 +89,65 @@ public class AnalyticsCreateResolver {
|
||||||
@Path("/create")
|
@Path("/create")
|
||||||
@Consumes(MediaType.TEXT_PLAIN)
|
@Consumes(MediaType.TEXT_PLAIN)
|
||||||
@Produces(MediaType.TEXT_PLAIN)
|
@Produces(MediaType.TEXT_PLAIN)
|
||||||
public Response createAnalyticsURL(@Context HttpServletRequest req, String body) throws WebApplicationException{
|
public Response createAnalyticsURL(@Context HttpServletRequest req, String body) throws WebApplicationException {
|
||||||
logger.info(this.getClass().getSimpleName()+" POST starts...");
|
logger.info(this.getClass().getSimpleName() + " POST starts...");
|
||||||
|
|
||||||
try{
|
try {
|
||||||
logger.info("body is: "+body);
|
logger.info("body is: " + body);
|
||||||
|
|
||||||
DataMinerInvocation jsonRequest = null;
|
DataMinerInvocation jsonRequest = null;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
jsonRequest = DataMinerInvocationManager.getInstance().unmarshalingJSON(IOUtils.toInputStream(body), true);
|
jsonRequest = DataMinerInvocationManager.getInstance().unmarshalingJSON(IOUtils.toInputStream(body),
|
||||||
}
|
true);
|
||||||
catch (IOException | JAXBException | SAXException e1) {
|
} catch (IOException | JAXBException | SAXException e1) {
|
||||||
logger.error("The body is not a valid DataMinerInvocation JSON request",e1);
|
logger.error("The body is not a valid DataMinerInvocation JSON request", e1);
|
||||||
throw ExceptionManager.badRequestException(req, "Bad 'dataminer-invocation' JSON request: \n"+e1.getCause().getMessage(), this.getClass(), helpURI);
|
throw ExceptionManager.badRequestException(req,
|
||||||
|
"Bad 'dataminer-invocation' JSON request: \n" + e1.getCause().getMessage(), this.getClass(),
|
||||||
|
helpURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("The body contains the request: "+jsonRequest.toString());
|
logger.debug("The body contains the request: " + jsonRequest.toString());
|
||||||
|
|
||||||
String contextToken = SecurityTokenProvider.instance.get();
|
String contextToken = SecurityTokenProvider.instance.get();
|
||||||
String scope = ScopeProvider.instance.get();
|
String scope = ScopeProvider.instance.get();
|
||||||
// logger.info("SecurityTokenProvider contextToken: "+contextToken);
|
// logger.info("SecurityTokenProvider contextToken: "+contextToken);
|
||||||
logger.info("ScopeProvider has scope: "+scope);
|
logger.info("ScopeProvider has scope: " + scope);
|
||||||
|
|
||||||
String appToken = req.getServletContext().getInitParameter(RequestHandler.ROOT_APP_TOKEN);
|
String appToken = req.getServletContext().getInitParameter(RequestHandler.ROOT_APP_TOKEN);
|
||||||
|
|
||||||
if(contextToken.compareTo(appToken)==0){
|
if (contextToken.compareTo(appToken) == 0) {
|
||||||
logger.error("Token not passed, SecurityTokenProvider contains the root app token: "+appToken.substring(0,10)+"...");
|
logger.error("Token not passed, SecurityTokenProvider contains the root app token: "
|
||||||
throw ExceptionManager.unauthorizedException(req, "You are not authorized. You must pass a token of VRE", this.getClass(), helpURI);
|
+ appToken.substring(0, 10) + "...");
|
||||||
|
throw ExceptionManager.unauthorizedException(req,
|
||||||
|
"You are not authorized. You must pass a token of VRE", this.getClass(), helpURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
String operatorID = jsonRequest.getOperatorId();
|
String operatorID = jsonRequest.getOperatorId();
|
||||||
|
|
||||||
if(scope==null || scope.isEmpty()){
|
if (scope == null || scope.isEmpty()) {
|
||||||
logger.error("The parameter 'scope' not found or empty in the JSON object");
|
logger.error("The parameter 'scope' not found or empty in the JSON object");
|
||||||
throw ExceptionManager.badRequestException(req, "Mandatory body parameter 'scope' not found or empty in the JSON object", this.getClass(), helpURI);
|
throw ExceptionManager.badRequestException(req,
|
||||||
|
"Mandatory body parameter 'scope' not found or empty in the JSON object", this.getClass(),
|
||||||
|
helpURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (operatorID == null || operatorID.isEmpty()) {
|
||||||
if(operatorID==null || operatorID.isEmpty()){
|
|
||||||
logger.error("The parameter 'operatorId' not found or empty in the JSON object");
|
logger.error("The parameter 'operatorId' not found or empty in the JSON object");
|
||||||
throw ExceptionManager.badRequestException(req, "Mandatory body parameter 'operatorId' not found or empty in the JSON object", this.getClass(), helpURI);
|
throw ExceptionManager.badRequestException(req,
|
||||||
|
"Mandatory body parameter 'operatorId' not found or empty in the JSON object", this.getClass(),
|
||||||
|
helpURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopeBean scopeBean = new ScopeBean(scope);
|
ScopeBean scopeBean = new ScopeBean(scope);
|
||||||
String publicLinkToDMInvFile = "";
|
String publicLinkToDMInvFile = "";
|
||||||
|
|
||||||
if(scopeBean.is(Type.VRE)){
|
if (scopeBean.is(Type.VRE)) {
|
||||||
String vreName = scopeBean.name();
|
String vreName = scopeBean.name();
|
||||||
|
|
||||||
String analyticsGetResolverURL = String.format("%s/%s", Util.getServerURL(req), "analytics/get");
|
String analyticsGetResolverURL = String.format("%s/%s", Util.getServerURL(req), "analytics/get");
|
||||||
//Creating DM invocation file
|
// Creating DM invocation file
|
||||||
if(jsonRequest.getActionType()==null)
|
if (jsonRequest.getActionType() == null)
|
||||||
jsonRequest.setActionType(ActionType.RUN);
|
jsonRequest.setActionType(ActionType.RUN);
|
||||||
|
|
||||||
File tempInvocationFile = null;
|
File tempInvocationFile = null;
|
||||||
|
@ -150,17 +156,20 @@ public class AnalyticsCreateResolver {
|
||||||
String xmlRequest = DataMinerInvocationManager.getInstance().marshalingXML(jsonRequest, true, true);
|
String xmlRequest = DataMinerInvocationManager.getInstance().marshalingXML(jsonRequest, true, true);
|
||||||
String uniqueName = createDMInvocationFileName(jsonRequest.getOperatorId());
|
String uniqueName = createDMInvocationFileName(jsonRequest.getOperatorId());
|
||||||
tempInvocationFile = createTempFile(uniqueName, ".xml", xmlRequest.getBytes());
|
tempInvocationFile = createTempFile(uniqueName, ".xml", xmlRequest.getBytes());
|
||||||
logger.info("Created StorageHubClient Instance, uploading file: "+tempInvocationFile.getName());
|
logger.info("Created StorageHubClient Instance, uploading file: " + tempInvocationFile.getName());
|
||||||
|
|
||||||
AuthorizationEntry entry = authorizationService().get(contextToken);
|
AuthorizationEntry entry = authorizationService().get(contextToken);
|
||||||
//retrieve the info of the token owner
|
// retrieve the info of the token owner
|
||||||
ClientInfo clientInfo = entry.getClientInfo();
|
ClientInfo clientInfo = entry.getClientInfo();
|
||||||
String owner = clientInfo.getId(); //IS THIS THE USERNAME?
|
String owner = clientInfo.getId(); // IS THIS THE USERNAME?
|
||||||
|
|
||||||
String infra = ScopeUtil.getInfrastructureNameFromScope(ScopeProvider.instance.get());
|
String infra = ScopeUtil.getInfrastructureNameFromScope(ScopeProvider.instance.get());
|
||||||
String theAppToken = readApplicationTokenFromSE(req, infra);
|
String theAppToken = readApplicationTokenFromSE(req, infra);
|
||||||
|
|
||||||
logger.info("By using infra scope: "+infra +" and the Application Token: "+theAppToken.substring(0,theAppToken.length()/2)+"... of "+ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME+" to instance the "+StorageHubManagement.class.getSimpleName());
|
logger.info("By using infra scope: " + infra + " and the Application Token: "
|
||||||
|
+ theAppToken.substring(0, theAppToken.length() / 2) + "... of "
|
||||||
|
+ ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME + " to instance the "
|
||||||
|
+ StorageHubManagement.class.getSimpleName());
|
||||||
ScopeProvider.instance.set(infra);
|
ScopeProvider.instance.set(infra);
|
||||||
ApplicationMode applicationMode = new ApplicationMode(theAppToken);
|
ApplicationMode applicationMode = new ApplicationMode(theAppToken);
|
||||||
applicationMode.start();
|
applicationMode.start();
|
||||||
|
@ -170,140 +179,159 @@ public class AnalyticsCreateResolver {
|
||||||
Map<String, String> theMap = new HashMap<String, String>();
|
Map<String, String> theMap = new HashMap<String, String>();
|
||||||
theMap.put("owner", owner);
|
theMap.put("owner", owner);
|
||||||
URL thePublicLink = null;
|
URL thePublicLink = null;
|
||||||
try{
|
try {
|
||||||
|
|
||||||
logger.info("Saving dataminer-invocation file for the user: "+owner);
|
logger.info("Saving dataminer-invocation file for the user: " + owner);
|
||||||
thePublicLink = storageHubManagement.persistFile(new FileInputStream(tempInvocationFile), tempInvocationFile.getName(), "application/xml", metadata);
|
thePublicLink = storageHubManagement.persistFile(new FileInputStream(tempInvocationFile),
|
||||||
logger.info("Saved dataminer-invocation file at: "+thePublicLink);
|
tempInvocationFile.getName(), "application/xml", metadata);
|
||||||
}catch(Exception e){
|
logger.info("Saved dataminer-invocation file at: " + thePublicLink);
|
||||||
|
} catch (Exception e) {
|
||||||
logger.error("Error when storing your 'dataminer-invocation':", e);
|
logger.error("Error when storing your 'dataminer-invocation':", e);
|
||||||
throw ExceptionManager.internalErrorException(req, "Error when storing your 'dataminer-invocation' request with "+jsonRequest+". \nPlease contact the support", this.getClass(), helpURI);
|
throw ExceptionManager
|
||||||
|
.internalErrorException(
|
||||||
|
req, "Error when storing your 'dataminer-invocation' request with "
|
||||||
|
+ jsonRequest + ". \nPlease contact the support",
|
||||||
|
this.getClass(), helpURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FileContainer fileContainer = shc.getWSRoot().uploadFile(new FileInputStream(tempInvocationFile), tempInvocationFile.getName(), "DataMinerInvocation Request created by "+this.getClass().getSimpleName());
|
// FileContainer fileContainer = shc.getWSRoot().uploadFile(new FileInputStream(tempInvocationFile), tempInvocationFile.getName(), "DataMinerInvocation Request created by "+this.getClass().getSimpleName());
|
||||||
// logger.info("UPLOADED FILE at: "+fileContainer.getPublicLink());
|
// logger.info("UPLOADED FILE at: "+fileContainer.getPublicLink());
|
||||||
// URL thePublicLink = fileContainer.getPublicLink();
|
// URL thePublicLink = fileContainer.getPublicLink();
|
||||||
publicLinkToDMInvFile = thePublicLink!=null?thePublicLink.toString():null;
|
publicLinkToDMInvFile = thePublicLink != null ? thePublicLink.toString() : null;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
|
|
||||||
if(e instanceof InternalServerException){
|
if (e instanceof InternalServerException) {
|
||||||
//error during storing the file via StorageHubManagent
|
// error during storing the file via StorageHubManagent
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
logger.error("Error on creating 'dataminer-invocation:", e);
|
logger.error("Error on creating 'dataminer-invocation:", e);
|
||||||
throw ExceptionManager.badRequestException(req, "Error on creating your 'dataminer-invocation' request with "+jsonRequest+". \nPlease contact the support", this.getClass(), helpURI);
|
throw ExceptionManager.badRequestException(req,
|
||||||
}finally{
|
"Error on creating your 'dataminer-invocation' request with " + jsonRequest
|
||||||
//No needed to reset the scope, it is provided by TokenSetter
|
+ ". \nPlease contact the support",
|
||||||
try{
|
this.getClass(), helpURI);
|
||||||
//DELETING THE TEMP FILE
|
} finally {
|
||||||
if(tempInvocationFile!=null && tempInvocationFile.exists())
|
// No needed to reset the scope, it is provided by TokenSetter
|
||||||
tempInvocationFile.delete();
|
try {
|
||||||
}catch(Exception e){
|
// DELETING THE TEMP FILE
|
||||||
//silent
|
if (tempInvocationFile != null && tempInvocationFile.exists())
|
||||||
|
tempInvocationFile.delete();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// silent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(publicLinkToDMInvFile==null){
|
if (publicLinkToDMInvFile == null) {
|
||||||
logger.error("Error on creating the public link to file");
|
logger.error("Error on creating the public link to file");
|
||||||
throw ExceptionManager.badRequestException(req, "Error on getting link to your 'dataminer-invocation' request. Plese contact the support "+jsonRequest, this.getClass(), helpURI);
|
throw ExceptionManager.badRequestException(req,
|
||||||
|
"Error on getting link to your 'dataminer-invocation' request. Plese contact the support "
|
||||||
|
+ jsonRequest,
|
||||||
|
this.getClass(), helpURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
String dataMinerURL = String.format("%s/%s?%s=%s", analyticsGetResolverURL, vreName, DATAMINER_INVOCATION_MODEL, publicLinkToDMInvFile);
|
String dataMinerURL = String.format("%s/%s?%s=%s", analyticsGetResolverURL, vreName,
|
||||||
logger.info("Returning Analytics URL: "+dataMinerURL);
|
DATAMINER_INVOCATION_MODEL, publicLinkToDMInvFile);
|
||||||
|
logger.info("Returning Analytics URL: " + dataMinerURL);
|
||||||
return Response.ok(dataMinerURL).header("Location", dataMinerURL).build();
|
return Response.ok(dataMinerURL).header("Location", dataMinerURL).build();
|
||||||
|
|
||||||
}else{
|
} else {
|
||||||
logger.error("The input scope "+scope+" is not a VRE");
|
logger.error("The input scope " + scope + " is not a VRE");
|
||||||
throw ExceptionManager.badRequestException(req, "Working in the "+scope+" scope that is not a VRE. Use a token of VRE", this.getClass(), helpURI);
|
throw ExceptionManager.badRequestException(req,
|
||||||
|
"Working in the " + scope + " scope that is not a VRE. Use a token of VRE", this.getClass(),
|
||||||
|
helpURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
if(!(e instanceof WebApplicationException)){
|
if (!(e instanceof WebApplicationException)) {
|
||||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||||
String error = "Error occurred on creating the Analytics for the request "+body+". Please, contact the support!";
|
String error = "Error occurred on creating the Analytics for the request " + body
|
||||||
if(e.getCause()!=null)
|
+ ". Please, contact the support!";
|
||||||
error+="\n\nCaused: "+e.getCause().getMessage();
|
if (e.getCause() != null)
|
||||||
|
error += "\n\nCaused: " + e.getCause().getMessage();
|
||||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||||
}
|
}
|
||||||
//ALREADY MANAGED AS WebApplicationException
|
// ALREADY MANAGED AS WebApplicationException
|
||||||
logger.error("Exception:", e);
|
logger.error("Exception:", e);
|
||||||
throw (WebApplicationException) e;
|
throw (WebApplicationException) e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the Application Token from Service Endpoint {@link AnalyticsCreateResolver#ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME}
|
* Reads the Application Token from Service Endpoint
|
||||||
|
* {@link AnalyticsCreateResolver#ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME}
|
||||||
*
|
*
|
||||||
* @param req the req
|
* @param req the req
|
||||||
* @param scope the scope
|
* @param scope the scope
|
||||||
* @return the string
|
* @return the string
|
||||||
*/
|
*/
|
||||||
private static String readApplicationTokenFromSE(HttpServletRequest req, String scope){
|
private static String readApplicationTokenFromSE(HttpServletRequest req, String scope) {
|
||||||
|
|
||||||
String callerScope = null;
|
String callerScope = null;
|
||||||
String gCubeAppToken = null;
|
String gCubeAppToken = null;
|
||||||
try{
|
try {
|
||||||
callerScope = ScopeProvider.instance.get();
|
callerScope = ScopeProvider.instance.get();
|
||||||
ScopeProvider.instance.set(scope);
|
ScopeProvider.instance.set(scope);
|
||||||
logger.info("Searching SE "+ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME+" configurations in the scope: "+ScopeProvider.instance.get());
|
logger.info("Searching SE " + ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME + " configurations in the scope: "
|
||||||
|
+ ScopeProvider.instance.get());
|
||||||
|
|
||||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||||
query.addCondition("$resource/Profile/Name/text() eq '"+ ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME +"'");
|
query.addCondition("$resource/Profile/Name/text() eq '" + ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME + "'");
|
||||||
query.addCondition("$resource/Profile/Category/text() eq 'Service'");
|
query.addCondition("$resource/Profile/Category/text() eq 'Service'");
|
||||||
|
|
||||||
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
||||||
List<ServiceEndpoint> toReturn = client.submit(query);
|
List<ServiceEndpoint> toReturn = client.submit(query);
|
||||||
|
|
||||||
logger.info("The query returned "+toReturn.size()+ " ServiceEndpoint/s");
|
logger.info("The query returned " + toReturn.size() + " ServiceEndpoint/s");
|
||||||
|
|
||||||
if(toReturn.size()==0){
|
if (toReturn.size() == 0) {
|
||||||
String errorMessage = "No "+ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME+" registered in the scope: "+ScopeProvider.instance.get();
|
String errorMessage = "No " + ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME + " registered in the scope: "
|
||||||
|
+ ScopeProvider.instance.get();
|
||||||
logger.error(errorMessage);
|
logger.error(errorMessage);
|
||||||
throw ExceptionManager.internalErrorException(req, errorMessage, AnalyticsCreateResolver.class, helpURI);
|
throw ExceptionManager.internalErrorException(req, errorMessage, AnalyticsCreateResolver.class,
|
||||||
|
helpURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ServiceEndpoint se = toReturn.get(0);
|
ServiceEndpoint se = toReturn.get(0);
|
||||||
Collection<AccessPoint> theAccessPoints = se.profile().accessPoints().asCollection();
|
Collection<AccessPoint> theAccessPoints = se.profile().accessPoints().asCollection();
|
||||||
for (AccessPoint accessPoint : theAccessPoints) {
|
for (AccessPoint accessPoint : theAccessPoints) {
|
||||||
Collection<Property> properties = accessPoint.properties().asCollection();
|
Collection<Property> properties = accessPoint.properties().asCollection();
|
||||||
for (Property property : properties) {
|
for (Property property : properties) {
|
||||||
if(property.name().equalsIgnoreCase(GCUBE_TOKEN)){
|
if (property.name().equalsIgnoreCase(GCUBE_TOKEN)) {
|
||||||
logger.info("gcube-token as property was found, returning it");
|
logger.info("gcube-token as property was found, returning it");
|
||||||
gCubeAppToken = property.value();
|
gCubeAppToken = property.value();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(gCubeAppToken!=null)
|
if (gCubeAppToken != null)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(gCubeAppToken!=null){
|
if (gCubeAppToken != null) {
|
||||||
String decryptedPassword = StringEncrypter.getEncrypter().decrypt(gCubeAppToken);
|
String decryptedPassword = StringEncrypter.getEncrypter().decrypt(gCubeAppToken);
|
||||||
logger.info("Returning decrypted Application Token registered into "+ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME +" SE: "+decryptedPassword.substring(0,decryptedPassword.length()/2)+"....");
|
logger.info("Returning decrypted Application Token registered into "
|
||||||
|
+ ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME + " SE: "
|
||||||
|
+ decryptedPassword.substring(0, decryptedPassword.length() / 2) + "....");
|
||||||
return decryptedPassword;
|
return decryptedPassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String errorMessage = "No " + GCUBE_TOKEN + " as Property saved in the "
|
||||||
String errorMessage = "No "+GCUBE_TOKEN+" as Property saved in the "+ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME+" SE registered in the scope: "+ScopeProvider.instance.get();
|
+ ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME + " SE registered in the scope: "
|
||||||
|
+ ScopeProvider.instance.get();
|
||||||
logger.error(errorMessage);
|
logger.error(errorMessage);
|
||||||
throw ExceptionManager.internalErrorException(req, errorMessage, AnalyticsCreateResolver.class, helpURI);
|
throw ExceptionManager.internalErrorException(req, errorMessage, AnalyticsCreateResolver.class, helpURI);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
}catch(Exception e){
|
String errorMessage = "Error occurred on reading the " + ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME
|
||||||
String errorMessage = "Error occurred on reading the "+ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME+" SE registered in the scope: "+ScopeProvider.instance.get();
|
+ " SE registered in the scope: " + ScopeProvider.instance.get();
|
||||||
logger.error(errorMessage, e);
|
logger.error(errorMessage, e);
|
||||||
throw ExceptionManager.internalErrorException(req, errorMessage, AnalyticsCreateResolver.class, helpURI);
|
throw ExceptionManager.internalErrorException(req, errorMessage, AnalyticsCreateResolver.class, helpURI);
|
||||||
|
|
||||||
}finally{
|
} finally {
|
||||||
if(callerScope!=null){
|
if (callerScope != null) {
|
||||||
logger.info("Setting to the callerScope scope: "+callerScope);
|
logger.info("Setting to the callerScope scope: " + callerScope);
|
||||||
ScopeProvider.instance.set(callerScope);
|
ScopeProvider.instance.set(callerScope);
|
||||||
}else{
|
} else {
|
||||||
logger.info("Reset scope");
|
logger.info("Reset scope");
|
||||||
ScopeProvider.instance.reset();
|
ScopeProvider.instance.reset();
|
||||||
}
|
}
|
||||||
|
@ -311,48 +339,38 @@ public class AnalyticsCreateResolver {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 Temp File: " + file.getAbsolutePath());
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the temp file.
|
* Creates the dm invocation file name.
|
||||||
*
|
*
|
||||||
* @param fileName the file name
|
* @param operatorId the operator id
|
||||||
* @param extension the extension
|
* @return the string
|
||||||
* @param data the data
|
*/
|
||||||
* @return the file
|
private static String createDMInvocationFileName(String operatorId) {
|
||||||
* @throws IOException Signals that an I/O exception has occurred.
|
String fileName = "dim";
|
||||||
*/
|
int index = operatorId.lastIndexOf(".");
|
||||||
private static File createTempFile(String fileName, String extension, byte[] data) throws IOException {
|
if (index > 0 && index < operatorId.length()) {
|
||||||
// Since Java 1.7 Files and Path API simplify operations on files
|
fileName += "-" + operatorId.substring(index + 1, operatorId.length());
|
||||||
java.nio.file.Path path = Files.createTempFile(fileName, extension);
|
}
|
||||||
File file = path.toFile();
|
fileName += "-" + System.currentTimeMillis();
|
||||||
// writing sample data
|
|
||||||
Files.write(path, data);
|
|
||||||
logger.info("Created the Temp File: "+file.getAbsolutePath());
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the dm invocation file name.
|
|
||||||
*
|
|
||||||
* @param operatorId the operator id
|
|
||||||
* @return the string
|
|
||||||
*/
|
|
||||||
private static String createDMInvocationFileName(String operatorId){
|
|
||||||
String fileName = "dim";
|
|
||||||
int index = operatorId.lastIndexOf(".");
|
|
||||||
if(index>0 && index<operatorId.length()){
|
|
||||||
fileName+="-"+operatorId.substring(index+1,operatorId.length());
|
|
||||||
}
|
|
||||||
fileName+="-"+System.currentTimeMillis();
|
|
||||||
return fileName;
|
return fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// public static void main(String[] args) {
|
|
||||||
//
|
|
||||||
// System.out.println(readApplicationTokenFromSE(null, "/gcube"));
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,20 +23,19 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
|
import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class AnalyticsGetResolver.
|
* The Class AnalyticsGetResolver.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
* Dec 13, 2018
|
*
|
||||||
|
* Mar 24, 2022
|
||||||
*/
|
*/
|
||||||
@Path("analytics")
|
@Path("analytics")
|
||||||
public class AnalyticsGetResolver {
|
public class AnalyticsGetResolver {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(AnalyticsGetResolver.class);
|
private static Logger logger = LoggerFactory.getLogger(AnalyticsGetResolver.class);
|
||||||
|
|
||||||
private static final String ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL =
|
private static final String ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL = "org.gcube.portlets.user.dataminermanager.server.DataMinerManagerServiceImpl";
|
||||||
"org.gcube.portlets.user.dataminermanager.server.DataMinerManagerServiceImpl";
|
|
||||||
|
|
||||||
private static final String APPLICATION_PROFILE = "ApplicationProfile";
|
private static final String APPLICATION_PROFILE = "ApplicationProfile";
|
||||||
|
|
||||||
|
@ -44,60 +43,70 @@ public class AnalyticsGetResolver {
|
||||||
|
|
||||||
private static final String ANALYTICS_EXECUTOR_PORTLET_NAME = "Analytics Executor";
|
private static final String ANALYTICS_EXECUTOR_PORTLET_NAME = "Analytics Executor";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve analytics url.
|
* Resolve analytics url.
|
||||||
*
|
*
|
||||||
* @param req the req
|
* @param req the req
|
||||||
* @param vreName the vre name
|
* @param vreName the vre name
|
||||||
* @return the response
|
* @return the response
|
||||||
|
* @throws WebApplicationException the web application exception
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("/get/{vreName}")
|
@Path("/get/{vreName}")
|
||||||
public Response resolveAnalyticsURL(@Context HttpServletRequest req, @PathParam("vreName") String vreName) throws WebApplicationException{
|
public Response resolveAnalyticsURL(@Context HttpServletRequest req, @PathParam("vreName") String vreName)
|
||||||
logger.info(this.getClass().getSimpleName()+" GET starts...");
|
throws WebApplicationException {
|
||||||
|
logger.info(this.getClass().getSimpleName() + " GET starts...");
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if(vreName==null || vreName.isEmpty()){
|
if (vreName == null || vreName.isEmpty()) {
|
||||||
logger.error("The path parameter 'vreName' not found or empty in the path");
|
logger.error("The path parameter 'vreName' not found or empty in the path");
|
||||||
throw ExceptionManager.badRequestException(req, "Mandatory path parameter 'vreName' not found or empty", this.getClass(), helpURI);
|
throw ExceptionManager.badRequestException(req, "Mandatory path parameter 'vreName' not found or empty",
|
||||||
|
this.getClass(), helpURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopeBean fullScopeBean = null;
|
ScopeBean fullScopeBean = null;
|
||||||
|
|
||||||
//CHECKING IF THE INPUT VRE NAME IS REGISTRED IN THE INFRASTRUCTURE...
|
// CHECKING IF THE INPUT VRE NAME IS REGISTRED IN THE INFRASTRUCTURE...
|
||||||
try{
|
try {
|
||||||
fullScopeBean = LoadingMapOfScopeCache.get(vreName);
|
fullScopeBean = LoadingMapOfScopeCache.get(vreName);
|
||||||
}catch(ExecutionException | InvalidCacheLoadException e){
|
} catch (ExecutionException | InvalidCacheLoadException e) {
|
||||||
logger.error("Error on getting the fullscope from cache for vreName "+vreName, e);
|
logger.error("Error on getting the fullscope from cache for vreName " + vreName, e);
|
||||||
throw ExceptionManager.wrongParameterException(req, "Error on getting full scope for the VRE name "+vreName+". Is it registered as VRE in the D4Science Infrastructure System?", this.getClass(), helpURI);
|
throw ExceptionManager.wrongParameterException(req,
|
||||||
|
"Error on getting full scope for the VRE name " + vreName
|
||||||
|
+ ". Is it registered as VRE in the D4Science Infrastructure System?",
|
||||||
|
this.getClass(), helpURI);
|
||||||
}
|
}
|
||||||
ApplicationProfileReader reader = null;
|
ApplicationProfileReader reader = null;
|
||||||
try{
|
try {
|
||||||
reader = new ApplicationProfileReader(fullScopeBean.toString(), APPLICATION_PROFILE, ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL, false);
|
reader = new ApplicationProfileReader(fullScopeBean.toString(), APPLICATION_PROFILE,
|
||||||
}catch(Exception e){
|
ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL, false);
|
||||||
logger.error("Error on reading the "+APPLICATION_PROFILE+" with APPID: "+ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL, e);
|
} catch (Exception e) {
|
||||||
throw ExceptionManager.internalErrorException(req, "Error on reading the Application Profile for the "+ANALYTICS_EXECUTOR_PORTLET_NAME+". Please contact the support", this.getClass(), helpURI);
|
logger.error("Error on reading the " + APPLICATION_PROFILE + " with APPID: "
|
||||||
|
+ ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL, e);
|
||||||
|
throw ExceptionManager.internalErrorException(req, "Error on reading the Application Profile for the "
|
||||||
|
+ ANALYTICS_EXECUTOR_PORTLET_NAME + ". Please contact the support", this.getClass(), helpURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
//READ THE DATAMINER URL PORTLET FROM APPLICATION PROFRILE IN THE SCOPE fullScope
|
// READ THE DATAMINER URL PORTLET FROM APPLICATION PROFRILE IN THE SCOPE
|
||||||
|
// fullScope
|
||||||
String analyticsExecutorEndPoint = reader.getApplicationProfile().getUrl();
|
String analyticsExecutorEndPoint = reader.getApplicationProfile().getUrl();
|
||||||
//CHECKING THE QUERY STRING
|
// CHECKING THE QUERY STRING
|
||||||
String queryString = req.getQueryString()!=null?req.getQueryString():"";
|
String queryString = req.getQueryString() != null ? req.getQueryString() : "";
|
||||||
String analitycsExecutorURL = String.format("%s?%s", analyticsExecutorEndPoint, queryString);
|
String analitycsExecutorURL = String.format("%s?%s", analyticsExecutorEndPoint, queryString);
|
||||||
logger.info("Resolving the request with the "+ANALYTICS_EXECUTOR_PORTLET_NAME+" URL: "+analitycsExecutorURL);
|
logger.info("Resolving the request with the " + ANALYTICS_EXECUTOR_PORTLET_NAME + " URL: "
|
||||||
|
+ analitycsExecutorURL);
|
||||||
return Response.seeOther(new URI(analitycsExecutorURL)).build();
|
return Response.seeOther(new URI(analitycsExecutorURL)).build();
|
||||||
|
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
if(!(e instanceof WebApplicationException)){
|
if (!(e instanceof WebApplicationException)) {
|
||||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||||
String error = "Error occurred on resolving the Analytics URL. Please, contact the support!";
|
String error = "Error occurred on resolving the Analytics URL. Please, contact the support!";
|
||||||
if(e.getCause()!=null)
|
if (e.getCause() != null)
|
||||||
error+="\n\nCaused: "+e.getCause().getMessage();
|
error += "\n\nCaused: " + e.getCause().getMessage();
|
||||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||||
}
|
}
|
||||||
//ALREADY MANAGED AS WebApplicationException
|
// ALREADY MANAGED AS WebApplicationException
|
||||||
logger.error("Exception:", e);
|
logger.error("Exception:", e);
|
||||||
throw (WebApplicationException) e;
|
throw (WebApplicationException) e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,33 +47,42 @@ import eu.trentorise.opendata.jackan.model.CkanDataset;
|
||||||
* The Class CatalogueResolver.
|
* The Class CatalogueResolver.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||||
* Nov 16, 2018
|
* Nov 16, 2018
|
||||||
*/
|
*/
|
||||||
@Path("{entityContext:ctlg(-(o|g|p|d))?}")
|
@Path("{entityContext:ctlg(-(o|g|p|d))?}")
|
||||||
public class CatalogueResolver {
|
public class CatalogueResolver {
|
||||||
|
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(CatalogueResolver.class);
|
private static Logger logger = LoggerFactory.getLogger(CatalogueResolver.class);
|
||||||
private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#CATALOGUE_Resolver";
|
private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#CATALOGUE_Resolver";
|
||||||
private static enum SCOPE_STATUS {ACTIVE, DETACHED}
|
|
||||||
|
/**
|
||||||
|
* The Enum SCOPE_STATUS.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* Mar 24, 2022
|
||||||
|
*/
|
||||||
|
private static enum SCOPE_STATUS {
|
||||||
|
ACTIVE, DETACHED
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve catalogue.
|
* Resolve catalogue.
|
||||||
*
|
*
|
||||||
* @param req the req
|
* @param req the req
|
||||||
* @param entityName the entity name
|
* @param entityName the entity name
|
||||||
* @param vreName the vre name
|
* @param vreName the vre name
|
||||||
* @param entityContext the entity context
|
* @param entityContext the entity context
|
||||||
* @return the response
|
* @return the response
|
||||||
|
* @throws WebApplicationException the web application exception
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("/{vreName}/{entityName}")
|
@Path("/{vreName}/{entityName}")
|
||||||
public Response resolveCatalogue(@Context HttpServletRequest req,
|
public Response resolveCatalogue(@Context HttpServletRequest req, @PathParam("entityName") String entityName,
|
||||||
@PathParam("entityName") String entityName,
|
@PathParam("vreName") String vreName, @PathParam("entityContext") String entityContext)
|
||||||
@PathParam("vreName") String vreName,
|
throws WebApplicationException {
|
||||||
@PathParam("entityContext") String entityContext) throws WebApplicationException{
|
|
||||||
|
|
||||||
logger.info(this.getClass().getSimpleName()+" GET starts...");
|
logger.info(this.getClass().getSimpleName() + " GET starts...");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
InnerMethodName.instance.set("resolveCataloguePublicLink");
|
InnerMethodName.instance.set("resolveCataloguePublicLink");
|
||||||
|
@ -81,31 +90,36 @@ public class CatalogueResolver {
|
||||||
|
|
||||||
String itemCatalogueURL;
|
String itemCatalogueURL;
|
||||||
|
|
||||||
if(itemCatalogueURLs.isPublicItem()){
|
if (itemCatalogueURLs.isPublicItem()) {
|
||||||
logger.info("The dataset "+itemCatalogueURLs.getItemName()+" was detected as public item (not private to VRE)");
|
logger.info("The dataset " + itemCatalogueURLs.getItemName()
|
||||||
if(itemCatalogueURLs.getPublicVRECataloguePortletURL()!=null && !itemCatalogueURLs.getPublicVRECataloguePortletURL().isEmpty()) {
|
+ " was detected as public item (not private to VRE)");
|
||||||
|
if (itemCatalogueURLs.getPublicVRECataloguePortletURL() != null
|
||||||
|
&& !itemCatalogueURLs.getPublicVRECataloguePortletURL().isEmpty()) {
|
||||||
itemCatalogueURL = itemCatalogueURLs.getPublicVRECataloguePortletURL();
|
itemCatalogueURL = itemCatalogueURLs.getPublicVRECataloguePortletURL();
|
||||||
logger.info("I found the public VRE catalogue URL, so using public access to it: "+itemCatalogueURL);
|
logger.info(
|
||||||
}else {
|
"I found the public VRE catalogue URL, so using public access to it: " + itemCatalogueURL);
|
||||||
|
} else {
|
||||||
itemCatalogueURL = itemCatalogueURLs.getPublicGatewayCataloguePortletURL();
|
itemCatalogueURL = itemCatalogueURLs.getPublicGatewayCataloguePortletURL();
|
||||||
logger.info("No public VRE catalogue URL found, so using public access to gateway CKAN portlet: "+itemCatalogueURL);
|
logger.info("No public VRE catalogue URL found, so using public access to gateway CKAN portlet: "
|
||||||
|
+ itemCatalogueURL);
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
itemCatalogueURL = itemCatalogueURLs.getPrivateVRECataloguePortletURL();
|
itemCatalogueURL = itemCatalogueURLs.getPrivateVRECataloguePortletURL();
|
||||||
logger.info("The dataset "+itemCatalogueURLs.getItemName()+" is a private item (to VRE) so using protected access to CKAN portlet: "+itemCatalogueURL);
|
logger.info("The dataset " + itemCatalogueURLs.getItemName()
|
||||||
|
+ " is a private item (to VRE) so using protected access to CKAN portlet: " + itemCatalogueURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Response.seeOther(new URL(itemCatalogueURL).toURI()).build();
|
return Response.seeOther(new URL(itemCatalogueURL).toURI()).build();
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
if(!(e instanceof WebApplicationException)){
|
if (!(e instanceof WebApplicationException)) {
|
||||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||||
String error = "Error occurred on resolving the Catalgoue URL. Please, contact the support!";
|
String error = "Error occurred on resolving the Catalgoue URL. Please, contact the support!";
|
||||||
if(e.getCause()!=null)
|
if (e.getCause() != null)
|
||||||
error+="\n\nCaused: "+e.getCause().getMessage();
|
error += "\n\nCaused: " + e.getCause().getMessage();
|
||||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||||
}
|
}
|
||||||
//ALREADY MANAGED AS WebApplicationException
|
// ALREADY MANAGED AS WebApplicationException
|
||||||
logger.error("Exception:", e);
|
logger.error("Exception:", e);
|
||||||
throw (WebApplicationException) e;
|
throw (WebApplicationException) e;
|
||||||
}
|
}
|
||||||
|
@ -114,63 +128,72 @@ public class CatalogueResolver {
|
||||||
/**
|
/**
|
||||||
* Post catalogue.
|
* Post catalogue.
|
||||||
*
|
*
|
||||||
* @param req the req
|
* @param req the req
|
||||||
* @param jsonRequest the json request
|
* @param jsonRequest the json request
|
||||||
* @return the response
|
* @return the response
|
||||||
|
* @throws WebApplicationException the web application exception
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("")
|
@Path("")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.TEXT_PLAIN)
|
@Produces(MediaType.TEXT_PLAIN)
|
||||||
public Response postCatalogue(@Context HttpServletRequest req, CatalogueRequest jsonRequest) throws WebApplicationException{
|
public Response postCatalogue(@Context HttpServletRequest req, CatalogueRequest jsonRequest)
|
||||||
logger.info(this.getClass().getSimpleName()+" POST starts...");
|
throws WebApplicationException {
|
||||||
|
logger.info(this.getClass().getSimpleName() + " POST starts...");
|
||||||
|
|
||||||
try{
|
try {
|
||||||
|
|
||||||
InnerMethodName.instance.set("postCataloguePublicLink");
|
InnerMethodName.instance.set("postCataloguePublicLink");
|
||||||
logger.info("The body contains the request: "+jsonRequest.toString());
|
logger.info("The body contains the request: " + jsonRequest.toString());
|
||||||
|
|
||||||
//CHECK IF INPUT SCOPE IS VALID
|
// CHECK IF INPUT SCOPE IS VALID
|
||||||
String scope = jsonRequest.getGcube_scope();
|
String scope = jsonRequest.getGcube_scope();
|
||||||
if(!scope.startsWith(ConstantsResolver.SCOPE_SEPARATOR)){
|
if (!scope.startsWith(ConstantsResolver.SCOPE_SEPARATOR)) {
|
||||||
logger.info("Scope not start with char '{}' adding it",ConstantsResolver.SCOPE_SEPARATOR);
|
logger.info("Scope not start with char '{}' adding it", ConstantsResolver.SCOPE_SEPARATOR);
|
||||||
scope+=ConstantsResolver.SCOPE_SEPARATOR+scope;
|
scope += ConstantsResolver.SCOPE_SEPARATOR + scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
String serverUrl = Util.getServerURL(req);
|
String serverUrl = Util.getServerURL(req);
|
||||||
|
|
||||||
final String vreName = scope.substring(scope.lastIndexOf(ConstantsResolver.SCOPE_SEPARATOR)+1, scope.length());
|
final String vreName = scope.substring(scope.lastIndexOf(ConstantsResolver.SCOPE_SEPARATOR) + 1,
|
||||||
|
scope.length());
|
||||||
ScopeBean fullScope = null;
|
ScopeBean fullScope = null;
|
||||||
|
|
||||||
//CHECK IF THE vreName has a valid scope, so it is a valid VRE
|
// CHECK IF THE vreName has a valid scope, so it is a valid VRE
|
||||||
try {
|
try {
|
||||||
fullScope = LoadingMapOfScopeCache.get(vreName);
|
fullScope = LoadingMapOfScopeCache.get(vreName);
|
||||||
}catch(ExecutionException e){
|
} catch (ExecutionException e) {
|
||||||
logger.error("Error on getting the fullscope from cache for vreName "+vreName, e);
|
logger.error("Error on getting the fullscope from cache for vreName " + vreName, e);
|
||||||
throw ExceptionManager.wrongParameterException(req, "Error on getting full scope for the VRE name "+vreName+". Is it registered as VRE in the D4Science Infrastructure System?", this.getClass(), helpURI);
|
throw ExceptionManager.wrongParameterException(req,
|
||||||
|
"Error on getting full scope for the VRE name " + vreName
|
||||||
|
+ ". Is it registered as VRE in the D4Science Infrastructure System?",
|
||||||
|
this.getClass(), helpURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fullScope==null)
|
if (fullScope == null)
|
||||||
throw ExceptionManager.notFoundException(req, "The scope '"+scope+"' does not matching any scope in the infrastructure. Is it valid?", this.getClass(), helpURI);
|
throw ExceptionManager.notFoundException(req,
|
||||||
|
"The scope '" + scope + "' does not matching any scope in the infrastructure. Is it valid?",
|
||||||
|
this.getClass(), helpURI);
|
||||||
|
|
||||||
ResourceCatalogueCodes rc = ResourceCatalogueCodes.valueOfCodeValue(jsonRequest.getEntity_context());
|
ResourceCatalogueCodes rc = ResourceCatalogueCodes.valueOfCodeValue(jsonRequest.getEntity_context());
|
||||||
if(rc==null){
|
if (rc == null) {
|
||||||
logger.error("Entity context is null/malformed");
|
logger.error("Entity context is null/malformed");
|
||||||
throw ExceptionManager.badRequestException(req, "Entity context is null/malformed", this.getClass(), helpURI);
|
throw ExceptionManager.badRequestException(req, "Entity context is null/malformed", this.getClass(),
|
||||||
|
helpURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
String linkURL = String.format("%s/%s/%s/%s", serverUrl, rc.getId(), vreName, jsonRequest.getEntity_name());
|
String linkURL = String.format("%s/%s/%s/%s", serverUrl, rc.getId(), vreName, jsonRequest.getEntity_name());
|
||||||
logger.info("Returining Catalogue URL: "+linkURL);
|
logger.info("Returining Catalogue URL: " + linkURL);
|
||||||
return Response.ok(linkURL).header("Location", linkURL).build();
|
return Response.ok(linkURL).header("Location", linkURL).build();
|
||||||
|
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
if(!(e instanceof WebApplicationException)){
|
if (!(e instanceof WebApplicationException)) {
|
||||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||||
String error = "Error occurred on resolving the Analytics URL. Please, contact the support!";
|
String error = "Error occurred on resolving the Analytics URL. Please, contact the support!";
|
||||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||||
}
|
}
|
||||||
//ALREADY MANAGED AS WebApplicationExceptiongetItemCatalogueURLs
|
// ALREADY MANAGED AS WebApplicationExceptiongetItemCatalogueURLs
|
||||||
logger.error("Exception:", e);
|
logger.error("Exception:", e);
|
||||||
throw (WebApplicationException) e;
|
throw (WebApplicationException) e;
|
||||||
}
|
}
|
||||||
|
@ -179,24 +202,27 @@ public class CatalogueResolver {
|
||||||
/**
|
/**
|
||||||
* Gets the item catalogue UR ls.
|
* Gets the item catalogue UR ls.
|
||||||
*
|
*
|
||||||
* @param req the req
|
* @param req the req
|
||||||
* @param scopeName the scope name
|
* @param scopeName the scope name
|
||||||
* @param entityContext the entity context
|
* @param entityContext the entity context
|
||||||
* @param entityName the entity name
|
* @param entityName the entity name
|
||||||
* @return the item catalogue UR ls
|
* @return the item catalogue UR ls
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
protected static ItemCatalogueURLs getItemCatalogueURLs(HttpServletRequest req, String scopeName, String entityContext, String entityName) throws Exception{
|
protected static ItemCatalogueURLs getItemCatalogueURLs(HttpServletRequest req, String scopeName,
|
||||||
|
String entityContext, String entityName) throws Exception {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String entityContextValue = ResourceCatalogueCodes.valueOfCodeId(entityContext).getValue();
|
String entityContextValue = ResourceCatalogueCodes.valueOfCodeId(entityContext).getValue();
|
||||||
ScopeBean scopeBean = null;
|
ScopeBean scopeBean = null;
|
||||||
SCOPE_STATUS scopeStatus = SCOPE_STATUS.ACTIVE;
|
SCOPE_STATUS scopeStatus = SCOPE_STATUS.ACTIVE;
|
||||||
VRE vreDetached = null;
|
VRE vreDetached = null;
|
||||||
try{
|
try {
|
||||||
scopeBean = LoadingMapOfScopeCache.get(scopeName);
|
scopeBean = LoadingMapOfScopeCache.get(scopeName);
|
||||||
}catch(ExecutionException | InvalidCacheLoadException e){
|
} catch (ExecutionException | InvalidCacheLoadException e) {
|
||||||
logger.error("Error on getting the fullscope from cache for scopeName {}. Tryng to load it from DetachedRE",scopeName);
|
logger.error(
|
||||||
|
"Error on getting the fullscope from cache for scopeName {}. Tryng to load it from DetachedRE",
|
||||||
|
scopeName);
|
||||||
|
|
||||||
boolean isScopeDetached = false;
|
boolean isScopeDetached = false;
|
||||||
try {
|
try {
|
||||||
|
@ -205,106 +231,115 @@ public class CatalogueResolver {
|
||||||
scopeStatus = SCOPE_STATUS.DETACHED;
|
scopeStatus = SCOPE_STATUS.DETACHED;
|
||||||
logger.info("I loaded a valid VRE obj for scope name {}", scopeName);
|
logger.info("I loaded a valid VRE obj for scope name {}", scopeName);
|
||||||
isScopeDetached = true;
|
isScopeDetached = true;
|
||||||
}catch (Exception e1) {
|
} catch (Exception e1) {
|
||||||
logger.warn("I was not able to load a detached VRE for vreName {}. Going to error for wrong scope",scopeName);
|
logger.warn("I was not able to load a detached VRE for vreName {}. Going to error for wrong scope",
|
||||||
|
scopeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
//If is not a cas of scope detached, going to error for wrong scope
|
// If is not a cas of scope detached, going to error for wrong scope
|
||||||
if(!isScopeDetached) {
|
if (!isScopeDetached) {
|
||||||
logger.error("Error on getting the fullscope from cache for scopeName "+scopeName, e);
|
logger.error("Error on getting the fullscope from cache for scopeName " + scopeName, e);
|
||||||
throw ExceptionManager.wrongParameterException(req, "Error on getting full scope for the scope name '"+scopeName+"'. Is it registered as a valid Scope in the D4Science Infrastructure System?", CatalogueResolver.class, helpURI);
|
throw ExceptionManager.wrongParameterException(req,
|
||||||
|
"Error on getting full scope for the scope name '" + scopeName
|
||||||
|
+ "'. Is it registered as a valid Scope in the D4Science Infrastructure System?",
|
||||||
|
CatalogueResolver.class, helpURI);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String fullScope = scopeBean.toString();
|
String fullScope = scopeBean.toString();
|
||||||
logger.info("Read fullScope: "+fullScope + " for SCOPE name: "+scopeName +" from cache created by: "+GetAllInfrastructureScopes.class.getSimpleName());
|
logger.info("Read fullScope: " + fullScope + " for SCOPE name: " + scopeName + " from cache created by: "
|
||||||
|
+ GetAllInfrastructureScopes.class.getSimpleName());
|
||||||
|
|
||||||
if(scopeBean.is(Type.VO)) {
|
if (scopeBean.is(Type.VO)) {
|
||||||
logger.info("It is a {} scope", Type.VO);
|
logger.info("It is a {} scope", Type.VO);
|
||||||
logger.warn("The Catalogue can't work at {} level, I'm overriding the scope to {} level", Type.VO, Type.INFRASTRUCTURE);
|
logger.warn("The Catalogue can't work at {} level, I'm overriding the scope to {} level", Type.VO,
|
||||||
|
Type.INFRASTRUCTURE);
|
||||||
String[] splitScope = fullScope.split(ConstantsResolver.SCOPE_SEPARATOR);
|
String[] splitScope = fullScope.split(ConstantsResolver.SCOPE_SEPARATOR);
|
||||||
fullScope = ConstantsResolver.SCOPE_SEPARATOR+splitScope[1]; //THIS IS THE INFRASTRUCTURE SCOPE
|
fullScope = ConstantsResolver.SCOPE_SEPARATOR + splitScope[1]; // THIS IS THE INFRASTRUCTURE SCOPE
|
||||||
logger.info("Overriden the input scope {} with {} as type: {}", scopeBean.toString(), Type.INFRASTRUCTURE, fullScope);
|
logger.info("Overriden the input scope {} with {} as type: {}", scopeBean.toString(),
|
||||||
|
Type.INFRASTRUCTURE, fullScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopeProvider.instance.set(fullScope);
|
ScopeProvider.instance.set(fullScope);
|
||||||
GatewayCKANCatalogueReference ckanCatalogueReference = null;
|
GatewayCKANCatalogueReference ckanCatalogueReference = null;
|
||||||
logger.info("Managing scope status: {}",scopeStatus);
|
logger.info("Managing scope status: {}", scopeStatus);
|
||||||
|
|
||||||
switch (scopeStatus) {
|
switch (scopeStatus) {
|
||||||
case DETACHED:
|
case DETACHED:
|
||||||
|
|
||||||
String privatePortletURL = vreDetached.getCatalogPortletURL();
|
String privatePortletURL = vreDetached.getCatalogPortletURL();
|
||||||
//The private portlet URL
|
// The private portlet URL
|
||||||
Map<ACCESS_LEVEL_TO_CATALOGUE_PORTLET, String> mapAccessURLToCatalogue = new HashMap<ACCESS_LEVEL_TO_CATALOGUE_PORTLET, String>(3);
|
Map<ACCESS_LEVEL_TO_CATALOGUE_PORTLET, String> mapAccessURLToCatalogue = new HashMap<ACCESS_LEVEL_TO_CATALOGUE_PORTLET, String>(
|
||||||
mapAccessURLToCatalogue.put(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PRIVATE_VRE,privatePortletURL);
|
3);
|
||||||
|
mapAccessURLToCatalogue.put(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PRIVATE_VRE, privatePortletURL);
|
||||||
|
|
||||||
//Building the gateway catalogue public URL from private VRE Portlet URL
|
// Building the gateway catalogue public URL from private VRE Portlet URL
|
||||||
URI toURL = new URI(privatePortletURL);
|
URI toURL = new URI(privatePortletURL);
|
||||||
String publicURL = privatePortletURL.startsWith("https://")?"https://"+toURL.getHost():"http://"+toURL.getHost();
|
String publicURL = privatePortletURL.startsWith("https://") ? "https://" + toURL.getHost()
|
||||||
//It returns the string "catalogue"
|
: "http://" + toURL.getHost();
|
||||||
|
// It returns the string "catalogue"
|
||||||
CatalogueStaticConfigurations staticConf = new CatalogueStaticConfigurations();
|
CatalogueStaticConfigurations staticConf = new CatalogueStaticConfigurations();
|
||||||
//Replacing for example "ckan-bb" with "[PREFIXES-TO-CATALOGUE-URL]-bb" (e.g catalogue-bb)
|
// Replacing for example "ckan-bb" with "[PREFIXES-TO-CATALOGUE-URL]-bb" (e.g
|
||||||
String relativeURLWithCatalogueName = staticConf.buildRelativeURLToPublicCatalogueGateway(vreDetached.getCatalogUrl());
|
// catalogue-bb)
|
||||||
|
String relativeURLWithCatalogueName = staticConf
|
||||||
|
.buildRelativeURLToPublicCatalogueGateway(vreDetached.getCatalogUrl());
|
||||||
String toGatewayPortletURL = String.format("%s/%s", publicURL, relativeURLWithCatalogueName);
|
String toGatewayPortletURL = String.format("%s/%s", publicURL, relativeURLWithCatalogueName);
|
||||||
mapAccessURLToCatalogue.put(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_GATEWAY,toGatewayPortletURL);
|
mapAccessURLToCatalogue.put(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_GATEWAY, toGatewayPortletURL);
|
||||||
|
|
||||||
ckanCatalogueReference = new GatewayCKANCatalogueReference(fullScope, vreDetached.getCatalogUrl(), mapAccessURLToCatalogue);
|
ckanCatalogueReference = new GatewayCKANCatalogueReference(fullScope, vreDetached.getCatalogUrl(),
|
||||||
|
mapAccessURLToCatalogue);
|
||||||
break;
|
break;
|
||||||
case ACTIVE:
|
case ACTIVE:
|
||||||
default:
|
default:
|
||||||
|
|
||||||
ckanCatalogueReference = CkanCatalogueConfigurationsReader.loadCatalogueEndPoints();
|
ckanCatalogueReference = CkanCatalogueConfigurationsReader.loadCatalogueEndPoints();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info("For scope " + fullScope + " loaded end points: " + ckanCatalogueReference);
|
||||||
|
|
||||||
logger.info("For scope "+fullScope+" loaded end points: "+ckanCatalogueReference);
|
// IS THE PRODUCT PLUBLIC OR PRIVATE?
|
||||||
|
|
||||||
//IS THE PRODUCT PLUBLIC OR PRIVATE?
|
|
||||||
String datasetName = entityName;
|
String datasetName = entityName;
|
||||||
boolean isPublicItem = false;
|
boolean isPublicItem = false;
|
||||||
if(ckanCatalogueReference.getCkanURL()!=null){
|
if (ckanCatalogueReference.getCkanURL() != null) {
|
||||||
try{
|
try {
|
||||||
CkanDataset dataset = CkanCatalogueConfigurationsReader.getDataset(datasetName, ckanCatalogueReference.getCkanURL());
|
CkanDataset dataset = CkanCatalogueConfigurationsReader.getDataset(datasetName,
|
||||||
if(dataset!=null){
|
ckanCatalogueReference.getCkanURL());
|
||||||
|
if (dataset != null) {
|
||||||
isPublicItem = true;
|
isPublicItem = true;
|
||||||
//ckanPorltetUrl = ckanCatalogueReference.getPublicPortletURL();
|
// ckanPorltetUrl = ckanCatalogueReference.getPublicPortletURL();
|
||||||
logger.info("The dataset "+datasetName+" is a public item");
|
logger.info("The dataset " + datasetName + " is a public item");
|
||||||
}
|
}
|
||||||
}catch(Exception e){
|
} catch (Exception e) {
|
||||||
logger.warn("Error on checking if dataset: "+datasetName+" is private or not", e);
|
logger.warn("Error on checking if dataset: " + datasetName + " is private or not", e);
|
||||||
isPublicItem = true;
|
isPublicItem = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String publicGatewayPorltetURL = String.format("%s?path=/%s/%s",
|
String publicGatewayPorltetURL = String.format("%s?path=/%s/%s",
|
||||||
ckanCatalogueReference.getCatalogueURL(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_GATEWAY),
|
ckanCatalogueReference.getCatalogueURL(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_GATEWAY),
|
||||||
entityContextValue,
|
entityContextValue, entityName);
|
||||||
entityName);
|
|
||||||
|
|
||||||
String privateVREPortletURL = String.format("%s?path=/%s/%s",
|
String privateVREPortletURL = String.format("%s?path=/%s/%s",
|
||||||
ckanCatalogueReference.getCatalogueURL(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PRIVATE_VRE),
|
ckanCatalogueReference.getCatalogueURL(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PRIVATE_VRE),
|
||||||
entityContextValue,
|
entityContextValue, entityName);
|
||||||
entityName);
|
|
||||||
|
|
||||||
//Checking if the public VRE portlet URL is available (so it was read from GR)
|
// Checking if the public VRE portlet URL is available (so it was read from GR)
|
||||||
String publicVREPortletURL = null;
|
String publicVREPortletURL = null;
|
||||||
String toCheckPublicVREPortletURL = ckanCatalogueReference.getCatalogueURL(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_VRE);
|
String toCheckPublicVREPortletURL = ckanCatalogueReference
|
||||||
if(toCheckPublicVREPortletURL!=null && !toCheckPublicVREPortletURL.isEmpty()) {
|
.getCatalogueURL(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_VRE);
|
||||||
//here the catalogue is available/deployed as public at VRE level
|
if (toCheckPublicVREPortletURL != null && !toCheckPublicVREPortletURL.isEmpty()) {
|
||||||
publicVREPortletURL = String.format("%s?path=/%s/%s",
|
// here the catalogue is available/deployed as public at VRE level
|
||||||
toCheckPublicVREPortletURL,
|
publicVREPortletURL = String.format("%s?path=/%s/%s", toCheckPublicVREPortletURL, entityContextValue,
|
||||||
entityContextValue,
|
|
||||||
entityName);
|
entityName);
|
||||||
}
|
}
|
||||||
return new ItemCatalogueURLs(entityName, isPublicItem, privateVREPortletURL, publicVREPortletURL, publicGatewayPorltetURL);
|
return new ItemCatalogueURLs(entityName, isPublicItem, privateVREPortletURL, publicVREPortletURL,
|
||||||
}catch (Exception e) {
|
publicGatewayPorltetURL);
|
||||||
|
} catch (Exception e) {
|
||||||
logger.error("Error when resolving CatalogueURL:", e);
|
logger.error("Error when resolving CatalogueURL:", e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,13 +32,11 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
|
import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class GisResolver.
|
* The Class GisResolver.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||||
* Dec 14, 2018
|
* Dec 14, 2018
|
||||||
*/
|
*/
|
||||||
@Path("gis")
|
@Path("gis")
|
||||||
public class GisResolver {
|
public class GisResolver {
|
||||||
|
@ -53,62 +51,60 @@ public class GisResolver {
|
||||||
public static final String SCOPE = "scope";
|
public static final String SCOPE = "scope";
|
||||||
public static final String GEO_EXPLORER_LAYER_UUID = "geo-exp";
|
public static final String GEO_EXPLORER_LAYER_UUID = "geo-exp";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Submit get.
|
* Submit get.
|
||||||
*
|
*
|
||||||
* @param req the req
|
* @param req the req
|
||||||
* @param scope the scope
|
* @param scope the scope
|
||||||
* @param gisUUID the gis uuid
|
* @param gisUUID the gis uuid
|
||||||
* @param geoExplorerUUID the geo explorer uuid
|
* @param geoExplorerUUID the geo explorer uuid
|
||||||
* @return the response
|
* @return the response
|
||||||
* @throws WebApplicationException the web application exception
|
* @throws WebApplicationException the web application exception
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("")
|
@Path("")
|
||||||
public Response submitGet(@Context HttpServletRequest req, @
|
public Response submitGet(@Context HttpServletRequest req, @QueryParam(SCOPE) String scope,
|
||||||
QueryParam(SCOPE) String scope,
|
@QueryParam(GIS_UUID) String gisUUID, @QueryParam(GEO_EXPLORER_LAYER_UUID) String geoExplorerUUID)
|
||||||
@QueryParam(GIS_UUID) String gisUUID,
|
throws WebApplicationException {
|
||||||
@QueryParam(GEO_EXPLORER_LAYER_UUID) String geoExplorerUUID) throws WebApplicationException{
|
|
||||||
|
|
||||||
logger.info(this.getClass().getSimpleName()+" GET starts...");
|
logger.info(this.getClass().getSimpleName() + " GET starts...");
|
||||||
|
|
||||||
try{
|
try {
|
||||||
boolean isGisLink = false;
|
boolean isGisLink = false;
|
||||||
boolean isGeoExplorerLink = false;
|
boolean isGeoExplorerLink = false;
|
||||||
|
|
||||||
if(scope==null || scope.isEmpty()){
|
if (scope == null || scope.isEmpty()) {
|
||||||
logger.error("Query Parameter 'scope' not found");
|
logger.error("Query Parameter 'scope' not found");
|
||||||
throw ExceptionManager.badRequestException(req, "Missing mandatory query parameter 'scope'", this.getClass(), help);
|
throw ExceptionManager.badRequestException(req, "Missing mandatory query parameter 'scope'",
|
||||||
|
this.getClass(), help);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(gisUUID==null || gisUUID.isEmpty()){
|
if (gisUUID == null || gisUUID.isEmpty()) {
|
||||||
logger.error("Path Parameter 'gis-UUID' not found");
|
logger.error("Path Parameter 'gis-UUID' not found");
|
||||||
throw ExceptionManager.badRequestException(req, "Missing mandatory query parameter 'gis-UUID'", this.getClass(), help);
|
throw ExceptionManager.badRequestException(req, "Missing mandatory query parameter 'gis-UUID'",
|
||||||
}else
|
this.getClass(), help);
|
||||||
|
} else
|
||||||
isGisLink = true;
|
isGisLink = true;
|
||||||
|
|
||||||
logger.info(SCOPE +" is: " + scope);
|
logger.info(SCOPE + " is: " + scope);
|
||||||
logger.info(GIS_UUID +" is: " + gisUUID);
|
logger.info(GIS_UUID + " is: " + gisUUID);
|
||||||
|
|
||||||
if (geoExplorerUUID == null || geoExplorerUUID.isEmpty()) {
|
if (geoExplorerUUID == null || geoExplorerUUID.isEmpty()) {
|
||||||
logger.debug(GEO_EXPLORER_LAYER_UUID+ " not found");
|
logger.debug(GEO_EXPLORER_LAYER_UUID + " not found");
|
||||||
}else
|
} else
|
||||||
isGeoExplorerLink = true;
|
isGeoExplorerLink = true;
|
||||||
|
|
||||||
logger.info(GEO_EXPLORER_LAYER_UUID +" is: " + geoExplorerUUID);
|
logger.info(GEO_EXPLORER_LAYER_UUID + " is: " + geoExplorerUUID);
|
||||||
|
|
||||||
if(!isGisLink && !isGeoExplorerLink){
|
if (!isGisLink && !isGeoExplorerLink) {
|
||||||
String err = GIS_UUID+" or "+GEO_EXPLORER_LAYER_UUID+" not found or empty in the query string";
|
String err = GIS_UUID + " or " + GEO_EXPLORER_LAYER_UUID + " not found or empty in the query string";
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
throw ExceptionManager.badRequestException(req, err, this.getClass(), help);
|
throw ExceptionManager.badRequestException(req, err, this.getClass(), help);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isGisLink) {
|
||||||
|
|
||||||
if(isGisLink){
|
|
||||||
ScopeProvider.instance.set(scope);
|
ScopeProvider.instance.set(scope);
|
||||||
//ServerParameters geonetworkParams = getCachedServerParameters(scope);
|
// ServerParameters geonetworkParams = getCachedServerParameters(scope);
|
||||||
GisLayerItem gisLayerItem = getGisLayerForLayerUUID(req, scope, gisUUID);
|
GisLayerItem gisLayerItem = getGisLayerForLayerUUID(req, scope, gisUUID);
|
||||||
|
|
||||||
logger.info("wms url is: " + gisLayerItem.getFullWmsUrlRequest());
|
logger.info("wms url is: " + gisLayerItem.getFullWmsUrlRequest());
|
||||||
|
@ -116,112 +112,132 @@ public class GisResolver {
|
||||||
logger.info("encoded WMS url is: " + wmsRequest);
|
logger.info("encoded WMS url is: " + wmsRequest);
|
||||||
|
|
||||||
String layerTitle = null;
|
String layerTitle = null;
|
||||||
if(gisLayerItem.getCitationTitle()!=null && !gisLayerItem.getCitationTitle().isEmpty())
|
if (gisLayerItem.getCitationTitle() != null && !gisLayerItem.getCitationTitle().isEmpty())
|
||||||
layerTitle = URLEncoder.encode(gisLayerItem.getCitationTitle(), UTF_8);
|
layerTitle = URLEncoder.encode(gisLayerItem.getCitationTitle(), UTF_8);
|
||||||
|
|
||||||
logger.info("layer Title encoded is: " + layerTitle);
|
logger.info("layer Title encoded is: " + layerTitle);
|
||||||
String gisViewerPortletUrl = null;
|
String gisViewerPortletUrl = null;
|
||||||
try{
|
try {
|
||||||
gisViewerPortletUrl = LoadingGisViewerApplicationURLCache.get(scope);
|
gisViewerPortletUrl = LoadingGisViewerApplicationURLCache.get(scope);
|
||||||
}catch(ExecutionException | InvalidCacheLoadException e){
|
} catch (ExecutionException | InvalidCacheLoadException e) {
|
||||||
logger.error("Error on getting the GisViewer Applicaton URL from cache for scope "+scope, e);
|
logger.error("Error on getting the GisViewer Applicaton URL from cache for scope " + scope, e);
|
||||||
throw ExceptionManager.wrongParameterException(req, "Error on getting the GisViewer Applicaton URL from cache for scope "+scope+".\nIs the Application Profile with APPID "+UriResolverSmartGearManagerInit.getGisViewerProfile().getAppId()+" registered for this scope: "+scope+"?", this.getClass(), help);
|
throw ExceptionManager.wrongParameterException(req,
|
||||||
|
"Error on getting the GisViewer Applicaton URL from cache for scope " + scope
|
||||||
|
+ ".\nIs the Application Profile with APPID "
|
||||||
|
+ UriResolverSmartGearManagerInit.getGisViewerProfile().getAppId()
|
||||||
|
+ " registered for this scope: " + scope + "?",
|
||||||
|
this.getClass(), help);
|
||||||
}
|
}
|
||||||
//CHECKING IF THE GisViewer Portlet URL is valid
|
// CHECKING IF THE GisViewer Portlet URL is valid
|
||||||
if(gisViewerPortletUrl==null || gisViewerPortletUrl.isEmpty())
|
if (gisViewerPortletUrl == null || gisViewerPortletUrl.isEmpty())
|
||||||
throw ExceptionManager.notFoundException(req, "GisViewer Portlet URL not found in the scope: "+scope +". Please contact the support", this.getClass(), help);
|
throw ExceptionManager.notFoundException(req,
|
||||||
|
"GisViewer Portlet URL not found in the scope: " + scope + ". Please contact the support",
|
||||||
|
this.getClass(), help);
|
||||||
|
|
||||||
logger.info("Gis Viewer Application url is: " + gisViewerPortletUrl);
|
logger.info("Gis Viewer Application url is: " + gisViewerPortletUrl);
|
||||||
gisViewerPortletUrl+="?rid="+new Random().nextLong()
|
gisViewerPortletUrl += "?rid=" + new Random().nextLong() + "&wmsrequest=" + wmsRequest + "&uuid="
|
||||||
+"&wmsrequest="+wmsRequest
|
+ URLEncoder.encode(gisUUID, UTF_8);
|
||||||
+"&uuid="+URLEncoder.encode(gisUUID, UTF_8);
|
|
||||||
|
|
||||||
if(layerTitle!=null)
|
if (layerTitle != null)
|
||||||
gisViewerPortletUrl+="&layertitle="+layerTitle;
|
gisViewerPortletUrl += "&layertitle=" + layerTitle;
|
||||||
|
|
||||||
logger.info("Redirecting to: "+gisViewerPortletUrl);
|
logger.info("Redirecting to: " + gisViewerPortletUrl);
|
||||||
return Response.seeOther(new URI(gisViewerPortletUrl)).build();
|
return Response.seeOther(new URI(gisViewerPortletUrl)).build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isGeoExplorerLink){
|
if (isGeoExplorerLink) {
|
||||||
|
|
||||||
ScopeProvider.instance.set(scope);
|
ScopeProvider.instance.set(scope);
|
||||||
String geoExplorerPortletUrl = null;
|
String geoExplorerPortletUrl = null;
|
||||||
try{
|
try {
|
||||||
geoExplorerPortletUrl = LoadingGeoExplorerApplicationURLCache.get(scope);
|
geoExplorerPortletUrl = LoadingGeoExplorerApplicationURLCache.get(scope);
|
||||||
}catch(ExecutionException e){
|
} catch (ExecutionException e) {
|
||||||
logger.error("Error on getting the GeoExplorer Applicaton URL from cache for scope "+scope, e);
|
logger.error("Error on getting the GeoExplorer Applicaton URL from cache for scope " + scope, e);
|
||||||
throw ExceptionManager.wrongParameterException(req, "Error on getting the GeoExplorer Applicaton URL from cache for scope "+scope+".\nIs the Application Profile with APPID "+UriResolverSmartGearManagerInit.getGeoExplorerProfile().getAppId()+" registered for this scope: "+scope+"?", this.getClass(), help);
|
throw ExceptionManager.wrongParameterException(req,
|
||||||
|
"Error on getting the GeoExplorer Applicaton URL from cache for scope " + scope
|
||||||
|
+ ".\nIs the Application Profile with APPID "
|
||||||
|
+ UriResolverSmartGearManagerInit.getGeoExplorerProfile().getAppId()
|
||||||
|
+ " registered for this scope: " + scope + "?",
|
||||||
|
this.getClass(), help);
|
||||||
}
|
}
|
||||||
//CHECKING IF THE GeoExplorer Portlet URL is valid
|
// CHECKING IF THE GeoExplorer Portlet URL is valid
|
||||||
if(geoExplorerPortletUrl==null || geoExplorerPortletUrl.isEmpty())
|
if (geoExplorerPortletUrl == null || geoExplorerPortletUrl.isEmpty())
|
||||||
throw ExceptionManager.notFoundException(req, "GeoExplorer Portlet URL not found in the scope: "+scope +". Please contact the support", this.getClass(), help);
|
throw ExceptionManager.notFoundException(req,
|
||||||
|
"GeoExplorer Portlet URL not found in the scope: " + scope + ". Please contact the support",
|
||||||
|
this.getClass(), help);
|
||||||
|
|
||||||
logger.info("GeoExplorer Application url is: " + geoExplorerPortletUrl);
|
logger.info("GeoExplorer Application url is: " + geoExplorerPortletUrl);
|
||||||
geoExplorerPortletUrl+="?rid="+new Random().nextLong()
|
geoExplorerPortletUrl += "?rid=" + new Random().nextLong() + "&luuid="
|
||||||
+"&luuid="+URLEncoder.encode(geoExplorerUUID, UTF_8);
|
+ URLEncoder.encode(geoExplorerUUID, UTF_8);
|
||||||
//urlRedirect(req, resp, geoExplorerPortletUrl);
|
// urlRedirect(req, resp, geoExplorerPortletUrl);
|
||||||
return Response.seeOther(new URI(geoExplorerPortletUrl)).build();
|
return Response.seeOther(new URI(geoExplorerPortletUrl)).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
throw ExceptionManager.badRequestException(req, GIS_UUID+" or "+GEO_EXPLORER_LAYER_UUID+" not found or empty in the query string", this.getClass(), help);
|
throw ExceptionManager.badRequestException(req,
|
||||||
|
GIS_UUID + " or " + GEO_EXPLORER_LAYER_UUID + " not found or empty in the query string",
|
||||||
|
this.getClass(), help);
|
||||||
|
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
if(!(e instanceof WebApplicationException)){
|
if (!(e instanceof WebApplicationException)) {
|
||||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||||
String error = "Sorry, an error occurred on resolving request with UUID "+gisUUID+" and scope "+scope+". Please, contact support!";
|
String error = "Sorry, an error occurred on resolving request with UUID " + gisUUID + " and scope "
|
||||||
if(e.getCause()!=null)
|
+ scope + ". Please, contact support!";
|
||||||
error+="\n\nCaused: "+e.getCause().getMessage();
|
if (e.getCause() != null)
|
||||||
|
error += "\n\nCaused: " + e.getCause().getMessage();
|
||||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), help);
|
throw ExceptionManager.internalErrorException(req, error, this.getClass(), help);
|
||||||
}
|
}
|
||||||
//ALREADY MANAGED AS WebApplicationException
|
// ALREADY MANAGED AS WebApplicationException
|
||||||
logger.error("Exception:", e);
|
logger.error("Exception:", e);
|
||||||
throw (WebApplicationException) e;
|
throw (WebApplicationException) e;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the gis layer for layer uuid.
|
* Gets the gis layer for layer uuid.
|
||||||
*
|
*
|
||||||
* @param req the req
|
* @param req the req
|
||||||
* @param scope the scope
|
* @param scope the scope
|
||||||
* @param gisUUID the gis uuid
|
* @param gisUUID the gis uuid
|
||||||
* @return the gis layer for layer uuid
|
* @return the gis layer for layer uuid
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
public GisLayerItem getGisLayerForLayerUUID(HttpServletRequest req, String scope, String gisUUID) throws Exception{
|
public GisLayerItem getGisLayerForLayerUUID(HttpServletRequest req, String scope, String gisUUID) throws Exception {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
GeonetworkInstance gi = null;
|
GeonetworkInstance gi = null;
|
||||||
try {
|
try {
|
||||||
gi = LoadingGeonetworkInstanceCache.get(scope);
|
gi = LoadingGeonetworkInstanceCache.get(scope);
|
||||||
|
|
||||||
}catch(ExecutionException | InvalidCacheLoadException e){
|
} catch (ExecutionException | InvalidCacheLoadException e) {
|
||||||
logger.error("Error on getting the Geonetwork Instance from cache for scope "+scope, e);
|
logger.error("Error on getting the Geonetwork Instance from cache for scope " + scope, e);
|
||||||
throw ExceptionManager.wrongParameterException(req, "Error on getting the Geonetwork Instance from cache for scope "+scope+". Is it registered for this scope: "+scope+"?", this.getClass(), help);
|
throw ExceptionManager.wrongParameterException(req,
|
||||||
|
"Error on getting the Geonetwork Instance from cache for scope " + scope
|
||||||
|
+ ". Is it registered for this scope: " + scope + "?",
|
||||||
|
this.getClass(), help);
|
||||||
}
|
}
|
||||||
if(gi==null)
|
if (gi == null)
|
||||||
throw new Exception("GeonetworkInstance not instanciable in the scope: "+scope);
|
throw new Exception("GeonetworkInstance not instanciable in the scope: " + scope);
|
||||||
|
|
||||||
LoginLevel toLoginLevel = LoginLevel.SCOPE;
|
LoginLevel toLoginLevel = LoginLevel.SCOPE;
|
||||||
logger.info("Performing authentication on GN with "+LoginLevel.class.getSimpleName()+" "+toLoginLevel);
|
logger.info(
|
||||||
|
"Performing authentication on GN with " + LoginLevel.class.getSimpleName() + " " + toLoginLevel);
|
||||||
gi.getGeonetworkPublisher().login(toLoginLevel);
|
gi.getGeonetworkPublisher().login(toLoginLevel);
|
||||||
|
|
||||||
GisLayerItem gisLayerItem = MetadataConverter.getWMSOnLineResource(gi, gisUUID);
|
GisLayerItem gisLayerItem = MetadataConverter.getWMSOnLineResource(gi, gisUUID);
|
||||||
return gisLayerItem;
|
return gisLayerItem;
|
||||||
//TODO CREATE A BEAN ADDING WMS REQUEST AND LAYER TITLE MetadataConverter.
|
// TODO CREATE A BEAN ADDING WMS REQUEST AND LAYER TITLE MetadataConverter.
|
||||||
}catch (GeonetworkInstanceException e){
|
} catch (GeonetworkInstanceException e) {
|
||||||
logger.error("An error occurred when instancing geonetowrk gis layer with UUID "+gisUUID, e);
|
logger.error("An error occurred when instancing geonetowrk gis layer with UUID " + gisUUID, e);
|
||||||
throw new IllegalArgumentException("Sorry, An error occurred when instancing geonetwork with UUID: "+gisUUID);
|
throw new IllegalArgumentException(
|
||||||
|
"Sorry, An error occurred when instancing geonetwork with UUID: " + gisUUID);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("An error occurred when retrieving gis layer with UUID "+gisUUID, e);
|
logger.error("An error occurred when retrieving gis layer with UUID " + gisUUID, e);
|
||||||
throw new IllegalArgumentException("Sorry, An error occurred when retrieving gis layer with UUID "+gisUUID);
|
throw new IllegalArgumentException(
|
||||||
|
"Sorry, An error occurred when retrieving gis layer with UUID " + gisUUID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,11 +23,12 @@ import org.gcube.datatransfer.resolver.util.Util;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The Class KnimeCreateResolver.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
* Dec 13, 2018
|
*
|
||||||
|
* Mar 24, 2022
|
||||||
*/
|
*/
|
||||||
@Path("knime")
|
@Path("knime")
|
||||||
public class KnimeCreateResolver {
|
public class KnimeCreateResolver {
|
||||||
|
@ -36,7 +37,6 @@ public class KnimeCreateResolver {
|
||||||
|
|
||||||
private static String helpURI = "https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#KNIME_Resolver";
|
private static String helpURI = "https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#KNIME_Resolver";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the knime URL.
|
* Creates the knime URL.
|
||||||
*
|
*
|
||||||
|
@ -48,51 +48,55 @@ public class KnimeCreateResolver {
|
||||||
@Path("/create")
|
@Path("/create")
|
||||||
@Consumes(MediaType.TEXT_PLAIN)
|
@Consumes(MediaType.TEXT_PLAIN)
|
||||||
@Produces(MediaType.TEXT_PLAIN)
|
@Produces(MediaType.TEXT_PLAIN)
|
||||||
public Response createKnimeURL(@Context HttpServletRequest req) throws WebApplicationException{
|
public Response createKnimeURL(@Context HttpServletRequest req) throws WebApplicationException {
|
||||||
|
|
||||||
logger.info(this.getClass().getSimpleName()+" POST starts...");
|
logger.info(this.getClass().getSimpleName() + " POST starts...");
|
||||||
|
|
||||||
try{
|
try {
|
||||||
String contextToken = SecurityTokenProvider.instance.get();
|
String contextToken = SecurityTokenProvider.instance.get();
|
||||||
String scope = ScopeProvider.instance.get();
|
String scope = ScopeProvider.instance.get();
|
||||||
// logger.info("SecurityTokenProvider contextToken: "+contextToken);
|
// logger.info("SecurityTokenProvider contextToken: "+contextToken);
|
||||||
logger.info("ScopeProvider has scope: "+scope);
|
logger.info("ScopeProvider has scope: " + scope);
|
||||||
|
|
||||||
String appToken = req.getServletContext().getInitParameter(RequestHandler.ROOT_APP_TOKEN);
|
String appToken = req.getServletContext().getInitParameter(RequestHandler.ROOT_APP_TOKEN);
|
||||||
|
|
||||||
if(contextToken.compareTo(appToken)==0){
|
if (contextToken.compareTo(appToken) == 0) {
|
||||||
logger.error("Token not passed, SecurityTokenProvider contains the root app token: "+appToken.substring(0,10)+"...");
|
logger.error("Token not passed, SecurityTokenProvider contains the root app token: "
|
||||||
throw ExceptionManager.unauthorizedException(req, "You are not authorized. You must pass a token of VRE", this.getClass(), helpURI);
|
+ appToken.substring(0, 10) + "...");
|
||||||
|
throw ExceptionManager.unauthorizedException(req,
|
||||||
|
"You are not authorized. You must pass a token of VRE", this.getClass(), helpURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopeBean scopeBean = new ScopeBean(scope);
|
ScopeBean scopeBean = new ScopeBean(scope);
|
||||||
|
|
||||||
if(scopeBean.is(Type.VRE)){
|
if (scopeBean.is(Type.VRE)) {
|
||||||
|
|
||||||
String vreName = scopeBean.name();
|
String vreName = scopeBean.name();
|
||||||
String knimeGetResolverURL = String.format("%s/%s/%s", Util.getServerURL(req), "knime/get", vreName);
|
String knimeGetResolverURL = String.format("%s/%s/%s", Util.getServerURL(req), "knime/get", vreName);
|
||||||
String queryString =req.getQueryString()==null?"":req.getQueryString();
|
String queryString = req.getQueryString() == null ? "" : req.getQueryString();
|
||||||
|
|
||||||
if(req.getQueryString()!=null)
|
if (req.getQueryString() != null)
|
||||||
knimeGetResolverURL+="?"+queryString;
|
knimeGetResolverURL += "?" + queryString;
|
||||||
|
|
||||||
logger.info("Returning Knime Resolver URL: "+knimeGetResolverURL);
|
logger.info("Returning Knime Resolver URL: " + knimeGetResolverURL);
|
||||||
return Response.ok(knimeGetResolverURL).header("Location", knimeGetResolverURL).build();
|
return Response.ok(knimeGetResolverURL).header("Location", knimeGetResolverURL).build();
|
||||||
|
|
||||||
}else{
|
} else {
|
||||||
logger.error("The input scope "+scope+" is not a VRE");
|
logger.error("The input scope " + scope + " is not a VRE");
|
||||||
throw ExceptionManager.badRequestException(req, "Working in the "+scope+" scope that is not a VRE. Use a token of VRE", this.getClass(), helpURI);
|
throw ExceptionManager.badRequestException(req,
|
||||||
|
"Working in the " + scope + " scope that is not a VRE. Use a token of VRE", this.getClass(),
|
||||||
|
helpURI);
|
||||||
}
|
}
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
if(!(e instanceof WebApplicationException)){
|
if (!(e instanceof WebApplicationException)) {
|
||||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||||
String error = "Sorry, an error occurred on creating Knime URL. Please, contact the support!";
|
String error = "Sorry, an error occurred on creating Knime URL. Please, contact the support!";
|
||||||
if(e.getCause()!=null)
|
if (e.getCause() != null)
|
||||||
error+="\n\nCaused: "+e.getCause().getMessage();
|
error += "\n\nCaused: " + e.getCause().getMessage();
|
||||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||||
}
|
}
|
||||||
//ALREADY MANAGED AS WebApplicationException
|
// ALREADY MANAGED AS WebApplicationException
|
||||||
logger.error("Exception:", e);
|
logger.error("Exception:", e);
|
||||||
throw (WebApplicationException) e;
|
throw (WebApplicationException) e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,12 @@ import org.gcube.datatransfer.resolver.util.ValidateContentDisposition;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The Class SMPIDResolver.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
* Oct 22, 2018
|
*
|
||||||
|
* Mar 24, 2022
|
||||||
*/
|
*/
|
||||||
@Path("id")
|
@Path("id")
|
||||||
public class SMPIDResolver {
|
public class SMPIDResolver {
|
||||||
|
@ -37,54 +38,54 @@ public class SMPIDResolver {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(SMPIDResolver.class);
|
private static Logger logger = LoggerFactory.getLogger(SMPIDResolver.class);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the smpid.
|
* Gets the smpid.
|
||||||
*
|
*
|
||||||
* @param req the req
|
* @param req the req
|
||||||
* @param smpId the smp id
|
* @param smpId the smp id
|
||||||
* @param fileName the file name
|
* @param fileName the file name
|
||||||
* @param contentType the content type
|
* @param contentType the content type
|
||||||
* @param validation the validation
|
* @param contentDisposition the content disposition
|
||||||
|
* @param validation the validation
|
||||||
* @return the smpid
|
* @return the smpid
|
||||||
* @throws WebApplicationException the web application exception
|
* @throws WebApplicationException the web application exception
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("")
|
@Path("")
|
||||||
public Response getSMPID(@Context HttpServletRequest req,
|
public Response getSMPID(@Context HttpServletRequest req, @QueryParam(SMP_ID) @Nullable String smpId,
|
||||||
@QueryParam(SMP_ID) @Nullable String smpId,
|
@QueryParam(ConstantsResolver.QUERY_PARAM_FILE_NAME) String fileName,
|
||||||
@QueryParam(ConstantsResolver.QUERY_PARAM_FILE_NAME) String fileName,
|
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENT_TYPE) String contentType,
|
||||||
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENT_TYPE) String contentType,
|
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION) String contentDisposition,
|
||||||
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION) String contentDisposition,
|
@QueryParam(ConstantsResolver.QUERY_PARAM_VALIDATION) boolean validation) throws WebApplicationException {
|
||||||
@QueryParam(ConstantsResolver.QUERY_PARAM_VALIDATION) boolean validation) throws WebApplicationException{
|
|
||||||
|
|
||||||
logger.info(this.getClass().getSimpleName()+" GET starts...");
|
logger.info(this.getClass().getSimpleName() + " GET starts...");
|
||||||
|
|
||||||
try{
|
try {
|
||||||
//Checking mandatory parameter smpId
|
// Checking mandatory parameter smpId
|
||||||
if(smpId==null || smpId.isEmpty()){
|
if (smpId == null || smpId.isEmpty()) {
|
||||||
logger.error(SMP_ID+" not found");
|
logger.error(SMP_ID + " not found");
|
||||||
throw ExceptionManager.badRequestException(req, "Missing mandatory parameter "+SMP_ID, SMPIDResolver.class, helpURI);
|
throw ExceptionManager.badRequestException(req, "Missing mandatory parameter " + SMP_ID,
|
||||||
|
SMPIDResolver.class, helpURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checking the optional parameter "Content-Disposition"
|
||||||
//Checking the optional parameter "Content-Disposition"
|
|
||||||
CONTENT_DISPOSITION_VALUE dispositionValue = CONTENT_DISPOSITION_VALUE.attachment;
|
CONTENT_DISPOSITION_VALUE dispositionValue = CONTENT_DISPOSITION_VALUE.attachment;
|
||||||
//Validating the Content-Disposition value
|
// Validating the Content-Disposition value
|
||||||
dispositionValue = ValidateContentDisposition.validValue(req, this.getClass(), helpURI, contentDisposition);
|
dispositionValue = ValidateContentDisposition.validValue(req, this.getClass(), helpURI, contentDisposition);
|
||||||
|
|
||||||
return StorageIDResolver.resolveStorageId(req, smpId, fileName, contentType, dispositionValue, validation);
|
return StorageIDResolver.resolveStorageId(req, smpId, fileName, contentType, dispositionValue, validation);
|
||||||
|
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
if(!(e instanceof WebApplicationException)){
|
if (!(e instanceof WebApplicationException)) {
|
||||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||||
String error = "Error occurred on resolving the "+SMP_ID+": "+smpId+". Please, contact the support!";
|
String error = "Error occurred on resolving the " + SMP_ID + ": " + smpId
|
||||||
if(e.getCause()!=null)
|
+ ". Please, contact the support!";
|
||||||
error+="\n\nCaused: "+e.getCause().getMessage();
|
if (e.getCause() != null)
|
||||||
|
error += "\n\nCaused: " + e.getCause().getMessage();
|
||||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||||
}
|
}
|
||||||
//ALREADY MANAGED AS WebApplicationException
|
// ALREADY MANAGED AS WebApplicationException
|
||||||
logger.error("Exception:", e);
|
logger.error("Exception:", e);
|
||||||
throw (WebApplicationException) e;
|
throw (WebApplicationException) e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,12 @@ import org.gcube.datatransfer.resolver.util.ValidateContentDisposition;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class SMPResolver.
|
* The Class SMPResolver.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
* Dec 14, 2018
|
*
|
||||||
|
* Mar 24, 2022
|
||||||
*/
|
*/
|
||||||
@Path("smp")
|
@Path("smp")
|
||||||
public class SMPResolver {
|
public class SMPResolver {
|
||||||
|
@ -41,48 +41,48 @@ public class SMPResolver {
|
||||||
/**
|
/**
|
||||||
* Gets the smpuri.
|
* Gets the smpuri.
|
||||||
*
|
*
|
||||||
* @param req the req
|
* @param req the req
|
||||||
* @param smpURI the smp uri
|
* @param smpURI the smp uri
|
||||||
* @param fileName the file name
|
* @param fileName the file name
|
||||||
* @param contentType the content type
|
* @param contentType the content type
|
||||||
* @param validation the validation
|
* @param contentDisposition the content disposition
|
||||||
|
* @param validation the validation
|
||||||
* @return the smpuri
|
* @return the smpuri
|
||||||
* @throws WebApplicationException the web application exception
|
* @throws WebApplicationException the web application exception
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("")
|
@Path("")
|
||||||
public Response getSMPURI(@Context HttpServletRequest req,
|
public Response getSMPURI(@Context HttpServletRequest req, @QueryParam(SMP_URI) @Nullable String smpURI,
|
||||||
@QueryParam(SMP_URI) @Nullable
|
@QueryParam(ConstantsResolver.QUERY_PARAM_FILE_NAME) String fileName,
|
||||||
String smpURI,
|
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENT_TYPE) String contentType,
|
||||||
@QueryParam(ConstantsResolver.QUERY_PARAM_FILE_NAME) String fileName,
|
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION) String contentDisposition,
|
||||||
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENT_TYPE) String contentType,
|
@QueryParam(ConstantsResolver.QUERY_PARAM_VALIDATION) boolean validation) throws WebApplicationException {
|
||||||
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION) String contentDisposition,
|
|
||||||
@QueryParam(ConstantsResolver.QUERY_PARAM_VALIDATION) boolean validation) throws WebApplicationException{
|
|
||||||
|
|
||||||
logger.info(this.getClass().getSimpleName()+" GET starts...");
|
logger.info(this.getClass().getSimpleName() + " GET starts...");
|
||||||
|
|
||||||
try{
|
try {
|
||||||
//Checking mandatory parameter smpURI
|
// Checking mandatory parameter smpURI
|
||||||
if(smpURI==null || smpURI.isEmpty()){
|
if (smpURI == null || smpURI.isEmpty()) {
|
||||||
logger.error(SMP_URI+" not found");
|
logger.error(SMP_URI + " not found");
|
||||||
throw ExceptionManager.badRequestException(req, "Missing mandatory parameter "+SMP_URI, SMPResolver.class, helpURI);
|
throw ExceptionManager.badRequestException(req, "Missing mandatory parameter " + SMP_URI,
|
||||||
|
SMPResolver.class, helpURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Checking the optional parameter "Content-Disposition"
|
// Checking the optional parameter "Content-Disposition"
|
||||||
CONTENT_DISPOSITION_VALUE dispositionValue = CONTENT_DISPOSITION_VALUE.attachment;
|
CONTENT_DISPOSITION_VALUE dispositionValue = CONTENT_DISPOSITION_VALUE.attachment;
|
||||||
//Validating the Content-Disposition value
|
// Validating the Content-Disposition value
|
||||||
dispositionValue = ValidateContentDisposition.validValue(req, this.getClass(), helpURI, contentDisposition);
|
dispositionValue = ValidateContentDisposition.validValue(req, this.getClass(), helpURI, contentDisposition);
|
||||||
|
|
||||||
return StorageIDResolver.resolveStorageId(req, smpURI, fileName, contentType, dispositionValue, validation);
|
return StorageIDResolver.resolveStorageId(req, smpURI, fileName, contentType, dispositionValue, validation);
|
||||||
|
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
if(!(e instanceof WebApplicationException)){
|
if (!(e instanceof WebApplicationException)) {
|
||||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||||
String error = "Error occurred on resolving the smpURI "+smpURI+". Please, contact the support!";
|
String error = "Error occurred on resolving the smpURI " + smpURI + ". Please, contact the support!";
|
||||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||||
}
|
}
|
||||||
//ALREADY MANAGED AS WebApplicationException
|
// ALREADY MANAGED AS WebApplicationException
|
||||||
logger.error("Exception:", e);
|
logger.error("Exception:", e);
|
||||||
throw (WebApplicationException) e;
|
throw (WebApplicationException) e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
|
||||||
import org.gcube.datatransfer.resolver.ConstantsResolver;
|
import org.gcube.datatransfer.resolver.ConstantsResolver;
|
||||||
import org.gcube.datatransfer.resolver.ConstantsResolver.CONTENT_DISPOSITION_VALUE;
|
import org.gcube.datatransfer.resolver.ConstantsResolver.CONTENT_DISPOSITION_VALUE;
|
||||||
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||||
import org.gcube.datatransfer.resolver.storage.StorageClientInstance;
|
|
||||||
import org.gcube.datatransfer.resolver.storage.StorageMetadataFile;
|
import org.gcube.datatransfer.resolver.storage.StorageMetadataFile;
|
||||||
import org.gcube.datatransfer.resolver.util.SingleFileStreamingOutput;
|
import org.gcube.datatransfer.resolver.util.SingleFileStreamingOutput;
|
||||||
import org.gcube.datatransfer.resolver.util.ValidateContentDisposition;
|
import org.gcube.datatransfer.resolver.util.ValidateContentDisposition;
|
||||||
|
|
|
@ -20,14 +20,24 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The Class UriResolverDocs.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Oct 22, 2018
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* Mar 24, 2022
|
||||||
*/
|
*/
|
||||||
@Path("docs")
|
@Path("docs")
|
||||||
public class UriResolverDocs {
|
public class UriResolverDocs {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(UriResolverDocs.class);
|
private static Logger logger = LoggerFactory.getLogger(UriResolverDocs.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To doc.
|
||||||
|
*
|
||||||
|
* @param req the req
|
||||||
|
* @return the input stream
|
||||||
|
* @throws WebApplicationException the web application exception
|
||||||
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Produces({ MediaType.TEXT_HTML })
|
@Produces({ MediaType.TEXT_HTML })
|
||||||
@Path("/{any: .*}")
|
@Path("/{any: .*}")
|
||||||
|
@ -58,6 +68,13 @@ public class UriResolverDocs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Index.
|
||||||
|
*
|
||||||
|
* @param req the req
|
||||||
|
* @return the input stream
|
||||||
|
* @throws WebApplicationException the web application exception
|
||||||
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Produces({ MediaType.TEXT_HTML })
|
@Produces({ MediaType.TEXT_HTML })
|
||||||
@Path("")
|
@Path("")
|
||||||
|
|
|
@ -20,37 +20,45 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The Class UriResolverIndex.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
* Oct 22, 2018
|
*
|
||||||
|
* Mar 24, 2022
|
||||||
*/
|
*/
|
||||||
@Path("index")
|
@Path("index")
|
||||||
public class UriResolverIndex {
|
public class UriResolverIndex {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(UriResolverIndex.class);
|
private static Logger logger = LoggerFactory.getLogger(UriResolverIndex.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Index.
|
||||||
|
*
|
||||||
|
* @param req the req
|
||||||
|
* @return the input stream
|
||||||
|
* @throws WebApplicationException the web application exception
|
||||||
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Produces({MediaType.TEXT_HTML})
|
@Produces({ MediaType.TEXT_HTML })
|
||||||
@Path("")
|
@Path("")
|
||||||
public InputStream index(@Context HttpServletRequest req) throws WebApplicationException{
|
public InputStream index(@Context HttpServletRequest req) throws WebApplicationException {
|
||||||
|
|
||||||
String indexFile = "/WEB-INF/jsp/index.jsp";
|
String indexFile = "/WEB-INF/jsp/index.jsp";
|
||||||
|
|
||||||
try{
|
try {
|
||||||
logger.info(UriResolverIndex.class.getSimpleName() +" called");
|
logger.info(UriResolverIndex.class.getSimpleName() + " called");
|
||||||
String realPath = req.getServletContext().getRealPath(indexFile);
|
String realPath = req.getServletContext().getRealPath(indexFile);
|
||||||
return new FileInputStream(new File(realPath));
|
return new FileInputStream(new File(realPath));
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
if(!(e instanceof WebApplicationException)){
|
if (!(e instanceof WebApplicationException)) {
|
||||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||||
String error = "Index.jsp not found. Please, contact the support!";
|
String error = "Index.jsp not found. Please, contact the support!";
|
||||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), null);
|
throw ExceptionManager.internalErrorException(req, error, this.getClass(), null);
|
||||||
}
|
}
|
||||||
//ALREADY MANAGED AS WebApplicationException
|
// ALREADY MANAGED AS WebApplicationException
|
||||||
logger.error("Exception:", e);
|
logger.error("Exception:", e);
|
||||||
throw (WebApplicationException) e;
|
throw (WebApplicationException) e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,18 +14,26 @@ import javax.ws.rs.core.Context;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The Class UriResolverInfo.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
* Oct 22, 2018
|
*
|
||||||
|
* Mar 24, 2022
|
||||||
*/
|
*/
|
||||||
@Path("info")
|
@Path("info")
|
||||||
public class UriResolverInfo {
|
public class UriResolverInfo {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Info.
|
||||||
|
*
|
||||||
|
* @param req the req
|
||||||
|
* @return the input stream
|
||||||
|
* @throws WebApplicationException the web application exception
|
||||||
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Produces({MediaType.TEXT_HTML})
|
@Produces({ MediaType.TEXT_HTML })
|
||||||
@Path("")
|
@Path("")
|
||||||
public InputStream info(@Context HttpServletRequest req) throws WebApplicationException{
|
public InputStream info(@Context HttpServletRequest req) throws WebApplicationException {
|
||||||
return new UriResolverIndex().index(req);
|
return new UriResolverIndex().index(req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,12 +20,12 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class ResourceListingResource.
|
* The Class UriResolverResources.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
* Feb 14, 2019
|
*
|
||||||
|
* Mar 24, 2022
|
||||||
*/
|
*/
|
||||||
@Path("resources")
|
@Path("resources")
|
||||||
@Singleton
|
@Singleton
|
||||||
|
@ -37,7 +37,7 @@ public class UriResolverResources {
|
||||||
* Show all.
|
* Show all.
|
||||||
*
|
*
|
||||||
* @param application the application
|
* @param application the application
|
||||||
* @param request the request
|
* @param request the request
|
||||||
* @return the response
|
* @return the response
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
|
|
|
@ -35,13 +35,12 @@ import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class WekeoResolver.
|
* The Class WekeoResolver.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
*
|
*
|
||||||
* Mar 30, 2021
|
* Mar 24, 2022
|
||||||
*/
|
*/
|
||||||
@Path("wekeo")
|
@Path("wekeo")
|
||||||
public class WekeoResolver {
|
public class WekeoResolver {
|
||||||
|
@ -53,8 +52,6 @@ public class WekeoResolver {
|
||||||
|
|
||||||
private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#Wekeo_Resolver";
|
private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#Wekeo_Resolver";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the token.
|
* Gets the token.
|
||||||
*
|
*
|
||||||
|
@ -65,21 +62,23 @@ public class WekeoResolver {
|
||||||
@GET
|
@GET
|
||||||
@Path("/gettoken")
|
@Path("/gettoken")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public Response getToken(@Context HttpServletRequest req) throws WebApplicationException{
|
public Response getToken(@Context HttpServletRequest req) throws WebApplicationException {
|
||||||
|
|
||||||
logger.info(this.getClass().getSimpleName()+" getToken starts...");
|
logger.info(this.getClass().getSimpleName() + " getToken starts...");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String contextToken = SecurityTokenProvider.instance.get();
|
String contextToken = SecurityTokenProvider.instance.get();
|
||||||
String scope = ScopeProvider.instance.get();
|
String scope = ScopeProvider.instance.get();
|
||||||
logger.info("ScopeProvider has scope: "+scope);
|
logger.info("ScopeProvider has scope: " + scope);
|
||||||
|
|
||||||
String appToken = req.getServletContext().getInitParameter(RequestHandler.ROOT_APP_TOKEN);
|
String appToken = req.getServletContext().getInitParameter(RequestHandler.ROOT_APP_TOKEN);
|
||||||
|
|
||||||
if(contextToken.compareTo(appToken)==0){
|
if (contextToken.compareTo(appToken) == 0) {
|
||||||
logger.error("Token not passed, SecurityTokenProvider contains the root app token: "+appToken.substring(0,10)+"...");
|
logger.error("Token not passed, SecurityTokenProvider contains the root app token: "
|
||||||
throw ExceptionManager.unauthorizedException(req, "You are not authorized. You must pass a token of VRE", this.getClass(), helpURI);
|
+ appToken.substring(0, 10) + "...");
|
||||||
|
throw ExceptionManager.unauthorizedException(req,
|
||||||
|
"You are not authorized. You must pass a token of VRE", this.getClass(), helpURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder wekeoResponse = new StringBuilder();
|
StringBuilder wekeoResponse = new StringBuilder();
|
||||||
|
@ -98,12 +97,12 @@ public class WekeoResolver {
|
||||||
logger.debug(msg);
|
logger.debug(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("The pwd is: "+wekeoPwd);
|
logger.info("The pwd is: " + wekeoPwd);
|
||||||
// decrypting the pwd
|
// decrypting the pwd
|
||||||
if (wekeoPwd != null) {
|
if (wekeoPwd != null) {
|
||||||
wekeoPwd = StringEncrypter.getEncrypter().decrypt(wekeoPwd);
|
wekeoPwd = StringEncrypter.getEncrypter().decrypt(wekeoPwd);
|
||||||
logger.info("Decrypted pwd registered into Access Point '" + wekeoAccessPoint.name() + "' is: "
|
logger.info("Decrypted pwd registered into Access Point '" + wekeoAccessPoint.name() + "' is: "
|
||||||
+ wekeoPwd.substring(0,wekeoPwd.length()/2)+"...");
|
+ wekeoPwd.substring(0, wekeoPwd.length() / 2) + "...");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wekeoUsername != null && wekeoPwd != null & wekeoAddress != null) {
|
if (wekeoUsername != null && wekeoPwd != null & wekeoAddress != null) {
|
||||||
|
@ -117,7 +116,7 @@ public class WekeoResolver {
|
||||||
String authStringEnc = new String(authEncBytes);
|
String authStringEnc = new String(authEncBytes);
|
||||||
logger.debug("Base64 encoded auth string: " + authStringEnc);
|
logger.debug("Base64 encoded auth string: " + authStringEnc);
|
||||||
|
|
||||||
logger.info("Performing the request to: "+wekeoAddress);
|
logger.info("Performing the request to: " + wekeoAddress);
|
||||||
URL url = new URL(wekeoAddress);
|
URL url = new URL(wekeoAddress);
|
||||||
connection = (HttpURLConnection) url.openConnection();
|
connection = (HttpURLConnection) url.openConnection();
|
||||||
connection.setRequestMethod("GET");
|
connection.setRequestMethod("GET");
|
||||||
|
@ -127,7 +126,7 @@ public class WekeoResolver {
|
||||||
content = (InputStream) connection.getInputStream();
|
content = (InputStream) connection.getInputStream();
|
||||||
in = new InputStreamReader(content);
|
in = new InputStreamReader(content);
|
||||||
|
|
||||||
logger.info("the response code is: "+connection.getResponseCode());
|
logger.info("the response code is: " + connection.getResponseCode());
|
||||||
|
|
||||||
int numCharsRead;
|
int numCharsRead;
|
||||||
char[] charArray = new char[1024];
|
char[] charArray = new char[1024];
|
||||||
|
@ -137,7 +136,7 @@ public class WekeoResolver {
|
||||||
sb.append(charArray, 0, numCharsRead);
|
sb.append(charArray, 0, numCharsRead);
|
||||||
}
|
}
|
||||||
wekeoResponse.append(sb.toString());
|
wekeoResponse.append(sb.toString());
|
||||||
//System.out.println(wekeoResponse);
|
// System.out.println(wekeoResponse);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error(e.getMessage(), e);
|
logger.error(e.getMessage(), e);
|
||||||
|
@ -145,12 +144,12 @@ public class WekeoResolver {
|
||||||
throw new Exception(error);
|
throw new Exception(error);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (content!= null && in != null) {
|
if (content != null && in != null) {
|
||||||
in.close();
|
in.close();
|
||||||
content.close();
|
content.close();
|
||||||
}
|
}
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//silent
|
// silent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,72 +163,83 @@ public class WekeoResolver {
|
||||||
|
|
||||||
// to be sure
|
// to be sure
|
||||||
if (wekeoResponse.length() == 0) {
|
if (wekeoResponse.length() == 0) {
|
||||||
String error = String
|
String error = String.format(
|
||||||
.format("Sorry an error occured on getting the access token from Wekeo. Please, retry the request");
|
"Sorry an error occured on getting the access token from Wekeo. Please, retry the request");
|
||||||
throw new Exception(error);
|
throw new Exception(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
String theResponse = wekeoResponse.toString();
|
String theResponse = wekeoResponse.toString();
|
||||||
logger.info("returning: \n"+theResponse);
|
logger.info("returning: \n" + theResponse);
|
||||||
|
|
||||||
return Response.ok(theResponse).build();
|
return Response.ok(theResponse).build();
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//ALREADY MANAGED AS WebApplicationException
|
// ALREADY MANAGED AS WebApplicationException
|
||||||
logger.error("Exception:", e);
|
|
||||||
throw (WebApplicationException) e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Produces({MediaType.TEXT_HTML})
|
|
||||||
@Path("")
|
|
||||||
public InputStream index(@Context HttpServletRequest req) throws WebApplicationException{
|
|
||||||
|
|
||||||
String indexFile = "/WEB-INF/jsp/wekeo.jsp";
|
|
||||||
|
|
||||||
try{
|
|
||||||
logger.info(this.getClass().getSimpleName() +" index called");
|
|
||||||
String realPath = req.getServletContext().getRealPath(indexFile);
|
|
||||||
return new FileInputStream(new File(realPath));
|
|
||||||
}catch (Exception e) {
|
|
||||||
|
|
||||||
if(!(e instanceof WebApplicationException)){
|
|
||||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
|
||||||
String error = "wekeo.jsp not found. Please, contact the support!";
|
|
||||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), null);
|
|
||||||
}
|
|
||||||
//ALREADY MANAGED AS WebApplicationException
|
|
||||||
logger.error("Exception:", e);
|
logger.error("Exception:", e);
|
||||||
throw (WebApplicationException) e;
|
throw (WebApplicationException) e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the wekeo endpoint information from IS. {The SE name is: @link WekeoResolver#RUNTIME_WKEO_RESOURCE_NAME}
|
* Index.
|
||||||
*
|
*
|
||||||
* @param req the req
|
* @param req the req
|
||||||
|
* @return the input stream
|
||||||
|
* @throws WebApplicationException the web application exception
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Produces({ MediaType.TEXT_HTML })
|
||||||
|
@Path("")
|
||||||
|
public InputStream index(@Context HttpServletRequest req) throws WebApplicationException {
|
||||||
|
|
||||||
|
String indexFile = "/WEB-INF/jsp/wekeo.jsp";
|
||||||
|
|
||||||
|
try {
|
||||||
|
logger.info(this.getClass().getSimpleName() + " index called");
|
||||||
|
String realPath = req.getServletContext().getRealPath(indexFile);
|
||||||
|
return new FileInputStream(new File(realPath));
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
if (!(e instanceof WebApplicationException)) {
|
||||||
|
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||||
|
String error = "wekeo.jsp not found. Please, contact the support!";
|
||||||
|
throw ExceptionManager.internalErrorException(req, error, this.getClass(), null);
|
||||||
|
}
|
||||||
|
// ALREADY MANAGED AS WebApplicationException
|
||||||
|
logger.error("Exception:", e);
|
||||||
|
throw (WebApplicationException) e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the wekeo endpoint information from IS. {The SE name is: @link
|
||||||
|
* WekeoResolver#RUNTIME_WKEO_RESOURCE_NAME}
|
||||||
|
*
|
||||||
|
* @param req the req
|
||||||
* @param scope the scope
|
* @param scope the scope
|
||||||
* @return the string
|
* @return the string
|
||||||
*/
|
*/
|
||||||
public static AccessPoint readWekeoServiceEndpoint(HttpServletRequest req, String scope){
|
public static AccessPoint readWekeoServiceEndpoint(HttpServletRequest req, String scope) {
|
||||||
|
|
||||||
String callerScope = null;
|
String callerScope = null;
|
||||||
try{
|
try {
|
||||||
callerScope = ScopeProvider.instance.get();
|
callerScope = ScopeProvider.instance.get();
|
||||||
ScopeProvider.instance.set(scope);
|
ScopeProvider.instance.set(scope);
|
||||||
logger.info("Searching SE "+RUNTIME_WKEO_RESOURCE_NAME+" configurations in the scope: "+ScopeProvider.instance.get());
|
logger.info("Searching SE " + RUNTIME_WKEO_RESOURCE_NAME + " configurations in the scope: "
|
||||||
|
+ ScopeProvider.instance.get());
|
||||||
|
|
||||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||||
query.addCondition("$resource/Profile/Name/text() eq '"+ RUNTIME_WKEO_RESOURCE_NAME +"'");
|
query.addCondition("$resource/Profile/Name/text() eq '" + RUNTIME_WKEO_RESOURCE_NAME + "'");
|
||||||
query.addCondition("$resource/Profile/Category/text() eq '"+ CATEGORY_WEKEO_TYPE +"'");
|
query.addCondition("$resource/Profile/Category/text() eq '" + CATEGORY_WEKEO_TYPE + "'");
|
||||||
|
|
||||||
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
||||||
List<ServiceEndpoint> toReturn = client.submit(query);
|
List<ServiceEndpoint> toReturn = client.submit(query);
|
||||||
|
|
||||||
logger.info("The query returned "+toReturn.size()+ " ServiceEndpoint/s");
|
logger.info("The query returned " + toReturn.size() + " ServiceEndpoint/s");
|
||||||
|
|
||||||
if(toReturn.size()==0){
|
if (toReturn.size() == 0) {
|
||||||
String errorMessage = String.format("Missing the RR with Name '%s' and Category '%s' in the scope '%s'. Please contact the support.",RUNTIME_WKEO_RESOURCE_NAME,CATEGORY_WEKEO_TYPE,ScopeProvider.instance.get());
|
String errorMessage = String.format(
|
||||||
|
"Missing the RR with Name '%s' and Category '%s' in the scope '%s'. Please contact the support.",
|
||||||
|
RUNTIME_WKEO_RESOURCE_NAME, CATEGORY_WEKEO_TYPE, ScopeProvider.instance.get());
|
||||||
logger.error(errorMessage);
|
logger.error(errorMessage);
|
||||||
throw ExceptionManager.notFoundException(req, errorMessage, WekeoResolver.class, helpURI);
|
throw ExceptionManager.notFoundException(req, errorMessage, WekeoResolver.class, helpURI);
|
||||||
|
|
||||||
|
@ -243,28 +253,29 @@ public class WekeoResolver {
|
||||||
for (AccessPoint accessPoint : theAccessPoints) {
|
for (AccessPoint accessPoint : theAccessPoints) {
|
||||||
wekeoUsername = accessPoint.username();
|
wekeoUsername = accessPoint.username();
|
||||||
wekeoPwd = accessPoint.password();
|
wekeoPwd = accessPoint.password();
|
||||||
if(wekeoUsername!=null && wekeoPwd!=null) {
|
if (wekeoUsername != null && wekeoPwd != null) {
|
||||||
logger.info("returning the access point with name: "+accessPoint.name());
|
logger.info("returning the access point with name: " + accessPoint.name());
|
||||||
return accessPoint;
|
return accessPoint;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}catch(Exception e){
|
} catch (Exception e) {
|
||||||
|
|
||||||
if(e instanceof NotFoundException)
|
if (e instanceof NotFoundException)
|
||||||
throw e;
|
throw e;
|
||||||
|
|
||||||
String errorMessage = "Error occurred on reading the "+RUNTIME_WKEO_RESOURCE_NAME+" SE registered in the scope: "+ScopeProvider.instance.get();
|
String errorMessage = "Error occurred on reading the " + RUNTIME_WKEO_RESOURCE_NAME
|
||||||
|
+ " SE registered in the scope: " + ScopeProvider.instance.get();
|
||||||
logger.error(errorMessage, e);
|
logger.error(errorMessage, e);
|
||||||
throw ExceptionManager.internalErrorException(req, errorMessage, WekeoResolver.class, helpURI);
|
throw ExceptionManager.internalErrorException(req, errorMessage, WekeoResolver.class, helpURI);
|
||||||
|
|
||||||
}finally{
|
} finally {
|
||||||
if(callerScope!=null){
|
if (callerScope != null) {
|
||||||
logger.info("Setting to the callerScope scope: "+callerScope);
|
logger.info("Setting to the callerScope scope: " + callerScope);
|
||||||
ScopeProvider.instance.set(callerScope);
|
ScopeProvider.instance.set(callerScope);
|
||||||
}else{
|
} else {
|
||||||
logger.info("Reset scope");
|
logger.info("Reset scope");
|
||||||
ScopeProvider.instance.reset();
|
ScopeProvider.instance.reset();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue