Search in sources :

Example 1 with ProgramMessageQueryParams

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);
}
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 2 with ProgramMessageQueryParams

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);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) DateTime(org.joda.time.DateTime) ProgramMessageQueryParams(org.hisp.dhis.program.message.ProgramMessageQueryParams) ProgramMessageRecipients(org.hisp.dhis.program.message.ProgramMessageRecipients) HashSet(java.util.HashSet)

Example 3 with ProgramMessageQueryParams

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);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ProgramMessageQueryParams(org.hisp.dhis.program.message.ProgramMessageQueryParams) SmsConfiguration(org.hisp.dhis.sms.config.SmsConfiguration) BulkSmsGatewayConfig(org.hisp.dhis.sms.config.BulkSmsGatewayConfig) ProgramMessageRecipients(org.hisp.dhis.program.message.ProgramMessageRecipients) Date(java.util.Date) HashSet(java.util.HashSet)

Aggregations

ProgramMessageQueryParams (org.hisp.dhis.program.message.ProgramMessageQueryParams)3 HashSet (java.util.HashSet)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 ProgramMessageRecipients (org.hisp.dhis.program.message.ProgramMessageRecipients)2 Date (java.util.Date)1 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)1 ProgramMessage (org.hisp.dhis.program.message.ProgramMessage)1 BulkSmsGatewayConfig (org.hisp.dhis.sms.config.BulkSmsGatewayConfig)1 SmsConfiguration (org.hisp.dhis.sms.config.SmsConfiguration)1 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)1 DateTime (org.joda.time.DateTime)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1