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:
parent
370b8851db
commit
0a0f61029f
|
@ -1,6 +1,7 @@
|
|||
package org.gcube.portlets.user.joinvre.client.panels;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
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.user.client.rpc.AsyncCallback;
|
||||
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.HTML;
|
||||
import com.google.gwt.user.client.ui.HTMLPanel;
|
||||
import com.google.gwt.user.client.ui.HasAlignment;
|
||||
import com.google.gwt.user.client.ui.HasVerticalAlignment;
|
||||
import com.google.gwt.user.client.ui.Image;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||
|
||||
/**
|
||||
|
@ -49,15 +53,28 @@ public class JoinVREPanel extends Composite {
|
|||
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>"));
|
||||
} else {
|
||||
Grid grid = new Grid(vres.size()/4+1, 4);
|
||||
mainPanel.add(grid);
|
||||
|
||||
for (int i = 0; i < vres.size(); i++) {
|
||||
grid.setWidget(i/4, i%4, new DisplayVRE(vres.get(i)));
|
||||
|
||||
int panelSize = vres.get(vres.size()-1).getRelevance();
|
||||
FlowPanel[] panels = new FlowPanel[panelSize];
|
||||
int last = -1;
|
||||
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
|
||||
|
@ -67,6 +84,7 @@ public class JoinVREPanel extends Composite {
|
|||
"Please check your connection and try refresh this page.</div>"));
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
initWidget(mainPanel);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -5,6 +5,7 @@ import java.util.List;
|
|||
import org.gcube.portlets.user.joinvre.client.JoinService;
|
||||
import org.gcube.portlets.user.joinvre.client.JoinServiceAsync;
|
||||
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.event.dom.client.ClickEvent;
|
||||
|
@ -76,9 +77,9 @@ public class DisplayVRE extends Composite {
|
|||
vreName.setText(name);
|
||||
vreName.addClickHandler(descriptionHandler);
|
||||
|
||||
List<String> categories = vre.getCategories();
|
||||
List<VRECategory> categories = vre.getCategories();
|
||||
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){
|
||||
vreCategories.add(new Label(","));
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.io.FileInputStream;
|
|||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
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.shared.UserBelonging;
|
||||
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.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.UserLocalServiceUtil;
|
||||
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
|
||||
|
@ -95,25 +99,35 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
|
|||
if (isWithinPortal()) {
|
||||
vres = getPortalOrganizationMappedToVRE();
|
||||
} else {
|
||||
List<String> devsecCategories = new ArrayList<String>();
|
||||
devsecCategories.add("Development");
|
||||
vres.add(new VRE(0, "devsec", "devsec VRE description", "", "", "/group/devsec", devsecCategories, UserBelonging.NOT_BELONGING, false));
|
||||
List<String> devVRECategories = new ArrayList<String>(devsecCategories);
|
||||
devVRECategories.add("Sailing");
|
||||
vres.add(new VRE(1, "devVRE", "devVRE VRE description", "", "", "/group/devVRE", devVRECategories, UserBelonging.NOT_BELONGING, false));
|
||||
List<String> devmodeategories = new ArrayList<String>(devsecCategories);
|
||||
devmodeategories.add("Climbing");
|
||||
vres.add(new VRE(2, "devmode", "devmode VRE description", "", "", "/group/devmode", devmodeategories, UserBelonging.NOT_BELONGING, true));
|
||||
vres.add(new VRE(3, "devsec", "devsec VRE description", "", "", "/group/devsec", devsecCategories, UserBelonging.NOT_BELONGING, false));
|
||||
vres.add(new VRE(4, "devsec", "devsec VRE description", "", "", "/group/devsec", devsecCategories, UserBelonging.NOT_BELONGING, false));
|
||||
vres.add(new VRE(5, "devsec", "devsec VRE description", "", "", "/group/devsec", devsecCategories, UserBelonging.NOT_BELONGING, false));
|
||||
List<VRECategory> devsecCategories = new ArrayList<VRECategory>();
|
||||
devsecCategories.add(new VRECategory(1, "Development"));
|
||||
vres.add(new VRE(0, "devsec", "devsec VRE description", "", "", "/group/devsec", devsecCategories, 0,UserBelonging.NOT_BELONGING, false));
|
||||
List<VRECategory> devVRECategories = new ArrayList<VRECategory>(devsecCategories);
|
||||
devVRECategories.add(new VRECategory(2, "Sailing"));
|
||||
vres.add(new VRE(1, "devVRE", "devVRE VRE description", "", "", "/group/devVRE", devVRECategories, 1, UserBelonging.NOT_BELONGING, false));
|
||||
List<VRECategory> devmodeategories = new ArrayList<VRECategory>(devsecCategories);
|
||||
devmodeategories.add(new VRECategory(3, "Climbing"));
|
||||
vres.add(new VRE(2, "devmode", "devmode VRE description", "", "", "/group/devmode", devmodeategories, 2, UserBelonging.NOT_BELONGING, true));
|
||||
vres.add(new VRE(3, "devsec2", "devsec VRE description", "", "", "/group/devsec", devsecCategories, 0, 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, "devsec4", "devsec VRE description", "", "", "/group/devsec", devsecCategories, 1, UserBelonging.NOT_BELONGING, false));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
_log.error("Error getting VREs", e);
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
||||
ArrayList<VRE> vres = new ArrayList<VRE>();
|
||||
|
@ -182,6 +229,9 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
|
|||
String vreName = vreOrganization.getName();
|
||||
String vreDescription = (vreOrganization.getComments()!=null) ? vreOrganization.getComments() : "";
|
||||
|
||||
|
||||
|
||||
|
||||
long logoId = vreOrganization.getLogoId();
|
||||
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);
|
||||
|
||||
List<String> categories = new ArrayList<String>();
|
||||
List<VRECategory> categories = getCategory(vreOrganization);
|
||||
_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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,11 +12,11 @@ public class VRE extends ResearchEnvironment implements Serializable, Comparable
|
|||
|
||||
protected boolean uponRequest;
|
||||
protected long id;
|
||||
protected List<String> categories;
|
||||
protected List<VRECategory> categories;
|
||||
protected int relevance;
|
||||
|
||||
public VRE() {
|
||||
super();
|
||||
this.uponRequest = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,12 +31,13 @@ public class VRE extends ResearchEnvironment implements Serializable, Comparable
|
|||
* @param uponRequest
|
||||
*/
|
||||
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) {
|
||||
super(vreName, description, imageURL, vomsGroupName, friendlyURL, userBelonging);
|
||||
this.uponRequest = uponRequest;
|
||||
this.id = id;
|
||||
this.categories = categories;
|
||||
this.relevance = relevance;
|
||||
}
|
||||
|
||||
public boolean isUponRequest() {
|
||||
|
@ -54,17 +55,31 @@ public class VRE extends ResearchEnvironment implements Serializable, Comparable
|
|||
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
|
||||
*/
|
||||
public List<String> getCategories() {
|
||||
public List<VRECategory> getCategories() {
|
||||
return categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param categories the categories to set
|
||||
*/
|
||||
public void setCategories(List<String> categories) {
|
||||
public void setCategories(List<VRECategory> categories) {
|
||||
this.categories = categories;
|
||||
}
|
||||
|
||||
|
@ -74,9 +89,8 @@ public class VRE extends ResearchEnvironment implements Serializable, Comparable
|
|||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(VRE o) {
|
||||
return this.getName().compareTo(o.getName());
|
||||
public int compareTo(VRE vre) {
|
||||
return this.getName().compareTo(vre.getName());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -1,3 +1,14 @@
|
|||
.relevance {
|
||||
color: #225f97;
|
||||
font-size: 110%;
|
||||
font-weight: bold;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.relevance.first {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.framed {
|
||||
width: 146px;
|
||||
padding: 10px;
|
||||
|
@ -7,6 +18,7 @@
|
|||
-moz-border-radius: 6px !important;
|
||||
-webkit-border-radius: 6px !important;
|
||||
border: 1px solid #9b9b9b;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.framed:hover {
|
||||
|
@ -57,7 +69,7 @@
|
|||
}
|
||||
|
||||
.vreCategories > * {
|
||||
display: inline;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.joinButton {
|
||||
|
|
Loading…
Reference in New Issue