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>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</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"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<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"/>
</attributes>
</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"/>
</classpath>

View File

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

View File

@ -1,8 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
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.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">
<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="/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/resources"/>
<property name="context-root" value="mail-reader-lr62"/>
<property name="java-output-path" value="/mail-reader-lr62/target/classes"/>
</wb-module>
</project-modules>

View File

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

52
pom.xml
View File

@ -5,15 +5,31 @@
<parent>
<artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId>
<version>1.0.0</version>
<version>1.1.0</version>
<relativePath />
</parent>
<groupId>org.gcube.portal.liferay</groupId>
<artifactId>mail-reader-lr62</artifactId>
<artifactId>mailreader-lr62-hook</artifactId>
<packaging>war</packaging>
<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>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>com.liferay.maven.plugins</groupId>
@ -30,11 +46,10 @@
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.6</source>
<target>1.6</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
@ -51,13 +66,23 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>LATEST</version>
<version>3.6.0-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<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>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-service</artifactId>
@ -101,17 +126,4 @@
<artifactId>slf4j-api</artifactId>
</dependency>
</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>

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";
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;
@ -28,18 +27,11 @@ public class GetCaller extends Thread {
public void run() {
try {
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);
for (String url : urlsToContact) {
String response = sendHTTPsGet(url+SERVLET_CONTEXT_MAIL);
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) {
e.printStackTrace();
}

View File

@ -3,13 +3,19 @@ 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.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.util.PortalUtil;
public class ServletTrigger extends SimpleAction {
private static final Logger _log = LoggerFactory.getLogger(ServletTrigger.class);
@ -41,22 +47,48 @@ public class ServletTrigger extends SimpleAction {
* @return
*/
private List<String> getVirtualHostURLs() {
_log.info("MAIL_PARSER STARTING ... getVirtualHostURLs() ");
List<String> toReturn = new ArrayList<String>();
List<VirtualHost> vHosts = null;
List<String> toReturn = new ArrayList<>();
_log.info("MAIL_PARSER STARTING ... getGateways() ");
GroupManager gm = new LiferayGroupManager();
List<Gateway> gateways = getGateways(gm);
try {
vHosts = VirtualHostLocalServiceUtil.getVirtualHosts(0, VirtualHostLocalServiceUtil.getVirtualHostsCount());
for (VirtualHost virtualHost : vHosts) {
if (virtualHost.getHostname().compareTo("localhost") != 0 && virtualHost.getLayoutSetId() != 0) {
String hostToContact = PROTOCOL+virtualHost.getHostname();
toReturn.add(hostToContact);
_log.info("Added host to contact: " + hostToContact);
}
for (Gateway gateway : gateways) {
LayoutSet layoutSet = null;
Group childGroup = gateway.getSite();
if (childGroup.hasPublicLayouts())
layoutSet = childGroup.getPublicLayoutSet();
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();
}
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;
}
}