diff --git a/pom.xml b/pom.xml
index 8ea3334..2560df3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -249,7 +249,7 @@
- org.gcube.data.access
+ org.gcube.accounting
accounting-summary-access
[0.0.1-SNAPSHOT,2.0.0-SNAPSHOT)
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 b8444d4..3b4e443 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
@@ -109,17 +109,20 @@ public class Controller {
}
public void getReport(RequestReportData requestReportData) {
+ monitorPresenter.enable(true);
service.getReport(requestReportData, new AsyncCallback() {
@Override
public void onFailure(Throwable caught) {
logger.log(Level.FINE, "Error in getReport(): ", caught);
+ monitorPresenter.enable(false);
errorPresenter.errorMessage(caught.getLocalizedMessage());
}
@Override
public void onSuccess(ReportData reportData) {
logger.log(Level.FINE, "ReportData: " + reportData);
+ monitorPresenter.enable(false);
// ScopeDataEvent event = new ScopeDataEvent(scopeData);
// eventBus.fireEvent(event);
}
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 4e68d26..db09b21 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
@@ -12,6 +12,7 @@ import org.gcube.portlets.user.accountingdashboard.client.application.event.Requ
import org.gcube.portlets.user.accountingdashboard.client.application.mainarea.filter.scopetree.ScopeTreeModel;
import org.gcube.portlets.user.accountingdashboard.client.resources.AppResources;
import org.gcube.portlets.user.accountingdashboard.client.resources.ScopeTreeResources;
+import org.gcube.portlets.user.accountingdashboard.shared.data.RequestReportData;
import org.gcube.portlets.user.accountingdashboard.shared.data.ScopeData;
import com.github.gwtbootstrap.client.ui.ListBox;
@@ -25,7 +26,9 @@ import com.google.gwt.user.cellview.client.CellTree;
import com.google.gwt.user.cellview.client.TreeNode;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget;
+import com.google.gwt.user.datepicker.client.CalendarUtil;
import com.google.gwt.view.client.ListDataProvider;
+
import com.gwtplatform.mvp.client.ViewWithUiHandlers;
/**
@@ -40,8 +43,6 @@ public class FilterAreaView extends ViewWithUiHandlers
interface Binder extends UiBinder {
}
-
-
@UiField
HTMLPanel periodPanel;
@@ -68,6 +69,8 @@ public class FilterAreaView extends ViewWithUiHandlers
@SuppressWarnings("unused")
private AppResources resources;
+ private ScopeData scopeData;
+
@Inject
FilterAreaView(Binder uiBinder, AppResources resources) {
this.resources = resources;
@@ -108,34 +111,73 @@ public class FilterAreaView extends ViewWithUiHandlers
dataProvider = new ListDataProvider();
- RequestReportEventHandler handler=new RequestReportEventHandler() {
-
+ RequestReportEventHandler handler = new RequestReportEventHandler() {
+
@Override
public void onData(RequestReportEvent event) {
- //TODO
-
+ scopeData = event.getScopeData();
+ requestReport();
+
}
};
-
-
- ScopeTreeModel scopeTreeModel = new ScopeTreeModel(dataProvider,handler);
+
+ ScopeTreeModel 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;
dataProvider.setList(scopeDataList);
dataProvider.refresh();
dataProvider.flush();
TreeNode root = scopeTree.getRootTreeNode();
root.setChildOpen(root.getIndex(), true);
+
+ }
+
+ 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("DateStart: "+dStart);
+ dateStart = dateTimeFormat.parse(dStart);
+ } catch (Exception 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("DateTemp: "+dEnd);
+ dateEnd = dateTimeFormat.parse(dEnd);
+ CalendarUtil.addMonthsToDate(dateEnd, 1);
+ CalendarUtil.addDaysToDate(dateEnd, -1);
+ logger.fine("DateEnd: "+dEnd);
+
+ } catch (Exception e) {
+ logger.log(Level.SEVERE,"Error in end date: "+e.getLocalizedMessage(),e);
+ }
+
+ RequestReportData requestReportData=new RequestReportData(scopeData, dateStart, dateEnd);
+ getUiHandlers().getReport(requestReportData);
}
-
-
}
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 59f694f..ab662b7 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
@@ -89,7 +89,7 @@ public class AccountingDashboardServiceImpl extends RemoteServiceServlet impleme
@SuppressWarnings("unused")
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(this.getThreadLocalRequest());
AccountingService as = new AccountingService(AccountingServiceType.PortalContex);
- ReportData reportData = as.getReport(requestReportData);
+ 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 12b1087..fb7db92 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
@@ -2,14 +2,13 @@ package org.gcube.portlets.user.accountingdashboard.server.accounting;
import java.util.ArrayList;
import java.util.Date;
-import java.util.GregorianCalendar;
import javax.servlet.http.HttpServletRequest;
-import org.gcube.data.access.accounting.summary.access.AccountingDao;
-import org.gcube.data.access.accounting.summary.access.model.MeasureResolution;
-import org.gcube.data.access.accounting.summary.access.model.Report;
-import org.gcube.data.access.accounting.summary.access.model.ScopeDescriptor;
+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.data.ReportData;
import org.gcube.portlets.user.accountingdashboard.shared.data.RequestReportData;
import org.gcube.portlets.user.accountingdashboard.shared.data.ScopeData;
@@ -86,42 +85,80 @@ public class AccountingService {
return scopeData;
}
-
- public ReportData getReport(RequestReportData requestReportData) throws ServiceException {
+
+ public ReportData getReport(HttpServletRequest httpServletRequest, RequestReportData requestReportData)
+ throws ServiceException {
try {
- logger.debug("AccountingService GetReport()");
-
- ScopeDescriptor scopeDescriptor=searchScopeDescriptor(requestReportData.getScopeData());
-
- int yearFrom=Integer.parseInt(requestReportData.getYearFrom());
- int monthFrom=Integer.parseInt(requestReportData.getMonthFrom());
-
- int yearTo=Integer.parseInt(requestReportData.getYearTo());
- int monthTo=Integer.parseInt(requestReportData.getMonthTo());
-
-
-
- Date from=new GregorianCalendar(yearFrom, monthFrom, 1).getTime();
- Date to=new GregorianCalendar(yearTo, monthTo, 1).getTime();
-
-
- Report report = dao.getReportByScope(scopeDescriptor, from, to,MeasureResolution.MONTHLY);
-
- logger.debug("Report: " + report);
- ReportData reportData=new ReportData();
-
- return reportData;
-
+ logger.debug("AccountingService GetReport(): " + requestReportData);
+ if (requestReportData != null && requestReportData.getScopeData() != null
+ && requestReportData.getScopeData().getId() != null
+ && !requestReportData.getScopeData().getId().isEmpty()) {
+
+ ScopeDescriptor scopeDescriptor = searchScopeDescriptor(httpServletRequest,
+ requestReportData.getScopeData());
+ Date dateFrom = requestReportData.getDateFrom();
+ Date dateTo = requestReportData.getDateTo();
+
+ Report report = dao.getReportByScope(scopeDescriptor, dateFrom, dateTo, MeasureResolution.MONTHLY);
+
+ logger.debug("Report: " + report);
+ ReportData reportData = new ReportData();
+ return reportData;
+ } else {
+ throw new ServiceException("Invalid report request, " + requestReportData);
+ }
} catch (Throwable e) {
- logger.error("Error retrieving Tree: " + e.getLocalizedMessage(), e);
- throw new ServiceException("Error retrieving Tree: " + e.getLocalizedMessage(), e);
+ logger.error("Error in crete report: " + e.getLocalizedMessage(), e);
+ throw new ServiceException("Error in create report: " + e.getLocalizedMessage(), e);
}
}
-
- private ScopeDescriptor searchScopeDescriptor(ScopeData scopeData){
- return null;
+
+ private ScopeDescriptor searchScopeDescriptor(HttpServletRequest httpServletRequest, ScopeData scopeData)
+ throws ServiceException {
+ try {
+ ScopeDescriptor scopeDescriptor = dao.getTree(httpServletRequest);
+ logger.debug("ScopeDescriptor: " + scopeDescriptor);
+ if (scopeDescriptor.getId().compareTo(scopeData.getId()) == 0) {
+ return scopeDescriptor;
+ } else {
+ if (scopeDescriptor.hasChildren()) {
+ return searchScopeDescriptorInChildren(scopeDescriptor, scopeData);
+ } else {
+ return null;
+ }
+
+ }
+
+ } catch (Throwable e) {
+ logger.error("Error searching scope descriptor: " + e.getLocalizedMessage(), e);
+ throw new ServiceException("Error searching scope descriptor: " + e.getLocalizedMessage(), e);
+ }
+ }
+
+ private ScopeDescriptor searchScopeDescriptorInChildren(ScopeDescriptor scopeDescriptor, ScopeData scopeData)
+ throws ServiceException {
+ try {
+ logger.debug("ScopeDescriptor: " + scopeDescriptor);
+ for(ScopeDescriptor child:scopeDescriptor.getChildren()){
+ if(child.getId().compareTo(scopeData.getId())==0){
+ return child;
+ } else {
+ if(child.hasChildren()){
+ ScopeDescriptor found=searchScopeDescriptorInChildren(child, scopeData);
+ if(found!=null){
+ return found;
+ }
+ }
+ }
+
+ }
+ return null;
+
+ } catch (Throwable e) {
+ logger.error("Error searching scope descriptor: " + e.getLocalizedMessage(), e);
+ throw new ServiceException("Error searching scope descriptor: " + e.getLocalizedMessage(), e);
+ }
}
-
}
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 4ac0fa8..89b3e49 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
@@ -11,8 +11,8 @@ import javax.servlet.http.HttpServletRequest;
import org.gcube.common.portal.GCubePortalConstants;
import org.gcube.common.portal.PortalContext;
-import org.gcube.data.access.accounting.summary.access.impl.ContextTreeProvider;
-import org.gcube.data.access.accounting.summary.access.model.ScopeDescriptor;
+import org.gcube.accounting.accounting.summary.access.impl.ContextTreeProvider;
+import org.gcube.accounting.accounting.summary.access.model.ScopeDescriptor;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/data/RecordData.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/data/RecordData.java
new file mode 100644
index 0000000..124201e
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/data/RecordData.java
@@ -0,0 +1,47 @@
+package org.gcube.portlets.user.accountingdashboard.shared.data;
+
+import java.io.Serializable;
+
+/**
+ *
+ * @author Giancarlo Panichi
+ *
+ */
+public class RecordData implements Serializable {
+
+ private static final long serialVersionUID = -7526935477801214643L;
+ private String x;
+ private Long y;
+
+ public RecordData() {
+ super();
+ }
+
+ public RecordData(String x, Long y) {
+ super();
+ this.x = x;
+ this.y = y;
+ }
+
+ public String getX() {
+ return x;
+ }
+
+ public void setX(String x) {
+ this.x = x;
+ }
+
+ public Long getY() {
+ return y;
+ }
+
+ public void setY(Long y) {
+ this.y = y;
+ }
+
+ @Override
+ public String toString() {
+ return "RecordData [x=" + x + ", y=" + y + "]";
+ }
+
+}
diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/data/ReportData.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/data/ReportData.java
index d40b8b8..c765859 100644
--- a/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/data/ReportData.java
+++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/data/ReportData.java
@@ -1,6 +1,7 @@
package org.gcube.portlets.user.accountingdashboard.shared.data;
import java.io.Serializable;
+import java.util.ArrayList;
/**
*
@@ -10,8 +11,28 @@ import java.io.Serializable;
public class ReportData implements Serializable {
private static final long serialVersionUID = -2420024317463146907L;
+ private ArrayList elements;
+
+ public ReportData() {
+ super();
+ }
+
+ public ReportData(ArrayList elements) {
+ super();
+ this.elements = elements;
+ }
+
+ public ArrayList getElements() {
+ return elements;
+ }
+
+ public void setElements(ArrayList elements) {
+ this.elements = elements;
+ }
+
+ @Override
+ public String toString() {
+ return "ReportData [elements=" + elements + "]";
+ }
-
-
-
}
diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/data/ReportElementData.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/data/ReportElementData.java
new file mode 100644
index 0000000..aa88deb
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/data/ReportElementData.java
@@ -0,0 +1,80 @@
+package org.gcube.portlets.user.accountingdashboard.shared.data;
+
+import java.io.Serializable;
+import java.util.Arrays;
+
+/**
+ *
+ * @author Giancarlo Panichi
+ *
+ */
+public class ReportElementData implements Serializable {
+
+ private static final long serialVersionUID = -4942929709611742287L;
+ private String label;
+ private String category;
+ private String xAxis;
+ private String yAxis;
+
+ private SeriesData[] serieses;
+
+ public ReportElementData() {
+ super();
+ }
+
+ public ReportElementData(String label, String category, String xAxis, String yAxis, SeriesData[] serieses) {
+ super();
+ this.label = label;
+ this.category = category;
+ this.xAxis = xAxis;
+ this.yAxis = yAxis;
+ this.serieses = serieses;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public String getCategory() {
+ return category;
+ }
+
+ public void setCategory(String category) {
+ this.category = category;
+ }
+
+ public String getxAxis() {
+ return xAxis;
+ }
+
+ public void setxAxis(String xAxis) {
+ this.xAxis = xAxis;
+ }
+
+ public String getyAxis() {
+ return yAxis;
+ }
+
+ public void setyAxis(String yAxis) {
+ this.yAxis = yAxis;
+ }
+
+ public SeriesData[] getSerieses() {
+ return serieses;
+ }
+
+ public void setSerieses(SeriesData[] serieses) {
+ this.serieses = serieses;
+ }
+
+ @Override
+ public String toString() {
+ return "ReportElementData [label=" + label + ", category=" + category + ", xAxis=" + xAxis + ", yAxis=" + yAxis
+ + ", serieses=" + Arrays.toString(serieses) + "]";
+ }
+
+}
diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/data/RequestReportData.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/data/RequestReportData.java
index 0ec04f7..c3791ec 100644
--- a/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/data/RequestReportData.java
+++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/data/RequestReportData.java
@@ -1,6 +1,7 @@
package org.gcube.portlets.user.accountingdashboard.shared.data;
import java.io.Serializable;
+import java.util.Date;
/**
*
@@ -11,22 +12,18 @@ public class RequestReportData implements Serializable {
private static final long serialVersionUID = -7428707426843173730L;
private ScopeData scopeData;
- private String yearFrom;
- private String monthFrom;
- private String yearTo;
- private String monthTo;
+ private Date dateFrom;
+ private Date dateTo;
public RequestReportData() {
super();
}
- public RequestReportData(ScopeData scopeData, String yearFrom, String monthFrom, String yearTo, String monthTo) {
+ public RequestReportData(ScopeData scopeData, Date dateFrom, Date dateTo) {
super();
this.scopeData = scopeData;
- this.yearFrom = yearFrom;
- this.monthFrom = monthFrom;
- this.yearTo = yearTo;
- this.monthTo = monthTo;
+ this.dateFrom = dateFrom;
+ this.dateTo = dateTo;
}
public ScopeData getScopeData() {
@@ -37,42 +34,25 @@ public class RequestReportData implements Serializable {
this.scopeData = scopeData;
}
- public String getYearFrom() {
- return yearFrom;
+ public Date getDateFrom() {
+ return dateFrom;
}
- public void setYearFrom(String yearFrom) {
- this.yearFrom = yearFrom;
+ public void setDateFrom(Date dateFrom) {
+ this.dateFrom = dateFrom;
}
- public String getMonthFrom() {
- return monthFrom;
+ public Date getDateTo() {
+ return dateTo;
}
- public void setMonthFrom(String monthFrom) {
- this.monthFrom = monthFrom;
- }
-
- public String getYearTo() {
- return yearTo;
- }
-
- public void setYearTo(String yearTo) {
- this.yearTo = yearTo;
- }
-
- public String getMonthTo() {
- return monthTo;
- }
-
- public void setMonthTo(String monthTo) {
- this.monthTo = monthTo;
+ public void setDateTo(Date dateTo) {
+ this.dateTo = dateTo;
}
@Override
public String toString() {
- return "RequestReport [scopeData=" + scopeData + ", yearFrom=" + yearFrom + ", monthFrom=" + monthFrom
- + ", yearTo=" + yearTo + ", monthTo=" + monthTo + "]";
+ return "RequestReportData [scopeData=" + scopeData + ", dateFrom=" + dateFrom + ", dateTo=" + dateTo + "]";
}
}
diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/data/SeriesData.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/data/SeriesData.java
new file mode 100644
index 0000000..93816aa
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/data/SeriesData.java
@@ -0,0 +1,48 @@
+package org.gcube.portlets.user.accountingdashboard.shared.data;
+
+import java.io.Serializable;
+import java.util.Arrays;
+
+/**
+ *
+ * @author Giancarlo Panichi
+ *
+ */
+public class SeriesData implements Serializable {
+
+ private static final long serialVersionUID = 3308676516412447011L;
+ private String label;
+ private RecordData[] dataRow;
+
+ public SeriesData() {
+ super();
+ }
+
+ public SeriesData(String label, RecordData[] dataRow) {
+ super();
+ this.label = label;
+ this.dataRow = dataRow;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public RecordData[] getDataRow() {
+ return dataRow;
+ }
+
+ public void setDataRow(RecordData[] dataRow) {
+ this.dataRow = dataRow;
+ }
+
+ @Override
+ public String toString() {
+ return "SeriesData [label=" + label + ", dataRow=" + Arrays.toString(dataRow) + "]";
+ }
+
+}