ref 12119:AccountingDashboard - Create a new Accounting Dashboard

https://support.d4science.org/issues/12119

Updated Report 

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/accounting-dashboard@169744 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2018-07-10 15:50:37 +00:00
parent 4487da2f9b
commit 5c3fef96d0
11 changed files with 348 additions and 90 deletions

View File

@ -249,7 +249,7 @@
<!-- accounting-summary-access --> <!-- accounting-summary-access -->
<dependency> <dependency>
<groupId>org.gcube.data.access</groupId> <groupId>org.gcube.accounting</groupId>
<artifactId>accounting-summary-access</artifactId> <artifactId>accounting-summary-access</artifactId>
<version>[0.0.1-SNAPSHOT,2.0.0-SNAPSHOT)</version> <version>[0.0.1-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency> </dependency>

View File

@ -109,17 +109,20 @@ public class Controller {
} }
public void getReport(RequestReportData requestReportData) { public void getReport(RequestReportData requestReportData) {
monitorPresenter.enable(true);
service.getReport(requestReportData, new AsyncCallback<ReportData>() { service.getReport(requestReportData, new AsyncCallback<ReportData>() {
@Override @Override
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
logger.log(Level.FINE, "Error in getReport(): ", caught); logger.log(Level.FINE, "Error in getReport(): ", caught);
monitorPresenter.enable(false);
errorPresenter.errorMessage(caught.getLocalizedMessage()); errorPresenter.errorMessage(caught.getLocalizedMessage());
} }
@Override @Override
public void onSuccess(ReportData reportData) { public void onSuccess(ReportData reportData) {
logger.log(Level.FINE, "ReportData: " + reportData); logger.log(Level.FINE, "ReportData: " + reportData);
monitorPresenter.enable(false);
// ScopeDataEvent event = new ScopeDataEvent(scopeData); // ScopeDataEvent event = new ScopeDataEvent(scopeData);
// eventBus.fireEvent(event); // eventBus.fireEvent(event);
} }

View File

@ -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.application.mainarea.filter.scopetree.ScopeTreeModel;
import org.gcube.portlets.user.accountingdashboard.client.resources.AppResources; import org.gcube.portlets.user.accountingdashboard.client.resources.AppResources;
import org.gcube.portlets.user.accountingdashboard.client.resources.ScopeTreeResources; 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 org.gcube.portlets.user.accountingdashboard.shared.data.ScopeData;
import com.github.gwtbootstrap.client.ui.ListBox; 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.cellview.client.TreeNode;
import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget; 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.google.gwt.view.client.ListDataProvider;
import com.gwtplatform.mvp.client.ViewWithUiHandlers; import com.gwtplatform.mvp.client.ViewWithUiHandlers;
/** /**
@ -40,8 +43,6 @@ public class FilterAreaView extends ViewWithUiHandlers<FilterAreaPresenter>
interface Binder extends UiBinder<Widget, FilterAreaView> { interface Binder extends UiBinder<Widget, FilterAreaView> {
} }
@UiField @UiField
HTMLPanel periodPanel; HTMLPanel periodPanel;
@ -68,6 +69,8 @@ public class FilterAreaView extends ViewWithUiHandlers<FilterAreaPresenter>
@SuppressWarnings("unused") @SuppressWarnings("unused")
private AppResources resources; private AppResources resources;
private ScopeData scopeData;
@Inject @Inject
FilterAreaView(Binder uiBinder, AppResources resources) { FilterAreaView(Binder uiBinder, AppResources resources) {
this.resources = resources; this.resources = resources;
@ -108,34 +111,73 @@ public class FilterAreaView extends ViewWithUiHandlers<FilterAreaPresenter>
dataProvider = new ListDataProvider<ScopeData>(); dataProvider = new ListDataProvider<ScopeData>();
RequestReportEventHandler handler=new RequestReportEventHandler() { RequestReportEventHandler handler = new RequestReportEventHandler() {
@Override @Override
public void onData(RequestReportEvent event) { 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); ScopeTreeResources scopeTreeResources = GWT.create(ScopeTreeResources.class);
scopeTree = new CellTree(scopeTreeModel, null, scopeTreeResources); scopeTree = new CellTree(scopeTreeModel, null, scopeTreeResources);
} }
@Override @Override
public void displayScopeData(ScopeData scopeData) { public void displayScopeData(ScopeData scopeData) {
ArrayList<ScopeData> scopeDataList = new ArrayList<>(); ArrayList<ScopeData> scopeDataList = new ArrayList<>();
scopeDataList.add(scopeData); scopeDataList.add(scopeData);
this.scopeData=scopeData;
dataProvider.setList(scopeDataList); dataProvider.setList(scopeDataList);
dataProvider.refresh(); dataProvider.refresh();
dataProvider.flush(); dataProvider.flush();
TreeNode root = scopeTree.getRootTreeNode(); TreeNode root = scopeTree.getRootTreeNode();
root.setChildOpen(root.getIndex(), true); 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);
} }
} }

View File

@ -89,7 +89,7 @@ public class AccountingDashboardServiceImpl extends RemoteServiceServlet impleme
@SuppressWarnings("unused") @SuppressWarnings("unused")
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(this.getThreadLocalRequest()); ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(this.getThreadLocalRequest());
AccountingService as = new AccountingService(AccountingServiceType.PortalContex); AccountingService as = new AccountingService(AccountingServiceType.PortalContex);
ReportData reportData = as.getReport(requestReportData); ReportData reportData = as.getReport(this.getThreadLocalRequest(),requestReportData);
return reportData; return reportData;
} catch (ServiceException e) { } catch (ServiceException e) {

View File

@ -2,14 +2,13 @@ package org.gcube.portlets.user.accountingdashboard.server.accounting;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.gcube.data.access.accounting.summary.access.AccountingDao; import org.gcube.accounting.accounting.summary.access.AccountingDao;
import org.gcube.data.access.accounting.summary.access.model.MeasureResolution; import org.gcube.accounting.accounting.summary.access.model.MeasureResolution;
import org.gcube.data.access.accounting.summary.access.model.Report; import org.gcube.accounting.accounting.summary.access.model.Report;
import org.gcube.data.access.accounting.summary.access.model.ScopeDescriptor; 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.ReportData;
import org.gcube.portlets.user.accountingdashboard.shared.data.RequestReportData; 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.ScopeData;
@ -86,42 +85,80 @@ public class AccountingService {
return scopeData; return scopeData;
} }
public ReportData getReport(RequestReportData requestReportData) throws ServiceException { public ReportData getReport(HttpServletRequest httpServletRequest, RequestReportData requestReportData)
throws ServiceException {
try { try {
logger.debug("AccountingService GetReport()"); logger.debug("AccountingService GetReport(): " + requestReportData);
if (requestReportData != null && requestReportData.getScopeData() != null
ScopeDescriptor scopeDescriptor=searchScopeDescriptor(requestReportData.getScopeData()); && requestReportData.getScopeData().getId() != null
&& !requestReportData.getScopeData().getId().isEmpty()) {
int yearFrom=Integer.parseInt(requestReportData.getYearFrom());
int monthFrom=Integer.parseInt(requestReportData.getMonthFrom()); ScopeDescriptor scopeDescriptor = searchScopeDescriptor(httpServletRequest,
requestReportData.getScopeData());
int yearTo=Integer.parseInt(requestReportData.getYearTo()); Date dateFrom = requestReportData.getDateFrom();
int monthTo=Integer.parseInt(requestReportData.getMonthTo()); Date dateTo = requestReportData.getDateTo();
Report report = dao.getReportByScope(scopeDescriptor, dateFrom, dateTo, MeasureResolution.MONTHLY);
Date from=new GregorianCalendar(yearFrom, monthFrom, 1).getTime(); logger.debug("Report: " + report);
Date to=new GregorianCalendar(yearTo, monthTo, 1).getTime(); ReportData reportData = new ReportData();
return reportData;
} else {
Report report = dao.getReportByScope(scopeDescriptor, from, to,MeasureResolution.MONTHLY); throw new ServiceException("Invalid report request, " + requestReportData);
}
logger.debug("Report: " + report);
ReportData reportData=new ReportData();
return reportData;
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Error retrieving Tree: " + e.getLocalizedMessage(), e); logger.error("Error in crete report: " + e.getLocalizedMessage(), e);
throw new ServiceException("Error retrieving Tree: " + e.getLocalizedMessage(), e); throw new ServiceException("Error in create report: " + e.getLocalizedMessage(), e);
} }
} }
private ScopeDescriptor searchScopeDescriptor(ScopeData scopeData){ private ScopeDescriptor searchScopeDescriptor(HttpServletRequest httpServletRequest, ScopeData scopeData)
return null; 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);
}
} }
} }

View File

@ -11,8 +11,8 @@ import javax.servlet.http.HttpServletRequest;
import org.gcube.common.portal.GCubePortalConstants; import org.gcube.common.portal.GCubePortalConstants;
import org.gcube.common.portal.PortalContext; import org.gcube.common.portal.PortalContext;
import org.gcube.data.access.accounting.summary.access.impl.ContextTreeProvider; import org.gcube.accounting.accounting.summary.access.impl.ContextTreeProvider;
import org.gcube.data.access.accounting.summary.access.model.ScopeDescriptor; import org.gcube.accounting.accounting.summary.access.model.ScopeDescriptor;
import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup; import org.gcube.vomanagement.usermanagement.model.GCubeGroup;

View File

@ -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 + "]";
}
}

View File

@ -1,6 +1,7 @@
package org.gcube.portlets.user.accountingdashboard.shared.data; package org.gcube.portlets.user.accountingdashboard.shared.data;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
/** /**
* *
@ -10,8 +11,28 @@ import java.io.Serializable;
public class ReportData implements Serializable { public class ReportData implements Serializable {
private static final long serialVersionUID = -2420024317463146907L; private static final long serialVersionUID = -2420024317463146907L;
private ArrayList<ReportElementData> elements;
public ReportData() {
super();
}
public ReportData(ArrayList<ReportElementData> elements) {
super();
this.elements = elements;
}
public ArrayList<ReportElementData> getElements() {
return elements;
}
public void setElements(ArrayList<ReportElementData> elements) {
this.elements = elements;
}
@Override
public String toString() {
return "ReportData [elements=" + elements + "]";
}
} }

View File

@ -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) + "]";
}
}

View File

@ -1,6 +1,7 @@
package org.gcube.portlets.user.accountingdashboard.shared.data; package org.gcube.portlets.user.accountingdashboard.shared.data;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date;
/** /**
* *
@ -11,22 +12,18 @@ public class RequestReportData implements Serializable {
private static final long serialVersionUID = -7428707426843173730L; private static final long serialVersionUID = -7428707426843173730L;
private ScopeData scopeData; private ScopeData scopeData;
private String yearFrom; private Date dateFrom;
private String monthFrom; private Date dateTo;
private String yearTo;
private String monthTo;
public RequestReportData() { public RequestReportData() {
super(); super();
} }
public RequestReportData(ScopeData scopeData, String yearFrom, String monthFrom, String yearTo, String monthTo) { public RequestReportData(ScopeData scopeData, Date dateFrom, Date dateTo) {
super(); super();
this.scopeData = scopeData; this.scopeData = scopeData;
this.yearFrom = yearFrom; this.dateFrom = dateFrom;
this.monthFrom = monthFrom; this.dateTo = dateTo;
this.yearTo = yearTo;
this.monthTo = monthTo;
} }
public ScopeData getScopeData() { public ScopeData getScopeData() {
@ -37,42 +34,25 @@ public class RequestReportData implements Serializable {
this.scopeData = scopeData; this.scopeData = scopeData;
} }
public String getYearFrom() { public Date getDateFrom() {
return yearFrom; return dateFrom;
} }
public void setYearFrom(String yearFrom) { public void setDateFrom(Date dateFrom) {
this.yearFrom = yearFrom; this.dateFrom = dateFrom;
} }
public String getMonthFrom() { public Date getDateTo() {
return monthFrom; return dateTo;
} }
public void setMonthFrom(String monthFrom) { public void setDateTo(Date dateTo) {
this.monthFrom = monthFrom; this.dateTo = dateTo;
}
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;
} }
@Override @Override
public String toString() { public String toString() {
return "RequestReport [scopeData=" + scopeData + ", yearFrom=" + yearFrom + ", monthFrom=" + monthFrom return "RequestReportData [scopeData=" + scopeData + ", dateFrom=" + dateFrom + ", dateTo=" + dateTo + "]";
+ ", yearTo=" + yearTo + ", monthTo=" + monthTo + "]";
} }
} }

View File

@ -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) + "]";
}
}