Task #12500 completed

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/ckan-util-library@171735 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-09-28 09:19:25 +00:00
parent 4318c1e7de
commit 804a7991fa
5 changed files with 194 additions and 12 deletions

View File

@ -15,6 +15,7 @@
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="com.google.gwt.eclipse.core.GWT_CONTAINER"/>

View File

@ -3,6 +3,7 @@
<ReleaseNotes>
<Changeset component="org.gcube.data-catalogue.ckan-util-library.2-7-0" date="${buildDate}">
<Change>Added the possibility to deny social post on catalogue-ws #12514</Change>
<Change>[Task #12500] Changing log from error to warning</Change>
</Changeset>
<Changeset component="org.gcube.data-catalogue.ckan-util-library.2-6-0" date="2018-07-18">
<Change>Enhance timeout in requests to CKAN in ckan-util-library #12050</Change>

View File

@ -2663,7 +2663,9 @@ public class DataCatalogueImpl implements DataCatalogue{
return client.getOrganization(ckanName);
}catch(Exception e){
logger.error("Failed to retrieve the organization with name" + name, e);
logger.warn("Failed to retrieve the organization with name" +name+ " on the ckan: "+client.getCatalogUrl());
//OLD PRINTING. FIXING Task #12500
//logger.error("Failed to retrieve the organization with name" + name, e);
}
return null;
}

View File

@ -0,0 +1,164 @@
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<String> scopes = new ArrayList<String>();
/**
* 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<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> 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<String> 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();
// }
//
// }
}

View File

@ -32,7 +32,8 @@ 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 = "/gcube/devNext/NextNext";
private String scope = "/d4science.research-infrastructures.eu";
private String testUser = "costantino_perciante";
String subjectId = "aa_father4";
String objectId = "bb_son4";
@ -41,7 +42,7 @@ public class TestDataCatalogueLib {
public void before() throws Exception{
factory = DataCatalogueFactory.getFactory();
}
//@Test
public void getSysadminEmail() throws Exception{
DataCatalogueImpl utils = factory.getUtilsPerScope(scope);
@ -55,7 +56,7 @@ public class TestDataCatalogueLib {
logger.debug("Statistics " + utils.getStatistics());
}
//@Test
public void getLandingPages() throws Exception{
@ -64,7 +65,7 @@ public class TestDataCatalogueLib {
}
//@Test
//@Test
public void getDatasetIdsFromDB() throws Exception{
DataCatalogueImpl utils = factory.getUtilsPerScope(scope);
List<String> ids = utils.getProductsIdsInGroupOrOrg("aquamaps", true, 0, Integer.MAX_VALUE);
@ -190,7 +191,7 @@ public class TestDataCatalogueLib {
System.out.println("Testing getOrganizationsByUser");
DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
String username = "francescomangiacrapa";
String username = "massimilianoassante";
List<CkanOrganization> organizations = instance.getOrganizationsByUser(username);
System.out.println("organizations for user " + username + " are: ");
@ -230,7 +231,7 @@ public class TestDataCatalogueLib {
Iterator<Entry<String, List<RolesCkanGroupOrOrg>>> iterator = orgs.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<java.lang.String, java.util.List<org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg>> entry = (Map.Entry<java.lang.String, java.util.List<org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg>>) iterator
Map.Entry<java.lang.String, java.util.List<org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg>> entry = iterator
.next();
logger.debug("Org is " + entry.getKey() + " and role is " + entry.getValue().get(0));
@ -315,7 +316,7 @@ public class TestDataCatalogueLib {
// dataset.setPriv(!dataset.isPriv());
// CkanDataset datasetUpd = client.updateDataset(dataset);
// logger.debug("Private value is " + datasetUpd.isPriv());
//
//
}
@ -495,13 +496,26 @@ public class TestDataCatalogueLib {
}
//@Test
//UPDATED By FRANCESCO FOR FIXING Incident #12563
public void getUserRoleByGroup() throws Exception{
DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
String username = "costantino_perciante";
String username = "massimiliano_assante";
long init = System.currentTimeMillis();
instance.getUserRoleByGroup(username, instance.getApiKeyFromUsername(username));
long end = System.currentTimeMillis();
logger.debug("Time taken " + (end - init));
//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);
}
}
//@Test