|
|
|
@ -1,16 +1,3 @@
|
|
|
|
|
/**
|
|
|
|
|
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or modify it under
|
|
|
|
|
* the terms of the GNU Lesser General Public License as published by the Free
|
|
|
|
|
* Software Foundation; either version 2.1 of the License, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
|
|
|
|
* details.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package org.gcube.portlets.user.cataloguebadge;
|
|
|
|
|
|
|
|
|
@ -56,7 +43,7 @@ import com.liferay.portal.util.PortalUtil;
|
|
|
|
|
@RequestMapping("VIEW")
|
|
|
|
|
public class PortletViewController {
|
|
|
|
|
private static Log _log = LogFactoryUtil.getLog(PortletViewController.class);
|
|
|
|
|
private static final String IMAGES_BASE_URL = "https://catalogue.d4science.org/";
|
|
|
|
|
// private static final String IMAGES_BASE_URL = "https://catalogue.d4science.org/";
|
|
|
|
|
private static final long K = 1000;
|
|
|
|
|
private static final long M = K * K;
|
|
|
|
|
private static final long G = M * K;
|
|
|
|
@ -68,7 +55,18 @@ public class PortletViewController {
|
|
|
|
|
model.addAttribute("releaseInfo", ReleaseInfo.getReleaseInfo());
|
|
|
|
|
PortletPreferences prefs = request.getPreferences();
|
|
|
|
|
String catalogueBaseURL = GetterUtil.getString(prefs.getValue("catalogueURL", StringPool.BLANK));
|
|
|
|
|
String catalogueTypes2Show = GetterUtil.getString(prefs.getValue("catalogueTypes2ShowNo", StringPool.BLANK));
|
|
|
|
|
int typesNo = 5;
|
|
|
|
|
if (catalogueTypes2Show != null && !catalogueTypes2Show.equals(StringPool.BLANK)) {
|
|
|
|
|
try{
|
|
|
|
|
typesNo = Integer.parseInt(catalogueTypes2Show);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
System.out.println(e.getMessage());
|
|
|
|
|
typesNo = 5;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
model.addAttribute("catalogueActualURL", catalogueBaseURL);
|
|
|
|
|
|
|
|
|
|
HttpServletRequest httpServletRequest = PortalUtil.getHttpServletRequest(request);
|
|
|
|
|
long groupId = -1;
|
|
|
|
|
boolean isRootVO = false;
|
|
|
|
@ -83,10 +81,13 @@ public class PortletViewController {
|
|
|
|
|
model.addAttribute("isRootVO", isRootVO);
|
|
|
|
|
if (catalogueBaseURL != null && catalogueBaseURL.compareTo("") != 0) { //if the config textbox with catalogueURL is filled in we show the types
|
|
|
|
|
try {
|
|
|
|
|
List<CatalogueType> theTypes = parseTypes(catalogueBaseURL+"/type", catalogueURL);
|
|
|
|
|
List<CatalogueType> theTypes = parseTypes(catalogueBaseURL+"/type", catalogueURL, catalogueBaseURL);
|
|
|
|
|
Collections.sort(theTypes, Collections.reverseOrder());
|
|
|
|
|
List<CatalogueType> theFiveTypes = new ArrayList<>();
|
|
|
|
|
for (int i = 0; i < 6; i++) {
|
|
|
|
|
int limit = typesNo-1;
|
|
|
|
|
if (theTypes.size() <= limit)
|
|
|
|
|
limit = theTypes.size()-1;
|
|
|
|
|
for (int i = 0; i <= limit; i++) {
|
|
|
|
|
theFiveTypes.add(theTypes.get(i));
|
|
|
|
|
}
|
|
|
|
|
model.addAttribute("catalogueTypes", theFiveTypes);
|
|
|
|
@ -135,7 +136,7 @@ public class PortletViewController {
|
|
|
|
|
return "Catalogue-badge-portlet/view";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<CatalogueType> parseTypes(String url, String catalogueURL) throws Exception {
|
|
|
|
|
private List<CatalogueType> parseTypes(String url, String catalogueURL, String catalogueBaseURL) throws Exception {
|
|
|
|
|
List<CatalogueType> toReturn = new ArrayList<>();
|
|
|
|
|
Document doc = Jsoup.connect(url)
|
|
|
|
|
.userAgent("Mozilla")
|
|
|
|
@ -165,7 +166,7 @@ public class PortletViewController {
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
_log.error("Could not find occurrence in string "+ nameAndOccurrence);
|
|
|
|
|
}
|
|
|
|
|
toReturn.add(new CatalogueType(name, IMAGES_BASE_URL+imgUrl, hrefPortlet, occurrence));
|
|
|
|
|
toReturn.add(new CatalogueType(name, catalogueBaseURL+imgUrl, hrefPortlet, occurrence));
|
|
|
|
|
}
|
|
|
|
|
return toReturn;
|
|
|
|
|
}
|
|
|
|
|