My VREs Portlet to categorize VREs by virtualGroups

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/my-vres@119979 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2015-10-22 16:32:48 +00:00
parent 8260b28982
commit 4aace3127a
11 changed files with 121 additions and 358 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" output="target/my-vres-1.4.0-SNAPSHOT/WEB-INF/classes" path="src/main/java"> <classpathentry kind="src" output="target/my-vres-1.5.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
@ -34,5 +34,5 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="output" path="target/my-vres-1.4.0-SNAPSHOT/WEB-INF/classes"/> <classpathentry kind="output" path="target/my-vres-1.5.0-SNAPSHOT/WEB-INF/classes"/>
</classpath> </classpath>

View File

@ -0,0 +1,3 @@
eclipse.preferences.version=1
validateFragments=false
validation.use-project-settings=true

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> <?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="${module}"> <wb-module deploy-name="my-vres-portlet">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/> <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="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>

View File

@ -4,4 +4,5 @@
<installed facet="wst.jsdt.web" version="1.0"/> <installed facet="wst.jsdt.web" version="1.0"/>
<installed facet="jst.web" version="2.5"/> <installed facet="jst.web" version="2.5"/>
<installed facet="java" version="1.7"/> <installed facet="java" version="1.7"/>
<installed facet="liferay.portlet" version="6.0"/>
</faceted-project> </faceted-project>

11
pom.xml
View File

@ -13,10 +13,10 @@
<groupId>org.gcube.portlets.user</groupId> <groupId>org.gcube.portlets.user</groupId>
<artifactId>my-vres</artifactId> <artifactId>my-vres</artifactId>
<packaging>war</packaging> <packaging>war</packaging>
<version>1.4.0-SNAPSHOT</version> <version>1.5.0-SNAPSHOT</version>
<name>My VREs Portlet</name> <name>My VREs Portlet</name>
<description> <description>
gCube My VREs Portlet shows only the VO and VREs a user is member of. gCube My VREs Portlet shows only the VO and VREs a user is member of, divided by category.
</description> </description>
<scm> <scm>
<connection>scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/${project.artifactId}</connection> <connection>scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/${project.artifactId}</connection>
@ -25,7 +25,7 @@
</scm> </scm>
<properties> <properties>
<!-- Convenience property to set the GWT version --> <!-- Convenience property to set the GWT version -->
<gwtVersion>2.5.1</gwtVersion> <gwtVersion>2.7.0</gwtVersion>
<distroDirectory>distro</distroDirectory> <distroDirectory>distro</distroDirectory>
<!-- GWT needs at least java 1.6 --> <!-- GWT needs at least java 1.6 -->
<maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.source>1.7</maven.compiler.source>
@ -51,6 +51,7 @@
<dependency> <dependency>
<groupId>com.google.gwt</groupId> <groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId> <artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.gcube.portlets.user</groupId> <groupId>org.gcube.portlets.user</groupId>
@ -60,6 +61,10 @@
<groupId>org.gcube.portal</groupId> <groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId> <artifactId>custom-portal-handler</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.gcube.common.portal</groupId>
<artifactId>portal-manager</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.gcube.applicationsupportlayer</groupId> <groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>accesslogger</artifactId> <artifactId>accesslogger</artifactId>

View File

@ -1,10 +1,9 @@
package org.gcube.portlet.user.my_vres.client; package org.gcube.portlet.user.my_vres.client;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap;
import org.gcube.portlet.user.my_vres.shared.VO; import org.gcube.portlet.user.my_vres.shared.VRE;
import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
@ -14,7 +13,7 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
*/ */
@RemoteServiceRelativePath("greet") @RemoteServiceRelativePath("greet")
public interface MyVREsService extends RemoteService { public interface MyVREsService extends RemoteService {
ArrayList<VO> getInfrastructureVOs(); LinkedHashMap<String, ArrayList<VRE>> getUserVREs();
void loadLayout(String scope, String URL); void loadLayout(String scope, String URL);
} }

View File

@ -1,14 +1,18 @@
package org.gcube.portlet.user.my_vres.client; package org.gcube.portlet.user.my_vres.client;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap;
import org.gcube.portlet.user.my_vres.shared.VO; import org.gcube.portlet.user.my_vres.shared.VRE;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
public interface MyVREsServiceAsync { public interface MyVREsServiceAsync {
void getInfrastructureVOs(AsyncCallback<ArrayList<VO>> callback);
void loadLayout(String scope, String URL, AsyncCallback<Void> callback); void loadLayout(String scope, String URL, AsyncCallback<Void> callback);
void getUserVREs(
AsyncCallback<LinkedHashMap<String, ArrayList<VRE>>> callback);
} }

View File

@ -3,21 +3,13 @@ package org.gcube.portlet.user.my_vres.client;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.LinkedHashMap;
import org.gcube.portlet.user.my_vres.client.widgets.BulletList;
import org.gcube.portlet.user.my_vres.client.widgets.ClickableVRE; import org.gcube.portlet.user.my_vres.client.widgets.ClickableVRE;
import org.gcube.portlet.user.my_vres.client.widgets.ListItem;
import org.gcube.portlet.user.my_vres.shared.UserBelonging;
import org.gcube.portlet.user.my_vres.shared.VO; import org.gcube.portlet.user.my_vres.shared.VO;
import org.gcube.portlet.user.my_vres.shared.VRE; import org.gcube.portlet.user.my_vres.shared.VRE;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Cookies;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.FlowPanel;
@ -36,21 +28,13 @@ public class VresPanel extends Composite {
* Create a remote service proxy to talk to the server-side service * Create a remote service proxy to talk to the server-side service
*/ */
private final MyVREsServiceAsync myVREsService = GWT.create(MyVREsService.class); private final MyVREsServiceAsync myVREsService = GWT.create(MyVREsService.class);
private static String VO = "Organizations";
private static String VRE = "Groups";
public static final String COOKIE_NAME = "gCube-EnvironmentViewRestore";
public static final int COOKIE_MONTHS_EXPIRY_TIME = 6; //6 Months
private HTML switcher = new HTML();
private FlowPanel flowPanel; private FlowPanel flowPanel;
private VerticalPanel mainPanel = new VerticalPanel(); private VerticalPanel mainPanel = new VerticalPanel();
private HorizontalPanel changeViewPanel = new HorizontalPanel(); private HorizontalPanel changeViewPanel = new HorizontalPanel();
private HorizontalPanel imagesPanel = new HorizontalPanel(); private HorizontalPanel imagesPanel = new HorizontalPanel();
private Timer t = null;
private ArrayList<VO> cachedVOs = null; private LinkedHashMap<String, ArrayList<VRE>> cachedVREs = null;
private boolean isIconView = true;
boolean hasVres = false; boolean hasVres = false;
public VresPanel() { public VresPanel() {
@ -65,87 +49,28 @@ public class VresPanel extends Composite {
changeViewPanel.setWidth("95%"); changeViewPanel.setWidth("95%");
changeViewPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); changeViewPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
changeViewPanel.add(imagesPanel); changeViewPanel.add(imagesPanel);
loadVREs();
initWidget(mainPanel); initWidget(mainPanel);
switcher.setStyleName("imageLink");
imagesPanel.add(switcher);
switcher.setStyleName("switcher");
switcher.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (isIconView)
showListView();
else
showIconView();
}
});
setLastStateUsingCookie();
} }
private void loadVREs() { private void loadVREs() {
myVREsService.getInfrastructureVOs(new AsyncCallback<ArrayList<VO>>() {
public void onSuccess(ArrayList<VO> result) { myVREsService.getUserVREs(new AsyncCallback<LinkedHashMap<String,ArrayList<VRE>>>() {
cachedVOs = result;
if (isIconView) @Override
showIconView();
else
showListView();
}
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
flowPanel.add(new HTML("Could not fetch personal VREs: " + caught.getMessage())); flowPanel.add(new HTML("Could not fetch personal VREs: " + caught.getMessage()));
} }
@Override
public void onSuccess(LinkedHashMap<String, ArrayList<VRE>> result) {
cachedVREs = result;
showIconView();
}
}); });
}
private void showListView() {
mainPanel.clear();
mainPanel.add(changeViewPanel);
HTML voTitle = new HTML(VO);
voTitle.setStyleName("listPanel-title");
BulletList voList = new BulletList();
voList.setStyleName("list");
boolean showVOs = false;
for (VO vo: cachedVOs) {
if (! vo.isRoot() && vo.getUserBelonging() == UserBelonging.BELONGING) {
voList.add(addVo(vo));
showVOs = true;
}
}
if (showVOs){
mainPanel.add(voTitle);
mainPanel.add(voList);
}
HTML vreTitle = new HTML(VRE);
vreTitle.setStyleName("listPanel-title");
BulletList vreList = new BulletList();
vreList.setStyleName("list");
boolean showVREs = false;
ArrayList<VRE> sortedVREs = new ArrayList<VRE>();
for (VO vo: cachedVOs) {
for (VRE vre : vo.getVres()) {
sortedVREs.add(vre);
hasVres = true;
}
}
Collections.sort(sortedVREs);
for (VRE vre : sortedVREs) {
vreList.add(addVRE(vre));
showVREs = true;
}
if (showVREs) {
mainPanel.add(vreTitle);
mainPanel.add(vreList);
}
Cookies.setCookie(COOKIE_NAME, "1", getExpiryDate());
isIconView = false;
setSwitcherText();
} }
private void showIconView() { private void showIconView() {
@ -155,13 +80,14 @@ public class VresPanel extends Composite {
mainPanel.add(flowPanel); mainPanel.add(flowPanel);
ArrayList<VRE> sortedVREs = new ArrayList<VRE>(); ArrayList<VRE> sortedVREs = new ArrayList<VRE>();
for (VO vo: cachedVOs) { for (String cat : cachedVREs.keySet()) {
for (VRE vre : vo.getVres()) { for (VRE vre: cachedVREs.get(cat)) {
sortedVREs.add(vre); sortedVREs.add(vre);
hasVres = true; hasVres = true;
} }
} }
Collections.sort(sortedVREs);
for (VRE vre : sortedVREs) { for (VRE vre : sortedVREs) {
ClickableVRE vreButton = new ClickableVRE(vre, myVREsService); ClickableVRE vreButton = new ClickableVRE(vre, myVREsService);
@ -172,105 +98,10 @@ public class VresPanel extends Composite {
mainPanel.add(new NoVresPanel()); mainPanel.add(new NoVresPanel());
imagesPanel.clear(); imagesPanel.clear();
} }
Cookies.setCookie(COOKIE_NAME, "0", getExpiryDate());
isIconView = true;
setSwitcherText();
} }
private ListItem addVo(final VO vo) {
final ListItem li = new ListItem();
li.setStyleName("list-item item-vo ");
li.setText(vo.getName());
li.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
showLoading(li);
String scope = vo.getGroupName();
myVREsService.loadLayout(scope, vo.getFriendlyURL(), new AsyncCallback<Void>() {
public void onFailure(Throwable arg0) {
Window.open( vo.getFriendlyURL(), "_self", "");
}
public void onSuccess(Void arg0) {
Window.open( vo.getFriendlyURL(), "_self", "");
}
});
}
});
return li;
}
private ListItem addVRE(final VRE vre) {
final ListItem li = new ListItem();
li.setStyleName("list-item item-vre ");
li.setText(vre.getName());
li.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
showLoading(li);
String scope = vre.getGroupName();
myVREsService.loadLayout(scope, vre.getFriendlyURL(), new AsyncCallback<Void>() {
public void onFailure(Throwable arg0) {
Window.open( vre.getFriendlyURL(), "_self", "");
}
public void onSuccess(Void arg0) {
Window.open( vre.getFriendlyURL(), "_self", "");
}
});
}
});
return li;
}
private void showLoading(final ListItem li) {
li.setText("Loading .");
t = new Timer() {
@Override
public void run() {
li.setText(li.getText() + " .");
t.schedule(250);
if (li.getText().length() > 50)
t.cancel();
}
};
t.schedule(250);
}
private void setSwitcherText() {
if (isIconView)
switcher.setHTML("SHOW LIST");
else
switcher.setHTML("SHOW TILES");
}
/**
*
* @return
*/
@SuppressWarnings("deprecation")
public Date getExpiryDate() {
Date expiryDate = new Date();
int month = expiryDate.getMonth();
month += COOKIE_MONTHS_EXPIRY_TIME ;
expiryDate.setMonth(month);
return expiryDate;
}
/**
*
*/
private void setLastStateUsingCookie() {
Date expiryDate = getExpiryDate();
if (Cookies.getCookie(COOKIE_NAME) == null) {
Cookies.setCookie(COOKIE_NAME, "0", expiryDate);
}
else {
String lastIconsState = Cookies.getCookie(COOKIE_NAME);
if (lastIconsState.compareTo("1") == 0)
isIconView = false;
else
isIconView = true;
}
loadVREs();
}
} }

View File

@ -7,6 +7,7 @@ import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window; import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.Window.Location;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.Image;
@ -50,16 +51,7 @@ public class ClickableVRE extends HTML {
addClickHandler(new ClickHandler() { addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) { public void onClick(ClickEvent event) {
showLoading(); showLoading();
String scope = vre.getGroupName(); Location.assign(vre.getFriendlyURL());
service.loadLayout(scope, vre.getFriendlyURL(), new AsyncCallback<Void>() {
public void onFailure(Throwable arg0) {
Window.open( vre.getFriendlyURL(), "_self", "");
}
public void onSuccess(Void arg0) {
Window.open( vre.getFriendlyURL(), "_self", "");
}
});
} }
}); });
} }

View File

@ -5,15 +5,17 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.gcube.application.framework.core.session.ASLSession; import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager; import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.common.portal.PortalContext;
import org.gcube.portal.custom.communitymanager.OrganizationsUtil; import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
import org.gcube.portal.custom.communitymanager.impl.OrganizationManagerImpl;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlet.user.my_vres.client.MyVREsService; import org.gcube.portlet.user.my_vres.client.MyVREsService;
import org.gcube.portlet.user.my_vres.shared.UserBelonging; import org.gcube.portlet.user.my_vres.shared.UserBelonging;
@ -25,7 +27,6 @@ import org.slf4j.LoggerFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.liferay.portal.kernel.servlet.ImageServletTokenUtil; import com.liferay.portal.kernel.servlet.ImageServletTokenUtil;
import com.liferay.portal.kernel.util.WebKeys; import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.model.Group;
import com.liferay.portal.model.Organization; import com.liferay.portal.model.Organization;
import com.liferay.portal.model.User; import com.liferay.portal.model.User;
import com.liferay.portal.service.OrganizationLocalServiceUtil; import com.liferay.portal.service.OrganizationLocalServiceUtil;
@ -87,130 +88,83 @@ public class MyVREsServiceImpl extends RemoteServiceServlet implements MyVREsSer
/** /**
* first method called by the UI * first method called by the UI
*/ */
public ArrayList<VO> getInfrastructureVOs() { public LinkedHashMap<String, ArrayList<VRE>> getUserVREs() {
getASLSession(); getASLSession();
//_log.trace("getInfrastructureVOs method called"); //_log.trace("getInfrastructureVOs method called");
if (!isWithinPortal()) if (!isWithinPortal())
return getFakeVOs(); return getFakeVREs();
//return new ArrayList<VO>(); //return new ArrayList<VO>();
else else
try { try {
String username = getASLSession().getUsername(); String username = getASLSession().getUsername();
User currUser = OrganizationsUtil.validateUser(username); User currUser = OrganizationsUtil.validateUser(username);
List<Organization> organizations = OrganizationLocalServiceUtil.getOrganizations(0, OrganizationLocalServiceUtil.getOrganizationsCount());
ThemeDisplay themeDisplay = (ThemeDisplay) this.getThreadLocalRequest().getSession().getAttribute(WebKeys.THEME_DISPLAY); ThemeDisplay themeDisplay = (ThemeDisplay) this.getThreadLocalRequest().getSession().getAttribute(WebKeys.THEME_DISPLAY);
LinkedHashMap<String, ArrayList<VRE>> toReturn = new LinkedHashMap<String, ArrayList<VRE>>();
//before iterating the actual groups create the virtualGroups in the correct order
List<String> virtualGroups = OrganizationManagerImpl.getVirtualGroups();
for (String vg : virtualGroups) {
String[] splits = vg.split("\\|");
String gName = splits[0];
ArrayList<VRE> toCreate = new ArrayList<VRE>();
String cat = gName;
toReturn.put(cat, toCreate);
}
//start of iteration of the actual groups
List<Organization> organizations = OrganizationLocalServiceUtil.getOrganizations(0, OrganizationLocalServiceUtil.getOrganizationsCount());
Organization rootOrganization = null; Organization rootOrganization = null;
for (Organization organization : organizations) { for (Organization organization : organizations) {
if (organization.getName().equals( getRootOrganizationName() ) ) { if (organization.getName().equals(PortalContext.getConfiguration().getInfrastructureName())) {
rootOrganization = organization; rootOrganization = organization;
break; break;
} }
} }
try { try {
//_log.info("root: " + rootOrganization.getName() ); _log.debug("root: " + rootOrganization.getName() );
} } catch (NullPointerException e) {
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 new ArrayList<VO>(); return toReturn;
} }
// Create the list of the Infrastructure VOs
List<VO> infrastructureVOs = new ArrayList<VO>();
//create and check the root VO
rootVO = new VO();
rootVO.setName(rootOrganization.getName());
rootVO.setGroupName("/"+rootOrganization.getName());
rootVO.setRoot(true);
Group orgGroup = rootOrganization.getGroup();
String friendlyURL = orgGroup.getPathFriendlyURL(true, themeDisplay) + orgGroup.getFriendlyURL();
rootVO.setFriendlyURL(getPortalBasicUrl()+friendlyURL);
long logoId = rootOrganization.getLogoId();
String logoURL = themeDisplay.getPathImage()+"/organization_logo?img_id="+ logoId +"&t" + ImageServletTokenUtil.getToken(logoId);
rootVO.setImageURL(logoURL);
if (rootOrganization.getComments() != null)
rootVO.setDescription(rootOrganization.getComments());
//for each root sub organizations (VO) //for each root sub organizations (VO)
for (Organization vOrg : rootOrganization.getSuborganizations()) { for (Organization vOrg : rootOrganization.getSuborganizations()) {
//_log.debug("SKIP GCUBE APPS " + vOrg.getName() );
//_log.debug("FOUND VO: " + vOrg.getName() );
//create the VO
VO voToAdd = new VO();
voToAdd.setName(vOrg.getName());
voToAdd.setGroupName("/"+vOrg.getParentOrganization().getName()+"/"+vOrg.getName());
voToAdd.setRoot(false);
for (Organization vre : vOrg.getSuborganizations()) { for (Organization vre : vOrg.getSuborganizations()) {
VRE vreToAdd = new VRE(); VRE vreToAdd = new VRE();
vreToAdd.setName(vre.getName()); vreToAdd.setName(vre.getName());
vreToAdd.setGroupName("/"+vOrg.getParentOrganization().getName()+"/"+vOrg.getName()+"/"+vre.getName()); vreToAdd.setGroupName("/"+vOrg.getParentOrganization().getName()+"/"+vOrg.getName()+"/"+vre.getName());
logoId = vre.getLogoId(); long logoId = vre.getLogoId();
logoURL = themeDisplay.getPathImage()+"/organization_logo?img_id="+ logoId +"&t" + ImageServletTokenUtil.getToken(logoId); String logoURL = themeDisplay.getPathImage()+"/organization_logo?img_id="+ logoId +"&t" + ImageServletTokenUtil.getToken(logoId);
vreToAdd.setImageURL(logoURL); vreToAdd.setImageURL(logoURL);
String vreUrl = vre.getGroup().getPathFriendlyURL(true, themeDisplay) + vre.getGroup().getFriendlyURL(); String vreUrl = vre.getGroup().getPathFriendlyURL(true, themeDisplay) + vre.getGroup().getFriendlyURL();
vreToAdd.setFriendlyURL(getPortalBasicUrl()+vreUrl); vreToAdd.setFriendlyURL(vreUrl);
//set the description for the vre
if (vre.getComments() != null) {
vreToAdd.setDescription(vre.getComments());
}
//check if the user belongs to it //check if the user belongs to it
if (currUser.getOrganizations().contains(vre)) { if (currUser.getOrganizations().contains(vre)) {
vreToAdd.setUserBelonging(UserBelonging.BELONGING); vreToAdd.setUserBelonging(UserBelonging.BELONGING);
voToAdd.addVRE(vreToAdd);
String catName = OrganizationManagerImpl.getVirtualGroupName(vre);
String[] splits = catName.split("\\|");
catName = splits[0];
//for preserving order we inserted the keys before
if (toReturn.containsKey(catName)) {
ArrayList<VRE> toUpdate = toReturn.get(catName);
toUpdate.add(vreToAdd);
}
}
} }
} }
//sort the vres in the groups
for (String cat : toReturn.keySet()) {
Group group = vOrg.getGroup(); ArrayList<VRE> toSort = toReturn.get(cat);
String url = group.getPathFriendlyURL(true, themeDisplay) + group.getFriendlyURL(); Collections.sort(toSort);
voToAdd.setFriendlyURL(getPortalBasicUrl() + url);
//set the description for the vre
if (vOrg.getComments() != null) voToAdd.setDescription(vOrg.getComments());
//check if the user belongs to it
if (currUser.getOrganizations().contains(vOrg)) {
voToAdd.setUserBelonging(UserBelonging.BELONGING);
} }
else
voToAdd.setUserBelonging(UserBelonging.NOT_BELONGING);
infrastructureVOs.add(voToAdd);
}
ArrayList<VO> toReturn = new ArrayList<VO>();
for (VO vo : infrastructureVOs) {
for (VRE vre : vo.getVres()) {
//_log.debug("VRE FOUND.... " + vre.getName());
}
toReturn.add(vo);
}
//sort the VOs
Collections.sort(toReturn, Collections.reverseOrder());
//set the root vo as FIRST
toReturn.add(0, rootVO);
ArrayList<VO> toStoreInSession = toReturn;
//_log.debug("SETTING INFRASTRUCTURE VOS in ASLSession");
getASLSession().setAttribute(CACHED_VOS, toStoreInSession);
return toReturn; return toReturn;
} }
@ -263,49 +217,17 @@ public class MyVREsServiceImpl extends RemoteServiceServlet implements MyVREsSer
return toReturn; return toReturn;
} }
/**
*
* @return the portal basic url, e.g. http://www.foo.com
*/
private String getPortalBasicUrl() {
HttpServletRequest request = this.getThreadLocalRequest();
String toReturn = "";
//protocol
String protocol = (request.isSecure()) ? "https://" : "http://" ;
toReturn += protocol;
//server name
toReturn += request.getServerName();
//port
toReturn += (request.getServerPort() == 80) ? "" : ":"+request.getServerPort() ;
// _log.trace("getPortalBasicUrl: " +toReturn + "queryString: " + request.getQueryString());
return toReturn;
}
/** /**
* simply returns fake VOS for debugging purpose * simply returns fake VREs for development purpose
* @return * @return
*/ */
protected static ArrayList<VO> getFakeVOs() { protected static LinkedHashMap<String, ArrayList<VRE>> getFakeVREs() {
VO rootVO = new VO(); LinkedHashMap<String, ArrayList<VRE>> toReturn = new LinkedHashMap<String, ArrayList<VRE>>();
rootVO.setRoot(true);
rootVO.setName("/d4science.research-infrastructures.eu/");
rootVO.setDescription("This is the description for the ROOT VO");
rootVO.setImageURL("http://portal.d4science.research-infrastructures.eu/vologin/html/RedGrid.jpg");
rootVO.setUserBelonging(UserBelonging.BELONGING);
final String categoryNameOne = "gCubeApps";
/***************************************/ final String categoryNameTwo = "BlueBRIDGE";
VO emVO = new VO();
emVO.setRoot(false);
emVO.setGroupName("/d4science.research-infrastructures.eu/EM/");
emVO.setName("EM VO");
emVO.setDescription("EM and AEM Virtual Organisation The FARM Virtual Organisation is the dynamic group of individuals and/or institutions defined around a set of sharing rules in which resource providers and consumers specify clearly and carefully just what is shared, who is allowed to share, and the conditions under which sharing occurs to serve the needs of the Fisheries and Aquaculture Resources Management.");
emVO.setImageURL("http://portal.d4science.research-infrastructures.eu/vologin/html/RedGrid.jpg");
emVO.setUserBelonging(UserBelonging.BELONGING);
//
// //
VRE cool_EM_VRE = new VRE(); VRE cool_EM_VRE = new VRE();
cool_EM_VRE.setName("BiodiversityResearchEnvironment"); cool_EM_VRE.setName("BiodiversityResearchEnvironment");
@ -314,7 +236,7 @@ public class MyVREsServiceImpl extends RemoteServiceServlet implements MyVREsSer
"This Virtual Research Environment is for cool authors, managers and researchers who produce reports containing cool data."); "This Virtual Research Environment is for cool authors, managers and researchers who produce reports containing cool data.");
cool_EM_VRE.setImageURL("http://portal.d4science.research-infrastructures.eu/vologin/html/gcm-preview.jpg"); cool_EM_VRE.setImageURL("http://portal.d4science.research-infrastructures.eu/vologin/html/gcm-preview.jpg");
cool_EM_VRE.setUserBelonging(UserBelonging.BELONGING); cool_EM_VRE.setUserBelonging(UserBelonging.BELONGING);
emVO.addVRE(cool_EM_VRE);
VRE cool_EM_VRE2 = new VRE(); VRE cool_EM_VRE2 = new VRE();
cool_EM_VRE2.setName("COOL VRE 2"); cool_EM_VRE2.setName("COOL VRE 2");
@ -334,6 +256,12 @@ public class MyVREsServiceImpl extends RemoteServiceServlet implements MyVREsSer
cool_EM_VRE3.setImageURL("https://newportal.i-marine.d4science.org/image/organization_logo?img_id=13302&t1339191699773"); cool_EM_VRE3.setImageURL("https://newportal.i-marine.d4science.org/image/organization_logo?img_id=13302&t1339191699773");
cool_EM_VRE3.setUserBelonging(UserBelonging.BELONGING); cool_EM_VRE3.setUserBelonging(UserBelonging.BELONGING);
ArrayList<VRE> toAdd = new ArrayList<VRE>();
toAdd.add(cool_EM_VRE);
toAdd.add(cool_EM_VRE2);
toAdd.add(cool_EM_VRE3);
VRE demo = new VRE(); VRE demo = new VRE();
demo.setName("Demo"); demo.setName("Demo");
demo.setGroupName("/d4science.research-infrastructures.eu/EM/Demo"); demo.setGroupName("/d4science.research-infrastructures.eu/EM/Demo");
@ -351,19 +279,13 @@ public class MyVREsServiceImpl extends RemoteServiceServlet implements MyVREsSer
vreGCM.setImageURL("https://newportal.i-marine.d4science.org/image/organization_logo?img_id=13302&t1339191699773"); vreGCM.setImageURL("https://newportal.i-marine.d4science.org/image/organization_logo?img_id=13302&t1339191699773");
vreGCM.setUserBelonging(UserBelonging.BELONGING); vreGCM.setUserBelonging(UserBelonging.BELONGING);
ArrayList<VRE> toAdd2 = new ArrayList<VRE>();
toAdd2.add(demo);
toAdd2.add(vreGCM);
emVO.addVRE(cool_EM_VRE); toReturn.put(categoryNameOne, toAdd);
emVO.addVRE(cool_EM_VRE2); toReturn.put(categoryNameTwo, toAdd2);
emVO.addVRE(cool_EM_VRE3);
emVO.addVRE(demo);
emVO.addVRE(vreGCM);
emVO.setUserBelonging(UserBelonging.BELONGING);
ArrayList<VO> toReturn = new ArrayList<VO>();
toReturn.add(rootVO);
toReturn.add(emVO);
toReturn.add(emVO);
return toReturn; return toReturn;
} }
} }

View File

@ -14,6 +14,12 @@
<short-title>VREs Login</short-title> <short-title>VREs Login</short-title>
<keywords>VRE</keywords> <keywords>VRE</keywords>
</portlet-info> </portlet-info>
<portlet-preferences>
<preference>
<name>portlet-setup-show-borders</name>
<value>true</value>
</preference>
</portlet-preferences>
<security-role-ref> <security-role-ref>
<role-name>administrator</role-name> <role-name>administrator</role-name>
</security-role-ref> </security-role-ref>