Search in sources :

Example 6 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 7 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 8 with ProgramMessage

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

the class ProgramMessageServiceTest method testSaveProgramMessage.

@Test
public void testSaveProgramMessage() {
    Integer pmsgAId = null;
    pmsgAId = programMessageService.saveProgramMessage(pmsgA);
    assertNotNull(pmsgAId);
    ProgramMessage programMessage = programMessageService.getProgramMessage(pmsgAId.intValue());
    assertTrue(programMessage.equals(pmsgA));
}
Also used : ProgramMessage(org.hisp.dhis.program.message.ProgramMessage) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 9 with ProgramMessage

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

the class ProgramMessageStoreTest method testGetProgramMessage.

// -------------------------------------------------------------------------
// Tests
// -------------------------------------------------------------------------
@Test
public void testGetProgramMessage() {
    programMessageStore.save(pmsgA);
    Integer id = pmsgA.getId();
    ProgramMessage actual = programMessageStore.get(id.intValue());
    assertNotNull(id);
    assertNotNull(actual);
    assertTrue(actual.equals(pmsgA));
}
Also used : ProgramMessage(org.hisp.dhis.program.message.ProgramMessage) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 10 with ProgramMessage

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

the class DhisConvenienceTest method createProgramMessage.

public static ProgramMessage createProgramMessage(String text, String subject, ProgramMessageRecipients recipients, ProgramMessageStatus status, Set<DeliveryChannel> channels) {
    ProgramMessage message = new ProgramMessage();
    message.setText(text);
    message.setSubject(subject);
    message.setRecipients(recipients);
    message.setMessageStatus(status);
    message.setDeliveryChannels(channels);
    return message;
}
Also used : ProgramMessage(org.hisp.dhis.program.message.ProgramMessage)

Aggregations

ProgramMessage (org.hisp.dhis.program.message.ProgramMessage)10 DhisSpringTest (org.hisp.dhis.DhisSpringTest)6 Test (org.junit.Test)6 ProgramMessageQueryParams (org.hisp.dhis.program.message.ProgramMessageQueryParams)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 HashSet (java.util.HashSet)1 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 BatchResponseStatus (org.hisp.dhis.outboundmessage.BatchResponseStatus)1 ProgramMessageBatch (org.hisp.dhis.program.message.ProgramMessageBatch)1 ProgramMessageRecipients (org.hisp.dhis.program.message.ProgramMessageRecipients)1 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)1 DateTime (org.joda.time.DateTime)1