diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/controller/Controller.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/controller/Controller.java index dc16134..c67f751 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/controller/Controller.java +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/controller/Controller.java @@ -33,7 +33,7 @@ public class Controller { private EventBus eventBus; private AccountingDashboardServiceAsync service; - private ApplicationCache cache; + //private ApplicationCache cache; private MonitorPresenter monitorPresenter; private ErrorPresenter errorPresenter; private InfoPresenter infoPresenter; @@ -46,7 +46,8 @@ public class Controller { this.monitorPresenter = monitorPresenter; this.errorPresenter = errorPresenter; this.infoPresenter = infoPresenter; - this.cache = new ApplicationCache(); + //this.cache = new ApplicationCache(); + } public void fireEvent(GwtEvent event) { @@ -61,6 +62,17 @@ public class Controller { return eventBus; } + public void errorShow(String error){ + logger.log(Level.FINE, "Error show: "+error); + errorPresenter.errorMessage(error); + } + + public void infoShow(String info){ + logger.log(Level.FINE, "Info show: "+info); + infoPresenter.infoMessage(info); + } + + public void hello() { eventBus.fireEvent(new HelloEvent()); } diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/dialog/error/ErrorView.ui.xml b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/dialog/error/ErrorView.ui.xml index 4befac1..2f755af 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/dialog/error/ErrorView.ui.xml +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/dialog/error/ErrorView.ui.xml @@ -10,10 +10,9 @@ - - Error - + Error +
diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/dialog/info/InfoView.ui.xml b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/dialog/info/InfoView.ui.xml index 037fef2..50704a8 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/dialog/info/InfoView.ui.xml +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/dialog/info/InfoView.ui.xml @@ -10,10 +10,9 @@ - - Error - + Info +
diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/dialog/monitor/MonitorView.ui.xml b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/dialog/monitor/MonitorView.ui.xml index 8d42ea5..3d07401 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/dialog/monitor/MonitorView.ui.xml +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/dialog/monitor/MonitorView.ui.xml @@ -9,9 +9,11 @@ - Please wait + Please wait... - + +
diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/filter/FilterAreaPresenter.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/filter/FilterAreaPresenter.java index 44790de..6830872 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/filter/FilterAreaPresenter.java +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/filter/FilterAreaPresenter.java @@ -1,5 +1,6 @@ package org.gcube.portlets.user.accountingdashboard.client.application.mainarea.filter; +import java.util.Date; import java.util.logging.Level; import java.util.logging.Logger; @@ -70,8 +71,19 @@ public class FilterAreaPresenter extends PresenterWidget 0) { + controller.errorShow("Attention the start date must be less than the end date!"); + return false; + } else { + return true; + } + } } diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/filter/FilterAreaView.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/filter/FilterAreaView.java index 62b4f5a..b37fc59 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/filter/FilterAreaView.java +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/filter/FilterAreaView.java @@ -17,6 +17,8 @@ import org.gcube.portlets.user.accountingdashboard.shared.data.ScopeData; import com.github.gwtbootstrap.client.ui.ListBox; import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ChangeEvent; +import com.google.gwt.event.dom.client.ChangeHandler; import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat; import com.google.gwt.i18n.client.LocaleInfo; @@ -66,6 +68,8 @@ public class FilterAreaView extends ViewWithUiHandlers CellTree scopeTree; private ListDataProvider dataProvider; + private ScopeTreeModel scopeTreeModel; + @SuppressWarnings("unused") private AppResources resources; @@ -93,13 +97,30 @@ public class FilterAreaView extends ViewWithUiHandlers for (int i = 2015; i <= year; i++) { yearStart.addItem(String.valueOf(i)); yearEnd.addItem(String.valueOf(i)); - if(i==year){ - + if (i == year) { + } } yearStart.setSelectedValue(String.valueOf(year)); yearEnd.setSelectedValue(String.valueOf(year)); - + + yearStart.addChangeHandler(new ChangeHandler() { + + @Override + public void onChange(ChangeEvent event) { + requestReport(); + + } + }); + + yearEnd.addChangeHandler(new ChangeHandler() { + + @Override + public void onChange(ChangeEvent event) { + requestReport(); + + } + }); // returns a String array with localized names of the months String[] months = LocaleInfo.getCurrentLocale().getDateTimeFormatInfo().monthsFull(); @@ -116,10 +137,28 @@ public class FilterAreaView extends ViewWithUiHandlers } String currentMonth = DateTimeFormat.getFormat(PredefinedFormat.MONTH).format(now); - monthStart.setSelectedValue(currentMonth); + + monthStart.setSelectedValue(months[0]); monthEnd.setSelectedValue(currentMonth); - - + + monthStart.addChangeHandler(new ChangeHandler() { + + @Override + public void onChange(ChangeEvent event) { + requestReport(); + + } + }); + + monthEnd.addChangeHandler(new ChangeHandler() { + + @Override + public void onChange(ChangeEvent event) { + requestReport(); + + } + }); + dataProvider = new ListDataProvider(); RequestReportEventHandler handler = new RequestReportEventHandler() { @@ -132,64 +171,62 @@ public class FilterAreaView extends ViewWithUiHandlers } }; - ScopeTreeModel scopeTreeModel = new ScopeTreeModel(dataProvider, handler); + scopeTreeModel = new ScopeTreeModel(dataProvider, handler); ScopeTreeResources scopeTreeResources = GWT.create(ScopeTreeResources.class); scopeTree = new CellTree(scopeTreeModel, null, scopeTreeResources); } - - - @Override public void displayScopeData(ScopeData scopeData) { ArrayList scopeDataList = new ArrayList<>(); scopeDataList.add(scopeData); - this.scopeData=scopeData; + this.scopeData = scopeData; dataProvider.setList(scopeDataList); dataProvider.refresh(); dataProvider.flush(); TreeNode root = scopeTree.getRootTreeNode(); root.setChildOpen(root.getIndex(), true); + scopeTreeModel.setSelected(scopeData, true); requestReport(); } private void requestReport() { DateTimeFormat dateTimeFormat = DateTimeFormat.getFormat("yyyy-M-dd"); - + String yearS = yearStart.getValue(); String monthS = monthStart.getValue(); Date dateStart = null; try { - String dStart=yearS + "-" + monthS + "-01"; - logger.fine("DateTemp1: "+dStart); + String dStart = yearS + "-" + monthS + "-01"; + logger.fine("DateTemp1: " + dStart); dateStart = dateTimeFormat.parse(dStart); - logger.fine("DateStart: "+dStart); + logger.fine("DateStart: " + dStart); } catch (Exception e) { - logger.log(Level.SEVERE,"Error in start date: "+e.getLocalizedMessage(),e); - + logger.log(Level.SEVERE, "Error in start date: " + e.getLocalizedMessage(), e); + } String yearE = yearEnd.getValue(); String monthE = monthEnd.getValue(); - + Date dateEnd = null; try { - String dEnd=yearE + "-" + monthE + "-01"; - logger.fine("DateTemp2: "+dEnd); + String dEnd = yearE + "-" + monthE + "-01"; + logger.fine("DateTemp2: " + dEnd); dateEnd = dateTimeFormat.parse(dEnd); CalendarUtil.addMonthsToDate(dateEnd, 1); CalendarUtil.addDaysToDate(dateEnd, -1); - logger.fine("DateEnd: "+dateEnd); - + logger.fine("DateEnd: " + dateEnd); + } catch (Exception e) { - logger.log(Level.SEVERE,"Error in end date: "+e.getLocalizedMessage(),e); + logger.log(Level.SEVERE, "Error in end date: " + e.getLocalizedMessage(), e); } - - RequestReportData requestReportData=new RequestReportData(scopeData, dateStart, dateEnd); + + RequestReportData requestReportData = new RequestReportData(scopeData, dateStart, dateEnd); getUiHandlers().getReport(requestReportData); - + } } diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/filter/scopetree/ScopeTreeModel.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/filter/scopetree/ScopeTreeModel.java index 88d6308..a6e05ab 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/filter/scopetree/ScopeTreeModel.java +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/filter/scopetree/ScopeTreeModel.java @@ -45,11 +45,18 @@ public class ScopeTreeModel implements TreeViewModel { } }); } + + + public void setSelected(ScopeData item, boolean selected){ + selectionModel.setSelected(item, selected); + } + + public boolean isSelected(ScopeData item){ + return selectionModel.isSelected(item); + } + + - /** - * Get the {@link NodeInfo} that provides the children of the specified - * value. - */ @Override public NodeInfo getNodeInfo(T value) { if (value == null) { @@ -83,8 +90,9 @@ public class ScopeTreeModel implements TreeViewModel { } } }; + return new DefaultNodeInfo(dataProvider, cell, selectionModel, null); - } + } /* * else if (value instanceof ScopeData) { @@ -99,10 +107,6 @@ public class ScopeTreeModel implements TreeViewModel { return null; } - /** - * Check if the specified value represents a leaf node. Leaf nodes cannot be - * opened. - */ @Override public boolean isLeaf(Object value) { // The leaf nodes are the songs, which are Strings. diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/ReportAreaPresenter.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/ReportAreaPresenter.java index 8fe54f4..33ea5f4 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/ReportAreaPresenter.java +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/ReportAreaPresenter.java @@ -5,7 +5,6 @@ import java.util.logging.Logger; import org.gcube.portlets.user.accountingdashboard.client.application.controller.Controller; import org.gcube.portlets.user.accountingdashboard.client.application.event.ReportEvent; -import org.gcube.portlets.user.accountingdashboard.client.application.event.ScopeDataEvent; import org.gcube.portlets.user.accountingdashboard.shared.data.ReportData; import com.google.inject.Inject; @@ -29,6 +28,7 @@ public class ReportAreaPresenter extends PresenterWidget @UiField HTMLPanel reportPanel; + private HashMap> categories; + private AppResources resources; @Inject @@ -42,123 +47,71 @@ public class ReportAreaView extends ViewWithUiHandlers this.resources = resources; init(); initWidget(uiBinder.createAndBindUi(this)); - - /* - RecordData recordData1 = new RecordData(); - recordData1.setX("Gennaio"); - recordData1.setY(3d); - - RecordData recordData2 = new RecordData(); - recordData2.setX("Febbraio"); - recordData2.setY(2d); - - RecordData recordData3 = new RecordData(); - recordData3.setX("Marzo"); - recordData3.setY(4d); - - RecordData[] dataRow1 = new RecordData[2]; - dataRow1[0] = recordData1; - dataRow1[1] = recordData2; - dataRow1[2] = recordData3; - - RecordData recordData4 = new RecordData(); - recordData4.setX("Gennaio"); - recordData4.setY(1d); - - RecordData recordData5 = new RecordData(); - recordData5.setX("Febbraio"); - recordData5.setY(5d); - - RecordData recordData6 = new RecordData(); - recordData6.setX("Marzo"); - recordData6.setY(2d); - - RecordData[] dataRow2 = new RecordData[2]; - dataRow2[0] = recordData4; - dataRow2[1] = recordData5; - dataRow2[2] = recordData6; - - SeriesData seriesData1 = new SeriesData(); - seriesData1.setLabel("Series1"); - seriesData1.setDataRow(dataRow1); - - SeriesData seriesData2 = new SeriesData(); - seriesData2.setLabel("Series2"); - seriesData2.setDataRow(dataRow2); - - SeriesData[] serieses = new SeriesData[2]; - serieses[0] = seriesData1; - serieses[1] = seriesData2; - - ReportData rData = new ReportData(); - ArrayList elements = new ArrayList<>(); - - ReportElementData reportElementData1 = new ReportElementData(); - reportElementData1.setxAxis("XAxis"); - reportElementData1.setyAxis("YAxis"); - reportElementData1.setCategory("Category"); - reportElementData1.setLabel("Label1"); - reportElementData1.setSerieses(serieses); - elements.add(reportElementData1); - - ReportElementData reportElementData2 = new ReportElementData(); - reportElementData2.setxAxis("XAxis"); - reportElementData2.setyAxis("YAxis"); - reportElementData2.setCategory("Category"); - reportElementData2.setLabel("Label2"); - reportElementData2.setSerieses(serieses); - elements.add(reportElementData2); - - rData.setElements(elements); - - displayReportData(rData);*/ } private void init() { } - /** - * LABEL | | _ yaxis | _ | | | | || |_ | | || | | - * --------------------------------------------------- - * - * - * *Series_label1 *Series_label2 *Series_label3 - * - * xAxis - * - */ - @Override public void displayReportData(ReportData reportData) { if (reportData == null) { reportPanel.clear(); } else { reportPanel.clear(); - HashMap> categories=new HashMap<>(); + categories = new HashMap<>(); for (int i = 0; i < reportData.getElements().size(); i++) { - ReportElementData reportElementData=reportData.getElements().get(i); + ReportElementData reportElementData = reportData.getElements().get(i); + String key = reportElementData.getCategory(); ArrayList category; - if(categories.containsKey(reportElementData.getCategory())){ - category=categories.get(reportElementData.getCategory()); + if (categories.containsKey(key)) { + category = categories.get(reportElementData.getCategory()); } else { - category=new ArrayList<>(); + category = new ArrayList<>(); } Chart chart = new Chart(resources, "report_" + i, reportElementData); - category.add(chart); + category.add(chart); + categories.put(key, category); } - - TabPanel tabPanel=new TabPanel(); - for(String category:categories.keySet()){ - Tab tab=new Tab(); - HTMLPanel tabContent=new HTMLPanel(""); - for(Chart chart:categories.get(category)){ + + TabPanel tabPanel = new TabPanel(); + boolean first = true; + for (String category : categories.keySet()) { + Tab tab = new Tab(); + tab.setHeading(category); + HTMLPanel tabContent = new HTMLPanel(""); + for (Chart chart : categories.get(category)) { tabContent.add(chart); } + if (first) { + tab.setActive(true); + first = false; + } + tab.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + logger.fine("ClickEvent: " + event.getSource().getClass()); + IconAnchor iconAnchor = (IconAnchor) event.getSource(); + String category = iconAnchor.getText(); + if (category != null) { + category = category.trim(); + } + logger.fine("Category found: " + category); + ArrayList chartsInCategory = categories.get(category); + // logger.fine("Charts List:"+chartsInCategory); + if (chartsInCategory != null) { + for (Chart chart : chartsInCategory) { + chart.forceLayout(); + } + } + } + }); + tab.add(tabContent); tabPanel.add(tab); } - + reportPanel.add(tabPanel); } diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/chartjs/Chart.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/chartjs/Chart.java index 85da010..4e918ba 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/chartjs/Chart.java +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/chartjs/Chart.java @@ -32,28 +32,38 @@ public class Chart extends HTMLPanel { } }); - } - - public String getYAxisLabel() { - return reportElementData.getyAxis(); } - /** - * LABEL | | _ yaxis | _ | | | | || |_ | | || | | - * --------------------------------------------------- - * - * - * *Series_label1 *Series_label2 *Series_label3 - * - * xAxis - * - */ + public void forceLayout() { + redrawChart(); + } - /** - * Series[] { Series : LABEL, dataRow [] Series : LABEL, dataRow [] Series : - * LABEL, dataRow [] Series : LABEL, dataRow [] } - */ + private native void redrawChart() /*-{ + console.log('RedrawChart()'); + + var canvas = @org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::getCanvas(Lorg/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/chartjs/Chart;)(this); + this.@org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::drawChart()(); + + }-*/; + + private static native void getCanvas(Chart chart)/*-{ + var name = chart.@org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::name; + console.log('Element name: ' + name); + var element = this; + console.log('Element found: ' + element); + var canvas = $doc.getElementById(name); + console.log('Canvas: ' + canvas); + + canvas.height = 500; + canvas.width = 1024; + var canvasW = canvas.width; + var canvasH = canvas.height; + console.log('Canvas dimensions: ' + canvasW + ' x ' + canvasH); + + return canvas; + + }-*/; private native void drawChart() /*-{ @@ -88,18 +98,9 @@ public class Chart extends HTMLPanel { return color; } - var name = this.@org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::name; - console.log('Element name: ' + name); - var element = this; - console.log('Element found: ' + element); - var canvas = $doc.getElementById(name); + var canvas = @org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::getCanvas(Lorg/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/chartjs/Chart;)(this); console.log('Canvas: ' + canvas); - var recordData = new $wnd.org.gcube.portlets.user.accountingdashboard.shared.data.RecordData(); - recordData.setX('ok'); - recordData.setY(1.0); - console.log('RecordData: ' + recordData.toString()); - var reportElementData = this.@org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::reportElementData; console.log('ReportElementData: ' + reportElementData); @@ -135,8 +136,6 @@ public class Chart extends HTMLPanel { var colorChart = getRandomColor(); console.log('Color: ' + colorChart); - // backgroundColor : 'rgba(255,0,0,0.9)', - // borderColor : 'rgba(255,0,0,1)', datasetsArray.push({ label : seriesData.getLabel(), @@ -147,9 +146,6 @@ public class Chart extends HTMLPanel { }); } - //var color = Chart.helpers.color; - //console.log('Color: ' + color); - var barChartData = { labels : labelsArray, datasets : datasetsArray @@ -161,13 +157,14 @@ public class Chart extends HTMLPanel { var yAxisLabel = reportElementData.getyAxis(); var ctx = canvas.getContext('2d'); + console.log('Create chart'); var chart = new Chart(ctx, { // The type of chart we want to create type : 'bar', data : barChartData, options : { animation : false, - responsive : true, + responsive : false, legend : { position : 'top', }, @@ -195,6 +192,15 @@ public class Chart extends HTMLPanel { } } }); + console.log('Chart: ' + chart); + //Chart.instances[].resize(); + //chart.resize(); + + chart.update(); + + var canvasW = canvas.width; + var canvasH = canvas.height; + console.log('Canvas dimensions: ' + canvasW + ' x ' + canvasH); }-*/; diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/resources/AppResources.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/resources/AppResources.java index d7b7014..8106e71 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/resources/AppResources.java +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/resources/AppResources.java @@ -48,9 +48,13 @@ public interface AppResources extends ClientBundle { String uiDataPopupGlass(); - //String uiDataFormTable(); + String uiDataPopupCaption(); - //String uiDataFormPager(); + String uiDataPopupHr(); + + // String uiDataFormTable(); + + // String uiDataFormPager(); // String uiDataActionParagraph(); // String uiDataAccordionGroup(); diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/resources/uiData.css b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/resources/uiData.css index 5ebbecf..c1d3dd8 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/resources/uiData.css +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/resources/uiData.css @@ -52,11 +52,12 @@ /* Report*/ .uiDataReportPanel { - float: left; + float: left; } /* Chart */ -.uiDataChartWrapper { +.uiDataChartWrapper { + } .uiDataChartCanvas { @@ -65,13 +66,12 @@ max-height: 800px; } - - /* Monitor Dialog */ .uiDataMonitorPopup { background-color: white; - border: 1px double black; + border: 1px double #999; padding: 0 15px; + height: 70px; z-index: 1070; } @@ -83,14 +83,14 @@ } .uiDataMonitorPopupProgress { - margin: 5px; + /*margin: 5px;*/ height: 20px; } /* Dialog */ .uiDataPopup { background-color: white; - border: 1px double black; + border: 1px double #999; padding: 0 15px; z-index: 1070; } @@ -102,6 +102,21 @@ z-index: 1050; } +.uiDataPopupCaption { + display: block; + font-size: large; + margin-top: 5px; + margin-bottom: 2px; +} + +.uiDataPopupHr { + margin: 0px!important; + margin-bottom: 5px; + height: 3px; + border: 0; + box-shadow: inset 0 3px 3px -3px rgba(0, 0, 0, 0.5); +} + /* .uiDataBody { padding-top: 0px; diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/server/AccountingDashboardServiceImpl.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/server/AccountingDashboardServiceImpl.java index c4022e6..b2a0643 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/server/AccountingDashboardServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/server/AccountingDashboardServiceImpl.java @@ -6,7 +6,6 @@ import org.gcube.portlets.user.accountingdashboard.client.rpc.AccountingDashboar import org.gcube.portlets.user.accountingdashboard.server.accounting.AccountingService; import org.gcube.portlets.user.accountingdashboard.server.accounting.AccountingServiceType; import org.gcube.portlets.user.accountingdashboard.server.util.ServiceCredentials; -import org.gcube.portlets.user.accountingdashboard.shared.Constants; import org.gcube.portlets.user.accountingdashboard.shared.data.ReportData; import org.gcube.portlets.user.accountingdashboard.shared.data.RequestReportData; import org.gcube.portlets.user.accountingdashboard.shared.data.ScopeData; @@ -69,13 +68,7 @@ public class AccountingDashboardServiceImpl extends RemoteServiceServlet impleme logger.debug("AccountingDashboardServiceImpl getScopeData()"); @SuppressWarnings("unused") ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(this.getThreadLocalRequest()); - AccountingService as = null; - if (Constants.DEBUG_MODE) { - as = new AccountingService(AccountingServiceType.CurrentScope); - } else { - as = new AccountingService(AccountingServiceType.PortalContex); - } - + AccountingService as = new AccountingService(AccountingServiceType.PortalContex); ScopeData scopeData = as.getTree(this.getThreadLocalRequest()); return scopeData; } catch (ServiceException e) { @@ -94,12 +87,7 @@ public class AccountingDashboardServiceImpl extends RemoteServiceServlet impleme logger.debug("AccountingDashboardServiceImpl getReport(): " + requestReportData); @SuppressWarnings("unused") ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(this.getThreadLocalRequest()); - AccountingService as = null; - if (Constants.DEBUG_MODE) { - as = new AccountingService(AccountingServiceType.CurrentScope); - } else { - as = new AccountingService(AccountingServiceType.PortalContex); - } + AccountingService as = new AccountingService(AccountingServiceType.PortalContex); ReportData reportData = as.getReport(this.getThreadLocalRequest(), requestReportData); return reportData; } catch (ServiceException e) { diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/AccountingService.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/AccountingService.java index ea80945..ea58c82 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/AccountingService.java +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/AccountingService.java @@ -5,13 +5,18 @@ import java.util.Date; import javax.servlet.http.HttpServletRequest; +import org.apache.bcel.classfile.Constant; import org.gcube.accounting.accounting.summary.access.AccountingDao; import org.gcube.accounting.accounting.summary.access.model.MeasureResolution; import org.gcube.accounting.accounting.summary.access.model.Report; import org.gcube.accounting.accounting.summary.access.model.ScopeDescriptor; +import org.gcube.portlets.user.accountingdashboard.shared.Constants; +import org.gcube.portlets.user.accountingdashboard.shared.data.RecordData; import org.gcube.portlets.user.accountingdashboard.shared.data.ReportData; +import org.gcube.portlets.user.accountingdashboard.shared.data.ReportElementData; import org.gcube.portlets.user.accountingdashboard.shared.data.RequestReportData; import org.gcube.portlets.user.accountingdashboard.shared.data.ScopeData; +import org.gcube.portlets.user.accountingdashboard.shared.data.SeriesData; import org.gcube.portlets.user.accountingdashboard.shared.exception.ServiceException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,6 +34,10 @@ public class AccountingService { public AccountingService(AccountingServiceType accountingServiceType) throws ServiceException { try { + if (Constants.DEBUG_MODE) { + return; + } + if (accountingServiceType == null) { logger.error("Invalid AccountingServiceType requested: null"); } @@ -48,6 +57,7 @@ public class AccountingService { break; } + } catch (Throwable e) { logger.error("Error retrieving Tree: " + e.getLocalizedMessage(), e); throw new ServiceException("Error retrieving Tree: " + e.getLocalizedMessage(), e); @@ -57,6 +67,9 @@ public class AccountingService { public ScopeData getTree(HttpServletRequest httpServletRequest) throws ServiceException { try { + if(Constants.DEBUG_MODE){ + return debugScope(); + } logger.debug("AccountingService GetTree()"); ScopeDescriptor scopeDescriptor = dao.getTree(httpServletRequest); logger.debug("ScopeDescriptor: " + scopeDescriptor); @@ -69,6 +82,8 @@ public class AccountingService { } } + + private ScopeData getScopeData(ScopeDescriptor scopeDescriptor) { ScopeData scopeData = null; if (scopeDescriptor != null) { @@ -89,6 +104,10 @@ public class AccountingService { public ReportData getReport(HttpServletRequest httpServletRequest, RequestReportData requestReportData) throws ServiceException { try { + if(Constants.DEBUG_MODE){ + return debugReport(); + } + logger.debug("AccountingService GetReport(): " + requestReportData); if (requestReportData != null && requestReportData.getScopeData() != null && requestReportData.getScopeData().getId() != null @@ -112,7 +131,7 @@ public class AccountingService { } } catch (Throwable e) { - logger.error("Error in crete report: " + e.getLocalizedMessage(), e); + logger.error("Error in create report: " + e.getLocalizedMessage(), e); throw new ServiceException("Error in create report: " + e.getLocalizedMessage(), e); } } @@ -163,5 +182,84 @@ public class AccountingService { throw new ServiceException("Error searching scope descriptor: " + e.getLocalizedMessage(), e); } } + + private ScopeData debugScope() { + ScopeData scopeData=new ScopeData("Debug", "Debug", null); + return scopeData; + } + + + private ReportData debugReport() { + + RecordData recordData1 = new RecordData(); + recordData1.setX("January"); + recordData1.setY(3d); + + RecordData recordData2 = new RecordData(); + recordData2.setX("February"); + recordData2.setY(2d); + + RecordData recordData3 = new RecordData(); + recordData3.setX("March"); + recordData3.setY(4d); + + RecordData[] dataRow1 = new RecordData[3]; + dataRow1[0] = recordData1; + dataRow1[1] = recordData2; + dataRow1[2] = recordData3; + + RecordData recordData4 = new RecordData(); + recordData4.setX("January"); + recordData4.setY(1d); + + RecordData recordData5 = new RecordData(); + recordData5.setX("February"); + recordData5.setY(5d); + + RecordData recordData6 = new RecordData(); + recordData6.setX("March"); + recordData6.setY(2d); + + RecordData[] dataRow2 = new RecordData[3]; + dataRow2[0] = recordData4; + dataRow2[1] = recordData5; + dataRow2[2] = recordData6; + + SeriesData seriesData1 = new SeriesData(); + seriesData1.setLabel("Series1"); + seriesData1.setDataRow(dataRow1); + + SeriesData seriesData2 = new SeriesData(); + seriesData2.setLabel("Series2"); + seriesData2.setDataRow(dataRow2); + + SeriesData[] serieses = new SeriesData[2]; + serieses[0] = seriesData1; + serieses[1] = seriesData2; + + ReportData reportData1 = new ReportData(); + ArrayList elements = new ArrayList<>(); + + ReportElementData reportElementData1 = new ReportElementData(); + reportElementData1.setxAxis("XAxis"); + reportElementData1.setyAxis("YAxis"); + reportElementData1.setCategory("Category1"); + reportElementData1.setLabel("Label1"); + reportElementData1.setSerieses(serieses); + elements.add(reportElementData1); + + ReportElementData reportElementData2 = new ReportElementData(); + reportElementData2.setxAxis("XAxis"); + reportElementData2.setyAxis("YAxis"); + reportElementData2.setCategory("Category2"); + reportElementData2.setLabel("Label2"); + reportElementData2.setSerieses(serieses); + elements.add(reportElementData2); + + reportData1.setElements(elements); + + return reportData1; + + } } diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/PortalContextTreeProvider.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/PortalContextTreeProvider.java index 89b3e49..4e2bd4b 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/PortalContextTreeProvider.java +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/PortalContextTreeProvider.java @@ -34,67 +34,53 @@ public class PortalContextTreeProvider implements ContextTreeProvider { private static Logger log = LoggerFactory.getLogger(PortalContextTreeProvider.class); - static { groupsManager = new LiferayGroupManager(); } @Override public ScopeDescriptor getTree(Object context) throws Exception { - if(context == null) throw new Exception("Unable to get tree, Request is null."); - if(!(context instanceof HttpServletRequest)) throw new - Exception("Invalid request object : "+context); - HttpServletRequest request=(HttpServletRequest) context; + if (context == null) + throw new Exception("Unable to get tree, Request is null."); + if (!(context instanceof HttpServletRequest)) + throw new Exception("Invalid request object : " + context); + HttpServletRequest request = (HttpServletRequest) context; // PARSE TREE - LinkedHashMap> gatewayTree=getPortalSitesMappedToVRE(request); + LinkedHashMap> gatewayTree = getPortalSitesMappedToVRE(request); - log.debug("Parsing tree from gateway. Size {} ",gatewayTree.size()); - - LinkedList rootChildren=new LinkedList<>(); - for(Entry> entry:gatewayTree.entrySet()) { - ScopeDescriptor rootChild=new ScopeDescriptor(entry.getKey().name, entry.getKey().categoryID+""); - for(VRE vre:entry.getValue()) + log.debug("Parsing tree from gateway. Size {} ", gatewayTree.size()); + + LinkedList rootChildren = new LinkedList<>(); + for (Entry> entry : gatewayTree.entrySet()) { + ScopeDescriptor rootChild = new ScopeDescriptor(entry.getKey().name, entry.getKey().categoryID + ""); + for (VRE vre : entry.getValue()) rootChild.getChildren().add(new ScopeDescriptor(vre.name, vre.scope)); rootChildren.add(rootChild); } - Group rootGroup=getSiteFromServletRequest(request); - ScopeDescriptor root=new ScopeDescriptor(rootGroup.getDescriptiveName(),rootGroup.getGroupId()+""); + Group rootGroup = getSiteFromServletRequest(request); + ScopeDescriptor root = new ScopeDescriptor(rootGroup.getDescriptiveName(), rootGroup.getGroupId() + ""); root.setChildren(rootChildren); - log.debug("TREE IS {} ",root); + log.debug("TREE IS {} ", root); return root; } -// private ScopeDescriptor asScopeDescriptor(GCubeGroup group) -// throws UserManagementSystemException, GroupRetrievalFault { -// ScopeDescriptor toReturn = new ScopeDescriptor(group.getGroupName(), -// groupsManager.getInfrastructureScope(group.getGroupId())); -// if (group.getChildren() != null && !group.getChildren().isEmpty()) { -// for (GCubeGroup child : group.getChildren()) { -// toReturn.getChildren().add(asScopeDescriptor(child)); -// } -// } -// return toReturn; -// } - - - /** * * @return the Virtual groups with their VREs in the order estabilished in - the LR Control Panel + * the LR Control Panel * @throws SystemException * @throws PortalException */ - private LinkedHashMap> - getPortalSitesMappedToVRE(HttpServletRequest request) throws Exception { + private LinkedHashMap> getPortalSitesMappedToVRE(HttpServletRequest request) + throws Exception { LinkedHashMap> toReturn = new LinkedHashMap>(); long currentSiteGroupId = getSiteFromServletRequest(request).getGroupId(); - List currentSiteVGroups = groupsManager.getVirtualGroups(currentSiteGroupId); + List currentSiteVGroups = groupsManager.getVirtualGroups(currentSiteGroupId); for (VirtualGroup vg : currentSiteVGroups) { ArrayList toCreate = new ArrayList(); @@ -105,9 +91,10 @@ public class PortalContextTreeProvider implements ContextTreeProvider { GCubeGroup rootGroupVO = groupsManager.getRootVO(); try { - log.debug("root: " + rootGroupVO.getGroupName() ); + log.debug("root: " + rootGroupVO.getGroupName()); } catch (NullPointerException e) { - log.error("Cannot find root organziation, please check gcube-data.properties file in $CATALINA_HOME/conf folder, unless your installing the Bundle"); + log.error( + "Cannot find root organziation, please check gcube-data.properties file in $CATALINA_HOME/conf folder, unless your installing the Bundle"); return toReturn; } PortalContext pContext = PortalContext.getConfiguration(); @@ -119,46 +106,54 @@ public class PortalContextTreeProvider implements ContextTreeProvider { currUserGroups = groupsManager.listGroupsByUser(currUser.getUserId()); } - //for each root sub organizations (VO) + // for each root sub organizations (VO) for (GCubeGroup vOrg : rootGroupVO.getChildren()) { for (GCubeGroup vreSite : vOrg.getChildren()) { - long vreID = vreSite.getGroupId(); + long vreID = vreSite.getGroupId(); String vreName = vreSite.getGroupName(); String vreDescription = vreSite.getDescription(); long logoId = vreSite.getLogoId(); String vreLogoURL = groupsManager.getGroupLogoURL(logoId); String infraScope = groupsManager.getInfrastructureScope(vreSite.getGroupId()); - String friendlyURL = GCubePortalConstants.PREFIX_GROUP_URL+vreSite.getFriendlyURL(); + String friendlyURL = GCubePortalConstants.PREFIX_GROUP_URL + vreSite.getFriendlyURL(); - List vreGroups = groupsManager.getVirtualGroups(vreID); + List vreGroups = groupsManager.getVirtualGroups(vreID); for (VirtualGroup vreGroup : vreGroups) { for (VRECategory vre : toReturn.keySet()) { - if (vre.getName().compareTo(vreGroup.getName())==0) { + if (vre.getName().compareTo(vreGroup.getName()) == 0) { ArrayList toUpdate = toReturn.get(vre); - // UserBelonging belongs = UserBelonging.NOT_BELONGING; - // VRE toAdd = new VRE(vreID,vreName, vreDescription, vreLogoURL, groupName, friendlyURL, belongs, getVREMembershipType(vreSite.getMembershipType())); - VRE toAdd= new VRE(vreName,vreDescription,vreID,friendlyURL,infraScope); - // if (GroupLocalServiceUtil.getGroup(vreID).getPublicLayoutsPageCount() > 0) { - // String publicURL = PREFIX_PUBLIC_URL+vreSite.getFriendlyURL(); - // toAdd.setPublicURL(publicURL); - // } - // if (currUser != null) { - // //check if the user belongs to it - // if (currUserGroups.contains(vreSite)) { - // toAdd.setUserBelonging(UserBelonging.BELONGING); - // } - // else if (checkPending(currUser.getUsername(), vreSite.getGroupId())) - // toAdd.setUserBelonging(UserBelonging.PENDING); - // } + // UserBelonging belongs = + // UserBelonging.NOT_BELONGING; + // VRE toAdd = new VRE(vreID,vreName, + // vreDescription, vreLogoURL, groupName, + // friendlyURL, belongs, + // getVREMembershipType(vreSite.getMembershipType())); + VRE toAdd = new VRE(vreName, vreDescription, vreID, friendlyURL, infraScope); + // if + // (GroupLocalServiceUtil.getGroup(vreID).getPublicLayoutsPageCount() + // > 0) { + // String publicURL = + // PREFIX_PUBLIC_URL+vreSite.getFriendlyURL(); + // toAdd.setPublicURL(publicURL); + // } + // if (currUser != null) { + // //check if the user belongs to it + // if (currUserGroups.contains(vreSite)) { + // toAdd.setUserBelonging(UserBelonging.BELONGING); + // } + // else if (checkPending(currUser.getUsername(), + // vreSite.getGroupId())) + // toAdd.setUserBelonging(UserBelonging.PENDING); + // } toUpdate.add(toAdd); } - } - } + } + } } } - //sort the vres in the groups + // sort the vres in the groups for (VRECategory cat : toReturn.keySet()) { ArrayList toSort = toReturn.get(cat); Collections.sort(toSort); @@ -166,12 +161,7 @@ public class PortalContextTreeProvider implements ContextTreeProvider { return toReturn; } - - - - - private Group getSiteFromServletRequest(final HttpServletRequest request) - throws PortalException, SystemException { + private Group getSiteFromServletRequest(final HttpServletRequest request) throws PortalException, SystemException { String serverName = request.getServerName(); log.debug("currentHost is " + serverName); Group site = null; @@ -179,9 +169,8 @@ public class PortalContextTreeProvider implements ContextTreeProvider { VirtualHostLocalServiceUtil.getVirtualHostsCount()); for (VirtualHost virtualHost : vHosts) { log.debug("Found " + virtualHost.getHostname()); - if (virtualHost.getHostname().compareTo("localhost") != 0 && - virtualHost.getLayoutSetId() != 0 && - virtualHost.getHostname().compareTo(serverName) == 0) { + if (virtualHost.getHostname().compareTo("localhost") != 0 && virtualHost.getLayoutSetId() != 0 + && virtualHost.getHostname().compareTo(serverName) == 0) { long layoutSetId = virtualHost.getLayoutSetId(); site = LayoutSetLocalServiceUtil.getLayoutSet(layoutSetId).getGroup(); log.debug("Found match! Your site is " + site.getName()); @@ -191,13 +180,11 @@ public class PortalContextTreeProvider implements ContextTreeProvider { return null; } - - - - private class VRECategory{ + private class VRECategory { private long categoryID; private String name; private String description; + public VRECategory(long categoryID, String name, String description) { super(); this.categoryID = categoryID; @@ -208,9 +195,11 @@ public class PortalContextTreeProvider implements ContextTreeProvider { public long getCategoryID() { return categoryID; } + public String getDescription() { return description; } + public String getName() { return name; } @@ -219,18 +208,16 @@ public class PortalContextTreeProvider implements ContextTreeProvider { public String toString() { return "VRECategory [categoryID=" + categoryID + ", name=" + name + ", description=" + description + "]"; } - + } - - private class VRE implements Comparable{ + private class VRE implements Comparable { private String name; - private String description; + private String description; private long id; private String url; private String scope; - public VRE(String name, String description, long id, String url, String scope) { super(); this.name = name; @@ -247,18 +234,19 @@ public class PortalContextTreeProvider implements ContextTreeProvider { public long getId() { return id; } + public String getName() { return name; } + public String getScope() { return scope; } + public String getUrl() { return url; } - - @Override public String toString() { return "VRE [name=" + name + ", description=" + description + ", id=" + id + ", url=" + url + ", scope="