From cda5599d275c637bcb9d4d83ea39391ce70d70c1 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 21 Apr 2022 09:44:18 +0200 Subject: [PATCH 1/6] #23156 Added support to `query_string` to CatalogueResolver --- .settings/org.eclipse.wst.common.component | 29 ++++++++++++------- CHANGELOG.md | 14 ++++++--- pom.xml | 2 +- .../resolver/catalogue/CatalogueRequest.java | 22 ++++++++------ .../resolver/services/CatalogueResolver.java | 17 +++++++++++ 5 files changed, 60 insertions(+), 24 deletions(-) diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 589972b..1331b59 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,61 +1,70 @@ - + - - + + + + - + + - + + - + + - + + - + + - + + - + + diff --git a/CHANGELOG.md b/CHANGELOG.md index 324d516..527e224 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,13 @@ 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.8.0-SNAPSHOT] - 2022-04-20 + +**New** + +- [#23156] CatalogueResolver enhanced to manage (create/resolve) an input query string + +## [v2.7.2] - 2022-04-06 **New** @@ -18,7 +24,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 +36,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 +47,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** diff --git a/pom.xml b/pom.xml index 24595a4..3df99b0 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.gcube.data.transfer uri-resolver - 2.7.2 + 2.8.0-SNAPSHOT war 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. diff --git a/src/main/java/org/gcube/datatransfer/resolver/catalogue/CatalogueRequest.java b/src/main/java/org/gcube/datatransfer/resolver/catalogue/CatalogueRequest.java index 1a025e5..320ee3c 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/catalogue/CatalogueRequest.java +++ b/src/main/java/org/gcube/datatransfer/resolver/catalogue/CatalogueRequest.java @@ -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(); } diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java index 6f781a5..7772103 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java @@ -2,6 +2,7 @@ package org.gcube.datatransfer.resolver.services; import java.net.URI; import java.net.URL; +import java.net.URLEncoder; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -33,6 +34,7 @@ import org.gcube.datatransfer.resolver.catalogue.resource.CkanCatalogueConfigura import org.gcube.datatransfer.resolver.catalogue.resource.GatewayCKANCatalogueReference; import org.gcube.datatransfer.resolver.catalogue.resource.GetAllInfrastructureScopes; import org.gcube.datatransfer.resolver.services.error.ExceptionManager; +import org.gcube.datatransfer.resolver.util.UrlEncoderUtil; import org.gcube.datatransfer.resolver.util.Util; import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VRE; import org.gcube.smartgears.utils.InnerMethodName; @@ -115,6 +117,15 @@ public class CatalogueResolver { + " is a private item (to VRE) so using protected access to CKAN portlet: " + itemCatalogueURL); } + String queryString = req.getQueryString(); + if (queryString != null) { + logger.debug("Query string found: " + queryString); + String qsEnc = URLEncoder.encode(queryString, "UTF-8"); + logger.info("Adding encoded query string " + qsEnc + " to Catalogue URL response"); + + itemCatalogueURL += "?" + qsEnc; + } + return Response.seeOther(new URL(itemCatalogueURL).toURI()).build(); } catch (Exception e) { @@ -190,6 +201,12 @@ public class CatalogueResolver { } String linkURL = String.format("%s/%s/%s/%s", serverUrl, rc.getId(), vreName, jsonRequest.getEntity_name()); + + if (jsonRequest.getQuery_string() != null) { + String qsEnc = URLEncoder.encode(jsonRequest.getQuery_string(), "UTF-8"); + linkURL += "?" + qsEnc; + } + logger.info("Returining Catalogue URL: " + linkURL); return Response.ok(linkURL).header("Location", linkURL).build(); -- 2.17.1 From ca07d7ae0ea9099e03ef2b1e96b8931e869482de Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 21 Apr 2022 11:08:43 +0200 Subject: [PATCH 2/6] Uppdated CatalogueResolver by adding query_string=BASE64[query_string_value] --- .../CatalogueStaticConfigurations.java | 4 ++-- .../resolver/services/CatalogueResolver.java | 19 +++++++++++-------- .../datatransfer/test/StorageHubTest.java | 13 ------------- src/test/java/rest/TestResolvers.java | 11 +---------- 4 files changed, 14 insertions(+), 33 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/CatalogueStaticConfigurations.java b/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/CatalogueStaticConfigurations.java index 07cb718..32da00a 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/CatalogueStaticConfigurations.java +++ b/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/CatalogueStaticConfigurations.java @@ -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; } diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java index 7772103..e4f749e 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java @@ -19,6 +19,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; @@ -34,7 +35,6 @@ import org.gcube.datatransfer.resolver.catalogue.resource.CkanCatalogueConfigura import org.gcube.datatransfer.resolver.catalogue.resource.GatewayCKANCatalogueReference; import org.gcube.datatransfer.resolver.catalogue.resource.GetAllInfrastructureScopes; import org.gcube.datatransfer.resolver.services.error.ExceptionManager; -import org.gcube.datatransfer.resolver.util.UrlEncoderUtil; import org.gcube.datatransfer.resolver.util.Util; import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VRE; import org.gcube.smartgears.utils.InnerMethodName; @@ -94,6 +94,7 @@ public class CatalogueResolver { try { InnerMethodName.instance.set("resolveCataloguePublicLink"); + ItemCatalogueURLs itemCatalogueURLs = getItemCatalogueURLs(req, vreName, entityContext, entityName); String itemCatalogueURL; @@ -113,17 +114,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.debug("Query string found: " + queryString); - String qsEnc = URLEncoder.encode(queryString, "UTF-8"); - logger.info("Adding encoded query string " + qsEnc + " to Catalogue URL response"); - - itemCatalogueURL += "?" + qsEnc; + 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(); diff --git a/src/test/java/org/gcube/datatransfer/test/StorageHubTest.java b/src/test/java/org/gcube/datatransfer/test/StorageHubTest.java index 7e146c2..02a424e 100644 --- a/src/test/java/org/gcube/datatransfer/test/StorageHubTest.java +++ b/src/test/java/org/gcube/datatransfer/test/StorageHubTest.java @@ -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; /** diff --git a/src/test/java/rest/TestResolvers.java b/src/test/java/rest/TestResolvers.java index 2b510cb..f5a4ac5 100644 --- a/src/test/java/rest/TestResolvers.java +++ b/src/test/java/rest/TestResolvers.java @@ -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); -- 2.17.1 From 25f54f122c4264f7ef6e7152f8814e1f407bb03b Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 22 Apr 2022 16:57:30 +0200 Subject: [PATCH 3/6] removed encoding from POST method --- .settings/org.eclipse.wst.common.component | 29 ++++++++++++------- .../resolver/services/CatalogueResolver.java | 3 +- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 1331b59..cc21f04 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,13 +1,15 @@ - + - - + + + + @@ -15,7 +17,8 @@ - + + @@ -23,7 +26,8 @@ - + + @@ -31,7 +35,8 @@ - + + @@ -39,7 +44,8 @@ - + + @@ -47,7 +53,8 @@ - + + @@ -55,7 +62,8 @@ - + + @@ -63,7 +71,8 @@ - + + diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java index e4f749e..41ea728 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java @@ -206,8 +206,7 @@ public class CatalogueResolver { String linkURL = String.format("%s/%s/%s/%s", serverUrl, rc.getId(), vreName, jsonRequest.getEntity_name()); if (jsonRequest.getQuery_string() != null) { - String qsEnc = URLEncoder.encode(jsonRequest.getQuery_string(), "UTF-8"); - linkURL += "?" + qsEnc; + linkURL += "?" + jsonRequest.getQuery_string(); } logger.info("Returining Catalogue URL: " + linkURL); -- 2.17.1 From 20d9a782bfe94105a6c72fca45275c69ea3352d5 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 27 Apr 2022 14:47:58 +0200 Subject: [PATCH 4/6] merged with #23213 bug fixing --- .settings/org.eclipse.wst.common.component | 30 +++++++++++++++------- CHANGELOG.md | 8 +++++- enunciate.xml | 8 +++++- pom.xml | 10 +------- 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index cc21f04..fc105e3 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,6 @@ - + + @@ -8,7 +9,8 @@ - + + @@ -17,7 +19,8 @@ - + + @@ -26,7 +29,8 @@ - + + @@ -35,7 +39,8 @@ - + + @@ -44,7 +49,11 @@ - + + uses + + + @@ -53,7 +62,8 @@ - + + @@ -62,7 +72,8 @@ - + + @@ -71,7 +82,8 @@ - + + diff --git a/CHANGELOG.md b/CHANGELOG.md index 527e224..f1c2f1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,12 +4,18 @@ 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.8.0-SNAPSHOT] - 2022-04-20 +## [v2.8.0-SNAPSHOT] - 2022-04-27 **New** - [#23156] CatalogueResolver enhanced to manage (create/resolve) an input query string +## [v2.7.3-SNAPSHOT] - 2022-04-27 + +**Bug Fixing** + +- [#23213] Fixed NoClassDefFoundError: org/geotoolkit/xml/XML + ## [v2.7.2] - 2022-04-06 **New** diff --git a/enunciate.xml b/enunciate.xml index 52d0ac2..b097c2d 100644 --- a/enunciate.xml +++ b/enunciate.xml @@ -10,11 +10,17 @@ pattern="org.gcube.datatransfer.resolver.services.UriResolverIndex" /> - + + + + + + diff --git a/pom.xml b/pom.xml index 3df99b0..3bd3cef 100644 --- a/pom.xml +++ b/pom.xml @@ -249,15 +249,7 @@ 4.8.2 test - - - - org.geotoolkit - geotk-xml-base - 3.20-geoapi-3.0 - provided - - + -- 2.17.1 From 71a1b524785551ec3f1f5c74ebaee9571fef2913 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 3 May 2022 17:01:49 +0200 Subject: [PATCH 5/6] removed unused imports --- .../gcube/datatransfer/resolver/services/CatalogueResolver.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java index 41ea728..fb1a8e2 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java @@ -2,7 +2,6 @@ package org.gcube.datatransfer.resolver.services; import java.net.URI; import java.net.URL; -import java.net.URLEncoder; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutionException; -- 2.17.1 From 89d3c847b48c33a9e98e43b96f8271a5b6be907a Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 13 Jun 2022 14:04:30 +0200 Subject: [PATCH 6/6] Bug fixing #23495 Removed the check on the gcube token stored in thread local --- .settings/org.eclipse.wst.common.component | 41 ++-- CHANGELOG.md | 7 +- pom.xml | 2 +- .../services/AnalyticsCreateResolver.java | 27 ++- .../services/KnimeCreateResolver.java | 14 +- .../resolver/services/WekeoResolver.java | 15 +- ...CatalogueMatching_SCOPE_CKANCONNECTOR.java | 158 +++++++++++++ .../datatransfer/test/StorageHubTest.java | 2 +- .../java/resources/GcoreEndpointReader.java | 161 +++++++++++++ .../resources/GetAllInfrastructureScopes.java | 221 ++++++++++++++++++ 10 files changed, 599 insertions(+), 49 deletions(-) create mode 100644 src/test/java/catalogue/CatalogueMatching_SCOPE_CKANCONNECTOR.java create mode 100644 src/test/java/resources/GcoreEndpointReader.java create mode 100644 src/test/java/resources/GetAllInfrastructureScopes.java diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index fc105e3..43b83d7 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,5 @@ - + @@ -8,8 +8,12 @@ - - + + + + + + @@ -19,7 +23,9 @@ - + + + @@ -29,7 +35,9 @@ - + + + @@ -39,7 +47,9 @@ - + + + @@ -49,10 +59,9 @@ - - uses - - + + + @@ -62,7 +71,9 @@ - + + + @@ -72,7 +83,9 @@ - + + + @@ -82,7 +95,9 @@ - + + + diff --git a/CHANGELOG.md b/CHANGELOG.md index f1c2f1b..428bc70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,12 +4,17 @@ 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.8.0-SNAPSHOT] - 2022-04-27 +## [v2.8.1-SNAPSHOT] - 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** diff --git a/pom.xml b/pom.xml index 3bd3cef..3ff57c4 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.gcube.data.transfer uri-resolver - 2.8.0-SNAPSHOT + 2.8.1-SNAPSHOT war 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. diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/AnalyticsCreateResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/AnalyticsCreateResolver.java index 4b9a1c3..2f76d81 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/AnalyticsCreateResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/AnalyticsCreateResolver.java @@ -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()) { @@ -148,8 +138,15 @@ public class AnalyticsCreateResolver { "Mandatory body parameter 'operatorId' not found or empty in the JSON object", this.getClass(), helpURI); } - + 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)) { @@ -162,7 +159,8 @@ 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 theMap = new HashMap(); + Map theMap = new HashMap(); theMap.put("owner", owner); + metadata.setMap(theMap); URL thePublicLink = null; try { diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/KnimeCreateResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/KnimeCreateResolver.java index d1de43d..274d32a 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/KnimeCreateResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/KnimeCreateResolver.java @@ -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(); diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/WekeoResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/WekeoResolver.java index af0c459..92dae4b 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/WekeoResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/WekeoResolver.java @@ -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); } diff --git a/src/test/java/catalogue/CatalogueMatching_SCOPE_CKANCONNECTOR.java b/src/test/java/catalogue/CatalogueMatching_SCOPE_CKANCONNECTOR.java new file mode 100644 index 0000000..822d051 --- /dev/null +++ b/src/test/java/catalogue/CatalogueMatching_SCOPE_CKANCONNECTOR.java @@ -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 scopesProd = new ArrayList(); + + // 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 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); + } + +} diff --git a/src/test/java/org/gcube/datatransfer/test/StorageHubTest.java b/src/test/java/org/gcube/datatransfer/test/StorageHubTest.java index 02a424e..485047a 100644 --- a/src/test/java/org/gcube/datatransfer/test/StorageHubTest.java +++ b/src/test/java/org/gcube/datatransfer/test/StorageHubTest.java @@ -21,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() { diff --git a/src/test/java/resources/GcoreEndpointReader.java b/src/test/java/resources/GcoreEndpointReader.java new file mode 100644 index 0000000..ee851e3 --- /dev/null +++ b/src/test/java/resources/GcoreEndpointReader.java @@ -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 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 client = client(); + List 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 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 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 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(); + } + } +} diff --git a/src/test/java/resources/GetAllInfrastructureScopes.java b/src/test/java/resources/GetAllInfrastructureScopes.java new file mode 100644 index 0000000..5eb5921 --- /dev/null +++ b/src/test/java/resources/GetAllInfrastructureScopes.java @@ -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 loadMapOfScopeNameToFullScope(String rootScope) throws Exception{ + + String originalScope = ScopeProvider.instance.get(); + + try{ + ScopeBean scopeBean = null; + Map scopeNameToFullScopeMap = new HashMap(); + 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 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 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 getListOfResourcesForSecondaryType(String secondaryType) { + + String queryString = "for $profile in collection('/db/Profiles/GenericResource')//Resource " + + "where $profile/Profile/SecondaryType/string() eq '"+secondaryType+"' return $profile"; + + List listResourceName = new ArrayList(); + + try { + logger.info("Trying to fetch GenericResource in the scope: "+ScopeProvider.instance.get()+", SecondaryType: " + secondaryType); + Query q = new QueryBox(queryString); + DiscoveryClient client = client(); + List 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 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 getListOfVOScopes(String secondaryType) { + + String queryString = "for $profile in collection('/db/Profiles/GenericResource')//Resource " + + "where $profile/Profile/SecondaryType/string() eq '"+secondaryType+"' return $profile"; + + List listOfVOScopes = new ArrayList(); + + try { + logger.info("Trying to fetch GenericResource in the scope: "+ScopeProvider.instance.get()+", SecondaryType: " + secondaryType); + Query q = new QueryBox(queryString); + DiscoveryClient client = client(); + List 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 resourceNames = helper.evaluate(RESOURCE_PROFILE_NAME_TEXT); +// +// if(resourceNames!=null && resourceNames.size()>0) +// listResourceName.add(resourceNames.get(0)); + + List 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; + + } +} -- 2.17.1