#23692 Integrated with new getListItemsForStatus with allFields parameter #2

Merged
francesco.mangiacrapa merged 1 commits from task_23692 into master 2022-08-01 15:12:23 +02:00
6 changed files with 54 additions and 46 deletions

View File

@ -4,6 +4,12 @@
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.1.0-SNAPSHOT] - 2022-07-29
#### Enhancements
- [#23692] Optimized the listing and the paging of catalogue items
## [v1.0.1] - 2022-06-27 ## [v1.0.1] - 2022-06-27
- [#23525] Removed the scope of xml-apis dependency - [#23525] Removed the scope of xml-apis dependency

View File

@ -14,7 +14,7 @@
<groupId>org.gcube.portlets.widgets</groupId> <groupId>org.gcube.portlets.widgets</groupId>
<artifactId>ckan-content-moderator-widget</artifactId> <artifactId>ckan-content-moderator-widget</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>1.0.1</version> <version>1.1.0-SNAPSHOT</version>
<name>gCube Ckan Content Moderator Widget</name> <name>gCube Ckan Content Moderator Widget</name>
<description> <description>

View File

@ -59,12 +59,15 @@ public interface CkanContentModeratorService extends RemoteService {
* @param theStatus the the status * @param theStatus the the status
* @param offset the offset * @param offset the offset
* @param limit the limit * @param limit the limit
* @param restrictedToLoggedInUser the restricted to logged in user * @param allFields the all fields. If true returns the all
* fields of an item
* @param restrictedToLoggedInUser if true restricts the list of items to logged
* in user
* @param sortForField the sort for field * @param sortForField the sort for field
* @return the list items for status * @return the list items for status
* @throws Exception the exception * @throws Exception the exception
*/ */
public List<CatalogueDataset> getListItemsForStatus(ItemStatus theStatus, int offset, int limit, List<CatalogueDataset> getListItemsForStatus(ItemStatus theStatus, int offset, int limit, boolean allFields,
boolean restrictedToLoggedInUser, String sortForField) throws Exception; boolean restrictedToLoggedInUser, String sortForField) throws Exception;
/** /**
@ -133,4 +136,5 @@ public interface CkanContentModeratorService extends RemoteService {
* @throws Exception the exception * @throws Exception the exception
*/ */
CatalogueDataset getItemForName(String itemName) throws Exception; CatalogueDataset getItemForName(String itemName) throws Exception;
} }

View File

@ -30,19 +30,8 @@ public interface CkanContentModeratorServiceAsync {
void rejectItem(List<String> itemNames, boolean permanentlyDelete, String reasonMsg, void rejectItem(List<String> itemNames, boolean permanentlyDelete, String reasonMsg,
AsyncCallback<OperationReport> callback); AsyncCallback<OperationReport> callback);
/** void getListItemsForStatus(ItemStatus theStatus, int offset, int limit, boolean allFields,
* Gets the list items for status. boolean restrictedToLoggedInUser, String sortForField, AsyncCallback<List<CatalogueDataset>> callback);
*
* @param theStatus the the status
* @param offset the offset
* @param limit the limit
* @param restrictedToLoggedInUser the restricted to logged in user
* @param sortForField the sort for field
* @param callback the callback
* @return the list items for status
*/
void getListItemsForStatus(ItemStatus theStatus, int offset, int limit, boolean restrictedToLoggedInUser,
String sortForField, AsyncCallback<List<CatalogueDataset>> callback);
/** /**
* Gets the data for status. * Gets the data for status.

View File

@ -176,6 +176,8 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
* @param theStatus the the status * @param theStatus the the status
* @param offset the offset * @param offset the offset
* @param limit the limit * @param limit the limit
* @param allFields the all fields. If true returns the all
* fields of an item
* @param restrictedToLoggedInUser if true restricts the list of items to logged * @param restrictedToLoggedInUser if true restricts the list of items to logged
* in user * in user
* @param sortForField the sort for field * @param sortForField the sort for field
@ -184,7 +186,7 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
*/ */
@Override @Override
public List<CatalogueDataset> getListItemsForStatus(ItemStatus theStatus, int offset, int limit, public List<CatalogueDataset> getListItemsForStatus(ItemStatus theStatus, int offset, int limit,
boolean restrictedToLoggedInUser, String sortForField) throws Exception { boolean allFields, boolean restrictedToLoggedInUser, String sortForField) throws Exception {
LOG.info("called getListItemsForStatus with [status: " + theStatus + ", offset: " + offset + ", limit: " + limit LOG.info("called getListItemsForStatus with [status: " + theStatus + ", offset: " + offset + ", limit: " + limit
+ ", restrictedToLoggedInUser: " + restrictedToLoggedInUser + "]"); + ", restrictedToLoggedInUser: " + restrictedToLoggedInUser + "]");
List<CatalogueDataset> datasetList = null; List<CatalogueDataset> datasetList = null;
@ -201,7 +203,7 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
filters.put(ContentModeratorWidgetConstants.CKAN_FIELD_NAME_AUTHOR_MAIL, valueOfQueryEmails); filters.put(ContentModeratorWidgetConstants.CKAN_FIELD_NAME_AUTHOR_MAIL, valueOfQueryEmails);
} }
List<CkanDataset> datasets = cmsInstance.getListItemsForStatus(theStatus, limit, offset, filters, List<CkanDataset> datasets = cmsInstance.getListItemsForStatus(theStatus, limit, offset, allFields, filters,
sortForField); sortForField);
if (datasets != null) { if (datasets != null) {
int size = datasets.size(); int size = datasets.size();
@ -258,22 +260,24 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
ds = toPatchedCatalogueDataset(ckanDataset, catalogueImpl.getCatalogueUrl()); ds = toPatchedCatalogueDataset(ckanDataset, catalogueImpl.getCatalogueUrl());
Boolean userModerator = isModeratorRoleAssigned(); Boolean userModerator = isModeratorRoleAssigned();
moderationCheckPassed = userModerator?true:false; moderationCheckPassed = userModerator ? true : false;
LOG.info("Moderation check: is the user a Moderator? "+moderationCheckPassed); LOG.info("Moderation check: is the user a Moderator? " + moderationCheckPassed);
//The user is not a Moderator, yes otherwise // The user is not a Moderator, yes otherwise
if(!moderationCheckPassed) { if (!moderationCheckPassed) {
String datasetAuthorMail = ds.getAuthorEmail(); String datasetAuthorMail = ds.getAuthorEmail();
String userMail = user.getEmail(); String userMail = user.getEmail();
if(datasetAuthorMail!=null && userMail!=null && datasetAuthorMail.compareTo(userMail)==0) { if (datasetAuthorMail != null && userMail != null
//The user is the owner of the dataset, so he/she can view the dataset (moderation check passed) && datasetAuthorMail.compareTo(userMail) == 0) {
// The user is the owner of the dataset, so he/she can view the dataset
// (moderation check passed)
moderationCheckPassed = true; moderationCheckPassed = true;
} }
LOG.info("Moderation check: is the user the owner of the dataset? "+moderationCheckPassed); LOG.info("Moderation check: is the user the owner of the dataset? " + moderationCheckPassed);
} }
} }
} }
if(!moderationCheckPassed) { if (!moderationCheckPassed) {
LOG.info("Moderation ckeck not passed, returning null"); LOG.info("Moderation ckeck not passed, returning null");
ds = null; ds = null;
} }
@ -283,7 +287,7 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
throw e; throw e;
} }
LOG.info("getItemForName "+itemName+", returning: " + ds); LOG.info("getItemForName " + itemName + ", returning: " + ds);
return ds; return ds;
} }
@ -472,7 +476,7 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
List<CatalogueDataset> listDataset = new ArrayList<CatalogueDataset>(); List<CatalogueDataset> listDataset = new ArrayList<CatalogueDataset>();
try { try {
LOG.debug("getListItemsForStatus with searchStartIndex: " + searchStartIndex + ", limit: " + limit); LOG.debug("getListItemsForStatus with searchStartIndex: " + searchStartIndex + ", limit: " + limit);
listDataset = getListItemsForStatus(status, searchStartIndex, limit, restrictedToLoggedInUser, listDataset = getListItemsForStatus(status, searchStartIndex, limit, true, restrictedToLoggedInUser,
sortForField); sortForField);
} catch (Exception e) { } catch (Exception e) {
String error = "Error occurred on getting items for status: " + status; String error = "Error occurred on getting items for status: " + status;

View File

@ -13,36 +13,41 @@ import org.gcube.datacatalogue.utillibrary.server.cms.CatalogueContentModeratorS
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.portlets.widgets.ckancontentmoderator.client.ContentModeratorWidgetConstants; import org.gcube.portlets.widgets.ckancontentmoderator.client.ContentModeratorWidgetConstants;
import org.junit.Test;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
public class CkanContentModeratorServiceTest { public class CkanContentModeratorServiceTest {
//private String scope = "/gcube/devsec/devVRE"; private String scope = "/gcube/devsec/devVRE";
private String scope = "/pred4s/preprod/Dorne"; // private String scope = "/pred4s/preprod/Dorne";
private String testUser = "francesco.mangiacrapa"; private String testUser = "francesco.mangiacrapa";
private String authorizationToken = ""; // private String authorizationToken = "";
// private String scope = "/gcube/devsec";
private String authorizationToken = "8d2107bd-640c-4cdc-88cd-72d3242d893e-98187548"; // devVRE
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(CkanContentModeratorServiceTest.class); private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(CkanContentModeratorServiceTest.class);
//@Test // @Test
public void test() { public void test() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
//@Test @Test
public void loadItemsForStatus() { public void loadItemsForStatus() {
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
SecurityTokenProvider.instance.set(authorizationToken); SecurityTokenProvider.instance.set(authorizationToken);
ItemStatus itemStatus = ItemStatus.PENDING; ItemStatus itemStatus = ItemStatus.PENDING;
try { try {
CatalogueContentModeratorSystem cms = CatalogueCMSFactory.getFactory().getCMSPerScope(scope); CatalogueContentModeratorSystem cms = CatalogueCMSFactory.getFactory().getCMSPerScope(scope);
Map<String, String> filters = new HashMap<String, String>(1); Map<String, String> filters = new HashMap<String, String>(1);
filters.put(ContentModeratorWidgetConstants.CKAN_FIELD_NAME_AUTHOR_MAIL, "francesco.mangiacrapa@isti.cnr.it"); filters.put(ContentModeratorWidgetConstants.CKAN_FIELD_NAME_AUTHOR_MAIL,
List<CkanDataset> items = cms.getListItemsForStatus(itemStatus, 20, 0, filters, GCatCaller.DEFAULT_SORT_VALUE); "francesco.mangiacrapa@isti.cnr.it");
List<CkanDataset> items = cms.getListItemsForStatus(itemStatus, 20, 0, true, filters,
GCatCaller.DEFAULT_SORT_VALUE);
int i = 0; int i = 0;
System.out.println("Datasets with status "+itemStatus+" are: "+items.size()); System.out.println("Datasets with status " + itemStatus + " are: " + items.size());
for (CkanDataset ckanDataset : items) { for (CkanDataset ckanDataset : items) {
System.out.println(i++ +")Read dataset: "+ckanDataset); System.out.println(i++ + ")Read dataset: " + ckanDataset);
} }
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block