Merge pull request 'feature_23113' (!4) from feature_23113 into master
Reviewed-on: #4
This commit is contained in:
commit
5c10312fe6
|
@ -19,7 +19,7 @@
|
|||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
|
@ -30,5 +30,10 @@
|
|||
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
||||
org.eclipse.jdt.core.compiler.release=disabled
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
|
|
|
@ -1,37 +1,55 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
|
||||
|
||||
|
||||
|
||||
|
||||
<wb-module deploy-name="uri-resolver-2.6.1">
|
||||
|
||||
|
||||
|
||||
<wb-module deploy-name="uri-resolver-2.7.1-SNAPSHOT">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<property name="context-root" value="uri-resolver"/>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<property name="java-output-path" value="/uri-resolver/target/classes"/>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</wb-module>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</project-modules>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<faceted-project>
|
||||
<fixed facet="wst.jsdt.web"/>
|
||||
<installed facet="wst.jsdt.web" version="1.0"/>
|
||||
<installed facet="java" version="1.7"/>
|
||||
<installed facet="jst.jaxrs" version="2.0"/>
|
||||
<installed facet="jst.web" version="3.0"/>
|
||||
<installed facet="java" version="1.8"/>
|
||||
</faceted-project>
|
||||
|
|
24
CHANGELOG.md
24
CHANGELOG.md
|
@ -4,6 +4,30 @@
|
|||
All notable changes to this project will be documented in this file.
|
||||
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [v2-7.2-SNAPSHOT] - 2022-04-05
|
||||
|
||||
**New**
|
||||
|
||||
- [#23113] Implemented a new legacy-token resolver interface
|
||||
|
||||
## [v2-7.1-SNAPSHOT] - 2022-03-29
|
||||
|
||||
**New**
|
||||
|
||||
- [#23049] Integrate Enunciate engine for Java Web service API (https://github.com/stoicflame/enunciate/)
|
||||
- [#20743] Integrate JavaMelody
|
||||
- [#23105] Added D4Science brand in the APIs Documentation pages
|
||||
|
||||
## [v2-7.0-SNAPSHOT] - 2022-01-31
|
||||
|
||||
**New**
|
||||
|
||||
- [#22757] moved to storagehub-client-library 2.0.0[-SNAPSHOT]
|
||||
|
||||
** Bug Fixing**
|
||||
|
||||
- [#20743] Integration with javamelody
|
||||
|
||||
## [v2-6-1] - 2022-01-17
|
||||
|
||||
**New features**
|
||||
|
|
|
@ -11,6 +11,8 @@ The URI Resolver is a RESTful service which gives access via HTTP(s) to differen
|
|||
|
||||
You can find the URI Resolver documentation at [URI Resolver Wiki Page](https://wiki.gcube-system.org/gcube/URI_Resolver)
|
||||
|
||||
The API documentation accessible by [links](https://wiki.gcube-system.org/gcube/URI_Resolver#Instances) is provided by [Enunciate](https://github.com/stoicflame/enunciate/)
|
||||
|
||||
## Change log
|
||||
|
||||
See the [URI Resolver Releases](https://code-repo.d4science.org/gCubeSystem/uri-resolver/releases)
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<enunciate
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="http://enunciate.webcohesion.com/schemas/enunciate-2.14.0.xsd">
|
||||
|
||||
<api-classes>
|
||||
<exclude
|
||||
pattern="org.gcube.datatransfer.resolver.services.DocsGenerator" />
|
||||
<exclude
|
||||
pattern="org.gcube.datatransfer.resolver.services.UriResolverIndex" />
|
||||
<exclude
|
||||
pattern="org.gcube.datatransfer.resolver.services.UriResolverInfo" />
|
||||
<exclude pattern="org.gcube.datatransfer.resolver.services.OatResolver" />
|
||||
<exclude
|
||||
pattern="org.gcube.datatransfer.resolver.services.tobackward.BackCatalogueResolver" />
|
||||
<exclude
|
||||
pattern="org.gcube.datatransfer.resolver.services.tobackward.BackUriResolverCatalogueResolver" />
|
||||
</api-classes>
|
||||
|
||||
<modules>
|
||||
<gwt-json-overlay disabled="true" />
|
||||
<php-json-client disabled="true" />
|
||||
<ruby-json-client disabled="true" />
|
||||
<java-json-client disabled="true" />
|
||||
<javascript-client disabled="true" />
|
||||
<docs docsDir="${project.build.directory}" docsSubdir="docs" />
|
||||
<!-- REPLACE THE ${project.artifactId} WITH YOUR APPLICATION NAME. E.g.
|
||||
/gcat, /uri-resolver /> if the ${project.artifactId} is not equal to YOUR
|
||||
APPLICATION NAME -->
|
||||
<!-- <swagger basePath="${project.artifactId}" /> -->
|
||||
<docs
|
||||
freemarkerTemplate="${project.basedir}/src/main/resources/META-INF/enunciate/d4science_docs.fmt">
|
||||
<additional-css
|
||||
file="css/d4science_enunciate_custom.css" />
|
||||
</docs>
|
||||
</modules>
|
||||
|
||||
</enunciate>
|
110
pom.xml
110
pom.xml
|
@ -9,9 +9,9 @@
|
|||
</parent>
|
||||
<groupId>org.gcube.data.transfer</groupId>
|
||||
<artifactId>uri-resolver</artifactId>
|
||||
<version>2.6.1</version>
|
||||
<version>2.7.2-SNAPSHOT</version>
|
||||
<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>
|
||||
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
|
||||
|
@ -21,9 +21,9 @@
|
|||
|
||||
<properties>
|
||||
<jersey.version>2.24.1</jersey.version>
|
||||
<maven.compiler.source>1.7</maven.compiler.source>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<!-- <additionalparam>-Xdoclint:none</additionalparam> -->
|
||||
<enunciate.version>2.14.0</enunciate.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
@ -77,8 +77,15 @@
|
|||
<groupId>org.gcube.data-publishing</groupId>
|
||||
<artifactId>storagehub-application-persistence</artifactId>
|
||||
<version>[1.0.0, 2.0.0-SNAPSHOT)</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>storagehub-client-library</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.data.analysis</groupId>
|
||||
<artifactId>dataminer-invocation-model</artifactId>
|
||||
|
@ -116,7 +123,7 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>storagehub-client-library</artifactId>
|
||||
<version>[1.0.0, 2.0.0-SNAPSHOT)</version>
|
||||
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -133,24 +140,39 @@
|
|||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- java melody -->
|
||||
<dependency>
|
||||
<groupId>net.bull.javamelody</groupId>
|
||||
<artifactId>javamelody-core</artifactId>
|
||||
<version>1.82.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/javax.interceptor/javax.interceptor-api -->
|
||||
<dependency>
|
||||
<groupId>javax.interceptor</groupId>
|
||||
<artifactId>javax.interceptor-api</artifactId>
|
||||
<version>1.2.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- weld -->
|
||||
<dependency>
|
||||
<groupId>javax.enterprise</groupId>
|
||||
<artifactId>cdi-api</artifactId>
|
||||
<version>1.1</version>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.weld.servlet</groupId>
|
||||
<artifactId>weld-servlet</artifactId>
|
||||
<version>2.2.10.Final</version>
|
||||
<artifactId>weld-servlet-core</artifactId>
|
||||
<version>3.1.0.Final</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jboss</groupId>
|
||||
<artifactId>jandex</artifactId>
|
||||
<version>1.2.2.Final</version>
|
||||
<version>2.2.2.Final</version>
|
||||
</dependency>
|
||||
|
||||
<!-- end weld -->
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
|
@ -180,19 +202,6 @@
|
|||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- REMOVE THIS ON RELESE, IT IS NEEDED TO compile 'geonetwork' -->
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>org.opengis</groupId> -->
|
||||
<!-- <artifactId>geoapi</artifactId> -->
|
||||
<!-- <version>3.0.0</version> -->
|
||||
<!-- </dependency> -->
|
||||
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>org.geotoolkit</groupId> -->
|
||||
<!-- <artifactId>geotk-xml-base</artifactId> -->
|
||||
<!-- <version>3.20-geoapi-3.0</version> -->
|
||||
<!-- </dependency> -->
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
|
@ -241,6 +250,14 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Required for Enunciate plugin -->
|
||||
<dependency>
|
||||
<groupId>org.geotoolkit</groupId>
|
||||
<artifactId>geotk-xml-base</artifactId>
|
||||
<version>3.20-geoapi-3.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -261,8 +278,6 @@
|
|||
</resource>
|
||||
</resources>
|
||||
|
||||
<!-- <finalName>${artifactId}</finalName> -->
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
|
@ -271,24 +286,51 @@
|
|||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- Enunciate Maven plugin -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<groupId>com.webcohesion.enunciate</groupId>
|
||||
<artifactId>enunciate-maven-plugin</artifactId>
|
||||
<version>${enunciate.version}</version>
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<descriptor>descriptor.xml</descriptor>
|
||||
</descriptors>
|
||||
<!-- <docsDir>${project.build.directory}/docs</docsDir> -->
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>servicearchive</id>
|
||||
<phase>install</phase>
|
||||
<id>assemble</id>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
<goal>assemble</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- Copy Enunciate Docs -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.5</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-enunciate-docs</id>
|
||||
<phase>process-resources</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>target</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<targetPath>${project.build.directory}/${project.artifactId}-${project.version}/docs</targetPath>
|
||||
<directory>${project.build.directory}/docs</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
</project>
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package org.gcube.datatransfer.resolver.catalogue;
|
||||
|
||||
|
||||
/**
|
||||
* The Class CatalogueRequest.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Nov 6, 2018
|
||||
*
|
||||
* Binding Catalogue Request as a JSON
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Mar 24, 2022
|
||||
*
|
||||
* Binding Catalogue Request as a JSON
|
||||
*/
|
||||
public class CatalogueRequest {
|
||||
|
||||
|
@ -42,7 +42,14 @@ public class CatalogueRequest {
|
|||
return entity_name;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/**
|
||||
* To string.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
|
|
|
@ -11,20 +11,41 @@ import lombok.NoArgsConstructor;
|
|||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Nov 26, 2018
|
||||
* Instantiates a new parthenos request.
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
|
||||
/**
|
||||
* Instantiates a new parthenos request.
|
||||
*
|
||||
* @param entity_name the entity name
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
|
||||
/**
|
||||
* Gets the entity name.
|
||||
*
|
||||
* @return the entity name
|
||||
*/
|
||||
@Getter
|
||||
|
||||
/**
|
||||
* Sets the entity name.
|
||||
*
|
||||
* @param entity_name the new entity name
|
||||
*/
|
||||
@Setter
|
||||
|
||||
/**
|
||||
* To string.
|
||||
*
|
||||
* @return the java.lang. string
|
||||
*/
|
||||
@ToString
|
||||
public class ParthenosRequest {
|
||||
|
||||
@JsonProperty(value="entity_name", required=true)
|
||||
@JsonProperty(value = "entity_name", required = true)
|
||||
private String entity_name;
|
||||
|
||||
}
|
||||
|
|
|
@ -57,10 +57,15 @@ import org.slf4j.LoggerFactory;
|
|||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* The Class AnalyticsCreateResolver.
|
||||
*
|
||||
* The AnalyticsCreateResolver provides a method to get the Analytics URLs by
|
||||
* which is possible to invoke through the DataMiner Executor the run of an
|
||||
* algorithm stored in a certain VRE.
|
||||
*
|
||||
* See more at
|
||||
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Analytics_Resolver
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Dec 12, 2018
|
||||
* Dec 12, 2018
|
||||
*/
|
||||
@Path("analytics")
|
||||
public class AnalyticsCreateResolver {
|
||||
|
@ -77,11 +82,15 @@ public class AnalyticsCreateResolver {
|
|||
private static Logger logger = LoggerFactory.getLogger(AnalyticsCreateResolver.class);
|
||||
private static String helpURI = "https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Analytics_Resolver";
|
||||
|
||||
|
||||
/**
|
||||
* Creates the analytics url.
|
||||
*
|
||||
* @param req the req
|
||||
*
|
||||
* Request format: [URI_RESOLVER_SERVICE_ENDPOINT]/analytics/create
|
||||
*
|
||||
* See more at
|
||||
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#HTTP_POST:_Create_an_Analytics_URL
|
||||
*
|
||||
* @param req the req
|
||||
* @param body the body
|
||||
* @return the response
|
||||
* @throws WebApplicationException the web application exception
|
||||
|
@ -90,58 +99,65 @@ public class AnalyticsCreateResolver {
|
|||
@Path("/create")
|
||||
@Consumes(MediaType.TEXT_PLAIN)
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public Response createAnalyticsURL(@Context HttpServletRequest req, String body) throws WebApplicationException{
|
||||
logger.info(this.getClass().getSimpleName()+" POST starts...");
|
||||
public Response createAnalyticsURL(@Context HttpServletRequest req, String body) throws WebApplicationException {
|
||||
logger.info(this.getClass().getSimpleName() + " POST starts...");
|
||||
|
||||
try{
|
||||
logger.info("body is: "+body);
|
||||
try {
|
||||
logger.info("body is: " + body);
|
||||
|
||||
DataMinerInvocation jsonRequest = null;
|
||||
try {
|
||||
|
||||
jsonRequest = DataMinerInvocationManager.getInstance().unmarshalingJSON(IOUtils.toInputStream(body), true);
|
||||
}
|
||||
catch (IOException | JAXBException | SAXException 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);
|
||||
jsonRequest = DataMinerInvocationManager.getInstance().unmarshalingJSON(IOUtils.toInputStream(body),
|
||||
true);
|
||||
} catch (IOException | JAXBException | SAXException 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);
|
||||
}
|
||||
|
||||
logger.debug("The body contains the request: "+jsonRequest.toString());
|
||||
logger.debug("The body contains the request: " + jsonRequest.toString());
|
||||
|
||||
String contextToken = SecurityTokenProvider.instance.get();
|
||||
String scope = ScopeProvider.instance.get();
|
||||
// logger.info("SecurityTokenProvider contextToken: "+contextToken);
|
||||
logger.info("ScopeProvider has scope: "+scope);
|
||||
// logger.info("SecurityTokenProvider contextToken: "+contextToken);
|
||||
logger.info("ScopeProvider has scope: " + scope);
|
||||
|
||||
String appToken = req.getServletContext().getInitParameter(RequestHandler.ROOT_APP_TOKEN);
|
||||
|
||||
if(contextToken.compareTo(appToken)==0){
|
||||
logger.error("Token not passed, SecurityTokenProvider contains the root app token: "+appToken.substring(0,10)+"...");
|
||||
throw ExceptionManager.unauthorizedException(req, "You are not authorized. You must pass a token of VRE", this.getClass(), helpURI);
|
||||
if (contextToken.compareTo(appToken) == 0) {
|
||||
logger.error("Token not passed, SecurityTokenProvider contains the root app token: "
|
||||
+ 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();
|
||||
|
||||
if(scope==null || scope.isEmpty()){
|
||||
if (scope == null || scope.isEmpty()) {
|
||||
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");
|
||||
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);
|
||||
String publicLinkToDMInvFile = "";
|
||||
|
||||
if(scopeBean.is(Type.VRE)){
|
||||
if (scopeBean.is(Type.VRE)) {
|
||||
String vreName = scopeBean.name();
|
||||
|
||||
String analyticsGetResolverURL = String.format("%s/%s", Util.getServerURL(req), "analytics/get");
|
||||
//Creating DM invocation file
|
||||
if(jsonRequest.getActionType()==null)
|
||||
String analyticsGetResolverURL = String.format("%s/%s", Util.getServerURL(req), "analytics/get");
|
||||
// Creating DM invocation file
|
||||
if (jsonRequest.getActionType() == null)
|
||||
jsonRequest.setActionType(ActionType.RUN);
|
||||
|
||||
File tempInvocationFile = null;
|
||||
|
@ -150,17 +166,20 @@ public class AnalyticsCreateResolver {
|
|||
String xmlRequest = DataMinerInvocationManager.getInstance().marshalingXML(jsonRequest, true, true);
|
||||
String uniqueName = createDMInvocationFileName(jsonRequest.getOperatorId());
|
||||
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);
|
||||
//retrieve the info of the token owner
|
||||
// retrieve the info of the token owner
|
||||
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 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);
|
||||
ApplicationMode applicationMode = new ApplicationMode(theAppToken);
|
||||
applicationMode.start();
|
||||
|
@ -170,140 +189,156 @@ public class AnalyticsCreateResolver {
|
|||
Map<String, String> theMap = new HashMap<String, String>();
|
||||
theMap.put("owner", owner);
|
||||
URL thePublicLink = null;
|
||||
try{
|
||||
try {
|
||||
|
||||
logger.info("Saving dataminer-invocation file for the user: "+owner);
|
||||
thePublicLink = storageHubManagement.persistFile(new FileInputStream(tempInvocationFile), tempInvocationFile.getName(), "application/xml", metadata);
|
||||
logger.info("Saved dataminer-invocation file at: "+thePublicLink);
|
||||
}catch(Exception e){
|
||||
logger.info("Saving dataminer-invocation file for the user: " + owner);
|
||||
thePublicLink = storageHubManagement.persistFile(new FileInputStream(tempInvocationFile),
|
||||
tempInvocationFile.getName(), "application/xml", metadata);
|
||||
logger.info("Saved dataminer-invocation file at: " + thePublicLink);
|
||||
} catch (Exception 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());
|
||||
// logger.info("UPLOADED FILE at: "+fileContainer.getPublicLink());
|
||||
// URL thePublicLink = fileContainer.getPublicLink();
|
||||
publicLinkToDMInvFile = thePublicLink!=null?thePublicLink.toString():null;
|
||||
}
|
||||
catch (Exception e) {
|
||||
publicLinkToDMInvFile = thePublicLink != null ? thePublicLink.toString() : null;
|
||||
} catch (Exception e) {
|
||||
|
||||
if(e instanceof InternalServerException){
|
||||
//error during storing the file via StorageHubManagent
|
||||
if (e instanceof InternalServerException) {
|
||||
// error during storing the file via StorageHubManagent
|
||||
throw 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);
|
||||
}finally{
|
||||
//No needed to reset the scope, it is provided by TokenSetter
|
||||
try{
|
||||
//DELETING THE TEMP FILE
|
||||
if(tempInvocationFile!=null && tempInvocationFile.exists())
|
||||
tempInvocationFile.delete();
|
||||
}catch(Exception e){
|
||||
//silent
|
||||
throw ExceptionManager.badRequestException(req,
|
||||
"Error on creating your 'dataminer-invocation' request with " + jsonRequest
|
||||
+ ". \nPlease contact the support",
|
||||
this.getClass(), helpURI);
|
||||
} finally {
|
||||
// No needed to reset the scope, it is provided by TokenSetter
|
||||
try {
|
||||
// DELETING THE TEMP FILE
|
||||
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");
|
||||
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);
|
||||
logger.info("Returning Analytics URL: "+dataMinerURL);
|
||||
String dataMinerURL = String.format("%s/%s?%s=%s", analyticsGetResolverURL, vreName,
|
||||
DATAMINER_INVOCATION_MODEL, publicLinkToDMInvFile);
|
||||
logger.info("Returning Analytics URL: " + dataMinerURL);
|
||||
return Response.ok(dataMinerURL).header("Location", dataMinerURL).build();
|
||||
|
||||
}else{
|
||||
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);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
|
||||
if(!(e instanceof WebApplicationException)){
|
||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error occurred on creating the Analytics for the request "+body+". Please, contact the support!";
|
||||
if(e.getCause()!=null)
|
||||
error+="\n\nCaused: "+e.getCause().getMessage();
|
||||
if (!(e instanceof WebApplicationException)) {
|
||||
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error occurred on creating the Analytics for the request " + body
|
||||
+ ". Please, contact the support!";
|
||||
if (e.getCause() != null)
|
||||
error += "\n\nCaused: " + e.getCause().getMessage();
|
||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||
}
|
||||
//ALREADY MANAGED AS WebApplicationException
|
||||
// ALREADY MANAGED AS WebApplicationException
|
||||
logger.error("Exception:", 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
|
||||
* @return the string
|
||||
*/
|
||||
private static String readApplicationTokenFromSE(HttpServletRequest req, String scope){
|
||||
private static String readApplicationTokenFromSE(HttpServletRequest req, String scope) {
|
||||
|
||||
String callerScope = null;
|
||||
String gCubeAppToken = null;
|
||||
try{
|
||||
try {
|
||||
callerScope = ScopeProvider.instance.get();
|
||||
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);
|
||||
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'");
|
||||
|
||||
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
||||
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){
|
||||
String errorMessage = "No "+ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME+" registered in the scope: "+ScopeProvider.instance.get();
|
||||
if (toReturn.size() == 0) {
|
||||
String errorMessage = "No " + ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME + " registered in the scope: "
|
||||
+ ScopeProvider.instance.get();
|
||||
logger.error(errorMessage);
|
||||
throw ExceptionManager.internalErrorException(req, errorMessage, AnalyticsCreateResolver.class, helpURI);
|
||||
throw ExceptionManager.internalErrorException(req, errorMessage, AnalyticsCreateResolver.class,
|
||||
helpURI);
|
||||
}
|
||||
|
||||
|
||||
ServiceEndpoint se = toReturn.get(0);
|
||||
Collection<AccessPoint> theAccessPoints = se.profile().accessPoints().asCollection();
|
||||
for (AccessPoint accessPoint : theAccessPoints) {
|
||||
Collection<Property> properties = accessPoint.properties().asCollection();
|
||||
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");
|
||||
gCubeAppToken = property.value();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(gCubeAppToken!=null)
|
||||
if (gCubeAppToken != null)
|
||||
break;
|
||||
}
|
||||
|
||||
if(gCubeAppToken!=null){
|
||||
if (gCubeAppToken != null) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
String errorMessage = "No "+GCUBE_TOKEN+" as Property saved in the "+ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME+" SE registered in the scope: "+ScopeProvider.instance.get();
|
||||
String errorMessage = "No " + GCUBE_TOKEN + " as Property saved in the "
|
||||
+ ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME + " SE registered in the scope: "
|
||||
+ ScopeProvider.instance.get();
|
||||
logger.error(errorMessage);
|
||||
throw ExceptionManager.internalErrorException(req, errorMessage, AnalyticsCreateResolver.class, helpURI);
|
||||
|
||||
|
||||
}catch(Exception e){
|
||||
String errorMessage = "Error occurred on reading the "+ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME+" SE registered in the scope: "+ScopeProvider.instance.get();
|
||||
} catch (Exception e) {
|
||||
String errorMessage = "Error occurred on reading the " + ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME
|
||||
+ " SE registered in the scope: " + ScopeProvider.instance.get();
|
||||
logger.error(errorMessage, e);
|
||||
throw ExceptionManager.internalErrorException(req, errorMessage, AnalyticsCreateResolver.class, helpURI);
|
||||
|
||||
}finally{
|
||||
if(callerScope!=null){
|
||||
logger.info("Setting to the callerScope scope: "+callerScope);
|
||||
} finally {
|
||||
if (callerScope != null) {
|
||||
logger.info("Setting to the callerScope scope: " + callerScope);
|
||||
ScopeProvider.instance.set(callerScope);
|
||||
}else{
|
||||
} else {
|
||||
logger.info("Reset scope");
|
||||
ScopeProvider.instance.reset();
|
||||
}
|
||||
|
@ -311,48 +346,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.
|
||||
*
|
||||
* @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 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();
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
// public static void main(String[] args) {
|
||||
//
|
||||
// System.out.println(readApplicationTokenFromSE(null, "/gcube"));
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,20 +23,22 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
|
||||
|
||||
|
||||
/**
|
||||
* The Class AnalyticsGetResolver.
|
||||
* The AnalyticsGetResolver to resolve an Analytics URL
|
||||
*
|
||||
* See more at
|
||||
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Analytics_Resolver
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Dec 13, 2018
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Mar 24, 2022
|
||||
*/
|
||||
@Path("analytics")
|
||||
public class AnalyticsGetResolver {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(AnalyticsGetResolver.class);
|
||||
|
||||
private static final String ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL =
|
||||
"org.gcube.portlets.user.dataminermanager.server.DataMinerManagerServiceImpl";
|
||||
private static final String ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL = "org.gcube.portlets.user.dataminermanager.server.DataMinerManagerServiceImpl";
|
||||
|
||||
private static final String APPLICATION_PROFILE = "ApplicationProfile";
|
||||
|
||||
|
@ -44,60 +46,73 @@ public class AnalyticsGetResolver {
|
|||
|
||||
private static final String ANALYTICS_EXECUTOR_PORTLET_NAME = "Analytics Executor";
|
||||
|
||||
|
||||
/**
|
||||
* Resolve analytics url.
|
||||
*
|
||||
* @param req the req
|
||||
* See more at
|
||||
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#HTTP_GET:_Resolve_an_Analytics_URL
|
||||
*
|
||||
* @param req the req
|
||||
* @param vreName the vre name
|
||||
* @return the response
|
||||
* @throws WebApplicationException the web application exception
|
||||
*/
|
||||
@GET
|
||||
@Path("/get/{vreName}")
|
||||
public Response resolveAnalyticsURL(@Context HttpServletRequest req, @PathParam("vreName") String vreName) throws WebApplicationException{
|
||||
logger.info(this.getClass().getSimpleName()+" GET starts...");
|
||||
public Response resolveAnalyticsURL(@Context HttpServletRequest req, @PathParam("vreName") String vreName)
|
||||
throws WebApplicationException {
|
||||
logger.info(this.getClass().getSimpleName() + " GET starts...");
|
||||
try {
|
||||
|
||||
if(vreName==null || vreName.isEmpty()){
|
||||
if (vreName == null || vreName.isEmpty()) {
|
||||
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;
|
||||
|
||||
//CHECKING IF THE INPUT VRE NAME IS REGISTRED IN THE INFRASTRUCTURE...
|
||||
try{
|
||||
// CHECKING IF THE INPUT VRE NAME IS REGISTRED IN THE INFRASTRUCTURE...
|
||||
try {
|
||||
fullScopeBean = LoadingMapOfScopeCache.get(vreName);
|
||||
}catch(ExecutionException | InvalidCacheLoadException 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);
|
||||
} catch (ExecutionException | InvalidCacheLoadException 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);
|
||||
}
|
||||
ApplicationProfileReader reader = null;
|
||||
try{
|
||||
reader = new ApplicationProfileReader(fullScopeBean.toString(), APPLICATION_PROFILE, ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL, false);
|
||||
}catch(Exception e){
|
||||
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);
|
||||
try {
|
||||
reader = new ApplicationProfileReader(fullScopeBean.toString(), APPLICATION_PROFILE,
|
||||
ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL, false);
|
||||
} catch (Exception e) {
|
||||
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();
|
||||
//CHECKING THE QUERY STRING
|
||||
String queryString = req.getQueryString()!=null?req.getQueryString():"";
|
||||
// CHECKING THE QUERY STRING
|
||||
String queryString = req.getQueryString() != null ? req.getQueryString() : "";
|
||||
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();
|
||||
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
|
||||
if(!(e instanceof WebApplicationException)){
|
||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
if (!(e instanceof WebApplicationException)) {
|
||||
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error occurred on resolving the Analytics URL. Please, contact the support!";
|
||||
if(e.getCause()!=null)
|
||||
error+="\n\nCaused: "+e.getCause().getMessage();
|
||||
if (e.getCause() != null)
|
||||
error += "\n\nCaused: " + e.getCause().getMessage();
|
||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||
}
|
||||
//ALREADY MANAGED AS WebApplicationException
|
||||
// ALREADY MANAGED AS WebApplicationException
|
||||
logger.error("Exception:", e);
|
||||
throw (WebApplicationException) e;
|
||||
}
|
||||
|
|
|
@ -44,36 +44,51 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
|
|||
import eu.trentorise.opendata.jackan.model.CkanDataset;
|
||||
|
||||
/**
|
||||
* The Class CatalogueResolver.
|
||||
* The CatalogueResolver is able to get/resolve a link to a "Catalogue Entity"
|
||||
* stored in one of the D4Science Catalogue's instances. A Catalogue Entity is
|
||||
* either a "group" or an "organization" or a "product" of D4Science Data
|
||||
* Catalogue.
|
||||
*
|
||||
* See more at
|
||||
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#CATALOGUE_Resolver
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Nov 16, 2018
|
||||
* Nov 16, 2018
|
||||
*/
|
||||
@Path("{entityContext:ctlg(-(o|g|p|d))?}")
|
||||
public class CatalogueResolver {
|
||||
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(CatalogueResolver.class);
|
||||
private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#CATALOGUE_Resolver";
|
||||
private static enum SCOPE_STATUS {ACTIVE, DETACHED}
|
||||
|
||||
/**
|
||||
* Resolve catalogue.
|
||||
* The Enum SCOPE_STATUS.
|
||||
*
|
||||
* @param req the req
|
||||
* @param entityName the entity name
|
||||
* @param vreName the vre name
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Mar 24, 2022
|
||||
*/
|
||||
private static enum SCOPE_STATUS {
|
||||
ACTIVE, DETACHED
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve an entity of the Catalogue
|
||||
*
|
||||
* @param req the req
|
||||
* @param entityName the entity name
|
||||
* @param vreName the vre name
|
||||
* @param entityContext the entity context
|
||||
* @return the response
|
||||
* @throws WebApplicationException the web application exception
|
||||
*/
|
||||
@GET
|
||||
@Path("/{vreName}/{entityName}")
|
||||
public Response resolveCatalogue(@Context HttpServletRequest req,
|
||||
@PathParam("entityName") String entityName,
|
||||
@PathParam("vreName") String vreName,
|
||||
@PathParam("entityContext") String entityContext) throws WebApplicationException{
|
||||
public Response resolveCatalogue(@Context HttpServletRequest req, @PathParam("entityName") String entityName,
|
||||
@PathParam("vreName") String vreName, @PathParam("entityContext") String entityContext)
|
||||
throws WebApplicationException {
|
||||
|
||||
logger.info(this.getClass().getSimpleName()+" GET starts...");
|
||||
logger.info(this.getClass().getSimpleName() + " GET starts...");
|
||||
|
||||
try {
|
||||
InnerMethodName.instance.set("resolveCataloguePublicLink");
|
||||
|
@ -81,96 +96,111 @@ public class CatalogueResolver {
|
|||
|
||||
String itemCatalogueURL;
|
||||
|
||||
if(itemCatalogueURLs.isPublicItem()){
|
||||
logger.info("The dataset "+itemCatalogueURLs.getItemName()+" was detected as public item (not private to VRE)");
|
||||
if(itemCatalogueURLs.getPublicVRECataloguePortletURL()!=null && !itemCatalogueURLs.getPublicVRECataloguePortletURL().isEmpty()) {
|
||||
if (itemCatalogueURLs.isPublicItem()) {
|
||||
logger.info("The dataset " + itemCatalogueURLs.getItemName()
|
||||
+ " was detected as public item (not private to VRE)");
|
||||
if (itemCatalogueURLs.getPublicVRECataloguePortletURL() != null
|
||||
&& !itemCatalogueURLs.getPublicVRECataloguePortletURL().isEmpty()) {
|
||||
itemCatalogueURL = itemCatalogueURLs.getPublicVRECataloguePortletURL();
|
||||
logger.info("I found the public VRE catalogue URL, so using public access to it: "+itemCatalogueURL);
|
||||
}else {
|
||||
logger.info(
|
||||
"I found the public VRE catalogue URL, so using public access to it: " + itemCatalogueURL);
|
||||
} else {
|
||||
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();
|
||||
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();
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
|
||||
if(!(e instanceof WebApplicationException)){
|
||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
if (!(e instanceof WebApplicationException)) {
|
||||
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error occurred on resolving the Catalgoue URL. Please, contact the support!";
|
||||
if(e.getCause()!=null)
|
||||
error+="\n\nCaused: "+e.getCause().getMessage();
|
||||
if (e.getCause() != null)
|
||||
error += "\n\nCaused: " + e.getCause().getMessage();
|
||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||
}
|
||||
//ALREADY MANAGED AS WebApplicationException
|
||||
// ALREADY MANAGED AS WebApplicationException
|
||||
logger.error("Exception:", e);
|
||||
throw (WebApplicationException) e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Post catalogue.
|
||||
* Create a Catalogue Link
|
||||
*
|
||||
*
|
||||
* @param req the req
|
||||
* @param req the req
|
||||
* @param jsonRequest the json request
|
||||
* @return the response
|
||||
* @throws WebApplicationException the web application exception
|
||||
*/
|
||||
@POST
|
||||
@Path("")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public Response postCatalogue(@Context HttpServletRequest req, CatalogueRequest jsonRequest) throws WebApplicationException{
|
||||
logger.info(this.getClass().getSimpleName()+" POST starts...");
|
||||
public Response postCatalogue(@Context HttpServletRequest req, CatalogueRequest jsonRequest)
|
||||
throws WebApplicationException {
|
||||
logger.info(this.getClass().getSimpleName() + " POST starts...");
|
||||
|
||||
try{
|
||||
try {
|
||||
|
||||
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();
|
||||
if(!scope.startsWith(ConstantsResolver.SCOPE_SEPARATOR)){
|
||||
logger.info("Scope not start with char '{}' adding it",ConstantsResolver.SCOPE_SEPARATOR);
|
||||
scope+=ConstantsResolver.SCOPE_SEPARATOR+scope;
|
||||
if (!scope.startsWith(ConstantsResolver.SCOPE_SEPARATOR)) {
|
||||
logger.info("Scope not start with char '{}' adding it", ConstantsResolver.SCOPE_SEPARATOR);
|
||||
scope += ConstantsResolver.SCOPE_SEPARATOR + scope;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
//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 {
|
||||
fullScope = LoadingMapOfScopeCache.get(vreName);
|
||||
}catch(ExecutionException 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);
|
||||
} catch (ExecutionException 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);
|
||||
}
|
||||
|
||||
if(fullScope==null)
|
||||
throw ExceptionManager.notFoundException(req, "The scope '"+scope+"' does not matching any scope in the infrastructure. Is it valid?", this.getClass(), helpURI);
|
||||
if (fullScope == null)
|
||||
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());
|
||||
if(rc==null){
|
||||
if (rc == null) {
|
||||
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());
|
||||
logger.info("Returining Catalogue URL: "+linkURL);
|
||||
logger.info("Returining Catalogue URL: " + linkURL);
|
||||
return Response.ok(linkURL).header("Location", linkURL).build();
|
||||
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
|
||||
if(!(e instanceof WebApplicationException)){
|
||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
if (!(e instanceof WebApplicationException)) {
|
||||
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error occurred on resolving the Analytics URL. Please, contact the support!";
|
||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||
}
|
||||
//ALREADY MANAGED AS WebApplicationExceptiongetItemCatalogueURLs
|
||||
// ALREADY MANAGED AS WebApplicationExceptiongetItemCatalogueURLs
|
||||
logger.error("Exception:", e);
|
||||
throw (WebApplicationException) e;
|
||||
}
|
||||
|
@ -179,25 +209,28 @@ public class CatalogueResolver {
|
|||
/**
|
||||
* Gets the item catalogue UR ls.
|
||||
*
|
||||
* @param req the req
|
||||
* @param scopeName the scope name
|
||||
* @param req the req
|
||||
* @param scopeName the scope name
|
||||
* @param entityContext the entity context
|
||||
* @param entityName the entity name
|
||||
* @param entityName the entity name
|
||||
* @return the item catalogue UR ls
|
||||
* @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 {
|
||||
String entityContextValue = ResourceCatalogueCodes.valueOfCodeId(entityContext).getValue();
|
||||
ScopeBean scopeBean = null;
|
||||
SCOPE_STATUS scopeStatus = SCOPE_STATUS.ACTIVE;
|
||||
VRE vreDetached = null;
|
||||
try{
|
||||
try {
|
||||
scopeBean = LoadingMapOfScopeCache.get(scopeName);
|
||||
}catch(ExecutionException | InvalidCacheLoadException e){
|
||||
logger.error("Error on getting the fullscope from cache for scopeName {}. Tryng to load it from DetachedRE",scopeName);
|
||||
|
||||
} catch (ExecutionException | InvalidCacheLoadException e) {
|
||||
logger.error(
|
||||
"Error on getting the fullscope from cache for scopeName {}. Tryng to load it from DetachedRE",
|
||||
scopeName);
|
||||
|
||||
boolean isScopeDetached = false;
|
||||
try {
|
||||
vreDetached = LoadingMapOfDetachedVRE.get(scopeName);
|
||||
|
@ -205,106 +238,115 @@ public class CatalogueResolver {
|
|||
scopeStatus = SCOPE_STATUS.DETACHED;
|
||||
logger.info("I loaded a valid VRE obj for scope name {}", scopeName);
|
||||
isScopeDetached = true;
|
||||
}catch (Exception e1) {
|
||||
logger.warn("I was not able to load a detached VRE for vreName {}. Going to error for wrong scope",scopeName);
|
||||
} catch (Exception e1) {
|
||||
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(!isScopeDetached) {
|
||||
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);
|
||||
|
||||
// If is not a cas of scope detached, going to error for wrong scope
|
||||
if (!isScopeDetached) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String fullScope = scopeBean.toString();
|
||||
logger.info("Read fullScope: "+fullScope + " for SCOPE name: "+scopeName +" from cache created by: "+GetAllInfrastructureScopes.class.getSimpleName());
|
||||
|
||||
if(scopeBean.is(Type.VO)) {
|
||||
logger.info("Read fullScope: " + fullScope + " for SCOPE name: " + scopeName + " from cache created by: "
|
||||
+ GetAllInfrastructureScopes.class.getSimpleName());
|
||||
|
||||
if (scopeBean.is(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);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
ScopeProvider.instance.set(fullScope);
|
||||
GatewayCKANCatalogueReference ckanCatalogueReference = null;
|
||||
logger.info("Managing scope status: {}",scopeStatus);
|
||||
|
||||
logger.info("Managing scope status: {}", scopeStatus);
|
||||
|
||||
switch (scopeStatus) {
|
||||
case DETACHED:
|
||||
|
||||
|
||||
String privatePortletURL = vreDetached.getCatalogPortletURL();
|
||||
//The private portlet URL
|
||||
Map<ACCESS_LEVEL_TO_CATALOGUE_PORTLET, String> mapAccessURLToCatalogue = new HashMap<ACCESS_LEVEL_TO_CATALOGUE_PORTLET, String>(3);
|
||||
mapAccessURLToCatalogue.put(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PRIVATE_VRE,privatePortletURL);
|
||||
|
||||
//Building the gateway catalogue public URL from private VRE Portlet URL
|
||||
// The private portlet URL
|
||||
Map<ACCESS_LEVEL_TO_CATALOGUE_PORTLET, String> mapAccessURLToCatalogue = new HashMap<ACCESS_LEVEL_TO_CATALOGUE_PORTLET, String>(
|
||||
3);
|
||||
mapAccessURLToCatalogue.put(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PRIVATE_VRE, privatePortletURL);
|
||||
|
||||
// Building the gateway catalogue public URL from private VRE Portlet URL
|
||||
URI toURL = new URI(privatePortletURL);
|
||||
String publicURL = privatePortletURL.startsWith("https://")?"https://"+toURL.getHost():"http://"+toURL.getHost();
|
||||
//It returns the string "catalogue"
|
||||
String publicURL = privatePortletURL.startsWith("https://") ? "https://" + toURL.getHost()
|
||||
: "http://" + toURL.getHost();
|
||||
// It returns the string "catalogue"
|
||||
CatalogueStaticConfigurations staticConf = new CatalogueStaticConfigurations();
|
||||
//Replacing for example "ckan-bb" with "[PREFIXES-TO-CATALOGUE-URL]-bb" (e.g catalogue-bb)
|
||||
String relativeURLWithCatalogueName = staticConf.buildRelativeURLToPublicCatalogueGateway(vreDetached.getCatalogUrl());
|
||||
// Replacing for example "ckan-bb" with "[PREFIXES-TO-CATALOGUE-URL]-bb" (e.g
|
||||
// catalogue-bb)
|
||||
String relativeURLWithCatalogueName = staticConf
|
||||
.buildRelativeURLToPublicCatalogueGateway(vreDetached.getCatalogUrl());
|
||||
String toGatewayPortletURL = String.format("%s/%s", publicURL, relativeURLWithCatalogueName);
|
||||
mapAccessURLToCatalogue.put(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_GATEWAY,toGatewayPortletURL);
|
||||
|
||||
ckanCatalogueReference = new GatewayCKANCatalogueReference(fullScope, vreDetached.getCatalogUrl(), mapAccessURLToCatalogue);
|
||||
mapAccessURLToCatalogue.put(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_GATEWAY, toGatewayPortletURL);
|
||||
|
||||
ckanCatalogueReference = new GatewayCKANCatalogueReference(fullScope, vreDetached.getCatalogUrl(),
|
||||
mapAccessURLToCatalogue);
|
||||
break;
|
||||
case ACTIVE:
|
||||
default:
|
||||
|
||||
ckanCatalogueReference = CkanCatalogueConfigurationsReader.loadCatalogueEndPoints();
|
||||
|
||||
ckanCatalogueReference = CkanCatalogueConfigurationsReader.loadCatalogueEndPoints();
|
||||
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;
|
||||
boolean isPublicItem = false;
|
||||
if(ckanCatalogueReference.getCkanURL()!=null){
|
||||
try{
|
||||
CkanDataset dataset = CkanCatalogueConfigurationsReader.getDataset(datasetName, ckanCatalogueReference.getCkanURL());
|
||||
if(dataset!=null){
|
||||
if (ckanCatalogueReference.getCkanURL() != null) {
|
||||
try {
|
||||
CkanDataset dataset = CkanCatalogueConfigurationsReader.getDataset(datasetName,
|
||||
ckanCatalogueReference.getCkanURL());
|
||||
if (dataset != null) {
|
||||
isPublicItem = true;
|
||||
//ckanPorltetUrl = ckanCatalogueReference.getPublicPortletURL();
|
||||
logger.info("The dataset "+datasetName+" is a public item");
|
||||
// ckanPorltetUrl = ckanCatalogueReference.getPublicPortletURL();
|
||||
logger.info("The dataset " + datasetName + " is a public item");
|
||||
}
|
||||
}catch(Exception e){
|
||||
logger.warn("Error on checking if dataset: "+datasetName+" is private or not", e);
|
||||
} catch (Exception e) {
|
||||
logger.warn("Error on checking if dataset: " + datasetName + " is private or not", e);
|
||||
isPublicItem = true;
|
||||
}
|
||||
}
|
||||
|
||||
String publicGatewayPorltetURL = String.format("%s?path=/%s/%s",
|
||||
ckanCatalogueReference.getCatalogueURL(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_GATEWAY),
|
||||
entityContextValue,
|
||||
entityName);
|
||||
|
||||
entityContextValue, entityName);
|
||||
|
||||
String privateVREPortletURL = String.format("%s?path=/%s/%s",
|
||||
ckanCatalogueReference.getCatalogueURL(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PRIVATE_VRE),
|
||||
entityContextValue,
|
||||
entityName);
|
||||
|
||||
//Checking if the public VRE portlet URL is available (so it was read from GR)
|
||||
entityContextValue, entityName);
|
||||
|
||||
// Checking if the public VRE portlet URL is available (so it was read from GR)
|
||||
String publicVREPortletURL = null;
|
||||
String toCheckPublicVREPortletURL = ckanCatalogueReference.getCatalogueURL(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_VRE);
|
||||
if(toCheckPublicVREPortletURL!=null && !toCheckPublicVREPortletURL.isEmpty()) {
|
||||
//here the catalogue is available/deployed as public at VRE level
|
||||
publicVREPortletURL = String.format("%s?path=/%s/%s",
|
||||
toCheckPublicVREPortletURL,
|
||||
entityContextValue,
|
||||
String toCheckPublicVREPortletURL = ckanCatalogueReference
|
||||
.getCatalogueURL(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_VRE);
|
||||
if (toCheckPublicVREPortletURL != null && !toCheckPublicVREPortletURL.isEmpty()) {
|
||||
// here the catalogue is available/deployed as public at VRE level
|
||||
publicVREPortletURL = String.format("%s?path=/%s/%s", toCheckPublicVREPortletURL, entityContextValue,
|
||||
entityName);
|
||||
}
|
||||
return new ItemCatalogueURLs(entityName, isPublicItem, privateVREPortletURL, publicVREPortletURL, publicGatewayPorltetURL);
|
||||
}catch (Exception e) {
|
||||
return new ItemCatalogueURLs(entityName, isPublicItem, privateVREPortletURL, publicVREPortletURL,
|
||||
publicGatewayPorltetURL);
|
||||
} catch (Exception e) {
|
||||
logger.error("Error when resolving CatalogueURL:", e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.datatransfer.resolver.services;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Context;
|
||||
|
||||
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Class DocsGenerator.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Apr 1, 2022
|
||||
*/
|
||||
@Path("docs")
|
||||
public class DocsGenerator {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(DocsGenerator.class);
|
||||
|
||||
/**
|
||||
* To doc.
|
||||
*
|
||||
* @param req the req
|
||||
* @return the input stream
|
||||
* @throws WebApplicationException the web application exception
|
||||
*/
|
||||
@GET
|
||||
@Path("/{any: .*}")
|
||||
public InputStream toDoc(@Context HttpServletRequest req) throws WebApplicationException {
|
||||
logger.info(DocsGenerator.class.getSimpleName() + " toDoc called");
|
||||
|
||||
String pathInfo = req.getPathInfo();
|
||||
logger.debug("pathInfo {}", pathInfo);
|
||||
try {
|
||||
|
||||
if (pathInfo.endsWith("/docs/")) {
|
||||
pathInfo += "index.html";
|
||||
}
|
||||
|
||||
logger.info("going to {}", pathInfo);
|
||||
|
||||
String realPath = req.getServletContext().getRealPath(pathInfo);
|
||||
return new FileInputStream(new File(realPath));
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
if (!(e instanceof WebApplicationException)) {
|
||||
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = pathInfo + " 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -48,10 +48,14 @@ import org.slf4j.LoggerFactory;
|
|||
import org.w3c.dom.Document;
|
||||
|
||||
/**
|
||||
* The Class GeonetworkResolver.
|
||||
* The GeonetworkResolver is a "middle tier" to perform queries
|
||||
* to D4Science's Geonetwork services.
|
||||
*
|
||||
* See more at
|
||||
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Geonetwork_Resolver
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Oct 23, 2018
|
||||
* Oct 23, 2018
|
||||
*/
|
||||
@Path("geonetwork")
|
||||
public class GeonetworkResolver {
|
||||
|
@ -60,7 +64,8 @@ public class GeonetworkResolver {
|
|||
*
|
||||
*/
|
||||
public static final String REPLACED_A_PUBLIC_UUID_PLEASE_IGNORE = "Replaced a public UUID, please ignore";
|
||||
public static final String REPLACED_UUID_BY_FILTER_PLEASE_IGNORE = "Replaced UUID by "+GeonetworkResolver.class.getSimpleName()+" filters, please ignore";
|
||||
public static final String REPLACED_UUID_BY_FILTER_PLEASE_IGNORE = "Replaced UUID by "
|
||||
+ GeonetworkResolver.class.getSimpleName() + " filters, please ignore";
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(GeonetworkResolver.class);
|
||||
|
||||
|
@ -78,180 +83,199 @@ public class GeonetworkResolver {
|
|||
public static final String QUERY_PARAM_RESET_CACHE_PARAM = "resetcache";
|
||||
public static final String QUERY_PARAM_RESET_CACHED_SCOPE_PARAM = "resetcachedscope";
|
||||
|
||||
public static final String SRV_EN_MEF_EXPORT = "/srv/en/mef.export"; //MEF Geonetwork service
|
||||
public static final String SRV_EN_MEF_EXPORT = "/srv/en/mef.export"; // MEF Geonetwork service
|
||||
|
||||
public static final String UUID = "uuid";
|
||||
|
||||
public static final String SCOPE_SEPARATOR = "|";
|
||||
|
||||
//protected Map<String, GeonetworkInstance> cacheGNInstances;
|
||||
// protected Map<String, GeonetworkInstance> cacheGNInstances;
|
||||
|
||||
private String helpURI = "https://wiki.gcube-system.org/gcube/GCube_Resource_Catalogue#Geonetwork_Resolver";
|
||||
|
||||
/**
|
||||
* Gets the geonetwork request criteria.
|
||||
* Creates a request criteria from input parameter pathWithoutGN
|
||||
* The parameter pathWithoutGN should be an ordered string (like REST request):
|
||||
* SCOPE/MODE/VISIBILITY/OWNER/$$
|
||||
* SCOPE must be: ROOT|VO|VRE
|
||||
* MODE must be: {@link MODE}
|
||||
* Gets the geonetwork request criteria. Creates a request criteria from input
|
||||
* parameter pathWithoutGN. The parameter pathWithoutGN should be an ordered
|
||||
* string (like REST request): SCOPE/MODE/VISIBILITY/OWNER/$$
|
||||
*
|
||||
* SCOPE must be: ROOT|VO|VRE
|
||||
* MODE must be: {@link MODE}
|
||||
* VISIBILITY must be: {@link VISIBILITY}
|
||||
* OWNER (is optional): filter by owner
|
||||
*
|
||||
* @param req the req
|
||||
* @param scope the scope
|
||||
* @param mode the mode
|
||||
* @param visibility the visibility
|
||||
* @param filterKey the filter key
|
||||
* @param req the req
|
||||
* @param scope the scope
|
||||
* @param mode the mode
|
||||
* @param visibility the visibility
|
||||
* @param filterKey the filter key
|
||||
* @param filterValue the filter value
|
||||
* @param remainPath the remain path
|
||||
* @param resetCache the reset cache
|
||||
* @param resetScope the reset scope
|
||||
* @param remainPath the remain path
|
||||
* @param resetCache the reset cache
|
||||
* @param resetScope the reset scope
|
||||
* @return the geonetwork request criteria
|
||||
* @throws WebApplicationException the web application exception
|
||||
*/
|
||||
|
||||
@GET
|
||||
@Path("/{"+PATH_PARAM_SCOPE+"}/{"+PATH_PARAM_MODE+"}/{"+PATH_PARAM_VISIBILITY+"}/{filterKey}/{filterValue}/$${"+PATH_PARAM_REMAINPATH+":(/[^?$]+)?}")
|
||||
public Response submitGet(@Context HttpServletRequest req,
|
||||
@PathParam(PATH_PARAM_SCOPE) @Nullable String scope,
|
||||
@PathParam(PATH_PARAM_MODE) @Nullable String mode,
|
||||
@PathParam(PATH_PARAM_VISIBILITY) @Nullable String visibility,
|
||||
@PathParam("filterKey") @Nullable String filterKey,
|
||||
@PathParam("filterValue") @Nullable String filterValue,
|
||||
@PathParam(PATH_PARAM_REMAINPATH) @Nullable String remainPath,
|
||||
@QueryParam(QUERY_PARAM_RESET_CACHE_PARAM) @Nullable String resetCache,
|
||||
@QueryParam(QUERY_PARAM_RESET_CACHED_SCOPE_PARAM) @Nullable String resetScope) throws WebApplicationException{
|
||||
@Path("/{" + PATH_PARAM_SCOPE + "}/{" + PATH_PARAM_MODE + "}/{" + PATH_PARAM_VISIBILITY
|
||||
+ "}/{filterKey}/{filterValue}/$${" + PATH_PARAM_REMAINPATH + ":(/[^?$]+)?}")
|
||||
public Response submitGet(@Context HttpServletRequest req, @PathParam(PATH_PARAM_SCOPE) @Nullable String scope,
|
||||
@PathParam(PATH_PARAM_MODE) @Nullable String mode,
|
||||
@PathParam(PATH_PARAM_VISIBILITY) @Nullable String visibility,
|
||||
@PathParam("filterKey") @Nullable String filterKey, @PathParam("filterValue") @Nullable String filterValue,
|
||||
@PathParam(PATH_PARAM_REMAINPATH) @Nullable String remainPath,
|
||||
@QueryParam(QUERY_PARAM_RESET_CACHE_PARAM) @Nullable String resetCache,
|
||||
@QueryParam(QUERY_PARAM_RESET_CACHED_SCOPE_PARAM) @Nullable String resetScope)
|
||||
throws WebApplicationException {
|
||||
|
||||
logger.info(this.getClass().getSimpleName()+" GET starts...");
|
||||
logger.info(this.getClass().getSimpleName() + " GET starts...");
|
||||
String gnGetlURL = null;
|
||||
|
||||
try {
|
||||
logger.info("Params are [mode: "+mode+", scope: "+scope+", visibility: "+visibility+", filterKey: "+filterKey+", filterValue: "+filterValue+", remainPath: "+remainPath+"]");
|
||||
logger.info(
|
||||
"Params are [mode: " + mode + ", scope: " + scope + ", visibility: " + visibility + ", filterKey: "
|
||||
+ filterKey + ", filterValue: " + filterValue + ", remainPath: " + remainPath + "]");
|
||||
|
||||
if(scope==null || scope.isEmpty()){
|
||||
if (scope == null || scope.isEmpty()) {
|
||||
logger.error("Path Parameter 'scope' not found");
|
||||
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'scope'", this.getClass(), helpURI);
|
||||
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'scope'",
|
||||
this.getClass(), helpURI);
|
||||
}
|
||||
|
||||
if(mode==null || mode.isEmpty()){
|
||||
if (mode == null || mode.isEmpty()) {
|
||||
logger.error("Path Parameter 'scope' not found");
|
||||
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'mode'", this.getClass(), helpURI);
|
||||
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'mode'",
|
||||
this.getClass(), helpURI);
|
||||
}
|
||||
|
||||
scope = ScopeUtil.normalizeScope(scope, "|");
|
||||
mode = mode.toUpperCase();
|
||||
try{
|
||||
try {
|
||||
MODE.valueOf(mode);
|
||||
}catch(Exception e){
|
||||
} catch (Exception e) {
|
||||
List<MODE> toPrint = Arrays.asList(MODE.values());
|
||||
logger.error("The 'mode' parameter is wrong, Have you pass a valid parameter MODE like "+toPrint+"?");
|
||||
throw ExceptionManager.wrongParameterException(req, "The 'mode' parameter must be value of "+toPrint, this.getClass(), helpURI);
|
||||
logger.error(
|
||||
"The 'mode' parameter is wrong, Have you pass a valid parameter MODE like " + toPrint + "?");
|
||||
throw ExceptionManager.wrongParameterException(req, "The 'mode' parameter must be value of " + toPrint,
|
||||
this.getClass(), helpURI);
|
||||
}
|
||||
|
||||
if(visibility==null){
|
||||
if (visibility == null) {
|
||||
logger.error("Path Parameter 'visibility' not found");
|
||||
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'visibility'", this.getClass(), helpURI);
|
||||
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'visibility'",
|
||||
this.getClass(), helpURI);
|
||||
}
|
||||
|
||||
visibility = visibility.toUpperCase();
|
||||
try{
|
||||
try {
|
||||
VISIBILITY.valueOf(visibility);
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
List<VISIBILITY> toPrint = Arrays.asList(VISIBILITY.values());
|
||||
logger.error("The 'visibility' parameter is wrong, Have you pass a valid parameter VISIBILITY like "+toPrint+"?");
|
||||
throw ExceptionManager.wrongParameterException(req, "The 'visibility' parameter must be value of "+toPrint, this.getClass(), helpURI);
|
||||
logger.error("The 'visibility' parameter is wrong, Have you pass a valid parameter VISIBILITY like "
|
||||
+ toPrint + "?");
|
||||
throw ExceptionManager.wrongParameterException(req,
|
||||
"The 'visibility' parameter must be value of " + toPrint, this.getClass(), helpURI);
|
||||
}
|
||||
|
||||
logger.info("Remaining path is: "+remainPath);
|
||||
|
||||
|
||||
logger.info("Remaining path is: " + remainPath);
|
||||
|
||||
try {
|
||||
|
||||
//I'M LOADING GN CONFIGURATIONS (ENDPOINT, USER, PWD AND SO ON..) FOR PASSED SCOPE FROM GN LIBRARY BY A GENERAL METHOD WITHOUT TO PERFORM AUTHENTICATION ON GN,
|
||||
//AFTER THAT I'M USING THEM TO PERFORM AUTHENTICATION ON GN VIA HTTP_CLIENTS IF NEEDED
|
||||
|
||||
// I'M LOADING GN CONFIGURATIONS (ENDPOINT, USER, PWD AND SO ON..) FOR PASSED
|
||||
// SCOPE FROM GN LIBRARY BY A GENERAL METHOD WITHOUT TO PERFORM AUTHENTICATION
|
||||
// ON GN,
|
||||
// AFTER THAT I'M USING THEM TO PERFORM AUTHENTICATION ON GN VIA HTTP_CLIENTS IF
|
||||
// NEEDED
|
||||
GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scope);
|
||||
logger.info("set scope provider "+scope);
|
||||
logger.info("set scope provider " + scope);
|
||||
ScopeProvider.instance.set(scope);
|
||||
Account account = gnInstance.getAccount();
|
||||
Version version = gnInstance.getVersion();
|
||||
String geonetworkUrl = gnInstance.getEndPoint();
|
||||
Configuration config = gnInstance.getConfig()!=null?gnInstance.getConfig():null;
|
||||
|
||||
if(account==null || account.getUser()==null || account.getPassword()==null || config==null) {
|
||||
Configuration config = gnInstance.getConfig() != null ? gnInstance.getConfig() : null;
|
||||
|
||||
if (account == null || account.getUser() == null || account.getPassword() == null || config == null) {
|
||||
logger.info("Loading GN instance and configurations via Geonetwork Library...");
|
||||
config = gnInstance.getGeonetworkPublisher().getConfiguration();
|
||||
account = config.getScopeConfiguration().getAccounts().get(Type.CKAN);
|
||||
version = config.getGeoNetworkVersion();
|
||||
geonetworkUrl = config.getGeoNetworkEndpoint();
|
||||
}
|
||||
|
||||
logger.info("SCOPE: {}, CKAN user used is: {}, GN EndPoint: {}",scope, account.getUser(), geonetworkUrl);
|
||||
|
||||
|
||||
logger.info("SCOPE: {}, CKAN user used is: {}, GN EndPoint: {}", scope, account.getUser(),
|
||||
geonetworkUrl);
|
||||
|
||||
HTTPCallsUtils httpUtils = new HTTPCallsUtils();
|
||||
|
||||
if(visibility.equals(VISIBILITY.PRV.name())){
|
||||
if(account.getUser()!=null){
|
||||
|
||||
if (visibility.equals(VISIBILITY.PRV.name())) {
|
||||
if (account.getUser() != null) {
|
||||
switch (version) {
|
||||
case DUE:
|
||||
boolean authorized = GNAuthentication.login(httpUtils, geonetworkUrl, account.getUser(), account.getPassword());
|
||||
logger.info("Authorized on GN2 "+geonetworkUrl +" ? "+authorized);
|
||||
boolean authorized = GNAuthentication.login(httpUtils, geonetworkUrl, account.getUser(),
|
||||
account.getPassword());
|
||||
logger.info("Authorized on GN2 " + geonetworkUrl + " ? " + authorized);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
httpUtils = new HTTPCallsUtils(account.getUser(), account.getPassword());
|
||||
logger.info("Authorized on GN3 via HTTCallsUtils...");
|
||||
break;
|
||||
}
|
||||
|
||||
}else {
|
||||
logger.warn("I'm not able to perform authentication, the user read from config with "+Type.CKAN+" is null");
|
||||
|
||||
} else {
|
||||
logger.warn("I'm not able to perform authentication, the user read from config with "
|
||||
+ Type.CKAN + " is null");
|
||||
}
|
||||
}
|
||||
|
||||
String baseURL = remainPath==null ||remainPath.isEmpty()?geonetworkUrl+"/"+CSW_SERVER:geonetworkUrl+"/"+CSW_SERVER+remainPath;
|
||||
logger.info("The base URL is: "+baseURL);
|
||||
String queryString = req.getQueryString()==null || req.getQueryString().isEmpty()?"":"?"+req.getQueryString();
|
||||
gnGetlURL = baseURL+queryString;
|
||||
logger.info("Sending get request to URL: "+gnGetlURL);
|
||||
String baseURL = remainPath == null || remainPath.isEmpty() ? geonetworkUrl + "/" + CSW_SERVER
|
||||
: geonetworkUrl + "/" + CSW_SERVER + remainPath;
|
||||
logger.info("The base URL is: " + baseURL);
|
||||
String queryString = req.getQueryString() == null || req.getQueryString().isEmpty() ? ""
|
||||
: "?" + req.getQueryString();
|
||||
gnGetlURL = baseURL + queryString;
|
||||
logger.info("Sending get request to URL: " + gnGetlURL);
|
||||
HttpResponse proxedGNResponse = httpUtils.get(gnGetlURL);
|
||||
|
||||
switch(proxedGNResponse.getStatus()){
|
||||
switch (proxedGNResponse.getStatus()) {
|
||||
case HttpServletResponse.SC_OK:
|
||||
|
||||
//Building the response
|
||||
// Building the response
|
||||
InputStream streamToWrite = IOUtils.toInputStream(proxedGNResponse.getResponse());
|
||||
StreamingOutput so = new SingleFileStreamingOutput(streamToWrite);
|
||||
|
||||
logger.info("Response return Content-Type: "+httpUtils.getLastContentType());
|
||||
logger.info("Response return Content-Type: " + httpUtils.getLastContentType());
|
||||
|
||||
ResponseBuilder responseBuilder = Response
|
||||
.ok(so)
|
||||
.header(ConstantsResolver.CONTENT_TYPE, httpUtils.getLastContentType());
|
||||
ResponseBuilder responseBuilder = Response.ok(so).header(ConstantsResolver.CONTENT_TYPE,
|
||||
httpUtils.getLastContentType());
|
||||
return responseBuilder.build();
|
||||
|
||||
case HttpServletResponse.SC_FORBIDDEN:
|
||||
throw ExceptionManager.forbiddenException(req, "You are not authorized to perform the request "+gnGetlURL, this.getClass(), helpURI);
|
||||
throw ExceptionManager.forbiddenException(req,
|
||||
"You are not authorized to perform the request " + gnGetlURL, this.getClass(), helpURI);
|
||||
|
||||
default:
|
||||
throw ExceptionManager.internalErrorException(req, "Sorry, an error occurred performing the geonetwork request "+gnGetlURL+" with scope "+scope, this.getClass(), helpURI);
|
||||
throw ExceptionManager.internalErrorException(req,
|
||||
"Sorry, an error occurred performing the geonetwork request " + gnGetlURL + " with scope "
|
||||
+ scope,
|
||||
this.getClass(), helpURI);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Exception:", e);
|
||||
String error = "Sorry, an error occurred on resolving geonetwork request with scope "+scope+". Please, contact support!";
|
||||
String error = "Sorry, an error occurred on resolving geonetwork request with scope " + scope
|
||||
+ ". Please, contact support!";
|
||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
}catch (Exception e) {
|
||||
|
||||
if(!(e instanceof WebApplicationException)){
|
||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error during perform GET operation to: "+gnGetlURL+". Please, contact the support!";
|
||||
if (!(e instanceof WebApplicationException)) {
|
||||
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error during perform GET operation to: " + gnGetlURL + ". Please, contact the support!";
|
||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||
}
|
||||
//ALREADY MANAGED AS WebApplicationException
|
||||
// ALREADY MANAGED AS WebApplicationException
|
||||
logger.error("Exception:", e);
|
||||
throw (WebApplicationException) e;
|
||||
}
|
||||
|
@ -259,159 +283,174 @@ public class GeonetworkResolver {
|
|||
}
|
||||
|
||||
/**
|
||||
* Submit post.
|
||||
* The post request
|
||||
*
|
||||
* @param req the req
|
||||
* @param scope the scope
|
||||
* @param mode the mode
|
||||
* @param visibility the visibility
|
||||
* @param filterKey the filter key
|
||||
* @param req the req
|
||||
* @param scope the scope
|
||||
* @param mode the mode
|
||||
* @param visibility the visibility
|
||||
* @param filterKey the filter key
|
||||
* @param filterValue the filter value
|
||||
* @param remainPath the remain path
|
||||
* @param resetCache the reset cache
|
||||
* @param resetScope the reset scope
|
||||
* @param remainPath the remain path
|
||||
* @param resetCache the reset cache
|
||||
* @param resetScope the reset scope
|
||||
* @return the response
|
||||
* @throws WebApplicationException the web application exception
|
||||
*/
|
||||
@POST
|
||||
@Path("/{"+PATH_PARAM_SCOPE+"}/{"+PATH_PARAM_MODE+"}/{"+PATH_PARAM_VISIBILITY+"}/{filterKey}/{filterValue}/$${"+PATH_PARAM_REMAINPATH+":(/[^?$]+)?}")
|
||||
public Response submitPost(@Context HttpServletRequest req,
|
||||
@PathParam(PATH_PARAM_SCOPE) @Nullable String scope,
|
||||
@PathParam(PATH_PARAM_MODE) @Nullable String mode,
|
||||
@PathParam(PATH_PARAM_VISIBILITY) @Nullable String visibility,
|
||||
@PathParam("filterKey") @Nullable String filterKey,
|
||||
@PathParam("filterValue") @Nullable String filterValue,
|
||||
@PathParam(PATH_PARAM_REMAINPATH) @Nullable String remainPath,
|
||||
@QueryParam(QUERY_PARAM_RESET_CACHE_PARAM) @Nullable String resetCache,
|
||||
@QueryParam(QUERY_PARAM_RESET_CACHED_SCOPE_PARAM) @Nullable String resetScope) throws WebApplicationException{
|
||||
@Path("/{" + PATH_PARAM_SCOPE + "}/{" + PATH_PARAM_MODE + "}/{" + PATH_PARAM_VISIBILITY
|
||||
+ "}/{filterKey}/{filterValue}/$${" + PATH_PARAM_REMAINPATH + ":(/[^?$]+)?}")
|
||||
public Response submitPost(@Context HttpServletRequest req, @PathParam(PATH_PARAM_SCOPE) @Nullable String scope,
|
||||
@PathParam(PATH_PARAM_MODE) @Nullable String mode,
|
||||
@PathParam(PATH_PARAM_VISIBILITY) @Nullable String visibility,
|
||||
@PathParam("filterKey") @Nullable String filterKey, @PathParam("filterValue") @Nullable String filterValue,
|
||||
@PathParam(PATH_PARAM_REMAINPATH) @Nullable String remainPath,
|
||||
@QueryParam(QUERY_PARAM_RESET_CACHE_PARAM) @Nullable String resetCache,
|
||||
@QueryParam(QUERY_PARAM_RESET_CACHED_SCOPE_PARAM) @Nullable String resetScope)
|
||||
throws WebApplicationException {
|
||||
|
||||
logger.info(this.getClass().getSimpleName()+" POST starts...");
|
||||
logger.info(this.getClass().getSimpleName() + " POST starts...");
|
||||
String gnCSWlURL = null;
|
||||
|
||||
try{
|
||||
logger.info("Params are [mode: "+mode+", scope: "+scope+", visibility: "+visibility+", filterKey: "+filterKey+", filterValue: "+filterValue+", remainPath: "+remainPath+"]");
|
||||
try {
|
||||
logger.info(
|
||||
"Params are [mode: " + mode + ", scope: " + scope + ", visibility: " + visibility + ", filterKey: "
|
||||
+ filterKey + ", filterValue: " + filterValue + ", remainPath: " + remainPath + "]");
|
||||
|
||||
if(scope==null || scope.isEmpty()){
|
||||
if (scope == null || scope.isEmpty()) {
|
||||
logger.error("Path Parameter 'scope' not found");
|
||||
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'scope'", this.getClass(), helpURI);
|
||||
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'scope'",
|
||||
this.getClass(), helpURI);
|
||||
}
|
||||
|
||||
if(mode==null || mode.isEmpty()){
|
||||
if (mode == null || mode.isEmpty()) {
|
||||
logger.error("Path Parameter 'scope' not found");
|
||||
ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'mode'", this.getClass(), helpURI);
|
||||
ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'mode'", this.getClass(),
|
||||
helpURI);
|
||||
}
|
||||
|
||||
scope = ScopeUtil.normalizeScope(scope, "|");
|
||||
mode = mode.toUpperCase();
|
||||
try{
|
||||
try {
|
||||
MODE.valueOf(mode);
|
||||
}catch(Exception e){
|
||||
} catch (Exception e) {
|
||||
List<MODE> toPrint = Arrays.asList(MODE.values());
|
||||
logger.error("The 'mode' parameter is wrong, Have you pass a valid parameter MODE like "+toPrint+"?");
|
||||
throw ExceptionManager.wrongParameterException(req, "The 'mode' parameter must be value of "+toPrint, this.getClass(), helpURI);
|
||||
logger.error(
|
||||
"The 'mode' parameter is wrong, Have you pass a valid parameter MODE like " + toPrint + "?");
|
||||
throw ExceptionManager.wrongParameterException(req, "The 'mode' parameter must be value of " + toPrint,
|
||||
this.getClass(), helpURI);
|
||||
}
|
||||
|
||||
if(visibility==null){
|
||||
if (visibility == null) {
|
||||
logger.error("Path Parameter 'visibility' not found");
|
||||
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'visibility'", this.getClass(), helpURI);
|
||||
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'visibility'",
|
||||
this.getClass(), helpURI);
|
||||
}
|
||||
|
||||
visibility = visibility.toUpperCase();
|
||||
try{
|
||||
try {
|
||||
VISIBILITY.valueOf(visibility);
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
List<VISIBILITY> toPrint = Arrays.asList(VISIBILITY.values());
|
||||
logger.error("The 'visibility' parameter is wrong, Have you pass a valid parameter VISIBILITY like "+toPrint+"?");
|
||||
throw ExceptionManager.wrongParameterException(req, "The 'visibility' parameter must be value of "+toPrint, this.getClass(), helpURI);
|
||||
logger.error("The 'visibility' parameter is wrong, Have you pass a valid parameter VISIBILITY like "
|
||||
+ toPrint + "?");
|
||||
throw ExceptionManager.wrongParameterException(req,
|
||||
"The 'visibility' parameter must be value of " + toPrint, this.getClass(), helpURI);
|
||||
}
|
||||
|
||||
//HOW TO PASS ANY FILTER?
|
||||
//TODO INVESTIGATE ON HOW TO PASS MORE THAN ONE FILTER...
|
||||
Map<String,String> filters = new HashMap<String, String>();
|
||||
if(filterKey!=null && filterValue!=null){
|
||||
//IGNORING THE EMPTY FILTER 'null|null'
|
||||
if(filterKey.compareToIgnoreCase("null")!=0){
|
||||
// HOW TO PASS ANY FILTER?
|
||||
// TODO INVESTIGATE ON HOW TO PASS MORE THAN ONE FILTER...
|
||||
Map<String, String> filters = new HashMap<String, String>();
|
||||
if (filterKey != null && filterValue != null) {
|
||||
// IGNORING THE EMPTY FILTER 'null|null'
|
||||
if (filterKey.compareToIgnoreCase("null") != 0) {
|
||||
filters.put(filterKey, filterValue);
|
||||
logger.debug("Added filter parmas to map filters: "+filters);
|
||||
logger.debug("Added filter parmas to map filters: " + filters);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
|
||||
//I'M LOADING GN CONFIGURATIONS (ENDPOINT, USER, PWD AND SO ON..) FOR PASSED SCOPE FROM GN LIBRARY BY A GENERAL METHOD WITHOUT TO PERFORM AUTHENTICATION ON GN,
|
||||
//AFTER THAT I'M USING THEM TO PERFORM AUTHENTICATION ON GN VIA HTTP_CLIENTS IF NEEDED
|
||||
// I'M LOADING GN CONFIGURATIONS (ENDPOINT, USER, PWD AND SO ON..) FOR PASSED
|
||||
// SCOPE FROM GN LIBRARY BY A GENERAL METHOD WITHOUT TO PERFORM AUTHENTICATION
|
||||
// ON GN,
|
||||
// AFTER THAT I'M USING THEM TO PERFORM AUTHENTICATION ON GN VIA HTTP_CLIENTS IF
|
||||
// NEEDED
|
||||
GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scope);
|
||||
logger.info("set scope provider "+scope);
|
||||
logger.info("set scope provider " + scope);
|
||||
ScopeProvider.instance.set(scope);
|
||||
Account account = gnInstance.getAccount();
|
||||
Version version = gnInstance.getVersion();
|
||||
String geonetworkUrl = gnInstance.getEndPoint();
|
||||
Configuration config = gnInstance.getConfig()!=null?gnInstance.getConfig():null;
|
||||
|
||||
if(account==null || account.getUser()==null || account.getPassword()==null || config==null) {
|
||||
Configuration config = gnInstance.getConfig() != null ? gnInstance.getConfig() : null;
|
||||
|
||||
if (account == null || account.getUser() == null || account.getPassword() == null || config == null) {
|
||||
logger.info("Loading GN instance and configurations via Geonetwork Library...");
|
||||
config = gnInstance.getGeonetworkPublisher().getConfiguration();
|
||||
account = config.getScopeConfiguration().getAccounts().get(Type.CKAN);
|
||||
version = config.getGeoNetworkVersion();
|
||||
geonetworkUrl = config.getGeoNetworkEndpoint();
|
||||
}
|
||||
logger.info("SCOPE: {}, CKAN user used is: {}, GN EndPoint: {}",scope, account.getUser(), geonetworkUrl);
|
||||
logger.info("SCOPE: {}, CKAN user used is: {}, GN EndPoint: {}", scope, account.getUser(),
|
||||
geonetworkUrl);
|
||||
|
||||
// logger.info("Parameters..");
|
||||
// for (Enumeration<String> e = req.getParameterNames(); e.hasMoreElements();){
|
||||
// String p = e.nextElement();
|
||||
// logger.debug("param "+p + " value "+Arrays.toString(req.getParameterValues(p)));
|
||||
// }
|
||||
// logger.info("Parameters..");
|
||||
// for (Enumeration<String> e = req.getParameterNames(); e.hasMoreElements();){
|
||||
// String p = e.nextElement();
|
||||
// logger.debug("param "+p + " value
|
||||
// "+Arrays.toString(req.getParameterValues(p)));
|
||||
// }
|
||||
|
||||
//DEBUG BODY
|
||||
// String readBody = IOUtils.toString(req.getReader());
|
||||
// logger.debug("doPost read body request: "+readBody);
|
||||
// DEBUG BODY
|
||||
// String readBody = IOUtils.toString(req.getReader());
|
||||
// logger.debug("doPost read body request: "+readBody);
|
||||
ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
|
||||
|
||||
|
||||
// SPECIFIC HANDLER FOR GEONETWORK REQUEST: /srv/en/mef.export
|
||||
if(remainPath!=null && remainPath.compareTo(SRV_EN_MEF_EXPORT)==0){
|
||||
if (remainPath != null && remainPath.compareTo(SRV_EN_MEF_EXPORT) == 0) {
|
||||
logger.info("In case of mef.export, perfoming a custom handler");
|
||||
gnCSWlURL = geonetworkUrl + SRV_EN_MEF_EXPORT;
|
||||
String[] uuidValues = req.getParameterValues(UUID);
|
||||
if(uuidValues!=null){
|
||||
if (uuidValues != null) {
|
||||
String data = null;
|
||||
for (String uuid : uuidValues) {
|
||||
data = UUID+"="+uuid;
|
||||
data = UUID + "=" + uuid;
|
||||
}
|
||||
if(data!=null){
|
||||
logger.debug("Writing "+data +" into byte array");
|
||||
if (data != null) {
|
||||
logger.debug("Writing " + data + " into byte array");
|
||||
byteArray.write(data.getBytes());
|
||||
}else
|
||||
} else
|
||||
IOUtils.copy(req.getInputStream(), byteArray);
|
||||
}else
|
||||
} else
|
||||
IOUtils.copy(req.getInputStream(), byteArray);
|
||||
}else{
|
||||
logger.debug("IS NOT A REQUEST TO "+SRV_EN_MEF_EXPORT);
|
||||
gnCSWlURL = remainPath==null || remainPath.isEmpty()?geonetworkUrl+"/"+CSW_SERVER:geonetworkUrl+"/"+CSW_SERVER+remainPath;
|
||||
} else {
|
||||
logger.debug("IS NOT A REQUEST TO " + SRV_EN_MEF_EXPORT);
|
||||
gnCSWlURL = remainPath == null || remainPath.isEmpty() ? geonetworkUrl + "/" + CSW_SERVER
|
||||
: geonetworkUrl + "/" + CSW_SERVER + remainPath;
|
||||
IOUtils.copy(req.getInputStream(), byteArray);
|
||||
}
|
||||
|
||||
HTTPCallsUtils httpUtils = new HTTPCallsUtils();
|
||||
|
||||
//PRIVATE LAYERS
|
||||
if(visibility.equals(VISIBILITY.PRV.name())){
|
||||
logger.info("Visibility: "+VISIBILITY.PRV+" getting private layers..");
|
||||
//VRE LAYERS
|
||||
if(mode.equals(MODE.VRE.name())){
|
||||
logger.info("Getting "+MODE.VRE+" layers..");
|
||||
//HARVESTED LAYERS
|
||||
}else{
|
||||
// PRIVATE LAYERS
|
||||
if (visibility.equals(VISIBILITY.PRV.name())) {
|
||||
logger.info("Visibility: " + VISIBILITY.PRV + " getting private layers..");
|
||||
// VRE LAYERS
|
||||
if (mode.equals(MODE.VRE.name())) {
|
||||
logger.info("Getting " + MODE.VRE + " layers..");
|
||||
// HARVESTED LAYERS
|
||||
} else {
|
||||
filters.put("isHarvested", "y");
|
||||
logger.info("Getting "+MODE.HARVEST+" layers, I added 'isHarvested = y' to the filters ["+filters+"]");
|
||||
logger.info("Getting " + MODE.HARVEST + " layers, I added 'isHarvested = y' to the filters ["
|
||||
+ filters + "]");
|
||||
}
|
||||
|
||||
if(account.getUser()!=null){
|
||||
if (account.getUser() != null) {
|
||||
switch (version) {
|
||||
case DUE:
|
||||
boolean authorized = GNAuthentication.login(httpUtils, geonetworkUrl, account.getUser(), account.getPassword());
|
||||
logger.info("Authorized on GN2 "+geonetworkUrl +" ? "+authorized);
|
||||
boolean authorized = GNAuthentication.login(httpUtils, geonetworkUrl, account.getUser(),
|
||||
account.getPassword());
|
||||
logger.info("Authorized on GN2 " + geonetworkUrl + " ? " + authorized);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -419,81 +458,101 @@ public class GeonetworkResolver {
|
|||
logger.info("Authorized on GN3 via HTTCallsUtils...");
|
||||
break;
|
||||
}
|
||||
|
||||
}else {
|
||||
logger.warn("I'm not able to perform authentication, the user read from config with "+Type.CKAN+" is null");
|
||||
|
||||
} else {
|
||||
logger.warn("I'm not able to perform authentication, the user read from config with "
|
||||
+ Type.CKAN + " is null");
|
||||
}
|
||||
|
||||
//PUBLIC LAYERS
|
||||
}else{
|
||||
logger.info("Visibility: "+VISIBILITY.PUB+" getting public layers..");
|
||||
//VRE LAYERS
|
||||
if(mode.equals(MODE.VRE.name())){
|
||||
logger.info("Getting "+MODE.VRE+" layers, the VRE account: "+account.getUser() +" will be used as owner user for filtering... Is it right?");
|
||||
// PUBLIC LAYERS
|
||||
} else {
|
||||
logger.info("Visibility: " + VISIBILITY.PUB + " getting public layers..");
|
||||
// VRE LAYERS
|
||||
if (mode.equals(MODE.VRE.name())) {
|
||||
logger.info("Getting " + MODE.VRE + " layers, the VRE account: " + account.getUser()
|
||||
+ " will be used as owner user for filtering... Is it right?");
|
||||
filters.put("ownername", account.getUser());
|
||||
//HARVESTED LAYERS
|
||||
}else{
|
||||
//filters.put("isHarvested", "y");
|
||||
logger.info("Getting "+MODE.HARVEST+" layers, I'm applying the filters ["+filters+"]");
|
||||
// HARVESTED LAYERS
|
||||
} else {
|
||||
// filters.put("isHarvested", "y");
|
||||
logger.info("Getting " + MODE.HARVEST + " layers, I'm applying the filters [" + filters + "]");
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("Sending CSW POST request to URL: "+gnCSWlURL);
|
||||
logger.debug("Content-Type: "+req.getContentType());
|
||||
logger.info("Sending CSW POST request to URL: " + gnCSWlURL);
|
||||
logger.debug("Content-Type: " + req.getContentType());
|
||||
|
||||
//DEBUG
|
||||
//logger.debug("POST - BODY : "+byteArray.toString());
|
||||
InputStream in = httpUtils.post(gnCSWlURL, new ByteArrayInputStream(byteArray.toByteArray()), req.getContentType(), req.getParameterMap());
|
||||
// DEBUG
|
||||
// logger.debug("POST - BODY : "+byteArray.toString());
|
||||
InputStream in = httpUtils.post(gnCSWlURL, new ByteArrayInputStream(byteArray.toByteArray()),
|
||||
req.getContentType(), req.getParameterMap());
|
||||
|
||||
if(in==null){
|
||||
logger.warn("Input stream returned is null, sending "+HttpServletResponse.SC_NOT_FOUND);
|
||||
throw ExceptionManager.notFoundException(req, "Input stream is null to the request "+gnCSWlURL+ " with body: "+byteArray.toString(), this.getClass(), helpURI);
|
||||
if (in == null) {
|
||||
logger.warn("Input stream returned is null, sending " + HttpServletResponse.SC_NOT_FOUND);
|
||||
throw ExceptionManager.notFoundException(req,
|
||||
"Input stream is null to the request " + gnCSWlURL + " with body: " + byteArray.toString(),
|
||||
this.getClass(), helpURI);
|
||||
}
|
||||
|
||||
try{
|
||||
try {
|
||||
|
||||
ReusableInputStream reus = new ReusableInputStream(in);
|
||||
|
||||
if(visibility.equals(VISIBILITY.PRV.name())){
|
||||
logger.info("Private VISIBILITY requested, retrieving public file identifiers to apply filtering..");
|
||||
if (visibility.equals(VISIBILITY.PRV.name())) {
|
||||
logger.info(
|
||||
"Private VISIBILITY requested, retrieving public file identifiers to apply filtering..");
|
||||
FilterGetRecords filterGetRecords = new FilterGetRecords(byteArray.toString(), geonetworkUrl);
|
||||
if(filterGetRecords.getFoundPublicIds()!=null && filterGetRecords.getFoundPublicIds().size()>0){
|
||||
logger.info("I'm removing list of public IDs with "+filterGetRecords.getFoundPublicIds().size() +" item/s. Is it right?");
|
||||
in = GetResponseRecordFilter.overrideResponseIdsByListIds(reus, filterGetRecords.getFoundPublicIds(), REPLACED_A_PUBLIC_UUID_PLEASE_IGNORE);
|
||||
if (filterGetRecords.getFoundPublicIds() != null
|
||||
&& filterGetRecords.getFoundPublicIds().size() > 0) {
|
||||
logger.info("I'm removing list of public IDs with "
|
||||
+ filterGetRecords.getFoundPublicIds().size() + " item/s. Is it right?");
|
||||
in = GetResponseRecordFilter.overrideResponseIdsByListIds(reus,
|
||||
filterGetRecords.getFoundPublicIds(), REPLACED_A_PUBLIC_UUID_PLEASE_IGNORE);
|
||||
}
|
||||
}
|
||||
|
||||
if(filters.size()>0){
|
||||
logger.info("Applying filtering on geonet:info... filter/s used: "+filters);
|
||||
if (filters.size() > 0) {
|
||||
logger.info("Applying filtering on geonet:info... filter/s used: " + filters);
|
||||
Document doc = GetResponseRecordFilter.inputStreamToW3CDocument(reus);
|
||||
List<String> fileIdentifiers = GetResponseRecordFilter.getTextContentStringsForTagName(doc, "gmd:fileIdentifier");
|
||||
List<String> fileIdentifiers = GetResponseRecordFilter.getTextContentStringsForTagName(doc,
|
||||
"gmd:fileIdentifier");
|
||||
List<String> noMatchingFilter = new ArrayList<String>();
|
||||
for (String fileId : fileIdentifiers) {
|
||||
|
||||
//CKECKING THE FILTERS
|
||||
// CKECKING THE FILTERS
|
||||
for (String fkey : filters.keySet()) {
|
||||
String value = GetResponseRecordFilter.getMetadataValueByFileIdentifier(fileId, config.getGeoNetworkEndpoint(),config.getAdminAccount().getUser(), config.getAdminAccount().getPassword(), fkey);
|
||||
//String own = GetResponseRecordFilter.getMetaOwnerNameByFileIdentifier(fileId, config.getGeoNetworkEndpoint(),config.getAdminAccount().getUser(), config.getAdminAccount().getPassword());
|
||||
String fValue = filters.get(fkey);
|
||||
//Either the filter KEY doesn't matching any geonet:info (value==null)
|
||||
//or the value of filterKey in geonet:info doesn't matching the passed filterValue (value.compareTo(fValue)!=0)
|
||||
if(value==null || value.compareTo(fValue)!=0){
|
||||
logger.trace(fkey +" of File Identifier "+fileId+" not matching the filter: "+fkey+" with value: "+fValue+", adding it to list to remove file identifier and exit from loop..");
|
||||
noMatchingFilter.add(fileId);
|
||||
//WHEN I ADD THE FILE IDENTIFIER TO FILTERED ID, I CAN EXIT FROM CKECKING FILTERS LOOP
|
||||
break;
|
||||
}
|
||||
String value = GetResponseRecordFilter.getMetadataValueByFileIdentifier(fileId,
|
||||
config.getGeoNetworkEndpoint(), config.getAdminAccount().getUser(),
|
||||
config.getAdminAccount().getPassword(), fkey);
|
||||
// String own = GetResponseRecordFilter.getMetaOwnerNameByFileIdentifier(fileId,
|
||||
// config.getGeoNetworkEndpoint(),config.getAdminAccount().getUser(),
|
||||
// config.getAdminAccount().getPassword());
|
||||
String fValue = filters.get(fkey);
|
||||
// Either the filter KEY doesn't matching any geonet:info (value==null)
|
||||
// or the value of filterKey in geonet:info doesn't matching the passed
|
||||
// filterValue (value.compareTo(fValue)!=0)
|
||||
if (value == null || value.compareTo(fValue) != 0) {
|
||||
logger.trace(fkey + " of File Identifier " + fileId + " not matching the filter: "
|
||||
+ fkey + " with value: " + fValue
|
||||
+ ", adding it to list to remove file identifier and exit from loop..");
|
||||
noMatchingFilter.add(fileId);
|
||||
// WHEN I ADD THE FILE IDENTIFIER TO FILTERED ID, I CAN EXIT FROM CKECKING
|
||||
// FILTERS LOOP
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(noMatchingFilter.size()>0){
|
||||
logger.info("Removing "+noMatchingFilter.size()+" layer/s that not macthing the filters: "+filters);
|
||||
//Document doc2 = GetResponseRecordFilter.inputStreamToW3CDocument(reus);
|
||||
in = GetResponseRecordFilter.overrideResponseIdsByListIds(reus, noMatchingFilter, REPLACED_UUID_BY_FILTER_PLEASE_IGNORE);
|
||||
//in = GetResponseRecordFilter.w3CDocumentToInputStream(doc);
|
||||
if (noMatchingFilter.size() > 0) {
|
||||
logger.info("Removing " + noMatchingFilter.size()
|
||||
+ " layer/s that not macthing the filters: " + filters);
|
||||
// Document doc2 = GetResponseRecordFilter.inputStreamToW3CDocument(reus);
|
||||
in = GetResponseRecordFilter.overrideResponseIdsByListIds(reus, noMatchingFilter,
|
||||
REPLACED_UUID_BY_FILTER_PLEASE_IGNORE);
|
||||
// in = GetResponseRecordFilter.w3CDocumentToInputStream(doc);
|
||||
|
||||
}else{
|
||||
logger.info("No replace on UUIDs was applied from filters: "+filters);
|
||||
} else {
|
||||
logger.info("No replace on UUIDs was applied from filters: " + filters);
|
||||
in = reus;
|
||||
}
|
||||
|
||||
|
@ -501,46 +560,49 @@ public class GeonetworkResolver {
|
|||
|
||||
ReusableInputStream reusIs = new ReusableInputStream(in);
|
||||
|
||||
//END DEBUG
|
||||
logger.info("Response return Content-Type: "+httpUtils.getLastContentType());
|
||||
return Response
|
||||
.ok(reusIs)
|
||||
//.header(ConstantsResolver.CONTENT_DISPOSITION,"attachment; filename = \""+fileName+"\"")
|
||||
.header(ConstantsResolver.CONTENT_TYPE, httpUtils.getLastContentType()).build();
|
||||
// END DEBUG
|
||||
logger.info("Response return Content-Type: " + httpUtils.getLastContentType());
|
||||
return Response.ok(reusIs)
|
||||
// .header(ConstantsResolver.CONTENT_DISPOSITION,"attachment; filename =
|
||||
// \""+fileName+"\"")
|
||||
.header(ConstantsResolver.CONTENT_TYPE, httpUtils.getLastContentType()).build();
|
||||
|
||||
}catch(Exception e){
|
||||
} catch (Exception e) {
|
||||
logger.error("Error on copy the response to send to client: ", e);
|
||||
throw ExceptionManager.internalErrorException(req, "Error on copy the response!", this.getClass(), helpURI);
|
||||
}finally{
|
||||
throw ExceptionManager.internalErrorException(req, "Error on copy the response!", this.getClass(),
|
||||
helpURI);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(in);
|
||||
}
|
||||
|
||||
} catch (IllegalArgumentException e){
|
||||
} catch (IllegalArgumentException e) {
|
||||
logger.error("IllegalArgumentException:", e);
|
||||
throw ExceptionManager.badRequestException(req, "Illegal argument to carry out the request!", this.getClass(), helpURI);
|
||||
throw ExceptionManager.badRequestException(req, "Illegal argument to carry out the request!",
|
||||
this.getClass(), helpURI);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Exception:", e);
|
||||
String error = "Sorry, an error occurred on resolving geonetwork request with scope "+scope+". Please, contact support!";
|
||||
String error = "Sorry, an error occurred on resolving geonetwork request with scope " + scope
|
||||
+ ". Please, contact support!";
|
||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||
}
|
||||
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
|
||||
if(!(e instanceof WebApplicationException)){
|
||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error during perform POST operation to: "+gnCSWlURL+". Please, contact the support!";
|
||||
if(e.getCause()!=null)
|
||||
error+="\n\nCaused: "+e.getCause().getMessage();
|
||||
if (!(e instanceof WebApplicationException)) {
|
||||
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error during perform POST operation to: " + gnCSWlURL
|
||||
+ ". Please, contact the support!";
|
||||
if (e.getCause() != null)
|
||||
error += "\n\nCaused: " + e.getCause().getMessage();
|
||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||
}
|
||||
//ALREADY MANAGED AS WebApplicationException
|
||||
// ALREADY MANAGED AS WebApplicationException
|
||||
logger.error("Exception:", e);
|
||||
throw (WebApplicationException) e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the geonetwork instance for scope.
|
||||
|
@ -549,15 +611,15 @@ public class GeonetworkResolver {
|
|||
* @return the geonetwork instance for scope
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
protected GeonetworkInstance getGeonetworkInstanceForScope(String scope) throws Exception{
|
||||
protected GeonetworkInstance getGeonetworkInstanceForScope(String scope) throws Exception {
|
||||
|
||||
logger.info("Trying to read the {} from cache for scope: {}",GeonetworkInstance.class.getSimpleName(), scope);
|
||||
logger.info("Trying to read the {} from cache for scope: {}", GeonetworkInstance.class.getSimpleName(), scope);
|
||||
GeonetworkInstance geoInstance;
|
||||
try {
|
||||
geoInstance = LoadingGeonetworkInstanceCache.get(scope);
|
||||
}catch (Exception e) {
|
||||
logger.error("An error occurred on reading GeonetworkInstance for scope "+scope, e);
|
||||
throw new Exception("Sorry, An error occurred on reading GeonetworkInstance for scope "+scope);
|
||||
} catch (Exception e) {
|
||||
logger.error("An error occurred on reading GeonetworkInstance for scope " + scope, e);
|
||||
throw new Exception("Sorry, An error occurred on reading GeonetworkInstance for scope " + scope);
|
||||
}
|
||||
return geoInstance;
|
||||
|
||||
|
|
|
@ -32,13 +32,16 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The Class GisResolver.
|
||||
*
|
||||
* The GisResolver is able to resolve GIS Links (as a redirect to Gis Viewer
|
||||
* Application) in order to display and navigate on web-map the gis layers
|
||||
* stored in D4Science's Geonetwork
|
||||
*
|
||||
* See more at
|
||||
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#GIS_Resolver
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Dec 14, 2018
|
||||
* Dec 14, 2018
|
||||
*/
|
||||
@Path("gis")
|
||||
public class GisResolver {
|
||||
|
@ -53,62 +56,60 @@ public class GisResolver {
|
|||
public static final String SCOPE = "scope";
|
||||
public static final String GEO_EXPLORER_LAYER_UUID = "geo-exp";
|
||||
|
||||
|
||||
/**
|
||||
* Submit get.
|
||||
*
|
||||
* @param req the req
|
||||
* @param scope the scope
|
||||
* @param gisUUID the gis uuid
|
||||
* @param req the req
|
||||
* @param scope the scope
|
||||
* @param gisUUID the gis uuid
|
||||
* @param geoExplorerUUID the geo explorer uuid
|
||||
* @return the response
|
||||
* @throws WebApplicationException the web application exception
|
||||
*/
|
||||
@GET
|
||||
@Path("")
|
||||
public Response submitGet(@Context HttpServletRequest req, @
|
||||
QueryParam(SCOPE) String scope,
|
||||
@QueryParam(GIS_UUID) String gisUUID,
|
||||
@QueryParam(GEO_EXPLORER_LAYER_UUID) String geoExplorerUUID) throws WebApplicationException{
|
||||
public Response submitGet(@Context HttpServletRequest req, @QueryParam(SCOPE) String scope,
|
||||
@QueryParam(GIS_UUID) String gisUUID, @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 isGeoExplorerLink = false;
|
||||
|
||||
if(scope==null || scope.isEmpty()){
|
||||
if (scope == null || scope.isEmpty()) {
|
||||
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");
|
||||
throw ExceptionManager.badRequestException(req, "Missing mandatory query parameter 'gis-UUID'", this.getClass(), help);
|
||||
}else
|
||||
throw ExceptionManager.badRequestException(req, "Missing mandatory query parameter 'gis-UUID'",
|
||||
this.getClass(), help);
|
||||
} else
|
||||
isGisLink = true;
|
||||
|
||||
logger.info(SCOPE +" is: " + scope);
|
||||
logger.info(GIS_UUID +" is: " + gisUUID);
|
||||
logger.info(SCOPE + " is: " + scope);
|
||||
logger.info(GIS_UUID + " is: " + gisUUID);
|
||||
|
||||
if (geoExplorerUUID == null || geoExplorerUUID.isEmpty()) {
|
||||
logger.debug(GEO_EXPLORER_LAYER_UUID+ " not found");
|
||||
}else
|
||||
logger.debug(GEO_EXPLORER_LAYER_UUID + " not found");
|
||||
} else
|
||||
isGeoExplorerLink = true;
|
||||
|
||||
logger.info(GEO_EXPLORER_LAYER_UUID +" is: " + geoExplorerUUID);
|
||||
logger.info(GEO_EXPLORER_LAYER_UUID + " is: " + geoExplorerUUID);
|
||||
|
||||
if(!isGisLink && !isGeoExplorerLink){
|
||||
String err = GIS_UUID+" or "+GEO_EXPLORER_LAYER_UUID+" not found or empty in the query string";
|
||||
if (!isGisLink && !isGeoExplorerLink) {
|
||||
String err = GIS_UUID + " or " + GEO_EXPLORER_LAYER_UUID + " not found or empty in the query string";
|
||||
logger.error(err);
|
||||
throw ExceptionManager.badRequestException(req, err, this.getClass(), help);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(isGisLink){
|
||||
if (isGisLink) {
|
||||
ScopeProvider.instance.set(scope);
|
||||
//ServerParameters geonetworkParams = getCachedServerParameters(scope);
|
||||
// ServerParameters geonetworkParams = getCachedServerParameters(scope);
|
||||
GisLayerItem gisLayerItem = getGisLayerForLayerUUID(req, scope, gisUUID);
|
||||
|
||||
logger.info("wms url is: " + gisLayerItem.getFullWmsUrlRequest());
|
||||
|
@ -116,112 +117,132 @@ public class GisResolver {
|
|||
logger.info("encoded WMS url is: " + wmsRequest);
|
||||
|
||||
String layerTitle = null;
|
||||
if(gisLayerItem.getCitationTitle()!=null && !gisLayerItem.getCitationTitle().isEmpty())
|
||||
layerTitle = URLEncoder.encode(gisLayerItem.getCitationTitle(), UTF_8);
|
||||
if (gisLayerItem.getCitationTitle() != null && !gisLayerItem.getCitationTitle().isEmpty())
|
||||
layerTitle = URLEncoder.encode(gisLayerItem.getCitationTitle(), UTF_8);
|
||||
|
||||
logger.info("layer Title encoded is: " + layerTitle);
|
||||
String gisViewerPortletUrl = null;
|
||||
try{
|
||||
try {
|
||||
gisViewerPortletUrl = LoadingGisViewerApplicationURLCache.get(scope);
|
||||
}catch(ExecutionException | InvalidCacheLoadException 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);
|
||||
} catch (ExecutionException | InvalidCacheLoadException 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);
|
||||
}
|
||||
//CHECKING IF THE GisViewer Portlet URL is valid
|
||||
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);
|
||||
// CHECKING IF THE GisViewer Portlet URL is valid
|
||||
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);
|
||||
|
||||
logger.info("Gis Viewer Application url is: " + gisViewerPortletUrl);
|
||||
gisViewerPortletUrl+="?rid="+new Random().nextLong()
|
||||
+"&wmsrequest="+wmsRequest
|
||||
+"&uuid="+URLEncoder.encode(gisUUID, UTF_8);
|
||||
gisViewerPortletUrl += "?rid=" + new Random().nextLong() + "&wmsrequest=" + wmsRequest + "&uuid="
|
||||
+ URLEncoder.encode(gisUUID, UTF_8);
|
||||
|
||||
if(layerTitle!=null)
|
||||
gisViewerPortletUrl+="&layertitle="+layerTitle;
|
||||
if (layerTitle != null)
|
||||
gisViewerPortletUrl += "&layertitle=" + layerTitle;
|
||||
|
||||
logger.info("Redirecting to: "+gisViewerPortletUrl);
|
||||
logger.info("Redirecting to: " + gisViewerPortletUrl);
|
||||
return Response.seeOther(new URI(gisViewerPortletUrl)).build();
|
||||
|
||||
}
|
||||
|
||||
if(isGeoExplorerLink){
|
||||
if (isGeoExplorerLink) {
|
||||
|
||||
ScopeProvider.instance.set(scope);
|
||||
String geoExplorerPortletUrl = null;
|
||||
try{
|
||||
try {
|
||||
geoExplorerPortletUrl = LoadingGeoExplorerApplicationURLCache.get(scope);
|
||||
}catch(ExecutionException 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);
|
||||
} catch (ExecutionException 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);
|
||||
}
|
||||
//CHECKING IF THE GeoExplorer Portlet URL is valid
|
||||
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);
|
||||
// CHECKING IF THE GeoExplorer Portlet URL is valid
|
||||
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);
|
||||
|
||||
logger.info("GeoExplorer Application url is: " + geoExplorerPortletUrl);
|
||||
geoExplorerPortletUrl+="?rid="+new Random().nextLong()
|
||||
+"&luuid="+URLEncoder.encode(geoExplorerUUID, UTF_8);
|
||||
//urlRedirect(req, resp, geoExplorerPortletUrl);
|
||||
geoExplorerPortletUrl += "?rid=" + new Random().nextLong() + "&luuid="
|
||||
+ URLEncoder.encode(geoExplorerUUID, UTF_8);
|
||||
// urlRedirect(req, resp, geoExplorerPortletUrl);
|
||||
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)){
|
||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Sorry, an error occurred on resolving request with UUID "+gisUUID+" and scope "+scope+". Please, contact support!";
|
||||
if(e.getCause()!=null)
|
||||
error+="\n\nCaused: "+e.getCause().getMessage();
|
||||
if (!(e instanceof 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!";
|
||||
if (e.getCause() != null)
|
||||
error += "\n\nCaused: " + e.getCause().getMessage();
|
||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), help);
|
||||
}
|
||||
//ALREADY MANAGED AS WebApplicationException
|
||||
// ALREADY MANAGED AS WebApplicationException
|
||||
logger.error("Exception:", e);
|
||||
throw (WebApplicationException) e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the gis layer for layer uuid.
|
||||
*
|
||||
* @param req the req
|
||||
* @param scope the scope
|
||||
* @param req the req
|
||||
* @param scope the scope
|
||||
* @param gisUUID the gis uuid
|
||||
* @return the gis layer for layer uuid
|
||||
* @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 {
|
||||
GeonetworkInstance gi = null;
|
||||
try {
|
||||
gi = LoadingGeonetworkInstanceCache.get(scope);
|
||||
|
||||
}catch(ExecutionException | InvalidCacheLoadException 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);
|
||||
|
||||
} catch (ExecutionException | InvalidCacheLoadException 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);
|
||||
}
|
||||
if(gi==null)
|
||||
throw new Exception("GeonetworkInstance not instanciable in the scope: "+scope);
|
||||
|
||||
if (gi == null)
|
||||
throw new Exception("GeonetworkInstance not instanciable in the scope: " + 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);
|
||||
|
||||
GisLayerItem gisLayerItem = MetadataConverter.getWMSOnLineResource(gi, gisUUID);
|
||||
return gisLayerItem;
|
||||
//TODO CREATE A BEAN ADDING WMS REQUEST AND LAYER TITLE MetadataConverter.
|
||||
}catch (GeonetworkInstanceException 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);
|
||||
// TODO CREATE A BEAN ADDING WMS REQUEST AND LAYER TITLE MetadataConverter.
|
||||
} catch (GeonetworkInstanceException 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);
|
||||
} catch (Exception 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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -23,11 +23,15 @@ import org.gcube.datatransfer.resolver.util.Util;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Dec 13, 2018
|
||||
* The KnimeCreateResolver is able to create a KNIME URL.
|
||||
*
|
||||
* See more at
|
||||
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#KNIME_Resolver
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Mar 24, 2022
|
||||
*/
|
||||
@Path("knime")
|
||||
public class KnimeCreateResolver {
|
||||
|
@ -36,9 +40,12 @@ public class KnimeCreateResolver {
|
|||
|
||||
private static String helpURI = "https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#KNIME_Resolver";
|
||||
|
||||
|
||||
/**
|
||||
* Creates the knime URL.
|
||||
* Creates the KNIME URL. Generate a Knime URL (then resolved by the /get path)
|
||||
* for a KNIME Model Simulation passed by query string.
|
||||
*
|
||||
* See more at
|
||||
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#HTTP_POST:_Create_a_KNIME_URL
|
||||
*
|
||||
* @param req the req
|
||||
* @return the response
|
||||
|
@ -48,51 +55,55 @@ public class KnimeCreateResolver {
|
|||
@Path("/create")
|
||||
@Consumes(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 scope = ScopeProvider.instance.get();
|
||||
// logger.info("SecurityTokenProvider contextToken: "+contextToken);
|
||||
logger.info("ScopeProvider has scope: "+scope);
|
||||
// logger.info("SecurityTokenProvider contextToken: "+contextToken);
|
||||
logger.info("ScopeProvider has scope: " + scope);
|
||||
|
||||
String appToken = req.getServletContext().getInitParameter(RequestHandler.ROOT_APP_TOKEN);
|
||||
|
||||
if(contextToken.compareTo(appToken)==0){
|
||||
logger.error("Token not passed, SecurityTokenProvider contains the root app token: "+appToken.substring(0,10)+"...");
|
||||
throw ExceptionManager.unauthorizedException(req, "You are not authorized. You must pass a token of VRE", this.getClass(), helpURI);
|
||||
if (contextToken.compareTo(appToken) == 0) {
|
||||
logger.error("Token not passed, SecurityTokenProvider contains the root app token: "
|
||||
+ 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);
|
||||
|
||||
if(scopeBean.is(Type.VRE)){
|
||||
if (scopeBean.is(Type.VRE)) {
|
||||
|
||||
String vreName = scopeBean.name();
|
||||
String knimeGetResolverURL = String.format("%s/%s/%s", Util.getServerURL(req), "knime/get", vreName);
|
||||
String queryString =req.getQueryString()==null?"":req.getQueryString();
|
||||
String knimeGetResolverURL = String.format("%s/%s/%s", Util.getServerURL(req), "knime/get", vreName);
|
||||
String queryString = req.getQueryString() == null ? "" : req.getQueryString();
|
||||
|
||||
if(req.getQueryString()!=null)
|
||||
knimeGetResolverURL+="?"+queryString;
|
||||
if (req.getQueryString() != null)
|
||||
knimeGetResolverURL += "?" + queryString;
|
||||
|
||||
logger.info("Returning Knime Resolver URL: "+knimeGetResolverURL);
|
||||
logger.info("Returning Knime Resolver URL: " + knimeGetResolverURL);
|
||||
return Response.ok(knimeGetResolverURL).header("Location", knimeGetResolverURL).build();
|
||||
|
||||
}else{
|
||||
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);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
|
||||
if(!(e instanceof WebApplicationException)){
|
||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
if (!(e instanceof WebApplicationException)) {
|
||||
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Sorry, an error occurred on creating Knime URL. Please, contact the support!";
|
||||
if(e.getCause()!=null)
|
||||
error+="\n\nCaused: "+e.getCause().getMessage();
|
||||
if (e.getCause() != null)
|
||||
error += "\n\nCaused: " + e.getCause().getMessage();
|
||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||
}
|
||||
//ALREADY MANAGED AS WebApplicationException
|
||||
// ALREADY MANAGED AS WebApplicationException
|
||||
logger.error("Exception:", e);
|
||||
throw (WebApplicationException) e;
|
||||
}
|
||||
|
|
|
@ -23,12 +23,14 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
|
||||
|
||||
|
||||
/**
|
||||
* The Class KnimeGetResolver.
|
||||
* The KnimeGetResolver provides a method to get the Knime URLs (that are simply
|
||||
* URLs) by which is possible to invoke the KNIME Model Simulation Application.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Dec 13, 2018
|
||||
* See more at
|
||||
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#KNIME_Resolver
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Dec 13, 2018
|
||||
*/
|
||||
@Path("knime")
|
||||
public class KnimeGetResolver {
|
||||
|
@ -37,8 +39,7 @@ public class KnimeGetResolver {
|
|||
|
||||
private static String helpURI = "https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#KNIME_Resolver";
|
||||
|
||||
private static final String ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL =
|
||||
"org.gcube.portlets.user.model-simulation-configuration.server.KnimeModelSimulationManagerServiceImpl";
|
||||
private static final String ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL = "org.gcube.portlets.user.model-simulation-configuration.server.KnimeModelSimulationManagerServiceImpl";
|
||||
|
||||
private static final String APPLICATION_PROFILE = "ApplicationProfile";
|
||||
|
||||
|
@ -47,55 +48,62 @@ public class KnimeGetResolver {
|
|||
/**
|
||||
* Resolve knime url.
|
||||
*
|
||||
* @param req the req
|
||||
* @param req the req
|
||||
* @param vreName the vre name
|
||||
* @return the response
|
||||
*/
|
||||
@GET
|
||||
@Path("/get/{vreName}")
|
||||
public Response resolveKnimeURL(@Context HttpServletRequest req, @PathParam("vreName") String vreName) {
|
||||
logger.info(this.getClass().getSimpleName()+" GET starts...");
|
||||
logger.info(this.getClass().getSimpleName() + " GET starts...");
|
||||
|
||||
try {
|
||||
if(vreName==null || vreName.isEmpty()){
|
||||
if (vreName == null || vreName.isEmpty()) {
|
||||
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 scopeBean = null;
|
||||
try{
|
||||
try {
|
||||
scopeBean = LoadingMapOfScopeCache.get(vreName);
|
||||
}catch(ExecutionException | InvalidCacheLoadException 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);
|
||||
} catch (ExecutionException | InvalidCacheLoadException 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);
|
||||
}
|
||||
ApplicationProfileReader reader = null;
|
||||
String fullScope = scopeBean.toString();
|
||||
try{
|
||||
reader = new ApplicationProfileReader(fullScope, APPLICATION_PROFILE, ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL, false);
|
||||
}catch(Exception e){
|
||||
logger.error("Error on reading the "+APPLICATION_PROFILE+" with APPID: "+ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL, e);
|
||||
throw ExceptionManager.internalErrorException(req, "Error on reading the Application Profile for the "+KNIME_EXECUTOR_APPLICATION+". Please contact the support", this.getClass(), helpURI);
|
||||
try {
|
||||
reader = new ApplicationProfileReader(fullScope, APPLICATION_PROFILE,
|
||||
ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL, false);
|
||||
} catch (Exception e) {
|
||||
logger.error("Error on reading the " + APPLICATION_PROFILE + " with APPID: "
|
||||
+ ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL, e);
|
||||
throw ExceptionManager.internalErrorException(req, "Error on reading the Application Profile for the "
|
||||
+ KNIME_EXECUTOR_APPLICATION + ". Please contact the support", this.getClass(), helpURI);
|
||||
}
|
||||
|
||||
//READ THE KNIME URL PORTLET FROM APPLICATION PROFRILE IN THE SCOPE fullScope
|
||||
// READ THE KNIME URL PORTLET FROM APPLICATION PROFRILE IN THE SCOPE fullScope
|
||||
String knimeExecutorEndPoint = reader.getApplicationProfile().getUrl();
|
||||
//CHECKING THE QUERY STRING
|
||||
String queryString = req.getQueryString()!=null?req.getQueryString():"";
|
||||
// CHECKING THE QUERY STRING
|
||||
String queryString = req.getQueryString() != null ? req.getQueryString() : "";
|
||||
String knimeExecutorURL = String.format("%s?%s", knimeExecutorEndPoint, queryString);
|
||||
logger.info("Resolving the Knime URL with: "+knimeExecutorURL);
|
||||
logger.info("Resolving the Knime URL with: " + knimeExecutorURL);
|
||||
return Response.seeOther(new URI(knimeExecutorURL)).build();
|
||||
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
|
||||
if(!(e instanceof WebApplicationException)){
|
||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
if (!(e instanceof WebApplicationException)) {
|
||||
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Sorry, an error occurred on resolving the Knime URL. Please, contact the support!";
|
||||
if(e.getCause()!=null)
|
||||
error+="\n\nCaused: "+e.getCause().getMessage();
|
||||
if (e.getCause() != null)
|
||||
error += "\n\nCaused: " + e.getCause().getMessage();
|
||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||
}
|
||||
//ALREADY MANAGED AS WebApplicationException
|
||||
// ALREADY MANAGED AS WebApplicationException
|
||||
logger.error("Exception:", e);
|
||||
throw (WebApplicationException) e;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
package org.gcube.datatransfer.resolver.services;
|
||||
|
||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||
import org.gcube.common.authorization.library.provider.UserInfo;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* The Class OatResolver.
|
||||
*
|
||||
* generates an old authz token from an UMAToken
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Apr 5, 2022
|
||||
*/
|
||||
@Path("oat")
|
||||
public class OatResolver {
|
||||
|
||||
private static Logger LOG = LoggerFactory.getLogger(OatResolver.class);
|
||||
|
||||
/**
|
||||
* Gets the legacy token.
|
||||
*
|
||||
* @param req the req
|
||||
* @return the legacy token
|
||||
* @throws WebApplicationException the web application exception
|
||||
*/
|
||||
@GET
|
||||
@Path("/get")
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public Response getLegacyToken(@Context HttpServletRequest req) throws WebApplicationException {
|
||||
LOG.info(this.getClass().getSimpleName() + " GET starts...");
|
||||
|
||||
try {
|
||||
|
||||
String scope = ScopeProvider.instance.get();
|
||||
LOG.info("ScopeProvider has scope: " + scope);
|
||||
String username = AuthorizationProvider.instance.get().getClient().getId();
|
||||
UserInfo userInfo = new UserInfo(username, new ArrayList<>());
|
||||
String userToken = authorizationService().generateUserToken(userInfo, scope);
|
||||
String msgToken = userToken.substring(0, 10) + "_MASKED_TOKEN";
|
||||
LOG.info("returning legacy token {} for user {}", msgToken, username);
|
||||
return Response.ok(userToken).build();
|
||||
} catch (Exception e) {
|
||||
LOG.error("Exception:", e);
|
||||
|
||||
if (!(e instanceof WebApplicationException)) {
|
||||
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error occurred on getting legacy token. Please, contact the support!";
|
||||
if (e.getCause() != null)
|
||||
error += "\n\nCaused: " + e.getCause().getMessage();
|
||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), null);
|
||||
}
|
||||
// ALREADY MANAGED AS WebApplicationException
|
||||
throw (WebApplicationException) e;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -28,12 +28,13 @@ import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* The Class PartheosRegistryResolver.
|
||||
* The PartheosRegistryResolver.
|
||||
*
|
||||
* See more at
|
||||
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Parthenos_URL_Resolver
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Nov 16, 2018
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Nov 16, 2018
|
||||
*/
|
||||
@Path("parthenos_registry")
|
||||
public class PartheosRegistryResolver {
|
||||
|
@ -43,65 +44,70 @@ public class PartheosRegistryResolver {
|
|||
|
||||
/**
|
||||
* Resolve parthenos url.
|
||||
*
|
||||
* To resolve an "item" from a Parthenos URL stored in the Parthenos Catalogue
|
||||
* at https://ckan-parthenos.d4science.org/
|
||||
*
|
||||
* @param req the req
|
||||
* @param provider the provider
|
||||
* @param path the path
|
||||
* @param req the req
|
||||
* @param provider the provider
|
||||
* @param path the path
|
||||
* @param remainPath the remain path
|
||||
* @return the response
|
||||
*/
|
||||
@GET
|
||||
@Path("/{provider}/{path}{remainPath:(/[^?$]+)?}")
|
||||
public Response resolveParthenosURL(@Context HttpServletRequest req,
|
||||
@PathParam("provider") String provider,
|
||||
@PathParam("path") String path,
|
||||
@PathParam("remainPath") String remainPath) throws WebApplicationException {
|
||||
public Response resolveParthenosURL(@Context HttpServletRequest req, @PathParam("provider") String provider,
|
||||
@PathParam("path") String path, @PathParam("remainPath") String remainPath) throws WebApplicationException {
|
||||
|
||||
logger.info(this.getClass().getSimpleName()+" GET starts...");
|
||||
logger.info(this.getClass().getSimpleName() + " GET starts...");
|
||||
String remainPathParthenosURL = null;
|
||||
|
||||
try {
|
||||
|
||||
logger.debug("provider is: "+provider);
|
||||
logger.debug("path is: "+path);
|
||||
logger.debug("remainPath is: "+remainPath);
|
||||
logger.debug("provider is: " + provider);
|
||||
logger.debug("path is: " + path);
|
||||
logger.debug("remainPath is: " + remainPath);
|
||||
|
||||
remainPathParthenosURL = String.format("%s/%s",provider,path);
|
||||
remainPathParthenosURL = String.format("%s/%s", provider, path);
|
||||
|
||||
if(remainPath!=null && !remainPath.isEmpty()){
|
||||
remainPathParthenosURL+=remainPath.startsWith("/")?remainPath:"/"+remainPath;
|
||||
if (remainPath != null && !remainPath.isEmpty()) {
|
||||
remainPathParthenosURL += remainPath.startsWith("/") ? remainPath : "/" + remainPath;
|
||||
}
|
||||
|
||||
logger.info("Resolving parthenos URL: "+remainPathParthenosURL);
|
||||
//APPLYING URL DECODING
|
||||
logger.info("Resolving parthenos URL: " + remainPathParthenosURL);
|
||||
// APPLYING URL DECODING
|
||||
remainPathParthenosURL = URLDecoder.decode(remainPathParthenosURL, "UTF-8");
|
||||
//APPLYING NAME TRANSFORMATION
|
||||
// APPLYING NAME TRANSFORMATION
|
||||
String normalizedEntityName = toNameForCatalogue(remainPathParthenosURL);
|
||||
logger.info("Trying to resolve with Catalogue EntityName: "+normalizedEntityName);
|
||||
ItemCatalogueURLs itemCatalogueURLs = CatalogueResolver.getItemCatalogueURLs(req, UriResolverSmartGearManagerInit.getParthenosVREName(), ResourceCatalogueCodes.CTLGD.getId(), normalizedEntityName);
|
||||
logger.info("Trying to resolve with Catalogue EntityName: " + normalizedEntityName);
|
||||
ItemCatalogueURLs itemCatalogueURLs = CatalogueResolver.getItemCatalogueURLs(req,
|
||||
UriResolverSmartGearManagerInit.getParthenosVREName(), ResourceCatalogueCodes.CTLGD.getId(),
|
||||
normalizedEntityName);
|
||||
return Response.seeOther(new URL(itemCatalogueURLs.getPrivateVRECataloguePortletURL()).toURI()).build();
|
||||
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
|
||||
if(!(e instanceof WebApplicationException)){
|
||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error occurred on resolving the path "+remainPathParthenosURL+". Please, contact the support!";
|
||||
if(e.getCause()!=null)
|
||||
error+="\n\nCaused: "+e.getCause().getMessage();
|
||||
if (!(e instanceof WebApplicationException)) {
|
||||
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error occurred on resolving the path " + remainPathParthenosURL
|
||||
+ ". Please, contact the support!";
|
||||
if (e.getCause() != null)
|
||||
error += "\n\nCaused: " + e.getCause().getMessage();
|
||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||
}
|
||||
//ALREADY MANAGED AS WebApplicationException
|
||||
// ALREADY MANAGED AS WebApplicationException
|
||||
logger.error("Exception:", e);
|
||||
throw (WebApplicationException) e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Post catalogue.
|
||||
* To get a normalized item name from a Parthenos URL. It applies a
|
||||
* normalization function to get from an input Parthenos URL an item name that
|
||||
* is catalogue compliant.
|
||||
*
|
||||
* @param req the req
|
||||
* @param req the req
|
||||
* @param jsonRequest the json request
|
||||
* @return the response
|
||||
* @throws Exception the exception
|
||||
|
@ -110,59 +116,67 @@ public class PartheosRegistryResolver {
|
|||
@Path("")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public Response postCatalogue(@Context HttpServletRequest req, ParthenosRequest jsonRequest) throws WebApplicationException{
|
||||
logger.info(this.getClass().getSimpleName()+" POST starts...");
|
||||
public Response postCatalogue(@Context HttpServletRequest req, ParthenosRequest jsonRequest)
|
||||
throws WebApplicationException {
|
||||
logger.info(this.getClass().getSimpleName() + " POST starts...");
|
||||
|
||||
try{
|
||||
try {
|
||||
String entityName = jsonRequest.getEntity_name();
|
||||
|
||||
if(entityName==null || entityName.isEmpty()){
|
||||
if (entityName == null || entityName.isEmpty()) {
|
||||
logger.error("Entity Name Parameter like 'entity_name' not found or empty");
|
||||
throw ExceptionManager.badRequestException(req, "Mandatory body parameter 'entity_name' not found or empty", this.getClass(), helpURI);
|
||||
throw ExceptionManager.badRequestException(req,
|
||||
"Mandatory body parameter 'entity_name' not found or empty", this.getClass(), helpURI);
|
||||
}
|
||||
|
||||
//REMOVING FIRST '/' IF EXISTS
|
||||
entityName = entityName.startsWith("/")?entityName.substring(1,entityName.length()):entityName;
|
||||
// REMOVING FIRST '/' IF EXISTS
|
||||
entityName = entityName.startsWith("/") ? entityName.substring(1, entityName.length()) : entityName;
|
||||
|
||||
//APPLYING NAME TRANSFORMATION
|
||||
// APPLYING NAME TRANSFORMATION
|
||||
String normalizedEntityName = toNameForCatalogue(entityName);
|
||||
ItemCatalogueURLs itemCatalogueURLs = CatalogueResolver.getItemCatalogueURLs(req, UriResolverSmartGearManagerInit.getParthenosVREName(), ResourceCatalogueCodes.CTLGD.getId(), normalizedEntityName);
|
||||
logger.info("Returining Catalogue URL: "+itemCatalogueURLs.getPrivateVRECataloguePortletURL());
|
||||
return Response.ok(normalizedEntityName).header("Location", itemCatalogueURLs.getPrivateVRECataloguePortletURL()).build();
|
||||
ItemCatalogueURLs itemCatalogueURLs = CatalogueResolver.getItemCatalogueURLs(req,
|
||||
UriResolverSmartGearManagerInit.getParthenosVREName(), ResourceCatalogueCodes.CTLGD.getId(),
|
||||
normalizedEntityName);
|
||||
logger.info("Returining Catalogue URL: " + itemCatalogueURLs.getPrivateVRECataloguePortletURL());
|
||||
return Response.ok(normalizedEntityName)
|
||||
.header("Location", itemCatalogueURLs.getPrivateVRECataloguePortletURL()).build();
|
||||
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
|
||||
if(!(e instanceof WebApplicationException)){
|
||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error occurred on transforming the "+jsonRequest+". Please, contact the support!";
|
||||
if (!(e instanceof WebApplicationException)) {
|
||||
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error occurred on transforming the " + jsonRequest + ". Please, contact the support!";
|
||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||
}
|
||||
//ALREADY MANAGED AS WebApplicationException
|
||||
// ALREADY MANAGED AS WebApplicationException
|
||||
logger.error("Exception:", e);
|
||||
throw (WebApplicationException) e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* To name for catalogue.
|
||||
* this method applyes a fuction to transform a parthenos URL to acceptable catalogue name (that is URL)
|
||||
* To name for catalogue. this method applyes a fuction to transform a parthenos
|
||||
* URL to acceptable catalogue name (that is URL)
|
||||
*
|
||||
* @param remainPathParthenosURL the remain path parthenos url
|
||||
* @return the string
|
||||
* @throws UnsupportedEncodingException the unsupported encoding exception
|
||||
*/
|
||||
protected String toNameForCatalogue(final String remainPathParthenosURL) throws UnsupportedEncodingException {
|
||||
//need to double decode for URLs like: http://parthenos.d4science.org/handle/Parthenos/REG/Dataset/Appellation/Isidore%2520Dataset
|
||||
String name = StringUtils.replaceChars(URLDecoder.decode(remainPathParthenosURL,"UTF-8"),"/ .:", "_").toLowerCase().replaceAll("[^A-Za-z0-9]", "_");
|
||||
//TO LOWERCASE FOR CKAN SUPPORTING
|
||||
// need to double decode for URLs like:
|
||||
// http://parthenos.d4science.org/handle/Parthenos/REG/Dataset/Appellation/Isidore%2520Dataset
|
||||
String name = StringUtils.replaceChars(URLDecoder.decode(remainPathParthenosURL, "UTF-8"), "/ .:", "_")
|
||||
.toLowerCase().replaceAll("[^A-Za-z0-9]", "_");
|
||||
// TO LOWERCASE FOR CKAN SUPPORTING
|
||||
return name.toLowerCase();
|
||||
}
|
||||
|
||||
//TO TEST
|
||||
// public static void main(String[] args) throws UnsupportedEncodingException {
|
||||
// TO TEST
|
||||
// public static void main(String[] args) throws UnsupportedEncodingException {
|
||||
//
|
||||
// String remainPathParthenosURL = "Culturalitalia/unknown/Dataset/oai%3Aculturaitalia.it%3Aoai%3Aculturaitalia.it%3Amuseiditalia-mus_11953";
|
||||
// System.out.println(URLDecoder.decode(remainPathParthenosURL, "UTF-8"));
|
||||
// String remainPathParthenosURL =
|
||||
// "Culturalitalia/unknown/Dataset/oai%3Aculturaitalia.it%3Aoai%3Aculturaitalia.it%3Amuseiditalia-mus_11953";
|
||||
// System.out.println(URLDecoder.decode(remainPathParthenosURL, "UTF-8"));
|
||||
//
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -19,11 +19,15 @@ import org.gcube.datatransfer.resolver.util.ValidateContentDisposition;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Oct 22, 2018
|
||||
* The SMPIDResolver is able to give HTTP resolution to storage resource by ID.
|
||||
*
|
||||
* See more at
|
||||
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#SMP-ID_Resolver
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Mar 24, 2022
|
||||
*/
|
||||
@Path("id")
|
||||
public class SMPIDResolver {
|
||||
|
@ -37,54 +41,54 @@ public class SMPIDResolver {
|
|||
|
||||
private static Logger logger = LoggerFactory.getLogger(SMPIDResolver.class);
|
||||
|
||||
|
||||
/**
|
||||
* Gets the smpid.
|
||||
*
|
||||
* @param req the req
|
||||
* @param smpId the smp id
|
||||
* @param fileName the file name
|
||||
* @param contentType the content type
|
||||
* @param validation the validation
|
||||
* @param req the req
|
||||
* @param smpId the smp id
|
||||
* @param fileName the file name
|
||||
* @param contentType the content type
|
||||
* @param contentDisposition the content disposition
|
||||
* @param validation the validation
|
||||
* @return the smpid
|
||||
* @throws WebApplicationException the web application exception
|
||||
*/
|
||||
@GET
|
||||
@Path("")
|
||||
public Response getSMPID(@Context HttpServletRequest req,
|
||||
@QueryParam(SMP_ID) @Nullable String smpId,
|
||||
@QueryParam(ConstantsResolver.QUERY_PARAM_FILE_NAME) String fileName,
|
||||
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENT_TYPE) String contentType,
|
||||
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION) String contentDisposition,
|
||||
@QueryParam(ConstantsResolver.QUERY_PARAM_VALIDATION) boolean validation) throws WebApplicationException{
|
||||
|
||||
logger.info(this.getClass().getSimpleName()+" GET starts...");
|
||||
public Response getSMPID(@Context HttpServletRequest req, @QueryParam(SMP_ID) @Nullable String smpId,
|
||||
@QueryParam(ConstantsResolver.QUERY_PARAM_FILE_NAME) String fileName,
|
||||
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENT_TYPE) String contentType,
|
||||
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION) String contentDisposition,
|
||||
@QueryParam(ConstantsResolver.QUERY_PARAM_VALIDATION) boolean validation) throws WebApplicationException {
|
||||
|
||||
try{
|
||||
//Checking mandatory parameter smpId
|
||||
if(smpId==null || smpId.isEmpty()){
|
||||
logger.error(SMP_ID+" not found");
|
||||
throw ExceptionManager.badRequestException(req, "Missing mandatory parameter "+SMP_ID, SMPIDResolver.class, helpURI);
|
||||
logger.info(this.getClass().getSimpleName() + " GET starts...");
|
||||
|
||||
try {
|
||||
// Checking mandatory parameter smpId
|
||||
if (smpId == null || smpId.isEmpty()) {
|
||||
logger.error(SMP_ID + " not found");
|
||||
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;
|
||||
//Validating the Content-Disposition value
|
||||
// Validating the Content-Disposition value
|
||||
dispositionValue = ValidateContentDisposition.validValue(req, this.getClass(), helpURI, contentDisposition);
|
||||
|
||||
return StorageIDResolver.resolveStorageId(req, smpId, fileName, contentType, dispositionValue, validation);
|
||||
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
|
||||
if(!(e instanceof WebApplicationException)){
|
||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error occurred on resolving the "+SMP_ID+": "+smpId+". Please, contact the support!";
|
||||
if(e.getCause()!=null)
|
||||
error+="\n\nCaused: "+e.getCause().getMessage();
|
||||
if (!(e instanceof WebApplicationException)) {
|
||||
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error occurred on resolving the " + SMP_ID + ": " + smpId
|
||||
+ ". Please, contact the support!";
|
||||
if (e.getCause() != null)
|
||||
error += "\n\nCaused: " + e.getCause().getMessage();
|
||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||
}
|
||||
//ALREADY MANAGED AS WebApplicationException
|
||||
// ALREADY MANAGED AS WebApplicationException
|
||||
logger.error("Exception:", e);
|
||||
throw (WebApplicationException) e;
|
||||
}
|
||||
|
|
|
@ -19,12 +19,15 @@ import org.gcube.datatransfer.resolver.util.ValidateContentDisposition;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* The Class SMPResolver.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Dec 14, 2018
|
||||
* The SMPResolver is able to give HTTP resolution to SMP protocol URIs
|
||||
*
|
||||
* See more at
|
||||
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#SMP_Resolver
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Mar 24, 2022
|
||||
*/
|
||||
@Path("smp")
|
||||
public class SMPResolver {
|
||||
|
@ -41,48 +44,48 @@ public class SMPResolver {
|
|||
/**
|
||||
* Gets the smpuri.
|
||||
*
|
||||
* @param req the req
|
||||
* @param smpURI the smp uri
|
||||
* @param fileName the file name
|
||||
* @param contentType the content type
|
||||
* @param validation the validation
|
||||
* @param req the req
|
||||
* @param smpURI the smp uri
|
||||
* @param fileName the file name
|
||||
* @param contentType the content type
|
||||
* @param contentDisposition the content disposition
|
||||
* @param validation the validation
|
||||
* @return the smpuri
|
||||
* @throws WebApplicationException the web application exception
|
||||
*/
|
||||
@GET
|
||||
@Path("")
|
||||
public Response getSMPURI(@Context HttpServletRequest req,
|
||||
@QueryParam(SMP_URI) @Nullable
|
||||
String smpURI,
|
||||
@QueryParam(ConstantsResolver.QUERY_PARAM_FILE_NAME) String fileName,
|
||||
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENT_TYPE) String contentType,
|
||||
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION) String contentDisposition,
|
||||
@QueryParam(ConstantsResolver.QUERY_PARAM_VALIDATION) boolean validation) throws WebApplicationException{
|
||||
public Response getSMPURI(@Context HttpServletRequest req, @QueryParam(SMP_URI) @Nullable String smpURI,
|
||||
@QueryParam(ConstantsResolver.QUERY_PARAM_FILE_NAME) String fileName,
|
||||
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENT_TYPE) String contentType,
|
||||
@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{
|
||||
//Checking mandatory parameter smpURI
|
||||
if(smpURI==null || smpURI.isEmpty()){
|
||||
logger.error(SMP_URI+" not found");
|
||||
throw ExceptionManager.badRequestException(req, "Missing mandatory parameter "+SMP_URI, SMPResolver.class, helpURI);
|
||||
try {
|
||||
// Checking mandatory parameter smpURI
|
||||
if (smpURI == null || smpURI.isEmpty()) {
|
||||
logger.error(SMP_URI + " not found");
|
||||
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;
|
||||
//Validating the Content-Disposition value
|
||||
// Validating the Content-Disposition value
|
||||
dispositionValue = ValidateContentDisposition.validValue(req, this.getClass(), helpURI, contentDisposition);
|
||||
|
||||
return StorageIDResolver.resolveStorageId(req, smpURI, fileName, contentType, dispositionValue, validation);
|
||||
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
|
||||
if(!(e instanceof WebApplicationException)){
|
||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error occurred on resolving the smpURI "+smpURI+". Please, contact the support!";
|
||||
if (!(e instanceof WebApplicationException)) {
|
||||
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error occurred on resolving the smpURI " + smpURI + ". Please, contact the support!";
|
||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||
}
|
||||
//ALREADY MANAGED AS WebApplicationException
|
||||
// ALREADY MANAGED AS WebApplicationException
|
||||
logger.error("Exception:", e);
|
||||
throw (WebApplicationException) e;
|
||||
}
|
||||
|
|
|
@ -25,10 +25,14 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Class StorageHubResolver.
|
||||
*
|
||||
* The StorageHubResolver provides the methods either to download a gCube
|
||||
* Workspace file or to get its metadata.
|
||||
*
|
||||
* See more at
|
||||
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#STORAGE-HUB_Resolver
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Dec 14, 2018
|
||||
* Dec 14, 2018
|
||||
*/
|
||||
@Path("shub")
|
||||
public class StorageHubResolver {
|
||||
|
@ -46,7 +50,6 @@ public class StorageHubResolver {
|
|||
@PathParam(STORAGE_HUB_ID)
|
||||
String id;
|
||||
|
||||
|
||||
/**
|
||||
* Gets the metadata.
|
||||
*
|
||||
|
@ -56,45 +59,47 @@ public class StorageHubResolver {
|
|||
@HEAD
|
||||
@Path("/{id}")
|
||||
public Response getMetadata(@Context HttpServletRequest req) {
|
||||
logger.info(this.getClass().getSimpleName()+" HEAD getMetadata called");
|
||||
logger.info(this.getClass().getSimpleName() + " HEAD getMetadata called");
|
||||
|
||||
try{
|
||||
//TODO Do we need to check the token?
|
||||
try {
|
||||
// TODO Do we need to check the token?
|
||||
|
||||
//Checking mandatory parameter id
|
||||
if(id==null || id.isEmpty()){
|
||||
logger.error("Path Parameter "+STORAGE_HUB_ID+" not found");
|
||||
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter "+STORAGE_HUB_ID, this.getClass(), help);
|
||||
// Checking mandatory parameter id
|
||||
if (id == null || id.isEmpty()) {
|
||||
logger.error("Path Parameter " + STORAGE_HUB_ID + " not found");
|
||||
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter " + STORAGE_HUB_ID,
|
||||
this.getClass(), help);
|
||||
}
|
||||
|
||||
try{
|
||||
try {
|
||||
|
||||
ItemManagerClient client = AbstractPlugin.item().build();
|
||||
StreamDescriptor descriptor = client.resolvePublicLink(id);
|
||||
ResponseBuilder response = Response.ok();
|
||||
response = new StorageHubMetadataResponseBuilder(req, response).fillMetadata(descriptor, id, CONTENT_DISPOSITION_VALUE.attachment);
|
||||
response = new StorageHubMetadataResponseBuilder(req, response).fillMetadata(descriptor, id,
|
||||
CONTENT_DISPOSITION_VALUE.attachment);
|
||||
return response.build();
|
||||
|
||||
}catch(Exception e){
|
||||
logger.error("Error on getting metadata for file with "+id, e);
|
||||
String errorMsg = "Error on getting metadata for file with hub id '"+id+"'. "+e.getMessage();
|
||||
} catch (Exception e) {
|
||||
logger.error("Error on getting metadata for file with " + id, e);
|
||||
String errorMsg = "Error on getting metadata for file with hub id '" + id + "'. " + e.getMessage();
|
||||
throw ExceptionManager.internalErrorException(req, errorMsg, this.getClass(), help);
|
||||
}
|
||||
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
|
||||
if(!(e instanceof WebApplicationException)){
|
||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error occurred on resolving the StorageHub URL with id: "+id+". Please, contact the support!";
|
||||
if (!(e instanceof WebApplicationException)) {
|
||||
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error occurred on resolving the StorageHub URL with id: " + id
|
||||
+ ". Please, contact the support!";
|
||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), help);
|
||||
}
|
||||
//ALREADY MANAGED as WebApplicationException
|
||||
// ALREADY MANAGED as WebApplicationException
|
||||
logger.error("Exception:", e);
|
||||
throw (WebApplicationException) e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Download.
|
||||
*
|
||||
|
@ -103,46 +108,50 @@ public class StorageHubResolver {
|
|||
*/
|
||||
@GET
|
||||
@Path("/{id}")
|
||||
public Response download(@Context HttpServletRequest req, @QueryParam(ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION) String contentDisposition) {
|
||||
logger.info(this.getClass().getSimpleName()+" GET download called");
|
||||
public Response download(@Context HttpServletRequest req,
|
||||
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION) String contentDisposition) {
|
||||
logger.info(this.getClass().getSimpleName() + " GET download called");
|
||||
|
||||
try{
|
||||
try {
|
||||
InnerMethodName.instance.set("resolveStorageHubPublicLink");
|
||||
|
||||
//Checking mandatory parameter "id"
|
||||
if(id==null || id.isEmpty()){
|
||||
logger.error("Path Parameter "+STORAGE_HUB_ID+" not found");
|
||||
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter "+STORAGE_HUB_ID, StorageHubResolver.class, help);
|
||||
// Checking mandatory parameter "id"
|
||||
if (id == null || id.isEmpty()) {
|
||||
logger.error("Path Parameter " + STORAGE_HUB_ID + " not found");
|
||||
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter " + STORAGE_HUB_ID,
|
||||
StorageHubResolver.class, help);
|
||||
}
|
||||
|
||||
//Checking the optional parameter "Content-Disposition"
|
||||
|
||||
// Checking the optional parameter "Content-Disposition"
|
||||
CONTENT_DISPOSITION_VALUE dispositionValue = CONTENT_DISPOSITION_VALUE.attachment;
|
||||
//Validating the Content-Disposition value
|
||||
// Validating the Content-Disposition value
|
||||
dispositionValue = ValidateContentDisposition.validValue(req, this.getClass(), help, contentDisposition);
|
||||
|
||||
try{
|
||||
try {
|
||||
|
||||
ItemManagerClient client = AbstractPlugin.item().build();
|
||||
StreamDescriptor descriptor = client.resolvePublicLink(id);
|
||||
ResponseBuilder response = Response.ok(descriptor.getStream());
|
||||
|
||||
response = new StorageHubMetadataResponseBuilder(req, response).fillMetadata(descriptor, id, dispositionValue);
|
||||
response = new StorageHubMetadataResponseBuilder(req, response).fillMetadata(descriptor, id,
|
||||
dispositionValue);
|
||||
return response.build();
|
||||
|
||||
}catch(Exception e){
|
||||
logger.error("Error on getting file with "+id, e);
|
||||
String errorMsg = "Error on getting file with hub id '"+id+"'. "+e.getMessage();
|
||||
} catch (Exception e) {
|
||||
logger.error("Error on getting file with " + id, e);
|
||||
String errorMsg = "Error on getting file with hub id '" + id + "'. " + e.getMessage();
|
||||
throw ExceptionManager.internalErrorException(req, errorMsg, StorageHubResolver.class, help);
|
||||
}
|
||||
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
|
||||
if(!(e instanceof WebApplicationException)){
|
||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error occurred on resolving the StorageHub URL with id: "+id+". Please, contact the support!";
|
||||
if (!(e instanceof WebApplicationException)) {
|
||||
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error occurred on resolving the StorageHub URL with id: " + id
|
||||
+ ". Please, contact the support!";
|
||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), help);
|
||||
}
|
||||
//ALREADY MANAGED AS WebApplicationException
|
||||
// ALREADY MANAGED AS WebApplicationException
|
||||
logger.error("Exception:", 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.CONTENT_DISPOSITION_VALUE;
|
||||
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.util.SingleFileStreamingOutput;
|
||||
import org.gcube.datatransfer.resolver.util.ValidateContentDisposition;
|
||||
|
@ -37,8 +36,11 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
|
||||
/**
|
||||
* The Class StorageIDResolver.
|
||||
*
|
||||
* The StorageIDResolver is able to give HTTP resolution to storage resource by ID
|
||||
*
|
||||
* See more at
|
||||
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#STORAGE-ID_Resolver
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Dec 14, 2018
|
||||
*/
|
||||
|
|
|
@ -20,37 +20,45 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Class UriResolverIndex.
|
||||
*
|
||||
* @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("index")
|
||||
public class UriResolverIndex {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(UriResolverIndex.class);
|
||||
|
||||
/**
|
||||
* Index.
|
||||
*
|
||||
* @param req the req
|
||||
* @return the input stream
|
||||
* @throws WebApplicationException the web application exception
|
||||
*/
|
||||
@GET
|
||||
@Produces({MediaType.TEXT_HTML})
|
||||
@Produces({ MediaType.TEXT_HTML })
|
||||
@Path("")
|
||||
public InputStream index(@Context HttpServletRequest req) throws WebApplicationException{
|
||||
public InputStream index(@Context HttpServletRequest req) throws WebApplicationException {
|
||||
|
||||
String indexFile = "/WEB-INF/jsp/index.jsp";
|
||||
|
||||
try{
|
||||
logger.info(UriResolverIndex.class.getSimpleName() +" called");
|
||||
String realPath = req.getServletContext().getRealPath(indexFile);
|
||||
return new FileInputStream(new File(realPath));
|
||||
}catch (Exception e) {
|
||||
try {
|
||||
logger.info(UriResolverIndex.class.getSimpleName() + " 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
|
||||
if (!(e instanceof WebApplicationException)) {
|
||||
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Index.jsp not found. Please, contact the support!";
|
||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), null);
|
||||
}
|
||||
//ALREADY MANAGED AS WebApplicationException
|
||||
// ALREADY MANAGED AS WebApplicationException
|
||||
logger.error("Exception:", e);
|
||||
throw (WebApplicationException) e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,18 +14,26 @@ import javax.ws.rs.core.Context;
|
|||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
/**
|
||||
* The UriResolverInfo get index.
|
||||
*
|
||||
* @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("info")
|
||||
public class UriResolverInfo {
|
||||
|
||||
/**
|
||||
* Info.
|
||||
*
|
||||
* @param req the req
|
||||
* @return the input stream
|
||||
* @throws WebApplicationException the web application exception
|
||||
*/
|
||||
@GET
|
||||
@Produces({MediaType.TEXT_HTML})
|
||||
@Produces({ MediaType.TEXT_HTML })
|
||||
@Path("")
|
||||
public InputStream info(@Context HttpServletRequest req) throws WebApplicationException{
|
||||
public InputStream info(@Context HttpServletRequest req) throws WebApplicationException {
|
||||
return new UriResolverIndex().index(req);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,12 +20,12 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
/**
|
||||
* The Class ResourceListingResource.
|
||||
* The UriResolverResources. Show the resources as a JSON
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Feb 14, 2019
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Mar 24, 2022
|
||||
*/
|
||||
@Path("resources")
|
||||
@Singleton
|
||||
|
@ -37,7 +37,7 @@ public class UriResolverResources {
|
|||
* Show all.
|
||||
*
|
||||
* @param application the application
|
||||
* @param request the request
|
||||
* @param request the request
|
||||
* @return the response
|
||||
*/
|
||||
@GET
|
||||
|
|
|
@ -35,26 +35,27 @@ import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* The Class WekeoResolver.
|
||||
* The WekeoResolver provides a method to wrap the basic authentication from
|
||||
* D4Science account to WekeoBroker service.
|
||||
*
|
||||
* See more at
|
||||
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Wekeo_Resolver
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Mar 30, 2021
|
||||
* Mar 24, 2022
|
||||
*/
|
||||
@Path("wekeo")
|
||||
public class WekeoResolver {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(WekeoResolver.class);
|
||||
|
||||
|
||||
private final static String RUNTIME_WKEO_RESOURCE_NAME = "WekeoDataBroker";
|
||||
private final static String CATEGORY_WEKEO_TYPE = "OnlineService";
|
||||
|
||||
private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#Wekeo_Resolver";
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the token.
|
||||
*
|
||||
|
@ -65,23 +66,25 @@ public class WekeoResolver {
|
|||
@GET
|
||||
@Path("/gettoken")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getToken(@Context HttpServletRequest req) throws WebApplicationException{
|
||||
|
||||
logger.info(this.getClass().getSimpleName()+" getToken starts...");
|
||||
|
||||
public Response getToken(@Context HttpServletRequest req) throws WebApplicationException {
|
||||
|
||||
logger.info(this.getClass().getSimpleName() + " getToken starts...");
|
||||
|
||||
try {
|
||||
|
||||
|
||||
String contextToken = SecurityTokenProvider.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);
|
||||
|
||||
if(contextToken.compareTo(appToken)==0){
|
||||
logger.error("Token not passed, SecurityTokenProvider contains the root app token: "+appToken.substring(0,10)+"...");
|
||||
throw ExceptionManager.unauthorizedException(req, "You are not authorized. You must pass a token of VRE", this.getClass(), helpURI);
|
||||
if (contextToken.compareTo(appToken) == 0) {
|
||||
logger.error("Token not passed, SecurityTokenProvider contains the root app token: "
|
||||
+ 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();
|
||||
AccessPoint wekeoAccessPoint = WekeoResolver.readWekeoServiceEndpoint(req, scope);
|
||||
|
||||
|
@ -98,12 +101,12 @@ public class WekeoResolver {
|
|||
logger.debug(msg);
|
||||
}
|
||||
|
||||
logger.info("The pwd is: "+wekeoPwd);
|
||||
logger.info("The pwd is: " + wekeoPwd);
|
||||
// decrypting the pwd
|
||||
if (wekeoPwd != null) {
|
||||
wekeoPwd = StringEncrypter.getEncrypter().decrypt(wekeoPwd);
|
||||
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) {
|
||||
|
@ -117,18 +120,18 @@ public class WekeoResolver {
|
|||
String authStringEnc = new String(authEncBytes);
|
||||
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);
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setDoOutput(true);
|
||||
connection.setRequestProperty("Authorization", "Basic " + authStringEnc);
|
||||
|
||||
|
||||
content = (InputStream) connection.getInputStream();
|
||||
in = new InputStreamReader(content);
|
||||
|
||||
logger.info("the response code is: "+connection.getResponseCode());
|
||||
|
||||
|
||||
logger.info("the response code is: " + connection.getResponseCode());
|
||||
|
||||
int numCharsRead;
|
||||
char[] charArray = new char[1024];
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
@ -137,7 +140,7 @@ public class WekeoResolver {
|
|||
sb.append(charArray, 0, numCharsRead);
|
||||
}
|
||||
wekeoResponse.append(sb.toString());
|
||||
//System.out.println(wekeoResponse);
|
||||
// System.out.println(wekeoResponse);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
|
@ -145,12 +148,12 @@ public class WekeoResolver {
|
|||
throw new Exception(error);
|
||||
} finally {
|
||||
try {
|
||||
if (content!= null && in != null) {
|
||||
if (content != null && in != null) {
|
||||
in.close();
|
||||
content.close();
|
||||
}
|
||||
}catch (Exception e) {
|
||||
//silent
|
||||
} catch (Exception e) {
|
||||
// silent
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -164,72 +167,83 @@ public class WekeoResolver {
|
|||
|
||||
// to be sure
|
||||
if (wekeoResponse.length() == 0) {
|
||||
String error = String
|
||||
.format("Sorry an error occured on getting the access token from Wekeo. Please, retry the request");
|
||||
String error = String.format(
|
||||
"Sorry an error occured on getting the access token from Wekeo. Please, retry the request");
|
||||
throw new Exception(error);
|
||||
}
|
||||
|
||||
|
||||
String theResponse = wekeoResponse.toString();
|
||||
logger.info("returning: \n"+theResponse);
|
||||
|
||||
logger.info("returning: \n" + theResponse);
|
||||
|
||||
return Response.ok(theResponse).build();
|
||||
}catch (Exception e) {
|
||||
//ALREADY MANAGED AS WebApplicationException
|
||||
} catch (Exception e) {
|
||||
// ALREADY MANAGED AS WebApplicationException
|
||||
logger.error("Exception:", e);
|
||||
throw (WebApplicationException) e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Index.
|
||||
*
|
||||
* @param req the req
|
||||
* @return the input stream
|
||||
* @throws WebApplicationException the web application exception
|
||||
*/
|
||||
@GET
|
||||
@Produces({MediaType.TEXT_HTML})
|
||||
@Produces({ MediaType.TEXT_HTML })
|
||||
@Path("")
|
||||
public InputStream index(@Context HttpServletRequest req) throws WebApplicationException{
|
||||
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) {
|
||||
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
|
||||
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
|
||||
// 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}
|
||||
* Reads the wekeo endpoint information from IS. {The SE name is: @link
|
||||
* WekeoResolver#RUNTIME_WKEO_RESOURCE_NAME}
|
||||
*
|
||||
* @param req the req
|
||||
* @param req the req
|
||||
* @param scope the scope
|
||||
* @return the string
|
||||
*/
|
||||
public static AccessPoint readWekeoServiceEndpoint(HttpServletRequest req, String scope){
|
||||
public static AccessPoint readWekeoServiceEndpoint(HttpServletRequest req, String scope) {
|
||||
|
||||
String callerScope = null;
|
||||
try{
|
||||
try {
|
||||
callerScope = ScopeProvider.instance.get();
|
||||
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);
|
||||
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/Name/text() eq '" + RUNTIME_WKEO_RESOURCE_NAME + "'");
|
||||
query.addCondition("$resource/Profile/Category/text() eq '" + CATEGORY_WEKEO_TYPE + "'");
|
||||
|
||||
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
||||
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){
|
||||
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());
|
||||
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());
|
||||
logger.error(errorMessage);
|
||||
throw ExceptionManager.notFoundException(req, errorMessage, WekeoResolver.class, helpURI);
|
||||
|
||||
|
@ -237,34 +251,35 @@ public class WekeoResolver {
|
|||
|
||||
String wekeoUsername = null;
|
||||
String wekeoPwd = null;
|
||||
|
||||
|
||||
ServiceEndpoint se = toReturn.get(0);
|
||||
Collection<AccessPoint> theAccessPoints = se.profile().accessPoints().asCollection();
|
||||
for (AccessPoint accessPoint : theAccessPoints) {
|
||||
wekeoUsername = accessPoint.username();
|
||||
wekeoPwd = accessPoint.password();
|
||||
if(wekeoUsername!=null && wekeoPwd!=null) {
|
||||
logger.info("returning the access point with name: "+accessPoint.name());
|
||||
if (wekeoUsername != null && wekeoPwd != null) {
|
||||
logger.info("returning the access point with name: " + accessPoint.name());
|
||||
return accessPoint;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
|
||||
}catch(Exception e){
|
||||
|
||||
if(e instanceof NotFoundException)
|
||||
} catch (Exception e) {
|
||||
|
||||
if (e instanceof NotFoundException)
|
||||
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);
|
||||
throw ExceptionManager.internalErrorException(req, errorMessage, WekeoResolver.class, helpURI);
|
||||
|
||||
}finally{
|
||||
if(callerScope!=null){
|
||||
logger.info("Setting to the callerScope scope: "+callerScope);
|
||||
} finally {
|
||||
if (callerScope != null) {
|
||||
logger.info("Setting to the callerScope scope: " + callerScope);
|
||||
ScopeProvider.instance.set(callerScope);
|
||||
}else{
|
||||
} else {
|
||||
logger.info("Reset scope");
|
||||
ScopeProvider.instance.reset();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
|
||||
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
|
||||
bean-discovery-mode="all">
|
||||
</beans>
|
File diff suppressed because it is too large
Load Diff
|
@ -6,4 +6,5 @@
|
|||
<include>/analytics/create/*</include>
|
||||
<include>/knime/create/*</include>
|
||||
<include>/wekeo/gettoken/*</include>
|
||||
<include>/oat/get/*</include>
|
||||
</application>
|
|
@ -18,11 +18,11 @@ body {
|
|||
height: 300px;
|
||||
margin-top: -150px; /*set to a negative number 1/2 of your height*/
|
||||
margin-left: -300px; /*set to a negative number 1/2 of your width*/
|
||||
/* border: 1px solid #ccc; */
|
||||
/* border: 1px solid #ccc; */
|
||||
/* background-color: #9b9b9b; */
|
||||
position: fixed;
|
||||
text-align: center;
|
||||
/* vertical-align: middle; */
|
||||
/* vertical-align: middle; */
|
||||
}
|
||||
|
||||
.myTitle {
|
||||
|
@ -39,8 +39,13 @@ body {
|
|||
<div class="myTitle">The URI Resolver</div>
|
||||
<p>
|
||||
See wiki page at <a
|
||||
href="https://gcube.wiki.gcube-system.org/gcube/index.php/URI_Resolver" target="_blank">gCube Wiki URI
|
||||
Resolver</a>
|
||||
href="https://gcube.wiki.gcube-system.org/gcube/index.php/URI_Resolver"
|
||||
target="_blank">gCube Wiki URI Resolver</a>
|
||||
</p>
|
||||
<p>
|
||||
See API documentation at <a
|
||||
href="docs/index.html"
|
||||
target="_blank">URI Resolver API</a>
|
||||
</p>
|
||||
</div>
|
||||
</body>
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
.d4science_intro {
|
||||
top: 0;
|
||||
z-index: 2000;
|
||||
position: fixed;
|
||||
display: block ruby;
|
||||
padding: 10px;
|
||||
background: white;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.navbar-fixed-top {
|
||||
top: 100px !important;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
top: 160px !important;
|
||||
}
|
||||
|
||||
.navbar {
|
||||
margin-bottom: 40px !important;
|
||||
}
|
||||
|
||||
.main {
|
||||
top: 90px;
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
package org.gcube.datatransfer.test;
|
||||
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.gcube.common.encryption.StringEncrypter;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.datatransfer.resolver.services.exceptions.NotFoundException;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
|
||||
/**
|
||||
* The Class ServiceEndpointReader.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Jan 27, 2022
|
||||
*/
|
||||
public class ServiceEndpointReader {
|
||||
|
||||
private static final String RESOURCE_NAME = "DEV Geoserver";
|
||||
private static final String CATEGORY_NAME = "Gis";
|
||||
private static final String SCOPE = "/gcube/devsec/devVRE";
|
||||
|
||||
public static Logger LOG = Logger.getLogger(ServiceEndpointReader.class);
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
readServiceEndpoint(SCOPE);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Read service endpoint.
|
||||
*
|
||||
* @param req the req
|
||||
* @param scope the scope
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void readServiceEndpoint(String scope) throws Exception{
|
||||
|
||||
String callerScope = null;
|
||||
try{
|
||||
callerScope = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(scope);
|
||||
LOG.info("Searching SE "+RESOURCE_NAME +" configurations in the scope: "+ScopeProvider.instance.get());
|
||||
|
||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||
query.addCondition("$resource/Profile/Name/text() eq '"+ RESOURCE_NAME +"'");
|
||||
query.addCondition("$resource/Profile/Category/text() eq '"+ CATEGORY_NAME +"'");
|
||||
|
||||
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
||||
List<ServiceEndpoint> toReturn = client.submit(query);
|
||||
|
||||
LOG.info("The query returned "+toReturn.size()+ " ServiceEndpoint/s");
|
||||
|
||||
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.",RESOURCE_NAME,CATEGORY_NAME,ScopeProvider.instance.get());
|
||||
LOG.error(errorMessage);
|
||||
throw new Exception(errorMessage);
|
||||
|
||||
}
|
||||
|
||||
String accessPointUsername = null;
|
||||
String accessPointPwd = null;
|
||||
|
||||
ServiceEndpoint se = toReturn.get(0);
|
||||
Collection<AccessPoint> theAccessPoints = se.profile().accessPoints().asCollection();
|
||||
for (AccessPoint accessPoint : theAccessPoints) {
|
||||
accessPointUsername = accessPoint.username();
|
||||
System.out.println("AccessPoint username: "+accessPointPwd);
|
||||
accessPointPwd = accessPoint.password();
|
||||
if(accessPointUsername!=null && accessPointPwd!=null) {
|
||||
LOG.info("returning the access point with name: "+accessPoint.name());
|
||||
if (accessPointPwd != null) {
|
||||
accessPointPwd = StringEncrypter.getEncrypter().decrypt(accessPointPwd);
|
||||
LOG.info("Decrypted pwd registered into Access Point '" + accessPoint.name() + "' is: "
|
||||
+ accessPointPwd.substring(0,accessPointPwd.length()/2)+"...");
|
||||
|
||||
System.out.println("AccessPoint pwd is: "+accessPointPwd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}catch(Exception e){
|
||||
|
||||
if(e instanceof NotFoundException)
|
||||
throw e;
|
||||
|
||||
String errorMessage = "Error occurred on reading the "+RESOURCE_NAME+" SE registered in the scope: "+ScopeProvider.instance.get();
|
||||
LOG.error(errorMessage, e);
|
||||
throw new Exception(errorMessage);
|
||||
|
||||
}finally{
|
||||
if(callerScope!=null){
|
||||
LOG.info("Setting to the callerScope scope: "+callerScope);
|
||||
ScopeProvider.instance.set(callerScope);
|
||||
}else{
|
||||
LOG.info("Reset scope");
|
||||
ScopeProvider.instance.reset();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue