Skip to content

Commit

Permalink
Updated Mailer Service
Browse files Browse the repository at this point in the history
  • Loading branch information
akumar074 committed Jan 5, 2023
1 parent d4a9d3f commit 039a187
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 27 deletions.
12 changes: 8 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-flyway</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-graphql</artifactId>
Expand Down Expand Up @@ -153,6 +149,14 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-container-image-jib</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-mutiny</artifactId>
</dependency>
<!-- Uncomment this next dependency if you are using JDK 10 or earlier and you also want to use
RSASSA-PSS (PS256, PS384, PS512) algorithms. JDK 11 or later does not require it for those algorithms:
<dependency>
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/shareNwork/domain/constants/EmailType.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

public enum EmailType {

OPENROTA_INVITATION("openRotaInvitation"),
OPENROTA_INVITATION("openrotaInvitation"),
INVITATION_EXPIRATION("invitationExpiration"),
NEW_ACCESS_REQ("newAccessReq"),
ACCESS_REQ_STATUS("accessReqStatus"),
NEW_RESOURCE_REQ("newResourceReq"),
RESOURCE_REQUEST_STATUS("resourceRequestStatus"),
PROJECT_CLOSURE_DUE_REMINDER("projectClosureDueReminder"),
PROJECT_CLOSURE_REMINDER("projectClosureReminder");
PROJECT_CLOSURE_REMINDER("projectClosureReminder"),
PROJECT_COMPLETED("projectCompleted");

private final String value;
EmailType(String value) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/shareNwork/proxy/MailerProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@Path("/mailer")
@Produces(MediaType.APPLICATION_JSON)
@RegisterRestClient(baseUri = "http://localhost:8082")
@RegisterRestClient
public interface MailerProxy {

@POST
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/shareNwork/repository/ProjectRepository.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.shareNwork.repository;

import com.shareNwork.domain.EmailData;
import com.shareNwork.domain.Project;
import com.shareNwork.domain.ProjectFeedback;
import com.shareNwork.domain.ProjectSkillsProficiency;
import com.shareNwork.domain.constants.EmailType;
import com.shareNwork.domain.constants.ProjectStatus;
import com.shareNwork.domain.constants.ResourceRequestStatus;
import com.shareNwork.proxy.MailerProxy;
import io.quarkus.hibernate.orm.panache.PanacheRepository;
import io.quarkus.mailer.Mail;
import org.eclipse.microprofile.rest.client.inject.RestClient;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
Expand All @@ -16,13 +21,17 @@
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@ApplicationScoped
public class ProjectRepository implements PanacheRepository<Project> {

@Inject
EntityManager em;

@RestClient
MailerProxy mailerProxy;

@Transactional
public Project createOrUpdateProject(Project project) throws ParseException {
if (project.id == null) {
Expand Down Expand Up @@ -109,6 +118,10 @@ public Project completeProject(long projectId, String comments) throws ParseExce
projectFeedback.setFeedback(comments);
projectFeedback.persist();
em.merge(project);
mailerProxy.sendEmail(EmailData.builder()
.emailType(EmailType.PROJECT_COMPLETED.value())
.mailTo(project.getProjectManager().getEmailId())
.emailTemplateVariables(Map.of("projectId", String.valueOf(projectId))).build());
}
else {
throw new NotFoundException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,18 @@ public ResourceRequest handleActions(RowAction actionName, ResourceRequest resou
}
request.setStatus(ResourceRequestStatus.COMPLETED);
convertResourceRequestToProject(request);
mailerProxy.sendEmail(new EmailData(EmailType.RESOURCE_REQUEST_STATUS.value(),
request.getRequester().getEmailId(),
Map.of("approved", String.valueOf(actionName.equals(RowAction.APPROVE)),
"resourceName", request.getResource().getEmailId())));
} else if (actionName.equals(RowAction.REJECT)) {
// send an email here
request.setStatus(ResourceRequestStatus.CANCELLED);
mailerProxy.sendEmail(new EmailData(EmailType.RESOURCE_REQUEST_STATUS.value(),
request.getRequester().getEmailId(),
Map.of("approved", String.valueOf(actionName.equals(RowAction.APPROVE)))));
}
em.merge(request);
mailerProxy.sendEmail(new EmailData(EmailType.RESOURCE_REQUEST_STATUS.value(),
request.getRequester().getEmailId(),
Map.of("approved", String.valueOf(actionName.equals(RowAction.APPROVE)),
"resourceName", request.getResource().getEmailId())));
} else {
throw new NotFoundException();
}
Expand Down
15 changes: 1 addition & 14 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
quarkus.package.type=${PACKAGE_TYPE:fast-jar}
quarkus.log.console.level=${LOG_CONSOLE_LEVEL:ALL}
openrota.ui.url=${OPENROTA_URL:https://prod.foo.redhat.com:1337/#/}
com.shareNwork.proxy.MailerProxy/mp-rest/url=http://localhost:8082


########################
Expand All @@ -27,16 +28,6 @@ quarkus.container-image.group=openrota
quarkus.container-image.name=openrota-backend


########################
# Mailer properties
########################
quarkus.mailer.auth-methods=DIGEST-MD5 CRAM-SHA256 CRAM-SHA1 CRAM-MD5 PLAIN LOGIN
quarkus.mailer.host=${MAILER_HOST:smtp.gmail.com}
quarkus.mailer.port=${MAILER_PORT:465}
quarkus.mailer.ssl=${MAILER_SSL:true}
quarkus.mailer.mock=${MAILER_MOCK_ENABLED:false}


########################
# Database properties
########################
Expand Down Expand Up @@ -64,7 +55,3 @@ quarkus.optaplanner.solver.termination.spent-limit=${OPTAPLANNER_SOLVER_TERMINAT
# Effectively disable this termination in favor of the best-score-limit
%test.quarkus.optaplanner.solver.termination.spent-limit=1h
%test.quarkus.optaplanner.solver.termination.best-score-limit=0hard/*soft


# Flyway minimal config properties
#quarkus.flyway.migrate-at-start=true
3 changes: 1 addition & 2 deletions src/test/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
quarkus.datasource.db-kind=h2
quarkus.datasource.jdbc.url=jdbc:h2:tcp://localhost/mem:test
quarkus.datasource.jdbc.driver=org.h2.Driver
quarkus.flyway.migrate-at-start=true

quarkus.http.auth.basic=false
quarkus.http.auth.basic=false

0 comments on commit 039a187

Please sign in to comment.