integrated with gCatCaller methods

This commit is contained in:
Francesco Mangiacrapa 2022-02-18 14:17:19 +01:00
parent b726ba0b83
commit cbb9bfc4ca
7 changed files with 198 additions and 92 deletions

View File

@ -29,11 +29,14 @@ public interface CkanContentModeratorService extends RemoteService {
/**
* Sets the status.
*
* Currently, this only used to change the status from Rejected to Pending
*
* @param theStatus the the status
* @param itemNames the item names
* @return the operation report
* @throws Exception
*/
public void setStatus(ItemStatus theStatus, List<String> itemNames);
public OperationReport setStatus(ItemStatus theStatus, List<String> itemNames) throws Exception;
/**
* Reject item.

View File

@ -9,13 +9,12 @@ import org.gcube.portlets.widgets.ckancontentmoderator.shared.SearchedData;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
* The Interface CkanContentModeratorServiceAsync.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Jan 11, 2022
* Jan 11, 2022
*/
public interface CkanContentModeratorServiceAsync {
@ -29,10 +28,10 @@ public interface CkanContentModeratorServiceAsync {
/**
* Reject item.
*
* @param itemNames the item names
* @param itemNames the item names
* @param permanentlyDelete the permanently delete
* @param reasonMsg the reason msg
* @param callback the callback
* @param reasonMsg the reason msg
* @param callback the callback
*/
void rejectItem(List<String> itemNames, boolean permanentlyDelete, String reasonMsg,
AsyncCallback<OperationReport> callback);
@ -41,9 +40,9 @@ public interface CkanContentModeratorServiceAsync {
* 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,
@ -52,10 +51,10 @@ public interface CkanContentModeratorServiceAsync {
/**
* Gets the data for status.
*
* @param status the status
* @param startIndex the start index
* @param lenght the lenght
* @param serverIndex the server index
* @param status the status
* @param startIndex the start index
* @param lenght the lenght
* @param serverIndex the server index
* @param asyncCallback the async callback
* @return the data for status
*/
@ -65,9 +64,9 @@ public interface CkanContentModeratorServiceAsync {
/**
* Approve item.
*
* @param itemNames the item names
* @param itemNames the item names
* @param moderatorMessage the moderator message
* @param callback the callback
* @param callback the callback
*/
void approveItem(List<String> itemNames, String moderatorMessage, AsyncCallback<OperationReport> callback);
@ -75,7 +74,7 @@ public interface CkanContentModeratorServiceAsync {
* Permanently delete.
*
* @param itemNames the item names
* @param callback the callback
* @param callback the callback
*/
void permanentlyDelete(List<String> itemNames, AsyncCallback<OperationReport> callback);
@ -84,8 +83,8 @@ public interface CkanContentModeratorServiceAsync {
*
* @param theStatus the the status
* @param itemNames the item names
* @param callback the callback
* @param callback the callback
*/
void setStatus(ItemStatus theStatus, List<String> itemNames, AsyncCallback<Void> callback);
void setStatus(ItemStatus theStatus, List<String> itemNames, AsyncCallback<OperationReport> callback);
}

View File

@ -173,7 +173,7 @@ public class CkanContentModeratorWidgetController {
if(statusSelectedEvent.getDisplayMessage()!=null) {
final Alert alert = new Alert(statusSelectedEvent.getDisplayMessage());
alert.setType(AlertType.INFO);
alert.setType(statusSelectedEvent.getAlertType());
alert.setClose(true);
alert.setAnimation(true);
infoPanel.add(alert);

View File

@ -2,6 +2,7 @@ package org.gcube.portlets.widgets.ckancontentmoderator.client.events;
import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
import com.google.gwt.event.shared.GwtEvent;
/**
@ -9,22 +10,25 @@ import com.google.gwt.event.shared.GwtEvent;
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Jun 28, 2021
* Jun 28, 2021
*/
public class SelectItemsWithItemStatusEvent extends GwtEvent<SelectItemsWithItemStatusEventHandler> {
public static Type<SelectItemsWithItemStatusEventHandler> TYPE = new Type<SelectItemsWithItemStatusEventHandler>();
private ItemStatus itemStatus;
private String displayMessage;
private AlertType alertType = AlertType.INFO;
/**
* Instantiates a new click item event.
*
* @param itemStatus the item status
* @param itemStatus the item status
* @param displayMessage the display message
* @param alerType the aler type
*/
public SelectItemsWithItemStatusEvent(ItemStatus itemStatus, String displayMessage) {
public SelectItemsWithItemStatusEvent(ItemStatus itemStatus, String displayMessage, AlertType alerType) {
this.itemStatus = itemStatus;
this.displayMessage = displayMessage;
this.alertType = alerType;
}
/**
@ -55,7 +59,7 @@ public class SelectItemsWithItemStatusEvent extends GwtEvent<SelectItemsWithItem
public ItemStatus getItemStatus() {
return itemStatus;
}
/**
* Gets the display message.
*
@ -65,4 +69,13 @@ public class SelectItemsWithItemStatusEvent extends GwtEvent<SelectItemsWithItem
return displayMessage;
}
/**
* Gets the alert type.
*
* @return the alert type
*/
public AlertType getAlertType() {
return alertType;
}
}

View File

@ -65,9 +65,9 @@ public class ContentModeratorToolbar extends Composite {
@Override
public void onClick(ClickEvent event) {
GWT.log("clicked: "+status);
GWT.log("clicked: " + status);
setActiveStatus(status);
eventBus.fireEvent(new SelectItemsWithItemStatusEvent(status, null));
eventBus.fireEvent(new SelectItemsWithItemStatusEvent(status, null, null));
}
});

View File

@ -19,6 +19,7 @@ import com.github.gwtbootstrap.client.ui.Dropdown;
import com.github.gwtbootstrap.client.ui.Heading;
import com.github.gwtbootstrap.client.ui.NavLink;
import com.github.gwtbootstrap.client.ui.base.AlertBase;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
import com.github.gwtbootstrap.client.ui.event.ClosedEvent;
import com.github.gwtbootstrap.client.ui.event.ClosedHandler;
import com.google.gwt.core.client.GWT;
@ -29,6 +30,7 @@ import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
@ -246,7 +248,7 @@ public class HomeView extends Composite {
return;
}
DoActionCMSView doActionCMS = new DoActionCMSView();
final DoActionCMSView doActionCMS = new DoActionCMSView();
final List<CatalogueDataset> selectedItems = paginatedView.getSelectItems();
doActionCMS.updateStatus(fromStatus, toStatus, selectedItems);
@ -265,22 +267,22 @@ public class HomeView extends Composite {
@Override
public void onClick(ClickEvent event) {
confirmPanelContainer.clear();
//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";
}
performCMSAction(doActionCMS);
// TODO DO ACTION UPDATE STATUS OR DELETE PERMANENTLY
msg += " moved to " + toStatus + " status";
}
eventBus.fireEvent(new SelectItemsWithItemStatusEvent(displayingItemStatus, msg));
// 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));
}
});
@ -324,10 +326,7 @@ public class HomeView extends Composite {
@Override
public void onClick(ClickEvent event) {
confirmPanelContainer.clear();
//TODO DO ACTION DELETE PERMANENTLY
AlertType alert = AlertType.SUCCESS;
int count = selectedItems.size();
String msg = "Deleted permanently";
if (count > 0) {
@ -339,7 +338,7 @@ public class HomeView extends Composite {
msg += " from Catalogue";
}
eventBus.fireEvent(new SelectItemsWithItemStatusEvent(displayingItemStatus, msg));
eventBus.fireEvent(new SelectItemsWithItemStatusEvent(displayingItemStatus, msg, alert));
}
});
@ -382,25 +381,46 @@ public class HomeView extends Composite {
*
* @param doActionCMSView the do action CMS view
*/
public void performCMSAction(DoActionCMSView doActionCMSView) {
private void performCMSAction(DoActionCMSView doActionCMSView) {
ItemStatus toStatus = doActionCMSView.getToStatus();
final ItemStatus toStatus = doActionCMSView.getToStatus();
List<String> listDatasetNames = UtilFunct.toListDatasetNames(doActionCMSView.getListSelectItems());
switch (toStatus) {
case PENDING:
CkanContentModeratorWidgetController.contentModeratorService.setStatus(toStatus, listDatasetNames,
new AsyncCallback<Void>() {
new AsyncCallback<OperationReport>() {
@Override
public void onSuccess(Void result) {
// TODO Auto-generated method stub
public void onSuccess(OperationReport result) {
AlertType alert = AlertType.SUCCESS;
int count = result.getPassedListItems().size();
String msg = "";
if (count > 0) {
if (count == 1) {
msg += "One item";
} else {
msg += count + " items";
}
msg += " moved to " + toStatus + " status.";
}
int errorCount = result.getErrorListItems().size();
if (errorCount > 0) {
msg += " <br/>Error occurred on updating status to " + errorCount + " item/s";
alert = AlertType.WARNING;
}
eventBus.fireEvent(new SelectItemsWithItemStatusEvent(displayingItemStatus, msg, alert));
}
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
Window.alert(caught.getMessage());
eventBus.fireEvent(new SelectItemsWithItemStatusEvent(displayingItemStatus,
"Sorry an error occurred. Please, refresh and try again", AlertType.ERROR));
}
});
@ -408,41 +428,87 @@ public class HomeView extends Composite {
break;
case APPROVED:
CkanContentModeratorWidgetController.contentModeratorService.approveItem(listDatasetNames, doActionCMSView.getTxtReasonMsg(), new AsyncCallback<OperationReport>() {
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
CkanContentModeratorWidgetController.contentModeratorService.approveItem(listDatasetNames,
doActionCMSView.getTxtReasonMsg(), new AsyncCallback<OperationReport>() {
@Override
public void onFailure(Throwable caught) {
Window.alert(caught.getMessage());
eventBus.fireEvent(new SelectItemsWithItemStatusEvent(displayingItemStatus,
"Sorry an error occurred. Please, refresh and try again", AlertType.ERROR));
}
@Override
public void onSuccess(OperationReport result) {
AlertType alert = AlertType.SUCCESS;
int count = result.getPassedListItems().size();
String msg = "";
if (count > 0) {
if (count == 1) {
msg += "One item";
} else {
msg += count + " items";
}
msg += " moved to " + toStatus + " status.";
}
int errorCount = result.getErrorListItems().size();
if (errorCount > 0) {
msg += " <br/>Error occurred on approving " + errorCount + " item/s";
alert = AlertType.WARNING;
}
eventBus.fireEvent(new SelectItemsWithItemStatusEvent(displayingItemStatus, msg, alert));
}
});
@Override
public void onSuccess(OperationReport result) {
// TODO Auto-generated method stub
}
});
break;
case REJECTED:
CkanContentModeratorWidgetController.contentModeratorService.rejectItem(listDatasetNames, doActionCMSView.isPermanentlyDelete(), doActionCMSView.getTxtReasonMsg(), new AsyncCallback<OperationReport>() {
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
CkanContentModeratorWidgetController.contentModeratorService.rejectItem(listDatasetNames,
doActionCMSView.isPermanentlyDelete(), doActionCMSView.getTxtReasonMsg(),
new AsyncCallback<OperationReport>() {
@Override
public void onFailure(Throwable caught) {
Window.alert(caught.getMessage());
eventBus.fireEvent(new SelectItemsWithItemStatusEvent(displayingItemStatus,
"Sorry an error occurred. Please, refresh and try again", AlertType.ERROR));
}
@Override
public void onSuccess(OperationReport result) {
AlertType alert = AlertType.SUCCESS;
int count = result.getPassedListItems().size();
String msg = "";
if (count > 0) {
if (count == 1) {
msg += "One item";
} else {
msg += count + " items";
}
msg += " moved to " + toStatus + " status.";
}
int errorCount = result.getErrorListItems().size();
if (errorCount > 0) {
msg += " <br/>Error occurred on rejecting " + errorCount + " item/s";
alert = AlertType.WARNING;
}
eventBus.fireEvent(new SelectItemsWithItemStatusEvent(displayingItemStatus, msg, alert));
}
});
@Override
public void onSuccess(OperationReport result) {
// TODO Auto-generated method stub
}
});
break;
default:

View File

@ -66,18 +66,6 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
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);
}
/**
* Gets the list items for status.
*
@ -119,6 +107,43 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
LOG.info("returning " + datasetList.size() + " dataset");
return datasetList;
}
/**
* Sets the status.
*
* @param theStatus the the status
* @param itemNames the item names
* @return the operation report
* @throws Exception
*/
@Override
public OperationReport setStatus(ItemStatus theStatus, List<String> itemNames) throws Exception {
LOG.info("Called set status " + theStatus + " for Items with name: " + itemNames);
try {
String scope = setContexts();
DataCatalogueImpl catalogueImpl = CatalogueCMSFactory.getFactory().getCatalogueImplPerScope(scope);
List<String> errorListItems = new ArrayList<String>();
List<String> approvedListItems = new ArrayList<String>();
for (String itemName : itemNames) {
try {
catalogueImpl.refreshDataset(itemName);
approvedListItems.add(itemName);
} catch (Exception e) {
LOG.warn("Error when setting status (updating) the itemName: " + itemName, e);
errorListItems.add(itemName);
}
}
return new OperationReport(theStatus.getLabel(), errorListItems, approvedListItems);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new Exception("Error occurred on updating the status for item/s: " + itemNames + ". Caused by: " + e.getMessage());
}
}
/**
* Approve item.