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