diff --git a/distro/changelog.xml b/distro/changelog.xml index 1d4daeb..8652a90 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -3,7 +3,6 @@ Added the possibility to deny social post on catalogue-ws #12514 - [Task #12500] Changing log from error to warning Enhance timeout in requests to CKAN in ckan-util-library #12050 diff --git a/src/test/java/org/gcube/datacatalogue/ckanutillibrary/server/RuntimeResourceReader.java b/src/test/java/org/gcube/datacatalogue/ckanutillibrary/server/RuntimeResourceReader.java deleted file mode 100644 index 7736eee..0000000 --- a/src/test/java/org/gcube/datacatalogue/ckanutillibrary/server/RuntimeResourceReader.java +++ /dev/null @@ -1,164 +0,0 @@ -package org.gcube.datacatalogue.ckanutillibrary.server; -/** - * - */ - - -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.resources.gcore.ServiceEndpoint; -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 RuntimeResourceReader. - * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Mar 10, 2017 - */ -public class RuntimeResourceReader { - - public static final Logger logger = LoggerFactory.getLogger(RuntimeResourceReader.class); - - private List scopes = new ArrayList(); - - /** - * 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 runtimeName, String endPoint) throws Exception { - read(scope, platformName, runtimeName, endPoint); - } - - - /** - * Read. - * - * @param scope the scope - * @param runtimeName the runtime name - * @param endPoint the end point - * @return the server parameters - * @throws Exception the exception - */ - private void read(String scope, String platformName, String runtimeName, 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/Category/text() eq 'Application'"); - //query.addCondition("$resource/Profile/Category/Name/text() eq '"+runtimeName+"'"); - - if(platformName!=null && !platformName.isEmpty()) - query.addCondition("$resource/Profile/Platform/Name/text() eq '"+platformName+"'"); - - if(endPoint!=null && !endPoint.isEmpty()) - query.addCondition("$resource/Profile/AccessPoint/Interface/Endpoint/text() eq '"+endPoint+"'"); - - logger.info("RuntimeReader, using scope: "+scope + ", query is: "+query.toString()); - - DiscoveryClient client = clientFor(ServiceEndpoint.class); - - List r = client.submit(query); - if (r == null || r.isEmpty()) throw new Exception("Cannot retrieve the runtime resource: "+runtimeName); - - - for (ServiceEndpoint serviceEndpoint : r) { - System.out.println(serviceEndpoint.toString()); - } - - ServiceEndpoint se = r.get(0); - if(se.profile()==null) - throw new Exception("IS profile is null for resource: "+platformName); - - - scopes.addAll(se.scopes().asCollection()); - - }catch (Exception e) { - System.out.println(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; - } - - - /** - * Gets the scopes. - * - * @return the scopes - */ - public List getScopes() { - - return scopes; - } - - - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - - StringBuilder builder = new StringBuilder(); - builder.append("RuntimeResourceReader [scopes="); - builder.append(scopes); - builder.append("]"); - return builder.toString(); - } - - - -// /** -// * The main method. -// * -// * @param args the arguments -// */ -// public static void main(String[] args) { -// -// String scope = "/d4science.research-infrastructures.eu"; -// String platformName = null; -// String runtimeName = "CKanDataCatalogue"; -// String endPoint = null; -// RuntimeResourceReader reader; -// try { -// reader = new RuntimeResourceReader(scope, platformName, runtimeName, endPoint); -// System.out.println(reader.toString()); -// -// System.out.println("Scopes are: "+reader.getScopes().size()); -// } -// catch (Exception e) { -// // TODO Auto-generated catch block -// e.printStackTrace(); -// } -// -// } - - -} diff --git a/src/test/java/org/gcube/datacatalogue/ckanutillibrary/server/TestDataCatalogueLib.java b/src/test/java/org/gcube/datacatalogue/ckanutillibrary/server/TestDataCatalogueLib.java index 10f10bf..bd06576 100644 --- a/src/test/java/org/gcube/datacatalogue/ckanutillibrary/server/TestDataCatalogueLib.java +++ b/src/test/java/org/gcube/datacatalogue/ckanutillibrary/server/TestDataCatalogueLib.java @@ -32,8 +32,7 @@ public class TestDataCatalogueLib { private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TestDataCatalogueLib.class); private DataCatalogueFactory factory; - //private String scope = "/gcube/devNext/NextNext"; - private String scope = "/d4science.research-infrastructures.eu"; + private String scope = "/gcube/devNext/NextNext"; private String testUser = "costantino_perciante"; String subjectId = "aa_father4"; String objectId = "bb_son4"; @@ -42,7 +41,7 @@ public class TestDataCatalogueLib { public void before() throws Exception{ factory = DataCatalogueFactory.getFactory(); } - + //@Test public void getSysadminEmail() throws Exception{ DataCatalogueImpl utils = factory.getUtilsPerScope(scope); @@ -56,7 +55,7 @@ public class TestDataCatalogueLib { logger.debug("Statistics " + utils.getStatistics()); } - + //@Test public void getLandingPages() throws Exception{ @@ -65,7 +64,7 @@ public class TestDataCatalogueLib { } - //@Test + //@Test public void getDatasetIdsFromDB() throws Exception{ DataCatalogueImpl utils = factory.getUtilsPerScope(scope); List ids = utils.getProductsIdsInGroupOrOrg("aquamaps", true, 0, Integer.MAX_VALUE); @@ -191,7 +190,7 @@ public class TestDataCatalogueLib { System.out.println("Testing getOrganizationsByUser"); DataCatalogueImpl instance = factory.getUtilsPerScope(scope); - String username = "massimilianoassante"; + String username = "francescomangiacrapa"; List organizations = instance.getOrganizationsByUser(username); System.out.println("organizations for user " + username + " are: "); @@ -231,7 +230,7 @@ public class TestDataCatalogueLib { Iterator>> iterator = orgs.entrySet().iterator(); while (iterator.hasNext()) { - Map.Entry> entry = iterator + Map.Entry> entry = (Map.Entry>) iterator .next(); logger.debug("Org is " + entry.getKey() + " and role is " + entry.getValue().get(0)); @@ -316,7 +315,7 @@ public class TestDataCatalogueLib { // dataset.setPriv(!dataset.isPriv()); // CkanDataset datasetUpd = client.updateDataset(dataset); // logger.debug("Private value is " + datasetUpd.isPriv()); - // + // } @@ -496,26 +495,13 @@ public class TestDataCatalogueLib { } //@Test - //UPDATED By FRANCESCO FOR FIXING Incident #12563 public void getUserRoleByGroup() throws Exception{ DataCatalogueImpl instance = factory.getUtilsPerScope(scope); - String username = "massimiliano_assante"; + String username = "costantino_perciante"; long init = System.currentTimeMillis(); - - //Fixing Incident #12563 - try{ - String apiKey = instance.getApiKeyFromUsername(username); - logger.debug("ApiKey is "+apiKey+ " retrieved for user: "+username); - //Fixing Incident #12563 - if(apiKey!=null && !apiKey.isEmpty()){ - instance.getUserRoleByGroup(username, apiKey); - long end = System.currentTimeMillis(); - logger.debug("Time taken " + (end - init)); - }else - logger.warn("The API_KEY for "+username+ " is null or empty in the catalogue: "+instance.getCatalogueUrl()); - }catch(Exception e){ - logger.error("Error on recovery the user groups for "+username, e); - } + instance.getUserRoleByGroup(username, instance.getApiKeyFromUsername(username)); + long end = System.currentTimeMillis(); + logger.debug("Time taken " + (end - init)); } //@Test