diff --git a/distro/changelog.xml b/distro/changelog.xml index a826ea8..26ecb9b 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -44,9 +44,19 @@ - [Feature #4207] Uri Resolver upgrade: it must support new Geonetwork Manager + [Feature #4207] Uri Resolver upgrade: it must support new + Geonetwork Manager - [Task #4250] Geonetwork Resolver upgrade: it must return only "private" Metadata Ids for CKAN harversting + [Task #4250] Geonetwork Resolver upgrade: it must return only + "private" Metadata Ids for CKAN harversting + + Removed scope provider from several resolver + + + [Task #6119] Provide CatalogueResolver: get/resolve a link to a CKAN Entity + \ No newline at end of file diff --git a/pom.xml b/pom.xml index fe0fcbf..468fcfe 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ org.gcube.data.transfer uri-resolver - 1.8.0-SNAPSHOT + 1.9.0-SNAPSHOT war The URI Resolver is an HTTP URI resolver implemented as an HTTP servlet which gives access trough HTTP to different protocols URIs. @@ -41,6 +41,13 @@ [2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT) + + org.json + json + 20140107 + compile + + org.gcube.contentmanagement storage-manager-core diff --git a/src/main/java/org/gcube/datatransfer/resolver/applicationprofile/ApplicationProfileReader.java b/src/main/java/org/gcube/datatransfer/resolver/applicationprofile/ApplicationProfileReader.java index c3f26b6..d3336a0 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/applicationprofile/ApplicationProfileReader.java +++ b/src/main/java/org/gcube/datatransfer/resolver/applicationprofile/ApplicationProfileReader.java @@ -40,19 +40,22 @@ public class ApplicationProfileReader { private String appId; private String scope; private ApplicationProfile applicationProfile; + private boolean useRootScope = false; /** * Instantiates a new application profile reader. * - * @param scope - the scope to be searched - * @param secondaryType the secondary type - * @param portletClassName - the AppId of generic resource + * @param scope - the scope where to search the Application Profile + * @param secondaryType the secondary type of Application Profile + * @param portletClassName - the AppId of Generic Resource + * @param useRootScope the use root scope, if true the root scope is used to discovery the Application Profile, otherwise scope is used */ - public ApplicationProfileReader(String scope, String secondaryType, String portletClassName) { + public ApplicationProfileReader(String scope, String secondaryType, String portletClassName, boolean useRootScope) { this.scope = scope; this.secondaryType = secondaryType; this.appId = portletClassName; + this.useRootScope = useRootScope; this.applicationProfile = readProfileFromInfrastrucure(); } @@ -79,15 +82,15 @@ public class ApplicationProfileReader { try { originalScope = ScopeProvider.instance.get(); - String infra = ScopeUtil.getInfrastructureNameFromScope(scope); - ScopeProvider.instance.set(infra); - logger.info("Trying to fetch ApplicationProfile in the infra scope: "+infra+", SecondaryType: " + secondaryType + ", AppId: " + appId); + String discoveryScope = useRootScope?ScopeUtil.getInfrastructureNameFromScope(scope):scope; + ScopeProvider.instance.set(discoveryScope); + logger.info("Trying to fetch ApplicationProfile in the infra scope: "+discoveryScope+", SecondaryType: " + secondaryType + ", AppId: " + appId); Query q = new QueryBox(queryString); DiscoveryClient client = client(); List appProfile = client.submit(q); if (appProfile == null || appProfile.size() == 0) - throw new ApplicationProfileNotFoundException("ApplicationProfile with SecondaryType: " + secondaryType + ", AppId: " + appId +" is not registered in the infra scope: "+infra); + throw new ApplicationProfileNotFoundException("ApplicationProfile with SecondaryType: " + secondaryType + ", AppId: " + appId +" is not registered in the infra scope: "+discoveryScope); else { String elem = appProfile.get(0); DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); diff --git a/src/main/java/org/gcube/datatransfer/resolver/catalogue/CatalogueEntityRequest.java b/src/main/java/org/gcube/datatransfer/resolver/catalogue/CatalogueEntityRequest.java new file mode 100644 index 0000000..e128035 --- /dev/null +++ b/src/main/java/org/gcube/datatransfer/resolver/catalogue/CatalogueEntityRequest.java @@ -0,0 +1,76 @@ +/** + * + */ +package org.gcube.datatransfer.resolver.catalogue; + +import java.util.HashMap; +import java.util.Map; + + +/** + * The Class CatalogueEntityRequest. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Dec 2, 2016 + */ +public class CatalogueEntityRequest { + + + Map parameters = new HashMap(); + + /** + * Instantiates a new catalogue entity request. + */ + public CatalogueEntityRequest() { + } + + + /** + * Adds the parameter to request. + * + * @param key the key + * @param value the value + */ + public void addParameterToRequest(String key, String value) { + + this.parameters.put(key, value); + + } + + /** + * @return the parameters + */ + public Map getParameters() { + + return parameters; + } + + + /** + * Gets the value of parameter. + * + * @param key the key + * @return the value of parameter + */ + public String getValueOfParameter(String key) { + + return this.parameters.get(key); + } + + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + builder.append("CatalogueEntityRequest [parameters="); + builder.append(parameters); + builder.append("]"); + return builder.toString(); + } + + + +} diff --git a/src/main/java/org/gcube/datatransfer/resolver/catalogue/CatalogueParameter.java b/src/main/java/org/gcube/datatransfer/resolver/catalogue/CatalogueParameter.java new file mode 100644 index 0000000..179716a --- /dev/null +++ b/src/main/java/org/gcube/datatransfer/resolver/catalogue/CatalogueParameter.java @@ -0,0 +1,79 @@ +/** + * + */ +package org.gcube.datatransfer.resolver.catalogue; + + +/** + * The Class CatalogueParameter. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Dec 2, 2016 + */ +public class CatalogueParameter { + + private String key; + private boolean mandatory; + + /** + * Instantiates a new catalogue parameter. + * + * @param key the key + * @param mandatory the mandatory + */ + public CatalogueParameter(String key, boolean mandatory) { + this.key = key; + this.mandatory = mandatory; + } + + /** + * @return the key + */ + public String getKey() { + + return key; + } + + + /** + * @return the mandatory + */ + public boolean isMandatory() { + + return mandatory; + } + + + /** + * @param key the key to set + */ + public void setKey(String key) { + + this.key = key; + } + + + /** + * @param mandatory the mandatory to set + */ + public void setMandatory(boolean mandatory) { + + this.mandatory = mandatory; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + builder.append("CatalogueParameter [key="); + builder.append(key); + builder.append(", mandatory="); + builder.append(mandatory); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/datatransfer/resolver/catalogue/CatalogueRequestParameter.java b/src/main/java/org/gcube/datatransfer/resolver/catalogue/CatalogueRequestParameter.java new file mode 100644 index 0000000..eb026e9 --- /dev/null +++ b/src/main/java/org/gcube/datatransfer/resolver/catalogue/CatalogueRequestParameter.java @@ -0,0 +1,45 @@ +/** + * + */ +package org.gcube.datatransfer.resolver.catalogue; + + +/** + * The Interface CatalogueRequestParameter. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Dec 2, 2016 + */ +public enum CatalogueRequestParameter { + + GCUBE_SCOPE("gcube_scope",true), + ENTITY_CONTEXT("entity_context",true), + ENTITY_NAME("entity_name",true), + QUERY_STRING("query_string",false); + + private String key; + private boolean mandatory; + /** + * + */ + private CatalogueRequestParameter(String key, boolean isMandatory) { + this.key = key; + this.mandatory = isMandatory; + } + + /** + * @return the key + */ + public String getKey() { + + return key; + } + + /** + * @return the mandatory + */ + public boolean isMandatory() { + + return mandatory; + } +} diff --git a/src/main/java/org/gcube/datatransfer/resolver/catalogue/CatalogueResolver.java b/src/main/java/org/gcube/datatransfer/resolver/catalogue/CatalogueResolver.java new file mode 100644 index 0000000..9abac1b --- /dev/null +++ b/src/main/java/org/gcube/datatransfer/resolver/catalogue/CatalogueResolver.java @@ -0,0 +1,239 @@ +/** + * + */ +package org.gcube.datatransfer.resolver.catalogue; + +import java.io.IOException; +import java.io.StringReader; +import java.io.UnsupportedEncodingException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.io.IOUtils; +import org.gcube.common.encryption.StringEncrypter; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The Class GisResolver. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Jan 7, 2016 + */ +public class CatalogueResolver extends HttpServlet{ + + private static final long serialVersionUID = -8273405286016095823L; + + private static final String TEXT_PALIN_CHARSET_UTF_8 = "text/palin;charset=UTF-8"; + public static final String UTF_8 = "UTF-8"; + + /** The logger. */ + private static final Logger logger = LoggerFactory.getLogger(CatalogueResolver.class); + + /* (non-Javadoc) + * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + + /*String scope = cer.getValueOfParameter(CatalogueRequestParameter.GCUBE_SCOPE.getKey()); + logger.info("Using scope "+scope+ " to search Ckan Portlet URL from IS"); + ScopeProvider.instance.set(scope); + String ckanPorltetUrl = CkanPorltetApplicationProfile.getPortletUrlFromInfrastrucure(); + if(ckanPorltetUrl == null || ckanPorltetUrl.isEmpty()){ + sendError(null, HttpStatus.SC_INTERNAL_SERVER_ERROR, "An error occurred during discovery Data Catalogue URL, try again later"); + return; + }*/ + + } + + + /* (non-Javadoc) + * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + + CatalogueEntityRequest cer = new CatalogueEntityRequest(); + + try{ + String jsonRequest = IOUtils.toString(req.getInputStream()); + +// jsonRequest = "{" + +// "\"gcube_scope\" : \"/gcube\"," + +// "\"entity_context\" : \"dataset\"," + +// "\"entity_name\" : \"sarda-sarda\"" + +// "}"; +//// String test = "{" + +//// "\"gcube_scope\" : \"/gcube\"," + +//// "\"entity_context\" : \"dataset\"," + +//// "\"entity_name\" : \"sarda-sarda\"," + +//// "\"query\" : {\"key1\" : \"value1\", \"key2\":\"value2\"}" + +// +// +//// "}"; + + logger.debug("Read json request: "+jsonRequest); + JSONObject inputJson = new JSONObject(jsonRequest); + + for (CatalogueRequestParameter parameter : CatalogueRequestParameter.values()) { + + try{ + + switch (parameter) { + case QUERY_STRING: + //TODO must be implemented + JSONArray queryString = inputJson.getJSONArray(parameter.getKey()); + break; + default: + String value = inputJson.getString(parameter.getKey()); + logger.debug("Read value: "+value+", for parameter: "+parameter.getKey()); + cer.addParameterToRequest(parameter.getKey(), value); + break; + } + + }catch(Exception e){ + String error = ""; + try { + + if(parameter.isMandatory()){ + error = parameter.getKey() +" not found"; + sendError(null, HttpStatus.SC_BAD_REQUEST, error); + return; + } + else + logger.debug("Not Mandatory parameter: "+parameter.getKey()+", not found, I goes on"); + + }catch (IOException e1) { + //silent + } + } + + } + }catch(JSONException e){ + try { + logger.error("Json passed is malformed: ", e); + sendError(null, HttpStatus.SC_BAD_REQUEST, "Json passed is malformed"); + } + catch (IOException e1) { + //silent + } + return; + } + + try{ + + String buildLink = getServletContextURL(req); + String query = UrlEncoderUtil.encodeQuery(cer.getParameters()); + logger.info("Builded query string: "+query); + String encriptedQuery = StringEncrypter.getEncrypter().encrypt(query); + logger.info("Encrypted query: "+encriptedQuery); + String encodedQuery = base64EncodeStringURLSafe(encriptedQuery); + buildLink+="?"+encodedQuery; + logger.info("Writing link: "+buildLink); + + resp.setContentType(TEXT_PALIN_CHARSET_UTF_8); + resp.setCharacterEncoding(UTF_8); + resp.getWriter().write(buildLink); + + }catch(Exception e){ + try { + logger.error("An internal error is occurred: ", e); + sendError(null, HttpStatus.SC_INTERNAL_SERVER_ERROR, "An error occurred during generating Data Catalogue Link, try again later"); + return; + } + catch (IOException e1) { + //silent + } + } + + } + + /** + * Send error. + * + * @param response the response + * @param status the status + * @param message the message + * @throws IOException Signals that an I/O exception has occurred. + */ + protected static void sendError(HttpServletResponse response, int status, String message) throws IOException{ + + logger.error("error message: "+message); + logger.info("writing response..."); + + if(response==null) + return; + + response.setStatus(status); + StringReader sr = new StringReader(message); + IOUtils.copy(sr, response.getOutputStream()); + logger.info("response writed"); + response.flushBuffer(); + } + + + /** + * Gets the servlet context url. + * + * @param req the req + * @return the servlet context url + */ + public String getServletContextURL(HttpServletRequest req) { + + String scheme = req.getScheme(); // http + String serverName = req.getServerName(); // hostname.com + int serverPort = req.getServerPort(); // 80 + String contextPath = req.getContextPath(); // /mywebapp + + // Reconstruct original requesting URL + StringBuffer url = new StringBuffer(); + url.append(scheme).append("://").append(serverName); + + if (serverPort != 80 && serverPort != 443) + url.append(":").append(serverPort); + + if(contextPath!=null) + url.append(":").append(contextPath); + + String uToS = url.toString(); + logger.debug("returning servlet context URL: "+uToS); + return uToS; + } + + /** + * The main method. + * + * @param args the arguments + */ + public static void main(String[] args) { + + } + + /** + * Base64 encode string url safe. + * + * @param s the s + * @return the string + */ + public static String base64EncodeStringURLSafe(String s) { + + try { + return Base64.encodeBase64URLSafeString(s.getBytes(UTF_8)); + } + catch (UnsupportedEncodingException e) { + logger.error("Failed to decode the String", e); + logger.error("Returning input string: " + s); + return s; + } + } +} diff --git a/src/main/java/org/gcube/datatransfer/resolver/catalogue/CkanPorltetApplicationProfile.java b/src/main/java/org/gcube/datatransfer/resolver/catalogue/CkanPorltetApplicationProfile.java new file mode 100644 index 0000000..25d38cb --- /dev/null +++ b/src/main/java/org/gcube/datatransfer/resolver/catalogue/CkanPorltetApplicationProfile.java @@ -0,0 +1,82 @@ +/** + * + */ + +package org.gcube.datatransfer.resolver.catalogue; + +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.Node; +import org.xml.sax.InputSource; + +/** + * The Class GetCkanPorltet. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Dec 2, 2016 + */ +public class CkanPorltetApplicationProfile { + + private static final Logger logger = LoggerFactory.getLogger(CkanPorltetApplicationProfile.class); + private final static String APPLICATION_PROFILE_NAME = "CkanPortlet"; + + /** + * Gets the portlet url from infrastrucure. + * + * @return the portlet url from infrastrucure + * @throws Exception + */ + public static String getPortletUrlFromInfrastrucure() throws Exception { + + String scope = ScopeProvider.instance.get(); + logger.debug("Trying to fetch applicationProfile profile from the infrastructure for " + + APPLICATION_PROFILE_NAME + " scope: " + scope); + try { + Query q = + new QueryBox( + "for $profile in collection('/db/Profiles/GenericResource')//Resource " + + "where $profile/Profile/SecondaryType/string() eq 'ApplicationProfile' and $profile/Profile/Name/string() " + + " eq '" + + APPLICATION_PROFILE_NAME + + "'" + + "return $profile"); + DiscoveryClient client = client(); + List appProfile = client.submit(q); + if (appProfile == null || appProfile.size() == 0) + throw new ApplicationProfileNotFoundException( + "Your applicationProfile is not registered in the infrastructure"); + else { + String elem = appProfile.get(0); + DocumentBuilder docBuilder = + DocumentBuilderFactory.newInstance().newDocumentBuilder(); + Node node = docBuilder.parse(new InputSource(new StringReader(elem))).getDocumentElement(); + XPathHelper helper = new XPathHelper(node); + List currValue = null; + currValue = + helper.evaluate("/Resource/Profile/Body/url/text()"); + if (currValue != null && currValue.size() > 0) { + logger.debug("CKAN Portlet url found is " + currValue.get(0)); + return currValue.get(0); + } + } + } + catch (Exception e) { + throw new Exception("Error while trying to fetch applicationProfile profile for name "+APPLICATION_PROFILE_NAME+"from the infrastructure, using scope: "+scope); + } + + return null; + } +} diff --git a/src/main/java/org/gcube/datatransfer/resolver/catalogue/UrlEncoderUtil.java b/src/main/java/org/gcube/datatransfer/resolver/catalogue/UrlEncoderUtil.java new file mode 100644 index 0000000..5653fdb --- /dev/null +++ b/src/main/java/org/gcube/datatransfer/resolver/catalogue/UrlEncoderUtil.java @@ -0,0 +1,87 @@ +/** + * + */ +package org.gcube.datatransfer.resolver.catalogue; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.Map; + +import org.apache.log4j.Logger; + + +/** + * The Class UrlEncoderUtil. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Dec 2, 2016 + */ +public class UrlEncoderUtil { + + public static String charset = "UTF-8"; + public static Logger logger = Logger.getLogger(UrlEncoderUtil.class); + + /** + * Encode query. + * + * @param parameters the parameters + * @return the string + */ + public static String encodeQuery(String... parameters){ + + String query = ""; + for (String string : parameters) { + + try { + query+=URLEncoder.encode(string, charset)+"&"; + } catch (UnsupportedEncodingException e) { + logger.error(e); + return query; + } + + } + return removeLastChar(query); + } + + /** + * Encode query. + * + * @param parameters the parameters + * @return the string + */ + public static String encodeQuery(Map parameters){ + + String query = ""; + + if(parameters==null) + return query; + + for (String key : parameters.keySet()) { + try { + query+=String.format(key+"=%s", URLEncoder.encode(parameters.get(key), charset))+"&"; + } catch (UnsupportedEncodingException e) { + logger.error(e); + return query; + } + } + + return removeLastChar(query); + } + + /** + * Removes the last char. + * + * @param string the string + * @return the string + */ + public static String removeLastChar(String string){ + + if(string == null) + return null; + + if(string.length()>0) + return string.substring(0, string.length()-1); + + return string; + } +} diff --git a/src/main/java/org/gcube/datatransfer/resolver/gis/GisResolver.java b/src/main/java/org/gcube/datatransfer/resolver/gis/GisResolver.java index e22bda4..6fcb8a6 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/gis/GisResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/gis/GisResolver.java @@ -162,7 +162,7 @@ public class GisResolver extends HttpServlet{ if(gisViewerAppPropertyReader==null) resetGisViewerAppEndPoint(); - ApplicationProfileReader reader = new ApplicationProfileReader(scope, gisViewerAppPropertyReader.getGenericResource(), gisViewerAppPropertyReader.getAppId()); + ApplicationProfileReader reader = new ApplicationProfileReader(scope, gisViewerAppPropertyReader.getGenericResource(), gisViewerAppPropertyReader.getAppId(), true); String url = reader.getApplicationProfile().getUrl(); cachedGisViewerApplHostname.put(scope, url); logger.info("Updated GisViewerApplication cache! Scope "+scope+" linking "+url); diff --git a/src/main/java/org/gcube/datatransfer/resolver/http/HttpResolver.java b/src/main/java/org/gcube/datatransfer/resolver/http/HttpResolver.java index b19869b..48f89ec 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/http/HttpResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/http/HttpResolver.java @@ -266,23 +266,22 @@ public class HttpResolver extends HttpServlet { doGet(request,response); } - /** - * The main method. - * - * @param args the arguments - */ - public static void main(String[] args) { - - String fileName = "COL_taxa.taf.gz"; - String smpPath = "smp://Share/89971b8f-a993-4e7b-9a95-8d774cb68a99/Work+Packages/WP+6+-+Virtual+Research+Environments+Deployment+and+Operation/T6.2+Resources+and+Tools/COMET-Species-Matching-Engine/YASMEEN/1.2.0/Data/BiOnymTAF/COL_taxa.taf.gz"; - try { - System.out.println(validateItemName(smpPath, fileName)); - } - catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - +// /** +// * The main method. +// * +// * @param args the arguments +// */ +// public static void main(String[] args) { +// +// String fileName = "COL_taxa.taf.gz"; +// String smpPath = "smp://Share/89971b8f-a993-4e7b-9a95-8d774cb68a99/Work+Packages/WP+6+-+Virtual+Research+Environments+Deployment+and+Operation/T6.2+Resources+and+Tools/COMET-Species-Matching-Engine/YASMEEN/1.2.0/Data/BiOnymTAF/COL_taxa.taf.gz"; +// try { +// System.out.println(validateItemName(smpPath, fileName)); +// } +// catch (Exception e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } +// } } \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 9a568a6..6aaf420 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -21,6 +21,13 @@ 1 + + catalogue + catalogue + org.gcube.datatransfer.resolver.catalogue.CatalogueResolver + 1 + + id id @@ -34,7 +41,7 @@ org.gcube.datatransfer.resolver.gis.GisResolver 1 - + geonetwork geonetwork @@ -52,14 +59,19 @@ /gis + + catalogue + /catalogue + + id /id - + geonetwork /geonetwork - + diff --git a/src/test/java/GeonetworkQueryTest.java b/src/test/java/GeonetworkQueryTest.java index c0c416c..11b049d 100644 --- a/src/test/java/GeonetworkQueryTest.java +++ b/src/test/java/GeonetworkQueryTest.java @@ -1,6 +1,7 @@ import it.geosolutions.geonetwork.util.GNSearchRequest; import it.geosolutions.geonetwork.util.GNSearchResponse; +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; @@ -9,7 +10,6 @@ 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; /** * @@ -20,18 +20,18 @@ public class GeonetworkQueryTest { private static final int MAX = 10; - private String[] scopes = {"/gcube/devsec"}; + //private String[] scopes = {"/gcube/devNext/NextNext"}; - private String[] scopesProd = {"/d4science.research-infrastructures.eu/gCubeApps/RPrototypingLab", "/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab"}; + private String[] scopesProd = {"/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab"}; - private LoginLevel loginLevel = LoginLevel.SCOPE; + private LoginLevel loginLevel = LoginLevel.ADMIN; - private Type accountType = Type.CKAN; + private Type accountType = Type.SCOPE; -// @Test + //@Test public void getCount() throws Exception{ try{ - for(String scope:scopes){ + for(String scope:scopesProd){ ScopeProvider.instance.set(scope); GeoNetworkPublisher reader=GeoNetwork.get(); @@ -39,12 +39,20 @@ public class GeonetworkQueryTest { Configuration config = reader.getConfiguration(); Account account=config.getScopeConfiguration().getAccounts().get(accountType); - System.out.println("User: "+account.getUser()+", Pwd: "+account.getPassword()); + //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"); +// req.addParam(GNSearchRequest.Param.any,"Thredds"); GNSearchResponse resp = reader.query(req); int publicCount=resp.getCount(); reader.login(loginLevel); @@ -74,7 +82,7 @@ public class GeonetworkQueryTest { } - @Test +// @Test public void getCountProd() throws Exception{ try{ for(String scope:scopesProd){