Search in sources :

Example 11 with SmsConfiguration

use of org.hisp.dhis.sms.config.SmsConfiguration in project dhis2-core by dhis2.

the class UpdateDefaultGatewayAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    SmsConfiguration smsConfig = smsConfigurationManager.getSmsConfiguration();
    SmsGatewayConfig defaultGateway = smsConfig.getGateways().get(index);
    if (defaultGateway != null) {
        int i = 0;
        for (SmsGatewayConfig gw : smsConfig.getGateways()) {
            if (index == i) {
                gw.setDefault(true);
                log.info(gw.getName() + " is set as default gateway");
            } else {
                gw.setDefault(false);
            }
            smsConfig.getGateways().set(i++, gw);
        }
        smsConfigurationManager.updateSmsConfiguration(smsConfig);
    }
    return SUCCESS;
}
Also used : SmsConfiguration(org.hisp.dhis.sms.config.SmsConfiguration) SmsGatewayConfig(org.hisp.dhis.sms.config.SmsGatewayConfig)

Example 12 with SmsConfiguration

use of org.hisp.dhis.sms.config.SmsConfiguration in project dhis2-core by dhis2.

the class GetSmsConfigurationAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    smsConfig = smsConfigurationManager.getSmsConfiguration();
    if (smsConfig != null) {
        int index = 0;
        for (SmsGatewayConfig gw : smsConfig.getGateways()) {
            index = smsConfig.getGateways().indexOf(gw);
            gatewayConfigMap.put(index, gw);
            if (gw instanceof BulkSmsGatewayConfig) {
                bulkIndex = index;
            } else if (gw instanceof ClickatellGatewayConfig) {
                clickatellIndex = index;
            } else {
                httpIndex = index;
            }
        }
    } else {
        smsConfig = new SmsConfiguration(true);
        smsConfigurationManager.updateSmsConfiguration(smsConfig);
    }
    return SUCCESS;
}
Also used : SmsConfiguration(org.hisp.dhis.sms.config.SmsConfiguration) BulkSmsGatewayConfig(org.hisp.dhis.sms.config.BulkSmsGatewayConfig) ClickatellGatewayConfig(org.hisp.dhis.sms.config.ClickatellGatewayConfig) SmsGatewayConfig(org.hisp.dhis.sms.config.SmsGatewayConfig) BulkSmsGatewayConfig(org.hisp.dhis.sms.config.BulkSmsGatewayConfig)

Example 13 with SmsConfiguration

use of org.hisp.dhis.sms.config.SmsConfiguration in project dhis2-core by dhis2.

the class RemoveGatewayConfigAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    SmsConfiguration smsConfig = smsConfigurationManager.getSmsConfiguration();
    Iterator<SmsGatewayConfig> it = smsConfig.getGateways().iterator();
    while (it.hasNext()) {
        if (smsConfig.getGateways().indexOf(it.next()) == id) {
            SmsGatewayConfig gatewayConfig = smsConfig.getGateways().get(id);
            it.remove();
            smsConfigurationManager.updateSmsConfiguration(smsConfig);
            if (gatewayConfig instanceof BulkSmsGatewayConfig) {
                gatewayAdminService.getGatewayConfigurationMap().remove(gatewayConfig.getName());
            }
            if (gatewayConfig instanceof ClickatellGatewayConfig) {
                gatewayAdminService.getGatewayConfigurationMap().remove(gatewayConfig.getName());
            }
            if (gatewayConfig instanceof GenericHttpGatewayConfig) {
                gatewayAdminService.getGatewayConfigurationMap().remove(gatewayConfig.getName());
            }
            log.info(gatewayConfig.getName() + " configuration has been removed");
            break;
        }
    }
    return SUCCESS;
}
Also used : SmsConfiguration(org.hisp.dhis.sms.config.SmsConfiguration) BulkSmsGatewayConfig(org.hisp.dhis.sms.config.BulkSmsGatewayConfig) ClickatellGatewayConfig(org.hisp.dhis.sms.config.ClickatellGatewayConfig) SmsGatewayConfig(org.hisp.dhis.sms.config.SmsGatewayConfig) BulkSmsGatewayConfig(org.hisp.dhis.sms.config.BulkSmsGatewayConfig) GenericHttpGatewayConfig(org.hisp.dhis.sms.config.GenericHttpGatewayConfig)

Example 14 with SmsConfiguration

use of org.hisp.dhis.sms.config.SmsConfiguration 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

SmsConfiguration (org.hisp.dhis.sms.config.SmsConfiguration)14 SmsGatewayConfig (org.hisp.dhis.sms.config.SmsGatewayConfig)8 BulkSmsGatewayConfig (org.hisp.dhis.sms.config.BulkSmsGatewayConfig)4 ClickatellGatewayConfig (org.hisp.dhis.sms.config.ClickatellGatewayConfig)3 GenericHttpGatewayConfig (org.hisp.dhis.sms.config.GenericHttpGatewayConfig)3 HashSet (java.util.HashSet)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 Date (java.util.Date)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 ProgramMessageQueryParams (org.hisp.dhis.program.message.ProgramMessageQueryParams)1 ProgramMessageRecipients (org.hisp.dhis.program.message.ProgramMessageRecipients)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1