Search in sources :

Example 1 with ProgramMessageRecipients

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()));
}
Also used : ProgramMessageRecipients(org.hisp.dhis.program.message.ProgramMessageRecipients) ProgramMessage(org.hisp.dhis.program.message.ProgramMessage) Test(org.junit.jupiter.api.Test)

Example 2 with ProgramMessageRecipients

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()));
}
Also used : ProgramMessageRecipients(org.hisp.dhis.program.message.ProgramMessageRecipients) ProgramMessage(org.hisp.dhis.program.message.ProgramMessage) Test(org.junit.jupiter.api.Test)

Example 3 with ProgramMessageRecipients

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;
}
Also used : ProgramMessageService(org.hisp.dhis.program.message.ProgramMessageService) java.util(java.util) CategoryService(org.hisp.dhis.category.CategoryService) NotificationMessageRenderer(org.hisp.dhis.notification.NotificationMessageRenderer) BiFunction(java.util.function.BiFunction) DataSet(org.hisp.dhis.dataset.DataSet) MessageConversationParams(org.hisp.dhis.message.MessageConversationParams) PeriodService(org.hisp.dhis.period.PeriodService) BatchResponseStatus(org.hisp.dhis.outboundmessage.BatchResponseStatus) ProgramMessage(org.hisp.dhis.program.message.ProgramMessage) Autowired(org.springframework.beans.factory.annotation.Autowired) CompleteDataSetRegistrationService(org.hisp.dhis.dataset.CompleteDataSetRegistrationService) SendStrategy(org.hisp.dhis.notification.SendStrategy) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) MessageService(org.hisp.dhis.message.MessageService) ProgramMessageRecipients(org.hisp.dhis.program.message.ProgramMessageRecipients) I18nFormat(org.hisp.dhis.i18n.I18nFormat) Service(org.springframework.stereotype.Service) User(org.hisp.dhis.user.User) NotificationTrigger(org.hisp.dhis.program.notification.NotificationTrigger) I18nManager(org.hisp.dhis.i18n.I18nManager) Period(org.hisp.dhis.period.Period) Function(com.google.common.base.Function) MessageType(org.hisp.dhis.message.MessageType) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) UserGroup(org.hisp.dhis.user.UserGroup) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) DeliveryChannel(org.hisp.dhis.common.DeliveryChannel) NotificationMessage(org.hisp.dhis.notification.NotificationMessage) DateUtils(org.hisp.dhis.util.DateUtils) TextUtils(org.hisp.dhis.commons.util.TextUtils) Transactional(org.springframework.transaction.annotation.Transactional) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DeliveryChannel(org.hisp.dhis.common.DeliveryChannel) ProgramMessageRecipients(org.hisp.dhis.program.message.ProgramMessageRecipients)

Example 4 with ProgramMessageRecipients

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;
}
Also used : NotificationMessage(org.hisp.dhis.notification.NotificationMessage) ProgramMessageRecipients(org.hisp.dhis.program.message.ProgramMessageRecipients) ProgramMessage(org.hisp.dhis.program.message.ProgramMessage)

Example 5 with ProgramMessageRecipients

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);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) DateTime(org.joda.time.DateTime) ProgramMessageQueryParams(org.hisp.dhis.program.message.ProgramMessageQueryParams) ProgramMessageRecipients(org.hisp.dhis.program.message.ProgramMessageRecipients) HashSet(java.util.HashSet)

Aggregations

ProgramMessageRecipients (org.hisp.dhis.program.message.ProgramMessageRecipients)10 ProgramMessage (org.hisp.dhis.program.message.ProgramMessage)6 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 DeliveryChannel (org.hisp.dhis.common.DeliveryChannel)3 NotificationMessage (org.hisp.dhis.notification.NotificationMessage)3 Test (org.junit.jupiter.api.Test)3 Sets (com.google.common.collect.Sets)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 Collectors (java.util.stream.Collectors)2 MessageService (org.hisp.dhis.message.MessageService)2 MessageType (org.hisp.dhis.message.MessageType)2 NotificationMessageRenderer (org.hisp.dhis.notification.NotificationMessageRenderer)2 BatchResponseStatus (org.hisp.dhis.outboundmessage.BatchResponseStatus)2 ProgramMessageQueryParams (org.hisp.dhis.program.message.ProgramMessageQueryParams)2 ProgramMessageService (org.hisp.dhis.program.message.ProgramMessageService)2 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)2 User (org.hisp.dhis.user.User)2 Function (com.google.common.base.Function)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1