added check configurations. Improved GUI

This commit is contained in:
Francesco Mangiacrapa 2022-02-22 14:48:17 +01:00
parent 12bca95bf8
commit 2ca89206e6
13 changed files with 416 additions and 250 deletions

View File

@ -0,0 +1,162 @@
package org.gcube.portlets.widgets.ckancontentmoderator.client;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
* The Class CkanContentModeratorCheckConfig.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Feb 22, 2022
*/
public class CkanContentModeratorCheckConfig {
private int configurationLoaded = 0;
private static final int CONFIGURATION_EXPECTED = 2;
private int MAX_RETRY_ON_LOADING_CONFIG = 20;
private int attemptLC = 0;
private Boolean contentModerationEnabled = null;
private Boolean moderatorRoleAssigned = null;
/**
* Instantiates a new ckan content moderator check config.
*/
public CkanContentModeratorCheckConfig() {
}
/**
* Check configs.
*
* @param whenDone the when done
* @throws Exception the exception
*/
public void checkConfigs(final Command whenDone) throws Exception {
configurationLoaded = 0;
attemptLC = 0;
CkanContentModeratorWidgetController.contentModeratorService
.isContentModeratorEnabled(new AsyncCallback<Boolean>() {
@Override
public void onFailure(Throwable caught) {
contentModerationEnabled = false;
incrementConfigurationLoaded();
}
@Override
public void onSuccess(Boolean result) {
incrementConfigurationLoaded();
GWT.log("isContentModeratorEnabled: "+result);
contentModerationEnabled = result;
}
});
CkanContentModeratorWidgetController.contentModeratorService
.isModeratorRoleAssigned(new AsyncCallback<Boolean>() {
@Override
public void onFailure(Throwable caught) {
moderatorRoleAssigned = false;
incrementConfigurationLoaded();
}
@Override
public void onSuccess(Boolean result) {
incrementConfigurationLoaded();
GWT.log("isModeratorRoleAssigned: "+result);
moderatorRoleAssigned = result;
}
});
if (whenDone != null) {
final Timer timer = new Timer() {
@Override
public void run() {
attemptLC++;
GWT.log("checking configuration loaded, attempt "+attemptLC+" of "+MAX_RETRY_ON_LOADING_CONFIG);
boolean configsLoaded = getConfigurationLoaded() == CONFIGURATION_EXPECTED;
GWT.log("configsLoaded: "+configsLoaded);
if (configsLoaded) {
GWT.log("ContentModeratorCheckConfig loaded correclty");
whenDone.execute();
this.cancel();
}
if (attemptLC > MAX_RETRY_ON_LOADING_CONFIG) {
GWT.log("MAX_RETRY_ON_LOADING_CONFIG reached, timer cancelled");
this.cancel();
}
}
};
timer.scheduleRepeating(500);
}
}
/**
* Increment configuration loaded.
*/
private void incrementConfigurationLoaded() {
configurationLoaded++;
}
/**
* Decrement configuration loaded.
*/
private synchronized void decrementConfigurationLoaded() {
configurationLoaded--;
}
/**
* Gets the configuration loaded.
*
* @return the configuration loaded
*/
private synchronized int getConfigurationLoaded() {
return configurationLoaded;
}
/**
* Checks if is moderator role assigned.
*
* @return the boolean
* @throws Exception the exception
*/
public Boolean isModeratorRoleAssigned() throws Exception {
if (moderatorRoleAssigned == null)
throw new Exception(
"Please, first check if the Moderator role is assigned in this context by calling checkContentModeratorConfiguration");
return moderatorRoleAssigned;
}
/**
* Checks if is content moderation enabled.
*
* @return true, if is content moderation enabled
* @throws Exception the exception
*/
public boolean isContentModerationEnabled() throws Exception {
if (contentModerationEnabled == null)
throw new Exception(
"Please, first check if the content moderation is enabled in this context by calling checkContentModeratorConfiguration");
return contentModerationEnabled;
}
}

View File

@ -3,7 +3,6 @@ package org.gcube.portlets.widgets.ckancontentmoderator.client;
import java.util.List; import java.util.List;
import org.gcube.datacatalogue.utillibrary.shared.ItemStatus; import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.CMSUserRole;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset; import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.ModerationUserRole; import org.gcube.portlets.widgets.ckancontentmoderator.shared.ModerationUserRole;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.OperationReport; import org.gcube.portlets.widgets.ckancontentmoderator.shared.OperationReport;
@ -27,7 +26,7 @@ public interface CkanContentModeratorService extends RemoteService {
* *
* @return true, if is content moderator enabled * @return true, if is content moderator enabled
*/ */
public boolean isContentModeratorEnabled(); public Boolean isContentModeratorEnabled();
/** /**
* Sets the status. Currently, this only used to change the status from Rejected * Sets the status. Currently, this only used to change the status from Rejected
@ -76,7 +75,7 @@ public interface CkanContentModeratorService extends RemoteService {
* Gets the data for status. * Gets the data for status.
* *
* @param status the status * @param status the status
* @param startIndex the start index * @param star@Override tIndex the start index
* @param lenght the lenght * @param lenght the lenght
* @param serverIndex the server index * @param serverIndex the server index
* @return the data for status * @return the data for status
@ -102,4 +101,12 @@ public interface CkanContentModeratorService extends RemoteService {
* @throws Exception the exception * @throws Exception the exception
*/ */
ModerationUserRole getCMSRolesForUserInTheContext() throws Exception; ModerationUserRole getCMSRolesForUserInTheContext() throws Exception;
/**
* Checks if is moderator role assigned.
*
* @return the moderation user role
* @throws Exception the exception
*/
Boolean isModeratorRoleAssigned() throws Exception;
} }

View File

@ -96,4 +96,11 @@ public interface CkanContentModeratorServiceAsync {
*/ */
void getCMSRolesForUserInTheContext(AsyncCallback<ModerationUserRole> callback); void getCMSRolesForUserInTheContext(AsyncCallback<ModerationUserRole> callback);
/**
* Checks if is moderator role assigned.
*
* @param callback the callback
*/
void isModeratorRoleAssigned(AsyncCallback<Boolean> callback);
} }

View File

@ -15,7 +15,7 @@ import com.google.gwt.user.client.ui.ComplexPanel;
*/ */
public class CkanContentModeratorWidget { public class CkanContentModeratorWidget {
CkanContentModeratorWidgetController cmsController; private CkanContentModeratorWidgetController cmsController;
/** /**
* Instantiates a new ckan content moderator widget. * Instantiates a new ckan content moderator widget.
@ -24,36 +24,10 @@ public class CkanContentModeratorWidget {
* @param displayFields the display fields * @param displayFields the display fields
* @param sortByField the sort by field * @param sortByField the sort by field
*/ */
public CkanContentModeratorWidget(ItemStatus status, DISPLAY_FIELD[] displayFields, DISPLAY_FIELD sortByField) { public CkanContentModeratorWidget(ItemStatus status, DISPLAY_FIELD[] displayFields, DISPLAY_FIELD sortByField,
Command onConfigurationLoaded) {
cmsController = new CkanContentModeratorWidgetController(status, displayFields, sortByField); cmsController = new CkanContentModeratorWidgetController(status, displayFields, sortByField);
try {
cmsController.checkContentModeratorConfiguration(null);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Checks if is content moderator enabled.
*
* @return true, if is content moderator enabled
* @throws Exception the exception
*/
public boolean isContentModeratorEnabled() throws Exception {
return cmsController.isContentModeratorEnabled();
}
/**
* Check content moderator configuration.
*
* @param onSuccess the on success
* @throws Exception the exception
*/
public void checkContentModeratorConfiguration(final Command onSuccess) throws Exception {
cmsController.checkContentModeratorConfiguration(onSuccess);
} }
/** /**
@ -64,4 +38,5 @@ public class CkanContentModeratorWidget {
public ComplexPanel getPanel() { public ComplexPanel getPanel() {
return cmsController.getMainPanel(); return cmsController.getMainPanel();
} }
} }

View File

@ -16,6 +16,8 @@ import org.gcube.portlets.widgets.ckancontentmoderator.client.events.SelectItems
import org.gcube.portlets.widgets.ckancontentmoderator.client.events.SelectItemsWithItemStatusEventHandler; import org.gcube.portlets.widgets.ckancontentmoderator.client.events.SelectItemsWithItemStatusEventHandler;
import org.gcube.portlets.widgets.ckancontentmoderator.client.events.ShowItemEvent; import org.gcube.portlets.widgets.ckancontentmoderator.client.events.ShowItemEvent;
import org.gcube.portlets.widgets.ckancontentmoderator.client.events.ShowItemEventHandler; import org.gcube.portlets.widgets.ckancontentmoderator.client.events.ShowItemEventHandler;
import org.gcube.portlets.widgets.ckancontentmoderator.client.events.ShowMessageEvent;
import org.gcube.portlets.widgets.ckancontentmoderator.client.events.ShowMessageEventHandler;
import org.gcube.portlets.widgets.ckancontentmoderator.client.events.TableRangeViewChangedEvent; import org.gcube.portlets.widgets.ckancontentmoderator.client.events.TableRangeViewChangedEvent;
import org.gcube.portlets.widgets.ckancontentmoderator.client.events.TableRangeViewChangedEventHandler; import org.gcube.portlets.widgets.ckancontentmoderator.client.events.TableRangeViewChangedEventHandler;
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.CkanFramePanel; import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.CkanFramePanel;
@ -26,11 +28,10 @@ import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.table.ItemsTabl
import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset; import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset;
import com.github.gwtbootstrap.client.ui.Alert; import com.github.gwtbootstrap.client.ui.Alert;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.ComplexPanel; import com.google.gwt.user.client.ui.ComplexPanel;
import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.FlowPanel;
@ -51,7 +52,7 @@ public class CkanContentModeratorWidgetController {
private ContentModeratorToolbar toolbar; private ContentModeratorToolbar toolbar;
private MainTabPanel mainTabPanel = new MainTabPanel(); private MainTabPanel mainTabPanel = new MainTabPanel();
private Boolean isContentModeratorEnabled = null;
public final static HandlerManager eventBus = new HandlerManager(null); public final static HandlerManager eventBus = new HandlerManager(null);
private HomeView howeView; private HomeView howeView;
@ -170,14 +171,36 @@ public class CkanContentModeratorWidgetController {
mainTabPanel.selectTab(0); mainTabPanel.selectTab(0);
} }
if(statusSelectedEvent.getDisplayMessage()!=null) { if (statusSelectedEvent.getDisplayMessage() != null) {
final Alert alert = new Alert(statusSelectedEvent.getDisplayMessage()); showMessage(statusSelectedEvent.getDisplayMessage(), statusSelectedEvent.getAlertType());
alert.setType(statusSelectedEvent.getAlertType()); }
}
});
eventBus.addHandler(ShowMessageEvent.TYPE, new ShowMessageEventHandler() {
@Override
public void onShowMessage(ShowMessageEvent showMessageEvent) {
if (showMessageEvent.getMsg() != null) {
showMessage(showMessageEvent.getMsg(), showMessageEvent.getAlerType());
}
}
});
}
private void showMessage(String msg, AlertType alertType) {
final Alert alert = new Alert(msg);
alertType = alertType != null ? alertType : AlertType.INFO;
alert.setType(alertType);
alert.setClose(true); alert.setClose(true);
alert.setAnimation(true); alert.setAnimation(true);
infoPanel.add(alert); infoPanel.add(alert);
//Cleans the info panel after 10 sec. // Cleans the info panel after 12 sec.
Timer t = new Timer() { Timer t = new Timer() {
@Override @Override
@ -186,54 +209,7 @@ public class CkanContentModeratorWidgetController {
} }
}; };
t.schedule(10000); t.schedule(12000);
}
}
});
}
/**
* Checks if is content moderator enabled.
*
* @return true, if is content moderator enabled
* @throws Exception the exception
*/
public boolean isContentModeratorEnabled() throws Exception {
if (isContentModeratorEnabled == null)
throw new Exception("Please, first check if the content moderator is enabled in this context");
return isContentModeratorEnabled;
}
/**
* Check content moderator configuration.
*
* @param whenDone the when done
* @throws Exception the exception
*/
public void checkContentModeratorConfiguration(final Command whenDone) throws Exception {
contentModeratorService.isContentModeratorEnabled(new AsyncCallback<Boolean>() {
@Override
public void onFailure(Throwable caught) {
whenDone.execute();
}
@Override
public void onSuccess(Boolean result) {
isContentModeratorEnabled = result;
if (whenDone != null)
whenDone.execute();
}
});
} }
/** /**

View File

@ -1,7 +1,6 @@
package org.gcube.portlets.widgets.ckancontentmoderator.client; package org.gcube.portlets.widgets.ckancontentmoderator.client;
import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
/** /**
* Entry point classes define <code>onModuleLoad()</code>. * Entry point classes define <code>onModuleLoad()</code>.
@ -14,41 +13,10 @@ public class CkanContentModeratorWidgetEntryPoint implements EntryPoint {
private static final String SERVER_ERROR = "An error occurred while " private static final String SERVER_ERROR = "An error occurred while "
+ "attempting to contact the server. Please check your network " + "connection and try again."; + "attempting to contact the server. Please check your network " + "connection and try again.";
/**
* Create a remote service proxy to talk to the server-side Greeting service.
*/
private final CkanContentModeratorServiceAsync greetingService = GWT.create(CkanContentModeratorService.class);
/** /**
* This is the entry point method. * This is the entry point method.
*/ */
public void onModuleLoad() { public void onModuleLoad() {
/*StyleInjector.inject(DataTableClientBundle.INSTANCE.dataTable().getText());
// MaterialDataTable<String> table = new MaterialDataTable<String>();
// table.getTableTitle().setText("Customers");
// List<String> users = new ArrayList<String>();
// users.add("Pippo");
// table.setRowData(0, users);
final CustomizedView cvTable = new CustomizedView();
RootPanel.get().add(cvTable);
// table.getView().refresh();
greetingService.getListItemsForStatus(ItemStatus.PENDING, 20, 0, new AsyncCallback<List<CatalogueDataset>>() {
@Override
public void onSuccess(List<CatalogueDataset> result) {
cvTable.setData(result);
}
@Override
public void onFailure(Throwable caught) {
Window.alert(caught.getMessage());
}
});*/
} }
} }

View File

@ -0,0 +1,68 @@
package org.gcube.portlets.widgets.ckancontentmoderator.client.events;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
import com.google.gwt.event.shared.GwtEvent;
/**
* The Class ShowMessageEvent.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Feb 22, 2022
*/
public class ShowMessageEvent extends GwtEvent<ShowMessageEventHandler> {
public static Type<ShowMessageEventHandler> TYPE = new Type<ShowMessageEventHandler>();
private String msg;
private AlertType alerType;
/**
* Instantiates a new click item event.
*
* @param msg the msg
* @param alerType the aler type
*/
public ShowMessageEvent(String msg, AlertType alerType) {
this.msg = msg;
this.alerType = alerType;
}
/**
* Gets the associated type.
*
* @return the associated type
*/
/*
* (non-Javadoc)
*
* @see com.google.gwt.event.shared.GwtEvent#getAssociatedType()
*/
@Override
public Type<ShowMessageEventHandler> getAssociatedType() {
return TYPE;
}
/**
* Dispatch.
*
* @param handler the handler
*/
/*
* (non-Javadoc)
*
* @see
* com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared.
* EventHandler)
*/
@Override
protected void dispatch(ShowMessageEventHandler handler) {
handler.onShowMessage(this);
}
public String getMsg() {
return msg;
}
public AlertType getAlerType() {
return alerType;
}
}

View File

@ -0,0 +1,20 @@
package org.gcube.portlets.widgets.ckancontentmoderator.client.events;
import com.google.gwt.event.shared.EventHandler;
/**
* The Interface ShowMessageEventHandler.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Feb 22, 2022
*/
public interface ShowMessageEventHandler extends EventHandler {
/**
* On show message.
*
* @param showMessageEvent the show message event
*/
void onShowMessage(ShowMessageEvent showMessageEvent);
}

View File

@ -5,6 +5,7 @@ import java.util.List;
import org.gcube.datacatalogue.utillibrary.shared.ItemStatus; import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
import org.gcube.portlets.widgets.ckancontentmoderator.client.CkanContentModeratorWidgetController; import org.gcube.portlets.widgets.ckancontentmoderator.client.CkanContentModeratorWidgetController;
import org.gcube.portlets.widgets.ckancontentmoderator.client.ContentModeratorWidgetConstants; import org.gcube.portlets.widgets.ckancontentmoderator.client.ContentModeratorWidgetConstants;
import org.gcube.portlets.widgets.ckancontentmoderator.client.events.ShowMessageEvent;
import org.gcube.portlets.widgets.ckancontentmoderator.client.events.TableRangeViewChangedEvent; import org.gcube.portlets.widgets.ckancontentmoderator.client.events.TableRangeViewChangedEvent;
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.table.ItemsTable; import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.table.ItemsTable;
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.table.ItemsTable.DISPLAY_FIELD; import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.table.ItemsTable.DISPLAY_FIELD;
@ -13,6 +14,7 @@ import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.util.LoadingPan
import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset; import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.SearchedData; import org.gcube.portlets.widgets.ckancontentmoderator.shared.SearchedData;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.cellview.client.SimplePager; import com.google.gwt.user.cellview.client.SimplePager;
@ -30,7 +32,6 @@ import com.google.gwt.view.client.Range;
import com.google.gwt.view.client.SelectionModel; import com.google.gwt.view.client.SelectionModel;
import com.google.gwt.view.client.SingleSelectionModel; import com.google.gwt.view.client.SingleSelectionModel;
/** /**
* The Class GeonaRecordsPaginatedView. * The Class GeonaRecordsPaginatedView.
* *
@ -147,7 +148,8 @@ public class ContentModeratorPaginatedView {
*/ */
private void loadNewPage(final int startIdx, final int limit, final boolean resetStore) { private void loadNewPage(final int startIdx, final int limit, final boolean resetStore) {
// initFirstRangeChanged = resetStore; // initFirstRangeChanged = resetStore;
GWT.log("loadNewPage with parameters [startIdx: " + startIdx + ", limit: " + limit + ", resetStore:"+ resetStore + "]"); GWT.log("loadNewPage with parameters [startIdx: " + startIdx + ", limit: " + limit + ", resetStore:"
+ resetStore + "]");
// showLoading(true); // showLoading(true);
int newStartIndex = startIdx; int newStartIndex = startIdx;
@ -181,14 +183,14 @@ public class ContentModeratorPaginatedView {
* @param result the new new page result * @param result the new new page result
*/ */
private void setNewPageResult(SearchedData result) { private void setNewPageResult(SearchedData result) {
GWT.log("setNewPageResult: "+result); GWT.log("setNewPageResult: " + result);
serverStartIndex = result.getServerEndIndex(); serverStartIndex = result.getServerEndIndex();
SelectionModel<? super CatalogueDataset> sm = getCellTable().getSelectionModel(); SelectionModel<? super CatalogueDataset> sm = getCellTable().getSelectionModel();
if (sm instanceof SingleSelectionModel) { if (sm instanceof SingleSelectionModel) {
SingleSelectionModel<CatalogueDataset> ssm = (SingleSelectionModel<CatalogueDataset>) sm; SingleSelectionModel<CatalogueDataset> ssm = (SingleSelectionModel<CatalogueDataset>) sm;
ssm.clear(); ssm.clear();
}else if (sm instanceof MultiSelectionModel) { } else if (sm instanceof MultiSelectionModel) {
MultiSelectionModel<CatalogueDataset> msm = (MultiSelectionModel<CatalogueDataset>) sm; MultiSelectionModel<CatalogueDataset> msm = (MultiSelectionModel<CatalogueDataset>) sm;
msm.clear(); msm.clear();
} }
@ -240,6 +242,8 @@ public class ContentModeratorPaginatedView {
@Override @Override
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
showLoading(false); showLoading(false);
eventBus.fireEvent(new ShowMessageEvent(caught.getMessage(), AlertType.ERROR));
} }
}); });

View File

@ -276,23 +276,7 @@ public class HomeView extends Composite {
@Override @Override
public void onClick(ClickEvent event) { public void onClick(ClickEvent event) {
confirmPanelContainer.clear(); confirmPanelContainer.clear();
performCMSAction(doActionCMS); performCMSAction(doActionCMS);
// TODO DO ACTION UPDATE STATUS OR DELETE PERMANENTLY
// int count = selectedItems.size();
// String msg = "";
// if (count > 0) {
// if (count == 1) {
// msg += "One item";
// } else {
// msg += count + " items";
// }
//
// msg += " moved to " + toStatus + " status";
// }
// eventBus.fireEvent(new SelectItemsWithItemStatusEvent(displayingItemStatus, msg));
} }
}); });
@ -416,9 +400,13 @@ public class HomeView extends Composite {
msg += " moved to " + toStatus + " status."; msg += " moved to " + toStatus + " status.";
} }
int errorCount = result.getErrorListItems().size(); int errorCount = result.getErrorMapItems().size();
if (errorCount > 0) { if (errorCount > 0) {
msg += " <br/>Error occurred on updating status to " + errorCount + " item/s"; msg += " <br/>Error occurred on updating status to " + errorCount + " item/s:";
for (String key : result.getErrorMapItems().keySet()) {
msg += "<br/> "+ key+". Error: "+ result.getErrorMapItems().get(key);
}
alert = AlertType.WARNING; alert = AlertType.WARNING;
} }
@ -465,10 +453,12 @@ public class HomeView extends Composite {
msg += " moved to " + toStatus + " status."; msg += " moved to " + toStatus + " status.";
} }
int errorCount = result.getErrorListItems().size(); int errorCount = result.getErrorMapItems().size();
if (errorCount > 0) { if (errorCount > 0) {
msg += " <br/>Error occurred on approving " + errorCount + " item/s"; msg += " <br/>Error occurred on approving " + errorCount + " item/s:";
alert = AlertType.WARNING; for (String key : result.getErrorMapItems().keySet()) {
msg += "<br/> "+ key+". Error: "+ result.getErrorMapItems().get(key);
}
} }
eventBus.fireEvent(new SelectItemsWithItemStatusEvent(displayingItemStatus, msg, alert)); eventBus.fireEvent(new SelectItemsWithItemStatusEvent(displayingItemStatus, msg, alert));
@ -507,10 +497,12 @@ public class HomeView extends Composite {
msg += " moved to " + toStatus + " status."; msg += " moved to " + toStatus + " status.";
} }
int errorCount = result.getErrorListItems().size(); int errorCount = result.getErrorMapItems().size();
if (errorCount > 0) { if (errorCount > 0) {
msg += " <br/>Error occurred on rejecting " + errorCount + " item/s"; msg += " <br/>Error occurred on rejecting " + errorCount + " item/s:";
alert = AlertType.WARNING; for (String key : result.getErrorMapItems().keySet()) {
msg += "<br/> "+ key+". Error: "+ result.getErrorMapItems().get(key);
}
} }
eventBus.fireEvent(new SelectItemsWithItemStatusEvent(displayingItemStatus, msg, alert)); eventBus.fireEvent(new SelectItemsWithItemStatusEvent(displayingItemStatus, msg, alert));

View File

@ -1,7 +1,9 @@
package org.gcube.portlets.widgets.ckancontentmoderator.server; package org.gcube.portlets.widgets.ckancontentmoderator.server;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
@ -39,7 +41,7 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
* @return true, if is content moderator enabled * @return true, if is content moderator enabled
*/ */
@Override @Override
public boolean isContentModeratorEnabled() { public Boolean isContentModeratorEnabled() {
LOG.info("called isContentModeratorEnabled"); LOG.info("called isContentModeratorEnabled");
String scope = setContexts(); String scope = setContexts();
boolean isContentModeratorEnabled = false; boolean isContentModeratorEnabled = false;
@ -54,6 +56,26 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
return isContentModeratorEnabled; return isContentModeratorEnabled;
} }
/**
* Checks if is moderator role is assigned to working user in the context.
*
* @return the moderation user role
* @throws Exception the exception
*/
@Override
public Boolean isModeratorRoleAssigned() throws Exception {
LOG.info("called isModeratorRoleAssigned");
ModerationUserRole userRole = getCMSRolesForUserInTheContext();
boolean isCatalogueModerator = false;
if (userRole != null && userRole.getRoles() != null
&& userRole.getRoles().contains(CMSUserRole.CATALOGUE_MODERATOR)) {
LOG.info("called isModeratorRoleAssigned");
isCatalogueModerator = true;
}
LOG.info("is " + CMSUserRole.CATALOGUE_MODERATOR.getRoleName() + " assigned? " + isCatalogueModerator);
return isCatalogueModerator;
}
/** /**
* Gets the CMS roles for user in the context. * Gets the CMS roles for user in the context.
@ -69,7 +91,7 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
GcubeContextUtil.getCurrentUser(getThreadLocalRequest()); GcubeContextUtil.getCurrentUser(getThreadLocalRequest());
ModerationUserRole userRole = new ModerationUserRole(getServletInfo(), roles); ModerationUserRole userRole = new ModerationUserRole(getServletInfo(), roles);
LOG.info("return: "+userRole); LOG.info("return: " + userRole);
return userRole; return userRole;
} }
@ -120,9 +142,8 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
} }
} catch (Exception e) { } catch (Exception e) {
LOG.error(e.getMessage(), e); LOG.error("Error occurred on reading items for status: " + theStatus, e);
throw new Exception( throw e;
"Error occurred on reading items for status: " + theStatus + ". Caused by: " + e.getMessage());
} }
LOG.info("returning " + datasetList.size() + " dataset"); LOG.info("returning " + datasetList.size() + " dataset");
@ -135,7 +156,7 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
* @param theStatus the the status * @param theStatus the the status
* @param itemNames the item names * @param itemNames the item names
* @return the operation report * @return the operation report
* @throws Exception * @throws Exception the exception
*/ */
@Override @Override
public OperationReport setStatus(ItemStatus theStatus, List<String> itemNames) throws Exception { public OperationReport setStatus(ItemStatus theStatus, List<String> itemNames) throws Exception {
@ -144,7 +165,7 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
try { try {
String scope = setContexts(); String scope = setContexts();
DataCatalogueImpl catalogueImpl = CatalogueCMSFactory.getFactory().getCatalogueImplPerScope(scope); DataCatalogueImpl catalogueImpl = CatalogueCMSFactory.getFactory().getCatalogueImplPerScope(scope);
List<String> errorListItems = new ArrayList<String>(); Map<String, String> errorMapItems = new HashMap<String, String>();
List<String> changedStatusListItems = new ArrayList<String>(); List<String> changedStatusListItems = new ArrayList<String>();
for (String itemName : itemNames) { for (String itemName : itemNames) {
try { try {
@ -152,11 +173,11 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
changedStatusListItems.add(itemName); changedStatusListItems.add(itemName);
} catch (Exception e) { } catch (Exception e) {
LOG.warn("Error when setting status (updating) the itemName: " + itemName, e); LOG.warn("Error when setting status (updating) the itemName: " + itemName, e);
errorListItems.add(itemName); errorMapItems.put(itemName, e.getMessage());
} }
} }
return new OperationReport(theStatus.getLabel(), errorListItems, changedStatusListItems); return new OperationReport(theStatus.getLabel(), changedStatusListItems, errorMapItems);
} catch (Exception e) { } catch (Exception e) {
LOG.error(e.getMessage(), e); LOG.error(e.getMessage(), e);
@ -182,7 +203,7 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
DataCatalogueImpl catalogueImpl = CatalogueCMSFactory.getFactory().getCatalogueImplPerScope(scope); DataCatalogueImpl catalogueImpl = CatalogueCMSFactory.getFactory().getCatalogueImplPerScope(scope);
CatalogueContentModeratorSystem cmsInstance = catalogueImpl.getCatalogueContentModerator(); CatalogueContentModeratorSystem cmsInstance = catalogueImpl.getCatalogueContentModerator();
List<String> errorListItems = new ArrayList<String>(); Map<String, String> errorMapItems = new HashMap<String, String>();
List<String> approvedListItems = new ArrayList<String>(); List<String> approvedListItems = new ArrayList<String>();
for (String itemName : itemNames) { for (String itemName : itemNames) {
try { try {
@ -190,11 +211,11 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
approvedListItems.add(itemName); approvedListItems.add(itemName);
} catch (Exception e) { } catch (Exception e) {
LOG.warn("Error when approving itemName: " + itemName, e); LOG.warn("Error when approving itemName: " + itemName, e);
errorListItems.add(itemName); errorMapItems.put(itemName, e.getMessage());
} }
} }
return new OperationReport(ItemStatus.APPROVED.getLabel(), errorListItems, approvedListItems); return new OperationReport(ItemStatus.APPROVED.getLabel(), approvedListItems, errorMapItems);
} catch (Exception e) { } catch (Exception e) {
LOG.error(e.getMessage(), e); LOG.error(e.getMessage(), e);
@ -221,7 +242,7 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
DataCatalogueImpl catalogueImpl = CatalogueCMSFactory.getFactory().getCatalogueImplPerScope(scope); DataCatalogueImpl catalogueImpl = CatalogueCMSFactory.getFactory().getCatalogueImplPerScope(scope);
CatalogueContentModeratorSystem cmsInstance = catalogueImpl.getCatalogueContentModerator(); CatalogueContentModeratorSystem cmsInstance = catalogueImpl.getCatalogueContentModerator();
List<String> errorListItems = new ArrayList<String>(); Map<String, String> errorMapItems = new HashMap<String, String>();
List<String> passedListItems = new ArrayList<String>(); List<String> passedListItems = new ArrayList<String>();
for (String itemName : itemNames) { for (String itemName : itemNames) {
try { try {
@ -229,11 +250,11 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
passedListItems.add(itemName); passedListItems.add(itemName);
} catch (Exception e) { } catch (Exception e) {
LOG.warn("Error when rejecting itemName: " + itemName, e); LOG.warn("Error when rejecting itemName: " + itemName, e);
errorListItems.add(itemName); errorMapItems.put(itemName, e.getMessage());
} }
} }
return new OperationReport(ItemStatus.REJECTED.getLabel(), errorListItems, passedListItems); return new OperationReport(ItemStatus.REJECTED.getLabel(), passedListItems, errorMapItems);
} catch (Exception e) { } catch (Exception e) {
LOG.error(e.getMessage(), e); LOG.error(e.getMessage(), e);
@ -257,7 +278,7 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
DataCatalogueImpl catalogueImpl = CatalogueCMSFactory.getFactory().getCatalogueImplPerScope(scope); DataCatalogueImpl catalogueImpl = CatalogueCMSFactory.getFactory().getCatalogueImplPerScope(scope);
CatalogueContentModeratorSystem cmsInstance = catalogueImpl.getCatalogueContentModerator(); CatalogueContentModeratorSystem cmsInstance = catalogueImpl.getCatalogueContentModerator();
List<String> errorListItems = new ArrayList<String>(); Map<String, String> errorMapItems = new HashMap<String, String>();
List<String> passedListItems = new ArrayList<String>(); List<String> passedListItems = new ArrayList<String>();
for (String itemName : itemNames) { for (String itemName : itemNames) {
try { try {
@ -265,11 +286,11 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
passedListItems.add(itemName); passedListItems.add(itemName);
} catch (Exception e) { } catch (Exception e) {
LOG.warn("Error when deleting permanently the itemName: " + itemName, e); LOG.warn("Error when deleting permanently the itemName: " + itemName, e);
errorListItems.add(itemName); errorMapItems.put(itemName, e.getMessage());
} }
} }
return new OperationReport("Permanently Delete", errorListItems, passedListItems); return new OperationReport("Permanently Delete", passedListItems, errorMapItems);
} catch (Exception e) { } catch (Exception e) {
LOG.error(e.getMessage(), e); LOG.error(e.getMessage(), e);
@ -294,12 +315,8 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
LOG.info("called getDataForStatus [status: " + status + ", offset: " + offset + ", limit: " + limit LOG.info("called getDataForStatus [status: " + status + ", offset: " + offset + ", limit: " + limit
+ ", serverIndex: " + serverStartIndex); + ", serverIndex: " + serverStartIndex);
try {
String scope = setContexts(); String scope = setContexts();
// int searchStartIndex = limit < serverStartIndex? serverStartIndex : offset;
int searchStartIndex = offset; int searchStartIndex = offset;
CatalogueContentModeratorSystem cmsInstance = CatalogueCMSFactory.getFactory().getCMSPerScope(scope); CatalogueContentModeratorSystem cmsInstance = CatalogueCMSFactory.getFactory().getCMSPerScope(scope);
SearchedData searchedData = new SearchedData(offset, limit, searchStartIndex, false); SearchedData searchedData = new SearchedData(offset, limit, searchStartIndex, false);
long totalItemsForStatus = cmsInstance.countListItemsForStatus(status); long totalItemsForStatus = cmsInstance.countListItemsForStatus(status);
@ -309,7 +326,9 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
LOG.debug("getListItemsForStatus with searchStartIndex: " + searchStartIndex + ", limit: " + limit); LOG.debug("getListItemsForStatus with searchStartIndex: " + searchStartIndex + ", limit: " + limit);
listDataset = getListItemsForStatus(status, searchStartIndex, limit); listDataset = getListItemsForStatus(status, searchStartIndex, limit);
} catch (Exception e) { } catch (Exception e) {
LOG.error("Error occurred on gettin items for status: " + status, e); String error = "Error occurred on getting items for status: " + status;
LOG.error(error, e);
throw new Exception(error+". Cause: "+e.getMessage());
} }
int listDatasetSize = listDataset.size(); int listDatasetSize = listDataset.size();
@ -325,37 +344,7 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
return searchedData; return searchedData;
} }
/*
* int offsetStartIndex = searchStartIndex; boolean pageOffsetOut = false;
* while(listDatasetSize < offset && !searchedData.isServerSearchFinished() &&
* !pageOffsetOut){ //&& SEARCH NOT ULTIMATED
* LOG.debug("MyLg new WHILE Items count: "
* +totalItemsForStatus+" is less than limit..");
*
* int newOffsetStartIndex = offsetStartIndex+limit+1;
* LOG.debug("MyLg NewStartIndex is startIndex+limit: "+newOffsetStartIndex);
*
* //THERE ARE OTHER CHILDREN OVER NEW START INDEX if(newOffsetStartIndex <
* totalItemsForStatus){ //newLimit = limit - childrenToReturn.size();
* LOG.debug("MyLg getting items with index start: "+newOffsetStartIndex +
* ", limit: "+offset);
*
* int diff = (int) (offset - totalItemsForStatus); //How items are remaining
* //int offset = 0; LOG.debug("MyLg new search start: "+newOffsetStartIndex +
* ", diff: "+diff+ ", retrieved: "+listDatasetSize); if(diff >=
* listDatasetSize){ }else{ pageOffsetOut = true; } offsetStartIndex =
* newOffsetStartIndex; LOG.debug("MyLg items count is: "+totalItemsForStatus +
* " serverEndIndex: "+offsetStartIndex);
* searchedData.setServerEndIndex(offsetStartIndex); }else{ LOG.
* debug("New start index (oldStartIndex+limit) is grather than total items count, search is finished"
* ); searchedData.setServerSearchFinished(true); } }
*/
LOG.debug("Returning: " + searchedData); LOG.debug("Returning: " + searchedData);
return searchedData; return searchedData;
} catch (Exception e) {
LOG.error("Error during folder retrieving", e);
throw new Exception("Sorry, an error occurred on loading items");
}
} }
} }

View File

@ -31,10 +31,6 @@ public class ModerationUserRole implements Serializable {
this.roles = roles; this.roles = roles;
} }
public static long getSerialversionuid() {
return serialVersionUID;
}
public String getUsername() { public String getUsername() {
return username; return username;
} }

View File

@ -2,25 +2,27 @@ package org.gcube.portlets.widgets.ckancontentmoderator.shared;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
public class OperationReport implements Serializable { public class OperationReport implements Serializable {
/** /**
* *
*/ */
private static final long serialVersionUID = 879318163198093725L; private static final long serialVersionUID = 4960774282956107668L;
private String operationType; private String operationType;
private List<String> errorListItems = new ArrayList<String>(); private Map<String, String> errorMapItems = new HashMap<String, String>();
private List<String> passedListItems = new ArrayList<String>(); private List<String> passedListItems = new ArrayList<String>();
public OperationReport() { public OperationReport() {
} }
public OperationReport(String operationType, List<String> errorListItems, List<String> passedListItems) { public OperationReport(String operationType, List<String> passedListItems, Map<String, String> errorMapItems) {
super();
this.operationType = operationType; this.operationType = operationType;
this.errorListItems = errorListItems; this.errorMapItems = errorMapItems;
this.passedListItems = passedListItems; this.passedListItems = passedListItems;
} }
@ -28,8 +30,8 @@ public class OperationReport implements Serializable {
return operationType; return operationType;
} }
public List<String> getErrorListItems() { public Map<String, String> getErrorMapItems() {
return errorListItems; return errorMapItems;
} }
public List<String> getPassedListItems() { public List<String> getPassedListItems() {
@ -40,8 +42,8 @@ public class OperationReport implements Serializable {
this.operationType = operationType; this.operationType = operationType;
} }
public void setErrorListItems(List<String> errorListItems) { public void setErrorMapItems(Map<String, String> errorMapItems) {
this.errorListItems = errorListItems; this.errorMapItems = errorMapItems;
} }
public void setPassedListItems(List<String> passedListItems) { public void setPassedListItems(List<String> passedListItems) {
@ -53,8 +55,8 @@ public class OperationReport implements Serializable {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("OperationReport [operationType="); builder.append("OperationReport [operationType=");
builder.append(operationType); builder.append(operationType);
builder.append(", errorListItems="); builder.append(", errorMapItems=");
builder.append(errorListItems); builder.append(errorMapItems);
builder.append(", passedListItems="); builder.append(", passedListItems=");
builder.append(passedListItems); builder.append(passedListItems);
builder.append("]"); builder.append("]");