ref 18815: Accounting Dashboard Reminiscence

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

Added detachedres-library
Future/18815
Giancarlo Panichi 4 years ago
parent d5266a0b7c
commit 82361090f7

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry including="**/*.java" kind="src" output="target/accounting-dashboard-1.2.0/WEB-INF/classes" path="src/main/java">
<classpathentry including="**/*.java" kind="src" output="target/accounting-dashboard-1.3.0/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/accounting-dashboard-1.2.0/WEB-INF/classes" path="src/main/resources">
<classpathentry excluding="**" kind="src" output="target/accounting-dashboard-1.3.0/WEB-INF/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@ -50,5 +50,5 @@
</classpathentry>
<classpathentry kind="lib" path="/home/giancarlo/gwt/gwt-2.8.2/validation-api-1.0.0.GA.jar" sourcepath="/home/giancarlo/gwt/gwt-2.8.2/validation-api-1.0.0.GA-sources.jar"/>
<classpathentry kind="lib" path="/home/giancarlo/gwt/gwt-2.8.2/validation-api-1.0.0.GA-sources.jar"/>
<classpathentry kind="output" path="target/accounting-dashboard-1.2.0/WEB-INF/classes"/>
<classpathentry kind="output" path="target/accounting-dashboard-1.3.0/WEB-INF/classes"/>
</classpath>

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="accounting-dashboard-1.2.0">
<wb-module deploy-name="accounting-dashboard-1.3.0">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>

@ -7,13 +7,13 @@
<groupId>org.gcube.tools</groupId>
<version>1.1.0</version>
<relativePath />
</parent>
</parent>
<!-- POM file generated with GWT webAppCreator -->
<modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>accounting-dashboard</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>
<packaging>war</packaging>
<name>accounting-dashboard</name>
@ -256,6 +256,14 @@
<version>[1.0.0,2.0.0-SNAPSHOT)</version>
</dependency>
<!-- detachedres-library -->
<dependency>
<groupId>org.gcube.infrastructure.detachedres</groupId>
<artifactId>detachedres-library</artifactId>
<version>[0.0.1,2.0.0-SNAPSHOT)</version>
</dependency>
<!-- Portal Service -->
<dependency>
<groupId>com.liferay.portal</groupId>

@ -13,6 +13,7 @@ import org.gcube.portlets.user.accountingdashboard.client.rpc.AccountingDashboar
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;
import org.gcube.portlets.user.accountingdashboard.shared.options.TreeOptions;
import org.gcube.portlets.user.accountingdashboard.shared.session.UserInfo;
import com.google.gwt.event.shared.EventBus;
@ -37,6 +38,7 @@ public class Controller {
private MonitorPresenter monitorPresenter;
private ErrorPresenter errorPresenter;
private InfoPresenter infoPresenter;
private TreeOptions treeOptions=null;
@Inject
Controller(@Named("ControllerEventBus") EventBus eventBus, AccountingDashboardServiceAsync service,
@ -47,6 +49,7 @@ public class Controller {
this.errorPresenter = errorPresenter;
this.infoPresenter = infoPresenter;
//this.cache = new ApplicationCache();
this.setTreeOptions(new TreeOptions(false));
}
@ -72,6 +75,14 @@ public class Controller {
infoPresenter.infoMessage(info);
}
public TreeOptions getTreeOptions() {
return treeOptions;
}
public void setTreeOptions(TreeOptions treeOptions) {
this.treeOptions = treeOptions;
}
public void hello() {
eventBus.fireEvent(new HelloEvent());
@ -102,7 +113,7 @@ public class Controller {
}
public void getTree() {
service.getScopeData(new AsyncCallback<ScopeData>() {
service.getScopeData(treeOptions,new AsyncCallback<ScopeData>() {
@Override
public void onFailure(Throwable caught) {
@ -123,7 +134,7 @@ public class Controller {
public void getReport(RequestReportData requestReportData) {
monitorPresenter.enable(true);
service.getReport(requestReportData, new AsyncCallback<ReportData>() {
service.getReport(requestReportData,treeOptions, new AsyncCallback<ReportData>() {
@Override
public void onFailure(Throwable caught) {
@ -144,4 +155,5 @@ public class Controller {
}
}

@ -4,6 +4,7 @@ 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;
import org.gcube.portlets.user.accountingdashboard.shared.exception.ServiceException;
import org.gcube.portlets.user.accountingdashboard.shared.options.TreeOptions;
import org.gcube.portlets.user.accountingdashboard.shared.session.UserInfo;
import com.google.gwt.user.client.rpc.RemoteService;
@ -26,8 +27,8 @@ public interface AccountingDashboardService extends RemoteService {
*/
public UserInfo hello() throws ServiceException;
public ScopeData getScopeData() throws ServiceException;
public ScopeData getScopeData(TreeOptions treeOptions) throws ServiceException;
public ReportData getReport(RequestReportData requestReportdata) throws ServiceException;
public ReportData getReport(RequestReportData requestReportdata, TreeOptions treeOptions) throws ServiceException;
}

@ -6,6 +6,7 @@ package org.gcube.portlets.user.accountingdashboard.client.rpc;
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;
import org.gcube.portlets.user.accountingdashboard.shared.options.TreeOptions;
import org.gcube.portlets.user.accountingdashboard.shared.session.UserInfo;
import com.google.gwt.core.client.GWT;
@ -24,8 +25,9 @@ public interface AccountingDashboardServiceAsync {
void hello(AsyncCallback<UserInfo> callback);
void getScopeData(AsyncCallback<ScopeData> callback);
void getScopeData(TreeOptions treeOptions, AsyncCallback<ScopeData> callback);
void getReport(RequestReportData requestReportdata, AsyncCallback<ReportData> asyncCallback);
void getReport(RequestReportData requestReportdata, TreeOptions treeOptions,
AsyncCallback<ReportData> asyncCallback);
}

@ -12,6 +12,7 @@ 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;
import org.gcube.portlets.user.accountingdashboard.shared.exception.ServiceException;
import org.gcube.portlets.user.accountingdashboard.shared.options.TreeOptions;
import org.gcube.portlets.user.accountingdashboard.shared.session.UserInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -65,11 +66,11 @@ public class AccountingDashboardServiceImpl extends RemoteServiceServlet impleme
}
@Override
public ScopeData getScopeData() throws ServiceException {
public ScopeData getScopeData(TreeOptions treeOptions) throws ServiceException {
try {
logger.debug("AccountingDashboardServiceImpl getScopeData()");
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(this.getThreadLocalRequest());
AccountingService as = new AccountingService(getAccountingContext(serviceCredentials.getScope()));
AccountingService as = new AccountingService(getAccountingContext(serviceCredentials.getScope()),treeOptions);
ScopeData scopeData = as.getTree(this.getThreadLocalRequest());
return scopeData;
} catch (ServiceException e) {
@ -83,11 +84,11 @@ public class AccountingDashboardServiceImpl extends RemoteServiceServlet impleme
}
@Override
public ReportData getReport(RequestReportData requestReportData) throws ServiceException {
public ReportData getReport(RequestReportData requestReportData,TreeOptions treeOptions) throws ServiceException {
try {
logger.debug("AccountingDashboardServiceImpl getReport(): " + requestReportData);
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(this.getThreadLocalRequest());
AccountingService as = new AccountingService(getAccountingContext(serviceCredentials.getScope()));
AccountingService as = new AccountingService(getAccountingContext(serviceCredentials.getScope()), treeOptions);
ReportData reportData = as.getReport(this.getThreadLocalRequest(), requestReportData);
return reportData;
} catch (ServiceException e) {

@ -17,6 +17,7 @@ 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.gcube.portlets.user.accountingdashboard.shared.options.TreeOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -31,7 +32,7 @@ public class AccountingService {
private AccountingDao dao;
public AccountingService(AccountingServiceType accountingServiceType) throws ServiceException {
public AccountingService(AccountingServiceType accountingServiceType, TreeOptions treeOptions) throws ServiceException {
try {
if (Constants.DEBUG_MODE) {
return;
@ -41,6 +42,7 @@ public class AccountingService {
logger.error("Invalid AccountingServiceType requested: null");
}
PortalContextTreeProvider portalContextTreeProvider=null;
switch (accountingServiceType) {
case CurrentScope:
logger.debug("AccountingService: CurrentScope");
@ -48,11 +50,14 @@ public class AccountingService {
break;
case PortalContex:
logger.debug("AccountingService: PortalContext");
dao = AccountingDao.get(new PortalContextTreeProvider(accountingServiceType));
portalContextTreeProvider=new PortalContextTreeProvider(accountingServiceType);
dao = AccountingDao.get(portalContextTreeProvider);
break;
case Infrastructure:
logger.debug("AccountingService: Infrastructure");
dao = AccountingDao.get(new PortalContextTreeProvider(accountingServiceType));
portalContextTreeProvider=new PortalContextTreeProvider(accountingServiceType);
portalContextTreeProvider.setTreeOptions(treeOptions);
dao = AccountingDao.get(portalContextTreeProvider);
break;
default:
logger.debug("AccountingService: CurrentScope");

@ -13,8 +13,13 @@ import org.gcube.accounting.accounting.summary.access.impl.ContextTreeProvider;
import org.gcube.accounting.accounting.summary.access.model.ScopeDescriptor;
import org.gcube.common.portal.GCubePortalConstants;
import org.gcube.common.portal.PortalContext;
import org.gcube.infrastructure.detachedres.detachedreslibrary.server.is.DetachedREsBuilder;
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.DetachedREs;
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.Gateway;
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VO;
import org.gcube.portlets.user.accountingdashboard.server.is.BuildInfraNode;
import org.gcube.portlets.user.accountingdashboard.shared.is.InfraNode;
import org.gcube.portlets.user.accountingdashboard.shared.options.TreeOptions;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
@ -42,8 +47,15 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
private static Logger logger = LoggerFactory.getLogger(PortalContextTreeProvider.class);
private AccountingServiceType accountingServiceType;
private TreeOptions treeOptions;
public PortalContextTreeProvider(AccountingServiceType accountingServiceType) {
this.accountingServiceType = accountingServiceType;
this.treeOptions = null;
}
public void setTreeOptions(TreeOptions treeOptions){
this.treeOptions=treeOptions;
}
static {
@ -74,7 +86,7 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
break;
case Infrastructure:
logger.debug("AccountingService: Infrastructure");
root = recreateTreeForInfrastructure(request);
root = recreateTreeForInfrastructure(request, treeOptions);
break;
default:
logger.debug("AccountingService: CurrentScope");
@ -85,7 +97,7 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
return root;
}
private ScopeDescriptor recreateTreeForInfrastructure(HttpServletRequest request)
private ScopeDescriptor recreateTreeForInfrastructure(HttpServletRequest request, TreeOptions treeOptions2)
throws Exception, PortalException, SystemException {
ScopeDescriptor infra = null;
PortalContext portalContext = PortalContext.getConfiguration();
@ -110,19 +122,19 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
currUser);
if (infraNode != null) {
String scopeGroup="";
if(gCubeGroup.getGroupName().toUpperCase().endsWith(" GATEWAY")){
int l=gCubeGroup.getGroupName().length();
scopeGroup=gCubeGroup.getGroupName().substring(0, l-8);
String scopeGroup = "";
if (gCubeGroup.getGroupName().toUpperCase().endsWith(" GATEWAY")) {
int l = gCubeGroup.getGroupName().length();
scopeGroup = gCubeGroup.getGroupName().substring(0, l - 8);
} else {
scopeGroup=gCubeGroup.getGroupName();
scopeGroup = gCubeGroup.getGroupName();
}
StringBuilder gatewayScope=new StringBuilder();
StringBuilder gatewayScope = new StringBuilder();
gatewayScope.append(infrastructureScope);
gatewayScope.append("/");
gatewayScope.append(scopeGroup);
ScopeDescriptor infraNodeScopeDescriptor = createRelativeInfraNode(infraNode, gatewayScope.toString());
if (gatewayChildren != null) {
gatewayChildren.addFirst(infraNodeScopeDescriptor);
@ -138,10 +150,59 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
infraChildren.add(gatewayScopeDescriptor);
}
if (treeOptions != null && treeOptions.isShowDetachedREs()) {
logger.debug("Show DestachedREs");
DetachedREs detachedREs = DetachedREsBuilder.build(infrastructureScope);
if (detachedREs != null && detachedREs.isEnabled()) {
logger.debug("DetachedREs is enabled");
if (detachedREs.getGateways() != null && !detachedREs.getGateways().isEmpty()) {
for (String key : detachedREs.getGateways().keySet()) {
Gateway gateway = detachedREs.getGateways().get(key);
ScopeDescriptor getewaySD = new ScopeDescriptor(gateway.getName(), key);
LinkedList<ScopeDescriptor> voChildren = retrieveVOChildren(gateway);
getewaySD.setChildren(voChildren);
infraChildren.add(getewaySD);
}
}
} else {
logger.debug("DetachedREs is disabled");
}
}
infra.setChildren(infraChildren);
return infra;
}
private LinkedList<ScopeDescriptor> retrieveVOChildren(Gateway gateway) {
if (gateway.getVos() != null && !gateway.getVos().isEmpty()) {
LinkedList<ScopeDescriptor> vos = new LinkedList<>();
for (String key : gateway.getVos().keySet()) {
VO vo = gateway.getVos().get(key);
ScopeDescriptor voSD = new ScopeDescriptor(vo.getName(), key);
LinkedList<ScopeDescriptor> voChildren = retrieveVREChildren(vo);
voSD.setChildren(voChildren);
vos.add(voSD);
}
return vos;
} else {
return null;
}
}
private LinkedList<ScopeDescriptor> retrieveVREChildren(VO vo) {
if (vo.getVres() != null && !vo.getVres().isEmpty()) {
LinkedList<ScopeDescriptor> vres = new LinkedList<>();
for (String key : vo.getVres().keySet()) {
org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VRE vre = vo.getVres().get(key);
ScopeDescriptor vreSD = new ScopeDescriptor(vre.getName(), key);
vres.add(vreSD);
}
return vres;
} else {
return null;
}
}
private ScopeDescriptor createRelativeInfraNode(InfraNode infraNode, String scope) {
StringBuilder absoluteScope = new StringBuilder();
absoluteScope.append(scope);
@ -164,28 +225,28 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
throws Exception, PortalException, SystemException {
ScopeDescriptor root;
Group group=getSiteFromServletRequest(request);
Group group = getSiteFromServletRequest(request);
long currentSiteGroupId = group.getGroupId();
String gatewayName=group.getName();
String gatewayName = group.getName();
PortalContext pContext = PortalContext.getConfiguration();
GCubeUser currUser = pContext.getCurrentUser(request);
String portalScope = pContext.getCurrentScope(currentSiteGroupId + "");
String scopeGroup="";
if(gatewayName.toUpperCase().endsWith(" GATEWAY")){
int l=gatewayName.length();
scopeGroup=gatewayName.substring(0, l-8);
String scopeGroup = "";
if (gatewayName.toUpperCase().endsWith(" GATEWAY")) {
int l = gatewayName.length();
scopeGroup = gatewayName.substring(0, l - 8);
} else {
scopeGroup=gatewayName;
scopeGroup = gatewayName;
}
StringBuilder gatewayScope=new StringBuilder();
StringBuilder gatewayScope = new StringBuilder();
gatewayScope.append(portalScope);
gatewayScope.append("/");
gatewayScope.append(scopeGroup);
InfraNode infraNode = BuildInfraNode.build(portalScope);
LinkedList<ScopeDescriptor> rootChildren = null;
rootChildren = retrieveGatewayChildren(request, currentSiteGroupId, currUser);

@ -0,0 +1,34 @@
package org.gcube.portlets.user.accountingdashboard.shared.options;
import java.io.Serializable;
/**
*
* @author Giancarlo Panichi
*
*/
public class TreeOptions implements Serializable {
private static final long serialVersionUID = 730133583251742872L;
private boolean showDetachedREs = false;
public TreeOptions(boolean showDetachedREs) {
super();
this.showDetachedREs = showDetachedREs;
}
public boolean isShowDetachedREs() {
return showDetachedREs;
}
public void setShowDetachedREs(boolean showDetachedREs) {
this.showDetachedREs = showDetachedREs;
}
@Override
public String toString() {
return "TreeOptions [showDetachedREs=" + showDetachedREs + "]";
}
}

@ -24,7 +24,7 @@ public class AccountingServiceTest extends TestCase {
try {
AuthTest.setToken();
new AccountingService(AccountingServiceType.CurrentScope);
new AccountingService(AccountingServiceType.CurrentScope,null);
//accountingService.getTree();
assertTrue(true);

@ -0,0 +1,49 @@
/**
*
*/
package org.gcube.portlets.user.accountingdashboard;
import org.gcube.infrastructure.detachedres.detachedreslibrary.server.DetachedREsClient;
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.DetachedREs;
import org.gcube.portlets.user.accountingdashboard.shared.Constants;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import junit.framework.TestCase;
/**
*
* @author Giancarlo Panichi
*
*
*/
public class ISDetachedREsTest extends TestCase {
private static Logger logger = LoggerFactory.getLogger(ISDetachedREsTest.class);
@Test
public void testAccountingDashboardResource() {
if (Constants.TEST_ENABLE) {
logger.debug("Test Enabled");
try {
DetachedREsClient detachedREsClient = new DetachedREsClient(Constants.DEFAULT_TOKEN);
DetachedREs detachedREs = detachedREsClient.getDetachedREsInScope(Constants.DEFAULT_SCOPE);
logger.debug("DetachedREs: " + detachedREs);
assertTrue(true);
} catch (Exception e) {
logger.error(e.getLocalizedMessage(), e);
assertTrue("Error searching the resource!", false);
}
} else {
logger.debug("Test Disabled");
assertTrue(true);
}
}
}
Loading…
Cancel
Save