Massimiliano Assante 2021-02-23 10:56:03 +00:00
parent 55475388c3
commit 3c0fc67a12
9 changed files with 128 additions and 49 deletions

View File

@ -15,11 +15,7 @@
<attributes> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> <attribute name="test" value="true"/>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
@ -28,5 +24,10 @@
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/> <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes> </attributes>
</classpathentry> </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"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>
</classpath> </classpath>

View File

@ -1,4 +1,5 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
encoding//src/main/java=UTF-8 encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8 encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8 encoding/<project>=UTF-8

View File

@ -1,8 +1,11 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.6 org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.6 org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -1,10 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> <?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="mail-reader-lr62-hook"> <wb-module deploy-name="mail-reader-lr62-hook">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/> <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/> <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<property name="context-root" value="mail-reader-lr62"/> <property name="context-root" value="mail-reader-lr62"/>
<property name="java-output-path" value="/mail-reader-lr62/target/classes"/> <property name="java-output-path" value="/mail-reader-lr62/target/classes"/>
</wb-module> </wb-module>
</project-modules> </project-modules>

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<faceted-project> <faceted-project>
<fixed facet="wst.jsdt.web"/> <fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.6"/>
<installed facet="jst.web" version="2.4"/> <installed facet="jst.web" version="2.4"/>
<installed facet="liferay.hook" version="6.0"/> <installed facet="liferay.hook" version="6.0"/>
<installed facet="wst.jsdt.web" version="1.0"/> <installed facet="wst.jsdt.web" version="1.0"/>
<installed facet="java" version="1.8"/>
</faceted-project> </faceted-project>

52
pom.xml
View File

@ -5,15 +5,31 @@
<parent> <parent>
<artifactId>maven-parent</artifactId> <artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId> <groupId>org.gcube.tools</groupId>
<version>1.0.0</version> <version>1.1.0</version>
<relativePath /> <relativePath />
</parent> </parent>
<groupId>org.gcube.portal.liferay</groupId> <groupId>org.gcube.portal.liferay</groupId>
<artifactId>mail-reader-lr62</artifactId> <artifactId>mailreader-lr62-hook</artifactId>
<packaging>war</packaging> <packaging>war</packaging>
<name>mail-reader-lr62 Hook</name> <name>mail-reader-lr62 Hook</name>
<version>1.0.0-SNAPSHOT</version> <version>2.0.0-SNAPSHOT</version>
<properties>
<liferay.version>6.2.5</liferay.version>
<liferay.maven.plugin.version>6.2.5</liferay.maven.plugin.version>
<liferay.auto.deploy.dir>/Users/massi/portal/liferay-portal-6.2-ce-ga6/deploy</liferay.auto.deploy.dir>
<liferay.app.server.deploy.dir>/Users/massi/portal/liferay-portal-6.2-ce-ga6/tomcat-7.0.62/webapps</liferay.app.server.deploy.dir>
<liferay.app.server.lib.global.dir>/Users/massi/portal/liferay-portal-6.2-ce-ga6/tomcat-7.0.62/lib/ext</liferay.app.server.lib.global.dir>
<liferay.app.server.portal.dir>/Users/massi/portal/liferay-portal-6.2-ce-ga6/tomcat-7.0.62/webapps/ROOT</liferay.app.server.portal.dir>
</properties>
<build> <build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
<plugins> <plugins>
<plugin> <plugin>
<groupId>com.liferay.maven.plugins</groupId> <groupId>com.liferay.maven.plugins</groupId>
@ -30,11 +46,10 @@
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>2.5</version>
<configuration> <configuration>
<encoding>UTF-8</encoding> <encoding>UTF-8</encoding>
<source>1.6</source> <source>1.8</source>
<target>1.6</target> <target>1.8</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
@ -51,13 +66,23 @@
<dependency> <dependency>
<groupId>org.gcube.distribution</groupId> <groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId> <artifactId>maven-portal-bom</artifactId>
<version>LATEST</version> <version>3.6.0-SNAPSHOT</version>
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
<dependencies> <dependencies>
<dependency>
<groupId>org.gcube.dvos</groupId>
<artifactId>usermanagement-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common.portal</groupId>
<artifactId>portal-manager</artifactId>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>com.liferay.portal</groupId> <groupId>com.liferay.portal</groupId>
<artifactId>portal-service</artifactId> <artifactId>portal-service</artifactId>
@ -101,17 +126,4 @@
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
<profiles>
<profile>
<id>Liferay-v6.2-CE-(Tomcat-7)-(2)</id>
<properties>
<liferay.version>6.2.5</liferay.version>
<liferay.maven.plugin.version>6.2.5</liferay.maven.plugin.version>
<liferay.auto.deploy.dir>/Users/massi/portal/liferay-portal-6.2-ce-ga6/deploy</liferay.auto.deploy.dir>
<liferay.app.server.deploy.dir>/Users/massi/portal/liferay-portal-6.2-ce-ga6/tomcat-7.0.62/webapps</liferay.app.server.deploy.dir>
<liferay.app.server.lib.global.dir>/Users/massi/portal/liferay-portal-6.2-ce-ga6/tomcat-7.0.62/lib/ext</liferay.app.server.lib.global.dir>
<liferay.app.server.portal.dir>/Users/massi/portal/liferay-portal-6.2-ce-ga6/tomcat-7.0.62/webapps/ROOT</liferay.app.server.portal.dir>
</properties>
</profile>
</profiles>
</project> </project>

View File

@ -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();
}
}

View File

@ -13,7 +13,6 @@ public class GetCaller extends Thread {
private final static String USER_AGENT = "Mozilla/5.0"; private final static String USER_AGENT = "Mozilla/5.0";
protected static final String SERVLET_CONTEXT_MAIL = "/social-mail-servlet/start-email-reader"; protected static final String SERVLET_CONTEXT_MAIL = "/social-mail-servlet/start-email-reader";
protected static final String SERVLET_URL_LDAP = "/ldap-export-servlet/start-ldap-export";
private List<String> urlsToContact; private List<String> urlsToContact;
@ -28,18 +27,11 @@ public class GetCaller extends Thread {
public void run() { public void run() {
try { try {
System.out.println("********** READING MAILS THREAD Waiting ... starting in " + WAITING_MILLISECONDS/60000 + " minutes"); System.out.println("********** READING MAILS THREAD Waiting ... starting in " + WAITING_MILLISECONDS/60000 + " minutes");
System.out.println("********** LDAP EXPORT THREAD Waiting ... starting in " + WAITING_MILLISECONDS/60000 + " minutes");
Thread.sleep(WAITING_MILLISECONDS); Thread.sleep(WAITING_MILLISECONDS);
for (String url : urlsToContact) { for (String url : urlsToContact) {
String response = sendHTTPsGet(url+SERVLET_CONTEXT_MAIL); String response = sendHTTPsGet(url+SERVLET_CONTEXT_MAIL);
System.out.println("**********\n\n"+ "Called URL=" + url + " correctly, response:" + response); System.out.println("**********\n\n"+ "Called URL=" + url + " correctly, response:" + response);
} }
if (!urlsToContact.isEmpty()) {
String response_ldap = sendHTTPsGet(urlsToContact.get(0)+SERVLET_URL_LDAP);
System.out.println("**********\n\n"+ "Called URL=" + urlsToContact.get(0)+SERVLET_URL_LDAP + " correctly, response: " + response_ldap);
} else {
System.out.println("The list of virtualHost was empty");
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -3,13 +3,19 @@ package org.gcube.portal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.liferay.portal.kernel.events.ActionException; import com.liferay.portal.kernel.events.ActionException;
import com.liferay.portal.kernel.events.SimpleAction; import com.liferay.portal.kernel.events.SimpleAction;
import com.liferay.portal.model.VirtualHost; 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.service.VirtualHostLocalServiceUtil;
import com.liferay.portal.util.PortalUtil;
public class ServletTrigger extends SimpleAction { public class ServletTrigger extends SimpleAction {
private static final Logger _log = LoggerFactory.getLogger(ServletTrigger.class); private static final Logger _log = LoggerFactory.getLogger(ServletTrigger.class);
@ -41,22 +47,48 @@ public class ServletTrigger extends SimpleAction {
* @return * @return
*/ */
private List<String> getVirtualHostURLs() { private List<String> getVirtualHostURLs() {
_log.info("MAIL_PARSER STARTING ... getVirtualHostURLs() "); List<String> toReturn = new ArrayList<>();
List<String> toReturn = new ArrayList<String>(); _log.info("MAIL_PARSER STARTING ... getGateways() ");
List<VirtualHost> vHosts = null; GroupManager gm = new LiferayGroupManager();
List<Gateway> gateways = getGateways(gm);
try { try {
vHosts = VirtualHostLocalServiceUtil.getVirtualHosts(0, VirtualHostLocalServiceUtil.getVirtualHostsCount()); for (Gateway gateway : gateways) {
for (VirtualHost virtualHost : vHosts) { LayoutSet layoutSet = null;
if (virtualHost.getHostname().compareTo("localhost") != 0 && virtualHost.getLayoutSetId() != 0) { Group childGroup = gateway.getSite();
String hostToContact = PROTOCOL+virtualHost.getHostname(); if (childGroup.hasPublicLayouts())
toReturn.add(hostToContact); layoutSet = childGroup.getPublicLayoutSet();
_log.info("Added host to contact: " + hostToContact); else
} layoutSet = childGroup.getPrivateLayoutSet();
final long companyId = PortalUtil.getDefaultCompanyId();
long layoutSetId = layoutSet.getLayoutSetId();
String virtualHost = VirtualHostLocalServiceUtil.getVirtualHost(companyId, layoutSetId).getHostname();
String hostToContact = PROTOCOL+virtualHost;
toReturn.add(hostToContact);
_log.info("\n*** MAILReader - Added host to contact: " + hostToContact);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return toReturn; return toReturn;
} }
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;
}
} }