Adding Categories and Properties to VRE. Refs #3272

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/join-vre@113536 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2015-03-10 10:29:28 +00:00
parent 370b8851db
commit 0a0f61029f
7 changed files with 203 additions and 32 deletions

View File

@ -1,6 +1,7 @@
package org.gcube.portlets.user.joinvre.client.panels; package org.gcube.portlets.user.joinvre.client.panels;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -12,11 +13,14 @@ import org.gcube.portlets.user.joinvre.shared.VRE;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
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.Grid; import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.HasAlignment; import com.google.gwt.user.client.ui.HasAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment; import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.VerticalPanel;
/** /**
@ -49,15 +53,28 @@ public class JoinVREPanel extends Composite {
if (vres == null || vres.isEmpty()) { if (vres == null || vres.isEmpty()) {
mainPanel.add(new HTML("<div class=\"frame\" style=\"font-size: 16px;\">Ops, something went wrong. Please <a href=\"javascript: location.reload();\">reload<a/> this page.</div>")); mainPanel.add(new HTML("<div class=\"frame\" style=\"font-size: 16px;\">Ops, something went wrong. Please <a href=\"javascript: location.reload();\">reload<a/> this page.</div>"));
} else { } else {
Grid grid = new Grid(vres.size()/4+1, 4);
mainPanel.add(grid); int panelSize = vres.get(vres.size()-1).getRelevance();
FlowPanel[] panels = new FlowPanel[panelSize];
for (int i = 0; i < vres.size(); i++) { int last = -1;
grid.setWidget(i/4, i%4, new DisplayVRE(vres.get(i))); for (VRE vre : vres) {
int relevance = vre.getRelevance();
if(last < relevance){
panels[relevance] = new FlowPanel();
Label label = new Label(Relevance.values()[relevance].name().replace('_', ' '));
label.addStyleName("relevance");
if(relevance == 0){
label.addStyleName("first");
}
panels[relevance].add(label);
mainPanel.add(panels[relevance]);
last = relevance;
}
panels[relevance].add(new DisplayVRE(vre));
} }
} }
} }
@Override @Override
@ -67,6 +84,7 @@ public class JoinVREPanel extends Composite {
"Please check your connection and try refresh this page.</div>")); "Please check your connection and try refresh this page.</div>"));
} }
}); });
initWidget(mainPanel); initWidget(mainPanel);
} }

View File

@ -0,0 +1,12 @@
/**
*
*/
package org.gcube.portlets.user.joinvre.client.panels;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public enum Relevance {
Must_Have, Recommended, New
}

View File

@ -5,6 +5,7 @@ import java.util.List;
import org.gcube.portlets.user.joinvre.client.JoinService; import org.gcube.portlets.user.joinvre.client.JoinService;
import org.gcube.portlets.user.joinvre.client.JoinServiceAsync; import org.gcube.portlets.user.joinvre.client.JoinServiceAsync;
import org.gcube.portlets.user.joinvre.shared.VRE; import org.gcube.portlets.user.joinvre.shared.VRE;
import org.gcube.portlets.user.joinvre.shared.VRECategory;
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.ClickEvent;
@ -76,9 +77,9 @@ public class DisplayVRE extends Composite {
vreName.setText(name); vreName.setText(name);
vreName.addClickHandler(descriptionHandler); vreName.addClickHandler(descriptionHandler);
List<String> categories = vre.getCategories(); List<VRECategory> categories = vre.getCategories();
for(int i=0; i<categories.size(); i++){ for(int i=0; i<categories.size(); i++){
vreCategories.add(new Label(categories.get(i))); vreCategories.add(new Label(categories.get(i).getName()));
if(i!=categories.size()-1){ if(i!=categories.size()-1){
vreCategories.add(new Label(",")); vreCategories.add(new Label(","));
} }

View File

@ -5,6 +5,7 @@ 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.Comparator;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
@ -17,6 +18,7 @@ import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlets.user.joinvre.client.JoinService; import org.gcube.portlets.user.joinvre.client.JoinService;
import org.gcube.portlets.user.joinvre.shared.UserBelonging; import org.gcube.portlets.user.joinvre.shared.UserBelonging;
import org.gcube.portlets.user.joinvre.shared.VRE; import org.gcube.portlets.user.joinvre.shared.VRE;
import org.gcube.portlets.user.joinvre.shared.VRECategory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.exception.PortalException;
@ -34,6 +36,8 @@ import com.liferay.portal.security.permission.PermissionThreadLocal;
import com.liferay.portal.service.OrganizationLocalServiceUtil; import com.liferay.portal.service.OrganizationLocalServiceUtil;
import com.liferay.portal.service.UserLocalServiceUtil; import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.theme.ThemeDisplay; import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portlet.asset.model.AssetCategory;
import com.liferay.portlet.asset.service.AssetCategoryLocalServiceUtil;
/** /**
* @author Massimiliano Assante, ISTI-CNR - massimiliano.assante@isti.cnr.it * @author Massimiliano Assante, ISTI-CNR - massimiliano.assante@isti.cnr.it
@ -95,25 +99,35 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
if (isWithinPortal()) { if (isWithinPortal()) {
vres = getPortalOrganizationMappedToVRE(); vres = getPortalOrganizationMappedToVRE();
} else { } else {
List<String> devsecCategories = new ArrayList<String>(); List<VRECategory> devsecCategories = new ArrayList<VRECategory>();
devsecCategories.add("Development"); devsecCategories.add(new VRECategory(1, "Development"));
vres.add(new VRE(0, "devsec", "devsec VRE description", "", "", "/group/devsec", devsecCategories, UserBelonging.NOT_BELONGING, false)); vres.add(new VRE(0, "devsec", "devsec VRE description", "", "", "/group/devsec", devsecCategories, 0,UserBelonging.NOT_BELONGING, false));
List<String> devVRECategories = new ArrayList<String>(devsecCategories); List<VRECategory> devVRECategories = new ArrayList<VRECategory>(devsecCategories);
devVRECategories.add("Sailing"); devVRECategories.add(new VRECategory(2, "Sailing"));
vres.add(new VRE(1, "devVRE", "devVRE VRE description", "", "", "/group/devVRE", devVRECategories, UserBelonging.NOT_BELONGING, false)); vres.add(new VRE(1, "devVRE", "devVRE VRE description", "", "", "/group/devVRE", devVRECategories, 1, UserBelonging.NOT_BELONGING, false));
List<String> devmodeategories = new ArrayList<String>(devsecCategories); List<VRECategory> devmodeategories = new ArrayList<VRECategory>(devsecCategories);
devmodeategories.add("Climbing"); devmodeategories.add(new VRECategory(3, "Climbing"));
vres.add(new VRE(2, "devmode", "devmode VRE description", "", "", "/group/devmode", devmodeategories, UserBelonging.NOT_BELONGING, true)); vres.add(new VRE(2, "devmode", "devmode VRE description", "", "", "/group/devmode", devmodeategories, 2, UserBelonging.NOT_BELONGING, true));
vres.add(new VRE(3, "devsec", "devsec VRE description", "", "", "/group/devsec", devsecCategories, UserBelonging.NOT_BELONGING, false)); vres.add(new VRE(3, "devsec2", "devsec VRE description", "", "", "/group/devsec", devsecCategories, 0, UserBelonging.NOT_BELONGING, false));
vres.add(new VRE(4, "devsec", "devsec VRE description", "", "", "/group/devsec", devsecCategories, UserBelonging.NOT_BELONGING, false)); vres.add(new VRE(4, "devsec3", "devsec VRE description", "", "", "/group/devsec", devsecCategories, 0, UserBelonging.NOT_BELONGING, false));
vres.add(new VRE(5, "devsec", "devsec VRE description", "", "", "/group/devsec", devsecCategories, UserBelonging.NOT_BELONGING, false)); vres.add(new VRE(5, "devsec4", "devsec VRE description", "", "", "/group/devsec", devsecCategories, 1, UserBelonging.NOT_BELONGING, false));
} }
} catch (Exception e) { } catch (Exception e) {
_log.error("Error getting VREs", e); _log.error("Error getting VREs", e);
} }
// Ordering VREs by Name // Ordering VREs by Name
Collections.sort(vres); Collections.sort(vres, new Comparator<VRE>(){
@Override
public int compare(VRE vre1, VRE vre2) {
int relevanceDiff = vre1.getRelevance() - vre2.getRelevance();
if (relevanceDiff != 0) {
return relevanceDiff;
} else {
return vre1.getName().compareTo(vre2.getName());
}
}
});
return vres; return vres;
} }
@ -149,6 +163,39 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
} }
} }
private static final String RELEVANCE = "relevance";
public int getRelevance(Organization organization){
try {
long companyId = OrganizationsUtil.getCompany().getCompanyId();
_log.trace("Setting Thread Permission");
User user = UserLocalServiceUtil.getUserByScreenName(companyId, ScopeHelper.getAdministratorUsername());
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user, false);
PermissionThreadLocal.setPermissionChecker(permissionChecker);
_log.trace("Setting Permission ok!");
if (organization.getExpandoBridge().getAttribute(RELEVANCE) == null || organization.getExpandoBridge().getAttribute(RELEVANCE).equals("")) {
_log.trace(String.format("Attribute %s not initialized. In this case by default Access Grant is permitted", REQUEST_BASED_GROUP));
return 0;
} else {
String attributeValue = (String) organization.getExpandoBridge().getAttribute(REQUEST_BASED_GROUP);
return Integer.parseInt(attributeValue);
}
} catch (Exception e) {
return 0;
}
}
public List<VRECategory> getCategory(Organization organization) throws SystemException{
List<VRECategory> categories = new ArrayList<VRECategory>();
long organizationPK = organization.getPrimaryKey();
List<AssetCategory> categoryList = AssetCategoryLocalServiceUtil.getCategories(Organization.class.getName(), organizationPK);
for(AssetCategory assetCategory : categoryList){
categories.add(new VRECategory(assetCategory.getCategoryId(), assetCategory.getName()));
}
return categories;
}
public ArrayList<VRE> getPortalOrganizationMappedToVRE() throws SystemException, PortalException { public ArrayList<VRE> getPortalOrganizationMappedToVRE() throws SystemException, PortalException {
ArrayList<VRE> vres = new ArrayList<VRE>(); ArrayList<VRE> vres = new ArrayList<VRE>();
@ -182,6 +229,9 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
String vreName = vreOrganization.getName(); String vreName = vreOrganization.getName();
String vreDescription = (vreOrganization.getComments()!=null) ? vreOrganization.getComments() : ""; String vreDescription = (vreOrganization.getComments()!=null) ? vreOrganization.getComments() : "";
long logoId = vreOrganization.getLogoId(); long logoId = vreOrganization.getLogoId();
String vreLogoURL = String.format("%s/organization_logo?img_id=%s&t=%s", imagePath, logoId, ImageServletTokenUtil.getToken(logoId)); String vreLogoURL = String.format("%s/organization_logo?img_id=%s&t=%s", imagePath, logoId, ImageServletTokenUtil.getToken(logoId));
@ -193,10 +243,12 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
boolean requireAccessGrant = requireAccessGrant(vreOrganization); boolean requireAccessGrant = requireAccessGrant(vreOrganization);
List<String> categories = new ArrayList<String>(); List<VRECategory> categories = getCategory(vreOrganization);
_log.debug(String.format("VRE preferences : %s", vreOrganization.getPreferences())); _log.debug(String.format("VRE preferences : %s", vreOrganization.getPreferences()));
vres.add(new VRE(vreID,vreName, vreDescription, vreLogoURL, groupName,friendlyURL, categories, UserBelonging.NOT_BELONGING, requireAccessGrant)); int relevance = getRelevance(vreOrganization);
vres.add(new VRE(vreID,vreName, vreDescription, vreLogoURL, groupName,friendlyURL, categories, relevance, UserBelonging.NOT_BELONGING, requireAccessGrant));
} }
} }

View File

@ -12,11 +12,11 @@ public class VRE extends ResearchEnvironment implements Serializable, Comparable
protected boolean uponRequest; protected boolean uponRequest;
protected long id; protected long id;
protected List<String> categories; protected List<VRECategory> categories;
protected int relevance;
public VRE() { public VRE() {
super(); super();
this.uponRequest = true;
} }
/** /**
@ -31,12 +31,13 @@ public class VRE extends ResearchEnvironment implements Serializable, Comparable
* @param uponRequest * @param uponRequest
*/ */
public VRE(long id, String vreName, String description, String imageURL, public VRE(long id, String vreName, String description, String imageURL,
String vomsGroupName, String friendlyURL, List<String> categories, String vomsGroupName, String friendlyURL, List<VRECategory> categories, int relevance,
UserBelonging userBelonging, boolean uponRequest) { UserBelonging userBelonging, boolean uponRequest) {
super(vreName, description, imageURL, vomsGroupName, friendlyURL, userBelonging); super(vreName, description, imageURL, vomsGroupName, friendlyURL, userBelonging);
this.uponRequest = uponRequest; this.uponRequest = uponRequest;
this.id = id; this.id = id;
this.categories = categories; this.categories = categories;
this.relevance = relevance;
} }
public boolean isUponRequest() { public boolean isUponRequest() {
@ -54,17 +55,31 @@ public class VRE extends ResearchEnvironment implements Serializable, Comparable
this.id = id; this.id = id;
} }
/**
* @return the relevance
*/
public int getRelevance() {
return relevance;
}
/**
* @param relevance the relevance to set
*/
public void setRelevance(int relevance) {
this.relevance = relevance;
}
/** /**
* @return the categories * @return the categories
*/ */
public List<String> getCategories() { public List<VRECategory> getCategories() {
return categories; return categories;
} }
/** /**
* @param categories the categories to set * @param categories the categories to set
*/ */
public void setCategories(List<String> categories) { public void setCategories(List<VRECategory> categories) {
this.categories = categories; this.categories = categories;
} }
@ -74,9 +89,8 @@ public class VRE extends ResearchEnvironment implements Serializable, Comparable
} }
@Override @Override
public int compareTo(VRE o) { public int compareTo(VRE vre) {
return this.getName().compareTo(o.getName()); return this.getName().compareTo(vre.getName());
} }
} }

View File

@ -0,0 +1,62 @@
/**
*
*/
package org.gcube.portlets.user.joinvre.shared;
import java.io.Serializable;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
@SuppressWarnings("serial")
public class VRECategory implements Serializable, Comparable<VRECategory> {
protected long categoryID;
protected String name;
public VRECategory() {
super();
}
/**
* @param categoryID
* @param name
*/
public VRECategory(long categoryID, String name) {
super();
this.categoryID = categoryID;
this.name = name;
}
/**
* @return the categoryID
*/
public long getCategoryID() {
return categoryID;
}
/**
* @param categoryID the categoryID to set
*/
public void setCategoryID(long categoryID) {
this.categoryID = categoryID;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/** {@inheritDoc} */
@Override
public int compareTo(VRECategory vreCategory) {
return name.compareTo(vreCategory.name);
}
}

View File

@ -1,3 +1,14 @@
.relevance {
color: #225f97;
font-size: 110%;
font-weight: bold;
margin-top: 10px;
}
.relevance.first {
margin-top: 0;
}
.framed { .framed {
width: 146px; width: 146px;
padding: 10px; padding: 10px;
@ -7,6 +18,7 @@
-moz-border-radius: 6px !important; -moz-border-radius: 6px !important;
-webkit-border-radius: 6px !important; -webkit-border-radius: 6px !important;
border: 1px solid #9b9b9b; border: 1px solid #9b9b9b;
display: inline-block;
} }
.framed:hover { .framed:hover {
@ -57,7 +69,7 @@
} }
.vreCategories > * { .vreCategories > * {
display: inline; display: inline-block;
} }
.joinButton { .joinButton {