Initial import.

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/email-templates-library@148561 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2017-05-12 10:19:12 +00:00
parent 1853c6153a
commit 869c426823
35 changed files with 8406 additions and 0 deletions

27
.classpath Normal file
View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</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>

36
.project Normal file
View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>email-templates-library</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>

View File

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

View File

@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
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.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="email-templates-library">
<wb-resource deploy-path="/" source-path="/src/main/java"/>
</wb-module>
</project-modules>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<installed facet="jst.utility" version="1.0"/>
<installed facet="java" version="1.8"/>
</faceted-project>

View File

@ -0,0 +1,2 @@
disabled=06target
eclipse.preferences.version=1

1
distro/LICENSE Normal file
View File

@ -0,0 +1 @@
${gcube.license}

67
distro/README Normal file
View File

@ -0,0 +1,67 @@
The gCube System - ${name}
--------------------------------------------------
${description}
${gcube.description}
${gcube.funding}
Version
--------------------------------------------------
${version} (${buildDate})
Please see the file named "changelog.xml" in this directory for the release notes.
Authors
--------------------------------------------------
* Massimiliano Assante (massimiliano.assante-AT-isti.cnr.it), Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" - CNR, Pisa (Italy).
Maintainers
-----------
* Massimiliano Assante (massimiliano.assante-AT-isti.cnr.it), Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" - CNR, Pisa (Italy).
Download information
--------------------------------------------------
Source code is available from SVN:
${scm.url}
Binaries can be downloaded from the gCube website:
${gcube.website}
Installation
--------------------------------------------------
Installation documentation is available on-line in the gCube Wiki:
${gcube.wikiRoot}/
Documentation
--------------------------------------------------
Documentation is available on-line in the gCube Wiki:
${gcube.wikiRoot}/
${gcube.wikiRoot}/
Support
--------------------------------------------------
Bugs and support requests can be reported in the gCube issue tracking tool:
${gcube.issueTracking}
Licensing
--------------------------------------------------
This software is licensed under the terms you may find in the file named "LICENSE" in this directory.

6
distro/changelog.xml Normal file
View File

@ -0,0 +1,6 @@
<ReleaseNotes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="xsd/changelog.xsd">
<Changeset component=" org.gcube.portal.mailing.email-templates-library.1-0-0" date="2017-05-11">
<Change>First Release</Change>
</Changeset>
</ReleaseNotes>

42
distro/descriptor.xml Normal file
View File

@ -0,0 +1,42 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>servicearchive</id>
<formats>
<format>tar.gz</format>
</formats>
<baseDirectory>/</baseDirectory>
<fileSets>
<fileSet>
<directory>${distroDirectory}</directory>
<outputDirectory>/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>README</include>
<include>LICENSE</include>
<include>changelog.xml</include>
<include>profile.xml</include>
</includes>
<fileMode>755</fileMode>
<filtered>true</filtered>
</fileSet>
<fileSet>
<directory>target/apidocs</directory>
<outputDirectory>/${artifactId}/doc/api</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<fileMode>755</fileMode>
</fileSet>
</fileSets>
<files>
<file>
<source>${distroDirectory}/profile.xml</source>
<outputDirectory>./</outputDirectory>
<filtered>true</filtered>
</file>
<file>
<source>target/${build.finalName}.jar</source>
<outputDirectory>/${artifactId}</outputDirectory>
</file>
</files>
</assembly>

25
distro/profile.xml Normal file
View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<Resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID></ID>
<Type>Library</Type>
<Profile>
<Description>${description}</Description>
<Class>Portal</Class>
<Name>${artifactId}</Name>
<Version>1.0.0</Version>
<Packages>
<Software>
<Name>${artifactId}</Name>
<Version>${version}</Version>
<MavenCoordinates>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
</MavenCoordinates>
<Files>
<File>${build.finalName}.jar</File>
</Files>
</Software>
</Packages>
</Profile>
</Resource>

147
pom.xml Normal file
View File

@ -0,0 +1,147 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId>
<version>1.0.0</version>
<relativePath />
</parent>
<groupId>org.gcube.portal.mailing</groupId>
<artifactId>email-templates-library</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>email-templates-library</name>
<description>email-templates-library is used to send predefined email messages</description>
<scm>
<connection>scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/portal/${project.artifactId}</connection>
<developerConnection>scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/portal/${project.artifactId}</developerConnection>
<url>http://svn.d4science.research-infrastructures.eu/gcube/trunk/portal/${project.artifactId}</url>
</scm>
<properties>
<distroDirectory>distro</distroDirectory>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>LATEST</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.common.portal</groupId>
<artifactId>portal-manager</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.dvos</groupId>
<artifactId>usermanagement-core</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-profile</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target</outputDirectory>
<resources>
<resource>
<directory>${distroDirectory}</directory>
<filtering>true</filtering>
<includes>
<include>profile.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<configuration>
<descriptors>
<descriptor>${distroDirectory}/descriptor.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>servicearchive</id>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,57 @@
package org.gcube.portal.mailing.message;
/**
* Represents an email address.
*
* @author Massimiliano Assante, CNR-ISTI
*
*/
public class EmailAddress {
/**
* The email address part (is of the form "user@domain.host")
*/
private String address;
/**
* The user name part (can be anything)
*/
private String personal;
/**
* Initialize the address with the email address and the personal parts.
*
* @param address the email address part, it is of the form "user@domain.host"
* @param personal the personal part
*/
public EmailAddress(String address, String personal) {
super();
this.address = address;
this.personal = personal;
}
/**
* Initialize the address with only the email address part.
* It is of the form "anyuser@anydomain.anyhost".
*
* @param address the email address part
*/
public EmailAddress(String address) {
this(address, null);
}
public String getAddress() {
return address;
}
public String getPersonal() {
return personal;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
if (personal != null && !personal.isEmpty()) {
builder.append(personal).append(" ");
}
builder.append("<").append(address).append(">");
return builder.toString();
}
}

View File

@ -0,0 +1,72 @@
package org.gcube.portal.mailing.message;
/**
* Represents an email recipient. The recipient contains:
* <ul>
* <li>The email address (see {@link EmailAddress})</li>
* <li>The recipient type (the field of the email: to, cc, bcc)</li>
* </ul>
*
* @author Massimiliano Assante, CNR-ISTI
*
*
*/
public class Recipient {
/**
* The recipient type
*/
private RecipientType type;
/**
* The recipient address
*/
private EmailAddress address;
/**
* The address is of the form "anyuser@anyhost.anydomain" or "Name LastName &lt;user@host.domain&gt;".
* The recipient type is set to {@link RecipientType#TO}.
*
* @param address the email address as described above
*/
public Recipient(String address) {
this(new EmailAddress(address));
}
/**
* Initialize the recipient with the provided address. The recipient type is
* set to {@link RecipientType#TO}.
*
* @param address
* the email address
*/
public Recipient(EmailAddress address) {
this(address, RecipientType.TO);
}
/**
* Initialize the recipient with the provided address and for the provided type.
*
* @param address the email address
* @param type the recipient type see {@link RecipientType#TO}.
*/
public Recipient(EmailAddress address, RecipientType type) {
super();
this.address = address;
this.type = type;
}
public EmailAddress getAddress() {
return address;
}
public RecipientType getType() {
return type;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(address).append("(").append(type).append(")");
return builder.toString();
}
}

View File

@ -0,0 +1,12 @@
package org.gcube.portal.mailing.message;
/**
*
* @author Massimiliano Assante, CNR-ISTI
*
*/
public enum RecipientType {
TO,
CC,
BCC;
}

View File

@ -0,0 +1,60 @@
package org.gcube.portal.mailing.service;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.gcube.common.portal.mailing.EmailNotification;
import org.gcube.common.portal.mailing.EmailNotification.EmailBuilder;
import org.gcube.common.portal.mailing.templates.Template;
import org.gcube.portal.mailing.message.Recipient;
/**
*
* @author Massimiliano Assante, CNR-ISTI
*
*/
public class EmailTemplateService {
/**
*
* Initialize the email with the following information:
* <ul>
* <li>The subject of the email</li>
* <li>The template instance for this email</li>
* <li>The httpServletRequest object</li>
* <li>One or several "to" recipient addresses</li>
* </ul>
*
* @param emailrecipients an list of email addresses to be added in the TO
* @param subject the subject of your email
* @param bodyTextHTML the body of your email in HTML
* @param httpServletRequest the httpServletRequest object if you have it, null otherwise (but the default sender will be applied in this case)
*/
public static void send(String subject, Template selectedTemplate, HttpServletRequest httpServletRequest, Recipient ... emailrecipients) {
List<String> toEmailrecipients = new ArrayList<>();
List<String> ccEmailrecipients = new ArrayList<>();
List<String> bccEmailrecipients = new ArrayList<>();
for (Recipient recipient : emailrecipients) {
switch (recipient.getType()) {
case TO:
toEmailrecipients.add(recipient.getAddress().getAddress());
break;
case CC:
ccEmailrecipients.add(recipient.getAddress().getAddress());
break;
case BCC:
bccEmailrecipients.add(recipient.getAddress().getAddress());
break;
}
}
EmailNotification mailToAdmin =
new EmailBuilder(subject, httpServletRequest, toEmailrecipients.toArray(new String[toEmailrecipients.size()]))
.withTemplate(selectedTemplate)
.cc(ccEmailrecipients.toArray(new String[ccEmailrecipients.size()]))
.bcc(ccEmailrecipients.toArray(new String[bccEmailrecipients.size()]))
.build();
mailToAdmin.sendEmail();
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,20 @@
STEP 1:
open link “http://foundation.zurb.com/emails/inliner.html” and paste $yourfile.html code inside the textarea provided.
Click on “Convert Email” button.
Remove the complete <style> tag from $yourfile.html, we do not need <style> tag since all our css classes have been assigned to the HTML tags as inline styles.
STEP 2:
Encode everything Base64 with an online tool: e.g. https://www.base64encode.org
Use the encoded string in the code then sthe like:
byte[] base64DecodedData = Base64.getDecoder().decode(encodedTemplate);
String template = new String(base64DecodedData)
.replace("{{SELECTED_VRE_NAME}}", selectedVRE)
.replace("{{USER_NAME}}", name)
.replace("{{OPTIONAL_MESSAGE}}", optionalMessage);
body.append(template);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,10 @@
{{GATEWAY_NAME}}
----------------------------------
Hi {{INVITED_USER_NAME}},
{{INVITING_USER_FULLNAME}} has invited you to {{SELECTED_VRE_NAME}}, you can find a brief description below:
{{SELECTED_VRE_DESCRIPTION}}
To accept the invite just follow this link: {{ACCEPT_INVITE_URL}}
Please note: if you do not have an account yet, sign up first: {{CREATE_ACCOUNT_URL}}

View File

@ -0,0 +1,12 @@
{{GATEWAY_NAME}}
----------------------------------
{{USER_FULLNAME}} has accepted the invite on {{SELECTED_VRE_NAME}} VRE.
Further info about {{USER_FULLNAME}}:
Email: {{USER_EMAIL}}
Username: {{USER_ID}}
You received this email because you are a manager of {{SELECTED_VRE_NAME}}.
The invite was sent by {{USER_WHO_INVITED}} ({{USER_WHO_INVITED_USERNAME}}) on {{INVITE_DATE}}.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,13 @@
{{GATEWAY_NAME}}
----------------------------------
{{USER_FULLNAME}} has just invited {{INVITED_USER_EMAIL}} to {{SELECTED_VRE_NAME}} VRE.
Further info about {{USER_FULLNAME}}:
Email: {{USER_EMAIL}}
Username: {{USER_ID}}
You received this email because you are a manager of {{SELECTED_VRE_NAME}}.
See all invites in {{SELECTED_VRE_NAME}} VRE: {{MANAGE_INVITE_URL}}

View File

@ -0,0 +1,14 @@
{{GATEWAY_NAME}}
----------------------------------
{{USER_FULLNAME}} would like to access {{SELECTED_VRE_NAME}} VRE, please manage this request:
{{MANAGE_REQUEST_URL}}
Further info about {{USER_FULLNAME}}:
Email: {{USER_EMAIL}}
Username: {{USER_ID}}
Optional message:
{{OPTIONAL_MESSAGE}}
You received this email because you are a manager of {{SELECTED_VRE_NAME}}.

View File

@ -0,0 +1,12 @@
{{GATEWAY_NAME}}
----------------------------------
{{USER_FULLNAME}} has self registered to {{SELECTED_VRE_NAME}} VRE.
Further info about {{USER_FULLNAME}}:
Email: {{USER_EMAIL}}
Username: {{USER_ID}}
You received this email because you are a manager of {{SELECTED_VRE_NAME}}.

View File

@ -0,0 +1,38 @@
package org.gcube.portal.mailing.email_templates_library;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}
}