2018-07-05 18:29:38 +02:00
|
|
|
package org.gcube.portlets.user.accountingdashboard.client.application.controller;
|
|
|
|
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
import org.gcube.portlets.user.accountingdashboard.client.application.dialog.error.ErrorPresenter;
|
|
|
|
import org.gcube.portlets.user.accountingdashboard.client.application.dialog.info.InfoPresenter;
|
|
|
|
import org.gcube.portlets.user.accountingdashboard.client.application.dialog.monitor.MonitorPresenter;
|
|
|
|
import org.gcube.portlets.user.accountingdashboard.client.application.event.HelloEvent;
|
2018-07-11 19:29:22 +02:00
|
|
|
import org.gcube.portlets.user.accountingdashboard.client.application.event.ReportEvent;
|
2018-07-06 17:48:46 +02:00
|
|
|
import org.gcube.portlets.user.accountingdashboard.client.application.event.ScopeDataEvent;
|
2018-07-05 18:29:38 +02:00
|
|
|
import org.gcube.portlets.user.accountingdashboard.client.rpc.AccountingDashboardServiceAsync;
|
2018-07-09 19:08:52 +02:00
|
|
|
import org.gcube.portlets.user.accountingdashboard.shared.data.ReportData;
|
|
|
|
import org.gcube.portlets.user.accountingdashboard.shared.data.RequestReportData;
|
2018-07-06 17:48:46 +02:00
|
|
|
import org.gcube.portlets.user.accountingdashboard.shared.data.ScopeData;
|
2020-04-07 17:34:45 +02:00
|
|
|
import org.gcube.portlets.user.accountingdashboard.shared.options.TreeOptions;
|
2018-07-05 18:29:38 +02:00
|
|
|
import org.gcube.portlets.user.accountingdashboard.shared.session.UserInfo;
|
|
|
|
|
|
|
|
import com.google.gwt.event.shared.EventBus;
|
|
|
|
import com.google.gwt.event.shared.EventHandler;
|
|
|
|
import com.google.gwt.event.shared.GwtEvent;
|
|
|
|
import com.google.gwt.event.shared.HandlerRegistration;
|
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
|
import com.google.inject.Inject;
|
|
|
|
import com.google.inject.name.Named;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author Giancarlo Panichi
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class Controller {
|
|
|
|
private static Logger logger = java.util.logging.Logger.getLogger("");
|
|
|
|
|
|
|
|
private EventBus eventBus;
|
|
|
|
private AccountingDashboardServiceAsync service;
|
2018-07-17 19:15:10 +02:00
|
|
|
//private ApplicationCache cache;
|
2018-07-05 18:29:38 +02:00
|
|
|
private MonitorPresenter monitorPresenter;
|
|
|
|
private ErrorPresenter errorPresenter;
|
|
|
|
private InfoPresenter infoPresenter;
|
2020-04-07 17:34:45 +02:00
|
|
|
private TreeOptions treeOptions=null;
|
2018-07-05 18:29:38 +02:00
|
|
|
|
|
|
|
@Inject
|
|
|
|
Controller(@Named("ControllerEventBus") EventBus eventBus, AccountingDashboardServiceAsync service,
|
|
|
|
MonitorPresenter monitorPresenter, ErrorPresenter errorPresenter, InfoPresenter infoPresenter) {
|
|
|
|
this.eventBus = eventBus;
|
|
|
|
this.service = service;
|
|
|
|
this.monitorPresenter = monitorPresenter;
|
|
|
|
this.errorPresenter = errorPresenter;
|
|
|
|
this.infoPresenter = infoPresenter;
|
2018-07-17 19:15:10 +02:00
|
|
|
//this.cache = new ApplicationCache();
|
2020-04-07 17:34:45 +02:00
|
|
|
this.setTreeOptions(new TreeOptions(false));
|
2018-07-17 19:15:10 +02:00
|
|
|
|
2018-07-05 18:29:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void fireEvent(GwtEvent<?> event) {
|
|
|
|
eventBus.fireEventFromSource(event, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public final <H extends EventHandler> HandlerRegistration addHandler(GwtEvent.Type<H> type, H handler) {
|
|
|
|
return eventBus.addHandler(type, handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
public EventBus getEventBus() {
|
|
|
|
return eventBus;
|
|
|
|
}
|
|
|
|
|
2018-07-17 19:15:10 +02:00
|
|
|
public void errorShow(String error){
|
|
|
|
logger.log(Level.FINE, "Error show: "+error);
|
|
|
|
errorPresenter.errorMessage(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void infoShow(String info){
|
|
|
|
logger.log(Level.FINE, "Info show: "+info);
|
|
|
|
infoPresenter.infoMessage(info);
|
|
|
|
}
|
|
|
|
|
2020-04-07 17:34:45 +02:00
|
|
|
public TreeOptions getTreeOptions() {
|
|
|
|
return treeOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTreeOptions(TreeOptions treeOptions) {
|
|
|
|
this.treeOptions = treeOptions;
|
|
|
|
}
|
|
|
|
|
2018-07-17 19:15:10 +02:00
|
|
|
|
2018-07-05 18:29:38 +02:00
|
|
|
public void hello() {
|
|
|
|
eventBus.fireEvent(new HelloEvent());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void callHello() {
|
|
|
|
/* String groupId= GCubeClientContext.getCurrentContextId(); */
|
|
|
|
|
|
|
|
// String token = Window.Location.getParameter(Constants.TOKEN);
|
|
|
|
// logger.log(Level.FINE,"Token: " + token);
|
|
|
|
|
|
|
|
// MaterialLoader.showLoading(true);
|
|
|
|
service.hello(new AsyncCallback<UserInfo>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
logger.log(Level.FINE, "Error in Hello(): ", caught);
|
|
|
|
errorPresenter.errorMessage(caught.getLocalizedMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(UserInfo result) {
|
|
|
|
logger.log(Level.FINE, "Hello: " + result.getUsername());
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-07-06 17:48:46 +02:00
|
|
|
public void getTree() {
|
2020-04-07 17:34:45 +02:00
|
|
|
service.getScopeData(treeOptions,new AsyncCallback<ScopeData>() {
|
2018-07-06 17:48:46 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2018-07-09 19:08:52 +02:00
|
|
|
logger.log(Level.FINE, "Error in getTree(): ", caught);
|
2018-07-06 17:48:46 +02:00
|
|
|
errorPresenter.errorMessage(caught.getLocalizedMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(ScopeData scopeData) {
|
|
|
|
logger.log(Level.FINE, "ScopeData: " + scopeData);
|
|
|
|
ScopeDataEvent event = new ScopeDataEvent(scopeData);
|
|
|
|
eventBus.fireEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-07-09 19:08:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void getReport(RequestReportData requestReportData) {
|
2018-07-10 17:50:37 +02:00
|
|
|
monitorPresenter.enable(true);
|
2020-04-07 17:34:45 +02:00
|
|
|
service.getReport(requestReportData,treeOptions, new AsyncCallback<ReportData>() {
|
2018-07-09 19:08:52 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
logger.log(Level.FINE, "Error in getReport(): ", caught);
|
2018-07-10 17:50:37 +02:00
|
|
|
monitorPresenter.enable(false);
|
2018-07-09 19:08:52 +02:00
|
|
|
errorPresenter.errorMessage(caught.getLocalizedMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(ReportData reportData) {
|
|
|
|
logger.log(Level.FINE, "ReportData: " + reportData);
|
2018-07-10 17:50:37 +02:00
|
|
|
monitorPresenter.enable(false);
|
2018-07-11 19:29:22 +02:00
|
|
|
ReportEvent event = new ReportEvent(reportData);
|
|
|
|
eventBus.fireEvent(event);
|
2018-07-09 19:08:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2018-07-06 17:48:46 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-07 17:34:45 +02:00
|
|
|
|
2018-07-05 18:29:38 +02:00
|
|
|
}
|