Merged from branch version 2.7 of release 4.13
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/ckan-util-library@173919 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
4d05b15506
commit
78ab28a7f3
|
@ -3,7 +3,6 @@
|
|||
<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>
|
||||
|
|
|
@ -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<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();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
}
|
|
@ -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<String> 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<CkanOrganization> organizations = instance.getOrganizationsByUser(username);
|
||||
|
||||
System.out.println("organizations for user " + username + " are: ");
|
||||
|
@ -231,7 +230,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 = iterator
|
||||
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
|
||||
.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
|
||||
|
|
Loading…
Reference in New Issue