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;
|
|
|
|
|
|
|
|
import org.gcube.portlets.admin.accountingmanager.client.event.AccountingMenuEvent;
|
2016-05-30 18:51:08 +02:00
|
|
|
import org.gcube.portlets.admin.accountingmanager.client.event.DownloadCSVRequestEvent;
|
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;
|
|
|
|
import org.gcube.portlets.admin.accountingmanager.client.rpc.AccountingManagerServiceAsync;
|
|
|
|
import org.gcube.portlets.admin.accountingmanager.client.state.AccountingState;
|
|
|
|
import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData;
|
|
|
|
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;
|
|
|
|
import org.gcube.portlets.admin.accountingmanager.client.utils.UtilsGXT3;
|
|
|
|
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;
|
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;
|
2015-07-31 18:27:02 +02:00
|
|
|
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterKey;
|
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-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 org.gcube.portlets.widgets.sessionchecker.client.CheckSession;
|
|
|
|
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
|
|
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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author "Giancarlo Panichi" <a
|
|
|
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class AccountingManagerController {
|
|
|
|
|
|
|
|
private SimpleEventBus eventBus;
|
|
|
|
private UserInfo userInfo;
|
|
|
|
private AccountingState accountingState;
|
|
|
|
private AccountingType accountingType;
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
private BorderLayoutContainer mainPanel;
|
|
|
|
private AccountingMonitor accountingMonitor;
|
|
|
|
|
|
|
|
public AccountingManagerController() {
|
|
|
|
eventBus = new SimpleEventBus();
|
|
|
|
accountingType = AccountingType.STORAGE;
|
|
|
|
accountingState = new AccountingState();
|
|
|
|
AccountingStateData accountingStateData = new AccountingStateData(
|
2015-09-07 19:11:34 +02:00
|
|
|
accountingType, null, null, null);
|
2015-07-17 15:38:33 +02:00
|
|
|
accountingState.setState(accountingType, accountingStateData);
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void init() {
|
|
|
|
callHello();
|
|
|
|
checkSession();
|
|
|
|
bindToEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkSession() {
|
|
|
|
// if you do not need to something when the session expire
|
2016-02-17 16:57:02 +01:00
|
|
|
//CheckSession.getInstance().startPolling();
|
2015-07-17 15:38:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void sessionExpiredShow() {
|
|
|
|
CheckSession.showLogoutDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the eventBus
|
|
|
|
*/
|
|
|
|
public EventBus getEventBus() {
|
|
|
|
return eventBus;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setMainPanelLayout(BorderLayoutContainer mainPanel) {
|
|
|
|
this.mainPanel = mainPanel;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void callHello() {
|
|
|
|
AccountingManagerServiceAsync.INSTANCE
|
|
|
|
.hello(new AsyncCallback<UserInfo>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
Log.info("No valid user found: " + caught.getMessage());
|
2016-05-30 18:51:08 +02:00
|
|
|
if (caught instanceof SessionExpiredException) {
|
2015-07-17 15:38:33 +02:00
|
|
|
UtilsGXT3.alert("Error", "Expired Session");
|
|
|
|
sessionExpiredShowDelayed();
|
|
|
|
} else {
|
|
|
|
UtilsGXT3.alert("Error", "No user found");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(UserInfo result) {
|
|
|
|
userInfo = result;
|
|
|
|
Log.info("Hello: " + userInfo.getUsername());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
String currentLocaleCookie = Cookies.getCookie(LocaleInfo
|
|
|
|
.getLocaleCookieName());
|
|
|
|
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() {
|
|
|
|
eventBus.addHandler(SessionExpiredEvent.TYPE,
|
|
|
|
new SessionExpiredEvent.SessionExpiredEventHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSessionExpired(SessionExpiredEvent event) {
|
|
|
|
Log.debug("Catch Event SessionExpiredEvent");
|
|
|
|
doSessionExpiredCommand(event);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
eventBus.addHandler(AccountingMenuEvent.TYPE,
|
|
|
|
new AccountingMenuEvent.AccountingMenuEventHandler() {
|
|
|
|
|
|
|
|
public void onMenu(AccountingMenuEvent event) {
|
|
|
|
Log.debug("Catch Event AccountingMenuEvent");
|
|
|
|
doMenuCommand(event);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
eventBus.addHandler(FiltersChangeEvent.TYPE,
|
|
|
|
new FiltersChangeEvent.FiltersChangeEventHandler() {
|
|
|
|
|
|
|
|
public void onFiltersChange(FiltersChangeEvent event) {
|
|
|
|
Log.debug("Catch Event FiltersChangeEvent");
|
|
|
|
doFiltersChangeCommand(event);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
2016-05-30 18:51:08 +02:00
|
|
|
|
|
|
|
eventBus.addHandler(DownloadCSVRequestEvent.TYPE,
|
|
|
|
new DownloadCSVRequestEvent.DownloadCSVRequestEventHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDownload(DownloadCSVRequestEvent event) {
|
|
|
|
Log.debug("Catch DownloadDataRequestEvent");
|
|
|
|
doSaveDataOnWorkspace(event);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-07-17 15:38:33 +02:00
|
|
|
|
|
|
|
eventBus.fireEvent(new UIStateEvent(UIStateType.START));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void doMenuCommand(AccountingMenuEvent event) {
|
|
|
|
AccountingStateData accountingStateData = null;
|
|
|
|
if (event == null || event.getAccountingType() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (event.getAccountingType()) {
|
|
|
|
case PORTLET:
|
|
|
|
case SERVICE:
|
|
|
|
case STORAGE:
|
|
|
|
case TASK:
|
|
|
|
case JOB:
|
2015-07-20 16:44:13 +02:00
|
|
|
Log.debug("AccountingType: " + event.getAccountingType());
|
2015-07-17 15:38:33 +02:00
|
|
|
accountingStateData = accountingState.getState(event
|
|
|
|
.getAccountingType());
|
|
|
|
if (accountingStateData == null) {
|
2015-07-20 16:44:13 +02:00
|
|
|
createDefaultChart(event.getAccountingType());
|
|
|
|
} else {
|
|
|
|
accountingType = event.getAccountingType();
|
|
|
|
StateChangeEvent stateChangeEvent = new StateChangeEvent(
|
|
|
|
StateChangeType.Restore, accountingStateData);
|
|
|
|
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() {
|
2015-07-20 16:44:13 +02:00
|
|
|
createDefaultChart(AccountingType.STORAGE);
|
|
|
|
}
|
2015-07-31 18:27:02 +02:00
|
|
|
|
2015-07-20 16:44:13 +02:00
|
|
|
private void createDefaultChart(AccountingType accountingType) {
|
|
|
|
accountingMonitor = new AccountingMonitor();
|
2015-09-09 14:25:36 +02:00
|
|
|
Date now = new Date();
|
|
|
|
DateTimeFormat dtf=DateTimeFormat.getFormat(PredefinedFormat.YEAR_MONTH_DAY);
|
|
|
|
String currentDate=dtf.format(now);
|
|
|
|
Date date=dtf.parse(currentDate);
|
|
|
|
Date lastMonth=new Date(date.getTime());
|
|
|
|
CalendarUtil.addMonthsToDate(lastMonth, -1);
|
2015-10-14 19:01:35 +02:00
|
|
|
SeriesRequest seriesRequest = new SeriesRequest(new AccountingPeriod(dtf.format(lastMonth),
|
2016-02-16 17:48:44 +01:00
|
|
|
dtf.format(date), AccountingPeriodMode.DAILY), new AccountingFilterBasic());
|
2015-10-14 19:01:35 +02:00
|
|
|
Log.debug("DefaultSeriesRequest: "+seriesRequest);
|
|
|
|
Log.debug("LastMoth= "+dtf.format(lastMonth)+" , date="+dtf.format(date));
|
2015-07-20 16:44:13 +02:00
|
|
|
this.accountingType = accountingType;
|
2015-09-07 19:11:34 +02:00
|
|
|
|
2015-07-20 16:44:13 +02:00
|
|
|
AccountingStateData accountingStateData = new AccountingStateData(
|
2015-09-07 19:11:34 +02:00
|
|
|
accountingType, seriesRequest, null, null);
|
|
|
|
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() {
|
|
|
|
|
|
|
|
AccountingManagerServiceAsync.INSTANCE.getFilterKeys(accountingType,
|
|
|
|
new AsyncCallback<ArrayList<FilterKey>>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2015-10-14 12:14:23 +02:00
|
|
|
accountingMonitor.hide();
|
2016-05-30 18:51:08 +02:00
|
|
|
if (caught instanceof SessionExpiredException) {
|
2015-07-31 18:27:02 +02:00
|
|
|
eventBus.fireEvent(new SessionExpiredEvent(
|
|
|
|
SessionExpiredType.EXPIREDONSERVER));
|
|
|
|
} else {
|
2015-09-07 19:11:34 +02:00
|
|
|
Log.error("Error retrieving filter keys for "
|
|
|
|
+ accountingType + ":"
|
2015-07-31 18:27:02 +02:00
|
|
|
+ caught.getLocalizedMessage());
|
|
|
|
UtilsGXT3.alert("Error retrieving filter keys",
|
|
|
|
caught.getLocalizedMessage());
|
|
|
|
}
|
2015-10-14 12:14:23 +02:00
|
|
|
|
2015-07-31 18:27:02 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(ArrayList<FilterKey> result) {
|
|
|
|
Log.debug("FilterKeys: " + result);
|
2015-09-07 19:11:34 +02:00
|
|
|
AccountingStateData accountingStateData = accountingState
|
|
|
|
.getState(accountingType);
|
2015-07-31 18:27:02 +02:00
|
|
|
accountingStateData.setAvailableFilterKeys(result);
|
|
|
|
accountingState.setState(accountingType,
|
|
|
|
accountingStateData);
|
|
|
|
callDefaultSeriesRequest();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2015-09-07 19:11:34 +02:00
|
|
|
|
2015-07-31 18:27:02 +02:00
|
|
|
private void callDefaultSeriesRequest() {
|
2015-07-20 16:44:13 +02:00
|
|
|
|
2015-09-07 19:11:34 +02:00
|
|
|
AccountingManagerServiceAsync.INSTANCE.getSeries(accountingType,
|
2015-07-31 18:27:02 +02:00
|
|
|
accountingState.getState(accountingType).getSeriesRequest(),
|
2015-07-20 16:44:13 +02:00
|
|
|
new AsyncCallback<SeriesResponse>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(SeriesResponse seriesResponse) {
|
2015-09-07 19:11:34 +02:00
|
|
|
Log.debug("SeriesResponse: " + seriesResponse);
|
|
|
|
AccountingStateData accountingStateData = accountingState
|
|
|
|
.getState(accountingType);
|
2015-07-20 16:44:13 +02:00
|
|
|
accountingStateData.setSeriesResponse(seriesResponse);
|
|
|
|
accountingState.setState(accountingType,
|
|
|
|
accountingStateData);
|
|
|
|
StateChangeEvent stateChangeEvent = new StateChangeEvent(
|
|
|
|
StateChangeType.Restore, accountingStateData);
|
|
|
|
eventBus.fireEvent(stateChangeEvent);
|
|
|
|
accountingMonitor.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
accountingMonitor.hide();
|
2016-05-30 18:51:08 +02:00
|
|
|
if (caught instanceof SessionExpiredException) {
|
2015-07-20 16:44:13 +02:00
|
|
|
eventBus.fireEvent(new SessionExpiredEvent(
|
|
|
|
SessionExpiredType.EXPIREDONSERVER));
|
|
|
|
} else {
|
|
|
|
Log.error("Error:" + caught.getLocalizedMessage());
|
2015-07-31 18:27:02 +02:00
|
|
|
caught.printStackTrace();
|
2015-07-20 16:44:13 +02:00
|
|
|
UtilsGXT3.alert("Error",
|
|
|
|
caught.getLocalizedMessage());
|
|
|
|
StateChangeEvent stateChangeEvent = new StateChangeEvent(
|
2015-09-07 19:11:34 +02:00
|
|
|
StateChangeType.Restore, accountingState
|
|
|
|
.getState(accountingType));
|
2015-07-20 16:44:13 +02:00
|
|
|
eventBus.fireEvent(stateChangeEvent);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
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();
|
|
|
|
AccountingStateData accountingStateData = accountingState
|
|
|
|
.getState(accountingType);
|
|
|
|
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());
|
|
|
|
|
|
|
|
AccountingManagerServiceAsync.INSTANCE.getSeries(accountingType,
|
2015-07-31 18:27:02 +02:00
|
|
|
accountingState.getState(accountingType).getSeriesRequest(),
|
2015-07-17 15:38:33 +02:00
|
|
|
new AsyncCallback<SeriesResponse>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(SeriesResponse seriesResponse) {
|
|
|
|
Log.debug("SeriesResponse: " + seriesResponse);
|
2015-09-07 19:11:34 +02:00
|
|
|
AccountingStateData accountingStateData = accountingState
|
|
|
|
.getState(accountingType);
|
2015-07-17 15:38:33 +02:00
|
|
|
accountingStateData.setSeriesResponse(seriesResponse);
|
|
|
|
accountingState.setState(accountingType,
|
|
|
|
accountingStateData);
|
|
|
|
StateChangeEvent stateChangeEvent = new StateChangeEvent(
|
|
|
|
StateChangeType.Update, accountingStateData);
|
|
|
|
eventBus.fireEvent(stateChangeEvent);
|
|
|
|
accountingMonitor.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
accountingMonitor.hide();
|
2016-05-30 18:51:08 +02:00
|
|
|
if (caught instanceof SessionExpiredException) {
|
2015-07-17 15:38:33 +02:00
|
|
|
eventBus.fireEvent(new SessionExpiredEvent(
|
|
|
|
SessionExpiredType.EXPIREDONSERVER));
|
|
|
|
} else {
|
|
|
|
Log.error("Error:" + caught.getLocalizedMessage());
|
|
|
|
UtilsGXT3.alert("Error",
|
|
|
|
caught.getLocalizedMessage());
|
2015-07-31 18:27:02 +02:00
|
|
|
caught.printStackTrace();
|
2015-07-17 15:38:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-30 18:51:08 +02:00
|
|
|
|
|
|
|
private void doSaveDataOnWorkspace(DownloadCSVRequestEvent event) {
|
|
|
|
accountingMonitor = new AccountingMonitor();
|
|
|
|
Log.debug("Call saveCSVOnWorkspace on server, params: " + event.getAccountingType());
|
|
|
|
|
|
|
|
AccountingManagerServiceAsync.INSTANCE.saveCSVOnWorkspace(accountingState.getState(event.getAccountingType()), new AsyncCallback<ItemDescription>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
accountingMonitor.hide();
|
|
|
|
if (caught instanceof SessionExpiredException) {
|
|
|
|
eventBus.fireEvent(new SessionExpiredEvent(
|
|
|
|
SessionExpiredType.EXPIREDONSERVER));
|
|
|
|
} else {
|
|
|
|
Log.error("Error:" + caught.getLocalizedMessage());
|
|
|
|
UtilsGXT3.alert("Error",
|
|
|
|
caught.getLocalizedMessage());
|
|
|
|
caught.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(ItemDescription result) {
|
|
|
|
Log.debug("ItemDescription: " + result);
|
|
|
|
doDownloadCSV(result);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-30 18:54:11 +02:00
|
|
|
private void doDownloadCSV(final ItemDescription itemDescription) {
|
2016-05-30 18:51:08 +02:00
|
|
|
Log.debug("DownloadCSV from server: " + itemDescription);
|
|
|
|
|
|
|
|
AccountingManagerServiceAsync.INSTANCE.getPublicLink(itemDescription, new AsyncCallback<String>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
accountingMonitor.hide();
|
|
|
|
if (caught instanceof SessionExpiredException) {
|
|
|
|
eventBus.fireEvent(new SessionExpiredEvent(
|
|
|
|
SessionExpiredType.EXPIREDONSERVER));
|
|
|
|
} else {
|
|
|
|
Log.error("Error:" + caught.getLocalizedMessage());
|
|
|
|
UtilsGXT3.alert("Error",
|
|
|
|
caught.getLocalizedMessage());
|
|
|
|
caught.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-05-30 18:54:11 +02:00
|
|
|
public void onSuccess(String link) {
|
2016-05-30 18:51:08 +02:00
|
|
|
accountingMonitor.hide();
|
2016-05-30 18:54:11 +02:00
|
|
|
Log.debug("Retrieved link: " + link);
|
|
|
|
Window.open(link, itemDescription.getName(), "");
|
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);
|
|
|
|
eventBus.fireEvent(new SessionExpiredEvent(
|
|
|
|
SessionExpiredType.EXPIREDONSERVER));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|