From 8f92b6ddace1dbd600e037d369b5f133c9fe0863 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Wed, 17 Jan 2024 17:11:37 +0100 Subject: [PATCH] the class is triggered at startup, missing publish yet --- src/main/java/org/gcube/portal/Gateway.java | 29 ++++++++ src/main/java/org/gcube/portal/GetCaller.java | 65 +++++++++++++++++ .../java/org/gcube/portal/TriggeredClass.java | 69 +++++++++++++++++++ src/main/java/portal.properties | 3 + src/main/webapp/WEB-INF/liferay-display.xml | 8 --- src/main/webapp/WEB-INF/liferay-hook.xml | 6 ++ .../WEB-INF/liferay-plugin-package.properties | 6 +- src/main/webapp/WEB-INF/liferay-portlet.xml | 27 -------- src/main/webapp/WEB-INF/portlet.xml | 34 --------- src/main/webapp/css/main.css | 0 src/main/webapp/js/main.js | 0 11 files changed, 175 insertions(+), 72 deletions(-) create mode 100644 src/main/java/org/gcube/portal/Gateway.java create mode 100644 src/main/java/org/gcube/portal/GetCaller.java create mode 100644 src/main/java/org/gcube/portal/TriggeredClass.java create mode 100644 src/main/java/portal.properties delete mode 100644 src/main/webapp/WEB-INF/liferay-display.xml create mode 100644 src/main/webapp/WEB-INF/liferay-hook.xml delete mode 100644 src/main/webapp/WEB-INF/liferay-portlet.xml delete mode 100644 src/main/webapp/WEB-INF/portlet.xml delete mode 100644 src/main/webapp/css/main.css delete mode 100644 src/main/webapp/js/main.js diff --git a/src/main/java/org/gcube/portal/Gateway.java b/src/main/java/org/gcube/portal/Gateway.java new file mode 100644 index 0000000..a6ddfc8 --- /dev/null +++ b/src/main/java/org/gcube/portal/Gateway.java @@ -0,0 +1,29 @@ +package org.gcube.portal; + + +import com.liferay.portal.model.Group; + +public class Gateway { + private Group site; + + public Gateway(Group site) { + super(); + this.site = site; + + } + public Group getSite() { + return site; + } + public void setSite(Group site) { + this.site = site; + } + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("Gateway [site="); + builder.append(site); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/portal/GetCaller.java b/src/main/java/org/gcube/portal/GetCaller.java new file mode 100644 index 0000000..a3b6acb --- /dev/null +++ b/src/main/java/org/gcube/portal/GetCaller.java @@ -0,0 +1,65 @@ +package org.gcube.portal; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.List; + +import javax.net.ssl.HttpsURLConnection; + +public class GetCaller extends Thread { + private final int WAITING_MILLISECONDS = 900000; + + private final static String USER_AGENT = "Mozilla/5.0"; + + protected static final String SERVLET_CONTEXT_MAIL = "/social-mail-servlet/start-email-reader"; + + private List urlsToContact; + + public GetCaller(List urlsToContact) { + super(); + this.urlsToContact = urlsToContact; + } + + + + @Override + public void run() { + try { + System.out.println("********** READING MAILS THREAD Waiting ... starting in " + WAITING_MILLISECONDS/60000 + " minutes"); + Thread.sleep(WAITING_MILLISECONDS); + for (String url : urlsToContact) { + String response = sendHTTPsGet(url+SERVLET_CONTEXT_MAIL); + System.out.println("**********\n\n"+ "Called URL=" + url + " correctly, response:" + response); + } + } catch (Exception e) { + e.printStackTrace(); + } + + } + + private String sendHTTPsGet(String url) throws Exception { + + URL obj = new URL(null, url, new sun.net.www.protocol.https.Handler()); + + + HttpsURLConnection con = (HttpsURLConnection) obj.openConnection(); + con.setRequestProperty("User-Agent", USER_AGENT); + int responseCode = con.getResponseCode(); + System.out.println("\nSending 'GET' request to URL : " + url); + System.out.println("Response Code : " + responseCode); + + BufferedReader in = new BufferedReader( + new InputStreamReader(con.getInputStream())); + String inputLine; + StringBuffer response = new StringBuffer(); + + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + in.close(); + return response.toString(); + } +} + + diff --git a/src/main/java/org/gcube/portal/TriggeredClass.java b/src/main/java/org/gcube/portal/TriggeredClass.java new file mode 100644 index 0000000..0f7c339 --- /dev/null +++ b/src/main/java/org/gcube/portal/TriggeredClass.java @@ -0,0 +1,69 @@ +package org.gcube.portal; + +import java.util.ArrayList; +import java.util.List; + +import org.gcube.vomanagement.usermanagement.GroupManager; +import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; +import org.gcube.vomanagement.usermanagement.util.ManagementUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.liferay.portal.kernel.events.ActionException; +import com.liferay.portal.kernel.events.SimpleAction; +import com.liferay.portal.model.Group; +import com.liferay.portal.model.LayoutSet; +import com.liferay.portal.service.GroupLocalServiceUtil; +import com.liferay.portal.service.VirtualHostLocalServiceUtil; +import com.liferay.portal.util.PortalUtil; + +public class TriggeredClass extends SimpleAction { + private static final Logger _log = LoggerFactory.getLogger(TriggeredClass.class); + + + /* (non-Java-doc) + * @see com.liferay.portal.kernel.events.SimpleAction#SimpleAction() + */ + public TriggeredClass() { + super(); + } + + /* (non-Java-doc) + * @see com.liferay.portal.kernel.events.SimpleAction#run(String[] arg0) + */ + public void run(String[] arg0) throws ActionException { + System.out.println("\n\nVRE-GATEWAY publisher starting ... "); + try { + List gateways = getGateways(new LiferayGroupManager()); + for (Gateway gateway : gateways) { + _log.info("found gateway: " + gateway.getSite().getName()); + } +// GetCaller gc = new GetCaller(urlsToContact); +// gc.start(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + public List getGateways(GroupManager groupsManager) { + List toReturn = new ArrayList<>(); + try{ + List candidateGateways = GroupLocalServiceUtil.getGroups(ManagementUtils.getCompany().getCompanyId(), 0, true); + // real gateways have no children as well + for (Group group : candidateGateways) { + List children = group.getChildren(true); + if(children == null || children.isEmpty()) + if(! (group.getFriendlyURL().equals("/guest") || group.getFriendlyURL().equals("/global") )) {// skipping these sites + toReturn.add(new Gateway(group)); + } + } + } catch(Exception e){ + _log.error("Failed to retrieve the list of gateways", e); + return null; + } + return toReturn; + } + +} \ No newline at end of file diff --git a/src/main/java/portal.properties b/src/main/java/portal.properties new file mode 100644 index 0000000..c02185e --- /dev/null +++ b/src/main/java/portal.properties @@ -0,0 +1,3 @@ +# +#Wed May 18 17:18:08 CEST 2016 +application.startup.events=org.gcube.portal.TriggeredClass diff --git a/src/main/webapp/WEB-INF/liferay-display.xml b/src/main/webapp/WEB-INF/liferay-display.xml deleted file mode 100644 index 0c94825..0000000 --- a/src/main/webapp/WEB-INF/liferay-display.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/liferay-hook.xml b/src/main/webapp/WEB-INF/liferay-hook.xml new file mode 100644 index 0000000..944195a --- /dev/null +++ b/src/main/webapp/WEB-INF/liferay-hook.xml @@ -0,0 +1,6 @@ + + + + + portal.properties + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/liferay-plugin-package.properties b/src/main/webapp/WEB-INF/liferay-plugin-package.properties index b8a348a..f2069cb 100644 --- a/src/main/webapp/WEB-INF/liferay-plugin-package.properties +++ b/src/main/webapp/WEB-INF/liferay-plugin-package.properties @@ -4,6 +4,6 @@ module-incremental-version=1 tags= short-description= change-log= -page-url=http://www.liferay.com -author=Liferay, Inc. -licenses=LGPL \ No newline at end of file +page-url=http://www.d4science.org +author=M. Assante +licenses=EUPL diff --git a/src/main/webapp/WEB-INF/liferay-portlet.xml b/src/main/webapp/WEB-INF/liferay-portlet.xml deleted file mode 100644 index ac8ec80..0000000 --- a/src/main/webapp/WEB-INF/liferay-portlet.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - vregateway-publisher-hook - /icon.png - /css/main.css - /js/main.js - - - administrator - Administrator - - - guest - Guest - - - power-user - Power User - - - user - User - - \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/portlet.xml b/src/main/webapp/WEB-INF/portlet.xml deleted file mode 100644 index 8e094a3..0000000 --- a/src/main/webapp/WEB-INF/portlet.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - vregateway-publisher-hook - vregateway-publisher-hook - com.liferay.util.bridges.mvc.MVCPortlet - - view-template - /view.jsp - - 0 - - text/html - - - vregateway-publisher-hook - vregateway-publisher-hook - vregateway-publisher-hook - - - administrator - - - guest - - - power-user - - - user - - - \ No newline at end of file diff --git a/src/main/webapp/css/main.css b/src/main/webapp/css/main.css deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/webapp/js/main.js b/src/main/webapp/js/main.js deleted file mode 100644 index e69de29..0000000