use of org.hisp.dhis.program.message.ProgramMessageQueryParams 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.ProgramMessageQueryParams 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);
}
use of org.hisp.dhis.program.message.ProgramMessageQueryParams in project dhis2-core by dhis2.
the class ProgramMessageServiceTest method setUpTest.
// -------------------------------------------------------------------------
// Prerequisite
// -------------------------------------------------------------------------
@Override
public void setUpTest() {
ouA = createOrganisationUnit('A');
ouA.setPhoneNumber(msisdn);
ouB = createOrganisationUnit('B');
orgUnitService.addOrganisationUnit(ouA);
orgUnitService.addOrganisationUnit(ouB);
Program program = createProgram('A');
program.setAutoFields();
program.setOrganisationUnits(Sets.newHashSet(ouA, ouB));
program.setName("programA");
program.setShortName("programAshortname");
program.setProgramType(ProgramType.WITHOUT_REGISTRATION);
programService.addProgram(program);
piA = new ProgramInstance();
piA.setProgram(program);
piA.setOrganisationUnit(ouA);
piA.setName("programInstanceA");
piA.setEnrollmentDate(new Date());
piA.setAutoFields();
programInstanceService.addProgramInstance(piA);
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);
recipientsD = new ProgramMessageRecipients();
recipientsD.setOrganisationUnit(ouA);
recipientsD.setTrackedEntityInstance(null);
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 = createProgramMessage(text, subject, recipientsA, messageStatus, channels);
pmsgA.setProgramInstance(piA);
pmsgA.setStoreCopy(false);
pmsgB = createProgramMessage(text, subject, recipientsB, messageStatus, channels);
pmsgB.setProgramInstance(piA);
pmsgC = createProgramMessage(text, subject, recipientsC, messageStatus, channels);
pmsgD = createProgramMessage(text, subject, recipientsD, messageStatus, channels);
pmsgD.setProgramInstance(piA);
pmsgD.setStoreCopy(false);
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);
params.setProgramInstance(piA);
params.setMessageStatus(messageStatus);
bulkSmsConfig = new BulkSmsGatewayConfig();
bulkSmsConfig.setDefault(true);
bulkSmsConfig.setName("bulk");
bulkSmsConfig.setUsername("user_uio");
bulkSmsConfig.setPassword("5cKMMQTGNMkD");
SmsConfiguration smsConfig = new SmsConfiguration();
smsConfig.getGateways().add(bulkSmsConfig);
smsConfigurationManager.updateSmsConfiguration(smsConfig);
}
Aggregations