diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
index a0e69ab..8b5c4dc 100644
--- a/.settings/org.eclipse.jdt.core.prefs
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -3,7 +3,7 @@ org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
@@ -13,4 +13,4 @@ org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
-org.eclipse.jdt.core.compiler.source=1.7
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/pom.xml b/pom.xml
index 92f60ea..387fc5d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -34,10 +34,8 @@
distro
UTF-8
UTF-8
- 1.7
+ 1.8
1.8
- ${project.build.directory}/${project.build.finalName}
- 2.4.0
@@ -85,6 +83,7 @@
com.google.gwt
gwt-user
${gwtVersion}
+ provided
com.google.gwt
diff --git a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/CkanContentModeratorService.java b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/CkanContentModeratorService.java
index 8a1e93c..e06c38e 100644
--- a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/CkanContentModeratorService.java
+++ b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/CkanContentModeratorService.java
@@ -4,18 +4,18 @@ import java.util.List;
import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset;
+import org.gcube.portlets.widgets.ckancontentmoderator.shared.OperationReport;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.SearchedData;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
-
/**
- * The client side stub for the RPC service.
+ * The Interface CkanContentModeratorService.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
- * Jun 14, 2021
+ * Jan 11, 2022
*/
@RemoteServiceRelativePath("greet")
public interface CkanContentModeratorService extends RemoteService {
@@ -27,7 +27,6 @@ public interface CkanContentModeratorService extends RemoteService {
*/
public boolean isContentModeratorEnabled();
-
/**
* Sets the status.
*
@@ -36,38 +35,33 @@ public interface CkanContentModeratorService extends RemoteService {
*/
public void setStatus(ItemStatus theStatus, List itemNames);
-
- /**
- * Approve item.
- *
- * @param itemNames the item names
- */
- public void approveItem(List itemNames);
-
-
/**
* Reject item.
*
- * @param itemNames the item names
+ * @param itemNames the item names
* @param permanentlyDelete the permanently delete
- * @param reasonMsg the reason msg
+ * @param reasonMsg the reason msg
+ * @return the operation report
+ * @throws Exception the exception
*/
- public void rejectItem(List itemNames, boolean permanentlyDelete, String reasonMsg);
-
+ public OperationReport rejectItem(List itemNames, boolean permanentlyDelete, String reasonMsg)
+ throws Exception;
/**
* Permanently delete.
*
* @param itemNames the item names
+ * @return the operation report
+ * @throws Exception the exception
*/
- public void permanentlyDelete(List itemNames);
+ public OperationReport permanentlyDelete(List itemNames) throws Exception;
/**
* Gets the list items for status.
*
* @param theStatus the the status
- * @param limit the limit
- * @param offset the offset
+ * @param limit the limit
+ * @param offset the offset
* @return the list items for status
* @throws Exception the exception
*/
@@ -76,13 +70,23 @@ public interface CkanContentModeratorService extends RemoteService {
/**
* Gets the data for status.
*
- * @param status the status
- * @param startIndex the start index
- * @param lenght the lenght
+ * @param status the status
+ * @param startIndex the start index
+ * @param lenght the lenght
* @param serverIndex the server index
* @return the data for status
* @throws Exception the exception
*/
SearchedData getDataForStatus(ItemStatus status, int startIndex, int lenght, int serverIndex) throws Exception;
+ /**
+ * Approve item.
+ *
+ * @param itemNames the item names
+ * @param moderatorMessage the moderator message
+ * @return the operation report
+ * @throws Exception the exception
+ */
+ OperationReport approveItem(List itemNames, String moderatorMessage) throws Exception;
+
}
diff --git a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/CkanContentModeratorServiceAsync.java b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/CkanContentModeratorServiceAsync.java
index 52da20f..3f27be9 100644
--- a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/CkanContentModeratorServiceAsync.java
+++ b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/CkanContentModeratorServiceAsync.java
@@ -4,6 +4,7 @@ import java.util.List;
import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset;
+import org.gcube.portlets.widgets.ckancontentmoderator.shared.OperationReport;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.SearchedData;
import com.google.gwt.user.client.rpc.AsyncCallback;
@@ -14,7 +15,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
- * Jun 23, 2021
+ * Jan 11, 2022
*/
public interface CkanContentModeratorServiceAsync {
@@ -25,16 +26,24 @@ public interface CkanContentModeratorServiceAsync {
*/
void isContentModeratorEnabled(AsyncCallback callback);
-
- void rejectItem(List itemNames, boolean permanentlyDelete, String reasonMsg, AsyncCallback callback);
+ /**
+ * Reject item.
+ *
+ * @param itemNames the item names
+ * @param permanentlyDelete the permanently delete
+ * @param reasonMsg the reason msg
+ * @param callback the callback
+ */
+ void rejectItem(List itemNames, boolean permanentlyDelete, String reasonMsg,
+ AsyncCallback callback);
/**
* Gets the list items for status.
*
* @param theStatus the the status
- * @param limit the limit
- * @param offset the offset
- * @param callback the callback
+ * @param limit the limit
+ * @param offset the offset
+ * @param callback the callback
* @return the list items for status
*/
void getListItemsForStatus(ItemStatus theStatus, int limit, int offset,
@@ -57,9 +66,10 @@ public interface CkanContentModeratorServiceAsync {
* Approve item.
*
* @param itemNames the item names
+ * @param moderatorMessage the moderator message
* @param callback the callback
*/
- void approveItem(List itemNames, AsyncCallback callback);
+ void approveItem(List itemNames, String moderatorMessage, AsyncCallback callback);
/**
* Permanently delete.
@@ -67,7 +77,7 @@ public interface CkanContentModeratorServiceAsync {
* @param itemNames the item names
* @param callback the callback
*/
- void permanentlyDelete(List itemNames, AsyncCallback callback);
+ void permanentlyDelete(List itemNames, AsyncCallback callback);
/**
* Sets the status.
diff --git a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/ContentModeratorPaginatedView.java b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/ContentModeratorPaginatedView.java
index 7acbe8f..27945e6 100644
--- a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/ContentModeratorPaginatedView.java
+++ b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/ContentModeratorPaginatedView.java
@@ -32,7 +32,7 @@ import com.google.gwt.view.client.SingleSelectionModel;
/**
- * The Class ContentModeratorPaginatedView.
+ * The Class GeonaRecordsPaginatedView.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
diff --git a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/server/CkanContentModeratorServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/server/CkanContentModeratorServiceImpl.java
index 72420eb..c3eb09d 100644
--- a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/server/CkanContentModeratorServiceImpl.java
+++ b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/server/CkanContentModeratorServiceImpl.java
@@ -11,6 +11,7 @@ import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset;
import org.gcube.portlets.widgets.ckancontentmoderator.client.CkanContentModeratorService;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset;
+import org.gcube.portlets.widgets.ckancontentmoderator.shared.OperationReport;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.SearchedData;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
@@ -19,20 +20,58 @@ import org.slf4j.LoggerFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
/**
- * The server side implementation of the RPC service.
+ * The Class CkanContentModeratorServiceImpl.
+ *
+ * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
+ *
+ * Jan 11, 2022
*/
@SuppressWarnings("serial")
public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implements CkanContentModeratorService {
private static Logger LOG = LoggerFactory.getLogger(CkanContentModeratorServiceImpl.class);
+ /**
+ * Checks if is content moderator enabled.
+ *
+ * @return true, if is content moderator enabled
+ */
@Override
public boolean isContentModeratorEnabled() {
LOG.info("called isContentModeratorEnabled");
- LOG.warn("isContentModeratorEnabled METHOD MUST BE IMPLEMENTED!!!");
- return true;
+ String scope = setContexts();
+ boolean isContentModeratorEnabled = false;
+ try {
+ DataCatalogueImpl catalogueImpl = CatalogueCMSFactory.getFactory().getCatalogueImplPerScope(scope);
+ CatalogueContentModeratorSystem cmsInstance = catalogueImpl.getCatalogueContentModerator();
+ isContentModeratorEnabled = cmsInstance.isContentModeratorEnabled();
+ } catch (Exception e) {
+ LOG.error("Error occured on cheching isContentModeratorEnabled, so returning false", e);
+ return false;
+ }
+ return isContentModeratorEnabled;
}
+ /**
+ * Sets the contexts.
+ *
+ * @return the scope operating in
+ */
+ private String setContexts() {
+ String scope = WsUtil.getCurrentScope(this.getThreadLocalRequest());
+ GCubeUser user = WsUtil.getCurrentUser(this.getThreadLocalRequest());
+ String token = WsUtil.getCurrentToken(scope, user.getUsername());
+ ScopeProvider.instance.set(scope);
+ SecurityTokenProvider.instance.set(token);
+ return scope;
+ }
+
+ /**
+ * Sets the status.
+ *
+ * @param theStatus the the status
+ * @param itemNames the item names
+ */
@Override
public void setStatus(ItemStatus theStatus, List itemNames) {
LOG.info("Called set status " + theStatus + " for Items with name: " + itemNames);
@@ -54,12 +93,7 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
+ limit + "]");
List datasetList = null;
try {
-
- String scope = WsUtil.getCurrentScope(this.getThreadLocalRequest());
- GCubeUser user = WsUtil.getCurrentUser(this.getThreadLocalRequest());
- String token = WsUtil.getCurrentToken(scope, user.getUsername());
- ScopeProvider.instance.set(scope);
- SecurityTokenProvider.instance.set(token);
+ String scope = setContexts();
DataCatalogueImpl catalogueImpl = CatalogueCMSFactory.getFactory().getCatalogueImplPerScope(scope);
CatalogueContentModeratorSystem cmsInstance = catalogueImpl.getCatalogueContentModerator();
List datasets = cmsInstance.getListItemsForStatus(theStatus, limit, offset);
@@ -79,31 +113,136 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new Exception(
- "Error occurrend on reading items for status: " + theStatus + ". Caused by: " + e.getMessage());
+ "Error occurred on reading items for status: " + theStatus + ". Caused by: " + e.getMessage());
}
LOG.info("returning " + datasetList.size() + " dataset");
return datasetList;
}
+ /**
+ * Approve item.
+ *
+ * @param itemNames the item names
+ * @param moderatorMessage the moderator message
+ * @return the operation report
+ * @throws Exception the exception
+ */
@Override
- public void approveItem(List itemNames) {
- LOG.info("Called approve Items with name: " + itemNames);
+ public OperationReport approveItem(List itemNames, String moderatorMessage) throws Exception {
+ LOG.info("Called approveItem with name/s: " + itemNames);
+ try {
+ String scope = setContexts();
+ DataCatalogueImpl catalogueImpl = CatalogueCMSFactory.getFactory().getCatalogueImplPerScope(scope);
+ CatalogueContentModeratorSystem cmsInstance = catalogueImpl.getCatalogueContentModerator();
+
+ List errorListItems = new ArrayList();
+ List approvedListItems = new ArrayList();
+ for (String itemName : itemNames) {
+ try {
+ cmsInstance.approveItem(itemName, moderatorMessage);
+ approvedListItems.add(itemName);
+ } catch (Exception e) {
+ LOG.warn("Error when approving itemName: " + itemName, e);
+ errorListItems.add(itemName);
+ }
+ }
+
+ return new OperationReport(ItemStatus.APPROVED.getLabel(), errorListItems, approvedListItems);
+
+ } catch (Exception e) {
+ LOG.error(e.getMessage(), e);
+ throw new Exception("Error occurred on approving item/s: " + itemNames + ". Caused by: " + e.getMessage());
+ }
}
+ /**
+ * Reject item.
+ *
+ * @param itemNames the item names
+ * @param permanentlyDelete the permanently delete
+ * @param reasonMsg the reason msg
+ * @return the operation report
+ * @throws Exception the exception
+ */
@Override
- public void rejectItem(List itemNames, boolean permanentlyDelete, String reasonMsg) {
- // TODO Auto-generated method stub
+ public OperationReport rejectItem(List itemNames, boolean permanentlyDelete, String reasonMsg)
+ throws Exception {
+ LOG.info("Called rejectItem with name/s: " + itemNames + ", permanentlyDelete: " + permanentlyDelete);
+ try {
+ String scope = setContexts();
+ DataCatalogueImpl catalogueImpl = CatalogueCMSFactory.getFactory().getCatalogueImplPerScope(scope);
+ CatalogueContentModeratorSystem cmsInstance = catalogueImpl.getCatalogueContentModerator();
+
+ List errorListItems = new ArrayList();
+ List passedListItems = new ArrayList();
+ for (String itemName : itemNames) {
+ try {
+ cmsInstance.rejectItem(itemName, permanentlyDelete, reasonMsg);
+ passedListItems.add(itemName);
+ } catch (Exception e) {
+ LOG.warn("Error when rejecting itemName: " + itemName, e);
+ errorListItems.add(itemName);
+ }
+ }
+
+ return new OperationReport(ItemStatus.REJECTED.getLabel(), errorListItems, passedListItems);
+
+ } catch (Exception e) {
+ LOG.error(e.getMessage(), e);
+ throw new Exception("Error occurred on rejecting item/s: " + itemNames + ". Caused by: " + e.getMessage());
+ }
}
+ /**
+ * Permanently delete.
+ *
+ * @param itemNames the item names
+ * @return the operation report
+ * @throws Exception the exception
+ */
@Override
- public void permanentlyDelete(List itemNames) {
- LOG.info("Called approve Items with name: " + itemNames);
+ public OperationReport permanentlyDelete(List itemNames) throws Exception {
+ LOG.info("Called permanently delete Items with name/s: " + itemNames);
+ try {
+ String scope = setContexts();
+ DataCatalogueImpl catalogueImpl = CatalogueCMSFactory.getFactory().getCatalogueImplPerScope(scope);
+ CatalogueContentModeratorSystem cmsInstance = catalogueImpl.getCatalogueContentModerator();
+
+ List errorListItems = new ArrayList();
+ List passedListItems = new ArrayList();
+ for (String itemName : itemNames) {
+ try {
+ cmsInstance.permanentlyDelete(itemName);
+ passedListItems.add(itemName);
+ } catch (Exception e) {
+ LOG.warn("Error when deleting permanently the itemName: " + itemName, e);
+ errorListItems.add(itemName);
+ }
+ }
+
+ return new OperationReport("Permanently Delete", errorListItems, passedListItems);
+
+ } catch (Exception e) {
+ LOG.error(e.getMessage(), e);
+ throw new Exception(
+ "Error occurred on permanently delete item/s: " + itemNames + ". Caused by: " + e.getMessage());
+ }
}
+ /**
+ * Gets the data for status.
+ *
+ * @param status the status
+ * @param offset the offset
+ * @param limit the limit
+ * @param serverStartIndex the server start index
+ * @return the data for status
+ * @throws Exception the exception
+ */
@Override
public SearchedData getDataForStatus(ItemStatus status, int offset, int limit, int serverStartIndex)
throws Exception {
@@ -111,11 +250,7 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
+ ", serverIndex: " + serverStartIndex);
try {
- String scope = WsUtil.getCurrentScope(this.getThreadLocalRequest());
- GCubeUser user = WsUtil.getCurrentUser(this.getThreadLocalRequest());
- String token = WsUtil.getCurrentToken(scope, user.getUsername());
- ScopeProvider.instance.set(scope);
- SecurityTokenProvider.instance.set(token);
+ String scope = setContexts();
// int searchStartIndex = limit < serverStartIndex? serverStartIndex : offset;
int searchStartIndex = offset;
diff --git a/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/shared/OperationReport.java b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/shared/OperationReport.java
new file mode 100644
index 0000000..ace9536
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/shared/OperationReport.java
@@ -0,0 +1,64 @@
+package org.gcube.portlets.widgets.ckancontentmoderator.shared;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+public class OperationReport implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 879318163198093725L;
+ private String operationType;
+ private List errorListItems = new ArrayList();
+ private List passedListItems = new ArrayList();
+
+ public OperationReport() {
+ }
+
+ public OperationReport(String operationType, List errorListItems, List passedListItems) {
+ super();
+ this.operationType = operationType;
+ this.errorListItems = errorListItems;
+ this.passedListItems = passedListItems;
+ }
+
+ public String getOperationType() {
+ return operationType;
+ }
+
+ public List getErrorListItems() {
+ return errorListItems;
+ }
+
+ public List getPassedListItems() {
+ return passedListItems;
+ }
+
+ public void setOperationType(String operationType) {
+ this.operationType = operationType;
+ }
+
+ public void setErrorListItems(List errorListItems) {
+ this.errorListItems = errorListItems;
+ }
+
+ public void setPassedListItems(List passedListItems) {
+ this.passedListItems = passedListItems;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("OperationReport [operationType=");
+ builder.append(operationType);
+ builder.append(", errorListItems=");
+ builder.append(errorListItems);
+ builder.append(", passedListItems=");
+ builder.append(passedListItems);
+ builder.append("]");
+ return builder.toString();
+ }
+
+}
diff --git a/src/test/java/org/gcube/portlets/widgets/ckancontentmoderator/server/CkanContentModeratorServiceTest.java b/src/test/java/org/gcube/portlets/widgets/ckancontentmoderator/server/CkanContentModeratorServiceTest.java
index 1e7f0da..a4ef342 100644
--- a/src/test/java/org/gcube/portlets/widgets/ckancontentmoderator/server/CkanContentModeratorServiceTest.java
+++ b/src/test/java/org/gcube/portlets/widgets/ckancontentmoderator/server/CkanContentModeratorServiceTest.java
@@ -16,7 +16,7 @@ public class CkanContentModeratorServiceTest {
private String scope = "/gcube/devsec/devVRE";
private String testUser = "francesco.mangiacrapa";
- private String authorizationToken = "8e74a17c-92f1-405a-b591-3a6090066248-98187548";
+ private String authorizationToken = "";
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(CkanContentModeratorServiceTest.class);