git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/catalogue-badge-portlet@163211 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
73a9b4ad38
commit
22c499d771
4
pom.xml
4
pom.xml
|
@ -54,6 +54,10 @@
|
||||||
<version>[2.4.1-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
<version>[2.4.1-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.dvos</groupId>
|
||||||
|
<artifactId>usermanagement-core</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.common.portal</groupId>
|
<groupId>org.gcube.common.portal</groupId>
|
||||||
<artifactId>portal-manager</artifactId>
|
<artifactId>portal-manager</artifactId>
|
||||||
|
|
|
@ -12,25 +12,30 @@
|
||||||
* details.
|
* details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.gcube.portlets.user;
|
package org.gcube.portlets.user.cataloguebadge;
|
||||||
|
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
|
||||||
import javax.portlet.RenderRequest;
|
import javax.portlet.RenderRequest;
|
||||||
import javax.portlet.RenderResponse;
|
import javax.portlet.RenderResponse;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.gcube.common.portal.GCubePortalConstants;
|
import org.gcube.common.portal.GCubePortalConstants;
|
||||||
import org.gcube.common.portal.PortalContext;
|
import org.gcube.common.portal.PortalContext;
|
||||||
|
import org.gcube.datacatalogue.ckanutillibrary.server.ApplicationProfileScopePerUrlReader;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueFactory;
|
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueFactory;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueImpl;
|
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueImpl;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.shared.LandingPages;
|
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.shared.Statistics;
|
import org.gcube.datacatalogue.ckanutillibrary.shared.Statistics;
|
||||||
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.portlet.bind.annotation.RenderMapping;
|
import org.springframework.web.portlet.bind.annotation.RenderMapping;
|
||||||
|
|
||||||
|
import com.liferay.portal.kernel.log.Log;
|
||||||
|
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
||||||
import com.liferay.portal.kernel.util.ReleaseInfo;
|
import com.liferay.portal.kernel.util.ReleaseInfo;
|
||||||
import com.liferay.portal.model.Group;
|
import com.liferay.portal.model.Group;
|
||||||
import com.liferay.portal.service.GroupLocalServiceUtil;
|
import com.liferay.portal.service.GroupLocalServiceUtil;
|
||||||
|
@ -39,59 +44,83 @@ import com.liferay.portal.util.PortalUtil;
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping("VIEW")
|
@RequestMapping("VIEW")
|
||||||
public class PortletViewController {
|
public class PortletViewController {
|
||||||
|
private static Log _log = LogFactoryUtil.getLog(PortletViewController.class);
|
||||||
private DataCatalogueFactory factory = DataCatalogueFactory.getFactory();
|
private DataCatalogueFactory factory = DataCatalogueFactory.getFactory();
|
||||||
private static final long K = 1000;
|
private static final long K = 1000;
|
||||||
private static final long M = K * K;
|
private static final long M = K * K;
|
||||||
private static final long G = M * K;
|
private static final long G = M * K;
|
||||||
|
|
||||||
|
private static GroupManager gm = new LiferayGroupManager();
|
||||||
|
|
||||||
@RenderMapping
|
@RenderMapping
|
||||||
public String question(RenderRequest request,RenderResponse response, Model model) {
|
public String question(RenderRequest request,RenderResponse response, Model model) {
|
||||||
model.addAttribute("releaseInfo", ReleaseInfo.getReleaseInfo());
|
model.addAttribute("releaseInfo", ReleaseInfo.getReleaseInfo());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
HttpServletRequest httpServletRequest = PortalUtil.getHttpServletRequest(request);
|
||||||
|
|
||||||
long groupId = PortalUtil.getScopeGroupId(request);
|
long groupId = PortalUtil.getScopeGroupId(request);
|
||||||
PortalContext pContext = PortalContext.getConfiguration();
|
PortalContext pContext = PortalContext.getConfiguration();
|
||||||
String context = pContext.getCurrentScope(""+groupId);
|
String context = pContext.getCurrentScope(""+groupId);
|
||||||
String catalogueURL = getCatalougeFriendlyURL(GroupLocalServiceUtil.getGroup(groupId));
|
String catalogueURL = getCatalougeFriendlyURL(GroupLocalServiceUtil.getGroup(groupId));
|
||||||
DataCatalogueImpl utils = factory.getUtilsPerScope(context);
|
DataCatalogueImpl utils = null;
|
||||||
|
if (gm.isRootVO(groupId)) {
|
||||||
|
String gatewaySiteURL = pContext.getGatewayURL(httpServletRequest);
|
||||||
|
if (!gatewaySiteURL.startsWith("https"))
|
||||||
|
gatewaySiteURL = gatewaySiteURL.replaceAll("http:", "https:");
|
||||||
|
String siteLandingPage = pContext.getSiteLandingPagePath(httpServletRequest);
|
||||||
|
String clientURL = gatewaySiteURL+siteLandingPage;
|
||||||
|
System.out.println(clientURL);
|
||||||
|
try {
|
||||||
|
String appPerScopeURL = ApplicationProfileScopePerUrlReader.getScopePerUrl(clientURL);
|
||||||
|
_log.info("Catalogue for this Gateway is in this scope: " + appPerScopeURL);
|
||||||
|
utils = factory.getUtilsPerScope(appPerScopeURL);
|
||||||
|
} catch (Exception e) {
|
||||||
|
_log.warn("Returning default catalogue for the context, could not find the catologue for this Gateway: " + clientURL);
|
||||||
|
utils = factory.getUtilsPerScope(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
utils = factory.getUtilsPerScope(context);
|
||||||
|
}
|
||||||
Statistics stats = utils.getStatistics();
|
Statistics stats = utils.getStatistics();
|
||||||
model.addAttribute("itemsNo", convertToStringRepresentation(stats.getNumItems()));
|
model.addAttribute("itemsNo", convertToStringRepresentation(stats.getNumItems()));
|
||||||
model.addAttribute("groupsNo", stats.getNumGroups());
|
model.addAttribute("groupsNo", stats.getNumGroups());
|
||||||
model.addAttribute("organisationsNo", stats.getNumOrganizations());
|
model.addAttribute("organisationsNo", stats.getNumOrganizations());
|
||||||
model.addAttribute("typesNo", stats.getNumTypes());
|
model.addAttribute("typesNo", stats.getNumTypes());
|
||||||
model.addAttribute("catalogueURL", catalogueURL);
|
model.addAttribute("catalogueURL", catalogueURL);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return "Catalogue-badge-portlet/view";
|
return "Catalogue-badge-portlet/view";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String convertToStringRepresentation(final long value){
|
public static String convertToStringRepresentation(final long value){
|
||||||
final long[] dividers = new long[] { G, M, K, 1 };
|
final long[] dividers = new long[] { G, M, K, 1 };
|
||||||
final String[] units = new String[] {"Giga", "M", "K", ""};
|
final String[] units = new String[] {"Giga", "M", "K", ""};
|
||||||
if(value < 1)
|
if(value < 1)
|
||||||
throw new IllegalArgumentException("Invalid file size: " + value);
|
throw new IllegalArgumentException("Invalid file size: " + value);
|
||||||
String result = null;
|
String result = null;
|
||||||
for(int i = 0; i < dividers.length; i++){
|
for(int i = 0; i < dividers.length; i++){
|
||||||
final long divider = dividers[i];
|
final long divider = dividers[i];
|
||||||
if(value >= divider){
|
if(value >= divider){
|
||||||
result = format(value, divider, units[i]);
|
result = format(value, divider, units[i]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String format(final long value,
|
private static String format(final long value,
|
||||||
final long divider,
|
final long divider,
|
||||||
final String unit){
|
final String unit){
|
||||||
final double result =
|
final double result =
|
||||||
divider > 1 ? (double) value / (double) divider : (double) value;
|
divider > 1 ? (double) value / (double) divider : (double) value;
|
||||||
return new DecimalFormat("#,##0.#").format(result) + " " + unit;
|
return new DecimalFormat("#,##0.#").format(result) + " " + unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param currentGroup
|
* @param currentGroup
|
||||||
* @return Returns the friendly u r l of this group.
|
* @return Returns the friendly u r l of this group.
|
||||||
|
@ -103,4 +132,6 @@ public class PortletViewController {
|
||||||
.append(GCubePortalConstants.CATALOGUE_FRIENDLY_URL);
|
.append(GCubePortalConstants.CATALOGUE_FRIENDLY_URL);
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
<!DOCTYPE display PUBLIC "-//Liferay//DTD Display 6.2.0//EN" "http://www.liferay.com/dtd/liferay-display_6_2_0.dtd">
|
<!DOCTYPE display PUBLIC "-//Liferay//DTD Display 6.2.0//EN" "http://www.liferay.com/dtd/liferay-display_6_2_0.dtd">
|
||||||
|
|
||||||
<display>
|
<display>
|
||||||
<category name="category.sample">
|
<category name="gCube Applications">
|
||||||
<portlet id="Catalogue-badge-portlet" />
|
<portlet id="Catalogue-badge-portlet" />
|
||||||
</category>
|
</category>
|
||||||
</display>
|
</display>
|
|
@ -1,9 +1,9 @@
|
||||||
name=Catalogue-badge-portlet
|
name=Catalogue-badge-portlet
|
||||||
module-group-id=liferay
|
module-group-id=liferay
|
||||||
module-incremental-version=1
|
module-incremental-version=2
|
||||||
tags=
|
tags=
|
||||||
short-description=
|
short-description=
|
||||||
change-log=
|
change-log=
|
||||||
page-url=http://www.liferay.com
|
page-url=http://www.gcube-system.org
|
||||||
author=Liferay, Inc.
|
author=M. Assante
|
||||||
licenses=LGPL
|
licenses=EUPL
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
</supports>
|
</supports>
|
||||||
<portlet-info>
|
<portlet-info>
|
||||||
<title>Catalogue</title>
|
<title>Catalogue</title>
|
||||||
<short-title>Catalogue-badge-portlet</short-title>
|
<short-title>Catalogue</short-title>
|
||||||
<keywords>Catalogue-badge-portlet</keywords>
|
<keywords>Catalogue</keywords>
|
||||||
</portlet-info>
|
</portlet-info>
|
||||||
<security-role-ref>
|
<security-role-ref>
|
||||||
<role-name>administrator</role-name>
|
<role-name>administrator</role-name>
|
||||||
|
|
|
@ -6,5 +6,5 @@
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"
|
||||||
>
|
>
|
||||||
<context:component-scan base-package="org.gcube.portlets.user.**" />
|
<context:component-scan base-package="org.gcube.portlets.user.cataloguebadge.**" />
|
||||||
</beans>
|
</beans>
|
Loading…
Reference in New Issue