use of org.hisp.dhis.program.message.ProgramMessageRecipients in project dhis2-core by dhis2.
the class MaintenanceServiceTest method testDeleteSoftDeletedProgramStageInstanceWithAProgramMessage.
@Test
void testDeleteSoftDeletedProgramStageInstanceWithAProgramMessage() {
ProgramMessageRecipients programMessageRecipients = new ProgramMessageRecipients();
programMessageRecipients.setEmailAddresses(Sets.newHashSet("testemail"));
programMessageRecipients.setPhoneNumbers(Sets.newHashSet("testphone"));
programMessageRecipients.setOrganisationUnit(organisationUnit);
ProgramMessage message = ProgramMessage.builder().subject("subject").text("text").recipients(programMessageRecipients).deliveryChannels(Sets.newHashSet(DeliveryChannel.EMAIL)).programStageInstance(programStageInstance).build();
long idA = programStageInstanceService.addProgramStageInstance(programStageInstance);
programMessageService.saveProgramMessage(message);
assertNotNull(programStageInstanceService.getProgramStageInstance(idA));
programStageInstanceService.deleteProgramStageInstance(programStageInstance);
assertNull(programStageInstanceService.getProgramStageInstance(idA));
assertTrue(programStageInstanceService.programStageInstanceExistsIncludingDeleted(programStageInstance.getUid()));
maintenanceService.deleteSoftDeletedProgramStageInstances();
assertFalse(programStageInstanceService.programStageInstanceExistsIncludingDeleted(programStageInstance.getUid()));
}
use of org.hisp.dhis.program.message.ProgramMessageRecipients in project dhis2-core by dhis2.
the class MaintenanceServiceTest method testDeleteSoftDeletedProgramInstanceWithAProgramMessage.
@Test
void testDeleteSoftDeletedProgramInstanceWithAProgramMessage() {
ProgramMessageRecipients programMessageRecipients = new ProgramMessageRecipients();
programMessageRecipients.setEmailAddresses(Sets.newHashSet("testemail"));
programMessageRecipients.setPhoneNumbers(Sets.newHashSet("testphone"));
programMessageRecipients.setOrganisationUnit(organisationUnit);
programMessageRecipients.setTrackedEntityInstance(entityInstance);
ProgramMessage message = ProgramMessage.builder().subject("subject").text("text").recipients(programMessageRecipients).deliveryChannels(Sets.newHashSet(DeliveryChannel.EMAIL)).programInstance(programInstance).build();
long idA = programInstanceService.addProgramInstance(programInstance);
programMessageService.saveProgramMessage(message);
assertNotNull(programInstanceService.getProgramInstance(idA));
programInstanceService.deleteProgramInstance(programInstance);
assertNull(programInstanceService.getProgramInstance(idA));
assertTrue(programInstanceService.programInstanceExistsIncludingDeleted(programInstance.getUid()));
maintenanceService.deleteSoftDeletedProgramInstances();
assertFalse(programInstanceService.programInstanceExistsIncludingDeleted(programInstance.getUid()));
}
use of org.hisp.dhis.program.message.ProgramMessageRecipients in project dhis2-core by dhis2.
the class DefaultDataSetNotificationService method resolveExternalRecipientsForSchedule.
private ProgramMessageRecipients resolveExternalRecipientsForSchedule(DataSetNotificationTemplate template, CompleteDataSetRegistration registration) {
ProgramMessageRecipients recipients = new ProgramMessageRecipients();
for (DeliveryChannel channel : template.getDeliveryChannels()) {
Set<OrganisationUnit> ous = registration.getDataSet().getSources().stream().filter(ou -> VALIDATOR.get(channel).test(ou)).collect(Collectors.toSet());
recipients = RECIPIENT_MAPPER.get(channel).apply(ous, recipients);
}
return recipients;
}
use of org.hisp.dhis.program.message.ProgramMessageRecipients in project dhis2-core by dhis2.
the class DefaultDataSetNotificationService method createProgramMessage.
private ProgramMessage createProgramMessage(DataSetNotificationTemplate template, CompleteDataSetRegistration registration) {
NotificationMessage message = renderer.render(registration, template);
ProgramMessageRecipients recipients;
if (template.getDataSetNotificationTrigger().isScheduled()) {
recipients = resolveExternalRecipientsForSchedule(template, registration);
} else {
recipients = resolveExternalRecipients(template, registration);
}
ProgramMessage programMessage = ProgramMessage.builder().subject(message.getSubject()).text(message.getMessage()).recipients(recipients).build();
programMessage.setDeliveryChannels(template.getDeliveryChannels());
return programMessage;
}
use of org.hisp.dhis.program.message.ProgramMessageRecipients in project dhis2-core by dhis2.
the class ProgramMessageStoreTest method setUpTest.
// -------------------------------------------------------------------------
// Prerequisite
// -------------------------------------------------------------------------
@Override
public void setUpTest() {
ouA = createOrganisationUnit('A');
ouB = createOrganisationUnit('B');
orgUnitService.addOrganisationUnit(ouA);
orgUnitService.addOrganisationUnit(ouB);
programA = createProgram('A', new HashSet<>(), ouA);
programService.addProgram(programA);
ProgramStage stageA = new ProgramStage("StageA", programA);
stageA.setSortOrder(1);
programStageService.saveProgramStage(stageA);
Set<ProgramStage> programStages = new HashSet<>();
programStages.add(stageA);
programA.setProgramStages(programStages);
programService.updateProgram(programA);
entityInstanceA = createTrackedEntityInstance(ouA);
entityInstanceService.addTrackedEntityInstance(entityInstanceA);
TrackedEntityInstance entityInstanceB = createTrackedEntityInstance(ouA);
entityInstanceService.addTrackedEntityInstance(entityInstanceB);
DateTime testDate1 = DateTime.now();
testDate1.withTimeAtStartOfDay();
testDate1 = testDate1.minusDays(70);
incidentDate = testDate1.toDate();
DateTime testDate2 = DateTime.now();
testDate2.withTimeAtStartOfDay();
enrollmentDate = testDate2.toDate();
programInstanceA = new ProgramInstance(enrollmentDate, incidentDate, entityInstanceA, programA);
programInstanceA.setUid("UID-A");
programStageInstanceA = new ProgramStageInstance(programInstanceA, stageA);
programStageInstanceA.setDueDate(enrollmentDate);
programStageInstanceA.setUid("UID-A");
Set<OrganisationUnit> ouSet = new HashSet<>();
ouSet.add(ouA);
Set<String> ouUids = new HashSet<>();
ouUids.add(ouA.getUid());
// ouSet.add( ouB );
teiA = createTrackedEntityInstance(ouA);
teiService.addTrackedEntityInstance(teiA);
recipientsA = new ProgramMessageRecipients();
recipientsA.setOrganisationUnit(ouA);
recipientsA.setTrackedEntityInstance(teiA);
recipientsB = new ProgramMessageRecipients();
recipientsB.setOrganisationUnit(ouA);
recipientsB.setTrackedEntityInstance(teiA);
recipientsC = new ProgramMessageRecipients();
recipientsC.setOrganisationUnit(ouA);
recipientsC.setTrackedEntityInstance(teiA);
Set<String> phoneNumberListA = new HashSet<>();
phoneNumberListA.add(msisdn);
recipientsA.setPhoneNumbers(phoneNumberListA);
Set<String> phoneNumberListB = new HashSet<>();
phoneNumberListB.add(msisdn);
recipientsB.setPhoneNumbers(phoneNumberListB);
Set<String> phoneNumberListC = new HashSet<>();
phoneNumberListC.add(msisdn);
recipientsC.setPhoneNumbers(phoneNumberListC);
channels.add(DeliveryChannel.SMS);
pmsgA = ProgramMessage.builder().subject(text).text(text).recipients(recipientsA).messageStatus(messageStatus).deliveryChannels(channels).notificationTemplate(notificationTemplate).build();
pmsgB = ProgramMessage.builder().subject(text).text(text).recipients(recipientsB).messageStatus(messageStatus).deliveryChannels(channels).notificationTemplate(notificationTemplate).build();
pmsgC = ProgramMessage.builder().subject(text).text(text).recipients(recipientsC).messageStatus(messageStatus).deliveryChannels(channels).notificationTemplate(notificationTemplate).build();
uidA = CodeGenerator.generateCode(10);
uidB = CodeGenerator.generateCode(10);
uidC = CodeGenerator.generateCode(10);
pmsgA.setUid(uidA);
pmsgB.setUid(uidB);
pmsgC.setUid(uidC);
params = new ProgramMessageQueryParams();
params.setOrganisationUnit(ouUids);
}
Aggregations