use of org.hisp.dhis.program.message.ProgramMessageRecipients in project dhis2-core by dhis2.
the class DefaultProgramNotificationService method resolveRecipients.
private ProgramMessageRecipients resolveRecipients(ProgramNotificationTemplate template, OrganisationUnit ou, TrackedEntityInstance tei, ProgramInstance pi) {
ProgramMessageRecipients recipients = new ProgramMessageRecipients();
ProgramNotificationRecipient recipientType = template.getNotificationRecipient();
if (recipientType == ProgramNotificationRecipient.ORGANISATION_UNIT_CONTACT) {
recipients.setOrganisationUnit(ou);
} else if (recipientType == ProgramNotificationRecipient.TRACKED_ENTITY_INSTANCE) {
recipients.setTrackedEntityInstance(tei);
} else if (recipientType == ProgramNotificationRecipient.PROGRAM_ATTRIBUTE && template.getRecipientProgramAttribute() != null) {
List<String> recipientList = pi.getEntityInstance().getTrackedEntityAttributeValues().stream().filter(av -> template.getRecipientProgramAttribute().getUid().equals(av.getAttribute().getUid())).map(TrackedEntityAttributeValue::getPlainValue).collect(Collectors.toList());
if (template.getDeliveryChannels().contains(DeliveryChannel.SMS)) {
recipients.getPhoneNumbers().addAll(recipientList);
} else if (template.getDeliveryChannels().contains(DeliveryChannel.EMAIL)) {
recipients.getEmailAddresses().addAll(recipientList);
}
}
return recipients;
}
use of org.hisp.dhis.program.message.ProgramMessageRecipients in project dhis2-core by dhis2.
the class DefaultProgramNotificationService method resolveProgramMessageRecipients.
private ProgramMessageRecipients resolveProgramMessageRecipients(ProgramNotificationTemplate template, OrganisationUnit organisationUnit, ProgramInstance programInstance) {
ProgramMessageRecipients recipients = new ProgramMessageRecipients();
TrackedEntityInstance trackedEntityInstance = programInstance.getEntityInstance();
ProgramNotificationRecipient recipientType = template.getNotificationRecipient();
if (recipientType == ProgramNotificationRecipient.ORGANISATION_UNIT_CONTACT) {
recipients.setOrganisationUnit(organisationUnit);
} else if (recipientType == ProgramNotificationRecipient.TRACKED_ENTITY_INSTANCE) {
recipients.setTrackedEntityInstance(trackedEntityInstance);
} else if (recipientType == ProgramNotificationRecipient.PROGRAM_ATTRIBUTE && template.getRecipientProgramAttribute() != null) {
List<String> recipientList = programInstance.getEntityInstance().getTrackedEntityAttributeValues().stream().filter(av -> template.getRecipientProgramAttribute().getUid().equals(av.getAttribute().getUid())).map(av -> av.getPlainValue()).collect(Collectors.toList());
if (template.getDeliveryChannels().contains(DeliveryChannel.SMS)) {
recipients.getPhoneNumbers().addAll(recipientList);
} else if (template.getDeliveryChannels().contains(DeliveryChannel.EMAIL)) {
recipients.getEmailAddresses().addAll(recipientList);
}
}
return recipients;
}
use of org.hisp.dhis.program.message.ProgramMessageRecipients in project dhis2-core by dhis2.
the class ProgramMessageServiceTest method setUpTest.
// -------------------------------------------------------------------------
// Prerequisite
// -------------------------------------------------------------------------
@Override
public void setUpTest() {
ouA = createOrganisationUnit('A');
ouA.setPhoneNumber(msisdn);
ouB = createOrganisationUnit('B');
orgUnitService.addOrganisationUnit(ouA);
orgUnitService.addOrganisationUnit(ouB);
Program program = createProgram('A');
program.setAutoFields();
program.setOrganisationUnits(Sets.newHashSet(ouA, ouB));
program.setName("programA");
program.setShortName("programAshortname");
program.setProgramType(ProgramType.WITHOUT_REGISTRATION);
programService.addProgram(program);
piA = new ProgramInstance();
piA.setProgram(program);
piA.setOrganisationUnit(ouA);
piA.setName("programInstanceA");
piA.setEnrollmentDate(new Date());
piA.setAutoFields();
programInstanceService.addProgramInstance(piA);
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);
recipientsD = new ProgramMessageRecipients();
recipientsD.setOrganisationUnit(ouA);
recipientsD.setTrackedEntityInstance(null);
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 = createProgramMessage(text, subject, recipientsA, messageStatus, channels);
pmsgA.setProgramInstance(piA);
pmsgA.setStoreCopy(false);
pmsgB = createProgramMessage(text, subject, recipientsB, messageStatus, channels);
pmsgB.setProgramInstance(piA);
pmsgC = createProgramMessage(text, subject, recipientsC, messageStatus, channels);
pmsgD = createProgramMessage(text, subject, recipientsD, messageStatus, channels);
pmsgD.setProgramInstance(piA);
pmsgD.setStoreCopy(false);
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);
params.setProgramInstance(piA);
params.setMessageStatus(messageStatus);
bulkSmsConfig = new BulkSmsGatewayConfig();
bulkSmsConfig.setDefault(true);
bulkSmsConfig.setName("bulk");
bulkSmsConfig.setUsername("user_uio");
bulkSmsConfig.setPassword("5cKMMQTGNMkD");
SmsConfiguration smsConfig = new SmsConfiguration();
smsConfig.getGateways().add(bulkSmsConfig);
smsConfigurationManager.updateSmsConfiguration(smsConfig);
}
use of org.hisp.dhis.program.message.ProgramMessageRecipients in project dhis2-core by dhis2.
the class MaintenanceServiceTest method testDeleteSoftDeletedTrackedEntityInstanceAProgramMessage.
@Test
void testDeleteSoftDeletedTrackedEntityInstanceAProgramMessage() {
ProgramMessageRecipients programMessageRecipients = new ProgramMessageRecipients();
programMessageRecipients.setEmailAddresses(Sets.newHashSet("testemail"));
programMessageRecipients.setPhoneNumbers(Sets.newHashSet("testphone"));
programMessageRecipients.setOrganisationUnit(organisationUnit);
programMessageRecipients.setTrackedEntityInstance(entityInstanceB);
ProgramMessage message = ProgramMessage.builder().subject("subject").text("text").recipients(programMessageRecipients).deliveryChannels(Sets.newHashSet(DeliveryChannel.EMAIL)).build();
long idA = entityInstanceService.addTrackedEntityInstance(entityInstanceB);
programMessageService.saveProgramMessage(message);
assertNotNull(entityInstanceService.getTrackedEntityInstance(idA));
entityInstanceService.deleteTrackedEntityInstance(entityInstanceB);
assertNull(entityInstanceService.getTrackedEntityInstance(idA));
assertTrue(entityInstanceService.trackedEntityInstanceExistsIncludingDeleted(entityInstanceB.getUid()));
maintenanceService.deleteSoftDeletedTrackedEntityInstances();
assertFalse(entityInstanceService.trackedEntityInstanceExistsIncludingDeleted(entityInstanceB.getUid()));
}
use of org.hisp.dhis.program.message.ProgramMessageRecipients in project dhis2-core by dhis2.
the class DefaultDataSetNotificationService method resolveExternalRecipients.
private ProgramMessageRecipients resolveExternalRecipients(DataSetNotificationTemplate template, CompleteDataSetRegistration registration) {
ProgramMessageRecipients recipients = new ProgramMessageRecipients();
OrganisationUnit ou = registration.getSource();
for (DeliveryChannel channel : template.getDeliveryChannels()) {
if (VALIDATOR.get(channel).test(ou)) {
recipients = RECIPIENT_MAPPER.get(channel).apply(Sets.newHashSet(ou), recipients);
} else {
log.error(String.format("DataSet notification not sent due to invalid %s recipient", channel));
throw new IllegalArgumentException(String.format("Invalid %s recipient", channel));
}
}
return recipients;
}
Aggregations