diff --git a/.classpath b/.classpath index 3b073e7..26981b6 100644 --- a/.classpath +++ b/.classpath @@ -25,7 +25,7 @@ - + diff --git a/pom.xml b/pom.xml index 71725c8..2aa07b6 100644 --- a/pom.xml +++ b/pom.xml @@ -48,6 +48,12 @@ + + org.gcube.data-catalogue + ckan-util-library + [2.4.1-SNAPSHOT, 3.0.0-SNAPSHOT) + compile + org.gcube.portal social-networking-library diff --git a/src/main/java/org/gcube/portlets/user/PortletViewController.java b/src/main/java/org/gcube/portlets/user/PortletViewController.java index 0f15f58..b9222a8 100644 --- a/src/main/java/org/gcube/portlets/user/PortletViewController.java +++ b/src/main/java/org/gcube/portlets/user/PortletViewController.java @@ -14,22 +14,93 @@ package org.gcube.portlets.user; -import com.liferay.portal.kernel.util.ReleaseInfo; +import java.text.DecimalFormat; + +import javax.portlet.RenderRequest; +import javax.portlet.RenderResponse; + +import org.gcube.common.portal.GCubePortalConstants; +import org.gcube.common.portal.PortalContext; +import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueFactory; +import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueImpl; +import org.gcube.datacatalogue.ckanutillibrary.shared.LandingPages; +import org.gcube.datacatalogue.ckanutillibrary.shared.Statistics; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.portlet.bind.annotation.RenderMapping; +import com.liferay.portal.kernel.util.ReleaseInfo; +import com.liferay.portal.model.Group; +import com.liferay.portal.service.GroupLocalServiceUtil; +import com.liferay.portal.util.PortalUtil; + @Controller @RequestMapping("VIEW") public class PortletViewController { - + private DataCatalogueFactory factory = DataCatalogueFactory.getFactory(); + private static final long K = 1000; + private static final long M = K * K; + private static final long G = M * K; + @RenderMapping - public String question(Model model) { + public String question(RenderRequest request,RenderResponse response, Model model) { model.addAttribute("releaseInfo", ReleaseInfo.getReleaseInfo()); + try { + long groupId = PortalUtil.getScopeGroupId(request); + PortalContext pContext = PortalContext.getConfiguration(); + String context = pContext.getCurrentScope(""+groupId); + String catalogueURL = getCatalougeFriendlyURL(GroupLocalServiceUtil.getGroup(groupId)); + DataCatalogueImpl utils = factory.getUtilsPerScope(context); + Statistics stats = utils.getStatistics(); + model.addAttribute("itemsNo", convertToStringRepresentation(stats.getNumItems())); + model.addAttribute("groupsNo", stats.getNumGroups()); + model.addAttribute("organisationsNo", stats.getNumOrganizations()); + model.addAttribute("typesNo", stats.getNumTypes()); + model.addAttribute("catalogueURL", catalogueURL); + + } catch (Exception e) { + e.printStackTrace(); + } + return "Catalogue-badge-portlet/view"; } + public static String convertToStringRepresentation(final long value){ + final long[] dividers = new long[] { G, M, K, 1 }; + final String[] units = new String[] {"Giga", "M", "K", ""}; + if(value < 1) + throw new IllegalArgumentException("Invalid file size: " + value); + String result = null; + for(int i = 0; i < dividers.length; i++){ + final long divider = dividers[i]; + if(value >= divider){ + result = format(value, divider, units[i]); + break; + } + } + return result; + } + + private static String format(final long value, + final long divider, + final String unit){ + final double result = + divider > 1 ? (double) value / (double) divider : (double) value; + return new DecimalFormat("#,##0.#").format(result) + " " + unit; + } + + /** + * @param currentGroup + * @return Returns the friendly u r l of this group. + */ + private static String getCatalougeFriendlyURL(final Group currentGroup) throws Exception { + String friendlyURL = GCubePortalConstants.PREFIX_GROUP_URL; + StringBuffer sb = new StringBuffer(); + sb.append(friendlyURL).append(currentGroup.getFriendlyURL()) + .append(GCubePortalConstants.CATALOGUE_FRIENDLY_URL); + return sb.toString(); + } } \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jsp/Catalogue-badge-portlet/view.jsp b/src/main/webapp/WEB-INF/jsp/Catalogue-badge-portlet/view.jsp index c98a303..96c954a 100644 --- a/src/main/webapp/WEB-INF/jsp/Catalogue-badge-portlet/view.jsp +++ b/src/main/webapp/WEB-INF/jsp/Catalogue-badge-portlet/view.jsp @@ -18,25 +18,25 @@ <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> -<%-- --%> +
-
diff --git a/src/main/webapp/js/main.js b/src/main/webapp/js/main.js index e69de29..7964857 100644 --- a/src/main/webapp/js/main.js +++ b/src/main/webapp/js/main.js @@ -0,0 +1,22 @@ +$(document).ready(function() { + $( "#searchCatalogueButton" ).click(function() { + queryCatalogue(); + }); + + $('#inputQueryCatalogue').on("keypress", function(e) { + if (e.keyCode == 13) { + queryCatalogue(); + } + }); +}); + +function queryCatalogue() { + var query = $.trim( $('#inputQueryCatalogue').val() ); + if (query == "") { + $('#inputQueryCatalogue').css("border","1px solid red"); + } else { + $('#inputQueryCatalogue').css("border","1px solid #ccc"); + var encodedQuery = btoa("q="+$('#inputQueryCatalogue').val()); + location.href = $('#catalogueURL').val() + "?query=" + encodedQuery; + } +} \ No newline at end of file