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);
}
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);
}
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));
}
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));
}
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;
}
Aggregations