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 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;
@ -67,13 +66,14 @@ public class AccountingService {
public ScopeData getTree(HttpServletRequest httpServletRequest) throws ServiceException {
try {
if(Constants.DEBUG_MODE){
return debugScope();
if (Constants.DEBUG_MODE) {
return debugScope();
}
logger.debug("AccountingService GetTree()");
ScopeDescriptor scopeDescriptor = dao.getTree(httpServletRequest);
logger.debug("ScopeDescriptor: " + scopeDescriptor);
ScopeData scopeData = getScopeData(scopeDescriptor);
ScopeData scopeData = getScopeData(scopeDescriptor, "");
logger.debug("ScopeData: " + scopeData);
return scopeData;
} catch (Throwable e) {
@ -82,19 +82,19 @@ public class AccountingService {
}
}
private ScopeData getScopeData(ScopeDescriptor scopeDescriptor) {
private ScopeData getScopeData(ScopeDescriptor scopeDescriptor, String parentScope) {
ScopeData scopeData = null;
if (scopeDescriptor != null) {
if (scopeDescriptor.hasChildren()) {
ArrayList<ScopeData> childs = new ArrayList<>();
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 {
scopeData = new ScopeData(scopeDescriptor.getId(), scopeDescriptor.getName(), null);
scopeData = new ScopeData(scopeDescriptor.getId(), scopeDescriptor.getName(),
parentScope + "/" + scopeDescriptor.getName(), null);
}
}
return scopeData;
@ -104,17 +104,18 @@ public class AccountingService {
public ReportData getReport(HttpServletRequest httpServletRequest, RequestReportData requestReportData)
throws ServiceException {
try {
if(Constants.DEBUG_MODE){
return debugReport();
if (Constants.DEBUG_MODE) {
return debugReport();
}
logger.debug("AccountingService GetReport(): " + requestReportData);
if (requestReportData != null && requestReportData.getScopeData() != null
&& requestReportData.getScopeData().getId() != null
&& !requestReportData.getScopeData().getId().isEmpty()) {
&& requestReportData.getScopeData().getScope() != null
&& !requestReportData.getScopeData().getScope().isEmpty()) {
ScopeDescriptor scopeDescriptor = searchScopeDescriptor(httpServletRequest,
requestReportData.getScopeData());
Date dateFrom = requestReportData.getDateFrom();
Date dateTo = requestReportData.getDateTo();
@ -139,55 +140,69 @@ public class AccountingService {
private ScopeDescriptor searchScopeDescriptor(HttpServletRequest httpServletRequest, ScopeData scopeData)
throws ServiceException {
try {
logger.debug("SearchScopeDescirptor(): ScopeData=" + scopeData);
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);
logger.debug("Service ScopeDescriptor: " + scopeDescriptor);
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;
}
} else {
return null;
throw new ServiceException("Scope descriptor not found: " + scopeToSearch);
}
} else {
throw new ServiceException("Scope descriptor not found: " + scopeToSearch);
}
} catch (ServiceException e) {
throw e;
} 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 {
private ScopeDescriptor searchInChild(ScopeDescriptor scopeDescriptor, String scopeToSearch, String[] searchPath,
int i) 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;
}
if (child.getName()!=null&&!child.getName().isEmpty()&&child.getName().compareTo(searchPath[i]) == 0) {
i++;
if (i < searchPath.length) {
return searchInChild(child, scopeToSearch, searchPath, i);
} else {
return child;
}
}
}
return null;
throw new ServiceException("Scope descriptor not found: " + scopeToSearch);
} catch (ServiceException e) {
throw e;
} catch (Throwable e) {
logger.error("Error searching scope descriptor: " + e.getLocalizedMessage(), e);
throw new ServiceException("Error searching scope descriptor: " + e.getLocalizedMessage(), e);
}
}
private ScopeData debugScope() {
ScopeData scopeData=new ScopeData("Debug", "Debug", null);
ScopeData scopeData = new ScopeData("Debug", "Debug", "/Debug", null);
return scopeData;
}
private ReportData debugReport() {

View File

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