ref 12119:AccountingDashboard - Create a new Accounting Dashboard

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

Updated Tree

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/accounting-dashboard@169705 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2018-07-06 15:48:46 +00:00
parent 5c49bc0dfc
commit cf23291ed6
12 changed files with 396 additions and 166 deletions

View File

@ -7,7 +7,9 @@ import org.gcube.portlets.user.accountingdashboard.client.application.dialog.err
import org.gcube.portlets.user.accountingdashboard.client.application.dialog.info.InfoPresenter; import org.gcube.portlets.user.accountingdashboard.client.application.dialog.info.InfoPresenter;
import org.gcube.portlets.user.accountingdashboard.client.application.dialog.monitor.MonitorPresenter; import org.gcube.portlets.user.accountingdashboard.client.application.dialog.monitor.MonitorPresenter;
import org.gcube.portlets.user.accountingdashboard.client.application.event.HelloEvent; import org.gcube.portlets.user.accountingdashboard.client.application.event.HelloEvent;
import org.gcube.portlets.user.accountingdashboard.client.application.event.ScopeDataEvent;
import org.gcube.portlets.user.accountingdashboard.client.rpc.AccountingDashboardServiceAsync; import org.gcube.portlets.user.accountingdashboard.client.rpc.AccountingDashboardServiceAsync;
import org.gcube.portlets.user.accountingdashboard.shared.data.ScopeData;
import org.gcube.portlets.user.accountingdashboard.shared.session.UserInfo; import org.gcube.portlets.user.accountingdashboard.shared.session.UserInfo;
import com.google.gwt.event.shared.EventBus; import com.google.gwt.event.shared.EventBus;
@ -84,5 +86,28 @@ public class Controller {
} }
public void getTree() {
service.getScopeData(new AsyncCallback<ScopeData>() {
@Override
public void onFailure(Throwable caught) {
logger.log(Level.FINE, "Error in Hello(): ", caught);
errorPresenter.errorMessage(caught.getLocalizedMessage());
}
@Override
public void onSuccess(ScopeData scopeData) {
logger.log(Level.FINE, "ScopeData: " + scopeData);
ScopeDataEvent event = new ScopeDataEvent(scopeData);
eventBus.fireEvent(event);
}
});
}
} }

View File

@ -0,0 +1,51 @@
package org.gcube.portlets.user.accountingdashboard.client.application.event;
import org.gcube.portlets.user.accountingdashboard.shared.data.ScopeData;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HasHandlers;
/**
*
* @author Giancarlo Panichi
*
*/
public class ScopeDataEvent extends GwtEvent<ScopeDataEvent.ScopeDataEventHandler> {
private ScopeData scopeData;
public interface ScopeDataEventHandler extends EventHandler {
void onData(ScopeDataEvent event);
}
public static final Type<ScopeDataEventHandler> TYPE = new Type<>();
public ScopeDataEvent(ScopeData scopeData) {
this.scopeData = scopeData;
}
public static void fire(HasHandlers source, ScopeDataEvent event) {
source.fireEvent(event);
}
@Override
public Type<ScopeDataEventHandler> getAssociatedType() {
return TYPE;
}
@Override
protected void dispatch(ScopeDataEventHandler handler) {
handler.onData(this);
}
public ScopeData getScopeData() {
return scopeData;
}
@Override
public String toString() {
return "ScopeDataEvent [scopeData=" + scopeData + "]";
}
}

View File

@ -1,8 +1,11 @@
package org.gcube.portlets.user.accountingdashboard.client.application.mainarea.filter; package org.gcube.portlets.user.accountingdashboard.client.application.mainarea.filter;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.gcube.portlets.user.accountingdashboard.client.application.controller.Controller; import org.gcube.portlets.user.accountingdashboard.client.application.controller.Controller;
import org.gcube.portlets.user.accountingdashboard.client.application.event.ScopeDataEvent;
import org.gcube.portlets.user.accountingdashboard.shared.data.ScopeData;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.web.bindery.event.shared.EventBus; import com.google.web.bindery.event.shared.EventBus;
@ -15,23 +18,22 @@ import com.gwtplatform.mvp.client.View;
* @author Giancarlo Panichi * @author Giancarlo Panichi
* *
*/ */
public class FilterAreaPresenter public class FilterAreaPresenter extends PresenterWidget<FilterAreaPresenter.FilterAreaView>
extends PresenterWidget<FilterAreaPresenter.FilterAreaView> implements FilterAreaUiHandlers { implements FilterAreaUiHandlers {
private static Logger logger = Logger.getLogger(""); private static Logger logger = Logger.getLogger("");
interface FilterAreaView extends View, HasUiHandlers<FilterAreaPresenter> { interface FilterAreaView extends View, HasUiHandlers<FilterAreaPresenter> {
void displayScopeData(ScopeData scopeData);
} }
private EventBus eventBus; private EventBus eventBus;
private Controller controller; private Controller controller;
@Inject @Inject
FilterAreaPresenter(EventBus eventBus, FilterAreaView view, FilterAreaPresenter(EventBus eventBus, FilterAreaView view, Controller controller) {
Controller controller) {
super(eventBus, view); super(eventBus, view);
this.eventBus = eventBus; this.eventBus = eventBus;
this.controller = controller; this.controller = controller;
@ -47,11 +49,22 @@ public class FilterAreaPresenter
private void bindToEvent() { private void bindToEvent() {
controller.getEventBus().addHandler(ScopeDataEvent.TYPE, new ScopeDataEvent.ScopeDataEventHandler() {
@Override
public void onData(ScopeDataEvent event) {
logger.log(Level.FINE, "ScopeDataEvent received");
getView().displayScopeData(event.getScopeData());
}
});
} }
@Override @Override
protected void onBind() { protected void onBind() {
super.onBind(); super.onBind();
controller.getTree();
} }
} }

View File

@ -20,7 +20,6 @@ import com.google.gwt.i18n.client.LocaleInfo;
import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.cellview.client.CellTree; import com.google.gwt.user.cellview.client.CellTree;
import com.google.gwt.user.cellview.client.CellTree.Resources;
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.view.client.ListDataProvider; import com.google.gwt.view.client.ListDataProvider;
@ -60,7 +59,8 @@ public class FilterAreaView extends ViewWithUiHandlers<FilterAreaPresenter>
@UiField(provided = true) @UiField(provided = true)
CellTree scopeTree; CellTree scopeTree;
private ListDataProvider<ScopeData> dataProvider;
@SuppressWarnings("unused")
private AppResources resources; private AppResources resources;
@Inject @Inject
@ -103,30 +103,24 @@ public class FilterAreaView extends ViewWithUiHandlers<FilterAreaPresenter>
monthEnd.addItem(months[i]); monthEnd.addItem(months[i]);
} }
ScopeData children1=new ScopeData("1","children1",null); dataProvider = new ListDataProvider<ScopeData>();
ScopeData children3=new ScopeData("3","children3",null);
ScopeData children4=new ScopeData("4","children4",null);
ArrayList<ScopeData> children2List=new ArrayList<>();
children2List.add(children3);
children2List.add(children4);
ScopeData children2=new ScopeData("2","children2",children2List);
ArrayList<ScopeData> rootList=new ArrayList<>();
rootList.add(children1);
rootList.add(children2);
ScopeData root=new ScopeData("0","root",rootList);
ArrayList<ScopeData> scopeDataList=new ArrayList<>();
scopeDataList.add(root);
ListDataProvider<ScopeData> dataProvider = new ListDataProvider<ScopeData>(scopeDataList);
ScopeTreeModel scopeTreeModel=new ScopeTreeModel(dataProvider); ScopeTreeModel scopeTreeModel=new ScopeTreeModel(dataProvider);
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
public void displayScopeData(ScopeData scopeData) {
ArrayList<ScopeData> scopeDataList=new ArrayList<>();
scopeDataList.add(scopeData);
dataProvider.setList(scopeDataList);
dataProvider.refresh();
dataProvider.flush();
}
} }

View File

@ -10,6 +10,12 @@ import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.view.client.ListDataProvider; import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.TreeViewModel; import com.google.gwt.view.client.TreeViewModel;
/**
*
* @author Giancarlo Panichi
*
*/
public class ScopeTreeModel implements TreeViewModel { public class ScopeTreeModel implements TreeViewModel {
private ListDataProvider<ScopeData> dataProvider; private ListDataProvider<ScopeData> dataProvider;
@ -23,6 +29,7 @@ public class ScopeTreeModel implements TreeViewModel {
public ScopeTreeModel(ListDataProvider<ScopeData> dataProvider) { public ScopeTreeModel(ListDataProvider<ScopeData> dataProvider) {
this.dataProvider=dataProvider; this.dataProvider=dataProvider;
} }
/** /**

View File

@ -1,5 +1,6 @@
package org.gcube.portlets.user.accountingdashboard.client.rpc; package org.gcube.portlets.user.accountingdashboard.client.rpc;
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.exception.ServiceException;
import org.gcube.portlets.user.accountingdashboard.shared.session.UserInfo; import org.gcube.portlets.user.accountingdashboard.shared.session.UserInfo;
@ -23,6 +24,8 @@ public interface AccountingDashboardService extends RemoteService {
*/ */
public UserInfo hello() throws ServiceException; public UserInfo hello() throws ServiceException;
public ScopeData getScopeData() throws ServiceException;
} }

View File

@ -3,6 +3,7 @@
*/ */
package org.gcube.portlets.user.accountingdashboard.client.rpc; package org.gcube.portlets.user.accountingdashboard.client.rpc;
import org.gcube.portlets.user.accountingdashboard.shared.data.ScopeData;
import org.gcube.portlets.user.accountingdashboard.shared.session.UserInfo; import org.gcube.portlets.user.accountingdashboard.shared.session.UserInfo;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
@ -20,6 +21,8 @@ public interface AccountingDashboardServiceAsync {
.create(AccountingDashboardService.class); .create(AccountingDashboardService.class);
void hello(AsyncCallback<UserInfo> callback); void hello(AsyncCallback<UserInfo> callback);
void getScopeData(AsyncCallback<ScopeData> callback);

View File

@ -3,7 +3,10 @@ package org.gcube.portlets.user.accountingdashboard.server;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import org.gcube.portlets.user.accountingdashboard.client.rpc.AccountingDashboardService; import org.gcube.portlets.user.accountingdashboard.client.rpc.AccountingDashboardService;
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.server.util.ServiceCredentials;
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.exception.ServiceException;
import org.gcube.portlets.user.accountingdashboard.shared.session.UserInfo; import org.gcube.portlets.user.accountingdashboard.shared.session.UserInfo;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -52,11 +55,29 @@ public class AccountingDashboardServiceImpl extends RemoteServiceServlet impleme
throw e; throw e;
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Hello(): " + e.getLocalizedMessage(), e); logger.error("Hello(): " + e.getLocalizedMessage(), e);
throw new ServiceException(e.getLocalizedMessage(), e); throw new ServiceException("Error retrivieving user credentials: " + e.getLocalizedMessage(), e);
} }
} }
@Override
public ScopeData getScopeData() throws ServiceException {
try {
logger.debug("AccountingDashboardServiceImpl getScopeData()");
@SuppressWarnings("unused")
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(this.getThreadLocalRequest());
AccountingService as = new AccountingService(AccountingServiceType.PortalContex);
ScopeData scopeData = as.getTree();
return scopeData;
} catch (ServiceException e) {
logger.error(e.getLocalizedMessage(), e);
throw e;
} catch (Throwable e) {
logger.error("GetScopeData(): " + e.getLocalizedMessage(), e);
throw new ServiceException("Error retrieving scope info: "+e.getLocalizedMessage(), e);
}
}
} }

View File

@ -1,7 +1,11 @@
package org.gcube.portlets.user.accountingdashboard.server.accounting; package org.gcube.portlets.user.accountingdashboard.server.accounting;
import java.util.ArrayList;
import org.gcube.data.access.accounting.summary.access.AccountingDao; import org.gcube.data.access.accounting.summary.access.AccountingDao;
import org.gcube.data.access.accounting.summary.access.model.ScopeDescriptor; import org.gcube.data.access.accounting.summary.access.model.ScopeDescriptor;
import org.gcube.portlets.user.accountingdashboard.shared.data.ScopeData;
import org.gcube.portlets.user.accountingdashboard.shared.exception.ServiceException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -11,23 +15,68 @@ import org.slf4j.LoggerFactory;
* *
*/ */
public class AccountingService { public class AccountingService {
private static Logger logger = LoggerFactory.getLogger(AccountingService.class); private static Logger logger = LoggerFactory.getLogger(AccountingService.class);
private AccountingDao dao; private AccountingDao dao;
public AccountingService() { public AccountingService(AccountingServiceType accountingServiceType) throws ServiceException {
dao = AccountingDao.get(new PortalContextTreeProvider()); try {
if (accountingServiceType == null) {
logger.error("Invalid AccountingServiceType requested: null");
}
switch (accountingServiceType) {
case CurrentScope:
logger.debug("AccountingService: CurrentScope");
dao = AccountingDao.get();
break;
case PortalContex:
logger.debug("AccountingService: PortalContext");
dao = AccountingDao.get(new PortalContextTreeProvider());
break;
default:
logger.debug("AccountingService: CurrentScope");
dao = AccountingDao.get();
break;
}
} catch (Throwable e) {
logger.error("Error retrieving Tree: " + e.getLocalizedMessage(), e);
throw new ServiceException("Error retrieving Tree: " + e.getLocalizedMessage(), e);
}
} }
public void getTree() { public ScopeData getTree() throws ServiceException {
try { try {
logger.debug("AccountingService GetTree()"); logger.debug("AccountingService GetTree()");
ScopeDescriptor scopeDescriptor = dao.getTree(null); ScopeDescriptor scopeDescriptor = dao.getTree(null);
logger.debug("ScopeDescriptor: "+scopeDescriptor); logger.debug("ScopeDescriptor: " + scopeDescriptor);
ScopeData scopeData = getScopeData(scopeDescriptor);
} catch (Exception e) { return scopeData;
logger.error("Error retrieving Tree: "+e.getLocalizedMessage(),e);
} catch (Throwable e) {
logger.error("Error retrieving Tree: " + e.getLocalizedMessage(), e);
throw new ServiceException("Error retrieving Tree: " + e.getLocalizedMessage(), e);
} }
} }
private ScopeData getScopeData(ScopeDescriptor scopeDescriptor) {
ScopeData scopeData = null;
if (scopeDescriptor != null) {
if (scopeDescriptor.hasChildren()) {
ArrayList<ScopeData> childs = new ArrayList<>();
for (ScopeDescriptor sd : scopeDescriptor.getChildren()) {
childs.add(getScopeData(sd));
}
scopeData = new ScopeData(scopeDescriptor.getId(), scopeDescriptor.getName(), childs);
} else {
scopeData = new ScopeData(scopeDescriptor.getId(), scopeDescriptor.getName(), null);
}
}
return scopeData;
}
} }

View File

@ -0,0 +1,12 @@
package org.gcube.portlets.user.accountingdashboard.server.accounting;
/**
*
* @author Giancarlo Panichi
*
*/
public enum AccountingServiceType {
PortalContex, CurrentScope;
}

View File

@ -1,7 +1,5 @@
package org.gcube.portlets.user.accountingdashboard.server.accounting; package org.gcube.portlets.user.accountingdashboard.server.accounting;
import javax.servlet.http.HttpServletRequest;
import org.gcube.data.access.accounting.summary.access.impl.ContextTreeProvider; import org.gcube.data.access.accounting.summary.access.impl.ContextTreeProvider;
import org.gcube.data.access.accounting.summary.access.model.ScopeDescriptor; import org.gcube.data.access.accounting.summary.access.model.ScopeDescriptor;
import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.GroupManager;
@ -15,142 +13,156 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
public class PortalContextTreeProvider implements ContextTreeProvider { public class PortalContextTreeProvider implements ContextTreeProvider {
private static GroupManager groupsManager; private static GroupManager groupsManager;
static { static {
groupsManager = new LiferayGroupManager(); groupsManager = new LiferayGroupManager();
} }
@Override @Override
public ScopeDescriptor getTree(Object context) throws Exception { public ScopeDescriptor getTree(Object context) throws Exception {
// if(context == null) throw new Exception("Unable to get tree, Request is null."); // if(context == null) throw new Exception("Unable to get tree, Request
// if(!(context instanceof HttpServletRequest)) throw new Exception("Invalid request object : "+context); // is null.");
// HttpServletRequest request=(HttpServletRequest) context; // if(!(context instanceof HttpServletRequest)) throw new
// Exception("Invalid request object : "+context);
// HttpServletRequest request=(HttpServletRequest) context;
// PARSE TREE // PARSE TREE
GCubeGroup rootGroupVO = groupsManager.getRootVO(); GCubeGroup rootGroupVO = groupsManager.getRootVO();
return asScopeDescriptor(rootGroupVO); return asScopeDescriptor(rootGroupVO);
} }
private ScopeDescriptor asScopeDescriptor(GCubeGroup group) throws UserManagementSystemException, GroupRetrievalFault { private ScopeDescriptor asScopeDescriptor(GCubeGroup group)
ScopeDescriptor toReturn=new ScopeDescriptor(group.getGroupName(),groupsManager.getInfrastructureScope(group.getGroupId())); throws UserManagementSystemException, GroupRetrievalFault {
for(GCubeGroup child:group.getChildren()) { ScopeDescriptor toReturn = new ScopeDescriptor(group.getGroupName(),
toReturn.getChildren().add(asScopeDescriptor(child)); groupsManager.getInfrastructureScope(group.getGroupId()));
if (group.getChildren() != null && !group.getChildren().isEmpty()) {
for (GCubeGroup child : group.getChildren()) {
toReturn.getChildren().add(asScopeDescriptor(child));
}
} }
return toReturn; return toReturn;
} }
// //
// //
// /** // /**
// * // *
// * @return the Virtual groups with their VREs in the order estabilished in the LR Control Panel // * @return the Virtual groups with their VREs in the order estabilished in
// * @throws SystemException // the LR Control Panel
// * @throws PortalException // * @throws SystemException
// */ // * @throws PortalException
// private LinkedHashMap<VRECategory, ArrayList<VRE>> getPortalSitesMappedToVRE(HttpServletRequest request) throws Exception { // */
// // private LinkedHashMap<VRECategory, ArrayList<VRE>>
// Group site=getSiteFromServletRequest(request); // getPortalSitesMappedToVRE(HttpServletRequest request) throws Exception {
// //
// ScopeDescriptor root=new ScopeDescriptor(site.getDescriptiveName(),site.getUuid()); // Group site=getSiteFromServletRequest(request);
// //
// LinkedList<ScopeDescriptor> groups=new LinkedList<>(); // ScopeDescriptor root=new
// // ScopeDescriptor(site.getDescriptiveName(),site.getUuid());
// long currentSiteGroupId = site.getGroupId(); //
// // LinkedList<ScopeDescriptor> groups=new LinkedList<>();
//// List<VirtualGroup> currentSiteVGroups = groupsManager.getVirtualGroups(currentSiteGroupId); //
//// // long currentSiteGroupId = site.getGroupId();
//// for (VirtualGroup vg : currentSiteVGroups) { //
//// ScopeDescriptor groupDescriptor=new ScopeDescriptor(vg.getName(),); //// List<VirtualGroup> currentSiteVGroups =
//// VRECategory cat = new VRECategory(1L, vg.getName(), vg.getDescription()); // groupsManager.getVirtualGroups(currentSiteGroupId);
//// toReturn.put(cat, toCreate); ////
//// } //// for (VirtualGroup vg : currentSiteVGroups) {
// //// ScopeDescriptor groupDescriptor=new ScopeDescriptor(vg.getName(),);
// GCubeGroup rootGroupVO = groupsManager.getRootVO(); //// VRECategory cat = new VRECategory(1L, vg.getName(),
//// // vg.getDescription());
//// try { //// toReturn.put(cat, toCreate);
//// 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"); // GCubeGroup rootGroupVO = groupsManager.getRootVO();
//// return toReturn; ////
//// } //// try {
//// PortalContext pContext = PortalContext.getConfiguration(); //// log.debug("root: " + rootGroupVO.getGroupName() );
//// //// } catch (NullPointerException e) {
//// List<GCubeGroup> currUserGroups = new ArrayList<GCubeGroup>(); //// log.error("Cannot find root organziation, please check
//// GCubeUser currUser = pContext.getCurrentUser(request); // gcube-data.properties file in $CATALINA_HOME/conf folder, unless your
//// if (currUser != null) { // installing the Bundle");
//// currUserGroups = groupsManager.listGroupsByUser(currUser.getUserId()); //// return toReturn;
//// } //// }
// //// PortalContext pContext = PortalContext.getConfiguration();
// //for each root sub organizations (VO) ////
// for (GCubeGroup vOrg : rootGroupVO.getChildren()) { //// List<GCubeGroup> currUserGroups = new ArrayList<GCubeGroup>();
// for (GCubeGroup vreSite : vOrg.getChildren()) { //// GCubeUser currUser = pContext.getCurrentUser(request);
// long vreID = vreSite.getGroupId(); //// if (currUser != null) {
// String vreName = vreSite.getGroupName(); //// currUserGroups = groupsManager.listGroupsByUser(currUser.getUserId());
// String vreDescription = vreSite.getDescription(); //// }
// //
// String groupName = groupsManager.getInfrastructureScope(vreSite.getGroupId()); // //for each root sub organizations (VO)
// // for (GCubeGroup vOrg : rootGroupVO.getChildren()) {
// List<VirtualGroup> vreGroups = groupsManager.getVirtualGroups(vreID); // for (GCubeGroup vreSite : vOrg.getChildren()) {
// for (VirtualGroup vreGroup : vreGroups) { // long vreID = vreSite.getGroupId();
// for (VRECategory vre : toReturn.keySet()) { // String vreName = vreSite.getGroupName();
// if (vre.getName().compareTo(vreGroup.getName())==0) { // String vreDescription = vreSite.getDescription();
// ArrayList<VRE> toUpdate = toReturn.get(vre); //
// UserBelonging belongs = UserBelonging.NOT_BELONGING; // String groupName =
// VRE toAdd = new VRE(vreID,vreName, vreDescription, vreLogoURL, groupName, friendlyURL, belongs, getVREMembershipType(vreSite.getMembershipType())); // groupsManager.getInfrastructureScope(vreSite.getGroupId());
//// if (GroupLocalServiceUtil.getGroup(vreID).getPublicLayoutsPageCount() > 0) { //
//// String publicURL = PREFIX_PUBLIC_URL+vreSite.getFriendlyURL(); // List<VirtualGroup> vreGroups = groupsManager.getVirtualGroups(vreID);
//// toAdd.setPublicURL(publicURL); // for (VirtualGroup vreGroup : vreGroups) {
//// } // for (VRECategory vre : toReturn.keySet()) {
//// if (currUser != null) { // if (vre.getName().compareTo(vreGroup.getName())==0) {
//// //check if the user belongs to it // ArrayList<VRE> toUpdate = toReturn.get(vre);
//// if (currUserGroups.contains(vreSite)) { // UserBelonging belongs = UserBelonging.NOT_BELONGING;
//// toAdd.setUserBelonging(UserBelonging.BELONGING); // VRE toAdd = new VRE(vreID,vreName, vreDescription, vreLogoURL, groupName,
//// } // friendlyURL, belongs, getVREMembershipType(vreSite.getMembershipType()));
//// else if (checkPending(currUser.getUsername(), vreSite.getGroupId())) //// if (GroupLocalServiceUtil.getGroup(vreID).getPublicLayoutsPageCount() >
//// toAdd.setUserBelonging(UserBelonging.PENDING); // 0) {
//// } //// String publicURL = PREFIX_PUBLIC_URL+vreSite.getFriendlyURL();
// toUpdate.add(toAdd); //// toAdd.setPublicURL(publicURL);
// } //// }
// } //// if (currUser != null) {
// } //// //check if the user belongs to it
// } //// if (currUserGroups.contains(vreSite)) {
// } //// toAdd.setUserBelonging(UserBelonging.BELONGING);
// //// }
// //sort the vres in the groups //// else if (checkPending(currUser.getUsername(), vreSite.getGroupId()))
// for (VRECategory cat : toReturn.keySet()) { //// toAdd.setUserBelonging(UserBelonging.PENDING);
// ArrayList<VRE> toSort = toReturn.get(cat); //// }
// Collections.sort(toSort); // toUpdate.add(toAdd);
// } // }
// return toReturn; // }
// } // }
// // }
// // }
// //
// // //sort the vres in the groups
// // for (VRECategory cat : toReturn.keySet()) {
// private Group getSiteFromServletRequest(final HttpServletRequest request) throws PortalException, SystemException { // ArrayList<VRE> toSort = toReturn.get(cat);
// String serverName = request.getServerName(); // Collections.sort(toSort);
// log.debug("currentHost is " + serverName); // }
// Group site = null; // return toReturn;
// List<VirtualHost> vHosts = VirtualHostLocalServiceUtil.getVirtualHosts(0, 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) { //
// long layoutSetId = virtualHost.getLayoutSetId(); // private Group getSiteFromServletRequest(final HttpServletRequest request)
// site = LayoutSetLocalServiceUtil.getLayoutSet(layoutSetId).getGroup(); // throws PortalException, SystemException {
// log.debug("Found match! Your site is " + site.getName()); // String serverName = request.getServerName();
// return site; // log.debug("currentHost is " + serverName);
// } // Group site = null;
// } // List<VirtualHost> vHosts = VirtualHostLocalServiceUtil.getVirtualHosts(0,
// return null; // 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) {
// long layoutSetId = virtualHost.getLayoutSetId();
// site = LayoutSetLocalServiceUtil.getLayoutSet(layoutSetId).getGroup();
// log.debug("Found match! Your site is " + site.getName());
// return site;
// }
// }
// return null;
// }
} }

View File

@ -1,8 +1,11 @@
package org.gcube.portlets.user.accountingdashboard; package org.gcube.portlets.user.accountingdashboard;
import java.util.ArrayList;
import org.gcube.portlets.user.accountingdashboard.server.accounting.AccountingService; import org.gcube.portlets.user.accountingdashboard.server.accounting.AccountingService;
import org.gcube.portlets.user.accountingdashboard.server.accounting.AccountingServiceType;
import org.gcube.portlets.user.accountingdashboard.shared.Constants; import org.gcube.portlets.user.accountingdashboard.shared.Constants;
import org.gcube.portlets.user.accountingdashboard.shared.data.ScopeData;
import org.junit.Test; import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -24,7 +27,7 @@ public class AccountingServiceTest extends TestCase {
try { try {
AuthTest.setToken(); AuthTest.setToken();
AccountingService accountingService=new AccountingService(); AccountingService accountingService = new AccountingService(AccountingServiceType.CurrentScope);
accountingService.getTree(); accountingService.getTree();
assertTrue("Success", true); assertTrue("Success", true);
@ -39,5 +42,42 @@ public class AccountingServiceTest extends TestCase {
} }
} }
@Test
public void testData() {
if (Constants.TEST_ENABLE) {
try {
ScopeData children1 = new ScopeData("1", "children1", null);
ScopeData children3 = new ScopeData("3", "children3", null);
ScopeData children4 = new ScopeData("4", "children4", null);
ArrayList<ScopeData> children2List = new ArrayList<>();
children2List.add(children3);
children2List.add(children4);
ScopeData children2 = new ScopeData("2", "children2", children2List);
ArrayList<ScopeData> rootList = new ArrayList<>();
rootList.add(children1);
rootList.add(children2);
ScopeData root = new ScopeData("0", "root", rootList);
ArrayList<ScopeData> scopeDataList = new ArrayList<>();
scopeDataList.add(root);
logger.debug("Data example: "+scopeDataList);
assertTrue("Success", true);
} catch (Throwable e) {
logger.error(e.getLocalizedMessage(), e);
fail("Error:" + e.getLocalizedMessage());
}
} else {
assertTrue("Success", true);
}
}
} }