task_21363 #1

Closed
francesco.mangiacrapa wants to merge 53 commits from task_21363 into master
7 changed files with 198 additions and 92 deletions
Showing only changes of commit cbb9bfc4ca - Show all commits

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,7 +9,6 @@ import org.gcube.portlets.widgets.ckancontentmoderator.shared.SearchedData;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
* The Interface CkanContentModeratorServiceAsync.
*
@ -86,6 +85,6 @@ public interface CkanContentModeratorServiceAsync {
* @param itemNames the item names
* @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;
/**
@ -15,16 +16,19 @@ public class SelectItemsWithItemStatusEvent extends GwtEvent<SelectItemsWithItem
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 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;
}
/**
@ -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

@ -67,7 +67,7 @@ public class ContentModeratorToolbar extends Composite {
public void onClick(ClickEvent event) {
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);
@ -266,21 +268,21 @@ public class HomeView extends Composite {
public void onClick(ClickEvent event) {
confirmPanelContainer.clear();
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));
// 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));
}
});
@ -409,17 +429,40 @@ public class HomeView extends Composite {
case APPROVED:
CkanContentModeratorWidgetController.contentModeratorService.approveItem(listDatasetNames, doActionCMSView.getTxtReasonMsg(), new AsyncCallback<OperationReport>() {
CkanContentModeratorWidgetController.contentModeratorService.approveItem(listDatasetNames,
doActionCMSView.getTxtReasonMsg(), new AsyncCallback<OperationReport>() {
@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));
}
@Override
public void onSuccess(OperationReport result) {
// TODO Auto-generated method stub
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));
}
});
@ -428,17 +471,40 @@ public class HomeView extends Composite {
case REJECTED:
CkanContentModeratorWidgetController.contentModeratorService.rejectItem(listDatasetNames, doActionCMSView.isPermanentlyDelete(), doActionCMSView.getTxtReasonMsg(), new AsyncCallback<OperationReport>() {
CkanContentModeratorWidgetController.contentModeratorService.rejectItem(listDatasetNames,
doActionCMSView.isPermanentlyDelete(), doActionCMSView.getTxtReasonMsg(),
new AsyncCallback<OperationReport>() {
@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));
}
@Override
public void onSuccess(OperationReport result) {
// TODO Auto-generated method stub
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));
}
});

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.
*
@ -120,6 +108,43 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
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.
*