use of de.symeda.sormas.backend.common.TaskCreationException in project SORMAS-Project by hzi-braunschweig.
the class TaskService method getTaskAssignee.
public User getTaskAssignee(Contact contact) throws TaskCreationException {
User assignee = null;
if (contact.getContactOfficer() != null) {
// 1) The contact officer that is responsible for the contact
assignee = contact.getContactOfficer();
} else {
// 2) A random user with user right CONTACT_RESPONSIBLE from the contact's, contact person's or contact case's district
Function<District, User> lookupByDistrict = district -> userService.getRandomDistrictUser(district, UserRight.CONTACT_RESPONSIBLE);
if (contact.getDistrict() != null) {
assignee = lookupByDistrict.apply(contact.getDistrict());
}
if (assignee == null && contact.getPerson().getAddress().getDistrict() != null) {
assignee = lookupByDistrict.apply(contact.getPerson().getAddress().getDistrict());
}
Case contactCase = contact.getCaze();
if (assignee == null && contactCase != null) {
assignee = lookupByDistrict.apply(contactCase.getResponsibleDistrict());
if (assignee == null && contactCase.getDistrict() != null) {
assignee = lookupByDistrict.apply(contactCase.getDistrict());
}
}
}
if (assignee == null) {
// 3) Assign a random user with user right CONTACT_RESPONSIBLE from the contact's, contact person's or contact case's region
Function<Region, User> lookupByRegion = region -> userService.getRandomRegionUser(region, UserRight.CONTACT_RESPONSIBLE);
if (contact.getRegion() != null) {
assignee = lookupByRegion.apply(contact.getRegion());
}
if (assignee == null && contact.getPerson().getAddress().getRegion() != null) {
assignee = lookupByRegion.apply(contact.getPerson().getAddress().getRegion());
}
Case contactCase = contact.getCaze();
if (assignee == null && contactCase != null) {
assignee = lookupByRegion.apply(contactCase.getResponsibleRegion());
if (assignee == null && contactCase.getRegion() != null) {
assignee = lookupByRegion.apply(contactCase.getRegion());
}
}
if (assignee == null) {
throw new TaskCreationException("Contact has not contact officer and no region - can't create follow-up task: " + contact.getUuid());
}
}
return assignee;
}
use of de.symeda.sormas.backend.common.TaskCreationException in project SORMAS-Project by hzi-braunschweig.
the class ContactFacadeEjb method generateContactFollowUpTasks.
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
@RolesAllowed(UserRight._SYSTEM)
public void generateContactFollowUpTasks() {
// get all contacts that are followed up
LocalDateTime fromDateTime = LocalDate.now().atStartOfDay();
LocalDateTime toDateTime = fromDateTime.plusDays(1);
List<Contact> contacts = service.getFollowUpBetween(DateHelper8.toDate(fromDateTime), DateHelper8.toDate(toDateTime));
for (Contact contact : contacts) {
// Only generate tasks for contacts that are under follow-up
if (!(contact.getFollowUpStatus().equals(FollowUpStatus.FOLLOW_UP) || contact.getFollowUpStatus().equals(FollowUpStatus.LOST))) {
continue;
}
User assignee;
try {
assignee = taskService.getTaskAssignee(contact);
} catch (TaskCreationException e) {
logger.warn(e.getMessage());
continue;
}
// find already existing tasks
TaskCriteria pendingUserTaskCriteria = new TaskCriteria().contact(contact.toReference()).taskType(TaskType.CONTACT_FOLLOW_UP).assigneeUser(assignee.toReference()).taskStatus(TaskStatus.PENDING);
List<Task> pendingUserTasks = taskService.findBy(pendingUserTaskCriteria, true);
if (!pendingUserTasks.isEmpty()) {
// the user still has a pending task for this contact
continue;
}
TaskCriteria dayTaskCriteria = new TaskCriteria().contact(contact.toReference()).taskType(TaskType.CONTACT_FOLLOW_UP).dueDateBetween(DateHelper8.toDate(fromDateTime), DateHelper8.toDate(toDateTime));
List<Task> dayTasks = taskService.findBy(dayTaskCriteria, true);
if (!dayTasks.isEmpty()) {
// there is already a task for the exact day
continue;
}
// none found -> create the task
Task task = createContactTask(TaskType.CONTACT_FOLLOW_UP, fromDateTime, toDateTime, contact, assignee);
taskService.ensurePersisted(task);
}
}
use of de.symeda.sormas.backend.common.TaskCreationException in project SORMAS-Project by hzi-braunschweig.
the class ContactFacadeEjb method createInvestigationTask.
private void createInvestigationTask(Contact entity) {
LocalDate now = LocalDate.now();
LocalDate reportDate = DateHelper8.toLocalDate(entity.getReportDateTime());
if (DAYS.between(reportDate, now) <= 30) {
try {
User assignee = taskService.getTaskAssignee(entity);
LocalDateTime fromDateTime = LocalDate.now().atStartOfDay();
LocalDateTime toDateTime = fromDateTime.plusDays(1);
Task task = createContactTask(TaskType.CONTACT_INVESTIGATION, fromDateTime, toDateTime, entity, assignee);
taskService.ensurePersisted(task);
} catch (TaskCreationException e) {
logger.warn(e.getMessage());
}
}
}
Aggregations