-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3231: Add PendingAssessmentsNotificationWorker
- Loading branch information
Showing
11 changed files
with
978 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
src/main/java/mil/dds/anet/emails/PendingAssessmentsNotificationEmail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package mil.dds.anet.emails; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.stream.Collectors; | ||
import mil.dds.anet.AnetObjectEngine; | ||
import mil.dds.anet.beans.Person; | ||
import mil.dds.anet.beans.Position; | ||
import mil.dds.anet.beans.Task; | ||
import mil.dds.anet.utils.IdDataLoaderKey; | ||
import mil.dds.anet.views.UuidFetcher; | ||
|
||
public class PendingAssessmentsNotificationEmail implements AnetEmailAction { | ||
|
||
private String advisorUuid; | ||
private List<String> positionUuidsToAssess; | ||
private List<String> taskUuidsToAssess; | ||
|
||
@Override | ||
public String getTemplateName() { | ||
return "/emails/pendingAssessmentsNotification.ftlh"; | ||
} | ||
|
||
@Override | ||
public String getSubject(Map<String, Object> context) { | ||
return "ANET assessments due"; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> buildContext(Map<String, Object> context) { | ||
@SuppressWarnings("unchecked") | ||
final Map<String, Object> dbContext = (Map<String, Object>) context.get("context"); | ||
|
||
// Load positions and person & organization for each position | ||
final UuidFetcher<Position> positionFetcher = new UuidFetcher<Position>(); | ||
final List<CompletableFuture<Position>> positions = positionUuidsToAssess.stream() | ||
.map(uuid -> positionFetcher.load(dbContext, IdDataLoaderKey.POSITIONS, uuid) | ||
.thenCompose(pos -> pos.loadPerson(dbContext).thenCompose( | ||
person -> pos.loadOrganization(dbContext).thenApply(organization -> pos)))) | ||
.collect(Collectors.toList()); | ||
|
||
// Load tasks | ||
final UuidFetcher<Task> taskFetcher = new UuidFetcher<Task>(); | ||
final List<CompletableFuture<Task>> tasks = taskUuidsToAssess.stream() | ||
.map(uuid -> taskFetcher.load(dbContext, IdDataLoaderKey.TASKS, uuid)) | ||
.collect(Collectors.toList()); | ||
|
||
// Wait for our futures to complete | ||
final List<CompletableFuture<?>> allFutures = new ArrayList<>(); | ||
allFutures.addAll(positions); | ||
allFutures.addAll(tasks); | ||
CompletableFuture.allOf(allFutures.toArray(new CompletableFuture<?>[0])).join(); | ||
|
||
// Fill email context | ||
context.put("advisor", AnetObjectEngine.getInstance().getPersonDao().getByUuid(advisorUuid)); | ||
context.put("positions", positions.stream().map(p -> p.join()).collect(Collectors.toList())); | ||
context.put("tasks", tasks.stream().map(p -> p.join()).collect(Collectors.toList())); | ||
return context; | ||
} | ||
|
||
public String getAdvisorUuid() { | ||
return advisorUuid; | ||
} | ||
|
||
public void setAdvisorUuid(String advisorUuid) { | ||
this.advisorUuid = advisorUuid; | ||
} | ||
|
||
public void setAdvisor(Person advisor) { | ||
this.advisorUuid = advisor.getUuid(); | ||
} | ||
|
||
public List<String> getPositionUuidsToAssess() { | ||
return positionUuidsToAssess; | ||
} | ||
|
||
public void setPositionUuidsToAssess(List<String> positionUuidsToAssess) { | ||
this.positionUuidsToAssess = positionUuidsToAssess; | ||
} | ||
|
||
public void setPositionsToAssess(Set<Position> positionsToAssess) { | ||
this.positionUuidsToAssess = | ||
positionsToAssess.stream().map(p -> p.getUuid()).collect(Collectors.toList()); | ||
} | ||
|
||
public List<String> getTaskUuidsToAssess() { | ||
return taskUuidsToAssess; | ||
} | ||
|
||
public void setTaskUuidsToAssess(List<String> taskUuidsToAssess) { | ||
this.taskUuidsToAssess = taskUuidsToAssess; | ||
} | ||
|
||
public void setTasksToAssess(Set<Task> tasksToAssess) { | ||
this.taskUuidsToAssess = | ||
tasksToAssess.stream().map(t -> t.getUuid()).collect(Collectors.toList()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.