the class is triggered at startup, missing publish yet
This commit is contained in:
parent
e1970c99c2
commit
8f92b6ddac
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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<String> urlsToContact;
|
||||
|
||||
public GetCaller(List<String> 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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<Gateway> 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<Gateway> getGateways(GroupManager groupsManager) {
|
||||
List<Gateway> toReturn = new ArrayList<>();
|
||||
try{
|
||||
List<Group> candidateGateways = GroupLocalServiceUtil.getGroups(ManagementUtils.getCompany().getCompanyId(), 0, true);
|
||||
// real gateways have no children as well
|
||||
for (Group group : candidateGateways) {
|
||||
List<Group> 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
#
|
||||
#Wed May 18 17:18:08 CEST 2016
|
||||
application.startup.events=org.gcube.portal.TriggeredClass
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE display PUBLIC "-//Liferay//DTD Display 6.2.0//EN" "http://www.liferay.com/dtd/liferay-display_6_2_0.dtd">
|
||||
|
||||
<display>
|
||||
<category name="category.sample">
|
||||
<portlet id="vregateway-publisher-hook" />
|
||||
</category>
|
||||
</display>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.2.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_2_0.dtd">
|
||||
|
||||
<hook>
|
||||
<portal-properties>portal.properties</portal-properties>
|
||||
</hook>
|
|
@ -4,6 +4,6 @@ module-incremental-version=1
|
|||
tags=
|
||||
short-description=
|
||||
change-log=
|
||||
page-url=http://www.liferay.com
|
||||
author=Liferay, Inc.
|
||||
licenses=LGPL
|
||||
page-url=http://www.d4science.org
|
||||
author=M. Assante
|
||||
licenses=EUPL
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 6.2.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_6_2_0.dtd">
|
||||
|
||||
<liferay-portlet-app>
|
||||
<portlet>
|
||||
<portlet-name>vregateway-publisher-hook</portlet-name>
|
||||
<icon>/icon.png</icon>
|
||||
<header-portlet-css>/css/main.css</header-portlet-css>
|
||||
<footer-portlet-javascript>/js/main.js</footer-portlet-javascript>
|
||||
</portlet>
|
||||
<role-mapper>
|
||||
<role-name>administrator</role-name>
|
||||
<role-link>Administrator</role-link>
|
||||
</role-mapper>
|
||||
<role-mapper>
|
||||
<role-name>guest</role-name>
|
||||
<role-link>Guest</role-link>
|
||||
</role-mapper>
|
||||
<role-mapper>
|
||||
<role-name>power-user</role-name>
|
||||
<role-link>Power User</role-link>
|
||||
</role-mapper>
|
||||
<role-mapper>
|
||||
<role-name>user</role-name>
|
||||
<role-link>User</role-link>
|
||||
</role-mapper>
|
||||
</liferay-portlet-app>
|
|
@ -1,34 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0">
|
||||
<portlet>
|
||||
<portlet-name>vregateway-publisher-hook</portlet-name>
|
||||
<display-name>vregateway-publisher-hook</display-name>
|
||||
<portlet-class>com.liferay.util.bridges.mvc.MVCPortlet</portlet-class>
|
||||
<init-param>
|
||||
<name>view-template</name>
|
||||
<value>/view.jsp</value>
|
||||
</init-param>
|
||||
<expiration-cache>0</expiration-cache>
|
||||
<supports>
|
||||
<mime-type>text/html</mime-type>
|
||||
</supports>
|
||||
<portlet-info>
|
||||
<title>vregateway-publisher-hook</title>
|
||||
<short-title>vregateway-publisher-hook</short-title>
|
||||
<keywords>vregateway-publisher-hook</keywords>
|
||||
</portlet-info>
|
||||
<security-role-ref>
|
||||
<role-name>administrator</role-name>
|
||||
</security-role-ref>
|
||||
<security-role-ref>
|
||||
<role-name>guest</role-name>
|
||||
</security-role-ref>
|
||||
<security-role-ref>
|
||||
<role-name>power-user</role-name>
|
||||
</security-role-ref>
|
||||
<security-role-ref>
|
||||
<role-name>user</role-name>
|
||||
</security-role-ref>
|
||||
</portlet>
|
||||
</portlet-app>
|
Loading…
Reference in New Issue