Compare commits
51 Commits
feature_23
...
master
10
.classpath
10
.classpath
|
@ -24,16 +24,16 @@
|
|||
<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">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<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>
|
||||
|
|
|
@ -5,7 +5,27 @@
|
|||
|
||||
|
||||
|
||||
<wb-module deploy-name="uri-resolver-2.7.2-SNAPSHOT">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<wb-module deploy-name="uri-resolver-2.9.0">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -19,6 +39,16 @@
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
||||
|
||||
|
||||
|
@ -26,6 +56,16 @@
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
||||
|
||||
|
||||
|
@ -33,6 +73,16 @@
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
|
||||
|
||||
|
||||
|
@ -40,6 +90,16 @@
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<property name="context-root" value="uri-resolver"/>
|
||||
|
||||
|
||||
|
@ -47,6 +107,16 @@
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<property name="java-output-path" value="/uri-resolver/target/classes"/>
|
||||
|
||||
|
||||
|
@ -54,6 +124,16 @@
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</wb-module>
|
||||
|
||||
|
||||
|
@ -61,4 +141,14 @@
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</project-modules>
|
||||
|
|
29
CHANGELOG.md
29
CHANGELOG.md
|
@ -4,7 +4,28 @@
|
|||
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] - 2022-04-06
|
||||
## [v2.9.0]
|
||||
|
||||
- GeoPortal-Resolver implemented [#24792]
|
||||
|
||||
## [v2.8.1] - 2022-06-13
|
||||
|
||||
**New**
|
||||
|
||||
- [#23156] CatalogueResolver enhanced to manage (create/resolve) an input query string
|
||||
|
||||
**Bug Fixing**
|
||||
|
||||
- [#23495] Removed the check on the gcube token stored in thread local. The working context of VRE will be checked from ScopeProvider
|
||||
|
||||
|
||||
## [v2.7.3-SNAPSHOT] - 2022-04-27
|
||||
|
||||
**Bug Fixing**
|
||||
|
||||
- [#23213] Fixed NoClassDefFoundError: org/geotoolkit/xml/XML
|
||||
|
||||
## [v2.7.2] - 2022-04-06
|
||||
|
||||
**New**
|
||||
|
||||
|
@ -18,7 +39,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
|
||||
- [#20743] Integration with javamelody
|
||||
|
||||
## [v2-6-1] - 2022-01-17
|
||||
## [v2.6.1] - 2022-01-17
|
||||
|
||||
**New features**
|
||||
|
||||
|
@ -30,7 +51,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
- [#21560] Checking the bug fix done
|
||||
- Moved to gcube-smartgears-bom.2.1.0
|
||||
|
||||
## [v2-5-0] - 2021-04-08
|
||||
## [v2.5.0] - 2021-04-08
|
||||
|
||||
**New features**
|
||||
|
||||
|
@ -41,7 +62,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
[#21093] StorageHubResolver HEAD request does not support Content-Length
|
||||
|
||||
|
||||
## [v2-4-1] - 2021-01-13
|
||||
## [v2.4.1] - 2021-01-13
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
|
|
|
@ -10,11 +10,17 @@
|
|||
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.OatResolver" />
|
||||
<exclude
|
||||
pattern="org.gcube.datatransfer.resolver.services.tobackward.BackCatalogueResolver" />
|
||||
<exclude
|
||||
pattern="org.gcube.datatransfer.resolver.services.tobackward.BackUriResolverCatalogueResolver" />
|
||||
|
||||
<exclude pattern="org.geotoolkit.internal.jaxb.referencing.*" />
|
||||
|
||||
<exclude pattern="org.opengis.metadata.*" />
|
||||
|
||||
</api-classes>
|
||||
|
||||
<modules>
|
||||
|
|
37
pom.xml
37
pom.xml
|
@ -9,7 +9,7 @@
|
|||
</parent>
|
||||
<groupId>org.gcube.data.transfer</groupId>
|
||||
<artifactId>uri-resolver</artifactId>
|
||||
<version>2.7.2</version>
|
||||
<version>2.9.0</version>
|
||||
<packaging>war</packaging>
|
||||
<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>
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-smartgears-bom</artifactId>
|
||||
<version>2.1.0</version>
|
||||
<version>2.4.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
@ -193,6 +193,22 @@
|
|||
<version>1.14.8</version>
|
||||
</dependency>
|
||||
|
||||
<!-- FOR BUILDING towards JDK_11 -->
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- FOR BUILDING towards JDK_11 -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- GIS RESOLVER DEPENDENCIES -->
|
||||
<dependency>
|
||||
|
@ -202,6 +218,15 @@
|
|||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- THIS ONE IS NOT A DIRECT DEPENDENCY OF URI-RESOLVER IT IS REQUIRED
|
||||
TO BUILD -->
|
||||
<dependency>
|
||||
<groupId>org.opengis</groupId>
|
||||
<artifactId>geoapi</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
|
@ -250,14 +275,6 @@
|
|||
<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>
|
||||
|
|
|
@ -5,15 +5,14 @@ package org.gcube.datatransfer.resolver.catalogue;
|
|||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Mar 24, 2022
|
||||
*
|
||||
* Binding Catalogue Request as a JSON
|
||||
* Apr 20, 2022
|
||||
*/
|
||||
public class CatalogueRequest {
|
||||
|
||||
private String gcube_scope;
|
||||
private String entity_context;
|
||||
private String entity_name;
|
||||
private String query_string;
|
||||
|
||||
/**
|
||||
* Gets the gcube_scope.
|
||||
|
@ -42,19 +41,22 @@ public class CatalogueRequest {
|
|||
return entity_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the query string.
|
||||
*
|
||||
* @return the query string
|
||||
*/
|
||||
public String getQuery_string() {
|
||||
return query_string;
|
||||
}
|
||||
|
||||
/**
|
||||
* To string.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("CatalogueRequest [gcube_scope=");
|
||||
builder.append(gcube_scope);
|
||||
|
@ -62,6 +64,8 @@ public class CatalogueRequest {
|
|||
builder.append(entity_context);
|
||||
builder.append(", entity_name=");
|
||||
builder.append(entity_name);
|
||||
builder.append(", query_string=");
|
||||
builder.append(query_string);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
|
|
@ -3,28 +3,27 @@
|
|||
*/
|
||||
package org.gcube.datatransfer.resolver.catalogue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* The Enum ResourceCatalogueCodes.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Jan 31, 2017
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jan 31, 2017
|
||||
*
|
||||
* see wiki page: https://wiki.gcube-system.org/gcube/URI_Resolver#CATALOGUE_Resolver
|
||||
* see wiki page:
|
||||
* https://wiki.gcube-system.org/gcube/URI_Resolver#CATALOGUE_Resolver
|
||||
*/
|
||||
public enum ResourceCatalogueCodes {
|
||||
|
||||
CTLG("ctlg","dataset", "Catalogue Product/Dataset"),
|
||||
//CTLGP("ctlg-p","product", "Catalogue Product"),
|
||||
CTLGD("ctlg-d","dataset", "Catalogue Dataset"),
|
||||
CTLGO("ctlg-o","organization", "Catalogue Organization"),
|
||||
CTLGG("ctlg-g","group", "Catalogue Group");
|
||||
CTLG("ctlg", "dataset", "Catalogue Product/Dataset"),
|
||||
// CTLGP("ctlg-p","product", "Catalogue Product"),
|
||||
CTLGD("ctlg-d", "dataset", "Catalogue Dataset"), CTLGO("ctlg-o", "organization", "Catalogue Organization"),
|
||||
CTLGG("ctlg-g", "group", "Catalogue Group");
|
||||
|
||||
private String id; //the code id
|
||||
private String value; //the code value
|
||||
private String id; // the code id
|
||||
private String value; // the code value
|
||||
private String description;
|
||||
|
||||
/**
|
||||
|
@ -50,7 +49,6 @@ public enum ResourceCatalogueCodes {
|
|||
return id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the value.
|
||||
*
|
||||
|
@ -61,7 +59,6 @@ public enum ResourceCatalogueCodes {
|
|||
return value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the description.
|
||||
*
|
||||
|
@ -72,40 +69,37 @@ public enum ResourceCatalogueCodes {
|
|||
return description;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Codes.
|
||||
*
|
||||
* @return the list
|
||||
*/
|
||||
public static List<String> codes(){
|
||||
public static List<String> codes() {
|
||||
|
||||
List<String> codes = new ArrayList<String>(ResourceCatalogueCodes.values().length);
|
||||
for (ResourceCatalogueCodes value : ResourceCatalogueCodes.values()) {
|
||||
codes.add(value.getId());
|
||||
return Arrays.asList(ResourceCatalogueCodes.values()).stream().map(ResourceCatalogueCodes::getId)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return codes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Value of code id.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the resource catalogue codes
|
||||
*/
|
||||
public static ResourceCatalogueCodes valueOfCodeId(String id){
|
||||
if(id==null || id.isEmpty())
|
||||
public static ResourceCatalogueCodes valueOfCodeId(String id) {
|
||||
if (id == null || id.isEmpty())
|
||||
return null;
|
||||
|
||||
for (ResourceCatalogueCodes value : ResourceCatalogueCodes.values()) {
|
||||
if(value.id.compareTo(id)==0)
|
||||
return value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
List<ResourceCatalogueCodes> codes = Arrays.asList(ResourceCatalogueCodes.values()).stream()
|
||||
.filter(r -> r.getId().compareTo(id) == 0)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (codes == null || codes.isEmpty())
|
||||
return null;
|
||||
|
||||
return codes.get(0);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Value of code value.
|
||||
|
@ -113,14 +107,17 @@ public enum ResourceCatalogueCodes {
|
|||
* @param codeValue the code value
|
||||
* @return the resource catalogue codes
|
||||
*/
|
||||
public static ResourceCatalogueCodes valueOfCodeValue(String codeValue){
|
||||
if(codeValue==null || codeValue.isEmpty())
|
||||
public static ResourceCatalogueCodes valueOfCodeValue(String codeValue) {
|
||||
if (codeValue == null || codeValue.isEmpty())
|
||||
return null;
|
||||
|
||||
for (ResourceCatalogueCodes rcc : ResourceCatalogueCodes.values()) {
|
||||
if(rcc.value.compareTo(codeValue)==0)
|
||||
return rcc;
|
||||
}
|
||||
List<ResourceCatalogueCodes> codes = Arrays.asList(ResourceCatalogueCodes.values()).stream()
|
||||
.filter(r -> r.getValue().compareTo(codeValue) == 0)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (codes == null || codes.isEmpty())
|
||||
return null;
|
||||
|
||||
return codes.get(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,12 +94,12 @@ public class CatalogueStaticConfigurations{
|
|||
if(toPrivateCKANCatalogueURL.startsWith(prefix)) {
|
||||
toPrivateCKANCatalogueURL = toPrivateCKANCatalogueURL.replaceFirst(prefix, ""); //removing prefix
|
||||
String catalogueName = toPrivateCKANCatalogueURL.substring(0,toPrivateCKANCatalogueURL.indexOf(".d4science"));
|
||||
LOG.info("Catalogue Name extration returning value: "+catalogueName);
|
||||
LOG.info("Catalogue Name extraction returning value: "+catalogueName);
|
||||
return catalogueName;
|
||||
}
|
||||
}
|
||||
|
||||
LOG.info("Catalogue Name extration returning null");
|
||||
LOG.info("Catalogue Name extraction returning null");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package org.gcube.datatransfer.resolver.geoportal;
|
||||
|
||||
/**
|
||||
* The Class GeoportalCommonConstants.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Dec 1, 2020
|
||||
*/
|
||||
public class GeoportalCommonConstants {
|
||||
|
||||
public static final String GET_GEONA_ITEM_TYPE = "git";
|
||||
public static final String GET_GEONA_ITEM_ID = "gid";
|
||||
|
||||
public static final String GEOPORTAL_DATA_VIEWER_APP = "geoportal-data-viewer-app";
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package org.gcube.datatransfer.resolver.geoportal;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* The Class GeoportalDataViewerConfigProfile.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Dec 21, 2021
|
||||
*/
|
||||
public class GeoportalDataViewerConfigProfile implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 2968334957258327191L;
|
||||
private String restrictedPortletURL;
|
||||
private String openPortletURL;
|
||||
|
||||
/**
|
||||
* Instantiates a new geo na data viewer profile.
|
||||
*/
|
||||
public GeoportalDataViewerConfigProfile() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the restricted portlet URL.
|
||||
*
|
||||
* @return the restricted portlet URL
|
||||
*/
|
||||
public String getRestrictedPortletURL() {
|
||||
return restrictedPortletURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the restricted portlet URL.
|
||||
*
|
||||
* @param restrictedPortletURL the new restricted portlet URL
|
||||
*/
|
||||
public void setRestrictedPortletURL(String restrictedPortletURL) {
|
||||
this.restrictedPortletURL = restrictedPortletURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the open portlet URL.
|
||||
*
|
||||
* @return the open portlet URL
|
||||
*/
|
||||
public String getOpenPortletURL() {
|
||||
return openPortletURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the open portlet URL.
|
||||
*
|
||||
* @param openPortletURL the new open portlet URL
|
||||
*/
|
||||
public void setOpenPortletURL(String openPortletURL) {
|
||||
this.openPortletURL = openPortletURL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("GeoportalDataViewerConfigProfile [restrictedPortletURL=");
|
||||
builder.append(restrictedPortletURL);
|
||||
builder.append(", openPortletURL=");
|
||||
builder.append(openPortletURL);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,170 @@
|
|||
package org.gcube.datatransfer.resolver.geoportal;
|
||||
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.client;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileNotFoundException;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.Query;
|
||||
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
/**
|
||||
* The Class GeoportalDataViewerConfigProfileReader.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Mar 23, 2023
|
||||
*/
|
||||
public class GeoportalDataViewerConfigProfileReader {
|
||||
|
||||
private static final String RESOURCE_PROFILE_BODY = "/Resource/Profile/Body";
|
||||
public static final String SECONDARY_TYPE = "ApplicationProfile";
|
||||
public static final String GENERIC_RESOURCE_NAME = "Geoportal-DataViewer-Configs";
|
||||
|
||||
private static Logger LOG = LoggerFactory.getLogger(GeoportalDataViewerConfigProfileReader.class);
|
||||
private String secondaryType;
|
||||
private String scope;
|
||||
private String appID;
|
||||
private GeoportalDataViewerConfigProfile geoportalDataViewerConfigProfile;
|
||||
|
||||
/**
|
||||
* Instantiates a new geoportal data viewer config profile reader.
|
||||
*
|
||||
* @param appID the app ID
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public GeoportalDataViewerConfigProfileReader(String appID) throws Exception {
|
||||
|
||||
this.appID = appID;
|
||||
this.secondaryType = SECONDARY_TYPE;
|
||||
this.scope = ScopeProvider.instance.get();
|
||||
this.geoportalDataViewerConfigProfile = readProfileFromInfrastructure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read profile from infrastrucure.
|
||||
*
|
||||
* @return the map
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
private GeoportalDataViewerConfigProfile readProfileFromInfrastructure() throws Exception {
|
||||
|
||||
String queryString = getGcubeGenericQueryString(secondaryType, appID);
|
||||
LOG.info("Scope " + scope + ", trying to perform query: " + queryString);
|
||||
|
||||
try {
|
||||
|
||||
if (scope == null)
|
||||
throw new Exception("Scope is null, set scope into ScopeProvider");
|
||||
|
||||
GeoportalDataViewerConfigProfile profile = new GeoportalDataViewerConfigProfile();
|
||||
|
||||
LOG.info("Trying to fetch ApplicationProfile in the scope: " + scope + ", SecondaryType: " + secondaryType
|
||||
+ ", AppId: " + appID);
|
||||
Query q = new QueryBox(queryString);
|
||||
DiscoveryClient<String> client = client();
|
||||
List<String> appProfile = client.submit(q);
|
||||
// String item_fields = "";
|
||||
|
||||
if (appProfile == null || appProfile.size() == 0)
|
||||
throw new ApplicationProfileNotFoundException("ApplicationProfile with SecondaryType: " + secondaryType
|
||||
+ ", AppId: " + appID + " is not registered in the scope: " + scope);
|
||||
else {
|
||||
String elem = appProfile.get(0);
|
||||
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Document doc = docBuilder.parse(new InputSource(new StringReader(elem)));
|
||||
|
||||
XPathHelper helper = new XPathHelper(doc.getDocumentElement());
|
||||
|
||||
List<String> currValue = null;
|
||||
String xPathExp = RESOURCE_PROFILE_BODY + "/RestrictedPortletURL/text()";
|
||||
currValue = helper.evaluate(xPathExp);
|
||||
if (currValue != null && currValue.size() > 0) {
|
||||
profile.setRestrictedPortletURL(currValue.get(0));
|
||||
} else
|
||||
throw new Exception("I'm not able to read the path: " + xPathExp);
|
||||
|
||||
xPathExp = RESOURCE_PROFILE_BODY + "/OpenPortletURL/text()";
|
||||
currValue = helper.evaluate(xPathExp);
|
||||
if (currValue != null && currValue.size() > 0) {
|
||||
profile.setOpenPortletURL(currValue.get(0));
|
||||
} else
|
||||
throw new Exception("I'm not able to read the path: " + xPathExp);
|
||||
|
||||
LOG.info("returning: " + profile);
|
||||
return profile;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error while trying to read the " + SECONDARY_TYPE + " with SecondaryType "
|
||||
+ GENERIC_RESOURCE_NAME + " from scope " + scope, e);
|
||||
return null;
|
||||
} finally {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public GeoportalDataViewerConfigProfile getGeoportalDataViewerConfigProfile() {
|
||||
return geoportalDataViewerConfigProfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the gcube generic query string.
|
||||
*
|
||||
* @param secondaryType the secondary type
|
||||
* @param appId the app id
|
||||
* @return the gcube generic query string
|
||||
*/
|
||||
public static String getGcubeGenericQueryString(String secondaryType, String appId) {
|
||||
|
||||
return "for $profile in collection('/db/Profiles/GenericResource')//Resource "
|
||||
+ "where $profile/Profile/SecondaryType/string() eq '" + secondaryType
|
||||
+ "' and $profile/Profile/Body/AppId/string() " + " eq '" + appId + "'" + "return $profile";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the secondary type.
|
||||
*
|
||||
* @return the secondary type
|
||||
*/
|
||||
public String getSecondaryType() {
|
||||
return secondaryType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the scope.
|
||||
*
|
||||
* @return the scope
|
||||
*/
|
||||
public String getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("GeoportalDataViewerConfigProfileReader [secondaryType=");
|
||||
builder.append(secondaryType);
|
||||
builder.append(", scope=");
|
||||
builder.append(scope);
|
||||
builder.append(", appID=");
|
||||
builder.append(appID);
|
||||
builder.append(", geoportalDataViewerConfigProfile=");
|
||||
builder.append(geoportalDataViewerConfigProfile);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package org.gcube.datatransfer.resolver.geoportal;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
/**
|
||||
* The Class GeoportalRequest.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Mar 23, 2023
|
||||
*/
|
||||
@Slf4j
|
||||
@Data
|
||||
public class GeoportalRequest {
|
||||
|
||||
public static final String P_GCUBE_SCOPE = "gcube_scope";
|
||||
public static final String P_ITEM_TYPE = "item_type";
|
||||
public static final String P_ITEM_ID = "item_id";
|
||||
public static final String P_QUERY_STRING = "query_string";
|
||||
|
||||
@JsonProperty(P_GCUBE_SCOPE)
|
||||
private String gcubeScope;
|
||||
/**
|
||||
* It is the UCD ID {usecase_id}
|
||||
*/
|
||||
@JsonProperty(P_ITEM_TYPE)
|
||||
private String itemType;
|
||||
/**
|
||||
* It is the Project ID {project_id}
|
||||
*/
|
||||
@JsonProperty(P_ITEM_ID)
|
||||
private String itemID;
|
||||
@JsonProperty(P_QUERY_STRING)
|
||||
private String queryString;
|
||||
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.datatransfer.resolver.geoportal;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.gcube.datatransfer.resolver.services.GeoportalResolver;
|
||||
|
||||
/**
|
||||
* The Enum TargetAppGeoportalCodes.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Mar 24, 2023
|
||||
*/
|
||||
public enum TargetAppGeoportalCodes {
|
||||
|
||||
GEO_DV(GeoportalResolver.GEO_DV, "data-viewer", "Geoportal Viewer"),
|
||||
GEO_DE(GeoportalResolver.GEO_DE, "data-entry", "Geoportal Entry");
|
||||
|
||||
private String id; // the code id
|
||||
private String name; // the code value
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* Instantiates a new resource catalogue codes.
|
||||
*
|
||||
* @param id the id
|
||||
* @param name the target app
|
||||
* @param description the description
|
||||
*/
|
||||
private TargetAppGeoportalCodes(String id, String name, String description) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
public String getId() {
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the target app.
|
||||
*
|
||||
* @return the target app
|
||||
*/
|
||||
public String getTarget_app() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the description.
|
||||
*
|
||||
* @return the description
|
||||
*/
|
||||
public String getDescription() {
|
||||
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Codes.
|
||||
*
|
||||
* @return the list
|
||||
*/
|
||||
public static List<String> codes() {
|
||||
|
||||
return Arrays.asList(TargetAppGeoportalCodes.values()).stream().map(TargetAppGeoportalCodes::getId)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Value of id.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the target app geoportal codes
|
||||
*/
|
||||
public static TargetAppGeoportalCodes valueOfId(String id) {
|
||||
if (id == null || id.isEmpty())
|
||||
return null;
|
||||
|
||||
List<TargetAppGeoportalCodes> codes = Arrays.asList(TargetAppGeoportalCodes.values()).stream()
|
||||
.filter(value -> value.getId().compareTo(id) == 0).collect(Collectors.toList());
|
||||
|
||||
if (codes == null || codes.isEmpty())
|
||||
return null;
|
||||
|
||||
return codes.get(0);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Value of name.
|
||||
*
|
||||
* @param name the name
|
||||
* @return the target app geoportal codes
|
||||
*/
|
||||
public static TargetAppGeoportalCodes valueOfName(String name) {
|
||||
if (name == null || name.isEmpty())
|
||||
return null;
|
||||
|
||||
List<TargetAppGeoportalCodes> codes = Arrays.asList(TargetAppGeoportalCodes.values()).stream()
|
||||
.filter(value -> value.getTarget_app().compareTo(name) == 0).collect(Collectors.toList());
|
||||
|
||||
if (codes == null || codes.isEmpty())
|
||||
return null;
|
||||
|
||||
return codes.get(0);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -43,7 +43,6 @@ import org.gcube.common.storagehub.model.Metadata;
|
|||
import org.gcube.data.analysis.dminvocation.ActionType;
|
||||
import org.gcube.data.analysis.dminvocation.DataMinerInvocationManager;
|
||||
import org.gcube.data.analysis.dminvocation.model.DataMinerInvocation;
|
||||
import org.gcube.datatransfer.resolver.requesthandler.RequestHandler;
|
||||
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||
import org.gcube.datatransfer.resolver.services.exceptions.InternalServerException;
|
||||
import org.gcube.datatransfer.resolver.util.ScopeUtil;
|
||||
|
@ -119,20 +118,11 @@ public class AnalyticsCreateResolver {
|
|||
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
String operatorID = jsonRequest.getOperatorId();
|
||||
|
||||
if (scope == null || scope.isEmpty()) {
|
||||
|
@ -150,6 +140,13 @@ public class AnalyticsCreateResolver {
|
|||
}
|
||||
|
||||
ScopeBean scopeBean = new ScopeBean(scope);
|
||||
if (scopeBean.is(Type.INFRASTRUCTURE) || scopeBean.is(Type.VO)) {
|
||||
logger.error(Type.INFRASTRUCTURE + "or " + Type.VO + " scope detected, you must set a scope of VRE");
|
||||
throw ExceptionManager.unauthorizedException(req,
|
||||
"You are not authorized. You must pass a token of VRE", this.getClass(), helpURI);
|
||||
}
|
||||
|
||||
|
||||
String publicLinkToDMInvFile = "";
|
||||
|
||||
if (scopeBean.is(Type.VRE)) {
|
||||
|
@ -163,6 +160,7 @@ public class AnalyticsCreateResolver {
|
|||
File tempInvocationFile = null;
|
||||
try {
|
||||
|
||||
String contextToken = SecurityTokenProvider.instance.get();
|
||||
String xmlRequest = DataMinerInvocationManager.getInstance().marshalingXML(jsonRequest, true, true);
|
||||
String uniqueName = createDMInvocationFileName(jsonRequest.getOperatorId());
|
||||
tempInvocationFile = createTempFile(uniqueName, ".xml", xmlRequest.getBytes());
|
||||
|
@ -186,8 +184,9 @@ public class AnalyticsCreateResolver {
|
|||
|
||||
StorageHubManagement storageHubManagement = new StorageHubManagement();
|
||||
Metadata metadata = new Metadata();
|
||||
Map<String, String> theMap = new HashMap<String, String>();
|
||||
Map<String, Object> theMap = new HashMap<String, Object>();
|
||||
theMap.put("owner", owner);
|
||||
metadata.setMap(theMap);
|
||||
URL thePublicLink = null;
|
||||
try {
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import javax.ws.rs.core.Context;
|
|||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.common.scope.impl.ScopeBean.Type;
|
||||
|
@ -111,8 +112,19 @@ public class CatalogueResolver {
|
|||
}
|
||||
} 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("Either the " + itemCatalogueURLs.getItemName()
|
||||
+ " is not an item (alias dataset) or it is a private item (to VRE) so using protected access to CKAN portlet: "
|
||||
+ itemCatalogueURL);
|
||||
}
|
||||
|
||||
String queryString = req.getQueryString();
|
||||
if (queryString != null) {
|
||||
logger.info("Query string found: " + queryString);
|
||||
byte[] stringEncBytes = Base64.encodeBase64(queryString.getBytes());
|
||||
String queryStringEnc = "query_string=" + new String(stringEncBytes);
|
||||
logger.info("Adding Base64 encoded: " + queryString);
|
||||
itemCatalogueURL += itemCatalogueURL.contains("?") ? "&" : "?";
|
||||
itemCatalogueURL += queryStringEnc;
|
||||
}
|
||||
|
||||
return Response.seeOther(new URL(itemCatalogueURL).toURI()).build();
|
||||
|
@ -120,7 +132,8 @@ public class CatalogueResolver {
|
|||
|
||||
if (!(e instanceof WebApplicationException)) {
|
||||
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error occurred on resolving the Catalgoue URL. Please, contact the support!";
|
||||
String error = "Error occurred on resolving the " + CatalogueResolver.class.getSimpleName()
|
||||
+ " URL. Please, contact the support!";
|
||||
if (e.getCause() != null)
|
||||
error += "\n\nCaused: " + e.getCause().getMessage();
|
||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||
|
@ -190,14 +203,20 @@ public class CatalogueResolver {
|
|||
}
|
||||
|
||||
String linkURL = String.format("%s/%s/%s/%s", serverUrl, rc.getId(), vreName, jsonRequest.getEntity_name());
|
||||
logger.info("Returining Catalogue URL: " + linkURL);
|
||||
|
||||
if (jsonRequest.getQuery_string() != null) {
|
||||
linkURL += "?" + jsonRequest.getQuery_string();
|
||||
}
|
||||
|
||||
logger.info("Returning " + CatalogueResolver.class.getSimpleName() + " URL: " + linkURL);
|
||||
return Response.ok(linkURL).header("Location", linkURL).build();
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
if (!(e instanceof WebApplicationException)) {
|
||||
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error occurred on resolving the Analytics URL. Please, contact the support!";
|
||||
String error = "Error occurred on creating the " + CatalogueResolver.class.getSimpleName()
|
||||
+ " URL. Please, contact the support!";
|
||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||
}
|
||||
// ALREADY MANAGED AS WebApplicationExceptiongetItemCatalogueURLs
|
||||
|
|
|
@ -0,0 +1,497 @@
|
|||
package org.gcube.datatransfer.resolver.services;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
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.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.datatransfer.resolver.ConstantsResolver;
|
||||
import org.gcube.datatransfer.resolver.caches.LoadingMapOfScopeCache;
|
||||
import org.gcube.datatransfer.resolver.geoportal.GeoportalCommonConstants;
|
||||
import org.gcube.datatransfer.resolver.geoportal.GeoportalDataViewerConfigProfile;
|
||||
import org.gcube.datatransfer.resolver.geoportal.GeoportalDataViewerConfigProfileReader;
|
||||
import org.gcube.datatransfer.resolver.geoportal.GeoportalRequest;
|
||||
import org.gcube.datatransfer.resolver.geoportal.TargetAppGeoportalCodes;
|
||||
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||
import org.gcube.datatransfer.resolver.util.Util;
|
||||
import org.gcube.smartgears.utils.InnerMethodName;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
|
||||
|
||||
/**
|
||||
* The GeoportalResolver is able to get/resolve a link to "Geoportal Viewer" or
|
||||
* "Geoportal Entry" Application.
|
||||
*
|
||||
* See more at
|
||||
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Geoportal_Resolver
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Mar 23, 2023
|
||||
*/
|
||||
@Path("/geo")
|
||||
public class GeoportalResolver {
|
||||
|
||||
public static final String GEO_DE = "de"; // data-entry
|
||||
public static final String GEO = "geo"; // geoportal
|
||||
public static final String GEO_DV = "dv"; // data-viewer
|
||||
|
||||
private static final String QP_RESOLVE_AS = "res";
|
||||
private static final String PATH_PROJECT_ID = "project_id";
|
||||
private static final String PATH_USECASE_ID = "usecase_id";
|
||||
private static final String PATH_VRE_NAME = "vre_name";
|
||||
private static final String PATH_TARGET_APP = "targetAppId";
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GeoportalResolver.class);
|
||||
private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#Geoportal_Resolver";
|
||||
|
||||
/**
|
||||
* The Enum RESOLVE_AS_PARAMETER.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Mar 24, 2023
|
||||
*/
|
||||
private static enum RESOLVE_AS {
|
||||
PUBLIC, PRIVATE
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve geoportal. Resolve a Geoportal Link to "Data-Viewer" App
|
||||
*
|
||||
* @param req the req
|
||||
* @param vreName the vre name
|
||||
* @param ucdID the ucd ID
|
||||
* @param projectID the project ID
|
||||
* @param resolveAs the resolve as
|
||||
* @return the response
|
||||
* @throws WebApplicationException the web application exception
|
||||
*/
|
||||
@GET
|
||||
@Path("/{vre_name}/{usecase_id}/{project_id}")
|
||||
public Response resolveGeoportalNoAppDef(@Context HttpServletRequest req, @PathParam(PATH_VRE_NAME) String vreName,
|
||||
@PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID,
|
||||
@QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException {
|
||||
|
||||
LOG.info(this.getClass().getSimpleName() + " resolveGeoportalNoAppDef - GET starts...");
|
||||
TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, null);
|
||||
LOG.info("The target app is: " + targetAppGeoportalCodes);
|
||||
return genericResolveLink(req, targetAppGeoportalCodes, vreName, ucdID, projectID, resolveAs);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve geoportal. Resolve a Geoportal Link to "Data-Viewer" or "Data-Entry"
|
||||
* App
|
||||
*
|
||||
* @param req the req
|
||||
* @param targetAppId the target app id
|
||||
* @param vreName the vre name
|
||||
* @param ucdID the ucd ID
|
||||
* @param projectID the project ID
|
||||
* @param resolveAs the resolve as
|
||||
* @return the response
|
||||
* @throws WebApplicationException the web application exception
|
||||
*/
|
||||
@GET
|
||||
@Path("/{targetAppId}/{vre_name}/{usecase_id}/{project_id}")
|
||||
public Response resolveGeoportal(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId,
|
||||
@PathParam(PATH_VRE_NAME) String vreName, @PathParam(PATH_USECASE_ID) String ucdID,
|
||||
@PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs)
|
||||
throws WebApplicationException {
|
||||
|
||||
LOG.info(this.getClass().getSimpleName() + " resolveGeoportal - GET starts...");
|
||||
TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, targetAppId);
|
||||
LOG.info("The target app is: " + targetAppGeoportalCodes);
|
||||
return genericResolveLink(req, targetAppGeoportalCodes, vreName, ucdID, projectID, resolveAs);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve data viewer link.
|
||||
*
|
||||
* @param req the req
|
||||
* @param gcubeScope the gcube scope
|
||||
* @param itemId the item id
|
||||
* @param itemType the item type
|
||||
* @param resolveAs the resolve as
|
||||
* @return the response
|
||||
* @throws WebApplicationException the web application exception
|
||||
*/
|
||||
@GET
|
||||
@Path("/")
|
||||
public Response resolveDataViewerLink(@Context HttpServletRequest req,
|
||||
@QueryParam(GeoportalRequest.P_GCUBE_SCOPE) String gcubeScope,
|
||||
@QueryParam(GeoportalRequest.P_ITEM_ID) String itemId,
|
||||
@QueryParam(GeoportalRequest.P_ITEM_TYPE) String itemType,
|
||||
@QueryParam(QP_RESOLVE_AS) String resolveAs)
|
||||
throws WebApplicationException {
|
||||
|
||||
LOG.info(this.getClass().getSimpleName() + " resolveDataViewerLink - GET starts...");
|
||||
TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, null);
|
||||
LOG.info("The target app is: " + targetAppGeoportalCodes);
|
||||
|
||||
if (gcubeScope == null || gcubeScope.isEmpty()) {
|
||||
|
||||
LOG.error("The query parameter '" + GeoportalRequest.P_GCUBE_SCOPE + "' not found or empty");
|
||||
throw ExceptionManager.badRequestException(req,
|
||||
"Mandatory query parameter '" + GeoportalRequest.P_GCUBE_SCOPE + "' not found or empty",
|
||||
this.getClass(), helpURI);
|
||||
|
||||
}
|
||||
|
||||
String scope = gcubeScope.substring(gcubeScope.lastIndexOf("/") + 1, gcubeScope.length());
|
||||
return genericResolveLink(req, targetAppGeoportalCodes, scope, itemType, itemId, resolveAs);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Post geoportal. Create a Geoportal Link to "Data-Viewer" App
|
||||
*
|
||||
* @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 postGeoportalNoAppDef(@Context HttpServletRequest req, GeoportalRequest jsonRequest)
|
||||
throws WebApplicationException {
|
||||
|
||||
LOG.info(this.getClass().getSimpleName() + " postGeoportalNoAppDef - POST starts...");
|
||||
TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, null);
|
||||
LOG.info("The target app is: " + targetAppGeoportalCodes);
|
||||
String linkURL = genericCreateLink(req, jsonRequest, targetAppGeoportalCodes);
|
||||
return Response.ok(linkURL).header("Location", linkURL).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Post geoportal. Create a Geoportal Link to "Data-Viewer" or "Data-Entry" App
|
||||
*
|
||||
* @param req the req
|
||||
* @param targetAppId the target app id
|
||||
* @param jsonRequest the json request
|
||||
* @return the response
|
||||
* @throws WebApplicationException the web application exception
|
||||
*/
|
||||
@POST
|
||||
@Path("/{targetAppId}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public Response postGeoportal(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId,
|
||||
GeoportalRequest jsonRequest) throws WebApplicationException {
|
||||
|
||||
LOG.info(this.getClass().getSimpleName() + " postGeoportal - POST starts...");
|
||||
TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, targetAppId);
|
||||
LOG.info("The target app is: " + targetAppGeoportalCodes);
|
||||
String linkURL = genericCreateLink(req, jsonRequest, targetAppGeoportalCodes);
|
||||
return Response.ok(linkURL).header("Location", linkURL).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check target appliction ID.
|
||||
*
|
||||
* @param req the req
|
||||
* @param targetAppId the target app id
|
||||
* @return the target app geoportal codes
|
||||
*/
|
||||
private TargetAppGeoportalCodes checkTargetApplictionID(@Context HttpServletRequest req, String targetAppId) {
|
||||
|
||||
TargetAppGeoportalCodes targetAppGeoportalCodes = null;
|
||||
|
||||
if (targetAppId == null) {
|
||||
targetAppGeoportalCodes = TargetAppGeoportalCodes.GEO_DV;
|
||||
LOG.warn("Target application parameter is null, using default: " + targetAppGeoportalCodes);
|
||||
} else {
|
||||
|
||||
// IF the target application passed in the request. It must be proper.
|
||||
targetAppGeoportalCodes = TargetAppGeoportalCodes.valueOfId(targetAppId);
|
||||
|
||||
if (targetAppGeoportalCodes == null) {
|
||||
LOG.error("Target application parameter is malformed");
|
||||
List<String> targetApps = Arrays.asList(TargetAppGeoportalCodes.values()).stream()
|
||||
.map(TargetAppGeoportalCodes::getTarget_app).collect(Collectors.toList());
|
||||
throw ExceptionManager.badRequestException(req,
|
||||
"Target application is wrong. It must be one value of: " + targetApps, this.getClass(),
|
||||
helpURI);
|
||||
}
|
||||
}
|
||||
|
||||
return targetAppGeoportalCodes;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic resolve link.
|
||||
*
|
||||
* @param req the req
|
||||
* @param resoruceGeoportalCodes the resoruce geoportal codes
|
||||
* @param vreName the vre name
|
||||
* @param ucdID the ucd ID
|
||||
* @param projectID the project ID
|
||||
* @param resolveAs the resolve as
|
||||
* @return the response
|
||||
* @throws WebApplicationException the web application exception
|
||||
*/
|
||||
public Response genericResolveLink(@Context HttpServletRequest req, TargetAppGeoportalCodes resoruceGeoportalCodes,
|
||||
@PathParam(PATH_VRE_NAME) String vreName, @PathParam(PATH_USECASE_ID) String ucdID,
|
||||
@PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs)
|
||||
throws WebApplicationException {
|
||||
|
||||
LOG.info(this.getClass().getSimpleName() + " genericResolveLink starts...");
|
||||
|
||||
try {
|
||||
InnerMethodName.instance.set("resolveGeoportalPublicLink");
|
||||
|
||||
LOG.info("Found target app: " + resoruceGeoportalCodes);
|
||||
|
||||
if (resoruceGeoportalCodes == null) {
|
||||
LOG.error("The path parameter '" + PATH_TARGET_APP + "' not found or empty in the path");
|
||||
throw ExceptionManager.badRequestException(req,
|
||||
"Mandatory path parameter '" + PATH_TARGET_APP + "' not found or empty", this.getClass(),
|
||||
helpURI);
|
||||
}
|
||||
|
||||
if (vreName == null || vreName.isEmpty()) {
|
||||
LOG.error("The path parameter '" + PATH_VRE_NAME + "' not found or empty in the path");
|
||||
throw ExceptionManager.badRequestException(req,
|
||||
"Mandatory path parameter '" + PATH_VRE_NAME + "' not found or empty", this.getClass(),
|
||||
helpURI);
|
||||
}
|
||||
|
||||
if (ucdID == null) {
|
||||
LOG.error("The path parameter '" + PATH_USECASE_ID + "' not found or empty in the path");
|
||||
throw ExceptionManager.badRequestException(req,
|
||||
"Mandatory path parameter '" + PATH_USECASE_ID + "' not found or empty", this.getClass(),
|
||||
helpURI);
|
||||
}
|
||||
|
||||
if (projectID == null) {
|
||||
LOG.error("The path parameter '" + PATH_PROJECT_ID + "' not found or empty in the path");
|
||||
throw ExceptionManager.badRequestException(req,
|
||||
"Mandatory path parameter '" + PATH_PROJECT_ID + "' not found or empty", this.getClass(),
|
||||
helpURI);
|
||||
}
|
||||
|
||||
ScopeBean fullScopeBean = null;
|
||||
|
||||
// CHECKING IF THE INPUT VRE NAME IS REGISTRED IN THE INFRASTRUCTURE...
|
||||
try {
|
||||
fullScopeBean = LoadingMapOfScopeCache.get(vreName);
|
||||
} catch (ExecutionException | InvalidCacheLoadException e) {
|
||||
LOG.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);
|
||||
}
|
||||
|
||||
RESOLVE_AS resolveTO = RESOLVE_AS.PUBLIC;
|
||||
if (resolveAs != null) {
|
||||
switch (resolveAs.toLowerCase()) {
|
||||
case "public":
|
||||
resolveTO = RESOLVE_AS.PUBLIC;
|
||||
break;
|
||||
case "private":
|
||||
resolveTO = RESOLVE_AS.PRIVATE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
LOG.info("Found RESOLVE_AS_PARAMETER: " + resolveAs);
|
||||
|
||||
String originalScope = ScopeProvider.instance.get();
|
||||
GeoportalDataViewerConfigProfileReader reader;
|
||||
try {
|
||||
String theScope = fullScopeBean.toString();
|
||||
LOG.info("Full scope is: " + theScope);
|
||||
ScopeProvider.instance.set(theScope);
|
||||
reader = new GeoportalDataViewerConfigProfileReader(
|
||||
org.gcube.datatransfer.resolver.geoportal.GeoportalCommonConstants.GEOPORTAL_DATA_VIEWER_APP);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error on reading the " + GeoportalDataViewerConfigProfileReader.SECONDARY_TYPE
|
||||
+ " with generic resource name: "
|
||||
+ GeoportalDataViewerConfigProfileReader.GENERIC_RESOURCE_NAME, e);
|
||||
throw ExceptionManager.internalErrorException(req,
|
||||
"Error on reading the " + GeoportalDataViewerConfigProfileReader.SECONDARY_TYPE + " for name "
|
||||
+ GeoportalDataViewerConfigProfileReader.GENERIC_RESOURCE_NAME
|
||||
+ ". Please contact the support",
|
||||
this.getClass(), helpURI);
|
||||
} finally {
|
||||
if (originalScope != null && !originalScope.isEmpty()) {
|
||||
ScopeProvider.instance.set(originalScope);
|
||||
LOG.info("scope provider set to orginal scope: " + originalScope);
|
||||
} else {
|
||||
ScopeProvider.instance.reset();
|
||||
LOG.info("scope provider reset");
|
||||
}
|
||||
}
|
||||
|
||||
// Resolving towards Data-Viewer or Data-Entry Application
|
||||
String itemLink = null;
|
||||
|
||||
switch (resoruceGeoportalCodes) {
|
||||
case GEO_DV: {
|
||||
|
||||
GeoportalDataViewerConfigProfile geonaDataProfile = reader.getGeoportalDataViewerConfigProfile();
|
||||
|
||||
switch (resolveTO) {
|
||||
case PUBLIC:
|
||||
// Open Link
|
||||
itemLink = String.format("%s?%s=%s&%s=%s", geonaDataProfile.getOpenPortletURL(),
|
||||
GeoportalCommonConstants.GET_GEONA_ITEM_ID, projectID,
|
||||
GeoportalCommonConstants.GET_GEONA_ITEM_TYPE, ucdID);
|
||||
break;
|
||||
case PRIVATE:
|
||||
|
||||
// Restricted Link
|
||||
itemLink = String.format("%s?%s=%s&%s=%s", geonaDataProfile.getRestrictedPortletURL(),
|
||||
GeoportalCommonConstants.GET_GEONA_ITEM_ID, projectID,
|
||||
GeoportalCommonConstants.GET_GEONA_ITEM_TYPE, ucdID);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case GEO_DE: {
|
||||
|
||||
LOG.error("The Resolver towards '" + resoruceGeoportalCodes + "' not implemented yet");
|
||||
throw ExceptionManager.internalErrorException(req,
|
||||
"The Resolver towards '" + resoruceGeoportalCodes + "' not implemented yet", this.getClass(),
|
||||
helpURI);
|
||||
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
LOG.info("Returning link: " + itemLink);
|
||||
return Response.seeOther(new URL(itemLink).toURI()).build();
|
||||
} catch (Exception e) {
|
||||
|
||||
if (!(e instanceof WebApplicationException)) {
|
||||
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error occurred on resolving the " + GeoportalResolver.class.getSimpleName()
|
||||
+ " URL. 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
|
||||
LOG.error("Exception:", e);
|
||||
throw (WebApplicationException) e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic create link.
|
||||
*
|
||||
* @param req the req
|
||||
* @param jsonRequest the json request
|
||||
* @param targetAppGeoportalCodes the target app geoportal codes
|
||||
* @return the URL
|
||||
*/
|
||||
protected String genericCreateLink(@Context HttpServletRequest req, GeoportalRequest jsonRequest,
|
||||
TargetAppGeoportalCodes targetAppGeoportalCodes) {
|
||||
|
||||
LOG.info(this.getClass().getSimpleName() + " genericCreateLink starts...");
|
||||
|
||||
try {
|
||||
|
||||
InnerMethodName.instance.set("postGeoportalPublicLink");
|
||||
LOG.info("The body contains the request: " + jsonRequest.toString());
|
||||
|
||||
if (jsonRequest.getGcubeScope() == null) {
|
||||
throw ExceptionManager.badRequestException(req, "Missing parameter " + GeoportalRequest.P_GCUBE_SCOPE,
|
||||
this.getClass(), helpURI);
|
||||
}
|
||||
|
||||
if (jsonRequest.getItemID() == null) {
|
||||
throw ExceptionManager.badRequestException(req, "Missing parameter " + GeoportalRequest.P_ITEM_ID,
|
||||
this.getClass(), helpURI);
|
||||
}
|
||||
|
||||
if (jsonRequest.getItemType() == null) {
|
||||
throw ExceptionManager.badRequestException(req, "Missing parameter " + GeoportalRequest.P_ITEM_TYPE,
|
||||
this.getClass(), helpURI);
|
||||
}
|
||||
|
||||
// CHECK IF INPUT SCOPE IS VALID
|
||||
String scope = jsonRequest.getGcubeScope();
|
||||
if (!scope.startsWith(ConstantsResolver.SCOPE_SEPARATOR)) {
|
||||
LOG.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());
|
||||
ScopeBean fullScope = null;
|
||||
|
||||
// CHECK IF THE vreName has a valid scope, so it is a valid VRE
|
||||
try {
|
||||
fullScope = LoadingMapOfScopeCache.get(vreName);
|
||||
} catch (ExecutionException e) {
|
||||
LOG.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);
|
||||
|
||||
String linkURL = String.format("%s/%s/%s/%s/%s/%s", serverUrl, GEO, targetAppGeoportalCodes.getId(),
|
||||
vreName, jsonRequest.getItemType(), jsonRequest.getItemID());
|
||||
|
||||
if (jsonRequest.getQueryString() != null) {
|
||||
linkURL += "?" + jsonRequest.getQueryString();
|
||||
}
|
||||
|
||||
LOG.info("Returning " + GeoportalResolver.class.getSimpleName() + " URL: " + linkURL);
|
||||
return linkURL;
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
if (!(e instanceof WebApplicationException)) {
|
||||
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error occurred on creating the " + GeoportalResolver.class.getSimpleName()
|
||||
+ " URL. Please, contact the support!";
|
||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||
}
|
||||
// ALREADY MANAGED AS WebApplicationExceptiongetItemCatalogueURLs
|
||||
LOG.error("Exception:", e);
|
||||
throw (WebApplicationException) e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -13,11 +13,9 @@ 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.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.common.scope.impl.ScopeBean.Type;
|
||||
import org.gcube.datatransfer.resolver.requesthandler.RequestHandler;
|
||||
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||
import org.gcube.datatransfer.resolver.util.Util;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -60,22 +58,18 @@ public class KnimeCreateResolver {
|
|||
logger.info(this.getClass().getSimpleName() + " POST starts...");
|
||||
|
||||
try {
|
||||
String contextToken = SecurityTokenProvider.instance.get();
|
||||
|
||||
String scope = ScopeProvider.instance.get();
|
||||
// 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) + "...");
|
||||
ScopeBean scopeBean = new ScopeBean(scope);
|
||||
if (scopeBean.is(Type.INFRASTRUCTURE) || scopeBean.is(Type.VO)) {
|
||||
logger.error(Type.INFRASTRUCTURE + "or " + Type.VO + " scope detected, you must set a scope of VRE");
|
||||
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)) {
|
||||
|
||||
String vreName = scopeBean.name();
|
||||
|
|
|
@ -22,12 +22,12 @@ import javax.ws.rs.core.MediaType;
|
|||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
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.requesthandler.RequestHandler;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.common.scope.impl.ScopeBean.Type;
|
||||
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||
import org.gcube.datatransfer.resolver.services.exceptions.NotFoundException;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
|
@ -72,15 +72,12 @@ public class WekeoResolver {
|
|||
|
||||
try {
|
||||
|
||||
String contextToken = SecurityTokenProvider.instance.get();
|
||||
String scope = ScopeProvider.instance.get();
|
||||
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) + "...");
|
||||
ScopeBean scopeBean = new ScopeBean(scope);
|
||||
if (scopeBean.is(Type.INFRASTRUCTURE) || scopeBean.is(Type.VO)) {
|
||||
logger.error(Type.INFRASTRUCTURE + "or " + Type.VO + " scope detected, you must set a scope of VRE");
|
||||
throw ExceptionManager.unauthorizedException(req,
|
||||
"You are not authorized. You must pass a token of VRE", this.getClass(), helpURI);
|
||||
}
|
||||
|
|
|
@ -9,10 +9,10 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Builder;
|
||||
|
||||
|
||||
@XmlRootElement(name="error")
|
||||
|
|
|
@ -10,10 +10,10 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Builder;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
padding: 10px;
|
||||
background: white;
|
||||
width: 100%;
|
||||
height: 100px;
|
||||
}
|
||||
|
||||
.navbar-fixed-top {
|
||||
|
|
|
@ -0,0 +1,158 @@
|
|||
package catalogue;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.spatial.data.geonetwork.LoginLevel;
|
||||
import org.junit.Test;
|
||||
|
||||
import resources.GcoreEndpointReader;
|
||||
import resources.GetAllInfrastructureScopes;
|
||||
|
||||
/**
|
||||
* The Class CatalogueMatching_SCOPE_CKANCONNECTOR.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Jun 7, 2022
|
||||
*/
|
||||
public class CatalogueMatching_SCOPE_CKANCONNECTOR {
|
||||
|
||||
// GN CONFIGURATIONS
|
||||
static String rootScope = "/d4science.research-infrastructures.eu";
|
||||
// static String rootScope = "/pred4s";
|
||||
// static String rootScope = "/gcube";
|
||||
static LoginLevel loginLevel = LoginLevel.CKAN;
|
||||
|
||||
static PrintWriter reportPrintWriter;
|
||||
static PrintWriter errorPrintWriter;
|
||||
|
||||
private static int c = 0;
|
||||
|
||||
/**
|
||||
* Test catalogue discovery.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void testCatalogueDiscovery() throws Exception {
|
||||
|
||||
try {
|
||||
FileWriter reportWriter = new FileWriter(rootScope.substring(1, rootScope.length()) + "_report_"
|
||||
+ CatalogueMatching_SCOPE_CKANCONNECTOR.class.getSimpleName() + ".csv", true);
|
||||
FileWriter errorWriter = new FileWriter(rootScope.substring(1, rootScope.length()) + "_error_"
|
||||
+ CatalogueMatching_SCOPE_CKANCONNECTOR.class.getSimpleName() + ".csv", true);
|
||||
BufferedWriter reportBW = new BufferedWriter(reportWriter);
|
||||
BufferedWriter errorBW = new BufferedWriter(errorWriter);
|
||||
reportPrintWriter = new PrintWriter(reportBW);
|
||||
reportPrintWriter.println("NB.; SCOPE; CKAN_CONNECTOR_URL;");
|
||||
errorPrintWriter = new PrintWriter(errorBW);
|
||||
errorPrintWriter.println("NB.; SCOPE; ERROR MESSAGE;");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// final Path destination = Paths.get("report_matching_gn_catalogue.csv");
|
||||
// Files.w(re, destination);
|
||||
|
||||
List<String> scopesProd = new ArrayList<String>();
|
||||
|
||||
// RuntimeResourceReader readerRR;
|
||||
try {
|
||||
// MODE-1
|
||||
// readerRR = new RuntimeResourceReader(rootScope, platformName, null);
|
||||
// System.out.println(readerRR.toString());
|
||||
// System.out.println("Using GN: "+readerRR.getParameters());
|
||||
// System.out.println("Scopes are: "+readerRR.getScopes().size());
|
||||
// scopesProd.addAll(readerRR.getScopes());
|
||||
|
||||
// MODE-2
|
||||
Map<String, String> mapScopes = GetAllInfrastructureScopes.loadMapOfScopeNameToFullScope(rootScope);
|
||||
scopesProd.addAll(mapScopes.values());
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("Read " + scopesProd.size() + " VREs from root scope: " + rootScope);
|
||||
for (String vre : scopesProd) {
|
||||
System.out.println("VRE: " + vre);
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
try {
|
||||
|
||||
final String ckanResource = "org.gcube.data.access.ckanconnector.CkanConnector";
|
||||
final String serviceName = "CkanConnector";
|
||||
final String serviceClass = "DataAccess";
|
||||
|
||||
int totalScope = scopesProd.size();
|
||||
int reportOp = 0;
|
||||
int errorOp = 0;
|
||||
for (String scope : scopesProd) {
|
||||
count++;
|
||||
System.out.println("#### Operation "+ count+ " of "+totalScope+") Fetching scope: " + scope);
|
||||
ScopeProvider.instance.set(scope);
|
||||
GcoreEndpointReader reader = null;
|
||||
try {
|
||||
// discovery = new GCatClientDiscovery();
|
||||
reader = new GcoreEndpointReader(scope, serviceClass, serviceName, ckanResource);
|
||||
} catch (Exception e) {
|
||||
System.out.println("gCat not instanciable in the scope: " + scope);
|
||||
errorOp++;
|
||||
writeError(errorOp + "; " + scope + " ; " + e.getMessage());
|
||||
}
|
||||
|
||||
if (reader != null) {
|
||||
reportOp++;
|
||||
writeReport(reportOp + "; " + scope + " ; " + reader.getEndPoints().get(0) + " ; ");
|
||||
}
|
||||
|
||||
System.out.println("Sleeping...");
|
||||
Thread.sleep(500);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (reportPrintWriter != null)
|
||||
reportPrintWriter.close();
|
||||
|
||||
if (errorPrintWriter != null)
|
||||
errorPrintWriter.close();
|
||||
|
||||
System.out.println("Performed fetching from " + count + " scopes");
|
||||
System.out.println("FINISHED!!!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Write report.
|
||||
*
|
||||
* @param newline the newline
|
||||
*/
|
||||
private static synchronized void writeReport(String newline) {
|
||||
c++;
|
||||
reportPrintWriter.println(newline);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write error.
|
||||
*
|
||||
* @param newline the newline
|
||||
*/
|
||||
private static synchronized void writeError(String newline) {
|
||||
c++;
|
||||
errorPrintWriter.println(newline);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,381 @@
|
|||
package gis;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.common.encryption.StringEncrypter;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.spatial.data.geonetwork.GeoNetwork;
|
||||
import org.gcube.spatial.data.geonetwork.GeoNetworkPublisher;
|
||||
import org.gcube.spatial.data.geonetwork.GeoNetworkReader;
|
||||
import org.gcube.spatial.data.geonetwork.LoginLevel;
|
||||
import org.gcube.spatial.data.geonetwork.configuration.Configuration;
|
||||
import org.gcube.spatial.data.geonetwork.model.Account;
|
||||
import org.gcube.spatial.data.geonetwork.model.Account.Type;
|
||||
import org.junit.Test;
|
||||
|
||||
import it.geosolutions.geonetwork.util.GNSearchRequest;
|
||||
import it.geosolutions.geonetwork.util.GNSearchResponse;
|
||||
import it.geosolutions.geonetwork.util.GNSearchResponse.GNMetadata;
|
||||
|
||||
/**
|
||||
* The Class GeonetworkQueryTest.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Aug 31, 2016
|
||||
*/
|
||||
public class GeonetworkQueryTest {
|
||||
|
||||
private static final int MAX = 30;
|
||||
|
||||
//private String[] scopes = {"/gcube/devsec/devVRE"};
|
||||
|
||||
//private String[] scopes = {"/gcube/devsec/StaTabTest"};
|
||||
|
||||
//private String[] scopes = {"/gcube/devsec/devVRE"};
|
||||
|
||||
//private String[] scopes = {"/pred4s/preprod/preVRE"};
|
||||
|
||||
//private String[] scopes = {"/d4science.research-infrastructures.eu"};
|
||||
|
||||
//private String[] scopesProd = {"/d4science.research-infrastructures.eu/gCubeApps/fisheriesandecosystematmii"};
|
||||
|
||||
//private String[] scopesProd = {"/d4science.research-infrastructures.eu/D4Research"};
|
||||
|
||||
//private String[] scopesProd = {"/d4science.research-infrastructures.eu"};
|
||||
|
||||
//private String[] scopes = {"/d4science.research-infrastructures.eu/gCubeApps/BlueBridgeProject"};
|
||||
|
||||
//private String[] scopes = {"/d4science.research-infrastructures.eu/gCubeApps/AquacultureAtlasGeneration"};
|
||||
|
||||
//private String[] scopes = {"/d4science.research-infrastructures.eu/gCubeApps/FrenchTropicalTunaAtlas"};
|
||||
|
||||
private String[] scopes = {"/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab"};
|
||||
|
||||
//private String[] scopes = {"/d4science.research-infrastructures.eu/gCubeApps/SIASPA"};
|
||||
|
||||
//private String[] scopes = {"/d4science.research-infrastructures.eu/gCubeApps/ICCAT_BFT-E"};
|
||||
|
||||
|
||||
|
||||
private LoginLevel loginLevel = LoginLevel.CKAN;
|
||||
|
||||
private Type accountType = Type.CKAN;
|
||||
|
||||
private String textToSearch = "geo_fea";
|
||||
|
||||
/**
|
||||
* Gets the count.
|
||||
*
|
||||
* @return the count
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
//@Test
|
||||
public void getCount() throws Exception{
|
||||
|
||||
try{
|
||||
for(String scope:scopes){
|
||||
ScopeProvider.instance.set(scope);
|
||||
GeoNetworkPublisher reader=GeoNetwork.get();
|
||||
|
||||
Configuration config = reader.getConfiguration();
|
||||
Account account=config.getScopeConfiguration().getAccounts().get(accountType);
|
||||
|
||||
// Configuration config = gnInstance.getGeonetworkPublisher().getConfiguration();
|
||||
// Account account = config.getScopeConfiguration().getAccounts().get(Type.CKAN);
|
||||
|
||||
//System.out.println("User: "+account.getUser()+", Pwd: "+account.getPassword());
|
||||
System.out.println("Admin: "+config.getAdminAccount().getUser()+", Pwd: "+config.getAdminAccount().getPassword());
|
||||
System.out.println("USER: "+account.getUser()+", Pwd: "+account.getPassword());
|
||||
System.out.println("GN: "+config.getGeoNetworkEndpoint());
|
||||
try{
|
||||
String decryptedPassword = StringEncrypter.getEncrypter().decrypt(account.getPassword());
|
||||
System.out.println("Decrypted Password: "+decryptedPassword);
|
||||
}catch(Exception e){
|
||||
System.out.println("ignoring exception during pwd decrypting");
|
||||
}
|
||||
|
||||
|
||||
// req.addParam("keyword", "Thredds");
|
||||
final GNSearchRequest req=new GNSearchRequest();
|
||||
// req.addParam(GNSearchRequest.Param.any,"Thredds");
|
||||
GNSearchResponse resp = reader.query(req);
|
||||
int publicCount=resp.getCount();
|
||||
System.out.println("Public UUIDs are: "+publicCount);
|
||||
Map<Long,String> publicUUIDs = getUUIDs(resp);
|
||||
System.out.println("Filled list of Public UUIDs with: "+publicUUIDs.size());
|
||||
System.out.println("Public layers are: ");
|
||||
printLayers(publicUUIDs);
|
||||
|
||||
reader.login(loginLevel);
|
||||
resp = reader.query(req);
|
||||
int totalCount=resp.getCount();
|
||||
System.out.println("All UUIDs are: "+totalCount);
|
||||
Map<Long,String> allUUIDs = getUUIDs(resp);
|
||||
System.out.println("Filled list of All UUIDs with: "+allUUIDs.size());
|
||||
|
||||
System.out.println("SCOPE "+scope+" found "+totalCount+" (public : "+publicCount+", private :"+(totalCount-publicCount)+")");
|
||||
|
||||
System.out.println("Private layers are: ");
|
||||
allUUIDs.keySet().removeAll(publicUUIDs.keySet());
|
||||
printLayers(allUUIDs);
|
||||
|
||||
/*if(totalCount==0)
|
||||
return;
|
||||
try{
|
||||
int last = totalCount<MAX?totalCount:MAX;
|
||||
for(int i=0; i<last; i++){
|
||||
String xml = reader.getByIdAsRawString(resp.getMetadata(i).getUUID());
|
||||
System.out.println(i+") UUID: "+resp.getMetadata(i).getUUID() + " ID: "+resp.getMetadata(i).getId());
|
||||
//System.out.println(i+") is Thredds? "+containsString(xml, "Thredds"));
|
||||
}
|
||||
|
||||
}catch(Exception e ){
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
System.out.println("DONE!!!");
|
||||
}
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prints the layers.
|
||||
*
|
||||
* @param layersUUIDs the layers UUI ds
|
||||
*/
|
||||
public void printLayers(Map<Long,String> layersUUIDs) {
|
||||
int index = 0;
|
||||
|
||||
for (Long key : layersUUIDs.keySet()) {
|
||||
index++;
|
||||
System.out.println(index+") ID: "+key+" - UUID: "+layersUUIDs.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the UUI ds.
|
||||
*
|
||||
* @param resp the resp
|
||||
* @return the UUI ds
|
||||
*/
|
||||
public static Map<Long,String> getUUIDs(GNSearchResponse resp){
|
||||
|
||||
Map<Long,String> listUUIDs = new HashMap<Long,String>();
|
||||
Iterator<GNMetadata> iterator = resp.iterator();
|
||||
while(iterator.hasNext()) {
|
||||
GNMetadata meta = iterator.next();
|
||||
//listUUIDs.add(new GN_META_REF(meta.getId(), meta.getUUID()));
|
||||
listUUIDs.put(meta.getId(), meta.getUUID());
|
||||
//System.out.println("Added: "+meta.getUUID());
|
||||
}
|
||||
|
||||
return listUUIDs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the layers by search.
|
||||
*
|
||||
* @return the layers by search
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
//@Test
|
||||
public void getLayersBySearch() throws Exception{
|
||||
try{
|
||||
for(String scope:scopes){
|
||||
ScopeProvider.instance.set(scope);
|
||||
GeoNetworkPublisher reader=GeoNetwork.get();
|
||||
|
||||
|
||||
|
||||
Configuration config = reader.getConfiguration();
|
||||
Account account=config.getScopeConfiguration().getAccounts().get(accountType);
|
||||
|
||||
//System.out.println("User: "+account.getUser()+", Pwd: "+account.getPassword());
|
||||
System.out.println("Admin: "+config.getAdminAccount().getUser()+", Pwd: "+config.getAdminAccount().getPassword());
|
||||
|
||||
try{
|
||||
String decryptedPassword = StringEncrypter.getEncrypter().decrypt(account.getPassword());
|
||||
System.out.println("Decrypted Password: "+decryptedPassword);
|
||||
}catch(Exception e){
|
||||
System.out.println("ignoring exception during pwd decrypting");
|
||||
}
|
||||
|
||||
|
||||
// req.addParam("keyword", "Thredds");
|
||||
//final GNSearchRequest req=new GNSearchRequest();
|
||||
final GNSearchRequest req = getRequest(true, textToSearch);
|
||||
// req.addParam(GNSearchRequest.Param.any,"Thredds");
|
||||
GNSearchResponse resp = reader.query(req);
|
||||
int publicCount=resp.getCount();
|
||||
reader.login(loginLevel);
|
||||
int totalCount=reader.query(req).getCount();
|
||||
System.out.println("QUERY "+textToSearch);
|
||||
System.out.println("SCOPE "+scope+" found "+totalCount+" (public : "+publicCount+", private :"+(totalCount-publicCount)+")");
|
||||
|
||||
// if(totalCount==0)
|
||||
// return;
|
||||
// try{
|
||||
// int last = totalCount>MAX?totalCount:MAX;
|
||||
//
|
||||
// for(int i=0; i<last; i++){
|
||||
// //String xml = reader.getByIdAsRawString(resp.getMetadata(i).getUUID());
|
||||
// GNMetadata xml = resp.getMetadata(i);
|
||||
// //System.out.println(i+") is Thredds? "+containsString(xml, "Thredds"));
|
||||
// System.out.println(xml.toString());
|
||||
// }
|
||||
// }catch(Exception e ){
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
}
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Contains string.
|
||||
*
|
||||
* @param txt the txt
|
||||
* @param value the value
|
||||
* @return true, if successful
|
||||
*/
|
||||
private boolean containsString(String txt, String value){
|
||||
return txt.contains(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the request.
|
||||
*
|
||||
* @param sortByTitle the sort by title
|
||||
* @param textToSearch the text to search
|
||||
* @return the request
|
||||
*/
|
||||
public GNSearchRequest getRequest(boolean sortByTitle, String textToSearch) {
|
||||
|
||||
GNSearchRequest req = new GNSearchRequest();
|
||||
|
||||
if(sortByTitle)
|
||||
req.addConfig(GNSearchRequest.Config.sortBy, "title");
|
||||
|
||||
if(textToSearch==null || textToSearch.isEmpty()){
|
||||
req.addParam(GNSearchRequest.Param.any, textToSearch);
|
||||
System.out.println("search by any text");
|
||||
}else{
|
||||
req.addParam(GNSearchRequest.Param.title, textToSearch);
|
||||
req.addConfig(GNSearchRequest.Config.similarity, "1");
|
||||
System.out.println("search by title");
|
||||
}
|
||||
System.out.println("text to search "+textToSearch);
|
||||
|
||||
return req;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Class GN_META_REF.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* May 20, 2019
|
||||
*/
|
||||
public static class GN_META_REF{
|
||||
Long id;
|
||||
String uuid;
|
||||
|
||||
/**
|
||||
* Gets the id.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the id.
|
||||
*
|
||||
* @param id the new id
|
||||
*/
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the uuid.
|
||||
*
|
||||
* @return the uuid
|
||||
*/
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the uuid.
|
||||
*
|
||||
* @param uuid the new uuid
|
||||
*/
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new gn meta ref.
|
||||
*
|
||||
* @param id the id
|
||||
* @param uuid the uuid
|
||||
*/
|
||||
public GN_META_REF(Long id, String uuid) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("GN_META_REF [id=");
|
||||
builder.append(id);
|
||||
builder.append(", uuid=");
|
||||
builder.append(uuid);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the count prod.
|
||||
*
|
||||
* @return the count prod
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
// @Test
|
||||
public void getCountProd() throws Exception{
|
||||
try{
|
||||
for(String scope:scopes){
|
||||
ScopeProvider.instance.set(scope);
|
||||
GeoNetworkReader reader=GeoNetwork.get();
|
||||
final GNSearchRequest req=new GNSearchRequest();
|
||||
// req.addParam("keyword", "Thredds");
|
||||
// req.addParam(GNSearchRequest.Param.any,"Oscar");
|
||||
int publicCount=reader.query(req).getCount();
|
||||
reader.login(loginLevel);
|
||||
int totalCount=reader.query(req).getCount();
|
||||
System.out.println("SCOPE "+scope+" found "+totalCount+" (public : "+publicCount+", private :"+(totalCount-publicCount)+")");
|
||||
}
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,267 @@
|
|||
//package gis;
|
||||
//import it.geosolutions.geonetwork.util.GNSearchRequest;
|
||||
//import it.geosolutions.geonetwork.util.GNSearchResponse;
|
||||
//
|
||||
//import java.io.BufferedInputStream;
|
||||
//import java.io.BufferedReader;
|
||||
//import java.io.FileNotFoundException;
|
||||
//import java.io.FileReader;
|
||||
//import java.io.IOException;
|
||||
//import java.io.InputStream;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//import java.util.stream.Collectors;
|
||||
//
|
||||
//import javax.xml.parsers.DocumentBuilder;
|
||||
//import javax.xml.parsers.DocumentBuilderFactory;
|
||||
//
|
||||
//import org.gcube.common.encryption.StringEncrypter;
|
||||
//import org.gcube.common.scope.api.ScopeProvider;
|
||||
//import org.gcube.spatial.data.geonetwork.GeoNetwork;
|
||||
//import org.gcube.spatial.data.geonetwork.GeoNetworkPublisher;
|
||||
//import org.gcube.spatial.data.geonetwork.LoginLevel;
|
||||
//import org.gcube.spatial.data.geonetwork.configuration.Configuration;
|
||||
//import org.gcube.spatial.data.geonetwork.model.Account;
|
||||
//import org.gcube.spatial.data.geonetwork.model.Account.Type;
|
||||
//import org.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
//import org.w3c.dom.Document;
|
||||
//import org.w3c.dom.Element;
|
||||
//import org.w3c.dom.NodeList;
|
||||
//
|
||||
///**
|
||||
// *
|
||||
// * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
// * Aug 31, 2016
|
||||
// */
|
||||
//public class ICCATQueryTest {
|
||||
//
|
||||
// private static final int MAX = 200;
|
||||
//
|
||||
// //private String[] scopes = {"/gcube/devNext/NextNext"};
|
||||
//
|
||||
// //private String[] scopesProd = {"/d4science.research-infrastructures.eu"};
|
||||
//
|
||||
// private static String[] scopesProd = {"/d4science.research-infrastructures.eu/gCubeApps/ICCAT_BFT-E"};
|
||||
//
|
||||
// //private String[] scopesProd = {"/d4science.research-infrastructures.eu/gCubeApps/fisheriesandecosystematmii"};
|
||||
//
|
||||
// //private String[] scopesProd = {"/d4science.research-infrastructures.eu/D4Research"};
|
||||
//
|
||||
// //private String[] scopesProd = {"/d4science.research-infrastructures.eu"};
|
||||
//
|
||||
// private static LoginLevel loginLevel = LoginLevel.CKAN;
|
||||
//
|
||||
// private static Type accountType = Type.SCOPE;
|
||||
//
|
||||
// private static String textToSearch = "geo_fea";
|
||||
//
|
||||
// private static Logger logger = LoggerFactory.getLogger(ICCATQueryTest.class);
|
||||
//
|
||||
// private static enum LAYER_TYPE {PRIVATE, PUBLIC, ALL}
|
||||
//
|
||||
//
|
||||
// public static List<String> getLayers(LAYER_TYPE type) throws Exception{
|
||||
//
|
||||
// try{
|
||||
// for(String scope:scopesProd){
|
||||
// ScopeProvider.instance.set(scope);
|
||||
// GeoNetworkPublisher reader=GeoNetwork.get();
|
||||
//
|
||||
// Configuration config = reader.getConfiguration();
|
||||
// Account account=config.getScopeConfiguration().getAccounts().get(accountType);
|
||||
//
|
||||
// //System.out.println("User: "+account.getUser()+", Pwd: "+account.getPassword());
|
||||
// System.out.println("Admin: "+config.getAdminAccount().getUser()+", Pwd: "+config.getAdminAccount().getPassword());
|
||||
//
|
||||
// try{
|
||||
// String decryptedPassword = StringEncrypter.getEncrypter().decrypt(account.getPassword());
|
||||
// System.out.println("Decrypted Password: "+decryptedPassword);
|
||||
// }catch(Exception e){
|
||||
// System.out.println("ignoring exception during pwd decrypting");
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // req.addParam("keyword", "Thredds");
|
||||
// final GNSearchRequest req=new GNSearchRequest();
|
||||
//// req.addParam(GNSearchRequest.Param.any,"Thredds");
|
||||
// GNSearchResponse resp = reader.query(req);
|
||||
// int publicCount=resp.getCount();
|
||||
//
|
||||
// List<String> publicLayers = new ArrayList<String>();
|
||||
// for(int i=0; i<publicCount; i++)
|
||||
// publicLayers.add(resp.getMetadata(i).getUUID());
|
||||
//
|
||||
// System.out.println("Public layers are: "+publicLayers.size());
|
||||
//
|
||||
// //PERFOMING LOGIN TO GET ALL LAYERS
|
||||
// reader.login(loginLevel);
|
||||
// resp = reader.query(req);
|
||||
// int totalCount=resp.getCount();
|
||||
// int privateCount = totalCount-publicCount;
|
||||
//
|
||||
// System.out.println("SCOPE "+scope+" found "+totalCount+" (public : "+publicCount+", private :"+privateCount+")");
|
||||
//
|
||||
// List<String> privateLayers = new ArrayList<String>();
|
||||
// for(int i=0; i<totalCount; i++){
|
||||
//
|
||||
// String uuid = resp.getMetadata(i).getUUID();
|
||||
// //System.out.println("Searching UUID: "+uuid);
|
||||
// if(!publicLayers.contains(uuid)){
|
||||
// privateLayers.add(uuid);
|
||||
// }
|
||||
//
|
||||
//// String xml = reader.getByIdAsRawString(resp.getMetadata(i).getUUID());
|
||||
//// InputStream stream = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
|
||||
//// iccatGNUUID.add(toGetFileIdentifier(stream));
|
||||
//
|
||||
// //System.out.println(i+") is Thredds? "+containsString(xml, "Thredds"));
|
||||
// }
|
||||
//
|
||||
// System.out.println("Private layers are: "+privateLayers.size());
|
||||
//
|
||||
//
|
||||
// switch (type) {
|
||||
// case PUBLIC:
|
||||
// return publicLayers;
|
||||
// case PRIVATE:
|
||||
// return privateLayers;
|
||||
// case ALL:
|
||||
// publicLayers.addAll(privateLayers);
|
||||
// return publicLayers;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }catch(Exception e){
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Override summary record.
|
||||
// *
|
||||
// * @param doc the doc
|
||||
// * @param identifier the identifier
|
||||
// * @return true, if successful
|
||||
// */
|
||||
// private static String getFileIdentifierValue(Document doc) {
|
||||
//
|
||||
// // <csw:SummaryRecord> list
|
||||
// NodeList nodes = doc.getElementsByTagName("gmd:MD_Metadata");
|
||||
// logger.debug("gmd:MD_Metadata are: " + nodes.getLength());
|
||||
// for (int i = 0; i < nodes.getLength(); i++) {
|
||||
// Element mdMetadata = (Element) nodes.item(i);
|
||||
//
|
||||
// // <dc:identifier>
|
||||
// NodeList fileIdentifierLst = mdMetadata.getElementsByTagName("gmd:fileIdentifier");
|
||||
// if(fileIdentifierLst==null || fileIdentifierLst.getLength()==0 || fileIdentifierLst.item(0)==null){
|
||||
// logger.info("skipping, it has not fileidentifier");
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// Element id = (Element) fileIdentifierLst.item(0);
|
||||
//
|
||||
// NodeList gcoLst = id.getElementsByTagName("gco:CharacterString");
|
||||
// if(gcoLst==null || gcoLst.getLength()==0 || gcoLst.item(0)==null){
|
||||
// logger.info("skipping, it has not gco:CharacterString");
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// Element gco = (Element) gcoLst.item(0);
|
||||
// String idValue = gco.getTextContent();
|
||||
// logger.trace("Summary gmd:fileIdentifier is: " + idValue);
|
||||
// return idValue;
|
||||
// }
|
||||
//
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Removes the summary ids by list ids.
|
||||
// *
|
||||
// * @param getRecordsResponse the get records response
|
||||
// * @param idsToRemove the ids to remove
|
||||
// * @return the input stream
|
||||
// * @throws IOException Signals that an I/O exception has occurred.
|
||||
// */
|
||||
// public static String toGetFileIdentifier(InputStream getRecordResponse) throws IOException {
|
||||
//
|
||||
// try {
|
||||
// // logger.trace("getRecordsResponse is: "+IOUtils.toString(getRecordsResponse));
|
||||
// BufferedInputStream bis = new BufferedInputStream(getRecordResponse);
|
||||
// DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
// dbf.setValidating(false);
|
||||
// DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
// Document doc = db.parse(bis);
|
||||
// return getFileIdentifierValue(doc);
|
||||
// }
|
||||
// catch (Exception e) {
|
||||
// logger.error("An error occurred during removing IDS by List: ", e);
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public static List<String> fileReader() throws FileNotFoundException{
|
||||
//
|
||||
// String fileName = "iccat_name_catalogue.csv";
|
||||
//
|
||||
//// //read file into stream, try-with-resources
|
||||
//// try (Stream<String> stream = Files.lines(Paths.get(fileName))) {
|
||||
////
|
||||
//// stream.forEach(System.out::println);
|
||||
////
|
||||
//// } catch (IOException e) {
|
||||
//// e.printStackTrace();
|
||||
//// }
|
||||
//
|
||||
// FileReader reportReader = new FileReader(fileName);
|
||||
// //Stream<String> stream = reportBW.lines();
|
||||
// List<String> list = new ArrayList<>();
|
||||
// try (BufferedReader reportBW = new BufferedReader(reportReader)){
|
||||
//
|
||||
// list = reportBW.lines().collect(Collectors.toList());
|
||||
//
|
||||
// }catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// return list;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public static void main(String[] args) {
|
||||
//
|
||||
// List<String> listCKAN;
|
||||
// try {
|
||||
// listCKAN = fileReader();
|
||||
// System.out.println("CKAN Layers are: "+listCKAN.size());
|
||||
//// for (String line : listCKAN) {
|
||||
//// System.out.println("CKAN UUID: "+line);
|
||||
//// }
|
||||
//
|
||||
// List<String> listLayersUUID = getLayers(LAYER_TYPE.PUBLIC);
|
||||
// System.out.println("List Layers UUID are: "+listLayersUUID.size());
|
||||
//// for (String line : listLayersUUID) {
|
||||
//// System.out.println("PRIVATE GN UUID: "+line);
|
||||
//// }
|
||||
//
|
||||
//
|
||||
// listCKAN.removeAll(listLayersUUID);
|
||||
//
|
||||
// System.out.println("\n\n\nCKAN contains other: "+listCKAN.size());
|
||||
// for (String line : listCKAN) {
|
||||
// System.out.println("CKAN UUID: "+line);
|
||||
// }
|
||||
//
|
||||
// }catch (Exception e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// }
|
||||
//}
|
|
@ -0,0 +1,169 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package gis;
|
||||
|
||||
import it.geosolutions.geonetwork.util.GNSearchRequest;
|
||||
import it.geosolutions.geonetwork.util.GNSearchResponse;
|
||||
import resources.GetAllInfrastructureScopes;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.spatial.data.geonetwork.GeoNetwork;
|
||||
import org.gcube.spatial.data.geonetwork.GeoNetworkPublisher;
|
||||
import org.gcube.spatial.data.geonetwork.LoginLevel;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Mar 10, 2017
|
||||
*/
|
||||
public class LayersMatchingGN_CKAN {
|
||||
|
||||
//GN CONFIGURATIONS
|
||||
public static String rootScope = "/d4science.research-infrastructures.eu";
|
||||
//static String rootScope = "/pred4s";
|
||||
// static String rootScope = "/gcube";
|
||||
public static String platformName = "geonetwork";
|
||||
public static LoginLevel loginLevel = LoginLevel.ADMIN;
|
||||
//static Type accountType = Type.SCOPE;
|
||||
public static String textToSearch = "geo_fea";
|
||||
|
||||
public static PrintWriter reportPrintWriter;
|
||||
public static PrintWriter errorPrintWriter;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try{
|
||||
FileWriter reportWriter = new FileWriter(rootScope.substring(1,rootScope.length())+"_report_matching_gn_catalogue.csv", true);
|
||||
FileWriter errorWriter = new FileWriter(rootScope.substring(1,rootScope.length())+"_error_matching_gn_catalogue.csv", true);
|
||||
BufferedWriter reportBW = new BufferedWriter(reportWriter);
|
||||
BufferedWriter errorBW = new BufferedWriter(errorWriter);
|
||||
reportPrintWriter = new PrintWriter(reportBW);
|
||||
reportPrintWriter.println("NB.; SCOPE; GN Endpoint; TOTAL LAYERS; PUBLIC LAYERS; PRIVATE LAYERS");
|
||||
errorPrintWriter = new PrintWriter(errorBW);
|
||||
errorPrintWriter.println("SCOPE;");
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// final Path destination = Paths.get("report_matching_gn_catalogue.csv");
|
||||
// Files.w(re, destination);
|
||||
|
||||
List<String> scopesProd = new ArrayList<String>();
|
||||
|
||||
//RuntimeResourceReader readerRR;
|
||||
try {
|
||||
//MODE-1
|
||||
// readerRR = new RuntimeResourceReader(rootScope, platformName, null);
|
||||
// System.out.println(readerRR.toString());
|
||||
// System.out.println("Using GN: "+readerRR.getParameters());
|
||||
// System.out.println("Scopes are: "+readerRR.getScopes().size());
|
||||
// scopesProd.addAll(readerRR.getScopes());
|
||||
|
||||
//MODE-2
|
||||
Map<String,String> mapScopes = GetAllInfrastructureScopes.loadMapOfScopeNameToFullScope(rootScope);
|
||||
scopesProd.addAll(mapScopes.values());
|
||||
}
|
||||
catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("Read "+scopesProd.size() +" VREs from root scope: "+rootScope);
|
||||
int i = 0;
|
||||
for (String vre : scopesProd) {
|
||||
System.out.println(++i +"; "+vre);
|
||||
}
|
||||
|
||||
System.out.println("Scope found: "+scopesProd.size());
|
||||
|
||||
int count = 0;
|
||||
try{
|
||||
|
||||
for(String scope:scopesProd){
|
||||
count++;
|
||||
System.out.println("\n\n#"+count+" of "+scopesProd.size()+ " - Fetching scope: "+scope);
|
||||
ScopeProvider.instance.set(scope);
|
||||
GeoNetworkPublisher reader = null;
|
||||
String gnEP = null;
|
||||
try{
|
||||
reader=GeoNetwork.get();
|
||||
gnEP = reader.getConfiguration().getGeoNetworkEndpoint();
|
||||
|
||||
}catch (Exception e) {
|
||||
System.out.println("GeoNetwork not instanciable in the scope: "+scope);
|
||||
writeError(count+"; "+scope+" ; "+e.getMessage());
|
||||
}
|
||||
|
||||
if(reader!=null){
|
||||
// Configuration config = reader.getConfiguration();
|
||||
// Account account=config.getScopeConfiguration().getAccounts().get(accountType);
|
||||
//
|
||||
// //System.out.println("User: "+account.getUser()+", Pwd: "+account.getPassword());
|
||||
// System.out.println("Admin: "+config.getAdminAccount().getUser()+", Pwd: "+config.getAdminAccount().getPassword());
|
||||
//
|
||||
// try{
|
||||
// String decryptedPassword = StringEncrypter.getEncrypter().decrypt(account.getPassword());
|
||||
// System.out.println("Decrypted Password: "+decryptedPassword);
|
||||
// }catch(Exception e){
|
||||
// System.out.println("ignoring exception during pwd decrypting");
|
||||
// }
|
||||
|
||||
|
||||
// req.addParam("keyword", "Thredds");
|
||||
final GNSearchRequest req=new GNSearchRequest();
|
||||
// req.addParam(GNSearchRequest.Param.any,"Thredds");
|
||||
GNSearchResponse resp = reader.query(req);
|
||||
int publicCount=resp.getCount();
|
||||
reader.login(loginLevel);
|
||||
int totalCount=reader.query(req).getCount();
|
||||
//System.out.println("SCOPE "+scope+" ; found "+totalCount+" (public : "+publicCount+", private :"+(totalCount-publicCount)+")");
|
||||
writeReport(count+"; "+scope+" ; "+gnEP+"; "+totalCount+" ; "+publicCount+"; "+(totalCount-publicCount));
|
||||
if(totalCount==0)
|
||||
return;
|
||||
// try{
|
||||
// int last = totalCount>MAX?totalCount:MAX;
|
||||
// for(int i=0; i<last; i++){
|
||||
// String xml = reader.getByIdAsRawString(resp.getMetadata(i).getUUID());
|
||||
// System.out.println(i+") is Thredds? "+containsString(xml, "Thredds"));
|
||||
// }
|
||||
// }catch(Exception e ){
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}finally{
|
||||
if(reportPrintWriter!=null)
|
||||
reportPrintWriter.close();
|
||||
|
||||
if(errorPrintWriter!=null)
|
||||
errorPrintWriter.close();
|
||||
|
||||
System.out.println("Performed fetching from "+count+" scopes");
|
||||
System.out.println("FINISHED!!!");
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeReport(String newline){
|
||||
|
||||
reportPrintWriter.println(newline);
|
||||
}
|
||||
|
||||
private static void writeError(String newline){
|
||||
|
||||
errorPrintWriter.println(newline);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,169 @@
|
|||
package gis;
|
||||
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.encryption.StringEncrypter;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Class RuntimeResourceReader.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Mar 10, 2017
|
||||
*/
|
||||
public class RuntimeResourceReader {
|
||||
|
||||
// public static final String GEONETWORK_END_POINT =
|
||||
// "http://geonetwork.d4science.org/geonetwork";
|
||||
|
||||
public static final Logger logger = LoggerFactory.getLogger(RuntimeResourceReader.class);
|
||||
|
||||
// private List<String> scopes = new ArrayList<String>();
|
||||
|
||||
private List<ServiceEndpointBean> listSE = new ArrayList<ServiceEndpointBean>();
|
||||
|
||||
/**
|
||||
* Instantiates a new runtime resource reader.
|
||||
*
|
||||
* @param scope the scope
|
||||
* @param platformName the platform name
|
||||
* @param endPoint the end point
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public RuntimeResourceReader(String scope, String platformName, String category, String endPoint) throws Exception {
|
||||
read(scope, platformName, category, endPoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read.
|
||||
*
|
||||
* @param scope the scope
|
||||
* @param platformName the platform name
|
||||
* @param endPoint the end point
|
||||
* @return the server parameters
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
private List<ServiceEndpointBean> read(String scope, String platformName, String category, String endPoint)
|
||||
throws Exception {
|
||||
|
||||
String originalScope = null;
|
||||
try {
|
||||
|
||||
originalScope = ScopeProvider.instance.get();
|
||||
|
||||
ScopeProvider.instance.set(scope);
|
||||
|
||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||
query.addCondition("$resource/Profile/Platform/Name/text() eq '" + platformName + "'");
|
||||
query.addCondition("$resource/Profile/Category/text() eq '" + category + "'");
|
||||
if (endPoint != null && !endPoint.isEmpty())
|
||||
query.addCondition("$resource/Profile/AccessPoint/Interface/Endpoint/text() eq '" + endPoint + "'");
|
||||
|
||||
// query.addVariable("$prop", "$resource/Profile/AccessPoint/Properties/Property")
|
||||
// .addCondition("$prop/Name/text() eq 'priority'")
|
||||
// .addCondition("$prop/Value/text() eq '1'");
|
||||
|
||||
logger.info("GeoRuntimeReader, using scope: " + scope + ", to get resource: " + platformName);
|
||||
|
||||
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
||||
|
||||
List<ServiceEndpoint> listServiceEndpoint = client.submit(query);
|
||||
if (listServiceEndpoint == null || listServiceEndpoint.isEmpty())
|
||||
throw new Exception("Cannot retrieve the runtime resource: " + platformName);
|
||||
|
||||
for (ServiceEndpoint serviceEndpoint : listServiceEndpoint) {
|
||||
|
||||
ServiceEndpointBean seb = new ServiceEndpointBean();
|
||||
|
||||
seb.setRuntime(serviceEndpoint.profile().runtime());
|
||||
|
||||
List<AccessPoint> listAp = new ArrayList<ServiceEndpoint.AccessPoint>();
|
||||
try {
|
||||
for (AccessPoint accessPoint : serviceEndpoint.profile().accessPoints()) {
|
||||
listAp.add(accessPoint);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error on reading Access point not found");
|
||||
}
|
||||
|
||||
System.out.println("sono qui");
|
||||
|
||||
seb.setListAP(listAp);
|
||||
listSE.add(seb);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Sorry, an error occurred on reading parameters in Runtime Resources", e);
|
||||
} finally {
|
||||
if (originalScope != null && !originalScope.isEmpty()) {
|
||||
ScopeProvider.instance.set(originalScope);
|
||||
logger.info("scope provider setted to orginal scope: " + originalScope);
|
||||
} else {
|
||||
ScopeProvider.instance.reset();
|
||||
logger.info("scope provider reset");
|
||||
}
|
||||
}
|
||||
|
||||
return listSE;
|
||||
}
|
||||
|
||||
public List<ServiceEndpointBean> getListSE() {
|
||||
return listSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* The main method.
|
||||
*
|
||||
* @param args the arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
String scope = "/gcube/devsec/devVRE";
|
||||
//String platformName = "GeoServer";
|
||||
|
||||
String platformName = "postgis";
|
||||
String category = "Database";
|
||||
|
||||
//scope = "/pred4s/preprod/preVRE";
|
||||
|
||||
RuntimeResourceReader reader;
|
||||
try {
|
||||
ScopeProvider.instance.set(scope);
|
||||
reader = new RuntimeResourceReader(scope, platformName, category, null);
|
||||
|
||||
for (ServiceEndpointBean seb : reader.getListSE()) {
|
||||
System.out.println("Found: " + seb);
|
||||
|
||||
List<AccessPoint> listAp = seb.getListAP();
|
||||
|
||||
for (AccessPoint ap : listAp) {
|
||||
System.out.println("username: " + ap.username());
|
||||
System.out.println("password: " + ap.password());
|
||||
try{
|
||||
String decryptedPassword = StringEncrypter.getEncrypter().decrypt(ap.password());
|
||||
System.out.println("Decrypted Password: "+decryptedPassword);
|
||||
}catch(Exception e){
|
||||
System.out.println("ignoring exception during pwd decrypting");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,167 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package gis;
|
||||
|
||||
import it.geosolutions.geonetwork.util.GNSearchRequest;
|
||||
import it.geosolutions.geonetwork.util.GNSearchResponse;
|
||||
import resources.GetAllInfrastructureScopes;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.spatial.data.geonetwork.GeoNetwork;
|
||||
import org.gcube.spatial.data.geonetwork.GeoNetworkPublisher;
|
||||
import org.gcube.spatial.data.geonetwork.LoginLevel;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.itextpdf.text.log.SysoCounter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Mar 10, 2017
|
||||
*/
|
||||
public class SE_Harvester_from_IS {
|
||||
|
||||
// GN CONFIGURATIONS
|
||||
public static String rootScope = "/d4science.research-infrastructures.eu";
|
||||
// static String rootScope = "/pred4s";
|
||||
// static String rootScope = "/gcube";
|
||||
public static final String platformName = "geoserver";
|
||||
public static final String category = "Gis";
|
||||
public static LoginLevel loginLevel = LoginLevel.ADMIN;
|
||||
|
||||
public static PrintWriter reportPrintWriter;
|
||||
public static PrintWriter errorPrintWriter;
|
||||
|
||||
public static HashSet<String> uniqueGNs = new HashSet<String>();
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
FileWriter reportWriter = new FileWriter(
|
||||
rootScope.substring(1, rootScope.length()) + "_report_" + platformName + "_harvester.csv", true);
|
||||
FileWriter errorWriter = new FileWriter(
|
||||
rootScope.substring(1, rootScope.length()) + "_error_" + platformName + "_harvester.csv", true);
|
||||
BufferedWriter reportBW = new BufferedWriter(reportWriter);
|
||||
BufferedWriter errorBW = new BufferedWriter(errorWriter);
|
||||
reportPrintWriter = new PrintWriter(reportBW);
|
||||
reportPrintWriter.println("NB.; SCOPE; SE Hosted_On; SE AccessPoint;");
|
||||
errorPrintWriter = new PrintWriter(errorBW);
|
||||
errorPrintWriter.println("SCOPE;");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// final Path destination = Paths.get("report_matching_gn_catalogue.csv");
|
||||
// Files.w(re, destination);
|
||||
|
||||
List<String> listScopes = new ArrayList<String>();
|
||||
|
||||
// RuntimeResourceReader readerRR;
|
||||
try {
|
||||
// MODE-1
|
||||
// readerRR = new RuntimeResourceReader(rootScope, platformName, null);
|
||||
// System.out.println(readerRR.toString());
|
||||
// System.out.println("Using GN: "+readerRR.getParameters());
|
||||
// System.out.println("Scopes are: "+readerRR.getScopes().size());
|
||||
// scopesProd.addAll(readerRR.getScopes());
|
||||
|
||||
// MODE-2
|
||||
Map<String, String> mapScopes = GetAllInfrastructureScopes.loadMapOfScopeNameToFullScope(rootScope);
|
||||
listScopes.addAll(mapScopes.values());
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("Read " + listScopes.size() + " VREs from root scope: " + rootScope);
|
||||
int i = 0;
|
||||
for (String vre : listScopes) {
|
||||
System.out.println(++i + "; " + vre);
|
||||
}
|
||||
|
||||
System.out.println("Scope found: " + listScopes.size());
|
||||
try {
|
||||
|
||||
searchFor(listScopes, platformName, category);
|
||||
searchFor(listScopes, "GeoServer", category);
|
||||
|
||||
System.out.println("\n\nUnique " + platformName + " addresses");
|
||||
uniqueGNs.stream().forEach(s -> System.out.println(s));
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (reportPrintWriter != null)
|
||||
reportPrintWriter.close();
|
||||
|
||||
if (errorPrintWriter != null)
|
||||
errorPrintWriter.close();
|
||||
|
||||
System.out.println("Performed fetching from " + listScopes.size() + " scopes");
|
||||
System.out.println("FINISHED!!!");
|
||||
}
|
||||
}
|
||||
|
||||
private static void searchFor(List<String> listScopes, String platformName, String category) {
|
||||
|
||||
int count = 0;
|
||||
int writerCount = 0;
|
||||
try {
|
||||
|
||||
for (String scope : listScopes) {
|
||||
count++;
|
||||
System.out.println("\n\n#" + count + " of " + listScopes.size() + " - Fetching scope: " + scope);
|
||||
|
||||
RuntimeResourceReader rrr = new RuntimeResourceReader(scope, platformName, category, null);
|
||||
|
||||
List<ServiceEndpointBean> listSE = rrr.getListSE();
|
||||
|
||||
for (ServiceEndpointBean seb : listSE) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (AccessPoint ap : seb.getListAP()) {
|
||||
sb.append(ap.address());
|
||||
sb.append(", ");
|
||||
|
||||
uniqueGNs.add(ap.address());
|
||||
}
|
||||
|
||||
sb.toString();
|
||||
writerCount++;
|
||||
writeReport(
|
||||
writerCount + "; " + scope + " ; " + seb.getRuntime().hostedOn() + "; " + sb.toString());
|
||||
|
||||
}
|
||||
|
||||
Thread.sleep(200);
|
||||
|
||||
// if(count==10)
|
||||
// break;
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeReport(String newline) {
|
||||
|
||||
reportPrintWriter.println(newline);
|
||||
}
|
||||
|
||||
private static void writeError(String newline) {
|
||||
|
||||
errorPrintWriter.println(newline);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package gis;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||
|
||||
/**
|
||||
* The Class ServerParameters.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it May 16, 2017
|
||||
*/
|
||||
public class ServiceEndpointBean implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 2459971193655529274L;
|
||||
|
||||
protected org.gcube.common.resources.gcore.ServiceEndpoint.Runtime runtime;
|
||||
protected List<AccessPoint> listAP;
|
||||
|
||||
public ServiceEndpointBean() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public ServiceEndpointBean(org.gcube.common.resources.gcore.ServiceEndpoint.Runtime runtime, List<AccessPoint> listAP) {
|
||||
super();
|
||||
this.runtime = runtime;
|
||||
this.listAP = listAP;
|
||||
}
|
||||
|
||||
public org.gcube.common.resources.gcore.ServiceEndpoint.Runtime getRuntime() {
|
||||
return runtime;
|
||||
}
|
||||
|
||||
public List<AccessPoint> getListAP() {
|
||||
return listAP;
|
||||
}
|
||||
|
||||
public void setRuntime(org.gcube.common.resources.gcore.ServiceEndpoint.Runtime runtime2) {
|
||||
this.runtime = runtime2;
|
||||
}
|
||||
|
||||
public void setListAP(List<AccessPoint> listAP) {
|
||||
this.listAP = listAP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("ServiceEndpoint [runtime=");
|
||||
builder.append(runtime);
|
||||
builder.append(", listAP=");
|
||||
builder.append(listAP);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -49,7 +49,7 @@ public class GeonetworkResolverTest {
|
|||
/*String scopeValue ="/gcube/devsec/devVRE";
|
||||
String remainValue = "/srv/en/mef.export";
|
||||
String queryString = "scope=/gcube/devsec/devVRE&remainPath=/srv/en/mef.export&version=2.0.2&request=GetCapabilities&service=CSW";
|
||||
ServerParameters geonetworkParams = new ServerParameters("http://geoserver-dev2.d4science-ii.research-infrastructures.eu/geonetwork", "", "");
|
||||
ServiceEndpointParameters geonetworkParams = new ServiceEndpointParameters("http://geoserver-dev2.d4science-ii.research-infrastructures.eu/geonetwork", "", "");
|
||||
|
||||
String newQueryString = purgeScopeFromQueryString(scopeValue, queryString);
|
||||
logger.info("Purged query string from "+scopeValue+" is: "+newQueryString);
|
||||
|
|
|
@ -18,7 +18,7 @@ public class GisResolverTest {
|
|||
public static void main(String[] args) {
|
||||
GisResolver gisResolver = new GisResolver();
|
||||
ScopeProvider.instance.set(scope);
|
||||
//ServerParameters geonetworkParams = getCachedServerParameters(scope);
|
||||
//ServiceEndpointParameters geonetworkParams = getCachedServerParameters(scope);
|
||||
try {
|
||||
GisLayerItem gisLayerItem = gisResolver.getGisLayerForLayerUUID(null, scope, gisUUID);
|
||||
} catch (Exception e) {
|
||||
|
@ -33,7 +33,7 @@ public class GisResolverTest {
|
|||
String scope = "/gcube/devsec/devVRE";
|
||||
String UUID = "177e1c3c-4a22-4ad9-b015-bfc443d16cb8";
|
||||
try {
|
||||
ServerParameters geonetworkParams = gisResolver.getCachedServerParameters(scope);
|
||||
ServiceEndpointParameters geonetworkParams = gisResolver.getCachedServerParameters(scope);
|
||||
String wmsRequest = gisResolver.getLayerWmsRequest(scope, UUID, geonetworkParams);
|
||||
System.out.println("Final url is: " + wmsRequest);
|
||||
wmsRequest = URLEncoder.encode(wmsRequest, UTF_8);
|
||||
|
|
|
@ -84,7 +84,7 @@ public class ServiceEndpointReader {
|
|||
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)+"...");
|
||||
+ accessPointPwd+"...");
|
||||
|
||||
System.out.println("AccessPoint pwd is: "+accessPointPwd);
|
||||
}
|
||||
|
|
|
@ -1,23 +1,10 @@
|
|||
package org.gcube.datatransfer.test;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.ResponseBuilder;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.storagehub.client.StreamDescriptor;
|
||||
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
||||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||
import org.gcube.datatransfer.resolver.catalogue.resource.CkanCatalogueConfigurationsReader;
|
||||
import org.gcube.datatransfer.resolver.catalogue.resource.GatewayCKANCatalogueReference;
|
||||
import org.gcube.datatransfer.resolver.init.UriResolverSmartGearManagerInit;
|
||||
import org.gcube.datatransfer.resolver.services.CatalogueResolver;
|
||||
import org.gcube.datatransfer.resolver.services.StorageHubResolver;
|
||||
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||
import org.gcube.datatransfer.resolver.shub.StorageHubMetadataResponseBuilder;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.itextpdf.text.log.SysoCounter;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -34,7 +21,7 @@ public class StorageHubTest {
|
|||
private static String vreName = "BlueBridgeProject";
|
||||
|
||||
private String rootContextScope = "/d4science.research-infrastructures.eu";
|
||||
private String authorizationToken = "ea16e0fa-722a-4589-83b0-0a731d2d4039-843339462";
|
||||
private String authorizationToken = "";
|
||||
|
||||
//@Before
|
||||
public void init() {
|
||||
|
|
|
@ -0,0 +1,161 @@
|
|||
package resources;
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.client;
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* The Class GcoreEndpointReader.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Jun 10, 2016
|
||||
*/
|
||||
public class GcoreEndpointReader implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = 7631710353375893823L;
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GcoreEndpointReader.class);
|
||||
private List<String> endPoints;
|
||||
|
||||
/**
|
||||
* Instantiates a new gcore endpoint reader.
|
||||
*
|
||||
* @param scope the scope
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public GcoreEndpointReader(String scope, String serviceClass, String serviceName, String ckanResource) throws Exception {
|
||||
|
||||
String currentScope = ScopeProvider.instance.get();
|
||||
try{
|
||||
|
||||
logger.info("set scope "+scope);
|
||||
ScopeProvider.instance.set(scope);
|
||||
|
||||
SimpleQuery query = queryFor(GCoreEndpoint.class);
|
||||
query.addCondition(String.format("$resource/Profile/ServiceClass/text() eq '%s'",serviceClass));
|
||||
query.addCondition("$resource/Profile/DeploymentData/Status/text() eq 'ready'");
|
||||
query.addCondition(String.format("$resource/Profile/ServiceName/text() eq '%s'",serviceName));
|
||||
query.addCondition(String.format("$resource/Scopes/Scope/text()[.='%s']", scope)); // i.e. check the resource contains among the scopes this one
|
||||
query.setResult("$resource/Profile/AccessPoint/RunningInstanceInterfaces//Endpoint[@EntryName/string() eq \""+ckanResource+"\"]/text()");
|
||||
|
||||
logger.debug("submitting quey "+query.toString());
|
||||
|
||||
DiscoveryClient<String> client = client();
|
||||
List<String> endpoints = client.submit(query);
|
||||
if (endpoints == null || endpoints.isEmpty()) throw new Exception("Cannot retrieve the GCoreEndpoint serviceName: "+serviceName +", serviceClass: " +serviceClass +", in scope: "+scope);
|
||||
|
||||
|
||||
for (String endpoint : endpoints) {
|
||||
System.out.println("end point "+endpoint);
|
||||
}
|
||||
this.endPoints = endpoints;
|
||||
if(endPoints==null)
|
||||
throw new Exception("Endpoint:"+ckanResource+", is null for serviceName: "+serviceName +", serviceClass: " +serviceClass +", in scope: "+scope);
|
||||
|
||||
logger.info("found entyname "+endPoints+" for ckanResource: "+ckanResource);
|
||||
|
||||
/*Group<Endpoint> accessPoints = se.profile().endpoints();
|
||||
if(accessPoints.size()==0) throw new Exception("Endpoint in serviceName serviceName: "+serviceName +", serviceClass: " +serviceClass +", in scope: "+scope +" not found");
|
||||
|
||||
Endpoint ep = accessPoints.iterator().next();
|
||||
|
||||
String epName = ep.name();
|
||||
|
||||
System.out.println(epName);*/
|
||||
|
||||
}catch(Exception e){
|
||||
String error = "An error occurred during GCoreEndpoint discovery, serviceName: "+serviceName +", serviceClass: " +serviceClass +", in scope: "+scope +".";
|
||||
logger.error(error, e);
|
||||
throw new Exception(error);
|
||||
}finally{
|
||||
logger.info("scope provider reset");
|
||||
ScopeProvider.instance.set(currentScope);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the end points.
|
||||
*
|
||||
* @return the end points
|
||||
*/
|
||||
public List<String> getEndPoints() {
|
||||
|
||||
return endPoints;
|
||||
}
|
||||
|
||||
// private static String[] scopes = {"" +
|
||||
// "/d4science.research-infrastructures.eu/gCubeApps",
|
||||
// "/d4science.research-infrastructures.eu/FARM",
|
||||
// "/d4science.research-infrastructures.eu/D4Research",
|
||||
// "/d4science.research-infrastructures.eu/OpenAIRE",
|
||||
// "/d4science.research-infrastructures.eu/Edison",
|
||||
// "/d4science.research-infrastructures.eu/SmartArea",
|
||||
// "/d4science.research-infrastructures.eu/SoBigData"};
|
||||
static PrintWriter reportPrintWriter;
|
||||
static PrintWriter errorPrintWriter;
|
||||
|
||||
/**
|
||||
* The main method.
|
||||
*
|
||||
* @param args the arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
FileWriter reportWriter = null;
|
||||
|
||||
final String ckanResource = "org.gcube.data.access.ckanconnector.CkanConnector";
|
||||
final String serviceName = "CkanConnector";
|
||||
final String serviceClass = "DataAccess";
|
||||
|
||||
final String rootScope = "/d4science.research-infrastructures.eu";
|
||||
|
||||
try{
|
||||
reportWriter = new FileWriter("report_ckanconnector.csv", true);
|
||||
BufferedWriter reportBW = new BufferedWriter(reportWriter);
|
||||
reportPrintWriter = new PrintWriter(reportBW);
|
||||
reportPrintWriter.println("NB.; SCOPE; END POINTS;");
|
||||
|
||||
try {
|
||||
int i = 0;
|
||||
Map<String, String> scopes = GetAllInfrastructureScopes.loadMapOfScopeNameToFullScope(rootScope);
|
||||
for (String scope : scopes.values()) {
|
||||
System.out.println("Ckecking scope: "+scope);
|
||||
ScopeProvider.instance.set(scope);
|
||||
try{
|
||||
i++;
|
||||
GcoreEndpointReader reader = new GcoreEndpointReader(scope, serviceClass, serviceName, ckanResource);
|
||||
System.out.println("Appending endpoints: "+reader.getEndPoints());
|
||||
reportPrintWriter.println(i+"; "+scope+"; "+reader.getEndPoints());
|
||||
}catch(Exception e){
|
||||
i--;
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
if(reportPrintWriter!=null)
|
||||
reportPrintWriter.close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,221 @@
|
|||
package resources;
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.client;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.common.scope.impl.ScopeBean.Type;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.Query;
|
||||
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
|
||||
/**
|
||||
* The Class GetAllInfrastructureScopes.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* May 16, 2019
|
||||
*/
|
||||
public class GetAllInfrastructureScopes {
|
||||
|
||||
public static Logger logger = LoggerFactory.getLogger(GetAllInfrastructureScopes.class);
|
||||
|
||||
protected static final String RESOURCE_PROFILE_NAME_TEXT = "/Resource/Profile/Name/text()";
|
||||
|
||||
|
||||
/**
|
||||
* Load map of scope name to full scope.
|
||||
*
|
||||
* @param rootScope the root scope
|
||||
* @return the map of binding between (VRE_NAME, FULL_SCOPE_OF_VRE_NAME)
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public static Map<String, String> loadMapOfScopeNameToFullScope(String rootScope) throws Exception{
|
||||
|
||||
String originalScope = ScopeProvider.instance.get();
|
||||
|
||||
try{
|
||||
ScopeBean scopeBean = null;
|
||||
Map<String, String> scopeNameToFullScopeMap = new HashMap<String,String>();
|
||||
ScopeProvider.instance.set(rootScope);
|
||||
String secondaryType = Type.INFRASTRUCTURE.name();
|
||||
scopeBean = new ScopeBean(rootScope);
|
||||
logger.info("Added the couple ({},{}) as {} (NAME, FULL SCOPE) into map", scopeBean.name(), rootScope, secondaryType);
|
||||
scopeNameToFullScopeMap.put(scopeBean.name(), rootScope);
|
||||
List<String> listVOScopes = getListOfVOScopes(secondaryType);
|
||||
logger.info("Searching for secondaryType={} the scope/s found is/are: " +secondaryType, listVOScopes);
|
||||
|
||||
//int noVOTypeCount = 0;
|
||||
for (String voScope : listVOScopes) {
|
||||
//int count = voScope.length() - voScope.replace("/", "").length();
|
||||
scopeBean = new ScopeBean(voScope);
|
||||
//IS A VO
|
||||
//if(count==2){
|
||||
if(scopeBean.is(Type.VO)){
|
||||
secondaryType = Type.VO.name();
|
||||
logger.info("{} is a {}...",voScope,secondaryType);
|
||||
ScopeProvider.instance.set(voScope);
|
||||
scopeBean = new ScopeBean(voScope);
|
||||
logger.info("Added the couple ({},{}) as {} (NAME, FULL SCOPE) into map", scopeBean.name(), voScope, secondaryType);
|
||||
scopeNameToFullScopeMap.put(scopeBean.name(), voScope);
|
||||
secondaryType = Type.VRE.name();
|
||||
List<String> listVREs = getListOfResourcesForSecondaryType(secondaryType);
|
||||
logger.debug("VREs found for VO "+voScope+ " is/are "+listVREs.size()+ ": "+listVREs);
|
||||
for (String vreName : listVREs) {
|
||||
String vreScope = String.format("%s/%s", voScope,vreName);
|
||||
scopeNameToFullScopeMap.put(vreName, vreScope);
|
||||
}
|
||||
|
||||
}else{
|
||||
//noVOTypeCount++;
|
||||
logger.info(voScope +" is not a VO, skipping it");
|
||||
}
|
||||
}
|
||||
|
||||
/*System.out.println("Total VO is: "+(listVOScopes.size()+noVOTypeCount));
|
||||
for (String vreName : vreNameFullScope.keySet()) {
|
||||
System.out.println("VRE Name: "+vreName + " has scope: "+vreNameFullScope.get(vreName));
|
||||
}*/
|
||||
|
||||
logger.info("Total VRE is: "+scopeNameToFullScopeMap.size());
|
||||
return scopeNameToFullScopeMap;
|
||||
|
||||
}catch(Exception e ){
|
||||
throw new Exception("Error on loading the map of VRE nameto scope: ", e);
|
||||
}
|
||||
finally{
|
||||
if(originalScope!=null && !originalScope.isEmpty()){
|
||||
ScopeProvider.instance.set(originalScope);
|
||||
}else
|
||||
ScopeProvider.instance.reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the list of resources for secondary type.
|
||||
*
|
||||
* @param secondaryType the secondary type
|
||||
* @return the list of resource names for the input secondary type
|
||||
*/
|
||||
private static List<String> getListOfResourcesForSecondaryType(String secondaryType) {
|
||||
|
||||
String queryString = "for $profile in collection('/db/Profiles/GenericResource')//Resource " +
|
||||
"where $profile/Profile/SecondaryType/string() eq '"+secondaryType+"' return $profile";
|
||||
|
||||
List<String> listResourceName = new ArrayList<String>();
|
||||
|
||||
try {
|
||||
logger.info("Trying to fetch GenericResource in the scope: "+ScopeProvider.instance.get()+", SecondaryType: " + secondaryType);
|
||||
Query q = new QueryBox(queryString);
|
||||
DiscoveryClient<String> client = client();
|
||||
List<String> listGenericResources = client.submit(q);
|
||||
|
||||
logger.info("# of GenericResource returned are: "+listGenericResources.size());
|
||||
|
||||
if (listGenericResources == null || listGenericResources.size() == 0)
|
||||
throw new Exception("GenericResource with SecondaryType: " + secondaryType + ", is not registered in the scope: "+ScopeProvider.instance.get());
|
||||
else {
|
||||
|
||||
|
||||
for (String genericResource : listGenericResources) {
|
||||
try{
|
||||
String elem = genericResource;
|
||||
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Document document = docBuilder.parse(new InputSource(new StringReader(elem)));
|
||||
Element rootElement = document.getDocumentElement();
|
||||
XPathHelper helper = new XPathHelper(rootElement);
|
||||
List<String> resourceNames = helper.evaluate(RESOURCE_PROFILE_NAME_TEXT);
|
||||
|
||||
if(resourceNames!=null && resourceNames.size()>0)
|
||||
listResourceName.add(resourceNames.get(0));
|
||||
|
||||
}catch(Exception e){
|
||||
throw new Exception("Error during parsing the generic resource: "+genericResource + " in the scope: "+ScopeProvider.instance.get());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error while trying to fetch generic resource from the infrastructure", e);
|
||||
}
|
||||
|
||||
return listResourceName;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the list of resources for secondary type.
|
||||
*
|
||||
* @param secondaryType the secondary type
|
||||
* @return the list of resource names for the input secondary type
|
||||
*/
|
||||
private static List<String> getListOfVOScopes(String secondaryType) {
|
||||
|
||||
String queryString = "for $profile in collection('/db/Profiles/GenericResource')//Resource " +
|
||||
"where $profile/Profile/SecondaryType/string() eq '"+secondaryType+"' return $profile";
|
||||
|
||||
List<String> listOfVOScopes = new ArrayList<String>();
|
||||
|
||||
try {
|
||||
logger.info("Trying to fetch GenericResource in the scope: "+ScopeProvider.instance.get()+", SecondaryType: " + secondaryType);
|
||||
Query q = new QueryBox(queryString);
|
||||
DiscoveryClient<String> client = client();
|
||||
List<String> listGenericResources = client.submit(q);
|
||||
|
||||
logger.info("# of GenericResource returned searching for secondaryType= "+secondaryType+" is/are: "+listGenericResources.size());
|
||||
|
||||
if (listGenericResources == null || listGenericResources.size() == 0)
|
||||
throw new Exception("GenericResource with SecondaryType: " + secondaryType + ", is not registered in the scope: "+ScopeProvider.instance.get());
|
||||
else {
|
||||
|
||||
|
||||
for (String genericResource : listGenericResources) {
|
||||
try{
|
||||
String elem = genericResource;
|
||||
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Document document = docBuilder.parse(new InputSource(new StringReader(elem)));
|
||||
Element rootElement = document.getDocumentElement();
|
||||
XPathHelper helper = new XPathHelper(rootElement);
|
||||
// List<String> resourceNames = helper.evaluate(RESOURCE_PROFILE_NAME_TEXT);
|
||||
//
|
||||
// if(resourceNames!=null && resourceNames.size()>0)
|
||||
// listResourceName.add(resourceNames.get(0));
|
||||
|
||||
List<String> scopes = helper.evaluate("/Resource/Profile/Body/infrastructures/infrastructure/vos/vo/scope/text()");
|
||||
for (String scopeFound : scopes) {
|
||||
listOfVOScopes.add(scopeFound);
|
||||
}
|
||||
|
||||
}catch(Exception e){
|
||||
throw new Exception("Error during parsing the generic resource: "+genericResource + " in the scope: "+ScopeProvider.instance.get());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error while trying to fetch generic resource from the infrastructure", e);
|
||||
}
|
||||
|
||||
return listOfVOScopes;
|
||||
|
||||
}
|
||||
}
|
|
@ -15,19 +15,10 @@ import java.nio.file.StandardCopyOption;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.ResponseBuilder;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.gcube.common.storagehub.client.StreamDescriptor;
|
||||
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
||||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileReader;
|
||||
import org.gcube.datatransfer.resolver.services.StorageHubResolver;
|
||||
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||
import org.gcube.datatransfer.resolver.shub.StorageHubMetadataResponseBuilder;
|
||||
import org.gcube.datatransfer.resolver.util.HTTPCallsUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -42,7 +33,7 @@ import org.slf4j.LoggerFactory;
|
|||
public class TestResolvers {
|
||||
|
||||
|
||||
public static final String URI_RESOLVER_SERVICE_ENDPOINT = "https://data1-d.d4science.net";
|
||||
public static final String URI_RESOLVER_SERVICE_ENDPOINT = "https://data.dev.d4science.org";
|
||||
|
||||
public static final Logger logger = LoggerFactory.getLogger(TestResolvers.class);
|
||||
|
||||
|
|
|
@ -12,3 +12,9 @@
|
|||
/preprod.gcubekey
|
||||
/pred4s.gcubekey
|
||||
/log4j.properties
|
||||
/D4OS.gcubekey
|
||||
/D4Research.gcubekey
|
||||
/OpenAIRE.gcubekey
|
||||
/ParthenosVO.gcubekey
|
||||
/SmartArea.gcubekey
|
||||
/SoBigData.gcubekey
|
||||
|
|
Loading…
Reference in New Issue