implementation is complete
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/catalogue-badge-portlet@162272 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
4dead7f5c1
commit
63fcb2b108
|
@ -25,7 +25,7 @@
|
|||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="owner.project.facets" value="java"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
|
|
6
pom.xml
6
pom.xml
|
@ -48,6 +48,12 @@
|
|||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.data-catalogue</groupId>
|
||||
<artifactId>ckan-util-library</artifactId>
|
||||
<version>[2.4.1-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.portal</groupId>
|
||||
<artifactId>social-networking-library</artifactId>
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -18,25 +18,25 @@
|
|||
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
|
||||
|
||||
<%-- <c:out escapeXml="true" value="${releaseInfo}" /> --%>
|
||||
<input type="hidden" value="${catalogueURL}" id="catalogueURL">
|
||||
<div id="catalogueDiv">
|
||||
<div class="input-append input-catalogue">
|
||||
<input type="text" class="input-large" name="q" value=""
|
||||
autocomplete="off" placeholder="Insert keywords here">
|
||||
<button class="btn btn-primary" type="button" title="Search">
|
||||
autocomplete="off" placeholder="Insert keywords here" id="inputQueryCatalogue">
|
||||
<button class="btn btn-primary" type="button" title="Search" id="searchCatalogueButton">
|
||||
<i class="icon-search"></i> <span>Search</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="catstats">
|
||||
<ul>
|
||||
<li><a href="/dataset"> <b><span>150</span></b> items
|
||||
<li><a href="${catalogueURL}?path=/dataset/"> <b><span>${itemsNo}</span></b> items
|
||||
</a></li>
|
||||
<li><a href="/organization"> <b><span>1</span></b>
|
||||
<li><a href="${catalogueURL}?path=/organization/"> <b><span>${organisationsNo}</span></b>
|
||||
organisation
|
||||
</a></li>
|
||||
<li><a href="/group"> <b><span>4</span></b> groups
|
||||
<li><a href="${catalogueURL}?path=/group/"> <b><span>${groupsNo}</span></b> groups
|
||||
</a></li>
|
||||
<li><a href="/types"> <b><span>4</span></b> types
|
||||
<li><a href="${catalogueURL}?path=/type/"> <b><span>${typesNo}</span></b> types
|
||||
</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue