ContactFacadeEjb implements ContactFacade { @RolesAllowed(UserRole._SYSTEM) @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void generateContactFollowUpTasks() { LocalDateTime fromDateTime = LocalDate.now().atStartOfDay(); LocalDateTime toDateTime = fromDateTime.plusDays(1); List<Contact> contacts = contactService.getFollowUpBetween(DateHelper8.toDate(fromDateTime), DateHelper8.toDate(toDateTime)); for (Contact contact : contacts) { 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; } 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()) { 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()) { continue; } Task task = createContactTask(TaskType.CONTACT_FOLLOW_UP, fromDateTime, toDateTime, contact, assignee); taskService.ensurePersisted(task); } }  @Override List<String> getAllActiveUuids(); @Override List<ContactDto> getAllActiveContactsAfter(Date date); @Override List<ContactDto> getByUuids(List<String> uuids); @Override List<String> getDeletedUuidsSince(Date since); @Override ContactDto getContactByUuid(String uuid); @Override Boolean isValidContactUuid(String uuid); @Override ContactReferenceDto getReferenceByUuid(String uuid); @Override ContactDto saveContact(ContactDto dto); @Override ContactDto saveContact(ContactDto dto, boolean handleChanges); @Override List<MapContactDto> getContactsForMap(
		RegionReferenceDto regionRef,
		DistrictReferenceDto districtRef,
		Disease disease,
		Date fromDate,
		Date toDate,
		List<MapCaseDto> mapCaseDtos); @Override void deleteContact(String contactUuid); @Override List<ContactExportDto> getExportList(ContactCriteria contactCriteria, int first, int max, Language userLanguage); @Override List<VisitSummaryExportDto> getVisitSummaryExportList(ContactCriteria contactCriteria, int first, int max, Language userLanguage); @Override long countMaximumFollowUpDays(ContactCriteria contactCriteria); @Override long count(ContactCriteria contactCriteria); @Override List<ContactFollowUpDto> getContactFollowUpList(
		ContactCriteria contactCriteria,
		Date referenceDate,
		int interval,
		Integer first,
		Integer max,
		List<SortProperty> sortProperties); @Override List<ContactIndexDto> getIndexList(ContactCriteria contactCriteria, Integer first, Integer max, List<SortProperty> sortProperties); @Override List<ContactIndexDetailedDto> getIndexDetailedList(
		ContactCriteria contactCriteria,
		Integer first,
		Integer max,
		List<SortProperty> sortProperties); @Override int[] getContactCountsByCasesForDashboard(List<Long> contactIds); @Override int getNonSourceCaseCountForDashboard(List<String> caseUuids); Contact fromDto(@NotNull ContactDto source); @Override boolean isDeleted(String contactUuid); @Override List<DashboardContactDto> getContactsForDashboard(
		RegionReferenceDto regionRef,
		DistrictReferenceDto districtRef,
		Disease disease,
		Date from,
		Date to); @Override List<DashboardQuarantineDataDto> getQuarantineDataForDashBoard(
		RegionReferenceDto regionRef,
		DistrictReferenceDto districtRef,
		Disease disease,
		Date from,
		Date to); @Override Map<ContactStatus, Long> getNewContactCountPerStatus(ContactCriteria contactCriteria); @Override Map<ContactClassification, Long> getNewContactCountPerClassification(ContactCriteria contactCriteria); @Override Map<FollowUpStatus, Long> getNewContactCountPerFollowUpStatus(ContactCriteria contactCriteria); @Override int getFollowUpUntilCount(ContactCriteria contactCriteria); ContactDto convertToDto(Contact source, Pseudonymizer pseudonymizer); static ContactReferenceDto toReferenceDto(Contact source); static ContactDto toDto(Contact source); @RolesAllowed(UserRole._SYSTEM) @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) void generateContactFollowUpTasks(); @Override void validate(ContactDto contact); @Override List<SimilarContactDto> getMatchingContacts(ContactSimilarityCriteria criteria); @Override boolean exists(String uuid); @Override boolean isContactEditAllowed(String contactUuid);  }
@Test public void testGenerateContactFollowUpTasks() { RDCFEntities rdcf = creator.createRDCFEntities("Region", "District", "Community", "Facility"); UserDto user = creator .createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR); UserDto contactOfficer = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Cont", "Off", UserRole.CONTACT_OFFICER); PersonDto cazePerson = creator.createPerson("Case", "Person"); CaseDataDto caze = creator.createCase( user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf); PersonDto contactPerson = creator.createPerson("Contact", "Person"); ContactDto contact = creator.createContact(user.toReference(), contactOfficer.toReference(), contactPerson.toReference(), caze, new Date(), new Date(), null); getContactFacade().generateContactFollowUpTasks(); List<TaskDto> tasks = getTaskFacade().getAllByContact(contact.toReference()).stream() .filter(t -> t.getTaskType() == TaskType.CONTACT_FOLLOW_UP) .collect(Collectors.toList()); assertEquals(1, tasks.size()); TaskDto task = tasks.get(0); assertEquals(TaskType.CONTACT_FOLLOW_UP, task.getTaskType()); assertEquals(TaskStatus.PENDING, task.getTaskStatus()); assertEquals(LocalDate.now(), DateHelper8.toLocalDate(task.getDueDate())); assertEquals(contactOfficer.toReference(), task.getAssigneeUser()); getContactFacade().generateContactFollowUpTasks(); tasks = getTaskFacade().getAllByContact(contact.toReference()).stream() .filter(t -> t.getTaskType() == TaskType.CONTACT_FOLLOW_UP) .collect(Collectors.toList()); assertEquals(1, tasks.size()); }