Search in sources :

Example 1 with ProgramMessage

use of org.hisp.dhis.program.message.ProgramMessage in project dhis2-core by dhis2.

the class ProgramMessageController method saveMessages.

// -------------------------------------------------------------------------
// POST
// -------------------------------------------------------------------------
@PreAuthorize("hasRole('ALL') or hasRole('F_MOBILE_SENDSMS')")
@RequestMapping(method = RequestMethod.POST, consumes = { "application/json" }, produces = { "application/json" })
public void saveMessages(HttpServletRequest request, HttpServletResponse response) throws IOException, WebMessageException {
    ProgramMessageBatch batch = renderService.fromJson(request.getInputStream(), ProgramMessageBatch.class);
    for (ProgramMessage programMessage : batch.getProgramMessages()) {
        programMessageService.validatePayload(programMessage);
    }
    BatchResponseStatus status = programMessageService.sendMessages(batch.getProgramMessages());
    response.setContentType(MediaType.APPLICATION_JSON_VALUE);
    renderService.toJson(response.getOutputStream(), status);
}
Also used : ProgramMessageBatch(org.hisp.dhis.program.message.ProgramMessageBatch) BatchResponseStatus(org.hisp.dhis.outboundmessage.BatchResponseStatus) ProgramMessage(org.hisp.dhis.program.message.ProgramMessage) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ProgramMessage

use of org.hisp.dhis.program.message.ProgramMessage in project dhis2-core by dhis2.

the class ProgramMessageController method getProgramMessages.

// -------------------------------------------------------------------------
// GET
// -------------------------------------------------------------------------
@PreAuthorize("hasRole('ALL') or hasRole('F_MOBILE_SENDSMS')")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" })
public void getProgramMessages(@RequestParam(required = false) Set<String> ou, @RequestParam(required = false) String programInstance, @RequestParam(required = false) String programStageInstance, @RequestParam(required = false) ProgramMessageStatus messageStatus, @RequestParam(required = false) Date afterDate, @RequestParam(required = false) Date beforeDate, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer pageSize, HttpServletRequest request, HttpServletResponse response) throws IOException, WebMessageException {
    ProgramMessageQueryParams params = programMessageService.getFromUrl(ou, programInstance, programStageInstance, messageStatus, page, pageSize, afterDate, beforeDate);
    if (programInstance == null && programStageInstance == null) {
        throw new WebMessageException(WebMessageUtils.conflict("ProgramInstance or ProgramStageInstance must be specified."));
    }
    List<ProgramMessage> programMessages = programMessageService.getProgramMessages(params);
    renderService.toJson(response.getOutputStream(), programMessages);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ProgramMessageQueryParams(org.hisp.dhis.program.message.ProgramMessageQueryParams) ProgramMessage(org.hisp.dhis.program.message.ProgramMessage) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ProgramMessage

use of org.hisp.dhis.program.message.ProgramMessage 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 4 with ProgramMessage

use of org.hisp.dhis.program.message.ProgramMessage 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 5 with ProgramMessage

use of org.hisp.dhis.program.message.ProgramMessage 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)

Aggregations

ProgramMessage (org.hisp.dhis.program.message.ProgramMessage)22 Test (org.junit.jupiter.api.Test)16 BatchResponseStatus (org.hisp.dhis.outboundmessage.BatchResponseStatus)8 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)7 NotificationTemplate (org.hisp.dhis.notification.NotificationTemplate)7 DhisSpringTest (org.hisp.dhis.DhisSpringTest)6 ProgramInstance (org.hisp.dhis.program.ProgramInstance)5 ProgramMessageRecipients (org.hisp.dhis.program.message.ProgramMessageRecipients)4 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 SqlHelper (org.hisp.dhis.commons.util.SqlHelper)1 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)1 NotificationMessage (org.hisp.dhis.notification.NotificationMessage)1 ProgramMessageBatch (org.hisp.dhis.program.message.ProgramMessageBatch)1 ProgramMessageQueryParams (org.hisp.dhis.program.message.ProgramMessageQueryParams)1