task_21363 #1

Closed
francesco.mangiacrapa wants to merge 53 commits from task_21363 into master
8 changed files with 271 additions and 59 deletions
Showing only changes of commit 259a809de1 - Show all commits

View File

@ -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

View File

@ -34,10 +34,8 @@
<distroDirectory>distro</distroDirectory>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
<gwt-material.version>2.4.0</gwt-material.version>
</properties>
<dependencyManagement>
@ -85,6 +83,7 @@
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>

View File

@ -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,31 +35,26 @@ public interface CkanContentModeratorService extends RemoteService {
*/
public void setStatus(ItemStatus theStatus, List<String> itemNames);
/**
* Approve item.
*
* @param itemNames the item names
*/
public void approveItem(List<String> itemNames);
/**
* 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
*/
public void rejectItem(List<String> itemNames, boolean permanentlyDelete, String reasonMsg);
public OperationReport rejectItem(List<String> 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<String> itemNames);
public OperationReport permanentlyDelete(List<String> itemNames) throws Exception;
/**
* Gets the list items for status.
@ -85,4 +79,14 @@ public interface CkanContentModeratorService extends RemoteService {
*/
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<String> itemNames, String moderatorMessage) throws Exception;
}

View File

@ -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,8 +26,16 @@ public interface CkanContentModeratorServiceAsync {
*/
void isContentModeratorEnabled(AsyncCallback<Boolean> callback);
void rejectItem(List<String> itemNames, boolean permanentlyDelete, String reasonMsg, AsyncCallback<Void> 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<String> itemNames, boolean permanentlyDelete, String reasonMsg,
AsyncCallback<OperationReport> callback);
/**
* Gets the list items for status.
@ -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<String> itemNames, AsyncCallback<Void> callback);
void approveItem(List<String> itemNames, String moderatorMessage, AsyncCallback<OperationReport> callback);
/**
* Permanently delete.
@ -67,7 +77,7 @@ public interface CkanContentModeratorServiceAsync {
* @param itemNames the item names
* @param callback the callback
*/
void permanentlyDelete(List<String> itemNames, AsyncCallback<Void> callback);
void permanentlyDelete(List<String> itemNames, AsyncCallback<OperationReport> callback);
/**
* Sets the status.

View File

@ -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
*

View File

@ -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<String> itemNames) {
LOG.info("Called set status " + theStatus + " for Items with name: " + itemNames);
@ -54,12 +93,7 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
+ limit + "]");
List<CatalogueDataset> 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<CkanDataset> 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<String> itemNames) {
LOG.info("Called approve Items with name: " + itemNames);
public OperationReport approveItem(List<String> 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<String> errorListItems = new ArrayList<String>();
List<String> approvedListItems = new ArrayList<String>();
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);
}
}
@Override
public void rejectItem(List<String> itemNames, boolean permanentlyDelete, String reasonMsg) {
// TODO Auto-generated method stub
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 permanentlyDelete(List<String> itemNames) {
LOG.info("Called approve Items with name: " + itemNames);
public OperationReport rejectItem(List<String> 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<String> errorListItems = new ArrayList<String>();
List<String> passedListItems = new ArrayList<String>();
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 OperationReport permanentlyDelete(List<String> 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<String> errorListItems = new ArrayList<String>();
List<String> passedListItems = new ArrayList<String>();
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;

View File

@ -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<String> errorListItems = new ArrayList<String>();
private List<String> passedListItems = new ArrayList<String>();
public OperationReport() {
}
public OperationReport(String operationType, List<String> errorListItems, List<String> passedListItems) {
super();
this.operationType = operationType;
this.errorListItems = errorListItems;
this.passedListItems = passedListItems;
}
public String getOperationType() {
return operationType;
}
public List<String> getErrorListItems() {
return errorListItems;
}
public List<String> getPassedListItems() {
return passedListItems;
}
public void setOperationType(String operationType) {
this.operationType = operationType;
}
public void setErrorListItems(List<String> errorListItems) {
this.errorListItems = errorListItems;
}
public void setPassedListItems(List<String> 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();
}
}

View File

@ -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);