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@169813 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2018-07-17 19:03:40 +00:00
parent 0e7b25e06f
commit b1e6fa5ec2
2 changed files with 68 additions and 43 deletions

View File

@ -5,7 +5,6 @@ import java.util.Date;
import javax.servlet.http.HttpServletRequest; 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.AccountingDao;
import org.gcube.accounting.accounting.summary.access.model.MeasureResolution; 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.Report;
@ -67,13 +66,14 @@ public class AccountingService {
public ScopeData getTree(HttpServletRequest httpServletRequest) throws ServiceException { public ScopeData getTree(HttpServletRequest httpServletRequest) throws ServiceException {
try { try {
if(Constants.DEBUG_MODE){ if (Constants.DEBUG_MODE) {
return debugScope(); return debugScope();
} }
logger.debug("AccountingService GetTree()"); logger.debug("AccountingService GetTree()");
ScopeDescriptor scopeDescriptor = dao.getTree(httpServletRequest); ScopeDescriptor scopeDescriptor = dao.getTree(httpServletRequest);
logger.debug("ScopeDescriptor: " + scopeDescriptor); logger.debug("ScopeDescriptor: " + scopeDescriptor);
ScopeData scopeData = getScopeData(scopeDescriptor); ScopeData scopeData = getScopeData(scopeDescriptor, "");
logger.debug("ScopeData: " + scopeData);
return scopeData; return scopeData;
} catch (Throwable e) { } catch (Throwable e) {
@ -82,19 +82,19 @@ public class AccountingService {
} }
} }
private ScopeData getScopeData(ScopeDescriptor scopeDescriptor, String parentScope) {
private ScopeData getScopeData(ScopeDescriptor scopeDescriptor) {
ScopeData scopeData = null; ScopeData scopeData = null;
if (scopeDescriptor != null) { if (scopeDescriptor != null) {
if (scopeDescriptor.hasChildren()) { if (scopeDescriptor.hasChildren()) {
ArrayList<ScopeData> childs = new ArrayList<>(); ArrayList<ScopeData> childs = new ArrayList<>();
for (ScopeDescriptor sd : scopeDescriptor.getChildren()) { for (ScopeDescriptor sd : scopeDescriptor.getChildren()) {
childs.add(getScopeData(sd)); childs.add(getScopeData(sd, parentScope + "/" + scopeDescriptor.getName()));
} }
scopeData = new ScopeData(scopeDescriptor.getId(), scopeDescriptor.getName(), childs); scopeData = new ScopeData(scopeDescriptor.getId(), scopeDescriptor.getName(),
parentScope + "/" + scopeDescriptor.getName(), childs);
} else { } else {
scopeData = new ScopeData(scopeDescriptor.getId(), scopeDescriptor.getName(), null); scopeData = new ScopeData(scopeDescriptor.getId(), scopeDescriptor.getName(),
parentScope + "/" + scopeDescriptor.getName(), null);
} }
} }
return scopeData; return scopeData;
@ -104,17 +104,18 @@ public class AccountingService {
public ReportData getReport(HttpServletRequest httpServletRequest, RequestReportData requestReportData) public ReportData getReport(HttpServletRequest httpServletRequest, RequestReportData requestReportData)
throws ServiceException { throws ServiceException {
try { try {
if(Constants.DEBUG_MODE){ if (Constants.DEBUG_MODE) {
return debugReport(); return debugReport();
} }
logger.debug("AccountingService GetReport(): " + requestReportData); logger.debug("AccountingService GetReport(): " + requestReportData);
if (requestReportData != null && requestReportData.getScopeData() != null if (requestReportData != null && requestReportData.getScopeData() != null
&& requestReportData.getScopeData().getId() != null && requestReportData.getScopeData().getScope() != null
&& !requestReportData.getScopeData().getId().isEmpty()) { && !requestReportData.getScopeData().getScope().isEmpty()) {
ScopeDescriptor scopeDescriptor = searchScopeDescriptor(httpServletRequest, ScopeDescriptor scopeDescriptor = searchScopeDescriptor(httpServletRequest,
requestReportData.getScopeData()); requestReportData.getScopeData());
Date dateFrom = requestReportData.getDateFrom(); Date dateFrom = requestReportData.getDateFrom();
Date dateTo = requestReportData.getDateTo(); Date dateTo = requestReportData.getDateTo();
@ -139,44 +140,59 @@ public class AccountingService {
private ScopeDescriptor searchScopeDescriptor(HttpServletRequest httpServletRequest, ScopeData scopeData) private ScopeDescriptor searchScopeDescriptor(HttpServletRequest httpServletRequest, ScopeData scopeData)
throws ServiceException { throws ServiceException {
try { try {
logger.debug("SearchScopeDescirptor(): ScopeData=" + scopeData);
ScopeDescriptor scopeDescriptor = dao.getTree(httpServletRequest); ScopeDescriptor scopeDescriptor = dao.getTree(httpServletRequest);
logger.debug("ScopeDescriptor: " + scopeDescriptor); logger.debug("Service ScopeDescriptor: " + scopeDescriptor);
if (scopeDescriptor.getId().compareTo(scopeData.getId()) == 0) { String scopeToSearch = scopeData.getScope();
logger.debug("Scope request: " + scopeToSearch);
String[] searchPath = scopeToSearch.split("\\/");
if (searchPath == null || searchPath.length == 0) {
logger.error("Error searching scope descriptor: scope=" + searchPath);
throw new ServiceException("Scope=" + searchPath);
}
logger.debug("Search path: " + searchPath);
if (searchPath.length > 1) {
int i = 1;
String segment = searchPath[i];
if (scopeDescriptor.getName().compareTo(segment) == 0) {
i++;
if (i < searchPath.length) {
return searchInChild(scopeDescriptor, scopeToSearch, searchPath, i);
} else {
return scopeDescriptor; return scopeDescriptor;
}
} else { } else {
if (scopeDescriptor.hasChildren()) { throw new ServiceException("Scope descriptor not found: " + scopeToSearch);
return searchScopeDescriptorInChildren(scopeDescriptor, scopeData); }
} else { } else {
return null; throw new ServiceException("Scope descriptor not found: " + scopeToSearch);
}
} }
} catch (ServiceException e) {
throw e;
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Error searching scope descriptor: " + e.getLocalizedMessage(), e); logger.error("Error searching scope descriptor: " + e.getLocalizedMessage(), e);
throw new ServiceException("Error searching scope descriptor: " + e.getLocalizedMessage(), e); throw new ServiceException("Error searching scope descriptor: " + e.getLocalizedMessage(), e);
} }
} }
private ScopeDescriptor searchScopeDescriptorInChildren(ScopeDescriptor scopeDescriptor, ScopeData scopeData) private ScopeDescriptor searchInChild(ScopeDescriptor scopeDescriptor, String scopeToSearch, String[] searchPath,
throws ServiceException { int i) throws ServiceException {
try { try {
logger.debug("ScopeDescriptor: " + scopeDescriptor);
for (ScopeDescriptor child : scopeDescriptor.getChildren()) { for (ScopeDescriptor child : scopeDescriptor.getChildren()) {
if (child.getId().compareTo(scopeData.getId()) == 0) { if (child.getName()!=null&&!child.getName().isEmpty()&&child.getName().compareTo(searchPath[i]) == 0) {
return child; i++;
if (i < searchPath.length) {
return searchInChild(child, scopeToSearch, searchPath, i);
} else { } else {
if (child.hasChildren()) { return child;
ScopeDescriptor found = searchScopeDescriptorInChildren(child, scopeData);
if (found != null) {
return found;
} }
} }
} }
throw new ServiceException("Scope descriptor not found: " + scopeToSearch);
} } catch (ServiceException e) {
return null; throw e;
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Error searching scope descriptor: " + e.getLocalizedMessage(), e); logger.error("Error searching scope descriptor: " + e.getLocalizedMessage(), e);
throw new ServiceException("Error searching scope descriptor: " + e.getLocalizedMessage(), e); throw new ServiceException("Error searching scope descriptor: " + e.getLocalizedMessage(), e);
@ -184,11 +200,10 @@ public class AccountingService {
} }
private ScopeData debugScope() { private ScopeData debugScope() {
ScopeData scopeData=new ScopeData("Debug", "Debug", null); ScopeData scopeData = new ScopeData("Debug", "Debug", "/Debug", null);
return scopeData; return scopeData;
} }
private ReportData debugReport() { private ReportData debugReport() {
RecordData recordData1 = new RecordData(); RecordData recordData1 = new RecordData();

View File

@ -15,16 +15,18 @@ public class ScopeData implements Serializable, Comparator<ScopeData>, Comparabl
private static final long serialVersionUID = -8445665293115680236L; private static final long serialVersionUID = -8445665293115680236L;
private String id; private String id;
private String name; private String name;
private String scope;
private ArrayList<ScopeData> children; private ArrayList<ScopeData> children;
public ScopeData() { public ScopeData() {
super(); super();
} }
public ScopeData(String id, String name, ArrayList<ScopeData> children) { public ScopeData(String id, String name, String scope, ArrayList<ScopeData> children) {
super(); super();
this.id = id; this.id = id;
this.name = name; this.name = name;
this.scope = scope;
this.children = children; this.children = children;
} }
@ -44,6 +46,14 @@ public class ScopeData implements Serializable, Comparator<ScopeData>, Comparabl
this.name = name; this.name = name;
} }
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
public ArrayList<ScopeData> getChildren() { public ArrayList<ScopeData> getChildren() {
return children; return children;
} }
@ -66,8 +76,8 @@ public class ScopeData implements Serializable, Comparator<ScopeData>, Comparabl
} else { } else {
int diff = -1; int diff = -1;
if (o1 != null) { if (o1 != null) {
if (o1.getId() != null) { if (o1.getScope() != null) {
diff = ((o2 != null) && (o2.getId() != null)) ? o1.getId().compareTo(o2.getId()) : 1; diff = ((o2 != null) && (o2.getScope() != null)) ? o1.getScope().compareTo(o2.getScope()) : 1;
} }
} }
return diff; return diff;
@ -83,7 +93,7 @@ public class ScopeData implements Serializable, Comparator<ScopeData>, Comparabl
@Override @Override
public String toString() { public String toString() {
return "ScopeData [id=" + id + ", name=" + name + ", children=" + children + "]"; return "ScopeData [id=" + id + ", name=" + name + ", scope=" + scope + ", children=" + children + "]";
} }
} }