Merge pull request 'task_23692' (!4) from task_23692 into master

Reviewed-on: #4
This commit is contained in:
Francesco Mangiacrapa 2022-08-01 15:03:13 +02:00
commit ef1d74e8cc
11 changed files with 312 additions and 92 deletions

View File

@ -4,6 +4,13 @@
All notable changes to this project will be documented in this file. 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). This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1.2.0-SNAPSHOT] - 2022-07-28
**Enhancements**
- [#23692] Optimized the listing and the paging of catalogue items
- Moved to maven-portal-bom 3.7.0-SNAPSHOT
## [v1.1.0] - 2022-05-18 ## [v1.1.0] - 2022-05-18
**New Features** **New Features**

16
pom.xml
View File

@ -12,8 +12,7 @@
<groupId>org.gcube.datacatalogue</groupId> <groupId>org.gcube.datacatalogue</groupId>
<artifactId>catalogue-util-library</artifactId> <artifactId>catalogue-util-library</artifactId>
<version>1.1.0</version> <version>1.2.0-SNAPSHOT</version>
<name>Ckan utility library</name> <name>Ckan utility library</name>
<description> <description>
Utility library to retrieve users information, organizations information and so on from the ckan d4science datacatalogue Utility library to retrieve users information, organizations information and so on from the ckan d4science datacatalogue
@ -42,7 +41,7 @@
<dependency> <dependency>
<groupId>org.gcube.distribution</groupId> <groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId> <artifactId>maven-portal-bom</artifactId>
<version>3.6.3</version> <version>3.7.0-SNAPSHOT</version>
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>
@ -53,6 +52,7 @@
<dependency> <dependency>
<groupId>com.google.gwt</groupId> <groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId> <artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
@ -101,7 +101,7 @@
<dependency> <dependency>
<groupId>org.gcube.data-catalogue</groupId> <groupId>org.gcube.data-catalogue</groupId>
<artifactId>gcat-client</artifactId> <artifactId>gcat-client</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0)</version> <version>[2.0.0, 3.0.0-SNAPSHOT)</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
@ -171,6 +171,14 @@
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- Test Dependencies -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-utils</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -226,19 +226,21 @@ public class GCatCaller {
* @param status the status * @param status the status
* @param limit the limit * @param limit the limit
* @param offset the offset * @param offset the offset
* @param allFields the all fields. If true returns the all fields of an item
* @param filters the filters * @param filters the filters
* @param sortForField the sort for field * @param sortForField the sort for field
* @return the list items for CM status * @return the list items for CM status
* @throws WebServiceException the web service exception * @throws WebServiceException the web service exception
* @throws MalformedURLException the malformed URL exception * @throws MalformedURLException the malformed URL exception
*/ */
public String getListItemsForCMStatus(CMItemStatus status, int limit, int offset, Map<String, String> filters, String sortForField) public String getListItemsForCMStatus(CMItemStatus status, int limit, int offset, Boolean allFields,
throws WebServiceException, MalformedURLException { Map<String, String> filters, String sortForField) throws WebServiceException, MalformedURLException {
LOG.trace("getListItemsForCMStatus called"); LOG.trace("getListItemsForCMStatus called");
LOG.info("called getListItemsForCMStatus called with [status: " + status + "], [limit: " + limit LOG.info("called getListItemsForCMStatus called with [status: " + status + "], [limit: " + limit
+ "], [offset: " + offset + "], [filters: " + filters + "]"); + "], [offset: " + offset + "], [filters: " + filters + "]");
Map<String, String> queryParams = GCatCallerUtil.genericQueryBuilderFor(status, limit, offset, false, filters, sortForField); Map<String, String> queryParams = GCatCallerUtil.genericQueryBuilderFor(status, limit, offset, false, allFields, filters,
sortForField);
return getListItemsForQuery(queryParams); return getListItemsForQuery(queryParams);
} }
@ -257,7 +259,8 @@ public class GCatCaller {
LOG.trace("countListItemsForCMStatus called"); LOG.trace("countListItemsForCMStatus called");
LOG.info("Calling count list items for [status: " + status + "], [filters: " + filters + "]"); LOG.info("Calling count list items for [status: " + status + "], [filters: " + filters + "]");
Map<String, String> queryParams = GCatCallerUtil.genericQueryBuilderFor(status, null, null, true, filters, null); Map<String, String> queryParams = GCatCallerUtil.genericQueryBuilderFor(status, null, null, true, false,
filters, null);
String theCount = getListItemsForQuery(queryParams); String theCount = getListItemsForQuery(queryParams);
int count = 0; int count = 0;

View File

@ -6,6 +6,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.gcube.gcat.api.GCatConstants;
import org.gcube.gcat.api.moderation.CMItemStatus; import org.gcube.gcat.api.moderation.CMItemStatus;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.parser.JSONParser; import org.json.simple.parser.JSONParser;
@ -30,14 +31,16 @@ public class GCatCallerUtil {
* @param status the status * @param status the status
* @param limit the limit * @param limit the limit
* @param offset the offset * @param offset the offset
* @param count the count * @param count the count. If true returns only the count
* @param allFields the all fields. If true returns the all fields of an item
* @param filters the filters * @param filters the filters
* @param sort the sort
* @return the map * @return the map
*/ */
public static Map<String, String> genericQueryBuilderFor(CMItemStatus status, Integer limit, Integer offset, public static Map<String, String> genericQueryBuilderFor(CMItemStatus status, Integer limit, Integer offset,
Boolean count, Map<String, String> filters, String sort) { Boolean count, Boolean allFields, Map<String, String> filters, String sort) {
LOG.info("genericQueryBuilderFor called with [status: " + status + "], [limit: " + limit + "], [offset: " LOG.info("genericQueryBuilderFor called with [status: " + status + "], [limit: " + limit + "], [offset: "
+ offset + "], [count: " + count + "], [filters: " + filters + "]"); + offset + "], [count: " + count + "], [allFields: " + allFields + "], [filters: " + filters + "]");
Map<String, String> queryParams = new HashMap<String, String>(); Map<String, String> queryParams = new HashMap<String, String>();
@ -62,11 +65,11 @@ public class GCatCallerUtil {
if (limit != null) { if (limit != null) {
limit = limit < 0 ? 10 : limit; limit = limit < 0 ? 10 : limit;
queryParams.put("limit", limit + ""); queryParams.put(GCatConstants.LIMIT_QUERY_PARAMETER, String.valueOf(limit));
} }
if (offset != null) { if (offset != null) {
offset = offset < 0 ? 0 : offset; offset = offset < 0 ? 0 : offset;
queryParams.put("offset", offset + ""); queryParams.put(GCatConstants.OFFSET_QUERY_PARAMETER, String.valueOf(offset));
} }
if (sort != null) { if (sort != null) {
@ -76,10 +79,15 @@ public class GCatCallerUtil {
queryParams.put("sort", GCatCaller.DEFAULT_SORT_VALUE); queryParams.put("sort", GCatCaller.DEFAULT_SORT_VALUE);
} }
if (count != null) { if (count != null) {
if (count) { if (count) {
queryParams.put("count", "true"); queryParams.put(GCatConstants.COUNT_QUERY_PARAMETER, String.valueOf(count));
}
}
if (allFields != null) {
if (allFields) {
queryParams.put(GCatConstants.ALL_FIELDS_QUERY_PARAMETER, String.valueOf(allFields));
} }
} }

View File

@ -35,6 +35,7 @@ public interface CatalogueContentModeratorSystem {
* @param theStatus the the status * @param theStatus the the status
* @param limit the limit * @param limit the limit
* @param offset the offset * @param offset the offset
* @param allFields the all fields. If true returns the all fields of an item
* @param filters add the input filters to query on CKAN * @param filters add the input filters to query on CKAN
* @param sortForField the sort for field * @param sortForField the sort for field
* @return the list items for status * @return the list items for status
@ -42,8 +43,9 @@ public interface CatalogueContentModeratorSystem {
* @throws MalformedURLException the malformed URL exception * @throws MalformedURLException the malformed URL exception
* @throws InvalidObjectException the invalid object exception * @throws InvalidObjectException the invalid object exception
*/ */
public List<CkanDataset> getListItemsForStatus(ItemStatus theStatus, int limit, int offset, List<CkanDataset> getListItemsForStatus(ItemStatus theStatus, int limit, int offset, Boolean allFields,
Map<String, String> filters, String sortForField) throws WebApplicationException, MalformedURLException, InvalidObjectException; Map<String, String> filters, String sortForField)
throws WebApplicationException, MalformedURLException, InvalidObjectException;
/** /**
* Reject item. * Reject item.
@ -85,4 +87,6 @@ public interface CatalogueContentModeratorSystem {
*/ */
void approveItem(String itemName, String moderatorMessage) throws WebApplicationException, MalformedURLException; void approveItem(String itemName, String moderatorMessage) throws WebApplicationException, MalformedURLException;
} }

View File

@ -19,6 +19,7 @@ import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset; import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset;
import org.gcube.gcat.api.moderation.CMItemStatus; import org.gcube.gcat.api.moderation.CMItemStatus;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser; import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException; import org.json.simple.parser.ParseException;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -118,6 +119,7 @@ public class DataCatalogueCMSImpl implements CatalogueContentModeratorSystem {
* @param theStatus the the status * @param theStatus the the status
* @param limit the limit * @param limit the limit
* @param offset the offset * @param offset the offset
* @param allFields the all fields. If true returns the all fields of an item
* @param filters add the input filters to query on CKAN * @param filters add the input filters to query on CKAN
* @param sortForField the sort for field * @param sortForField the sort for field
* @return the list items for status * @return the list items for status
@ -126,30 +128,40 @@ public class DataCatalogueCMSImpl implements CatalogueContentModeratorSystem {
* @throws InvalidObjectException the invalid object exception * @throws InvalidObjectException the invalid object exception
*/ */
@Override @Override
public List<CkanDataset> getListItemsForStatus(ItemStatus theStatus, int limit, int offset, public List<CkanDataset> getListItemsForStatus(ItemStatus theStatus, int limit, int offset, Boolean allFields,
Map<String, String> filters, String sortForField) throws WebApplicationException, MalformedURLException, InvalidObjectException { Map<String, String> filters, String sortForField)
throws WebApplicationException, MalformedURLException, InvalidObjectException {
LOG.info("called getListItemsForStatus with [status: " + theStatus + "], [limit: " + limit + "], [offset: " LOG.info("called getListItemsForStatus with [status: " + theStatus + "], [limit: " + limit + "], [offset: "
+ offset + "], [filters: " + filters + "]"); + offset + "], [allFields: " + allFields + "], [filters: " + filters + "]");
List<CkanDataset> listDataset = null; List<CkanDataset> listDataset = null;
checkNotNull(theStatus); checkNotNull(theStatus);
JSONArray jsonArray = getSourceArrayOfItemsForStatus(theStatus, limit, offset, filters, sortForField); JSONArray jsonArray = getSourceArrayOfItemsForStatus(theStatus, limit, offset, allFields, filters, sortForField);
if (jsonArray != null) { if (jsonArray != null) {
int size = jsonArray.size(); int size = jsonArray.size();
listDataset = new ArrayList<CkanDataset>(size); listDataset = new ArrayList<CkanDataset>(size);
LOG.info("reading and converting " + size + " dataset..."); LOG.info("reading and converting " + size + " dataset...");
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
String datasetName = null; String jsonValueDataset = null;
try { try {
datasetName = (String) jsonArray.get(i); CkanDataset toCkanDataset = null;
LOG.debug("reading dataset: " + datasetName); if(!allFields) {
String jsonValueDataset = gCatCaller.getDatasetForName(datasetName); //here the array contains the list of dataset name
String datasetName = (String) jsonArray.get(i);
LOG.debug("going to read from gCat the dataset: " + datasetName);
jsonValueDataset = gCatCaller.getDatasetForName(datasetName);
LOG.trace("the JSON dataset is: " + jsonValueDataset); LOG.trace("the JSON dataset is: " + jsonValueDataset);
CkanDataset toCkanDataset = MarshUnmarshCkanObject.toCkanDataset(jsonValueDataset, METHOD.TO_READ); }else {
LOG.debug("reading from the array the "+i+"mo json object");
//here the array contains the list of dataset json fields
jsonValueDataset = ((JSONObject) jsonArray.get(i)).toString();
LOG.trace("the JSON dataset is: " + jsonValueDataset);
}
toCkanDataset = MarshUnmarshCkanObject.toCkanDataset(jsonValueDataset, METHOD.TO_READ);
LOG.debug("converted as dataset: " + toCkanDataset); LOG.debug("converted as dataset: " + toCkanDataset);
listDataset.add(toCkanDataset); listDataset.add(toCkanDataset);
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Error on reading/converting the dataset name: " + datasetName, e); LOG.warn("Error on reading/converting the dataset: " + jsonValueDataset, e);
} }
} }
} }
@ -193,6 +205,7 @@ public class DataCatalogueCMSImpl implements CatalogueContentModeratorSystem {
* @param theStatus the the status * @param theStatus the the status
* @param limit the limit * @param limit the limit
* @param offset the offset * @param offset the offset
* @param allFields the all fields. If true returns the all fields of an item
* @param filters the filters * @param filters the filters
* @param sortForField the sort for field * @param sortForField the sort for field
* @return the source array of items for status * @return the source array of items for status
@ -201,9 +214,10 @@ public class DataCatalogueCMSImpl implements CatalogueContentModeratorSystem {
* @throws InvalidObjectException the invalid object exception * @throws InvalidObjectException the invalid object exception
*/ */
protected org.json.simple.JSONArray getSourceArrayOfItemsForStatus(ItemStatus theStatus, int limit, int offset, protected org.json.simple.JSONArray getSourceArrayOfItemsForStatus(ItemStatus theStatus, int limit, int offset,
Map<String, String> filters, String sortForField) throws WebApplicationException, MalformedURLException, InvalidObjectException { Boolean allFields, Map<String, String> filters, String sortForField)
throws WebApplicationException, MalformedURLException, InvalidObjectException {
LOG.info("called getSourceArrayOfItemsForStatus with [status: " + theStatus + "], [limit: " + limit LOG.info("called getSourceArrayOfItemsForStatus with [status: " + theStatus + "], [limit: " + limit
+ "], [offset: " + offset + "], [filters: " + filters + "]"); + "], [offset: " + offset + "], [allFields: " + allFields + "], [filters: " + filters + "]");
checkNotNull(theStatus); checkNotNull(theStatus);
// TODO MUST BE CHANGED FOR THE STATUS // TODO MUST BE CHANGED FOR THE STATUS
org.json.simple.JSONArray jsonArray = null; org.json.simple.JSONArray jsonArray = null;
@ -216,10 +230,11 @@ public class DataCatalogueCMSImpl implements CatalogueContentModeratorSystem {
*/ */
CMItemStatus cmiStatus = toCMStatus(theStatus); CMItemStatus cmiStatus = toCMStatus(theStatus);
String datasetNames = gCatCaller.getListItemsForCMStatus(cmiStatus, limit, offset, filters, sortForField); String datasetNames = gCatCaller.getListItemsForCMStatus(cmiStatus, limit, offset, allFields, filters,
sortForField);
if (datasetNames != null) { if (datasetNames != null) {
LOG.debug("for status " + theStatus + " found dataset: " + datasetNames); LOG.trace("for status " + theStatus + " found dataset: " + datasetNames);
JSONParser parser = new JSONParser(); JSONParser parser = new JSONParser();
try { try {
jsonArray = (JSONArray) parser.parse(datasetNames); jsonArray = (JSONArray) parser.parse(datasetNames);

1
src/test/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/resources/

1
src/test/java/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/token.properties

View File

@ -0,0 +1,147 @@
package org.gcube.datacatalogue.utillibrary.test;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.gcube.common.authorization.utils.manager.SecretManager;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
import org.gcube.common.authorization.utils.secret.GCubeSecret;
import org.gcube.common.authorization.utils.secret.Secret;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class ContextTest.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Jul 28, 2022
*/
public class ContextTest {
private static Logger logger = LoggerFactory.getLogger(ContextTest.class);
protected static Properties properties;
protected static final String PROPERTIES_FILENAME = "token.properties";
public static final String ROOT = "/gcube";
public static final String VO = ROOT + "/devsec";
public static final String VRE = VO + "/devVRE";
static {
properties = new Properties();
try (InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME)) {
if (input == null) {
String error = "Sorry, unable to find the file: " + PROPERTIES_FILENAME;
System.out.println(error);
throw new RuntimeException(error);
}
// load a properties file from class path, inside static method
properties.load(input);
// // get the property value and print it out
// System.out.println(prop.getProperty("db.url"));
// System.out.println(prop.getProperty("db.user"));
// System.out.println(prop.getProperty("db.password"));
} catch (IOException ex) {
ex.printStackTrace();
throw new RuntimeException(ex);
}
}
/**
* Sets the.
*
* @param secret the secret
* @throws Exception the exception
*/
public static void set(Secret secret) throws Exception {
SecretManagerProvider.instance.reset();
SecretManager secretManager = new SecretManager();
SecretManagerProvider.instance.set(secretManager);
secretManager.addSecret(secret);
secretManager.set();
String username = secretManager.getUser().getUsername();
String context = secretManager.getContext();
logger.debug("Set authorization for user {} in context {}", username, context);
}
/**
* Sets the context.
*
* @param token the new context
* @throws Exception the exception
*/
public static void setContext(String token) throws Exception {
Secret secret = getSecret(token);
set(secret);
}
/**
* Sets the context by name.
*
* @param fullContextName the new context by name
* @throws Exception the exception
*/
public static void setContextByName(String fullContextName) throws Exception {
logger.debug("setContextByName {}", fullContextName);
Secret secret = getSecretByContextName(fullContextName);
set(secret);
}
/**
* Gets the secret.
*
* @param token the token
* @return the secret
* @throws Exception the exception
*/
private static Secret getSecret(String token) throws Exception {
GCubeSecret secret = new GCubeSecret(token);
return secret;
}
/**
* Gets the secret by context name.
*
* @param fullContextName the full context name
* @return the secret by context name
* @throws Exception the exception
*/
private static Secret getSecretByContextName(String fullContextName) throws Exception {
logger.debug("getSecretByContextName {}", fullContextName);
String token = ContextTest.properties.getProperty(fullContextName);
logger.debug("token is {}", token);
return getSecret(token);
}
/**
* Before class.
*
* @throws Exception the exception
*/
@BeforeClass
public static void beforeClass() throws Exception {
logger.debug("beforeClass");
setContextByName(VRE);
}
/**
* After class.
*
* @throws Exception the exception
*/
@AfterClass
public static void afterClass() throws Exception {
logger.debug("afterClass");
SecretManagerProvider.instance.reset();
}
}

View File

@ -13,6 +13,7 @@ import org.gcube.datacatalogue.utillibrary.server.DataCatalogueImpl;
import org.gcube.datacatalogue.utillibrary.server.cms.CatalogueContentModeratorSystem; import org.gcube.datacatalogue.utillibrary.server.cms.CatalogueContentModeratorSystem;
import org.gcube.datacatalogue.utillibrary.shared.ItemStatus; import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset; import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset;
import org.gcube.gcat.client.Item;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -22,25 +23,43 @@ import org.slf4j.LoggerFactory;
* *
* @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy) Jun 1, 2020 * @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy) Jun 1, 2020
*/ */
public class TestDataCatalogueCMS { public class TestDataCatalogueCMS extends ContextTest {
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(TestDataCatalogueCMS.class); private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(TestDataCatalogueCMS.class);
private DataCatalogueFactory factory; private DataCatalogueFactory factory;
private String scope = "/gcube/devsec/devVRE";
private String testUser = "francesco.mangiacrapa"; private String testUser = "francesco.mangiacrapa";
private String authorizationToken = ""; private String scope = "/gcube/devsec/devVRE";
//private String scope = "/gcube/devsec";
private String authorizationToken = ""; //devVRE
/** /**
* Before. * Before.
* *
* @throws Exception the exception * @throws Exception the exception
*/ */
@Before //@Before
public void before() throws Exception { public void before() throws Exception {
factory = DataCatalogueFactory.getFactory(); factory = DataCatalogueFactory.getFactory();
} }
//@Test
public void testGCatAvailability() {
try {
LOG.info("testGCatAvailability running");
int offset = 0;
int limit = 10;
// ScopeProvider.instance.set(scope);
// SecurityTokenProvider.instance.set(authorizationToken);
// LOG.debug("Trying with scope: "+scope);
String items = new Item().list(limit, offset);
LOG.debug("List items: " + items);
} catch (Exception e) {
e.printStackTrace();
}
}
/** /**
* Factory test. * Factory test.
* *
@ -48,8 +67,8 @@ public class TestDataCatalogueCMS {
*/ */
//@Test //@Test
public void contentModeratorTest() throws Exception { public void contentModeratorTest() throws Exception {
ScopeProvider.instance.set(scope); // ScopeProvider.instance.set(scope);
SecurityTokenProvider.instance.set(authorizationToken); // SecurityTokenProvider.instance.set(authorizationToken);
DataCatalogueFactory factory = DataCatalogueFactory.getFactory(); DataCatalogueFactory factory = DataCatalogueFactory.getFactory();
DataCatalogueImpl dImpl = factory.getUtilsPerScope(scope); DataCatalogueImpl dImpl = factory.getUtilsPerScope(scope);
CatalogueContentModeratorSystem cCMS = dImpl.getCatalogueContentModerator(); CatalogueContentModeratorSystem cCMS = dImpl.getCatalogueContentModerator();
@ -58,9 +77,11 @@ public class TestDataCatalogueCMS {
//@Test //@Test
public void listItemsForCMStatus() throws Exception { public void listItemsForCMStatus() throws Exception {
try {
long start = System.currentTimeMillis();
ItemStatus theStatus = ItemStatus.PENDING; ItemStatus theStatus = ItemStatus.PENDING;
ScopeProvider.instance.set(scope); // ScopeProvider.instance.set(scope);
SecurityTokenProvider.instance.set(authorizationToken); // SecurityTokenProvider.instance.set(authorizationToken);
DataCatalogueImpl dImpl = factory.getUtilsPerScope(scope); DataCatalogueImpl dImpl = factory.getUtilsPerScope(scope);
CatalogueContentModeratorSystem cCMS = dImpl.getCatalogueContentModerator(); CatalogueContentModeratorSystem cCMS = dImpl.getCatalogueContentModerator();
LOG.debug(CatalogueContentModeratorSystem.class.getName() + " instancied correclty"); LOG.debug(CatalogueContentModeratorSystem.class.getName() + " instancied correclty");
@ -75,11 +96,17 @@ public class TestDataCatalogueCMS {
Map<String, String> filters = new HashMap<String, String>(); Map<String, String> filters = new HashMap<String, String>();
filters.put("author_email", theQuery); filters.put("author_email", theQuery);
List<CkanDataset> listItems = cCMS.getListItemsForStatus(theStatus, 10, 0, filters, GCatCaller.DEFAULT_SORT_VALUE); List<CkanDataset> listItems = cCMS.getListItemsForStatus(theStatus, 10, 0, true, filters,
GCatCaller.DEFAULT_SORT_VALUE);
int i = 0; int i = 0;
for (CkanDataset ckanDataset : listItems) { for (CkanDataset ckanDataset : listItems) {
System.out.println(++i + ") item returned: " + ckanDataset); System.out.println(++i + ") item returned: " + ckanDataset);
} }
long endTime = System.currentTimeMillis()-start;
System.out.println("Terminated in: "+endTime + "ms");
} catch (Exception e) {
e.printStackTrace();
}
} }
@ -89,7 +116,7 @@ public class TestDataCatalogueCMS {
* @return the scope per url * @return the scope per url
* @throws Exception * @throws Exception
*/ */
@Test // @Test
public void countListItemsForStatus() throws Exception { public void countListItemsForStatus() throws Exception {
try { try {
@ -102,7 +129,7 @@ public class TestDataCatalogueCMS {
List<String> emailsAddresses = new ArrayList<String>(); List<String> emailsAddresses = new ArrayList<String>();
// emailsAddresses.add("luca.frosini@isti.cnr.it"); // emailsAddresses.add("luca.frosini@isti.cnr.it");
//emailsAddresses.add("francesco.mangiacrapa@isti.cnr.it"); emailsAddresses.add("francesco.mangiacrapa@isti.cnr.it");
// emailsAddresses.add("pagano@cnr.it"); // emailsAddresses.add("pagano@cnr.it");
String theQuery = mockQueryForEmails(emailsAddresses, "OR"); String theQuery = mockQueryForEmails(emailsAddresses, "OR");

View File

@ -11,7 +11,6 @@ import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datacatalogue.utillibrary.ckan.MarshUnmarshCkanObject; import org.gcube.datacatalogue.utillibrary.ckan.MarshUnmarshCkanObject;
import org.gcube.datacatalogue.utillibrary.ckan.MarshUnmarshCkanObject.METHOD; import org.gcube.datacatalogue.utillibrary.ckan.MarshUnmarshCkanObject.METHOD;
import org.gcube.datacatalogue.utillibrary.gcat.GCatCaller;
import org.gcube.datacatalogue.utillibrary.server.ApplicationProfileScopePerUrlReader; import org.gcube.datacatalogue.utillibrary.server.ApplicationProfileScopePerUrlReader;
import org.gcube.datacatalogue.utillibrary.server.DataCatalogueFactory; import org.gcube.datacatalogue.utillibrary.server.DataCatalogueFactory;
import org.gcube.datacatalogue.utillibrary.server.DataCatalogueImpl; import org.gcube.datacatalogue.utillibrary.server.DataCatalogueImpl;