2015-07-17 15:38:33 +02:00
|
|
|
package org.gcube.portlets.admin.accountingmanager.client;
|
|
|
|
|
2015-07-31 18:27:02 +02:00
|
|
|
import java.util.ArrayList;
|
2015-07-17 15:38:33 +02:00
|
|
|
import java.util.Date;
|
|
|
|
|
2016-11-28 17:38:32 +01:00
|
|
|
import org.gcube.portal.clientcontext.client.GCubeClientContext;
|
2015-07-17 15:38:33 +02:00
|
|
|
import org.gcube.portlets.admin.accountingmanager.client.event.AccountingMenuEvent;
|
2016-09-22 18:47:29 +02:00
|
|
|
import org.gcube.portlets.admin.accountingmanager.client.event.EnableTabsEvent;
|
2016-06-09 16:26:02 +02:00
|
|
|
import org.gcube.portlets.admin.accountingmanager.client.event.ExportRequestEvent;
|
2015-07-17 15:38:33 +02:00
|
|
|
import org.gcube.portlets.admin.accountingmanager.client.event.FiltersChangeEvent;
|
|
|
|
import org.gcube.portlets.admin.accountingmanager.client.event.SessionExpiredEvent;
|
|
|
|
import org.gcube.portlets.admin.accountingmanager.client.event.StateChangeEvent;
|
|
|
|
import org.gcube.portlets.admin.accountingmanager.client.event.UIStateEvent;
|
|
|
|
import org.gcube.portlets.admin.accountingmanager.client.monitor.AccountingMonitor;
|
2017-02-14 18:04:47 +01:00
|
|
|
import org.gcube.portlets.admin.accountingmanager.client.monitor.MonitorRequest;
|
|
|
|
import org.gcube.portlets.admin.accountingmanager.client.monitor.MonitorRequestEvent;
|
|
|
|
import org.gcube.portlets.admin.accountingmanager.client.monitor.MonitorRequestEvent.MonitorRequestEventHandler;
|
2015-07-17 15:38:33 +02:00
|
|
|
import org.gcube.portlets.admin.accountingmanager.client.rpc.AccountingManagerServiceAsync;
|
2016-05-31 15:50:31 +02:00
|
|
|
import org.gcube.portlets.admin.accountingmanager.client.state.AccountingClientState;
|
|
|
|
import org.gcube.portlets.admin.accountingmanager.client.state.AccountingClientStateData;
|
2015-07-17 15:38:33 +02:00
|
|
|
import org.gcube.portlets.admin.accountingmanager.client.type.SessionExpiredType;
|
|
|
|
import org.gcube.portlets.admin.accountingmanager.client.type.StateChangeType;
|
|
|
|
import org.gcube.portlets.admin.accountingmanager.client.type.UIStateType;
|
2016-11-28 17:38:32 +01:00
|
|
|
import org.gcube.portlets.admin.accountingmanager.client.util.UtilsGXT3;
|
2015-07-17 15:38:33 +02:00
|
|
|
import org.gcube.portlets.admin.accountingmanager.shared.Constants;
|
2016-02-16 17:48:44 +01:00
|
|
|
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingFilterBasic;
|
2017-05-05 17:07:30 +02:00
|
|
|
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingFilterSpaces;
|
2015-07-20 16:44:13 +02:00
|
|
|
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingPeriod;
|
|
|
|
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingPeriodMode;
|
2015-07-17 15:38:33 +02:00
|
|
|
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingType;
|
2016-11-15 17:37:24 +01:00
|
|
|
import org.gcube.portlets.admin.accountingmanager.shared.data.Context;
|
2015-07-31 18:27:02 +02:00
|
|
|
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterKey;
|
2017-05-05 17:07:30 +02:00
|
|
|
import org.gcube.portlets.admin.accountingmanager.shared.data.Spaces;
|
2015-07-17 15:38:33 +02:00
|
|
|
import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest;
|
|
|
|
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse;
|
2016-05-30 18:51:08 +02:00
|
|
|
import org.gcube.portlets.admin.accountingmanager.shared.exception.SessionExpiredException;
|
2015-07-17 15:38:33 +02:00
|
|
|
import org.gcube.portlets.admin.accountingmanager.shared.session.UserInfo;
|
2016-09-20 18:18:11 +02:00
|
|
|
import org.gcube.portlets.admin.accountingmanager.shared.tabs.EnableTabs;
|
2016-05-30 18:51:08 +02:00
|
|
|
import org.gcube.portlets.admin.accountingmanager.shared.workspace.ItemDescription;
|
2015-07-17 15:38:33 +02:00
|
|
|
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
2016-05-31 15:50:31 +02:00
|
|
|
import com.google.gwt.core.client.GWT;
|
2015-07-17 15:38:33 +02:00
|
|
|
import com.google.gwt.event.shared.EventBus;
|
|
|
|
import com.google.gwt.event.shared.SimpleEventBus;
|
2015-09-09 14:25:36 +02:00
|
|
|
import com.google.gwt.i18n.client.DateTimeFormat;
|
|
|
|
import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
|
2015-07-17 15:38:33 +02:00
|
|
|
import com.google.gwt.i18n.client.LocaleInfo;
|
|
|
|
import com.google.gwt.user.client.Cookies;
|
|
|
|
import com.google.gwt.user.client.Timer;
|
2016-05-30 18:54:11 +02:00
|
|
|
import com.google.gwt.user.client.Window;
|
2015-07-17 15:38:33 +02:00
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
2015-07-20 16:44:13 +02:00
|
|
|
import com.google.gwt.user.datepicker.client.CalendarUtil;
|
2015-07-17 15:38:33 +02:00
|
|
|
import com.sencha.gxt.widget.core.client.container.BorderLayoutContainer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2017-05-09 17:35:45 +02:00
|
|
|
* @author Giancarlo Panichi
|
|
|
|
*
|
2015-07-17 15:38:33 +02:00
|
|
|
*/
|
|
|
|
public class AccountingManagerController {
|
|
|
|
|
|
|
|
private SimpleEventBus eventBus;
|
|
|
|
private UserInfo userInfo;
|
2017-02-15 20:20:23 +01:00
|
|
|
private Boolean rootScope;
|
2016-05-31 15:50:31 +02:00
|
|
|
private AccountingClientState accountingState;
|
2015-07-17 15:38:33 +02:00
|
|
|
private AccountingType accountingType;
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
private BorderLayoutContainer mainPanel;
|
|
|
|
private AccountingMonitor accountingMonitor;
|
2016-09-22 18:47:29 +02:00
|
|
|
private EnableTabs enableTabs;
|
2021-06-28 18:12:01 +02:00
|
|
|
private Context availableContext;
|
2015-07-17 15:38:33 +02:00
|
|
|
|
|
|
|
public AccountingManagerController() {
|
|
|
|
eventBus = new SimpleEventBus();
|
2016-05-31 15:50:31 +02:00
|
|
|
accountingState = new AccountingClientState();
|
2015-07-17 15:38:33 +02:00
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void init() {
|
|
|
|
callHello();
|
|
|
|
bindToEvents();
|
|
|
|
}
|
|
|
|
|
2016-09-22 18:47:29 +02:00
|
|
|
/*
|
|
|
|
* private void checkSession() { // if you do not need to something when the
|
|
|
|
* session expire // CheckSession.getInstance().startPolling(); }
|
|
|
|
*/
|
2015-07-17 15:38:33 +02:00
|
|
|
|
|
|
|
private void sessionExpiredShow() {
|
2016-12-20 18:45:40 +01:00
|
|
|
Log.error("Session expired");
|
2016-12-02 10:58:36 +01:00
|
|
|
// CheckSession.showLogoutDialog();
|
2015-07-17 15:38:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the eventBus
|
|
|
|
*/
|
|
|
|
public EventBus getEventBus() {
|
|
|
|
return eventBus;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setMainPanelLayout(BorderLayoutContainer mainPanel) {
|
|
|
|
this.mainPanel = mainPanel;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void callHello() {
|
2018-10-05 12:32:50 +02:00
|
|
|
AccountingManagerServiceAsync.INSTANCE.hello(new AsyncCallback<UserInfo>() {
|
2015-07-17 15:38:33 +02:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2021-06-28 18:12:01 +02:00
|
|
|
Log.error("No valid user found: " + caught.getMessage());
|
2018-10-05 12:32:50 +02:00
|
|
|
if (caught instanceof SessionExpiredException) {
|
|
|
|
UtilsGXT3.alert("Error", "Expired Session");
|
|
|
|
sessionExpiredShowDelayed();
|
|
|
|
} else {
|
|
|
|
UtilsGXT3.alert("Error", "No user found");
|
|
|
|
}
|
|
|
|
}
|
2015-07-17 15:38:33 +02:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
@Override
|
|
|
|
public void onSuccess(UserInfo result) {
|
|
|
|
userInfo = result;
|
|
|
|
Log.info("Hello: " + userInfo.getUsername());
|
|
|
|
isRootScope();
|
|
|
|
}
|
2017-02-15 20:20:23 +01:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
});
|
2017-02-15 20:20:23 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void isRootScope() {
|
2018-10-05 12:32:50 +02:00
|
|
|
AccountingManagerServiceAsync.INSTANCE.isRootScope(new AsyncCallback<Boolean>() {
|
2017-02-15 20:20:23 +01:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2021-06-28 18:12:01 +02:00
|
|
|
Log.error("Error in check root scope: " + caught.getMessage());
|
2018-10-05 12:32:50 +02:00
|
|
|
if (caught instanceof SessionExpiredException) {
|
|
|
|
UtilsGXT3.alert("Error", "Expired Session");
|
|
|
|
sessionExpiredShowDelayed();
|
|
|
|
} else {
|
|
|
|
UtilsGXT3.alert("Error", "Error checking the scope!");
|
|
|
|
}
|
|
|
|
}
|
2017-02-15 20:20:23 +01:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
@Override
|
|
|
|
public void onSuccess(Boolean result) {
|
|
|
|
rootScope = result;
|
|
|
|
Log.info("RootScope: " + result);
|
2021-06-28 18:12:01 +02:00
|
|
|
retrieveContext();
|
2018-10-05 12:32:50 +02:00
|
|
|
}
|
2015-07-17 15:38:33 +02:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
});
|
2015-07-17 15:38:33 +02:00
|
|
|
|
|
|
|
}
|
2021-06-28 18:12:01 +02:00
|
|
|
|
|
|
|
private void retrieveContext() {
|
|
|
|
|
|
|
|
AccountingManagerServiceAsync.INSTANCE.getContext(new AsyncCallback<Context>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
Log.error("Error in retrieve context: " + caught.getMessage());
|
|
|
|
if (caught instanceof SessionExpiredException) {
|
|
|
|
eventBus.fireEvent(new SessionExpiredEvent(SessionExpiredType.EXPIREDONSERVER));
|
|
|
|
} else {
|
|
|
|
Log.error("Error retrieving contexts for " + accountingType + ":" + caught.getLocalizedMessage());
|
|
|
|
UtilsGXT3.alert("Error retrieving contexts ", caught.getLocalizedMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(Context result) {
|
|
|
|
Log.debug("Available Context: " + result);
|
|
|
|
availableContext=result;
|
|
|
|
retrieveEnableTabs();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-09-22 18:47:29 +02:00
|
|
|
|
2016-09-20 18:18:11 +02:00
|
|
|
private void retrieveEnableTabs() {
|
2018-10-05 12:32:50 +02:00
|
|
|
AccountingManagerServiceAsync.INSTANCE.getEnableTabs(new AsyncCallback<EnableTabs>() {
|
2016-09-20 18:18:11 +02:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
Log.error("Error retrieving enable tabs: " + caught.getLocalizedMessage());
|
|
|
|
if (caught instanceof SessionExpiredException) {
|
|
|
|
UtilsGXT3.alert("Error", "Expired Session");
|
|
|
|
sessionExpiredShowDelayed();
|
|
|
|
} else {
|
|
|
|
UtilsGXT3.alert("Error", caught.getLocalizedMessage());
|
|
|
|
}
|
|
|
|
}
|
2016-09-20 18:18:11 +02:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
@Override
|
|
|
|
public void onSuccess(EnableTabs enableTabs) {
|
|
|
|
Log.info("Enable Tabs: " + enableTabs);
|
|
|
|
doEnableTabs(enableTabs);
|
|
|
|
}
|
2016-09-20 18:18:11 +02:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
});
|
2016-09-20 18:18:11 +02:00
|
|
|
|
|
|
|
}
|
2016-09-22 18:47:29 +02:00
|
|
|
|
|
|
|
private void doEnableTabs(EnableTabs enableTabs) {
|
2018-10-05 12:32:50 +02:00
|
|
|
if (enableTabs == null || enableTabs.getTabs() == null || enableTabs.getTabs().isEmpty()) {
|
|
|
|
UtilsGXT3.alert("Attention", "You don't have permissions to see Accounting Information in this scope!");
|
2016-09-22 18:47:29 +02:00
|
|
|
} else {
|
2016-12-02 10:58:36 +01:00
|
|
|
this.enableTabs = enableTabs;
|
2016-09-22 18:47:29 +02:00
|
|
|
EnableTabsEvent event = new EnableTabsEvent(enableTabs);
|
2017-05-05 17:07:30 +02:00
|
|
|
Log.debug("Fire: " + event);
|
2016-09-22 18:47:29 +02:00
|
|
|
eventBus.fireEvent(event);
|
2017-05-05 17:07:30 +02:00
|
|
|
|
2016-09-22 18:47:29 +02:00
|
|
|
}
|
|
|
|
}
|
2015-07-17 15:38:33 +02:00
|
|
|
|
|
|
|
private void sessionExpiredShowDelayed() {
|
|
|
|
Timer timeoutTimer = new Timer() {
|
|
|
|
public void run() {
|
|
|
|
sessionExpiredShow();
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
int TIMEOUT = 3; // 3 second timeout
|
|
|
|
|
|
|
|
timeoutTimer.schedule(TIMEOUT * 1000); // timeout is in milliseconds
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-09-01 18:34:45 +02:00
|
|
|
private void checkLocale() {
|
2015-07-17 15:38:33 +02:00
|
|
|
String[] locales = LocaleInfo.getAvailableLocaleNames();
|
|
|
|
|
|
|
|
for (String locale : locales) {
|
|
|
|
Log.debug("Locale avaible:" + locale);
|
|
|
|
}
|
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
String currentLocaleCookie = Cookies.getCookie(LocaleInfo.getLocaleCookieName());
|
2015-07-17 15:38:33 +02:00
|
|
|
Log.debug(Constants.AM_LANG_COOKIE + ":" + currentLocaleCookie);
|
|
|
|
|
|
|
|
LocaleInfo currentLocaleInfo = LocaleInfo.getCurrentLocale();
|
|
|
|
Log.debug("Current Locale:" + currentLocaleInfo.getLocaleName());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void changeLanguage(String localeName) {
|
|
|
|
Date now = new Date();
|
|
|
|
long nowLong = now.getTime();
|
|
|
|
nowLong = nowLong + (1000 * 60 * 60 * 24 * 21);
|
|
|
|
now.setTime(nowLong);
|
|
|
|
String cookieLang = Cookies.getCookie(Constants.AM_LANG_COOKIE);
|
|
|
|
if (cookieLang != null) {
|
|
|
|
Cookies.removeCookie(Constants.AM_LANG_COOKIE);
|
|
|
|
}
|
|
|
|
Cookies.setCookie(Constants.AM_LANG_COOKIE, localeName, now);
|
|
|
|
com.google.gwt.user.client.Window.Location.reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
public void restoreUISession() {
|
|
|
|
checkLocale();
|
2015-07-20 16:44:13 +02:00
|
|
|
showDefault();
|
2015-07-17 15:38:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Bind Controller to events on bus
|
|
|
|
private void bindToEvents() {
|
2018-10-05 12:32:50 +02:00
|
|
|
eventBus.addHandler(SessionExpiredEvent.TYPE, new SessionExpiredEvent.SessionExpiredEventHandler() {
|
2015-07-17 15:38:33 +02:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
@Override
|
|
|
|
public void onSessionExpired(SessionExpiredEvent event) {
|
|
|
|
Log.debug("Catch Event SessionExpiredEvent");
|
|
|
|
doSessionExpiredCommand(event);
|
2015-07-17 15:38:33 +02:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
}
|
|
|
|
});
|
2015-07-17 15:38:33 +02:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
eventBus.addHandler(AccountingMenuEvent.TYPE, new AccountingMenuEvent.AccountingMenuEventHandler() {
|
2015-07-17 15:38:33 +02:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
public void onMenu(AccountingMenuEvent event) {
|
|
|
|
Log.debug("Catch Event AccountingMenuEvent");
|
|
|
|
doMenuCommand(event);
|
2015-07-17 15:38:33 +02:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
}
|
|
|
|
});
|
2015-07-17 15:38:33 +02:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
eventBus.addHandler(FiltersChangeEvent.TYPE, new FiltersChangeEvent.FiltersChangeEventHandler() {
|
2015-07-17 15:38:33 +02:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
public void onFiltersChange(FiltersChangeEvent event) {
|
|
|
|
Log.debug("Catch Event FiltersChangeEvent");
|
|
|
|
doFiltersChangeCommand(event);
|
2015-07-17 15:38:33 +02:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
}
|
|
|
|
});
|
2016-05-31 15:50:31 +02:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
eventBus.addHandler(ExportRequestEvent.TYPE, new ExportRequestEvent.ExportRequestEventHandler() {
|
2016-05-30 18:51:08 +02:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
@Override
|
|
|
|
public void onExport(ExportRequestEvent event) {
|
|
|
|
Log.debug("Catch ExportRequestEvent");
|
|
|
|
doExportRequest(event);
|
2016-05-31 15:50:31 +02:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
}
|
|
|
|
});
|
2015-07-17 15:38:33 +02:00
|
|
|
|
|
|
|
eventBus.fireEvent(new UIStateEvent(UIStateType.START));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void doMenuCommand(AccountingMenuEvent event) {
|
2016-05-31 15:50:31 +02:00
|
|
|
AccountingClientStateData accountingStateData = null;
|
2015-07-17 15:38:33 +02:00
|
|
|
if (event == null || event.getAccountingType() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (event.getAccountingType()) {
|
|
|
|
case PORTLET:
|
|
|
|
case SERVICE:
|
|
|
|
case STORAGE:
|
|
|
|
case TASK:
|
|
|
|
case JOB:
|
2017-05-05 17:07:30 +02:00
|
|
|
case SPACE:
|
2015-07-20 16:44:13 +02:00
|
|
|
Log.debug("AccountingType: " + event.getAccountingType());
|
2018-10-05 12:32:50 +02:00
|
|
|
accountingStateData = accountingState.getState(event.getAccountingType());
|
2015-07-17 15:38:33 +02:00
|
|
|
if (accountingStateData == null) {
|
2015-07-20 16:44:13 +02:00
|
|
|
createDefaultChart(event.getAccountingType());
|
|
|
|
} else {
|
|
|
|
accountingType = event.getAccountingType();
|
2018-10-05 12:32:50 +02:00
|
|
|
StateChangeEvent stateChangeEvent = new StateChangeEvent(StateChangeType.Restore, accountingStateData);
|
2015-07-20 16:44:13 +02:00
|
|
|
eventBus.fireEvent(stateChangeEvent);
|
2015-07-17 15:38:33 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-09-07 19:11:34 +02:00
|
|
|
|
|
|
|
public void showDefault() {
|
2018-10-05 12:32:50 +02:00
|
|
|
if (enableTabs != null && enableTabs.getTabs() != null && enableTabs.getTabs().size() > 0
|
2016-12-02 10:58:36 +01:00
|
|
|
&& enableTabs.getTabs().get(0) != null) {
|
2017-05-05 17:07:30 +02:00
|
|
|
Log.debug("Create DefaultChart");
|
2016-12-02 10:58:36 +01:00
|
|
|
createDefaultChart(enableTabs.getTabs().get(0).getAccountingType());
|
|
|
|
}
|
2015-07-20 16:44:13 +02:00
|
|
|
}
|
2015-07-31 18:27:02 +02:00
|
|
|
|
2015-07-20 16:44:13 +02:00
|
|
|
private void createDefaultChart(AccountingType accountingType) {
|
|
|
|
accountingMonitor = new AccountingMonitor();
|
|
|
|
this.accountingType = accountingType;
|
2015-09-07 19:11:34 +02:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
AccountingClientStateData accountingStateData = new AccountingClientStateData(accountingType, rootScope);
|
2021-06-28 18:12:01 +02:00
|
|
|
accountingStateData.setAvailableContext(availableContext);
|
2015-09-07 19:11:34 +02:00
|
|
|
accountingState.setState(accountingType, accountingStateData);
|
|
|
|
|
2015-07-31 18:27:02 +02:00
|
|
|
retrieveFilterKey();
|
2015-09-07 19:11:34 +02:00
|
|
|
|
2015-07-20 16:44:13 +02:00
|
|
|
}
|
2015-09-07 19:11:34 +02:00
|
|
|
|
2015-07-31 18:27:02 +02:00
|
|
|
private void retrieveFilterKey() {
|
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
AccountingManagerServiceAsync.INSTANCE.getFilterKeys(accountingType, new AsyncCallback<ArrayList<FilterKey>>() {
|
2015-07-31 18:27:02 +02:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
accountingMonitor.hide();
|
|
|
|
if (caught instanceof SessionExpiredException) {
|
|
|
|
eventBus.fireEvent(new SessionExpiredEvent(SessionExpiredType.EXPIREDONSERVER));
|
|
|
|
} else {
|
|
|
|
Log.error(
|
|
|
|
"Error retrieving filter keys for " + accountingType + ":" + caught.getLocalizedMessage());
|
|
|
|
UtilsGXT3.alert("Error retrieving filter keys", caught.getLocalizedMessage());
|
|
|
|
}
|
2015-07-31 18:27:02 +02:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
}
|
2015-07-31 18:27:02 +02:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
@Override
|
|
|
|
public void onSuccess(ArrayList<FilterKey> result) {
|
|
|
|
Log.debug("FilterKeys: " + result);
|
|
|
|
AccountingClientStateData accountingStateData = accountingState.getState(accountingType);
|
|
|
|
accountingStateData.setAvailableFilterKeys(result);
|
|
|
|
accountingState.setState(accountingType, accountingStateData);
|
|
|
|
retrieveSpace();
|
|
|
|
}
|
|
|
|
});
|
2016-11-15 17:37:24 +01:00
|
|
|
|
|
|
|
}
|
2016-12-02 10:58:36 +01:00
|
|
|
|
2021-06-28 18:12:01 +02:00
|
|
|
|
|
|
|
|
2017-05-05 17:07:30 +02:00
|
|
|
private void retrieveSpace() {
|
|
|
|
if (rootScope) {
|
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
AccountingManagerServiceAsync.INSTANCE.getSpaces(new AsyncCallback<Spaces>() {
|
2017-05-05 17:07:30 +02:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
accountingMonitor.hide();
|
|
|
|
if (caught instanceof SessionExpiredException) {
|
|
|
|
eventBus.fireEvent(new SessionExpiredEvent(SessionExpiredType.EXPIREDONSERVER));
|
|
|
|
} else {
|
|
|
|
Log.error("Error retrieving sapces for " + accountingType + ":" + caught.getLocalizedMessage());
|
|
|
|
UtilsGXT3.alert("Error retrieving spaces ", caught.getLocalizedMessage());
|
|
|
|
}
|
2017-05-05 17:07:30 +02:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
}
|
2017-05-05 17:07:30 +02:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
@Override
|
|
|
|
public void onSuccess(Spaces result) {
|
|
|
|
Log.debug("Available Spaces: " + result);
|
|
|
|
createDefaultSeriesRequest(result);
|
|
|
|
}
|
|
|
|
});
|
2017-05-05 17:07:30 +02:00
|
|
|
} else {
|
|
|
|
createDefaultSeriesRequest(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void createDefaultSeriesRequest(Spaces spaces) {
|
|
|
|
Date now = new Date();
|
2018-10-05 12:32:50 +02:00
|
|
|
DateTimeFormat dtf = DateTimeFormat.getFormat(PredefinedFormat.YEAR_MONTH_DAY);
|
2017-05-05 17:07:30 +02:00
|
|
|
String currentDate = dtf.format(now);
|
|
|
|
Date date = dtf.parse(currentDate);
|
|
|
|
Date lastMonth = new Date(date.getTime());
|
|
|
|
CalendarUtil.addMonthsToDate(lastMonth, -1);
|
2018-10-05 12:32:50 +02:00
|
|
|
Log.debug("LastMoth= " + dtf.format(lastMonth) + " , date=" + dtf.format(date));
|
2017-05-05 17:07:30 +02:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
AccountingClientStateData accountingStateData = accountingState.getState(accountingType);
|
2017-05-05 17:07:30 +02:00
|
|
|
SeriesRequest seriesRequest = null;
|
|
|
|
|
|
|
|
switch (accountingType) {
|
|
|
|
case JOB:
|
|
|
|
case PORTLET:
|
|
|
|
case SERVICE:
|
|
|
|
case STORAGE:
|
|
|
|
case TASK:
|
2018-10-05 12:32:50 +02:00
|
|
|
seriesRequest = new SeriesRequest(
|
|
|
|
new AccountingPeriod(dtf.format(lastMonth), dtf.format(date), AccountingPeriodMode.DAILY),
|
|
|
|
new AccountingFilterBasic());
|
2017-05-05 17:07:30 +02:00
|
|
|
Log.debug("DefaultSeriesRequest: " + seriesRequest);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case SPACE:
|
|
|
|
accountingStateData.setAvailableSpaces(spaces);
|
2018-10-05 12:32:50 +02:00
|
|
|
seriesRequest = new SeriesRequest(
|
|
|
|
new AccountingPeriod(dtf.format(lastMonth), dtf.format(date), AccountingPeriodMode.DAILY),
|
|
|
|
new AccountingFilterSpaces(spaces));
|
2017-05-05 17:07:30 +02:00
|
|
|
Log.debug("DefaultSeriesRequest: " + seriesRequest);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
accountingStateData.setSeriesRequest(seriesRequest);
|
|
|
|
accountingState.setState(accountingType, accountingStateData);
|
|
|
|
callDefaultSeriesRequest();
|
|
|
|
}
|
|
|
|
|
2015-07-31 18:27:02 +02:00
|
|
|
private void callDefaultSeriesRequest() {
|
2015-07-20 16:44:13 +02:00
|
|
|
|
2017-02-13 19:36:24 +01:00
|
|
|
AccountingManagerServiceAsync.INSTANCE.getSeriesInCache(accountingType,
|
2018-10-05 12:32:50 +02:00
|
|
|
accountingState.getState(accountingType).getSeriesRequest(), new AsyncCallback<SeriesResponse>() {
|
2015-07-20 16:44:13 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(SeriesResponse seriesResponse) {
|
2015-09-07 19:11:34 +02:00
|
|
|
Log.debug("SeriesResponse: " + seriesResponse);
|
2017-02-13 19:36:24 +01:00
|
|
|
if (seriesResponse == null) {
|
|
|
|
callDefaultSeriesRequestNoCache();
|
|
|
|
} else {
|
2018-10-05 12:32:50 +02:00
|
|
|
AccountingClientStateData accountingStateData = accountingState.getState(accountingType);
|
|
|
|
accountingStateData.setSeriesResponse(seriesResponse);
|
|
|
|
accountingState.setState(accountingType, accountingStateData);
|
|
|
|
StateChangeEvent stateChangeEvent = new StateChangeEvent(StateChangeType.Restore,
|
2017-02-13 19:36:24 +01:00
|
|
|
accountingStateData);
|
|
|
|
eventBus.fireEvent(stateChangeEvent);
|
|
|
|
accountingMonitor.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2015-07-20 16:44:13 +02:00
|
|
|
accountingMonitor.hide();
|
2017-02-13 19:36:24 +01:00
|
|
|
if (caught instanceof SessionExpiredException) {
|
2018-10-05 12:32:50 +02:00
|
|
|
eventBus.fireEvent(new SessionExpiredEvent(SessionExpiredType.EXPIREDONSERVER));
|
2017-02-13 19:36:24 +01:00
|
|
|
} else {
|
|
|
|
Log.error("Error:" + caught.getLocalizedMessage());
|
|
|
|
caught.printStackTrace();
|
2018-10-05 12:32:50 +02:00
|
|
|
UtilsGXT3.alert("Error", caught.getLocalizedMessage());
|
|
|
|
AccountingClientStateData accountingStateData = accountingState.getState(accountingType);
|
2017-05-05 17:07:30 +02:00
|
|
|
accountingStateData.setSeriesResponse(null);
|
2018-10-05 12:32:50 +02:00
|
|
|
accountingState.setState(accountingType, accountingStateData);
|
|
|
|
StateChangeEvent stateChangeEvent = new StateChangeEvent(StateChangeType.Restore,
|
|
|
|
accountingState.getState(accountingType));
|
2017-02-13 19:36:24 +01:00
|
|
|
eventBus.fireEvent(stateChangeEvent);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2017-02-14 18:04:47 +01:00
|
|
|
|
2017-02-13 19:36:24 +01:00
|
|
|
private void callDefaultSeriesRequestNoCache() {
|
|
|
|
|
|
|
|
AccountingManagerServiceAsync.INSTANCE.getSeries(accountingType,
|
2018-10-05 12:32:50 +02:00
|
|
|
accountingState.getState(accountingType).getSeriesRequest(), new AsyncCallback<String>() {
|
2017-02-13 19:36:24 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(String operationId) {
|
|
|
|
Log.debug("Service OperationId: " + operationId);
|
2017-02-14 18:04:47 +01:00
|
|
|
if (operationId == null || operationId.isEmpty()) {
|
2017-02-13 19:36:24 +01:00
|
|
|
accountingMonitor.hide();
|
2017-02-14 18:04:47 +01:00
|
|
|
Log.error("Invalid Operation Id: " + operationId);
|
2018-10-05 12:32:50 +02:00
|
|
|
UtilsGXT3.alert("Error", "Invalid Operation Id: " + operationId);
|
|
|
|
AccountingClientStateData accountingStateData = accountingState.getState(accountingType);
|
2017-05-05 17:07:30 +02:00
|
|
|
accountingStateData.setSeriesResponse(null);
|
2018-10-05 12:32:50 +02:00
|
|
|
accountingState.setState(accountingType, accountingStateData);
|
|
|
|
StateChangeEvent stateChangeEvent = new StateChangeEvent(StateChangeType.Restore,
|
|
|
|
accountingState.getState(accountingType));
|
2017-02-13 19:36:24 +01:00
|
|
|
eventBus.fireEvent(stateChangeEvent);
|
|
|
|
} else {
|
2017-02-14 18:04:47 +01:00
|
|
|
defaultOperationMonitor(operationId);
|
2017-02-13 19:36:24 +01:00
|
|
|
}
|
2015-07-20 16:44:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
accountingMonitor.hide();
|
2016-05-30 18:51:08 +02:00
|
|
|
if (caught instanceof SessionExpiredException) {
|
2018-10-05 12:32:50 +02:00
|
|
|
eventBus.fireEvent(new SessionExpiredEvent(SessionExpiredType.EXPIREDONSERVER));
|
2015-07-20 16:44:13 +02:00
|
|
|
} else {
|
|
|
|
Log.error("Error:" + caught.getLocalizedMessage());
|
2015-07-31 18:27:02 +02:00
|
|
|
caught.printStackTrace();
|
2018-10-05 12:32:50 +02:00
|
|
|
UtilsGXT3.alert("Error", caught.getLocalizedMessage());
|
|
|
|
AccountingClientStateData accountingStateData = accountingState.getState(accountingType);
|
2017-05-05 17:07:30 +02:00
|
|
|
accountingStateData.setSeriesResponse(null);
|
2018-10-05 12:32:50 +02:00
|
|
|
accountingState.setState(accountingType, accountingStateData);
|
|
|
|
StateChangeEvent stateChangeEvent = new StateChangeEvent(StateChangeType.Restore,
|
|
|
|
accountingState.getState(accountingType));
|
2015-07-20 16:44:13 +02:00
|
|
|
eventBus.fireEvent(stateChangeEvent);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2017-02-13 19:36:24 +01:00
|
|
|
|
2017-02-14 18:04:47 +01:00
|
|
|
private void defaultOperationMonitor(final String operationId) {
|
|
|
|
final MonitorRequest monitorRequest = new MonitorRequest();
|
|
|
|
MonitorRequestEventHandler handler = new MonitorRequestEventHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onMonitor(MonitorRequestEvent event) {
|
|
|
|
switch (event.getMonitorRequestType()) {
|
|
|
|
case Period:
|
2018-10-05 12:32:50 +02:00
|
|
|
AccountingManagerServiceAsync.INSTANCE.operationMonitor(operationId,
|
|
|
|
new AsyncCallback<SeriesResponse>() {
|
2017-02-14 18:04:47 +01:00
|
|
|
|
|
|
|
@Override
|
2018-10-05 12:32:50 +02:00
|
|
|
public void onSuccess(SeriesResponse seriesResponse) {
|
|
|
|
Log.debug("SeriesResponse: " + seriesResponse);
|
2017-02-14 18:04:47 +01:00
|
|
|
if (seriesResponse != null) {
|
|
|
|
monitorRequest.stop();
|
|
|
|
AccountingClientStateData accountingStateData = accountingState
|
|
|
|
.getState(accountingType);
|
2018-10-05 12:32:50 +02:00
|
|
|
accountingStateData.setSeriesResponse(seriesResponse);
|
|
|
|
accountingState.setState(accountingType, accountingStateData);
|
2017-02-14 18:04:47 +01:00
|
|
|
StateChangeEvent stateChangeEvent = new StateChangeEvent(
|
2018-10-05 12:32:50 +02:00
|
|
|
StateChangeType.Restore, accountingStateData);
|
2017-02-14 18:04:47 +01:00
|
|
|
eventBus.fireEvent(stateChangeEvent);
|
|
|
|
accountingMonitor.hide();
|
|
|
|
} else {
|
|
|
|
monitorRequest.repeat();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
monitorRequest.stop();
|
|
|
|
accountingMonitor.hide();
|
|
|
|
if (caught instanceof SessionExpiredException) {
|
2018-10-05 12:32:50 +02:00
|
|
|
eventBus.fireEvent(new SessionExpiredEvent(SessionExpiredType.EXPIREDONSERVER));
|
2017-02-14 18:04:47 +01:00
|
|
|
} else {
|
2018-10-05 12:32:50 +02:00
|
|
|
Log.error("Error:" + caught.getLocalizedMessage());
|
2017-02-14 18:04:47 +01:00
|
|
|
caught.printStackTrace();
|
2018-10-05 12:32:50 +02:00
|
|
|
UtilsGXT3.alert("Error", caught.getLocalizedMessage());
|
2017-03-02 13:00:11 +01:00
|
|
|
AccountingClientStateData accountingStateData = accountingState
|
|
|
|
.getState(accountingType);
|
2018-10-05 12:32:50 +02:00
|
|
|
accountingStateData.setSeriesResponse(null);
|
|
|
|
accountingState.setState(accountingType, accountingStateData);
|
2017-02-14 18:04:47 +01:00
|
|
|
StateChangeEvent stateChangeEvent = new StateChangeEvent(
|
2018-10-05 12:32:50 +02:00
|
|
|
StateChangeType.Restore, accountingState.getState(accountingType));
|
2017-02-14 18:04:47 +01:00
|
|
|
eventBus.fireEvent(stateChangeEvent);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
break;
|
|
|
|
case TimeOut:
|
|
|
|
default:
|
|
|
|
monitorRequest.stop();
|
|
|
|
accountingMonitor.hide();
|
|
|
|
Log.error("Error: TimeOut!");
|
2017-02-17 18:26:45 +01:00
|
|
|
UtilsGXT3.alert("Error Time Out", "Time Out");
|
2018-10-05 12:32:50 +02:00
|
|
|
AccountingClientStateData accountingStateData = accountingState.getState(accountingType);
|
2017-05-05 17:07:30 +02:00
|
|
|
accountingStateData.setSeriesResponse(null);
|
2018-10-05 12:32:50 +02:00
|
|
|
accountingState.setState(accountingType, accountingStateData);
|
|
|
|
StateChangeEvent stateChangeEvent = new StateChangeEvent(StateChangeType.Restore,
|
2017-02-14 18:04:47 +01:00
|
|
|
accountingState.getState(accountingType));
|
|
|
|
eventBus.fireEvent(stateChangeEvent);
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
monitorRequest.addHandler(handler);
|
|
|
|
monitorRequest.start();
|
|
|
|
|
|
|
|
}
|
2015-07-17 15:38:33 +02:00
|
|
|
|
|
|
|
private void doFiltersChangeCommand(FiltersChangeEvent event) {
|
|
|
|
if (event == null || event.getFiltersChangeType() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (event.getFiltersChangeType()) {
|
|
|
|
case Update:
|
|
|
|
SeriesRequest seriesRequest = event.getSeriesRequest();
|
2018-10-05 12:32:50 +02:00
|
|
|
AccountingClientStateData accountingStateData = accountingState.getState(accountingType);
|
2015-07-17 15:38:33 +02:00
|
|
|
if (accountingStateData != null) {
|
2015-07-20 16:44:13 +02:00
|
|
|
accountingMonitor = new AccountingMonitor();
|
2015-07-17 15:38:33 +02:00
|
|
|
accountingStateData.setSeriesRequest(seriesRequest);
|
|
|
|
accountingState.setState(accountingType, accountingStateData);
|
2015-07-31 18:27:02 +02:00
|
|
|
callSeriesRequest();
|
2015-07-17 15:38:33 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-07-31 18:27:02 +02:00
|
|
|
private void callSeriesRequest() {
|
2015-09-07 19:11:34 +02:00
|
|
|
Log.debug("Call getSeries on server, params: " + accountingType + ", "
|
|
|
|
+ accountingState.getState(accountingType).getSeriesRequest());
|
|
|
|
|
2017-02-13 19:36:24 +01:00
|
|
|
AccountingManagerServiceAsync.INSTANCE.getSeriesInCache(accountingType,
|
2018-10-05 12:32:50 +02:00
|
|
|
accountingState.getState(accountingType).getSeriesRequest(), new AsyncCallback<SeriesResponse>() {
|
2015-07-17 15:38:33 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(SeriesResponse seriesResponse) {
|
|
|
|
Log.debug("SeriesResponse: " + seriesResponse);
|
2017-02-13 19:36:24 +01:00
|
|
|
if (seriesResponse == null) {
|
2017-02-14 18:04:47 +01:00
|
|
|
// TODO
|
|
|
|
callSeriesRequestNoCache();
|
2017-02-13 19:36:24 +01:00
|
|
|
} else {
|
2018-10-05 12:32:50 +02:00
|
|
|
AccountingClientStateData accountingStateData = accountingState.getState(accountingType);
|
|
|
|
accountingStateData.setSeriesResponse(seriesResponse);
|
|
|
|
accountingState.setState(accountingType, accountingStateData);
|
|
|
|
StateChangeEvent stateChangeEvent = new StateChangeEvent(StateChangeType.Update,
|
2017-02-13 19:36:24 +01:00
|
|
|
accountingStateData);
|
|
|
|
eventBus.fireEvent(stateChangeEvent);
|
|
|
|
accountingMonitor.hide();
|
|
|
|
}
|
2015-07-17 15:38:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
accountingMonitor.hide();
|
2016-05-30 18:51:08 +02:00
|
|
|
if (caught instanceof SessionExpiredException) {
|
2018-10-05 12:32:50 +02:00
|
|
|
eventBus.fireEvent(new SessionExpiredEvent(SessionExpiredType.EXPIREDONSERVER));
|
2015-07-17 15:38:33 +02:00
|
|
|
} else {
|
|
|
|
Log.error("Error:" + caught.getLocalizedMessage());
|
2018-10-05 12:32:50 +02:00
|
|
|
UtilsGXT3.alert("Error", caught.getLocalizedMessage());
|
2015-07-31 18:27:02 +02:00
|
|
|
caught.printStackTrace();
|
2018-10-05 12:32:50 +02:00
|
|
|
AccountingClientStateData accountingStateData = accountingState.getState(accountingType);
|
2017-05-05 17:07:30 +02:00
|
|
|
accountingStateData.setSeriesResponse(null);
|
2018-10-05 12:32:50 +02:00
|
|
|
accountingState.setState(accountingType, accountingStateData);
|
|
|
|
StateChangeEvent stateChangeEvent = new StateChangeEvent(StateChangeType.Update,
|
|
|
|
accountingState.getState(accountingType));
|
2017-03-02 13:00:11 +01:00
|
|
|
eventBus.fireEvent(stateChangeEvent);
|
2015-07-17 15:38:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-02-14 18:04:47 +01:00
|
|
|
private void callSeriesRequestNoCache() {
|
|
|
|
|
|
|
|
AccountingManagerServiceAsync.INSTANCE.getSeries(accountingType,
|
2018-10-05 12:32:50 +02:00
|
|
|
accountingState.getState(accountingType).getSeriesRequest(), new AsyncCallback<String>() {
|
2017-02-14 18:04:47 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(String operationId) {
|
|
|
|
Log.debug("Service OperationId: " + operationId);
|
|
|
|
if (operationId == null || operationId.isEmpty()) {
|
|
|
|
accountingMonitor.hide();
|
|
|
|
Log.error("Invalid Operation Id: " + operationId);
|
2018-10-05 12:32:50 +02:00
|
|
|
UtilsGXT3.alert("Error", "Invalid Operation Id: " + operationId);
|
|
|
|
AccountingClientStateData accountingStateData = accountingState.getState(accountingType);
|
2017-05-05 17:07:30 +02:00
|
|
|
accountingStateData.setSeriesResponse(null);
|
2018-10-05 12:32:50 +02:00
|
|
|
accountingState.setState(accountingType, accountingStateData);
|
|
|
|
StateChangeEvent stateChangeEvent = new StateChangeEvent(StateChangeType.Update,
|
|
|
|
accountingState.getState(accountingType));
|
2017-03-02 13:00:11 +01:00
|
|
|
eventBus.fireEvent(stateChangeEvent);
|
2017-02-14 18:04:47 +01:00
|
|
|
} else {
|
|
|
|
operationMonitor(operationId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
accountingMonitor.hide();
|
|
|
|
if (caught instanceof SessionExpiredException) {
|
2018-10-05 12:32:50 +02:00
|
|
|
eventBus.fireEvent(new SessionExpiredEvent(SessionExpiredType.EXPIREDONSERVER));
|
2017-02-14 18:04:47 +01:00
|
|
|
} else {
|
|
|
|
Log.error("Error:" + caught.getLocalizedMessage());
|
2018-10-05 12:32:50 +02:00
|
|
|
UtilsGXT3.alert("Error", caught.getLocalizedMessage());
|
2017-02-14 18:04:47 +01:00
|
|
|
caught.printStackTrace();
|
2018-10-05 12:32:50 +02:00
|
|
|
AccountingClientStateData accountingStateData = accountingState.getState(accountingType);
|
2017-05-05 17:07:30 +02:00
|
|
|
accountingStateData.setSeriesResponse(null);
|
2018-10-05 12:32:50 +02:00
|
|
|
accountingState.setState(accountingType, accountingStateData);
|
|
|
|
StateChangeEvent stateChangeEvent = new StateChangeEvent(StateChangeType.Update,
|
|
|
|
accountingState.getState(accountingType));
|
2017-03-02 13:00:11 +01:00
|
|
|
eventBus.fireEvent(stateChangeEvent);
|
2017-02-14 18:04:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void operationMonitor(final String operationId) {
|
|
|
|
final MonitorRequest monitorRequest = new MonitorRequest();
|
|
|
|
MonitorRequestEventHandler handler = new MonitorRequestEventHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onMonitor(MonitorRequestEvent event) {
|
|
|
|
switch (event.getMonitorRequestType()) {
|
|
|
|
case Period:
|
2018-10-05 12:32:50 +02:00
|
|
|
AccountingManagerServiceAsync.INSTANCE.operationMonitor(operationId,
|
|
|
|
new AsyncCallback<SeriesResponse>() {
|
2017-02-14 18:04:47 +01:00
|
|
|
|
|
|
|
@Override
|
2018-10-05 12:32:50 +02:00
|
|
|
public void onSuccess(SeriesResponse seriesResponse) {
|
|
|
|
Log.debug("SeriesResponse: " + seriesResponse);
|
2017-02-14 18:04:47 +01:00
|
|
|
if (seriesResponse != null) {
|
|
|
|
monitorRequest.stop();
|
|
|
|
AccountingClientStateData accountingStateData = accountingState
|
|
|
|
.getState(accountingType);
|
2018-10-05 12:32:50 +02:00
|
|
|
accountingStateData.setSeriesResponse(seriesResponse);
|
|
|
|
accountingState.setState(accountingType, accountingStateData);
|
|
|
|
StateChangeEvent stateChangeEvent = new StateChangeEvent(StateChangeType.Update,
|
2017-02-14 18:04:47 +01:00
|
|
|
accountingStateData);
|
|
|
|
eventBus.fireEvent(stateChangeEvent);
|
|
|
|
accountingMonitor.hide();
|
|
|
|
} else {
|
|
|
|
monitorRequest.repeat();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
monitorRequest.stop();
|
|
|
|
accountingMonitor.hide();
|
|
|
|
if (caught instanceof SessionExpiredException) {
|
2018-10-05 12:32:50 +02:00
|
|
|
eventBus.fireEvent(new SessionExpiredEvent(SessionExpiredType.EXPIREDONSERVER));
|
2017-02-14 18:04:47 +01:00
|
|
|
} else {
|
2018-10-05 12:32:50 +02:00
|
|
|
Log.error("Error:" + caught.getLocalizedMessage());
|
|
|
|
UtilsGXT3.alert("Error", caught.getLocalizedMessage());
|
2017-02-14 18:04:47 +01:00
|
|
|
caught.printStackTrace();
|
2017-03-02 13:00:11 +01:00
|
|
|
AccountingClientStateData accountingStateData = accountingState
|
|
|
|
.getState(accountingType);
|
2018-10-05 12:32:50 +02:00
|
|
|
accountingStateData.setSeriesResponse(null);
|
|
|
|
accountingState.setState(accountingType, accountingStateData);
|
|
|
|
StateChangeEvent stateChangeEvent = new StateChangeEvent(StateChangeType.Update,
|
|
|
|
accountingState.getState(accountingType));
|
2017-03-02 13:00:11 +01:00
|
|
|
eventBus.fireEvent(stateChangeEvent);
|
2017-02-14 18:04:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
break;
|
|
|
|
case TimeOut:
|
|
|
|
default:
|
|
|
|
monitorRequest.stop();
|
|
|
|
accountingMonitor.hide();
|
|
|
|
Log.error("Error: TimeOut!");
|
2017-02-17 18:26:45 +01:00
|
|
|
UtilsGXT3.alert("Error Time Out", "Time Out");
|
2018-10-05 12:32:50 +02:00
|
|
|
AccountingClientStateData accountingStateData = accountingState.getState(accountingType);
|
2017-05-05 17:07:30 +02:00
|
|
|
accountingStateData.setSeriesResponse(null);
|
2018-10-05 12:32:50 +02:00
|
|
|
accountingState.setState(accountingType, accountingStateData);
|
|
|
|
StateChangeEvent stateChangeEvent = new StateChangeEvent(StateChangeType.Update,
|
2017-05-05 17:07:30 +02:00
|
|
|
accountingState.getState(accountingType));
|
2017-03-02 13:00:11 +01:00
|
|
|
eventBus.fireEvent(stateChangeEvent);
|
2017-02-14 18:04:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
monitorRequest.addHandler(handler);
|
|
|
|
monitorRequest.start();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-09-22 18:47:29 +02:00
|
|
|
// TODO save on workspace
|
2016-06-28 17:55:13 +02:00
|
|
|
@SuppressWarnings("unused")
|
2016-06-09 16:26:02 +02:00
|
|
|
private void doSaveDataOnWorkspace(ExportRequestEvent event) {
|
2016-05-30 18:51:08 +02:00
|
|
|
accountingMonitor = new AccountingMonitor();
|
2018-10-05 12:32:50 +02:00
|
|
|
Log.debug("Call saveCSVOnWorkspace on server, params: " + event.getAccountingType());
|
2016-05-30 18:51:08 +02:00
|
|
|
|
2018-10-05 12:32:50 +02:00
|
|
|
AccountingManagerServiceAsync.INSTANCE.saveCSVOnWorkspace(event.getAccountingType(),
|
2016-05-31 15:50:31 +02:00
|
|
|
new AsyncCallback<ItemDescription>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
accountingMonitor.hide();
|
|
|
|
if (caught instanceof SessionExpiredException) {
|
2018-10-05 12:32:50 +02:00
|
|
|
eventBus.fireEvent(new SessionExpiredEvent(SessionExpiredType.EXPIREDONSERVER));
|
2016-05-31 15:50:31 +02:00
|
|
|
} else {
|
|
|
|
Log.error("Error:" + caught.getLocalizedMessage());
|
2018-10-05 12:32:50 +02:00
|
|
|
UtilsGXT3.alert("Error", caught.getLocalizedMessage());
|
2016-05-31 15:50:31 +02:00
|
|
|
caught.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(ItemDescription result) {
|
|
|
|
Log.debug("ItemDescription: " + result);
|
2018-10-05 12:32:50 +02:00
|
|
|
// doDownloadCSVFromWorkspace(result);
|
2016-05-31 15:50:31 +02:00
|
|
|
}
|
|
|
|
});
|
2016-05-30 18:51:08 +02:00
|
|
|
}
|
2016-05-31 15:50:31 +02:00
|
|
|
|
2016-05-30 18:51:08 +02:00
|
|
|
|
|
|
|
|
2016-06-09 16:26:02 +02:00
|
|
|
private void doExportRequest(ExportRequestEvent event) {
|
2016-05-31 15:50:31 +02:00
|
|
|
StringBuilder actionUrl = new StringBuilder();
|
|
|
|
actionUrl.append(GWT.getModuleBaseURL());
|
2018-10-05 12:32:50 +02:00
|
|
|
actionUrl.append(Constants.EXPORT_SERVLET + "?" + Constants.EXPORT_SERVLET_TYPE_PARAMETER + "="
|
|
|
|
+ event.getExportType().name() + "&" + Constants.EXPORT_SERVLET_ACCOUNTING_TYPE_PARAMETER + "="
|
|
|
|
+ event.getAccountingType().name() + "&" + Constants.CURR_GROUP_ID + "="
|
2017-01-19 18:47:04 +01:00
|
|
|
+ GCubeClientContext.getCurrentContextId());
|
2017-02-13 19:36:24 +01:00
|
|
|
|
|
|
|
// + "&"
|
|
|
|
// + Constants.CURR_USER_ID + "="
|
|
|
|
// + GCubeClientContext.getCurrentUserId());
|
2016-05-31 15:50:31 +02:00
|
|
|
|
|
|
|
Log.debug("Retrieved link: " + actionUrl);
|
2018-10-05 12:32:50 +02:00
|
|
|
Window.open(actionUrl.toString(), "_blank", "");
|
2016-05-31 15:50:31 +02:00
|
|
|
|
|
|
|
}
|
2016-05-30 18:51:08 +02:00
|
|
|
|
2015-07-17 15:38:33 +02:00
|
|
|
private void doSessionExpiredCommand(SessionExpiredEvent event) {
|
|
|
|
Log.debug("Session Expired Event: " + event.getSessionExpiredType());
|
|
|
|
sessionExpiredShow();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
private void asyncCodeLoadingFailed(Throwable reason) {
|
|
|
|
Log.error("Async code loading failed", reason);
|
2018-10-05 12:32:50 +02:00
|
|
|
eventBus.fireEvent(new SessionExpiredEvent(SessionExpiredType.EXPIREDONSERVER));
|
2015-07-17 15:38:33 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|