Skip to content

Commit

Permalink
Added new templates
Browse files Browse the repository at this point in the history
  • Loading branch information
akumar074 committed Jan 4, 2023
1 parent 04c029f commit f93ca9a
Show file tree
Hide file tree
Showing 16 changed files with 269 additions and 32 deletions.
20 changes: 18 additions & 2 deletions src/main/java/io/openrota/constants/MailerConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,23 @@

public class MailerConstants {

public static final String OPENROTA_INVITATION = "openRotaInvitation";
public static final String OPENROTA_INVITATION = "openrotaInvitation";
public static final String INVITATION_EXPIRATION = "invitationExpiration";
public static final String NEW_ACCESS_REQ = "newAccessReq";
public static final String ACCESS_REQ_STATUS = "accessReqStatus";
public static final String NEW_RESOURCE_REQ = "newResourceReq";
public static final String RESOURCE_REQUEST_STATUS = "resourceRequestStatus";
public static final String PROJECT_CLOSURE_DUE_REMINDER = "projectClosureDueReminder";
public static final String PROJECT_CLOSURE_REMINDER = "projectClosureReminder";
public static final String PROJECT_COMPLETED = "projectCompleted";

public static final String OPENROTA_INVITATION_SUBJECT = "[Action Required] Invitation from OpenRota";
}
public static final String INVITATION_EXPIRATION_SUBJECT = "Your Openrota invitation is expiring";
public static final String NEW_ACCESS_REQ_SUBJECT = "Openrota access request opened";
public static final String ACCESS_REQ_STATUS_SUBJECT = "Your Openrota access request status";
public static final String NEW_RESOURCE_REQ_SUBJECT = "New resource request opened";
public static final String RESOURCE_REQUEST_STATUS_SUBJECT = "Your Openrota resource request status";
public static final String PROJECT_CLOSURE_DUE_REMINDER_SUBJECT = "Reminder for dueproject closure";
public static final String PROJECT_CLOSURE_REMINDER_SUBJECT = "Reminder for project completion";
public static final String PROJECT_COMPLETED_SUBJECT = "Your project has been completed successfully";
}
20 changes: 18 additions & 2 deletions src/main/java/io/openrota/resource/MailerResource.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package io.openrota.resource;

import java.util.List;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import io.openrota.domain.EmailData;
import io.openrota.service.EventBusService;
import org.eclipse.microprofile.openapi.annotations.parameters.RequestBody;
import org.jboss.logging.Logger;

@Path("/mailer")
@ApplicationScoped
@Produces
public class MailerResource {
private static final Logger LOGGER = Logger.getLogger(MailerResource.class);

private final EventBusService eventBusService;

Expand All @@ -23,9 +29,19 @@ public MailerResource(EventBusService eventBusService) {

@POST
@Path("/mail")
@Consumes("application/json")
@Consumes(MediaType.APPLICATION_JSON)
public Response sendMail(@RequestBody EmailData emailData) {
eventBusService.sendEvent(emailData);
eventBusService.sendEvent(emailData).subscribe()
.with(item -> LOGGER.info(String.format("Mail %s sent Successfully!", emailData.getEmailType())),
failure -> LOGGER.error(failure));
return Response.accepted().entity("Email sent!").build();
}

@POST
@Path("/multi-mail")
@Consumes(MediaType.APPLICATION_JSON)
public Response sendMail(@RequestBody List<EmailData> emailDataList) {
emailDataList.stream().parallel().forEach(emailData -> eventBusService.sendEvent(emailData));
return Response.accepted().entity("Reminder mails sent!").build();
}
}
9 changes: 4 additions & 5 deletions src/main/java/io/openrota/service/EventBusService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.openrota.service;

import io.openrota.domain.EmailData;
import io.smallrye.mutiny.Uni;
import io.vertx.mutiny.core.eventbus.EventBus;
import io.vertx.mutiny.core.eventbus.Message;
import org.jboss.logging.Logger;
Expand All @@ -16,11 +17,9 @@ public class EventBusService {
@Inject
EventBus eventBus;

public void sendEvent(EmailData data) {
eventBus.request(data.getEmailType(), data)
.onFailure().invoke(e -> LOGGER.error(e.getMessage()))
.onItem().transform(Message::body)
.subscribe().with(t -> LOGGER.info("Event " + data.getEmailType() + " sent successfully!"));
public Uni sendEvent(EmailData data) {
return eventBus.request(data.getEmailType(), data)
.onItem().transform(Message::body);
}

}
18 changes: 17 additions & 1 deletion src/main/java/io/openrota/service/MailerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,21 @@

public interface MailerService {

Uni<String> send(final EmailData emailData);
Uni<Void> sendInvite(final EmailData emailData);

Uni<Void> sendInviteReminder(final EmailData emailData);

Uni<Void> sendNewAccessReq(final EmailData emailData);

Uni<Void> sendAccessReqStatus(final EmailData emailData);

Uni<Void> sendNewResourceReq(final EmailData emailData);

Uni<Void> sendResourceRequestStatus(final EmailData emailData);

Uni<Void> sendProjectClosureDueReminder(final EmailData emailData);

Uni<Void> sendProjectClosureReminder(final EmailData emailData);

Uni<Void> sendProjectCompletion(final EmailData emailData);
}
117 changes: 107 additions & 10 deletions src/main/java/io/openrota/service/impl/MailerServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.openrota.service.impl;

import java.util.Map;

import io.openrota.constants.MailerConstants;
import io.openrota.domain.EmailData;
import io.openrota.service.MailerService;
Expand All @@ -18,18 +20,113 @@ public class MailerServiceImpl implements MailerService {
private static final Logger LOGGER = Logger.getLogger(MailerServiceImpl.class);

@Inject
@Location("openRotaInvitation")
MailTemplate openRotaInvitation;
@Location("openrotaInvitation")
MailTemplate openrotaInvitation;
@Inject
@Location("inviteExpireReminder")
MailTemplate invitationExpiration;
@Inject
@Location("newAccessReq")
MailTemplate newAccessReq;
@Inject
@Location("accessReqStatus")
MailTemplate accessReqStatus;
@Inject
@Location("newResourceReq")
MailTemplate newResourceReq;
@Inject
@Location("resourceRequestStatus")
MailTemplate resourceRequestStatus;
@Inject
@Location("projectClosureDueReminder")
MailTemplate projectClosureDueReminder;
@Inject
@Location("projectClosureReminder")
MailTemplate projectClosureReminder;

@Inject
@Location("projectCompleted")
MailTemplate projectCompleted;

@Override
@ConsumeEvent(value = MailerConstants.OPENROTA_INVITATION)
public Uni<String> send(final EmailData emailData) {
openRotaInvitation.to(emailData.getMailTo())
.subject(MailerConstants.OPENROTA_INVITATION_SUBJECT)
.data("invitationLink", emailData.getEmailTemplateVariables().get("invitationLink"))
.send()
.subscribe()
.with(t -> LOGGER.info("Mail sent to " + emailData.getMailTo()));
return Uni.createFrom().item(() -> "Mail sent to " + emailData.getMailTo());
public Uni<Void> sendInvite(final EmailData emailData) {
return send(openrotaInvitation,
emailData,
MailerConstants.OPENROTA_INVITATION_SUBJECT);
}

@Override
@ConsumeEvent(value = MailerConstants.INVITATION_EXPIRATION)
public Uni<Void> sendInviteReminder(EmailData emailData) {
return send(invitationExpiration,
emailData,
MailerConstants.INVITATION_EXPIRATION_SUBJECT);
}

@Override
@ConsumeEvent(value = MailerConstants.NEW_ACCESS_REQ)
public Uni<Void> sendNewAccessReq(EmailData emailData) {
return send(newAccessReq,
emailData,
MailerConstants.NEW_ACCESS_REQ_SUBJECT);
}

@Override
@ConsumeEvent(value = MailerConstants.ACCESS_REQ_STATUS)
public Uni<Void> sendAccessReqStatus(EmailData emailData) {
return send(accessReqStatus,
emailData,
MailerConstants.ACCESS_REQ_STATUS_SUBJECT);
}

@Override
@ConsumeEvent(value = MailerConstants.NEW_RESOURCE_REQ)
public Uni<Void> sendNewResourceReq(EmailData emailData) {
return send(newResourceReq,
emailData,
MailerConstants.NEW_RESOURCE_REQ_SUBJECT); }

@Override
@ConsumeEvent(value = MailerConstants.RESOURCE_REQUEST_STATUS)
public Uni<Void> sendResourceRequestStatus(EmailData emailData) {
return send(resourceRequestStatus,
emailData,
MailerConstants.RESOURCE_REQUEST_STATUS_SUBJECT);
}

@Override
@ConsumeEvent(value = MailerConstants.PROJECT_CLOSURE_DUE_REMINDER)
public Uni<Void> sendProjectClosureDueReminder(EmailData emailData) {
return send(projectClosureDueReminder,
emailData,
MailerConstants.PROJECT_CLOSURE_DUE_REMINDER_SUBJECT);
}

@Override
@ConsumeEvent(value = MailerConstants.PROJECT_CLOSURE_REMINDER)
public Uni<Void> sendProjectClosureReminder(EmailData emailData) {
return send(projectClosureReminder,
emailData,
MailerConstants.PROJECT_CLOSURE_REMINDER_SUBJECT);
}

@Override
@ConsumeEvent(value = MailerConstants.PROJECT_COMPLETED)
public Uni<Void> sendProjectCompletion(EmailData emailData) {
return send(projectCompleted,
emailData,
MailerConstants.PROJECT_COMPLETED_SUBJECT);
}

private Uni<Void> send(MailTemplate template, final EmailData emailData, final String subject) {
MailTemplate.MailTemplateInstance ins = template.to(emailData.getMailTo())
.subject(subject);
initData(ins, emailData.getEmailTemplateVariables());
return ins.send();
}

private void initData(MailTemplate.MailTemplateInstance template, Map<String, String> templateVariables) {
templateVariables.entrySet().forEach(entry -> template.data(entry.getKey(), entry.getValue()));
}
}
2 changes: 2 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ quarkus.mailer.mock=${MAILER_MOCK_ENABLED:false}
quarkus.mailer.from=
quarkus.mailer.username=
quarkus.mailer.password=

%dev.quarkus.http.port=8082
14 changes: 14 additions & 0 deletions src/main/resources/templates/accessReqStatus.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Your openrota access request status</title>
</head>
<body>
{#if approved is 'true'}
<h3> Your openrota access request has been approved. You can now log in to openrota and create resource requests.</h3>
{#else}
<h3> Your openrota access request has been rejected. Please contact Openrota administrator for more details or raise a new access request.</h3>
{/if}
</body>
</html>
10 changes: 10 additions & 0 deletions src/main/resources/templates/inviteExpireReminder.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Your Openrota invitation is expiring</title>
</head>
<body>
<h3>Your Openrota invitation is expiring on {expiresOn}. Please login from openrota invitation to avoid expiration of invite.</h3>
</body>
</html>
10 changes: 10 additions & 0 deletions src/main/resources/templates/newAccessReq.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Openrota access request opened</title>
</head>
<body>
<h3>We have received your request to allow access to open Resource requests, We’ll let you know once your request has been accepted or rejected.</h3>
</body>
</html>
10 changes: 10 additions & 0 deletions src/main/resources/templates/newResourceReq.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>New Resource Request Opened</title>
</head>
<body>
<h3>You have created a new Request {requestId} to allocate resources for your project {projectName}. You’ll receive a confirmation email once your request is approved.</h3>
</body>
</html>
12 changes: 0 additions & 12 deletions src/main/resources/templates/openRotaInvitation.html

This file was deleted.

12 changes: 12 additions & 0 deletions src/main/resources/templates/openrotaInvitation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Invitation to OpenRota</title>
</head>
<body>
<h3 style="color: rgb(255, 0, 0)">IMPORTANT!</h3>
<h3>You are invited to join OpenRota. Please click the link below to review/update your profile.</h3>
<div><a href="{invitationLink}">Click Here</a></div>
</body>
</html>
10 changes: 10 additions & 0 deletions src/main/resources/templates/projectClosureDueReminder.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Reminder for project closure</title>
</head>
<body>
<h3>Your project {projectId} is scheduled to complete and {resourceName} will be released. Kindly head over to the application to complete and provide feedback for {projectId} or apply for extension.</h5>
</body>
</html>
10 changes: 10 additions & 0 deletions src/main/resources/templates/projectClosureReminder.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Project Completion Reminder</title>
</head>
<body>
<h3>Your project {projectId} is autocomplete since it has already passed the due date and the {resourceName} has been released and is now available for new projects. Kindly head over to the application to provide the feedback for {projectId}.</h5>
</body>
</html>
10 changes: 10 additions & 0 deletions src/main/resources/templates/projectCompleted.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h3>Your project with ID #{projectId} has been successfully completed. Please share your feedback on [email protected].</h3>
</body>
</html>
17 changes: 17 additions & 0 deletions src/main/resources/templates/resourceRequestStatus.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Your Openrota resource request status</title>
</head>
<body>
{#if approved is 'true'}
<h3>Your resource request has been approved and We have assigned {resourceName} to work on the task.
You can now go to “My projects” and view your project status.
You can find guidelines for onboarding resources here.
In case of any issue please reach out to [email protected].</h3>
{#else}
<h3>Your resource request has been rejected. Please contact Openrota administrator for more details or raise a new request.</h3>
{/if}
</body>
</html>

0 comments on commit f93ca9a

Please sign in to comment.