#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.
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
- [#23525] Removed the scope of xml-apis dependency

View File

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

View File

@ -59,12 +59,15 @@ public interface CkanContentModeratorService extends RemoteService {
* @param theStatus the the status
* @param offset the offset
* @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
* @return the list items for status
* @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;
/**
@ -133,4 +136,5 @@ public interface CkanContentModeratorService extends RemoteService {
* @throws Exception the 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,
AsyncCallback<OperationReport> callback);
/**
* Gets the list items for status.
*
* @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);
void getListItemsForStatus(ItemStatus theStatus, int offset, int limit, boolean allFields,
boolean restrictedToLoggedInUser, String sortForField, AsyncCallback<List<CatalogueDataset>> callback);
/**
* Gets the data for status.

View File

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

View File

@ -13,23 +13,26 @@ import org.gcube.datacatalogue.utillibrary.server.cms.CatalogueContentModeratorS
import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset;
import org.gcube.portlets.widgets.ckancontentmoderator.client.ContentModeratorWidgetConstants;
import org.junit.Test;
import org.slf4j.LoggerFactory;
public class CkanContentModeratorServiceTest {
//private String scope = "/gcube/devsec/devVRE";
private String scope = "/pred4s/preprod/Dorne";
private String scope = "/gcube/devsec/devVRE";
// private String scope = "/pred4s/preprod/Dorne";
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);
//@Test
// @Test
public void test() {
fail("Not yet implemented");
}
//@Test
@Test
public void loadItemsForStatus() {
ScopeProvider.instance.set(scope);
SecurityTokenProvider.instance.set(authorizationToken);
@ -37,12 +40,14 @@ public class CkanContentModeratorServiceTest {
try {
CatalogueContentModeratorSystem cms = CatalogueCMSFactory.getFactory().getCMSPerScope(scope);
Map<String, String> filters = new HashMap<String, String>(1);
filters.put(ContentModeratorWidgetConstants.CKAN_FIELD_NAME_AUTHOR_MAIL, "francesco.mangiacrapa@isti.cnr.it");
List<CkanDataset> items = cms.getListItemsForStatus(itemStatus, 20, 0, filters, GCatCaller.DEFAULT_SORT_VALUE);
filters.put(ContentModeratorWidgetConstants.CKAN_FIELD_NAME_AUTHOR_MAIL,
"francesco.mangiacrapa@isti.cnr.it");
List<CkanDataset> items = cms.getListItemsForStatus(itemStatus, 20, 0, true, filters,
GCatCaller.DEFAULT_SORT_VALUE);
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) {
System.out.println(i++ +")Read dataset: "+ckanDataset);
System.out.println(i++ + ")Read dataset: " + ckanDataset);
}
} catch (Exception e) {
// TODO Auto-generated catch block