ref 12119:AccountingDashboard - Create a new Accounting Dashboard

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

Updated Report support

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/accounting-dashboard@169812 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2018-07-17 17:15:10 +00:00
parent 845f76b807
commit 0e7b25e06f
15 changed files with 394 additions and 277 deletions

View File

@ -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());
}

View File

@ -10,10 +10,9 @@
<!-- styleName="{style.popup}" -->
<g:DialogBox ui:field="dialogBox" styleName="{res.uiDataCss.uiDataPopup}"
glassStyleName="{res.uiDataCss.uiDataPopupGlass}" glassEnabled="true">
<g:caption>
<b>Error</b>
</g:caption>
<g:caption><span class="{res.uiDataCss.uiDataPopupCaption}">Error</span></g:caption>
<g:HTMLPanel>
<hr class="{res.uiDataCss.uiDataPopupHr}"/>
<b:Container>
<b:Paragraph ui:field="errorMsg">
</b:Paragraph>

View File

@ -10,10 +10,9 @@
<!-- styleName="{style.popup}" -->
<g:DialogBox ui:field="dialogBox" styleName="{res.uiDataCss.uiDataPopup}"
glassStyleName="{res.uiDataCss.uiDataPopupGlass}" glassEnabled="true">
<g:caption>
<b>Error</b>
</g:caption>
<g:caption><span class="{res.uiDataCss.uiDataPopupCaption}">Info</span></g:caption>
<g:HTMLPanel>
<hr class="{res.uiDataCss.uiDataPopupHr}"/>
<b:Container>
<b:Paragraph ui:field="infoMsg">
</b:Paragraph>

View File

@ -9,9 +9,11 @@
<g:DialogBox ui:field="dialogBox" styleName="{res.uiDataCss.uiDataMonitorPopup}"
glassStyleName="{res.uiDataCss.uiDataMonitorPopupGlass}" glassEnabled="true">
<g:caption>
<b>Please wait</b>
<span class="{res.uiDataCss.uiDataPopupCaption}">Please wait...</span>
</g:caption>
<g:HTMLPanel width="300px" styleName="{res.uiDataCss.uiDataMonitorPopupProgress}">
<g:HTMLPanel width="300px"
styleName="{res.uiDataCss.uiDataMonitorPopupProgress}">
<hr class="{res.uiDataCss.uiDataPopupHr}" />
<b:ProgressBar type="ANIMATED" percent="100" text="In progress..." />
</g:HTMLPanel>
</g:DialogBox>

View File

@ -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<FilterAreaPresenter.Fil
@Override
public void getReport(RequestReportData requestReportData) {
controller.getReport(requestReportData);
if(checkDate(requestReportData.getDateFrom(),requestReportData.getDateTo())){
controller.getReport(requestReportData);
}
}
private boolean checkDate(Date dateStart, Date dateEnd) {
if (dateStart.compareTo(dateEnd) > 0) {
controller.errorShow("Attention the start date must be less than the end date!");
return false;
} else {
return true;
}
}
}

View File

@ -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<FilterAreaPresenter>
CellTree scopeTree;
private ListDataProvider<ScopeData> dataProvider;
private ScopeTreeModel scopeTreeModel;
@SuppressWarnings("unused")
private AppResources resources;
@ -93,13 +97,30 @@ public class FilterAreaView extends ViewWithUiHandlers<FilterAreaPresenter>
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,9 +137,27 @@ public class FilterAreaView extends ViewWithUiHandlers<FilterAreaPresenter>
}
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<ScopeData>();
@ -132,25 +171,23 @@ public class FilterAreaView extends ViewWithUiHandlers<FilterAreaPresenter>
}
};
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<ScopeData> 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();
}
@ -162,12 +199,12 @@ public class FilterAreaView extends ViewWithUiHandlers<FilterAreaPresenter>
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);
}
@ -176,18 +213,18 @@ public class FilterAreaView extends ViewWithUiHandlers<FilterAreaPresenter>
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);
}

View File

@ -46,10 +46,17 @@ public class ScopeTreeModel implements TreeViewModel {
});
}
/**
* Get the {@link NodeInfo} that provides the children of the specified
* value.
*/
public void setSelected(ScopeData item, boolean selected){
selectionModel.setSelected(item, selected);
}
public boolean isSelected(ScopeData item){
return selectionModel.isSelected(item);
}
@Override
public <T> NodeInfo<?> getNodeInfo(T value) {
if (value == null) {
@ -83,6 +90,7 @@ public class ScopeTreeModel implements TreeViewModel {
}
}
};
return new DefaultNodeInfo<ScopeData>(dataProvider, cell, selectionModel, null);
}
@ -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.

View File

@ -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<ReportAreaPresenter.Rep
}
@SuppressWarnings("unused")
private EventBus eventBus;
private Controller controller;

View File

@ -13,6 +13,9 @@ import org.gcube.portlets.user.accountingdashboard.shared.data.ReportElementData
import com.github.gwtbootstrap.client.ui.Tab;
import com.github.gwtbootstrap.client.ui.TabPanel;
import com.github.gwtbootstrap.client.ui.base.IconAnchor;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.HTMLPanel;
@ -35,6 +38,8 @@ public class ReportAreaView extends ViewWithUiHandlers<ReportAreaPresenter>
@UiField
HTMLPanel reportPanel;
private HashMap<String, ArrayList<Chart>> categories;
private AppResources resources;
@Inject
@ -42,119 +47,67 @@ public class ReportAreaView extends ViewWithUiHandlers<ReportAreaPresenter>
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<ReportElementData> 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<String, ArrayList<Chart>> 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<Chart> 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);
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<Chart> chartsInCategory = categories.get(category);
// logger.fine("Charts List:"+chartsInCategory);
if (chartsInCategory != null) {
for (Chart chart : chartsInCategory) {
chart.forceLayout();
}
}
}
});
tab.add(tabContent);
tabPanel.add(tab);
}

View File

@ -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);
}-*/;

View File

@ -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();

View File

@ -57,6 +57,7 @@
/* Chart */
.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;

View File

@ -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) {

View File

@ -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);
}
}
@ -164,4 +183,83 @@ public class AccountingService {
}
}
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<ReportElementData> 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;
}
}

View File

@ -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<VRECategory,ArrayList<VRE>> gatewayTree=getPortalSitesMappedToVRE(request);
LinkedHashMap<VRECategory, ArrayList<VRE>> gatewayTree = getPortalSitesMappedToVRE(request);
log.debug("Parsing tree from gateway. Size {} ",gatewayTree.size());
log.debug("Parsing tree from gateway. Size {} ", gatewayTree.size());
LinkedList<ScopeDescriptor> rootChildren=new LinkedList<>();
for(Entry<VRECategory,ArrayList<VRE>> entry:gatewayTree.entrySet()) {
ScopeDescriptor rootChild=new ScopeDescriptor(entry.getKey().name, entry.getKey().categoryID+"");
for(VRE vre:entry.getValue())
LinkedList<ScopeDescriptor> rootChildren = new LinkedList<>();
for (Entry<VRECategory, ArrayList<VRE>> 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<VRECategory, ArrayList<VRE>>
getPortalSitesMappedToVRE(HttpServletRequest request) throws Exception {
private LinkedHashMap<VRECategory, ArrayList<VRE>> getPortalSitesMappedToVRE(HttpServletRequest request)
throws Exception {
LinkedHashMap<VRECategory, ArrayList<VRE>> toReturn = new LinkedHashMap<VRECategory, ArrayList<VRE>>();
long currentSiteGroupId = getSiteFromServletRequest(request).getGroupId();
List<VirtualGroup> currentSiteVGroups = groupsManager.getVirtualGroups(currentSiteGroupId);
List<VirtualGroup> currentSiteVGroups = groupsManager.getVirtualGroups(currentSiteGroupId);
for (VirtualGroup vg : currentSiteVGroups) {
ArrayList<VRE> toCreate = new ArrayList<VRE>();
@ -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,38 +106,46 @@ 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<VirtualGroup> vreGroups = groupsManager.getVirtualGroups(vreID);
List<VirtualGroup> 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<VRE> 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);
}
}
@ -158,7 +153,7 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
}
}
//sort the vres in the groups
// sort the vres in the groups
for (VRECategory cat : toReturn.keySet()) {
ArrayList<VRE> 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;
}
@ -222,15 +211,13 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
}
private class VRE implements Comparable<VRE>{
private class VRE implements Comparable<VRE> {
private String name;
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="