From 22026c1d1be437d49d587d7dea2dc8fc6d77fc35 Mon Sep 17 00:00:00 2001 From: "giancarlo.panichi" Date: Mon, 30 May 2016 16:51:08 +0000 Subject: [PATCH] refs 4041: Accounting Manager portlet: give possibility to download raw data to users https://support.d4science.org/issues/4041 Added CSV file creation on workspace git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/admin/accounting-manager@128908 82a268e6-3cf1-43bd-a215-b396298e98cf --- pom.xml | 110 ++++++++++--- .../client/AccountingManagerController.java | 88 ++++++++++- .../client/event/DownloadCSVRequestEvent.java | 69 +++++++++ .../client/filters/ActiveFiltersPanel.java | 4 +- .../client/maindata/ChartViewerPanel.java | 14 +- .../maindata/charts/AccountingChart4Job.java | 13 +- .../charts/AccountingChart4Portlet.java | 11 +- .../charts/AccountingChart4Service.java | 17 ++- .../charts/AccountingChart4Storage.java | 17 ++- .../maindata/charts/AccountingChart4Task.java | 12 +- .../charts/AccountingChartBuilder.java | 4 +- .../charts/AccountingChartDirector.java | 4 +- .../charts/job/JobChartBasicPanel.java | 34 ++++- .../maindata/charts/job/JobChartTopPanel.java | 28 ++-- .../service/ServiceChartBasicPanel.java | 8 +- .../charts/service/ServiceChartTopPanel.java | 6 +- .../storage/StorageChartBasicPanel.java | 29 +++- .../charts/storage/StorageChartTopPanel.java | 28 +++- .../charts/utils/DownloadConstants.java | 1 + .../client/rpc/AccountingManagerService.java | 38 +++-- .../rpc/AccountingManagerServiceAsync.java | 18 +++ .../server/AccountingManagerServiceImpl.java | 107 +++++++++---- .../accountingmanager/server/SessionUtil.java | 8 +- .../server/amservice/AccountingCaller.java | 20 +-- .../amservice/AccountingCallerInterface.java | 8 +- .../amservice/AccountingCallerTester.java | 16 +- .../amservice/command/AccountingCommand.java | 4 +- .../command/AccountingCommandBasic.java | 16 +- .../AccountingCommandGetFilterKeys.java | 6 +- .../AccountingCommandGetFilterValues.java | 10 +- .../command/AccountingCommandTop.java | 16 +- .../amservice/query/AccountingQuery4Job.java | 12 +- .../query/AccountingQuery4Portlet.java | 12 +- .../query/AccountingQuery4Service.java | 12 +- .../query/AccountingQuery4Storage.java | 12 +- .../amservice/query/AccountingQuery4Task.java | 12 +- .../query/AccountingQueryBuilder.java | 4 +- .../query/AccountingQueryDirector.java | 4 +- .../response/SeriesResponse4JobBasic.java | 8 +- .../response/SeriesResponse4JobTop.java | 8 +- .../response/SeriesResponse4PortletBasic.java | 6 +- .../response/SeriesResponse4PortletTop.java | 8 +- .../response/SeriesResponse4ServiceBasic.java | 8 +- .../response/SeriesResponse4ServiceTop.java | 8 +- .../response/SeriesResponse4StorageBasic.java | 8 +- .../response/SeriesResponse4StorageTop.java | 8 +- .../response/SeriesResponse4TaskBasic.java | 6 +- .../response/SeriesResponse4TaskTop.java | 8 +- .../response/SeriesResponseBuilder.java | 4 +- .../response/SeriesResponseDirector.java | 4 +- .../server/csv/CSVManager.java | 132 ++++++++++++++++ .../server/csv/file/CSVDataRow.java | 40 +++++ .../server/csv/file/CSVModel.java | 72 +++++++++ .../server/csv/file/CSVModel4Service.java | 138 +++++++++++++++++ .../server/csv/file/CSVModel4Storage.java | 130 ++++++++++++++++ .../server/csv/file/CSVModelBuilder.java | 30 ++++ .../server/csv/file/CSVModelDirector.java | 38 +++++ .../server/csv/file/CSVModelSpec.java | 32 ++++ .../server/storage/StorageUtil.java | 144 ++++++++++++++++++ ...Exception.java => ChartDrawException.java} | 8 +- ...ceException.java => ServiceException.java} | 8 +- ...tion.java => SessionExpiredException.java} | 8 +- .../shared/workspace/ItemDescription.java | 112 ++++++++++++++ 63 files changed, 1541 insertions(+), 267 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/admin/accountingmanager/client/event/DownloadCSVRequestEvent.java create mode 100644 src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/CSVManager.java create mode 100644 src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVDataRow.java create mode 100644 src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVModel.java create mode 100644 src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVModel4Service.java create mode 100644 src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVModel4Storage.java create mode 100644 src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVModelBuilder.java create mode 100644 src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVModelDirector.java create mode 100644 src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVModelSpec.java create mode 100644 src/main/java/org/gcube/portlets/admin/accountingmanager/server/storage/StorageUtil.java rename src/main/java/org/gcube/portlets/admin/accountingmanager/shared/exception/{AccountingManagerChartDrawException.java => ChartDrawException.java} (60%) rename src/main/java/org/gcube/portlets/admin/accountingmanager/shared/exception/{AccountingManagerServiceException.java => ServiceException.java} (61%) rename src/main/java/org/gcube/portlets/admin/accountingmanager/shared/exception/{AccountingManagerSessionExpiredException.java => SessionExpiredException.java} (55%) create mode 100644 src/main/java/org/gcube/portlets/admin/accountingmanager/shared/workspace/ItemDescription.java diff --git a/pom.xml b/pom.xml index 78bdef8..914ef66 100644 --- a/pom.xml +++ b/pom.xml @@ -61,22 +61,36 @@ localRun + - org.slf4j - slf4j-api - compile - - - ch.qos.logback - logback-classic - 1.0.1 + org.gcube.contentmanagement + storage-manager-core runtime - org.gcube.accounting - accounting-lib - [2.0.0-SNAPSHOT,3.0.0-SNAPSHOT) + org.gcube.contentmanagement + storage-manager-wrapper + runtime + + + + org.gcube.common + home-library + runtime + + + org.gcube.common + home-library-jcr + runtime + + + org.gcube.common + home-library-model + runtime + + + org.gcube.common common-authorization @@ -89,6 +103,28 @@ runtime + + + org.slf4j + slf4j-api + compile + + + + ch.qos.logback + logback-classic + 1.0.1 + runtime + + + + + + org.gcube.accounting + accounting-lib + [2.0.0-SNAPSHOT,3.0.0-SNAPSHOT) + + @@ -210,15 +246,7 @@ aslsocial provided - - - - - + org.gcube.portlets.widgets @@ -233,6 +261,39 @@ provided + + + + org.gcube.contentmanagement + storage-manager-core + provided + + + + org.gcube.contentmanagement + storage-manager-wrapper + provided + + + + + org.gcube.common + home-library + provided + + + + org.gcube.common + home-library-jcr + provided + + + + org.gcube.common + home-library-model + provided + + org.gcube.accounting @@ -262,6 +323,15 @@ [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) + + + org.apache.commons + commons-csv + 1.4 + + + + com.allen-sauer.gwt.log diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/AccountingManagerController.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/AccountingManagerController.java index a6e517b..ce213b2 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/AccountingManagerController.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/AccountingManagerController.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.Date; import org.gcube.portlets.admin.accountingmanager.client.event.AccountingMenuEvent; +import org.gcube.portlets.admin.accountingmanager.client.event.DownloadCSVRequestEvent; 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; @@ -24,8 +25,9 @@ import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingType; import org.gcube.portlets.admin.accountingmanager.shared.data.FilterKey; import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerSessionExpiredException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.SessionExpiredException; import org.gcube.portlets.admin.accountingmanager.shared.session.UserInfo; +import org.gcube.portlets.admin.accountingmanager.shared.workspace.ItemDescription; import org.gcube.portlets.widgets.sessionchecker.client.CheckSession; import com.allen_sauer.gwt.log.client.Log; @@ -99,7 +101,7 @@ public class AccountingManagerController { @Override public void onFailure(Throwable caught) { Log.info("No valid user found: " + caught.getMessage()); - if (caught instanceof AccountingManagerSessionExpiredException) { + if (caught instanceof SessionExpiredException) { UtilsGXT3.alert("Error", "Expired Session"); sessionExpiredShowDelayed(); } else { @@ -198,6 +200,18 @@ public class AccountingManagerController { } }); + + eventBus.addHandler(DownloadCSVRequestEvent.TYPE, + new DownloadCSVRequestEvent.DownloadCSVRequestEventHandler() { + + @Override + public void onDownload(DownloadCSVRequestEvent event) { + Log.debug("Catch DownloadDataRequestEvent"); + doSaveDataOnWorkspace(event); + + } + }); + eventBus.fireEvent(new UIStateEvent(UIStateType.START)); @@ -266,7 +280,7 @@ public class AccountingManagerController { @Override public void onFailure(Throwable caught) { accountingMonitor.hide(); - if (caught instanceof AccountingManagerSessionExpiredException) { + if (caught instanceof SessionExpiredException) { eventBus.fireEvent(new SessionExpiredEvent( SessionExpiredType.EXPIREDONSERVER)); } else { @@ -317,7 +331,7 @@ public class AccountingManagerController { @Override public void onFailure(Throwable caught) { accountingMonitor.hide(); - if (caught instanceof AccountingManagerSessionExpiredException) { + if (caught instanceof SessionExpiredException) { eventBus.fireEvent(new SessionExpiredEvent( SessionExpiredType.EXPIREDONSERVER)); } else { @@ -386,7 +400,7 @@ public class AccountingManagerController { @Override public void onFailure(Throwable caught) { accountingMonitor.hide(); - if (caught instanceof AccountingManagerSessionExpiredException) { + if (caught instanceof SessionExpiredException) { eventBus.fireEvent(new SessionExpiredEvent( SessionExpiredType.EXPIREDONSERVER)); } else { @@ -401,6 +415,70 @@ public class AccountingManagerController { } + + 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() { + + @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); + } + }); + } + + + private void doDownloadCSV(ItemDescription itemDescription) { + Log.debug("DownloadCSV from server: " + itemDescription); + + AccountingManagerServiceAsync.INSTANCE.getPublicLink(itemDescription, new AsyncCallback() { + + @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(String result) { + accountingMonitor.hide(); + Log.debug("Link: " + result); + + } + }); + } + + + + + private void doSessionExpiredCommand(SessionExpiredEvent event) { Log.debug("Session Expired Event: " + event.getSessionExpiredType()); sessionExpiredShow(); diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/event/DownloadCSVRequestEvent.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/event/DownloadCSVRequestEvent.java new file mode 100644 index 0000000..49e6620 --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/event/DownloadCSVRequestEvent.java @@ -0,0 +1,69 @@ +package org.gcube.portlets.admin.accountingmanager.client.event; + +import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingType; + +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.event.shared.HasHandlers; + +/** + * + * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * + */ +public class DownloadCSVRequestEvent extends + GwtEvent { + + public static Type TYPE = new Type(); + private AccountingType accountingType; + + public interface DownloadCSVRequestEventHandler extends EventHandler { + void onDownload(DownloadCSVRequestEvent event); + } + + public interface HasDownloadCSVRequestEventHandler extends HasHandlers { + public HandlerRegistration addDownloadCSVRequestEventHandler( + DownloadCSVRequestEventHandler handler); + } + + public DownloadCSVRequestEvent(AccountingType accountingType) { + this.accountingType = accountingType; + } + + @Override + protected void dispatch(DownloadCSVRequestEventHandler handler) { + handler.onDownload(this); + } + + @Override + public Type getAssociatedType() { + return TYPE; + } + + public static Type getType() { + return TYPE; + } + + public static void fire(HasHandlers source, + DownloadCSVRequestEvent accountingMenuEvent) { + source.fireEvent(accountingMenuEvent); + } + + public AccountingType getAccountingType() { + return accountingType; + } + + @Override + public String toString() { + return "DownloadCSVRequestEvent [accountingType=" + accountingType + + "]"; + } + + + + + +} diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/filters/ActiveFiltersPanel.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/filters/ActiveFiltersPanel.java index be58755..74e8b9d 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/filters/ActiveFiltersPanel.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/filters/ActiveFiltersPanel.java @@ -21,7 +21,7 @@ import org.gcube.portlets.admin.accountingmanager.shared.data.ChartType; import org.gcube.portlets.admin.accountingmanager.shared.data.FilterKey; import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue; import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesRequest; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerSessionExpiredException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.SessionExpiredException; import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.cell.client.AbstractCell; @@ -779,7 +779,7 @@ public class ActiveFiltersPanel extends SimpleContainer { @Override public void onFailure(Throwable caught) { - if (caught instanceof AccountingManagerSessionExpiredException) { + if (caught instanceof SessionExpiredException) { eventBus.fireEvent(new SessionExpiredEvent( SessionExpiredType.EXPIREDONSERVER)); } else { diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/ChartViewerPanel.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/ChartViewerPanel.java index 38c95c2..3f216cc 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/ChartViewerPanel.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/ChartViewerPanel.java @@ -9,7 +9,7 @@ import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.Account import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.AccountingChartBuilder; import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.AccountingChartDirector; import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.AccountingChartPanel; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerChartDrawException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ChartDrawException; import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.event.shared.EventBus; @@ -86,19 +86,19 @@ public class ChartViewerPanel extends FramedPanel { switch (event.getAccountingStateData().getAccountingType()) { case JOB: - createChart(new AccountingChart4Job(event.getAccountingStateData())); + createChart(new AccountingChart4Job(eventBus, event.getAccountingStateData())); break; case PORTLET: - createChart(new AccountingChart4Portlet(event.getAccountingStateData())); + createChart(new AccountingChart4Portlet(eventBus, event.getAccountingStateData())); break; case SERVICE: - createChart(new AccountingChart4Service(event.getAccountingStateData())); + createChart(new AccountingChart4Service(eventBus, event.getAccountingStateData())); break; case STORAGE: - createChart(new AccountingChart4Storage(event.getAccountingStateData())); + createChart(new AccountingChart4Storage(eventBus, event.getAccountingStateData())); break; case TASK: - createChart(new AccountingChart4Task(event.getAccountingStateData())); + createChart(new AccountingChart4Task(eventBus, event.getAccountingStateData())); break; default: break; @@ -119,7 +119,7 @@ public class ChartViewerPanel extends FramedPanel { add(chart.getChart()); } - } catch (AccountingManagerChartDrawException e) { + } catch (ChartDrawException e) { Log.error(e.getLocalizedMessage()); e.printStackTrace(); } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChart4Job.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChart4Job.java index 29248bd..bc9bec6 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChart4Job.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChart4Job.java @@ -3,8 +3,9 @@ package org.gcube.portlets.admin.accountingmanager.client.maindata.charts; import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.job.JobChartBasicPanel; import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesJob; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerChartDrawException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ChartDrawException; +import com.google.gwt.event.shared.EventBus; import com.sencha.gxt.widget.core.client.container.SimpleContainer; /** @@ -17,13 +18,15 @@ import com.sencha.gxt.widget.core.client.container.SimpleContainer; public class AccountingChart4Job extends AccountingChartBuilder { private AccountingStateData accountingStateData; + private EventBus eventBus; - public AccountingChart4Job(AccountingStateData accountingStateData) { + public AccountingChart4Job(EventBus eventBus, AccountingStateData accountingStateData) { + this.eventBus=eventBus; this.accountingStateData = accountingStateData; } @Override - public void buildChart() throws AccountingManagerChartDrawException { + public void buildChart() throws ChartDrawException { AccountingChartPanel accountingChartPanel = null; if (accountingStateData == null @@ -48,7 +51,7 @@ public class AccountingChart4Job extends AccountingChartBuilder { } private SimpleContainer createJobChartPanel() - throws AccountingManagerChartDrawException { + throws ChartDrawException { if (accountingStateData == null || accountingStateData.getSeriesRequest() == null @@ -68,7 +71,7 @@ public class AccountingChart4Job extends AccountingChartBuilder { //return new JobChartTopPanel(accountingStateData); //createJobChart(new JobChart4Top(accountingStateData)); case Basic: - return new JobChartBasicPanel(accountingStateData); + return new JobChartBasicPanel(eventBus, accountingStateData); //createJobChart(new JobChart4Basic( //accountingStateData)); default: diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChart4Portlet.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChart4Portlet.java index df779b0..2fb264b 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChart4Portlet.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChart4Portlet.java @@ -2,7 +2,9 @@ package org.gcube.portlets.admin.accountingmanager.client.maindata.charts; import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorage; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerChartDrawException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ChartDrawException; + +import com.google.gwt.event.shared.EventBus; /** * Accounting Chart 4 Portlet @@ -12,15 +14,16 @@ import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingMan * */ public class AccountingChart4Portlet extends AccountingChartBuilder { - + private EventBus eventBus; private AccountingStateData accountingStateData; - public AccountingChart4Portlet(AccountingStateData accountingStateData) { + public AccountingChart4Portlet(EventBus eventBus, AccountingStateData accountingStateData) { + this.eventBus = eventBus; this.accountingStateData = accountingStateData; } @Override - public void buildChart() throws AccountingManagerChartDrawException { + public void buildChart() throws ChartDrawException { AccountingChartPanel accountingChartPanel = null; if (accountingStateData == null diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChart4Service.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChart4Service.java index fb291f8..409db3b 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChart4Service.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChart4Service.java @@ -4,8 +4,9 @@ import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.service import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.service.ServiceChartTopPanel; import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesService; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerChartDrawException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ChartDrawException; +import com.google.gwt.event.shared.EventBus; import com.sencha.gxt.widget.core.client.container.SimpleContainer; /** @@ -16,15 +17,17 @@ import com.sencha.gxt.widget.core.client.container.SimpleContainer; * */ public class AccountingChart4Service extends AccountingChartBuilder { - + private EventBus eventBus; private AccountingStateData accountingStateData; + - public AccountingChart4Service(AccountingStateData accountingStateData) { + public AccountingChart4Service(EventBus eventBus, AccountingStateData accountingStateData) { + this.eventBus=eventBus; this.accountingStateData = accountingStateData; } @Override - public void buildChart() throws AccountingManagerChartDrawException { + public void buildChart() throws ChartDrawException { AccountingChartPanel accountingChartPanel = null; if (accountingStateData == null @@ -49,7 +52,7 @@ public class AccountingChart4Service extends AccountingChartBuilder { } private SimpleContainer createServiceChartPanel() - throws AccountingManagerChartDrawException { + throws ChartDrawException { if (accountingStateData == null || accountingStateData.getSeriesRequest() == null @@ -64,9 +67,9 @@ public class AccountingChart4Service extends AccountingChartBuilder { .getAccountingFilterDefinition().getChartType()) { case Top: - return new ServiceChartTopPanel(accountingStateData); + return new ServiceChartTopPanel(eventBus,accountingStateData); case Basic: - return new ServiceChartBasicPanel(accountingStateData); + return new ServiceChartBasicPanel(eventBus, accountingStateData); default: return null; diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChart4Storage.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChart4Storage.java index 6107fb6..6498018 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChart4Storage.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChart4Storage.java @@ -4,8 +4,9 @@ import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage.StorageChartTopPanel; import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorage; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerChartDrawException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ChartDrawException; +import com.google.gwt.event.shared.EventBus; import com.sencha.gxt.widget.core.client.container.SimpleContainer; /** @@ -16,15 +17,17 @@ import com.sencha.gxt.widget.core.client.container.SimpleContainer; * */ public class AccountingChart4Storage extends AccountingChartBuilder { - + private EventBus eventBus; private AccountingStateData accountingStateData; + - public AccountingChart4Storage(AccountingStateData accountingStateData) { + public AccountingChart4Storage(EventBus eventBus, AccountingStateData accountingStateData) { + this.eventBus=eventBus; this.accountingStateData = accountingStateData; } @Override - public void buildChart() throws AccountingManagerChartDrawException { + public void buildChart() throws ChartDrawException { AccountingChartPanel accountingChartPanel = null; if (accountingStateData == null @@ -49,7 +52,7 @@ public class AccountingChart4Storage extends AccountingChartBuilder { } private SimpleContainer createStorageChartPanel() - throws AccountingManagerChartDrawException { + throws ChartDrawException { if (accountingStateData == null || accountingStateData.getSeriesRequest() == null @@ -65,10 +68,10 @@ public class AccountingChart4Storage extends AccountingChartBuilder { .getAccountingFilterDefinition().getChartType()) { case Top: - return new StorageChartTopPanel(accountingStateData); + return new StorageChartTopPanel(eventBus, accountingStateData); //createStorageChart(new StorageChart4Top(accountingStateData)); case Basic: - return new StorageChartBasicPanel(accountingStateData); + return new StorageChartBasicPanel(eventBus, accountingStateData); //createStorageChart(new StorageChart4Basic( //accountingStateData)); default: diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChart4Task.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChart4Task.java index fbd3f06..fa76d40 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChart4Task.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChart4Task.java @@ -2,7 +2,9 @@ package org.gcube.portlets.admin.accountingmanager.client.maindata.charts; import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorage; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerChartDrawException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ChartDrawException; + +import com.google.gwt.event.shared.EventBus; /** * Accounting Chart 4 Task @@ -12,15 +14,17 @@ import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingMan * */ public class AccountingChart4Task extends AccountingChartBuilder { - + private EventBus eventBus; private AccountingStateData accountingStateData; + - public AccountingChart4Task(AccountingStateData accountingStateData) { + public AccountingChart4Task(EventBus eventBus, AccountingStateData accountingStateData) { + this.eventBus=eventBus; this.accountingStateData = accountingStateData; } @Override - public void buildChart() throws AccountingManagerChartDrawException { + public void buildChart() throws ChartDrawException { AccountingChartPanel accountingChartPanel = null; if (accountingStateData == null diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChartBuilder.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChartBuilder.java index c712c06..95169ab 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChartBuilder.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChartBuilder.java @@ -1,6 +1,6 @@ package org.gcube.portlets.admin.accountingmanager.client.maindata.charts; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerChartDrawException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ChartDrawException; /** * Abstract class for build Accounting Chart @@ -20,7 +20,7 @@ public abstract class AccountingChartBuilder { } - public abstract void buildChart() throws AccountingManagerChartDrawException; + public abstract void buildChart() throws ChartDrawException; } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChartDirector.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChartDirector.java index 9d64ead..656b0f5 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChartDirector.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/AccountingChartDirector.java @@ -1,6 +1,6 @@ package org.gcube.portlets.admin.accountingmanager.client.maindata.charts; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerChartDrawException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ChartDrawException; /** @@ -23,7 +23,7 @@ public class AccountingChartDirector { } - public void constructAccountingChart() throws AccountingManagerChartDrawException { + public void constructAccountingChart() throws ChartDrawException { accountingChartBuilder.createSpec(); accountingChartBuilder.buildChart(); diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/job/JobChartBasicPanel.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/job/JobChartBasicPanel.java index 42525cc..caad13b 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/job/JobChartBasicPanel.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/job/JobChartBasicPanel.java @@ -2,6 +2,7 @@ package org.gcube.portlets.admin.accountingmanager.client.maindata.charts.job; import java.util.Date; +import org.gcube.portlets.admin.accountingmanager.client.event.DownloadCSVRequestEvent; import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.utils.ChartTimeMeasure; import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.utils.DownloadConstants; import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.utils.JobChartMeasure; @@ -23,6 +24,7 @@ import com.github.highcharts4gwt.model.highcharts.option.api.SeriesArea; import com.github.highcharts4gwt.model.highcharts.option.api.SeriesColumn; import com.google.gwt.event.logical.shared.SelectionEvent; import com.google.gwt.event.logical.shared.SelectionHandler; +import com.google.gwt.event.shared.EventBus; import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat; import com.sencha.gxt.cell.core.client.ButtonCell.ButtonArrowAlign; @@ -58,11 +60,13 @@ public class JobChartBasicPanel extends SimpleContainer { private HighchartsLayoutPanel highchartsLayoutPanel; // Download Menu + private MenuItem downloadCSVItem; private MenuItem downloadPNGItem; private MenuItem downloadJPGItem; private MenuItem downloadPDFItem; private MenuItem downloadSVGItem; + // Time Unit Menu private MenuItem msItem; private MenuItem sItem; @@ -76,8 +80,10 @@ public class JobChartBasicPanel extends SimpleContainer { private String unitMeasureLabel = TimeUnitMeasure.MS; private TextButton unitButton; private ToggleButton toggleButton; + private EventBus eventBus; - public JobChartBasicPanel(AccountingStateData accountingStateData) { + public JobChartBasicPanel(EventBus eventBus, AccountingStateData accountingStateData) { + this.eventBus=eventBus; this.accountingStateData = accountingStateData; forceLayoutOnResize = true; create(); @@ -222,6 +228,8 @@ public class JobChartBasicPanel extends SimpleContainer { private Menu createDownloadMenu() { Menu menuDownload = new Menu(); + downloadCSVItem = new MenuItem(DownloadConstants.DOWNLOAD_CSV, + AccountingManagerResources.INSTANCE.accountingByte24()); downloadPNGItem = new MenuItem(DownloadConstants.DOWNLOAD_PNG, AccountingManagerResources.INSTANCE.accountingFilePNG24()); downloadPNGItem.setHeight(30); @@ -235,6 +243,20 @@ public class JobChartBasicPanel extends SimpleContainer { AccountingManagerResources.INSTANCE.accountingFileSVG24()); downloadSVGItem.setHeight(30); + + downloadCSVItem.addSelectionHandler(new SelectionHandler() { + + @Override + public void onSelection(SelectionEvent event) { + onDownloadCSV(); + + } + + + }); + + + downloadPNGItem.addSelectionHandler(new SelectionHandler() { @Override @@ -271,7 +293,8 @@ public class JobChartBasicPanel extends SimpleContainer { onDownloadSVG(id); } }); - + + menuDownload.add(downloadCSVItem); menuDownload.add(downloadPNGItem); menuDownload.add(downloadJPGItem); menuDownload.add(downloadPDFItem); @@ -279,6 +302,13 @@ public class JobChartBasicPanel extends SimpleContainer { return menuDownload; } + + + private void onDownloadCSV() { + DownloadCSVRequestEvent event = new DownloadCSVRequestEvent( + accountingStateData.getAccountingType()); + eventBus.fireEvent(event); + } // chart.options.exporting.buttons.contextButton.menuItems[0].onclick(); diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/job/JobChartTopPanel.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/job/JobChartTopPanel.java index b6bf2fc..60d61dc 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/job/JobChartTopPanel.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/job/JobChartTopPanel.java @@ -23,6 +23,7 @@ import com.github.highcharts4gwt.model.highcharts.option.api.ChartOptions; import com.github.highcharts4gwt.model.highcharts.option.api.SeriesColumn; import com.google.gwt.event.logical.shared.SelectionEvent; import com.google.gwt.event.logical.shared.SelectionHandler; +import com.google.gwt.event.shared.EventBus; import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat; import com.sencha.gxt.cell.core.client.ButtonCell.ButtonArrowAlign; @@ -53,6 +54,7 @@ public class JobChartTopPanel extends SimpleContainer { private DateTimeFormat dtf = DateTimeFormat .getFormat(PredefinedFormat.YEAR_MONTH_DAY); + private EventBus eventBus; private AccountingStateData accountingStateData; private HighchartsLayoutPanel highchartsLayoutPanel; @@ -85,7 +87,9 @@ public class JobChartTopPanel extends SimpleContainer { private VerticalLayoutContainer vert; - public JobChartTopPanel(AccountingStateData accountingStateData) { + public JobChartTopPanel(EventBus eventBus, + AccountingStateData accountingStateData) { + this.eventBus = eventBus; this.accountingStateData = accountingStateData; forceLayoutOnResize = true; create(); @@ -234,8 +238,7 @@ public class JobChartTopPanel extends SimpleContainer { @Override public void onSelection(SelectionEvent event) { - measureButton.setText(JobChartMeasure.OperationCount - .getLabel()); + measureButton.setText(JobChartMeasure.OperationCount.getLabel()); measure = JobChartMeasure.OperationCount; unitButton.setVisible(false); updateChart(); @@ -458,14 +461,12 @@ public class JobChartTopPanel extends SimpleContainer { + " }" + " }"); ArrayList seriesColumn = new ArrayList<>(); - for (int i = 0; i < seriesJobTop.getSeriesJobDataTopList() - .size(); i++) { + for (int i = 0; i < seriesJobTop.getSeriesJobDataTopList().size(); i++) { SeriesColumn seriesColumnData = highchartsFactory .createSeriesColumn(); - seriesColumnData.name(seriesJobTop - .getSeriesJobDataTopList().get(i).getFilterValue() - .getValue()); + seriesColumnData.name(seriesJobTop.getSeriesJobDataTopList().get(i) + .getFilterValue().getValue()); seriesColumnData.color(colors.get(i)); seriesColumnData.type("column"); @@ -553,12 +554,11 @@ public class JobChartTopPanel extends SimpleContainer { + " \"style\": {" + " \"color\": \"" + colors.get(1) + "\"" + " }" + " }" + "}]"; case OperationCount: - return "[{" + " \"id\": \"" - + JobChartMeasure.OperationCount.name() + "\"," - + " \"labels\": { " + " \"format\": \"{value}\"," - + " \"style\": { " + " \"color\": \"" - + colors.get(1) + "\"" + " }" + " }," - + " \"stackLabels\": {" + " \"enabled\": \"true\"," + return "[{" + " \"id\": \"" + JobChartMeasure.OperationCount.name() + + "\"," + " \"labels\": { " + + " \"format\": \"{value}\"," + " \"style\": { " + + " \"color\": \"" + colors.get(1) + "\"" + " }" + + " }," + " \"stackLabels\": {" + " \"enabled\": \"true\"," + " \"style\": {" + " \"fontWeight\": \"bold\"," + " \"color\": \"gray\"" + " } " + " }," + " \"title\": { " + " \"text\": \"" diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/service/ServiceChartBasicPanel.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/service/ServiceChartBasicPanel.java index 4ca19b3..8b303e8 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/service/ServiceChartBasicPanel.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/service/ServiceChartBasicPanel.java @@ -23,6 +23,7 @@ import com.github.highcharts4gwt.model.highcharts.option.api.SeriesArea; import com.github.highcharts4gwt.model.highcharts.option.api.SeriesColumn; import com.google.gwt.event.logical.shared.SelectionEvent; import com.google.gwt.event.logical.shared.SelectionHandler; +import com.google.gwt.event.shared.EventBus; import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat; import com.sencha.gxt.cell.core.client.ButtonCell.ButtonArrowAlign; @@ -53,7 +54,8 @@ public class ServiceChartBasicPanel extends SimpleContainer { .getFormat(PredefinedFormat.YEAR_MONTH_DAY); private static final String TIME_UNIT = "Time Unit"; private static final String SINGLE_AXIS = "Single Axis"; - + + private EventBus eventBus; private AccountingStateData accountingStateData; private HighchartsLayoutPanel highchartsLayoutPanel; @@ -76,8 +78,10 @@ public class ServiceChartBasicPanel extends SimpleContainer { private String unitMeasureLabel = TimeUnitMeasure.MS; private TextButton unitButton; private ToggleButton toggleButton; + - public ServiceChartBasicPanel(AccountingStateData accountingStateData) { + public ServiceChartBasicPanel(EventBus eventBus, AccountingStateData accountingStateData) { + this.eventBus=eventBus; this.accountingStateData = accountingStateData; forceLayoutOnResize = true; create(); diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/service/ServiceChartTopPanel.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/service/ServiceChartTopPanel.java index 46a8085..437eeaf 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/service/ServiceChartTopPanel.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/service/ServiceChartTopPanel.java @@ -23,6 +23,7 @@ import com.github.highcharts4gwt.model.highcharts.option.api.ChartOptions; import com.github.highcharts4gwt.model.highcharts.option.api.SeriesColumn; import com.google.gwt.event.logical.shared.SelectionEvent; import com.google.gwt.event.logical.shared.SelectionHandler; +import com.google.gwt.event.shared.EventBus; import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat; import com.sencha.gxt.cell.core.client.ButtonCell.ButtonArrowAlign; @@ -53,6 +54,7 @@ public class ServiceChartTopPanel extends SimpleContainer { private DateTimeFormat dtf = DateTimeFormat .getFormat(PredefinedFormat.YEAR_MONTH_DAY); + private EventBus eventBus; private AccountingStateData accountingStateData; private HighchartsLayoutPanel highchartsLayoutPanel; @@ -84,8 +86,10 @@ public class ServiceChartTopPanel extends SimpleContainer { private TextButton measureButton; private VerticalLayoutContainer vert; + - public ServiceChartTopPanel(AccountingStateData accountingStateData) { + public ServiceChartTopPanel(EventBus eventBus, AccountingStateData accountingStateData) { + this.eventBus=eventBus; this.accountingStateData = accountingStateData; forceLayoutOnResize = true; create(); diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/storage/StorageChartBasicPanel.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/storage/StorageChartBasicPanel.java index c7ae59f..780de6c 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/storage/StorageChartBasicPanel.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/storage/StorageChartBasicPanel.java @@ -2,6 +2,7 @@ package org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storag import java.util.Date; +import org.gcube.portlets.admin.accountingmanager.client.event.DownloadCSVRequestEvent; import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.utils.ByteUnitMeasure; import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.utils.ChartTimeMeasure; import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.utils.DownloadConstants; @@ -23,6 +24,7 @@ import com.github.highcharts4gwt.model.highcharts.option.api.SeriesArea; import com.github.highcharts4gwt.model.highcharts.option.api.SeriesColumn; import com.google.gwt.event.logical.shared.SelectionEvent; import com.google.gwt.event.logical.shared.SelectionHandler; +import com.google.gwt.event.shared.EventBus; import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat; import com.sencha.gxt.cell.core.client.ButtonCell.ButtonArrowAlign; @@ -52,10 +54,12 @@ public class StorageChartBasicPanel extends SimpleContainer { private DateTimeFormat dtf = DateTimeFormat .getFormat(PredefinedFormat.YEAR_MONTH_DAY); + private EventBus eventBus; private AccountingStateData accountingStateData; private HighchartsLayoutPanel highchartsLayoutPanel; // Download Menu + private MenuItem downloadCSVItem; private MenuItem downloadPNGItem; private MenuItem downloadJPGItem; private MenuItem downloadPDFItem; @@ -74,7 +78,9 @@ public class StorageChartBasicPanel extends SimpleContainer { private ChartOptions options; private VerticalLayoutContainer vert; - public StorageChartBasicPanel(AccountingStateData accountingStateData) { + public StorageChartBasicPanel(EventBus eventBus, + AccountingStateData accountingStateData) { + this.eventBus = eventBus; this.accountingStateData = accountingStateData; forceLayoutOnResize = true; create(); @@ -122,7 +128,7 @@ public class StorageChartBasicPanel extends SimpleContainer { createChart(); highchartsLayoutPanel.renderChart(options); forceLayout(); - + /* * vert.remove(highchartsLayoutPanel); // createChart(); * @@ -209,6 +215,8 @@ public class StorageChartBasicPanel extends SimpleContainer { private Menu createDownloadMenu() { Menu menuDownload = new Menu(); + downloadCSVItem = new MenuItem(DownloadConstants.DOWNLOAD_CSV, + AccountingManagerResources.INSTANCE.accountingByte24()); downloadPNGItem = new MenuItem(DownloadConstants.DOWNLOAD_PNG, AccountingManagerResources.INSTANCE.accountingFilePNG24()); downloadPNGItem.setHeight(30); @@ -222,6 +230,16 @@ public class StorageChartBasicPanel extends SimpleContainer { AccountingManagerResources.INSTANCE.accountingFileSVG24()); downloadSVGItem.setHeight(30); + downloadCSVItem.addSelectionHandler(new SelectionHandler() { + + @Override + public void onSelection(SelectionEvent event) { + onDownloadCSV(); + + } + + }); + downloadPNGItem.addSelectionHandler(new SelectionHandler() { @Override @@ -259,6 +277,7 @@ public class StorageChartBasicPanel extends SimpleContainer { } }); + menuDownload.add(downloadCSVItem); menuDownload.add(downloadPNGItem); menuDownload.add(downloadJPGItem); menuDownload.add(downloadPDFItem); @@ -267,6 +286,12 @@ public class StorageChartBasicPanel extends SimpleContainer { } + private void onDownloadCSV() { + DownloadCSVRequestEvent event = new DownloadCSVRequestEvent( + accountingStateData.getAccountingType()); + eventBus.fireEvent(event); + } + // chart.options.exporting.buttons.contextButton.menuItems[0].onclick(); public static native void onDownloadPNG(String id) /*-{ diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/storage/StorageChartTopPanel.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/storage/StorageChartTopPanel.java index 8ac1a20..140bfe9 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/storage/StorageChartTopPanel.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/storage/StorageChartTopPanel.java @@ -3,6 +3,7 @@ package org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storag import java.util.ArrayList; import java.util.Date; +import org.gcube.portlets.admin.accountingmanager.client.event.DownloadCSVRequestEvent; import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.utils.ByteUnitMeasure; import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.utils.ChartTimeMeasure; import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.utils.DownloadConstants; @@ -23,6 +24,7 @@ import com.github.highcharts4gwt.model.highcharts.option.api.ChartOptions; import com.github.highcharts4gwt.model.highcharts.option.api.SeriesColumn; import com.google.gwt.event.logical.shared.SelectionEvent; import com.google.gwt.event.logical.shared.SelectionHandler; +import com.google.gwt.event.shared.EventBus; import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat; import com.sencha.gxt.cell.core.client.ButtonCell.ButtonArrowAlign; @@ -52,11 +54,13 @@ public class StorageChartTopPanel extends SimpleContainer { private DateTimeFormat dtf = DateTimeFormat .getFormat(PredefinedFormat.YEAR_MONTH_DAY); - + + private EventBus eventBus; private AccountingStateData accountingStateData; private HighchartsLayoutPanel highchartsLayoutPanel; // Download Menu + private MenuItem downloadCSVItem; private MenuItem downloadPNGItem; private MenuItem downloadJPGItem; private MenuItem downloadPDFItem; @@ -83,7 +87,9 @@ public class StorageChartTopPanel extends SimpleContainer { private VerticalLayoutContainer vert; - public StorageChartTopPanel(AccountingStateData accountingStateData) { + + public StorageChartTopPanel(EventBus eventBus, AccountingStateData accountingStateData) { + this.eventBus=eventBus; this.accountingStateData = accountingStateData; forceLayoutOnResize = true; create(); @@ -158,6 +164,8 @@ public class StorageChartTopPanel extends SimpleContainer { private Menu createDownloadMenu() { Menu menuDownload = new Menu(); + downloadCSVItem = new MenuItem(DownloadConstants.DOWNLOAD_CSV, + AccountingManagerResources.INSTANCE.accountingByte24()); downloadPNGItem = new MenuItem(DownloadConstants.DOWNLOAD_PNG, AccountingManagerResources.INSTANCE.accountingFilePNG24()); downloadPNGItem.setHeight(30); @@ -170,7 +178,17 @@ public class StorageChartTopPanel extends SimpleContainer { downloadSVGItem = new MenuItem(DownloadConstants.DOWNLOAD_SVG, AccountingManagerResources.INSTANCE.accountingFileSVG24()); downloadSVGItem.setHeight(30); + + downloadCSVItem.addSelectionHandler(new SelectionHandler() { + @Override + public void onSelection(SelectionEvent event) { + onDownloadCSV(); + + } + + }); + downloadPNGItem.addSelectionHandler(new SelectionHandler() { @Override @@ -319,6 +337,12 @@ public class StorageChartTopPanel extends SimpleContainer { return menuUnit; } + + private void onDownloadCSV() { + DownloadCSVRequestEvent event = new DownloadCSVRequestEvent( + accountingStateData.getAccountingType()); + eventBus.fireEvent(event); + } // chart.options.exporting.buttons.contextButton.menuItems[0].onclick(); diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/utils/DownloadConstants.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/utils/DownloadConstants.java index e26c398..cbc8b9b 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/utils/DownloadConstants.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/maindata/charts/utils/DownloadConstants.java @@ -8,6 +8,7 @@ package org.gcube.portlets.admin.accountingmanager.client.maindata.charts.utils; */ public class DownloadConstants { public static final String DOWNLOAD = "Download"; + public static final String DOWNLOAD_CSV = "Download CSV"; public static final String DOWNLOAD_PNG = "Download PNG Image"; public static final String DOWNLOAD_JPG = "Download JPG Image"; public static final String DOWNLOAD_PDF = "Download PDF Document"; diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/rpc/AccountingManagerService.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/rpc/AccountingManagerService.java index 1d6d5ea..239ed59 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/rpc/AccountingManagerService.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/rpc/AccountingManagerService.java @@ -2,14 +2,16 @@ package org.gcube.portlets.admin.accountingmanager.client.rpc; import java.util.ArrayList; +import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData; import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingType; import org.gcube.portlets.admin.accountingmanager.shared.data.FilterKey; import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue; import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesRequest; import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; import org.gcube.portlets.admin.accountingmanager.shared.session.UserInfo; +import org.gcube.portlets.admin.accountingmanager.shared.workspace.ItemDescription; import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; @@ -26,9 +28,9 @@ public interface AccountingManagerService extends RemoteService { * Get informations on the current user * * @return - * @throws AccountingManagerServiceException + * @throws ServiceException */ - public UserInfo hello() throws AccountingManagerServiceException; + public UserInfo hello() throws ServiceException; /** * Retrieve Accounting Series @@ -38,31 +40,49 @@ public interface AccountingManagerService extends RemoteService { * @param seriesRequest * filters and constraints descriptions * @return - * @throws AccountingManagerServiceException + * @throws ServiceException */ public SeriesResponse getSeries(AccountingType accountingType, SeriesRequest seriesRequest) - throws AccountingManagerServiceException; + throws ServiceException; /** * * @param accountingType * type of accounting * @return list of filter keys - * @throws AccountingManagerServiceException + * @throws ServiceException */ public ArrayList getFilterKeys(AccountingType accountingType) - throws AccountingManagerServiceException; + throws ServiceException; /** * * * @param filterValuesRequest request values available * @return - * @throws AccountingManagerServiceException + * @throws ServiceException */ public ArrayList getFilterValues(FilterValuesRequest filterValuesRequest) - throws AccountingManagerServiceException; + throws ServiceException; + + /** + * + * @param itemDescription item description + * @return + * @throws ServiceException + */ + public String getPublicLink(ItemDescription itemDescription) + throws ServiceException; + + /** + * + * @param accountingStateData + * @return + * @throws ServiceException + */ + public ItemDescription saveCSVOnWorkspace(AccountingStateData accountingStateData) + throws ServiceException; diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/rpc/AccountingManagerServiceAsync.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/rpc/AccountingManagerServiceAsync.java index b68b3e9..eac55bc 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/rpc/AccountingManagerServiceAsync.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/rpc/AccountingManagerServiceAsync.java @@ -5,6 +5,7 @@ package org.gcube.portlets.admin.accountingmanager.client.rpc; import java.util.ArrayList; +import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData; import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingType; import org.gcube.portlets.admin.accountingmanager.shared.data.FilterKey; import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue; @@ -12,6 +13,7 @@ import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesReques import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse; import org.gcube.portlets.admin.accountingmanager.shared.session.UserInfo; +import org.gcube.portlets.admin.accountingmanager.shared.workspace.ItemDescription; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -61,5 +63,21 @@ public interface AccountingManagerServiceAsync { */ void getFilterValues(FilterValuesRequest filterValuesRequest, AsyncCallback> callback); + + /** + * + * @param itemDescription item description + * @param callback + */ + void getPublicLink(ItemDescription itemDescription, + AsyncCallback callback); + + /** + * + * @param accountingStateData + * @param callback + */ + void saveCSVOnWorkspace(AccountingStateData accountingStateData, + AsyncCallback callback); } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/AccountingManagerServiceImpl.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/AccountingManagerServiceImpl.java index f08a8f7..ce833c7 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/AccountingManagerServiceImpl.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/AccountingManagerServiceImpl.java @@ -7,9 +7,12 @@ import javax.servlet.http.HttpSession; import org.gcube.application.framework.core.session.ASLSession; import org.gcube.portlets.admin.accountingmanager.client.rpc.AccountingManagerService; +import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData; import org.gcube.portlets.admin.accountingmanager.server.amservice.AccountingCaller; import org.gcube.portlets.admin.accountingmanager.server.amservice.AccountingCallerInterface; import org.gcube.portlets.admin.accountingmanager.server.amservice.AccountingCallerTester; +import org.gcube.portlets.admin.accountingmanager.server.csv.CSVManager; +import org.gcube.portlets.admin.accountingmanager.server.storage.StorageUtil; import org.gcube.portlets.admin.accountingmanager.shared.Constants; import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingType; import org.gcube.portlets.admin.accountingmanager.shared.data.FilterKey; @@ -17,8 +20,9 @@ import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue; import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesRequest; import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; import org.gcube.portlets.admin.accountingmanager.shared.session.UserInfo; +import org.gcube.portlets.admin.accountingmanager.shared.workspace.ItemDescription; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,7 +62,7 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet * {@inheritDoc} */ @Override - public UserInfo hello() throws AccountingManagerServiceException { + public UserInfo hello() throws ServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); ASLSession aslSession = SessionUtil.getASLSession(session); @@ -68,13 +72,13 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet aslSession.getUserEmailAddress(), aslSession.getUserFullName()); return userInfo; - } catch (AccountingManagerServiceException e) { + } catch (ServiceException e) { e.printStackTrace(); throw e; } catch (Throwable e) { e.printStackTrace(); logger.error("Hello(): " + e.getLocalizedMessage(), e); - throw new AccountingManagerServiceException(e.getLocalizedMessage()); + throw new ServiceException(e.getLocalizedMessage()); } } @@ -85,29 +89,28 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet */ @Override public SeriesResponse getSeries(AccountingType accountingType, - SeriesRequest seriesRequest) - throws AccountingManagerServiceException { + SeriesRequest seriesRequest) throws ServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); SessionUtil.getASLSession(session); AccountingCallerInterface accountingCaller; - if(Constants.DEBUG_MODE){ - accountingCaller= new AccountingCallerTester(); + if (Constants.DEBUG_MODE) { + accountingCaller = new AccountingCallerTester(); } else { - accountingCaller= new AccountingCaller(); + accountingCaller = new AccountingCaller(); } SeriesResponse seriesResponse = accountingCaller.getSeries( accountingType, seriesRequest); return seriesResponse; - } catch (AccountingManagerServiceException e) { + } catch (ServiceException e) { e.printStackTrace(); throw e; } catch (Throwable e) { e.printStackTrace(); logger.error("getSeries(): " + e.getLocalizedMessage(), e); - throw new AccountingManagerServiceException(e.getLocalizedMessage()); + throw new ServiceException(e.getLocalizedMessage()); } } @@ -118,27 +121,28 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet */ @Override public ArrayList getFilterKeys(AccountingType accountingType) - throws AccountingManagerServiceException { + throws ServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); SessionUtil.getASLSession(session); AccountingCallerInterface accountingCaller; - if(Constants.DEBUG_MODE){ - accountingCaller= new AccountingCallerTester(); + if (Constants.DEBUG_MODE) { + accountingCaller = new AccountingCallerTester(); } else { - accountingCaller= new AccountingCaller(); + accountingCaller = new AccountingCaller(); } - ArrayList filterKeys = accountingCaller.getFilterKeys(accountingType); - + ArrayList filterKeys = accountingCaller + .getFilterKeys(accountingType); + return filterKeys; - - } catch (AccountingManagerServiceException e) { + + } catch (ServiceException e) { e.printStackTrace(); throw e; } catch (Throwable e) { e.printStackTrace(); logger.error("getFilterKeys(): " + e.getLocalizedMessage(), e); - throw new AccountingManagerServiceException(e.getLocalizedMessage()); + throw new ServiceException(e.getLocalizedMessage()); } } @@ -149,31 +153,74 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet */ @Override public ArrayList getFilterValues( - FilterValuesRequest filterValuesRequest) - throws AccountingManagerServiceException { + FilterValuesRequest filterValuesRequest) throws ServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); SessionUtil.getASLSession(session); AccountingCallerInterface accountingCaller; - if(Constants.DEBUG_MODE){ - accountingCaller= new AccountingCallerTester(); + if (Constants.DEBUG_MODE) { + accountingCaller = new AccountingCallerTester(); } else { - accountingCaller= new AccountingCaller(); + accountingCaller = new AccountingCaller(); } - ArrayList filterValues = accountingCaller.getFilterValues(filterValuesRequest); - + ArrayList filterValues = accountingCaller + .getFilterValues(filterValuesRequest); + return filterValues; - - } catch (AccountingManagerServiceException e) { + + } catch (ServiceException e) { e.printStackTrace(); throw e; } catch (Throwable e) { e.printStackTrace(); logger.error("getFilterValues(): " + e.getLocalizedMessage(), e); - throw new AccountingManagerServiceException(e.getLocalizedMessage()); + throw new ServiceException(e.getLocalizedMessage()); } } + + @Override + public ItemDescription saveCSVOnWorkspace(AccountingStateData accountingStateData) + throws ServiceException { + try { + HttpSession session = this.getThreadLocalRequest().getSession(); + ASLSession aslSession = SessionUtil.getASLSession(session); + logger.debug("SaveDataOnWorkspace(): " + accountingStateData); + CSVManager csvManager=new CSVManager(aslSession.getUsername()); + ItemDescription itemDescription=csvManager.saveOnWorkspace(accountingStateData); + return itemDescription; + } catch (ServiceException e) { + e.printStackTrace(); + throw e; + } catch (Throwable e) { + logger.error("SaveDataOnWorkspace(): " + e.getLocalizedMessage(), e); + e.printStackTrace(); + throw new ServiceException(e.getLocalizedMessage(), e); + } + } + + + + @Override + public String getPublicLink(ItemDescription itemDescription) + throws ServiceException { + try { + HttpSession session = this.getThreadLocalRequest().getSession(); + ASLSession aslSession = SessionUtil.getASLSession(session); + logger.debug("GetPublicLink(): " + itemDescription); + String link = StorageUtil.getPublicLink(aslSession.getUsername(), + itemDescription.getId()); + + return link; + } catch (ServiceException e) { + e.printStackTrace(); + throw e; + } catch (Throwable e) { + logger.error("getPublicLink(): " + e.getLocalizedMessage(), e); + e.printStackTrace(); + throw new ServiceException(e.getLocalizedMessage(), e); + } + } } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/SessionUtil.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/SessionUtil.java index 6f3a58a..5eae2a6 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/SessionUtil.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/SessionUtil.java @@ -14,8 +14,8 @@ import org.gcube.application.framework.core.session.ASLSession; import org.gcube.application.framework.core.session.SessionManager; import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; import org.gcube.portlets.admin.accountingmanager.shared.Constants; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerSessionExpiredException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.SessionExpiredException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,7 +30,7 @@ public class SessionUtil { private static Logger logger = LoggerFactory.getLogger(SessionUtil.class); public static ASLSession getASLSession(HttpSession httpSession) - throws AccountingManagerServiceException { + throws ServiceException { String username = (String) httpSession .getAttribute(ScopeHelper.USERNAME_ATTRIBUTE); ASLSession aslSession; @@ -49,7 +49,7 @@ public class SessionUtil { aslSession.setScope(scope); } else { logger.info("No user found in session"); - throw new AccountingManagerSessionExpiredException("Session Expired!"); + throw new SessionExpiredException("Session Expired!"); } } else { diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/AccountingCaller.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/AccountingCaller.java index 5df335a..dd118c6 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/AccountingCaller.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/AccountingCaller.java @@ -22,7 +22,7 @@ import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue; import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesRequest; import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,14 +40,14 @@ public class AccountingCaller implements AccountingCallerInterface { } public ArrayList getFilterKeys(AccountingType accountingType) - throws AccountingManagerServiceException { + throws ServiceException { AccountingCommandGetFilterKeys accountingCommand=new AccountingCommandGetFilterKeys(accountingType); return accountingCommand.execute(); } public ArrayList getFilterValues( FilterValuesRequest filterValuesRequest) - throws AccountingManagerServiceException { + throws ServiceException { AccountingCommandGetFilterValues accountingCommand=new AccountingCommandGetFilterValues(filterValuesRequest); return accountingCommand.execute(); @@ -55,7 +55,7 @@ public class AccountingCaller implements AccountingCallerInterface { public SeriesResponse getSeries(AccountingType accountingType, SeriesRequest seriesRequest) - throws AccountingManagerServiceException { + throws ServiceException { try { logger.debug("getSeries(): [AccountingType=" + accountingType + " , seriesRequest=" + seriesRequest + "]"); @@ -71,7 +71,7 @@ public class AccountingCaller implements AccountingCallerInterface { logger.debug("Query: " + query); if (query == null || query.getChartType() == null) { - throw new AccountingManagerServiceException( + throw new ServiceException( "Error in invocation: Operation not supported"); } @@ -85,7 +85,7 @@ public class AccountingCaller implements AccountingCallerInterface { AccountingCommandTop accountingCommandTop=new AccountingCommandTop(accountingQueryTop,accountingType); return accountingCommandTop.execute(); default: - throw new AccountingManagerServiceException( + throw new ServiceException( "Error in invocation: Operation not supported"); } @@ -93,7 +93,7 @@ public class AccountingCaller implements AccountingCallerInterface { } catch (Throwable e) { logger.error("Error in GetSeries(): " + e.getLocalizedMessage()); e.printStackTrace(); - throw new AccountingManagerServiceException("No data available!"); + throw new ServiceException("No data available!"); } } @@ -101,9 +101,9 @@ public class AccountingCaller implements AccountingCallerInterface { private AccountingQueryBuilder getAccountQueryBuilder( AccountingType accountingType, SeriesRequest seriesRequest) - throws AccountingManagerServiceException { + throws ServiceException { if (accountingType == null) { - throw new AccountingManagerServiceException( + throw new ServiceException( "Error accounting type is null"); } @@ -124,7 +124,7 @@ public class AccountingCaller implements AccountingCallerInterface { case TASK: return new AccountingQuery4Task(seriesRequest); default: - throw new AccountingManagerServiceException( + throw new ServiceException( "Error request type is unknow!"); } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/AccountingCallerInterface.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/AccountingCallerInterface.java index d676681..a12f5f1 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/AccountingCallerInterface.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/AccountingCallerInterface.java @@ -8,7 +8,7 @@ import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue; import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesRequest; import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; /** * @@ -19,14 +19,14 @@ import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingMan public interface AccountingCallerInterface { public ArrayList getFilterKeys(AccountingType accountingType) - throws AccountingManagerServiceException; + throws ServiceException; public ArrayList getFilterValues( FilterValuesRequest filterValuesRequest) - throws AccountingManagerServiceException; + throws ServiceException; public SeriesResponse getSeries(AccountingType accountingType, SeriesRequest seriesRequest) - throws AccountingManagerServiceException; + throws ServiceException; } \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/AccountingCallerTester.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/AccountingCallerTester.java index 23a1e59..f9f0e9e 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/AccountingCallerTester.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/AccountingCallerTester.java @@ -30,7 +30,7 @@ import org.gcube.portlets.admin.accountingmanager.shared.data.response.storage.S import org.gcube.portlets.admin.accountingmanager.shared.data.response.storage.SeriesStorageDataTop; import org.gcube.portlets.admin.accountingmanager.shared.data.response.storage.SeriesStorageDefinition; import org.gcube.portlets.admin.accountingmanager.shared.data.response.storage.SeriesStorageTop; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,7 +49,7 @@ public class AccountingCallerTester implements AccountingCallerInterface { } public ArrayList getFilterKeys(AccountingType accountingType) - throws AccountingManagerServiceException { + throws ServiceException { try { logger.debug("getFilterKeys(): [AccountingType=" + accountingType + "]"); @@ -68,14 +68,14 @@ public class AccountingCallerTester implements AccountingCallerInterface { } catch (Throwable e) { logger.error("Error in getFilterKeys(): " + e.getLocalizedMessage()); e.printStackTrace(); - throw new AccountingManagerServiceException("No keys available!"); + throw new ServiceException("No keys available!"); } } public ArrayList getFilterValues( FilterValuesRequest filterValuesRequest) - throws AccountingManagerServiceException { + throws ServiceException { try { logger.debug("getFilterValue(): [FilterValueRequest=" + filterValuesRequest + "]"); @@ -115,14 +115,14 @@ public class AccountingCallerTester implements AccountingCallerInterface { logger.error("Error in getFilterValues(): " + e.getLocalizedMessage()); e.printStackTrace(); - throw new AccountingManagerServiceException("No values available!"); + throw new ServiceException("No values available!"); } } public SeriesResponse getSeries(AccountingType accountingType, SeriesRequest seriesRequest) - throws AccountingManagerServiceException { + throws ServiceException { try { logger.debug("getSeries(): [AccountingType=" + accountingType + " , seriesRequest=" + seriesRequest + "]"); @@ -268,7 +268,7 @@ public class AccountingCallerTester implements AccountingCallerInterface { } if (seriesResponse == null) { - throw new AccountingManagerServiceException( + throw new ServiceException( "Error creating series response!"); } logger.debug("SeriesResponse Created: " + seriesResponse); @@ -276,7 +276,7 @@ public class AccountingCallerTester implements AccountingCallerInterface { } catch (Throwable e) { logger.error("Error in GetSeries(): " + e.getLocalizedMessage()); e.printStackTrace(); - throw new AccountingManagerServiceException("No data available!"); + throw new ServiceException("No data available!"); } } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommand.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommand.java index 5e17dd3..4ae3094 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommand.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommand.java @@ -1,6 +1,6 @@ package org.gcube.portlets.admin.accountingmanager.server.amservice.command; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; /** @@ -11,6 +11,6 @@ import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingMan */ public interface AccountingCommand { - T execute() throws AccountingManagerServiceException; + T execute() throws ServiceException; } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandBasic.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandBasic.java index 552b84c..2313920 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandBasic.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandBasic.java @@ -18,7 +18,7 @@ import org.gcube.portlets.admin.accountingmanager.server.amservice.response.Seri import org.gcube.portlets.admin.accountingmanager.server.amservice.response.SeriesResponseDirector; import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingType; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,7 +41,7 @@ public class AccountingCommandBasic implements AccountingCommand @Override - public SeriesResponse execute() throws AccountingManagerServiceException { + public SeriesResponse execute() throws ServiceException { try { AccountingPersistenceQuery apq = AccountingPersistenceQueryFactory.getInstance(); @@ -51,7 +51,7 @@ public class AccountingCommandBasic implements AccountingCommand accountingQueryBasic.getFilters(), true); if (sm == null || sm.values()==null) { - throw new AccountingManagerServiceException( + throw new ServiceException( "Error retrieving info: sorted map is null!"); } @@ -70,7 +70,7 @@ public class AccountingCommandBasic implements AccountingCommand .getSeriesResponse(); if (seriesResponse == null) { - throw new AccountingManagerServiceException( + throw new ServiceException( "Error creating series response!"); } logger.debug("SeriesResponse Created: " + seriesResponse); @@ -78,16 +78,16 @@ public class AccountingCommandBasic implements AccountingCommand } catch (Throwable e) { logger.error("Error in AccountingCommandBasic(): " + e.getLocalizedMessage()); e.printStackTrace(); - throw new AccountingManagerServiceException("No data available!"); + throw new ServiceException("No data available!"); } } private SeriesResponseBuilder getSeriesResponseBuilder( AccountingType accountingType, List infos) - throws AccountingManagerServiceException { + throws ServiceException { if (accountingType == null) { - throw new AccountingManagerServiceException( + throw new ServiceException( "Error accounting type is null"); } @@ -103,7 +103,7 @@ public class AccountingCommandBasic implements AccountingCommand case TASK: return new SeriesResponse4TaskBasic(infos); default: - throw new AccountingManagerServiceException( + throw new ServiceException( "Error request type is unknow!"); } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandGetFilterKeys.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandGetFilterKeys.java index 8b02364..07b74b3 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandGetFilterKeys.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandGetFilterKeys.java @@ -9,7 +9,7 @@ import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord; import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord; import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingType; import org.gcube.portlets.admin.accountingmanager.shared.data.FilterKey; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,7 +30,7 @@ public class AccountingCommandGetFilterKeys implements AccountingCommand execute() throws AccountingManagerServiceException { + public ArrayList execute() throws ServiceException { try { logger.debug("getFilterKeys(): [AccountingType=" + accountingType + "]"); @@ -70,7 +70,7 @@ public class AccountingCommandGetFilterKeys implements AccountingCommand execute() - throws AccountingManagerServiceException { + throws ServiceException { try { logger.debug("getFilterValue(): [FilterValueRequest=" + filterValuesRequest + "]"); @@ -70,7 +70,7 @@ public class AccountingCommandGetFilterValues implements .getStartDate())); } catch (ParseException e) { e.printStackTrace(); - throw new AccountingManagerServiceException("Start Date not valid!"); + throw new ServiceException("Start Date not valid!"); } Calendar endCalendar = GregorianCalendar @@ -80,7 +80,7 @@ public class AccountingCommandGetFilterValues implements .getEndDate())); } catch (ParseException e) { e.printStackTrace(); - throw new AccountingManagerServiceException("End Date not valid!"); + throw new ServiceException("End Date not valid!"); } endCalendar.set(GregorianCalendar.HOUR_OF_DAY, 23); @@ -136,7 +136,7 @@ public class AccountingCommandGetFilterValues implements logger.error("Error in AccountingCommandGetFilterValues(): " + e.getLocalizedMessage()); e.printStackTrace(); - throw new AccountingManagerServiceException("No values available!"); + throw new ServiceException("No values available!"); } } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandTop.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandTop.java index a318291..2d357f7 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandTop.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandTop.java @@ -17,7 +17,7 @@ import org.gcube.portlets.admin.accountingmanager.server.amservice.response.Seri import org.gcube.portlets.admin.accountingmanager.server.amservice.response.SeriesResponseDirector; import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingType; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,7 +42,7 @@ public class AccountingCommandTop implements AccountingCommand { } @Override - public SeriesResponse execute() throws AccountingManagerServiceException { + public SeriesResponse execute() throws ServiceException { try { AccountingPersistenceQuery apq = AccountingPersistenceQueryFactory .getInstance(); @@ -58,7 +58,7 @@ public class AccountingCommandTop implements AccountingCommand { accountingQueryTop.getTopNumber()); if (topSM == null) { - throw new AccountingManagerServiceException( + throw new ServiceException( "Error retrieving info for top: sorted map is null!"); } @@ -76,7 +76,7 @@ public class AccountingCommandTop implements AccountingCommand { .getSeriesResponse(); if (seriesResponse == null) { - throw new AccountingManagerServiceException( + throw new ServiceException( "Error creating series response!"); } logger.debug("SeriesResponse Created: " + seriesResponse); @@ -86,16 +86,16 @@ public class AccountingCommandTop implements AccountingCommand { logger.error("Error in AccountingCommandTop(): " + e.getLocalizedMessage()); e.printStackTrace(); - throw new AccountingManagerServiceException("No data available!"); + throw new ServiceException("No data available!"); } } private SeriesResponseBuilder getSeriesResponseBuilder( AccountingType accountingType, SortedMap> topSM) - throws AccountingManagerServiceException { + throws ServiceException { if (accountingType == null) { - throw new AccountingManagerServiceException( + throw new ServiceException( "Error accounting type is null"); } @@ -111,7 +111,7 @@ public class AccountingCommandTop implements AccountingCommand { case TASK: return new SeriesResponse4TaskTop(topSM); default: - throw new AccountingManagerServiceException( + throw new ServiceException( "Error request type is unknow!"); } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQuery4Job.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQuery4Job.java index 8283174..101cacc 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQuery4Job.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQuery4Job.java @@ -13,7 +13,7 @@ import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingFilter; import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingFilterBasic; import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingFilterTop; import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,7 +34,7 @@ public class AccountingQuery4Job extends AccountingQueryBuilder { } @Override - public void buildOpEx() throws AccountingManagerServiceException { + public void buildOpEx() throws ServiceException { Calendar startCalendar = GregorianCalendar .getInstance(TemporalConstraint.DEFAULT_TIME_ZONE); @@ -43,7 +43,7 @@ public class AccountingQuery4Job extends AccountingQueryBuilder { .getStartDate())); } catch (ParseException e) { e.printStackTrace(); - throw new AccountingManagerServiceException("Start Date not valid!"); + throw new ServiceException("Start Date not valid!"); } Calendar endCalendar = GregorianCalendar @@ -53,7 +53,7 @@ public class AccountingQuery4Job extends AccountingQueryBuilder { .getEndDate())); } catch (ParseException e) { e.printStackTrace(); - throw new AccountingManagerServiceException("End Date not valid!"); + throw new ServiceException("End Date not valid!"); } endCalendar.set(GregorianCalendar.HOUR_OF_DAY, 23); @@ -110,14 +110,14 @@ public class AccountingQuery4Job extends AccountingQueryBuilder { temporalConstraint, filters); } else { logger.error("Invalid Request: " + seriesRequest); - throw new AccountingManagerServiceException( + throw new ServiceException( "Invalid Request!"); } } } else { logger.error("Invalid Request: " + seriesRequest); - throw new AccountingManagerServiceException("Invalid Request!"); + throw new ServiceException("Invalid Request!"); } accountingQuerySpec.setOp(invocation); diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQuery4Portlet.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQuery4Portlet.java index 0f9a1c5..8976bba 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQuery4Portlet.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQuery4Portlet.java @@ -13,7 +13,7 @@ import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingFilter; import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingFilterBasic; import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingFilterTop; import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,7 +34,7 @@ public class AccountingQuery4Portlet extends AccountingQueryBuilder { } @Override - public void buildOpEx() throws AccountingManagerServiceException { + public void buildOpEx() throws ServiceException { Calendar startCalendar = GregorianCalendar .getInstance(TemporalConstraint.DEFAULT_TIME_ZONE); try { @@ -42,7 +42,7 @@ public class AccountingQuery4Portlet extends AccountingQueryBuilder { .getStartDate())); } catch (ParseException e) { e.printStackTrace(); - throw new AccountingManagerServiceException("Start Date not valid!"); + throw new ServiceException("Start Date not valid!"); } Calendar endCalendar = GregorianCalendar @@ -52,7 +52,7 @@ public class AccountingQuery4Portlet extends AccountingQueryBuilder { .getEndDate())); } catch (ParseException e) { e.printStackTrace(); - throw new AccountingManagerServiceException("End Date not valid!"); + throw new ServiceException("End Date not valid!"); } endCalendar.set(GregorianCalendar.HOUR_OF_DAY, 23); @@ -109,14 +109,14 @@ public class AccountingQuery4Portlet extends AccountingQueryBuilder { temporalConstraint, filters); } else { logger.error("Invalid Request: " + seriesRequest); - throw new AccountingManagerServiceException( + throw new ServiceException( "Invalid Request!"); } } } else { logger.error("Invalid Request: " + seriesRequest); - throw new AccountingManagerServiceException("Invalid Request!"); + throw new ServiceException("Invalid Request!"); } accountingQuerySpec.setOp(invocation); diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQuery4Service.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQuery4Service.java index feb9fe3..506ed21 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQuery4Service.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQuery4Service.java @@ -13,7 +13,7 @@ import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingFilter; import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingFilterBasic; import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingFilterTop; import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,7 +34,7 @@ public class AccountingQuery4Service extends AccountingQueryBuilder { } @Override - public void buildOpEx() throws AccountingManagerServiceException { + public void buildOpEx() throws ServiceException { Calendar startCalendar = GregorianCalendar .getInstance(TemporalConstraint.DEFAULT_TIME_ZONE); @@ -43,7 +43,7 @@ public class AccountingQuery4Service extends AccountingQueryBuilder { .getStartDate())); } catch (ParseException e) { e.printStackTrace(); - throw new AccountingManagerServiceException("Start Date not valid!"); + throw new ServiceException("Start Date not valid!"); } Calendar endCalendar = GregorianCalendar @@ -53,7 +53,7 @@ public class AccountingQuery4Service extends AccountingQueryBuilder { .getEndDate())); } catch (ParseException e) { e.printStackTrace(); - throw new AccountingManagerServiceException("End Date not valid!"); + throw new ServiceException("End Date not valid!"); } endCalendar.set(GregorianCalendar.HOUR_OF_DAY, 23); @@ -110,14 +110,14 @@ public class AccountingQuery4Service extends AccountingQueryBuilder { temporalConstraint, filters); } else { logger.error("Invalid Request: " + seriesRequest); - throw new AccountingManagerServiceException( + throw new ServiceException( "Invalid Request!"); } } } else { logger.error("Invalid Request: " + seriesRequest); - throw new AccountingManagerServiceException("Invalid Request!"); + throw new ServiceException("Invalid Request!"); } accountingQuerySpec.setOp(invocation); diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQuery4Storage.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQuery4Storage.java index 0321f0f..7095395 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQuery4Storage.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQuery4Storage.java @@ -13,7 +13,7 @@ import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingFilter; import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingFilterBasic; import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingFilterTop; import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,7 +34,7 @@ public class AccountingQuery4Storage extends AccountingQueryBuilder { } @Override - public void buildOpEx() throws AccountingManagerServiceException { + public void buildOpEx() throws ServiceException { Calendar startCalendar = GregorianCalendar .getInstance(TemporalConstraint.DEFAULT_TIME_ZONE); @@ -43,7 +43,7 @@ public class AccountingQuery4Storage extends AccountingQueryBuilder { .getStartDate())); } catch (ParseException e) { e.printStackTrace(); - throw new AccountingManagerServiceException("Start Date not valid!"); + throw new ServiceException("Start Date not valid!"); } Calendar endCalendar = GregorianCalendar @@ -53,7 +53,7 @@ public class AccountingQuery4Storage extends AccountingQueryBuilder { .getEndDate())); } catch (ParseException e) { e.printStackTrace(); - throw new AccountingManagerServiceException("End Date not valid!"); + throw new ServiceException("End Date not valid!"); } endCalendar.set(GregorianCalendar.HOUR_OF_DAY, 23); @@ -110,14 +110,14 @@ public class AccountingQuery4Storage extends AccountingQueryBuilder { temporalConstraint, filters); } else { logger.error("Invalid Request: " + seriesRequest); - throw new AccountingManagerServiceException( + throw new ServiceException( "Invalid Request!"); } } } else { logger.error("Invalid Request: " + seriesRequest); - throw new AccountingManagerServiceException("Invalid Request!"); + throw new ServiceException("Invalid Request!"); } accountingQuerySpec.setOp(invocation); diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQuery4Task.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQuery4Task.java index a67cb10..cbd46ef 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQuery4Task.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQuery4Task.java @@ -13,7 +13,7 @@ import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingFilter; import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingFilterBasic; import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingFilterTop; import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,7 +34,7 @@ public class AccountingQuery4Task extends AccountingQueryBuilder { } @Override - public void buildOpEx() throws AccountingManagerServiceException { + public void buildOpEx() throws ServiceException { Calendar startCalendar = GregorianCalendar .getInstance(TemporalConstraint.DEFAULT_TIME_ZONE); try { @@ -42,7 +42,7 @@ public class AccountingQuery4Task extends AccountingQueryBuilder { .getStartDate())); } catch (ParseException e) { e.printStackTrace(); - throw new AccountingManagerServiceException("Start Date not valid!"); + throw new ServiceException("Start Date not valid!"); } Calendar endCalendar = GregorianCalendar @@ -52,7 +52,7 @@ public class AccountingQuery4Task extends AccountingQueryBuilder { .getEndDate())); } catch (ParseException e) { e.printStackTrace(); - throw new AccountingManagerServiceException("End Date not valid!"); + throw new ServiceException("End Date not valid!"); } endCalendar.set(GregorianCalendar.HOUR_OF_DAY, 23); @@ -109,14 +109,14 @@ public class AccountingQuery4Task extends AccountingQueryBuilder { temporalConstraint, filters); } else { logger.error("Invalid Request: " + seriesRequest); - throw new AccountingManagerServiceException( + throw new ServiceException( "Invalid Request!"); } } } else { logger.error("Invalid Request: " + seriesRequest); - throw new AccountingManagerServiceException("Invalid Request!"); + throw new ServiceException("Invalid Request!"); } accountingQuerySpec.setOp(invocation); diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQueryBuilder.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQueryBuilder.java index aee03f2..3ffc61d 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQueryBuilder.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQueryBuilder.java @@ -2,7 +2,7 @@ package org.gcube.portlets.admin.accountingmanager.server.amservice.query; import java.text.SimpleDateFormat; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; /** * Abstract class for build Accounting Query @@ -23,7 +23,7 @@ public abstract class AccountingQueryBuilder { } - public abstract void buildOpEx() throws AccountingManagerServiceException; + public abstract void buildOpEx() throws ServiceException; } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQueryDirector.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQueryDirector.java index 220b2a1..cad4925 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQueryDirector.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/query/AccountingQueryDirector.java @@ -2,7 +2,7 @@ package org.gcube.portlets.admin.accountingmanager.server.amservice.query; import java.util.ArrayList; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; /** @@ -30,7 +30,7 @@ public class AccountingQueryDirector { } - public void constructAccountingQuery() throws AccountingManagerServiceException { + public void constructAccountingQuery() throws ServiceException { accountingQueryBuilder.createSpec(); accountingQueryBuilder.buildOpEx(); diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4JobBasic.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4JobBasic.java index b2f9592..74f668d 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4JobBasic.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4JobBasic.java @@ -8,7 +8,7 @@ import org.gcube.accounting.datamodel.aggregation.AggregatedJobUsageRecord; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesJob; import org.gcube.portlets.admin.accountingmanager.shared.data.response.job.SeriesJobBasic; import org.gcube.portlets.admin.accountingmanager.shared.data.response.job.SeriesJobData; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,11 +30,11 @@ public class SeriesResponse4JobBasic extends SeriesResponseBuilder { } @Override - public void buildSeriesResponse() throws AccountingManagerServiceException { + public void buildSeriesResponse() throws ServiceException { try { if (infos.size() <= 0) { logger.error("Error creating series for job accounting: No data available!"); - throw new AccountingManagerServiceException( + throw new ServiceException( "No data available!"); } @@ -65,7 +65,7 @@ public class SeriesResponse4JobBasic extends SeriesResponseBuilder { logger.error("Error creating series for job accounting basic chart: " + e.getLocalizedMessage()); e.printStackTrace(); - throw new AccountingManagerServiceException( + throw new ServiceException( "Error creating series for job accounting basic chart: " + e.getLocalizedMessage()); } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4JobTop.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4JobTop.java index 0db782f..e19d488 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4JobTop.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4JobTop.java @@ -12,7 +12,7 @@ import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesJob import org.gcube.portlets.admin.accountingmanager.shared.data.response.job.SeriesJobData; import org.gcube.portlets.admin.accountingmanager.shared.data.response.job.SeriesJobDataTop; import org.gcube.portlets.admin.accountingmanager.shared.data.response.job.SeriesJobTop; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,11 +35,11 @@ public class SeriesResponse4JobTop extends SeriesResponseBuilder { } @Override - public void buildSeriesResponse() throws AccountingManagerServiceException { + public void buildSeriesResponse() throws ServiceException { try { if (topSM == null || topSM.isEmpty()) { logger.error("Error creating series for job accounting: No data available!"); - throw new AccountingManagerServiceException( + throw new ServiceException( "No data available!"); } @@ -80,7 +80,7 @@ public class SeriesResponse4JobTop extends SeriesResponseBuilder { logger.error("Error creating series for job accounting top chart: " + e.getLocalizedMessage()); e.printStackTrace(); - throw new AccountingManagerServiceException( + throw new ServiceException( "Error creating series for job accounting top chart: " + e.getLocalizedMessage()); } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4PortletBasic.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4PortletBasic.java index 62f5761..b747d6f 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4PortletBasic.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4PortletBasic.java @@ -4,7 +4,7 @@ import java.util.List; import org.gcube.accounting.analytics.Info; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -26,10 +26,10 @@ public class SeriesResponse4PortletBasic extends SeriesResponseBuilder { } @Override - public void buildSeriesResponse() throws AccountingManagerServiceException { + public void buildSeriesResponse() throws ServiceException { if(infos.size()<=0){ logger.error("Error creating series for portlet accounting: No data available!"); - throw new AccountingManagerServiceException("No data available!"); + throw new ServiceException("No data available!"); } //SeriesPortletBasic seriesPortletBasic=new SeriesPortletBasic(series); diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4PortletTop.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4PortletTop.java index 7c03469..028e7be 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4PortletTop.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4PortletTop.java @@ -12,7 +12,7 @@ import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesPor import org.gcube.portlets.admin.accountingmanager.shared.data.response.portlet.SeriesPortletData; import org.gcube.portlets.admin.accountingmanager.shared.data.response.portlet.SeriesPortletDataTop; import org.gcube.portlets.admin.accountingmanager.shared.data.response.portlet.SeriesPortletTop; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,11 +35,11 @@ public class SeriesResponse4PortletTop extends SeriesResponseBuilder { } @Override - public void buildSeriesResponse() throws AccountingManagerServiceException { + public void buildSeriesResponse() throws ServiceException { try { if (topSM == null || topSM.isEmpty()) { logger.error("Error creating series for portlet accounting: No data available!"); - throw new AccountingManagerServiceException( + throw new ServiceException( "No data available!"); } @@ -79,7 +79,7 @@ public class SeriesResponse4PortletTop extends SeriesResponseBuilder { logger.error("Error creating series for portlet accounting top chart: " + e.getLocalizedMessage()); e.printStackTrace(); - throw new AccountingManagerServiceException( + throw new ServiceException( "Error creating series for portlet accounting top chart: " + e.getLocalizedMessage()); } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4ServiceBasic.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4ServiceBasic.java index 64cd5ef..0821e47 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4ServiceBasic.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4ServiceBasic.java @@ -8,7 +8,7 @@ import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesService; import org.gcube.portlets.admin.accountingmanager.shared.data.response.service.SeriesServiceBasic; import org.gcube.portlets.admin.accountingmanager.shared.data.response.service.SeriesServiceData; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,11 +30,11 @@ public class SeriesResponse4ServiceBasic extends SeriesResponseBuilder { } @Override - public void buildSeriesResponse() throws AccountingManagerServiceException { + public void buildSeriesResponse() throws ServiceException { try { if(infos.size()<=0){ logger.error("Error creating series for service accounting: No data available!"); - throw new AccountingManagerServiceException("No data available!"); + throw new ServiceException("No data available!"); } ArrayList series=new ArrayList(); @@ -58,7 +58,7 @@ public class SeriesResponse4ServiceBasic extends SeriesResponseBuilder { } catch (Throwable e) { logger.error("Error creating series for service accounting chart basic: "+e.getLocalizedMessage()); e.printStackTrace(); - throw new AccountingManagerServiceException("Error creating series for service accounting chart basic: "+e.getLocalizedMessage()); + throw new ServiceException("Error creating series for service accounting chart basic: "+e.getLocalizedMessage()); } } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4ServiceTop.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4ServiceTop.java index 6fd49f3..b88b053 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4ServiceTop.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4ServiceTop.java @@ -12,7 +12,7 @@ import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesSer import org.gcube.portlets.admin.accountingmanager.shared.data.response.service.SeriesServiceData; import org.gcube.portlets.admin.accountingmanager.shared.data.response.service.SeriesServiceDataTop; import org.gcube.portlets.admin.accountingmanager.shared.data.response.service.SeriesServiceTop; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,11 +35,11 @@ public class SeriesResponse4ServiceTop extends SeriesResponseBuilder { } @Override - public void buildSeriesResponse() throws AccountingManagerServiceException { + public void buildSeriesResponse() throws ServiceException { try { if (topSM == null || topSM.isEmpty()) { logger.error("Error creating series for service accounting: No data available!"); - throw new AccountingManagerServiceException( + throw new ServiceException( "No data available!"); } @@ -82,7 +82,7 @@ public class SeriesResponse4ServiceTop extends SeriesResponseBuilder { logger.error("Error creating series for service accounting top chart: " + e.getLocalizedMessage()); e.printStackTrace(); - throw new AccountingManagerServiceException( + throw new ServiceException( "Error creating series for service accounting top chart: " + e.getLocalizedMessage()); } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4StorageBasic.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4StorageBasic.java index 3b452b2..463bd02 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4StorageBasic.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4StorageBasic.java @@ -8,7 +8,7 @@ import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorage; import org.gcube.portlets.admin.accountingmanager.shared.data.response.storage.SeriesStorageBasic; import org.gcube.portlets.admin.accountingmanager.shared.data.response.storage.SeriesStorageData; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,11 +30,11 @@ public class SeriesResponse4StorageBasic extends SeriesResponseBuilder { } @Override - public void buildSeriesResponse() throws AccountingManagerServiceException { + public void buildSeriesResponse() throws ServiceException { try { if(infos.size()<=0){ logger.error("Error creating series for storage accounting: No data available!"); - throw new AccountingManagerServiceException("No data available!"); + throw new ServiceException("No data available!"); } ArrayList series=new ArrayList(); @@ -54,7 +54,7 @@ public class SeriesResponse4StorageBasic extends SeriesResponseBuilder { } catch (Throwable e) { logger.error("Error creating series for storage accounting basic chart: "+e.getLocalizedMessage()); e.printStackTrace(); - throw new AccountingManagerServiceException("Error creating series for storage accounting basic chart: "+e.getLocalizedMessage()); + throw new ServiceException("Error creating series for storage accounting basic chart: "+e.getLocalizedMessage()); } } } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4StorageTop.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4StorageTop.java index 4704eff..2ea8432 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4StorageTop.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4StorageTop.java @@ -12,7 +12,7 @@ import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesSto import org.gcube.portlets.admin.accountingmanager.shared.data.response.storage.SeriesStorageData; import org.gcube.portlets.admin.accountingmanager.shared.data.response.storage.SeriesStorageDataTop; import org.gcube.portlets.admin.accountingmanager.shared.data.response.storage.SeriesStorageTop; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,11 +34,11 @@ public class SeriesResponse4StorageTop extends SeriesResponseBuilder { } @Override - public void buildSeriesResponse() throws AccountingManagerServiceException { + public void buildSeriesResponse() throws ServiceException { try { if(topSM==null||topSM.isEmpty()){ logger.error("Error creating series for storage accounting: No data available!"); - throw new AccountingManagerServiceException("No data available!"); + throw new ServiceException("No data available!"); } @@ -69,7 +69,7 @@ public class SeriesResponse4StorageTop extends SeriesResponseBuilder { } catch (Throwable e) { logger.error("Error creating series for storage accounting top chart: "+e.getLocalizedMessage()); e.printStackTrace(); - throw new AccountingManagerServiceException("Error creating series for storage accounting basic chart: "+e.getLocalizedMessage()); + throw new ServiceException("Error creating series for storage accounting basic chart: "+e.getLocalizedMessage()); } } } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4TaskBasic.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4TaskBasic.java index 385e6bd..a92b374 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4TaskBasic.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4TaskBasic.java @@ -4,7 +4,7 @@ import java.util.List; import org.gcube.accounting.analytics.Info; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -25,10 +25,10 @@ public class SeriesResponse4TaskBasic extends SeriesResponseBuilder { } @Override - public void buildSeriesResponse() throws AccountingManagerServiceException { + public void buildSeriesResponse() throws ServiceException { if(infos.size()<=0){ logger.error("Error creating series for task accounting: No data available!"); - throw new AccountingManagerServiceException("No data available!"); + throw new ServiceException("No data available!"); } //SeriesTaskBasic seriesTaskBasic=new SeriesTaskBasic(series); diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4TaskTop.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4TaskTop.java index 407baed..64bbf10 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4TaskTop.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponse4TaskTop.java @@ -12,7 +12,7 @@ import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesTas import org.gcube.portlets.admin.accountingmanager.shared.data.response.task.SeriesTaskData; import org.gcube.portlets.admin.accountingmanager.shared.data.response.task.SeriesTaskDataTop; import org.gcube.portlets.admin.accountingmanager.shared.data.response.task.SeriesTaskTop; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,11 +34,11 @@ public class SeriesResponse4TaskTop extends SeriesResponseBuilder { } @Override - public void buildSeriesResponse() throws AccountingManagerServiceException { + public void buildSeriesResponse() throws ServiceException { try { if (topSM == null || topSM.isEmpty()) { logger.error("Error creating series for task accounting: No data available!"); - throw new AccountingManagerServiceException( + throw new ServiceException( "No data available!"); } @@ -78,7 +78,7 @@ public class SeriesResponse4TaskTop extends SeriesResponseBuilder { logger.error("Error creating series for portlet accounting top chart: " + e.getLocalizedMessage()); e.printStackTrace(); - throw new AccountingManagerServiceException( + throw new ServiceException( "Error creating series for portlet accounting top chart: " + e.getLocalizedMessage()); } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponseBuilder.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponseBuilder.java index 2950c93..09da463 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponseBuilder.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponseBuilder.java @@ -1,6 +1,6 @@ package org.gcube.portlets.admin.accountingmanager.server.amservice.response; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; /** * Abstract class for build Series Response @@ -20,7 +20,7 @@ public abstract class SeriesResponseBuilder { } - public abstract void buildSeriesResponse() throws AccountingManagerServiceException; + public abstract void buildSeriesResponse() throws ServiceException; } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponseDirector.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponseDirector.java index bc8927c..b0157ad 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponseDirector.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/response/SeriesResponseDirector.java @@ -3,7 +3,7 @@ package org.gcube.portlets.admin.accountingmanager.server.amservice.response; import java.util.ArrayList; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse; -import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; /** @@ -31,7 +31,7 @@ public class SeriesResponseDirector { } - public void constructSeriesResponse() throws AccountingManagerServiceException { + public void constructSeriesResponse() throws ServiceException { seriesResponseBuilder.createSpec(); seriesResponseBuilder.buildSeriesResponse(); diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/CSVManager.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/CSVManager.java new file mode 100644 index 0000000..6314b0f --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/CSVManager.java @@ -0,0 +1,132 @@ +package org.gcube.portlets.admin.accountingmanager.server.csv; + +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardOpenOption; + +import org.apache.commons.csv.CSVFormat; +import org.apache.commons.csv.CSVPrinter; +import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData; +import org.gcube.portlets.admin.accountingmanager.server.csv.file.CSVDataRow; +import org.gcube.portlets.admin.accountingmanager.server.csv.file.CSVModel; +import org.gcube.portlets.admin.accountingmanager.server.csv.file.CSVModel4Storage; +import org.gcube.portlets.admin.accountingmanager.server.csv.file.CSVModelBuilder; +import org.gcube.portlets.admin.accountingmanager.server.csv.file.CSVModelDirector; +import org.gcube.portlets.admin.accountingmanager.server.storage.StorageUtil; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.workspace.ItemDescription; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * CSV Manager + * + * @author Giancarlo Panichi email: g.panichi@isti.cnr.it + * + */ +public class CSVManager { + + private static Logger logger = LoggerFactory.getLogger(CSVManager.class); + private String userName; + + public CSVManager(String userName){ + this.userName=userName; + } + + public ItemDescription saveOnWorkspace(AccountingStateData accountingStateData) throws ServiceException { + try { + if (accountingStateData == null) { + logger.error("AccountingStateData is null"); + throw new ServiceException("AccountingStateData is null!"); + } + + if (accountingStateData.getAccountingType() == null) { + logger.error("Accounting Type is null"); + throw new ServiceException("Accounting Type is null!"); + } + + CSVModelBuilder csvModelBuilder = null; + + switch (accountingStateData.getAccountingType()) { + case SERVICE: + break; + case STORAGE: + csvModelBuilder = new CSVModel4Storage(accountingStateData); + break; + case JOB: + case PORTLET: + case TASK: + default: + logger.error("Accounting Type not supported!"); + throw new ServiceException("Accounting Type not supported!!"); + } + + CSVModelDirector director = new CSVModelDirector(); + director.setCSVModelBuilder(csvModelBuilder); + director.constructCSVModel(); + CSVModel csvModel = director.getCSVModel(); + logger.debug("CSVModel: " + csvModel); + + if (csvModel == null) { + logger.error("CSV model created is null"); + throw new ServiceException("CSVModel created is null!"); + } + + Path tempFile = Files.createTempFile(csvModel.getFileName(), + csvModel.getFileExtension()); + logger.debug("Temp File: " + tempFile.toString()); + + // Create the CSVFormat object + CSVFormat format = CSVFormat.RFC4180.withHeader() + .withDelimiter(','); + + PrintStream printStream = new PrintStream(tempFile.toFile()); + // CSV Write Example using CSVPrinter + CSVPrinter printer = new CSVPrinter(printStream, format); + printer.printRecord(csvModel.getHeader()); + for (CSVDataRow row : csvModel.getRows()) { + printer.printRecord(row.getData()); + } + // close the printer + printer.close(); + printStream.close(); + + String destinationFolderId = StorageUtil + .createAccountingFolderOnWorkspace(userName); + ItemDescription itemDescription=null; + try (InputStream is = Files.newInputStream(tempFile, + StandardOpenOption.READ)) { + itemDescription=StorageUtil.saveOnWorkspace(userName, destinationFolderId, + csvModel.getFileName() + csvModel.getFileExtension(), + csvModel.getFileName(), is); + } + + try { + Files.delete(tempFile); + } catch (IOException e) { + logger.error("Error in deleting temp file: " + + e.getLocalizedMessage()); + e.printStackTrace(); + throw new ServiceException("Error deleting temp file: "+e.getLocalizedMessage(), + e); + } + + return itemDescription; + + } catch (ServiceException e) { + throw e; + } catch (Throwable e) { + logger.error("Error saving data: " + e.getLocalizedMessage()); + e.printStackTrace(); + throw new ServiceException("Error saving data: " + + e.getLocalizedMessage()); + + } + + } + +} diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVDataRow.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVDataRow.java new file mode 100644 index 0000000..68dc2c5 --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVDataRow.java @@ -0,0 +1,40 @@ +package org.gcube.portlets.admin.accountingmanager.server.csv.file; + +import java.io.Serializable; +import java.util.ArrayList; + +/** + * Row of csv + * + * @author Giancarlo Panichi email: g.panichi@isti.cnr.it + * + */ +public class CSVDataRow implements Serializable { + + private static final long serialVersionUID = -707694572028800959L; + private ArrayList data; + + public CSVDataRow() { + super(); + } + + public CSVDataRow(ArrayList data) { + super(); + this.data = data; + } + + public ArrayList getData() { + return data; + } + + public void setData(ArrayList data) { + this.data = data; + } + + @Override + public String toString() { + return "CSVDataRow [data=" + data + "]"; + } + +} diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVModel.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVModel.java new file mode 100644 index 0000000..5e92419 --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVModel.java @@ -0,0 +1,72 @@ +package org.gcube.portlets.admin.accountingmanager.server.csv.file; + +import java.io.Serializable; +import java.util.ArrayList; + +/** + * + * @author giancarlo email: g.panichi@isti.cnr.it + * + */ +public class CSVModel implements Serializable { + + private static final long serialVersionUID = 7127656837246518599L; + private String fileName; + private String fileExtension; + private ArrayList header; + private ArrayList rows; + + public CSVModel() { + super(); + } + + public CSVModel(String fileName, ArrayList header, + ArrayList rows) { + super(); + this.fileName = fileName; + this.fileExtension =".csv"; + this.header = header; + this.rows = rows; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public String getFileExtension() { + return fileExtension; + } + + public void setFileExtension(String fileExtension) { + this.fileExtension = fileExtension; + } + + public ArrayList getHeader() { + return header; + } + + public void setHeader(ArrayList header) { + this.header = header; + } + + public ArrayList getRows() { + return rows; + } + + public void setRows(ArrayList rows) { + this.rows = rows; + } + + @Override + public String toString() { + return "CSVModel [fileName=" + fileName + ", fileExtension=" + + fileExtension + ", header=" + header + ", rows=" + rows + "]"; + } + + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVModel4Service.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVModel4Service.java new file mode 100644 index 0000000..c06a9f5 --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVModel4Service.java @@ -0,0 +1,138 @@ +package org.gcube.portlets.admin.accountingmanager.server.csv.file; + +import java.util.ArrayList; +import java.util.Arrays; + +import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData; +import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue; +import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest; +import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse; +import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesService; +import org.gcube.portlets.admin.accountingmanager.shared.data.response.service.SeriesServiceBasic; +import org.gcube.portlets.admin.accountingmanager.shared.data.response.service.SeriesServiceData; +import org.gcube.portlets.admin.accountingmanager.shared.data.response.service.SeriesServiceDataTop; +import org.gcube.portlets.admin.accountingmanager.shared.data.response.service.SeriesServiceDefinition; +import org.gcube.portlets.admin.accountingmanager.shared.data.response.service.SeriesServiceTop; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * CSV Model 4 Service + * + * @author "Giancarlo Panichi" email: g.panichi@isti.cnr.it + * + */ +public class CSVModel4Service extends CSVModelBuilder { + protected static Logger logger = LoggerFactory + .getLogger(CSVModel4Service.class); + private AccountingStateData accountingStateData; + + public CSVModel4Service(AccountingStateData accountingStateData) { + this.accountingStateData = accountingStateData; + } + + @Override + public void buildOpEx() throws ServiceException { + SeriesRequest seriesRequest = accountingStateData.getSeriesRequest(); + + if (seriesRequest == null) { + logger.error("Error series request is null"); + throw new ServiceException( + "Error series request is null"); + + } + + String startDate = sdfFile.format(seriesRequest.getAccountingPeriod() + .getStartDate()); + String endDate = sdfFile.format(seriesRequest.getAccountingPeriod() + .getEndDate()); + String periodType = seriesRequest.getAccountingPeriod().getPeriod() + .getLabel(); + + SeriesResponse seriesResponse = accountingStateData.getSeriesResponse(); + + if (seriesResponse == null) { + logger.error("Error series response is null"); + throw new ServiceException( + "Error series response is null"); + } + + String fileName = "Untitled"; + ArrayList header; + ArrayList rows = new ArrayList<>(); + if (seriesResponse instanceof SeriesService) { + SeriesService seriesService = (SeriesService) seriesResponse; + SeriesServiceDefinition definition = seriesService + .getSerieServiceDefinition(); + if (definition instanceof SeriesServiceBasic) { + SeriesServiceBasic seriesServiceBasic = (SeriesServiceBasic) definition; + fileName = "Service_" + periodType + "_" + startDate + "_" + + endDate; + header = new ArrayList<>(Arrays.asList(new String[] { "Date", + "Operation Count", "Duration", "Max Invocation", + "Min Invocation" })); + ArrayList listData = seriesServiceBasic + .getSeries(); + for (SeriesServiceData seriesData : listData) { + ArrayList data = new ArrayList<>(); + data.add(sdf.format(seriesData.getDate())); + data.add(String.valueOf(seriesData.getOperationCount())); + data.add(String.valueOf(seriesData.getDuration())); + data.add(String.valueOf(seriesData.getMaxInvocationTime())); + data.add(String.valueOf(seriesData.getMinInvocationTime())); + CSVDataRow csvDataRow = new CSVDataRow(data); + rows.add(csvDataRow); + } + } else { + if (definition instanceof SeriesServiceTop) { + SeriesServiceTop seriesServiceTop = (SeriesServiceTop) definition; + fileName = "ServiceTop_" + periodType + "_" + startDate + + "_" + endDate; + header = new ArrayList<>(Arrays.asList(new String[] { + "Value", "Date", "Operation Count", "Duration", + "Max Invocation", "Min Invocation" })); + ArrayList listDataTop = seriesServiceTop + .getSeriesServiceDataTopList(); + for (SeriesServiceDataTop seriesDataTop : listDataTop) { + FilterValue filterValue = seriesDataTop + .getFilterValue(); + ArrayList listData = seriesDataTop + .getSeries(); + for (SeriesServiceData seriesData : listData) { + ArrayList data = new ArrayList<>(); + data.add(filterValue.getValue()); + data.add(sdf.format(seriesData.getDate())); + data.add(String.valueOf(seriesData + .getOperationCount())); + data.add(String.valueOf(seriesData.getDuration())); + data.add(String.valueOf(seriesData + .getMaxInvocationTime())); + data.add(String.valueOf(seriesData + .getMinInvocationTime())); + CSVDataRow csvDataRow = new CSVDataRow(data); + rows.add(csvDataRow); + } + } + } else { + logger.error("Unsupported Serie Definition for Service: " + + definition); + throw new ServiceException( + "Unsupported Serie Definition for Service: " + + definition); + } + } + } else { + logger.error("Service not support this serie response: " + + seriesResponse); + throw new ServiceException( + "Service not support this serie response: " + + seriesResponse); + } + + CSVModel invocation = new CSVModel(fileName, header, rows); + csvModelSpec.setOp(invocation); + + } +} diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVModel4Storage.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVModel4Storage.java new file mode 100644 index 0000000..78beeb4 --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVModel4Storage.java @@ -0,0 +1,130 @@ +package org.gcube.portlets.admin.accountingmanager.server.csv.file; + +import java.util.ArrayList; +import java.util.Arrays; + +import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData; +import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue; +import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest; +import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse; +import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorage; +import org.gcube.portlets.admin.accountingmanager.shared.data.response.storage.SeriesStorageBasic; +import org.gcube.portlets.admin.accountingmanager.shared.data.response.storage.SeriesStorageData; +import org.gcube.portlets.admin.accountingmanager.shared.data.response.storage.SeriesStorageDataTop; +import org.gcube.portlets.admin.accountingmanager.shared.data.response.storage.SeriesStorageDefinition; +import org.gcube.portlets.admin.accountingmanager.shared.data.response.storage.SeriesStorageTop; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * CSV Model 4 Storage + * + * @author "Giancarlo Panichi" email: g.panichi@isti.cnr.it + * + */ +public class CSVModel4Storage extends CSVModelBuilder { + protected static Logger logger = LoggerFactory + .getLogger(CSVModel4Storage.class); + private AccountingStateData accountingStateData; + + public CSVModel4Storage(AccountingStateData accountingStateData) { + this.accountingStateData = accountingStateData; + } + + @Override + public void buildOpEx() throws ServiceException { + SeriesRequest seriesRequest = accountingStateData.getSeriesRequest(); + + if (seriesRequest == null) { + logger.error("Error series request is null"); + throw new ServiceException( + "Error series request is null"); + + } + + String startDate = sdfFile.format(seriesRequest.getAccountingPeriod() + .getStartDate()); + String endDate = sdfFile.format(seriesRequest.getAccountingPeriod() + .getEndDate()); + String periodType = seriesRequest.getAccountingPeriod().getPeriod() + .getLabel(); + + SeriesResponse seriesResponse = accountingStateData.getSeriesResponse(); + + if (seriesResponse == null) { + logger.error("Error series response is null"); + throw new ServiceException( + "Error series response is null"); + } + + String fileName = "Untitled"; + ArrayList header; + ArrayList rows = new ArrayList<>(); + if (seriesResponse instanceof SeriesStorage) { + SeriesStorage seriesStorage = (SeriesStorage) seriesResponse; + SeriesStorageDefinition definition = seriesStorage + .getSeriesStorageDefinition(); + if (definition instanceof SeriesStorageBasic) { + SeriesStorageBasic seriesStorageBasic = (SeriesStorageBasic) definition; + fileName = "Storage_" + periodType + "_" + startDate + "_" + + endDate; + header = new ArrayList<>(Arrays.asList(new String[] { "Date", + "Operation Count", "Data Volume" })); + ArrayList listData = seriesStorageBasic + .getSeries(); + for (SeriesStorageData seriesData : listData) { + ArrayList data = new ArrayList<>(); + data.add(sdf.format(seriesData.getDate())); + data.add(sdf.format(seriesData.getOperationCount())); + data.add(sdf.format(seriesData.getDataVolume())); + CSVDataRow csvDataRow = new CSVDataRow(data); + rows.add(csvDataRow); + } + } else { + if (definition instanceof SeriesStorageTop) { + SeriesStorageTop seriesStorageTop = (SeriesStorageTop) definition; + fileName = "StorageTop_" + periodType + "_" + startDate + + "_" + endDate; + header = new ArrayList<>( + Arrays.asList(new String[] { "Value", "Date", + "Operation Count", "Data Volume" })); + ArrayList listDataTop = seriesStorageTop + .getSeriesStorageDataTopList(); + for (SeriesStorageDataTop seriesDataTop : listDataTop) { + FilterValue filterValue = seriesDataTop + .getFilterValue(); + ArrayList listData = seriesDataTop + .getSeries(); + for (SeriesStorageData seriesData : listData) { + ArrayList data = new ArrayList<>(); + data.add(filterValue.getValue()); + data.add(sdf.format(seriesData.getDate())); + data.add(sdf.format(seriesData.getOperationCount())); + data.add(sdf.format(seriesData.getDataVolume())); + CSVDataRow csvDataRow = new CSVDataRow(data); + rows.add(csvDataRow); + } + } + } else { + logger.error("Unsupported Serie Definition for Storage: " + + definition); + throw new ServiceException( + "Unsupported Serie Definition for Storage: " + + definition); + } + } + } else { + logger.error("Storage not support this serie response: " + + seriesResponse); + throw new ServiceException( + "Storage not support this serie response: " + + seriesResponse); + } + + CSVModel invocation = new CSVModel(fileName,header, rows); + csvModelSpec.setOp(invocation); + + } +} diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVModelBuilder.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVModelBuilder.java new file mode 100644 index 0000000..6aa510c --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVModelBuilder.java @@ -0,0 +1,30 @@ +package org.gcube.portlets.admin.accountingmanager.server.csv.file; + +import java.text.SimpleDateFormat; + +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; + +/** + * Abstract class for build CSV Model + * + * @author "Giancarlo Panichi" + * email: g.panichi@isti.cnr.it + * + */ +public abstract class CSVModelBuilder { + protected CSVModelSpec csvModelSpec; + protected SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + protected SimpleDateFormat sdfFile = new SimpleDateFormat("yyyyMMdd"); + + public CSVModelSpec getCSVModelSpec(){ + return csvModelSpec; + } + public void createSpec(){ + csvModelSpec=new CSVModelSpec(); + + } + + public abstract void buildOpEx() throws ServiceException; + + +} diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVModelDirector.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVModelDirector.java new file mode 100644 index 0000000..e3261d1 --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVModelDirector.java @@ -0,0 +1,38 @@ +package org.gcube.portlets.admin.accountingmanager.server.csv.file; + +import java.util.ArrayList; + +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; + + +/** + * CSV Model Director + * + * @author "Giancarlo Panichi" + * email: g.panichi@isti.cnr.it + * + */ +public class CSVModelDirector { + CSVModelBuilder csvModelBuilder; + + public void setCSVModelBuilder( + CSVModelBuilder csvModelBuilder) { + this.csvModelBuilder = csvModelBuilder; + } + + public CSVModel getCSVModel() { + return csvModelBuilder.getCSVModelSpec().getOp(); + + } + + public ArrayList getListOfCSVModel() { + return csvModelBuilder.getCSVModelSpec().getOps(); + + } + + public void constructCSVModel() throws ServiceException { + csvModelBuilder.createSpec(); + csvModelBuilder.buildOpEx(); + + } +} diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVModelSpec.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVModelSpec.java new file mode 100644 index 0000000..d012254 --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/csv/file/CSVModelSpec.java @@ -0,0 +1,32 @@ +package org.gcube.portlets.admin.accountingmanager.server.csv.file; + +import java.util.ArrayList; + +/** + * CSV Model Specification + * + * @author "Giancarlo Panichi" + * email: g.panichi@isti.cnr.it + * + */ +public class CSVModelSpec { + private CSVModel op; + private ArrayList ops; + + public CSVModel getOp() { + return op; + } + + public void setOp(CSVModel op) { + this.op = op; + } + + public ArrayList getOps() { + return ops; + } + + public void setOps(ArrayList ops) { + this.ops = ops; + } + +} diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/storage/StorageUtil.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/storage/StorageUtil.java new file mode 100644 index 0000000..b98a7aa --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/storage/StorageUtil.java @@ -0,0 +1,144 @@ +package org.gcube.portlets.admin.accountingmanager.server.storage; + +import java.io.InputStream; + +import org.apache.log4j.Logger; +import org.gcube.common.homelibrary.home.HomeLibrary; +import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException; +import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; +import org.gcube.common.homelibrary.home.workspace.Workspace; +import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; +import org.gcube.common.homelibrary.home.workspace.exceptions.InsufficientPrivilegesException; +import org.gcube.common.homelibrary.home.workspace.exceptions.ItemAlreadyExistException; +import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException; +import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException; +import org.gcube.common.homelibrary.home.workspace.exceptions.WrongDestinationException; +import org.gcube.common.homelibrary.home.workspace.folder.FolderItem; +import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile; +import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; +import org.gcube.portlets.admin.accountingmanager.shared.workspace.ItemDescription; + +/** + * + * @author Giancarlo Panichi email: g.panichi@isti.cnr.it + * + */ +public class StorageUtil { + + private static final String ACCOUNTING_MANAGER = "AccountingManager"; + private static Logger logger = Logger.getLogger(StorageUtil.class); + + /** + * + * @param user + * User + * @param itemId + * Item id + * @return Public link + * @throws StatAlgoImporterServiceException + */ + public static String getPublicLink(String user, String itemId) + throws ServiceException { + Workspace ws; + try { + ws = HomeLibrary.getUserWorkspace(user); + + WorkspaceItem workSpaceItem = ws.getItem(itemId); + if (workSpaceItem.isFolder()) { + throw new ServiceException("Attention this is a folder!"); + } + + if (workSpaceItem instanceof FolderItem) { + return workSpaceItem.getPublicLink(true); + } else { + throw new ServiceException( + "Attention no public link for this item!"); + } + + } catch (WorkspaceFolderNotFoundException | InternalErrorException + | HomeNotFoundException | ItemNotFoundException e) { + e.printStackTrace(); + throw new ServiceException(e.getLocalizedMessage()); + + } + } + + /** + * + * @param user + * @param destinationFolderId + * @param folderName + * @param folderDescription + * @return + * @throws ServiceException + */ + public static String createAccountingFolderOnWorkspace(String user) + throws ServiceException { + try { + logger.debug("CreateAccountingFolderOnWorkspace: [User=" + user + + "]"); + Workspace ws = HomeLibrary.getUserWorkspace(user); + WorkspaceItem workspaceItem = ws.find(ACCOUNTING_MANAGER); + if (workspaceItem == null) { + workspaceItem = ws.createFolder(ACCOUNTING_MANAGER, + ACCOUNTING_MANAGER, ws.getRoot().getId()); + } + return workspaceItem.getId(); + + } catch (WorkspaceFolderNotFoundException | InternalErrorException + | HomeNotFoundException | InsufficientPrivilegesException + | ItemAlreadyExistException | WrongDestinationException + | ItemNotFoundException e) { + logger.error("CreateAccountingFolderOnWorkspace: " + + e.getLocalizedMessage()); + e.printStackTrace(); + throw new ServiceException(e.getLocalizedMessage(), e); + + } + } + + /** + * + * @param user + * @param destinationFolderId + * @param fileName + * @param fileDescription + * @param mimeType + * @param is + * @return + * @throws ServiceException + */ + public static ItemDescription saveOnWorkspace(String user, + String destinationFolderId, String fileName, + String fileDescription, InputStream is) throws ServiceException { + try { + logger.debug("saveOnWorkspace: [User=" + user + ", FolderId:" + + destinationFolderId + ", fileName=" + fileName + + ", fileDescription=" + fileDescription + "]"); + Workspace ws = HomeLibrary.getUserWorkspace(user); + + WorkspaceItem workspaceItem = ws.getItem(destinationFolderId); + if (workspaceItem.isFolder()) { + ExternalFile externalfile = ws.createExternalFile(fileName, + fileDescription, null, is, destinationFolderId); + ItemDescription itemDescription=new ItemDescription(externalfile.getId(), externalfile.getName(), + externalfile.getOwner().getId(), externalfile.getPath(), + externalfile.getType().name()); + + return itemDescription; + } else { + throw new ServiceException("Invalid destination folder!"); + } + + } catch (WorkspaceFolderNotFoundException | InternalErrorException + | HomeNotFoundException | InsufficientPrivilegesException + | ItemAlreadyExistException | WrongDestinationException + | ItemNotFoundException e) { + logger.error("SaveOnWorkspace: " + e.getLocalizedMessage()); + e.printStackTrace(); + throw new ServiceException(e.getLocalizedMessage(), e); + + } + } +} diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/shared/exception/AccountingManagerChartDrawException.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/shared/exception/ChartDrawException.java similarity index 60% rename from src/main/java/org/gcube/portlets/admin/accountingmanager/shared/exception/AccountingManagerChartDrawException.java rename to src/main/java/org/gcube/portlets/admin/accountingmanager/shared/exception/ChartDrawException.java index 2616f03..ee2e0e6 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/shared/exception/AccountingManagerChartDrawException.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/shared/exception/ChartDrawException.java @@ -9,7 +9,7 @@ package org.gcube.portlets.admin.accountingmanager.shared.exception; * g.panichi@isti.cnr.it * */ -public class AccountingManagerChartDrawException extends Exception { +public class ChartDrawException extends Exception { private static final long serialVersionUID = -8737011216478988776L; @@ -18,19 +18,19 @@ public class AccountingManagerChartDrawException extends Exception { /** * */ - public AccountingManagerChartDrawException() { + public ChartDrawException() { super(); } /** * @param message */ - public AccountingManagerChartDrawException(String message) { + public ChartDrawException(String message) { super(message); } - public AccountingManagerChartDrawException(String message,Throwable t) { + public ChartDrawException(String message,Throwable t) { super(message,t); } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/shared/exception/AccountingManagerServiceException.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/shared/exception/ServiceException.java similarity index 61% rename from src/main/java/org/gcube/portlets/admin/accountingmanager/shared/exception/AccountingManagerServiceException.java rename to src/main/java/org/gcube/portlets/admin/accountingmanager/shared/exception/ServiceException.java index e0edbc8..b50de9f 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/shared/exception/AccountingManagerServiceException.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/shared/exception/ServiceException.java @@ -9,7 +9,7 @@ package org.gcube.portlets.admin.accountingmanager.shared.exception; * g.panichi@isti.cnr.it * */ -public class AccountingManagerServiceException extends Exception { +public class ServiceException extends Exception { private static final long serialVersionUID = -2255657546267656458L; @@ -18,19 +18,19 @@ public class AccountingManagerServiceException extends Exception { /** * */ - public AccountingManagerServiceException() { + public ServiceException() { super(); } /** * @param message */ - public AccountingManagerServiceException(String message) { + public ServiceException(String message) { super(message); } - public AccountingManagerServiceException(String message,Throwable t) { + public ServiceException(String message,Throwable t) { super(message,t); } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/shared/exception/AccountingManagerSessionExpiredException.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/shared/exception/SessionExpiredException.java similarity index 55% rename from src/main/java/org/gcube/portlets/admin/accountingmanager/shared/exception/AccountingManagerSessionExpiredException.java rename to src/main/java/org/gcube/portlets/admin/accountingmanager/shared/exception/SessionExpiredException.java index 3479e50..96cd989 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/shared/exception/AccountingManagerSessionExpiredException.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/shared/exception/SessionExpiredException.java @@ -6,21 +6,21 @@ package org.gcube.portlets.admin.accountingmanager.shared.exception; * @author "Giancarlo Panichi" * */ -public class AccountingManagerSessionExpiredException extends AccountingManagerServiceException { +public class SessionExpiredException extends ServiceException { private static final long serialVersionUID = -4831171355042165166L; /** * */ - public AccountingManagerSessionExpiredException() { + public SessionExpiredException() { super(); } /** * @param message */ - public AccountingManagerSessionExpiredException(String message) { + public SessionExpiredException(String message) { super(message); } @@ -29,7 +29,7 @@ public class AccountingManagerSessionExpiredException extends AccountingManager * @param message * @param t */ - public AccountingManagerSessionExpiredException(String message,Throwable t) { + public SessionExpiredException(String message,Throwable t) { super(message,t); } diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/shared/workspace/ItemDescription.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/shared/workspace/ItemDescription.java new file mode 100644 index 0000000..a9a05c2 --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/shared/workspace/ItemDescription.java @@ -0,0 +1,112 @@ +package org.gcube.portlets.admin.accountingmanager.shared.workspace; + +import java.io.Serializable; + +/** + * + * @author Giancarlo Panichi email: g.panichi@isti.cnr.it + * + */ +public class ItemDescription implements Serializable { + + private static final long serialVersionUID = -6624452446980057923L; + + private String id; + private String name; + private String owner; + private String path; + private String type; + private String publicLink; + + public ItemDescription() { + super(); + } + + public ItemDescription(String id, String name, String owner, String path, + String type) { + super(); + this.id = id; + this.name = name; + this.owner = owner; + this.path = path; + this.type = type; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getOwner() { + return owner; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getPublicLink() { + return publicLink; + } + + public void setPublicLink(String publicLink) { + this.publicLink = publicLink; + } + + /** + * Compare basic information with another ItemDescription not null + * + * @param itemDescription + * @return boolean + * + */ + public boolean compareInfo(ItemDescription itemDescription){ + if(itemDescription!=null && id.compareTo(itemDescription.getId())==0 && + name.compareTo(itemDescription.getName())==0 && + owner.compareTo(itemDescription.getOwner())==0 && + path.compareTo(itemDescription.getPath())==0 && + type.compareTo(itemDescription.getType())==0 + ){ + return true; + } else { + return false; + } + + } + + @Override + public String toString() { + return "ItemDescription [id=" + id + ", name=" + name + ", owner=" + + owner + ", path=" + path + ", type=" + type + ", publicLink=" + + publicLink + "]"; + } + +}