use of org.hisp.dhis.sms.config.BulkSmsGatewayConfig in project dhis2-core by dhis2.
the class UpdateBulkGateWayConfigAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
if (gatewayType != null && gatewayType.equals("bulksms")) {
SmsConfiguration smsConfig = smsConfigurationManager.getSmsConfiguration();
if (smsConfig != null) {
BulkSmsGatewayConfig bulkGatewayConfig = (BulkSmsGatewayConfig) smsConfigurationManager.checkInstanceOfGateway(BulkSmsGatewayConfig.class);
int index = -1;
if (bulkGatewayConfig == null) {
bulkGatewayConfig = new BulkSmsGatewayConfig();
} else {
index = smsConfig.getGateways().indexOf(bulkGatewayConfig);
}
bulkGatewayConfig.setName(name);
bulkGatewayConfig.setPassword(password);
bulkGatewayConfig.setUsername(username);
bulkGatewayConfig.setUid(CodeGenerator.generateCode(10));
if (smsConfig.getGateways() == null || smsConfig.getGateways().isEmpty()) {
bulkGatewayConfig.setDefault(true);
}
if (index >= 0) {
smsConfig.getGateways().set(index, bulkGatewayConfig);
} else {
smsConfig.getGateways().add(bulkGatewayConfig);
}
gatewayAdminService.getGatewayConfigurationMap().put(name, bulkGatewayConfig);
smsConfigurationManager.updateSmsConfiguration(smsConfig);
}
}
return SUCCESS;
}
use of org.hisp.dhis.sms.config.BulkSmsGatewayConfig in project dhis2-core by dhis2.
the class SmsMessageSenderTest method setUp.
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private void setUp() {
okStatus = new OutboundMessageResponse();
okStatus.setResponseObject(GatewayResponse.RESULT_CODE_0);
failedStatus = new OutboundMessageResponse();
failedStatus.setResponseObject(GatewayResponse.FAILED);
smsGatewayConfig = new BulkSmsGatewayConfig();
smsGatewayConfig.setUrlTemplate("");
smsGatewayConfig.setName(gateway);
smsGatewayConfig.setUsername(" ");
smsGatewayConfig.setPassword("");
smsGatewayConfig.setUrlTemplate("");
smsGatewayConfig.setDefault(true);
OutboundMessage outboundMessageA = new OutboundMessage(subject, text, recipientsNormalized);
OutboundMessage outboundMessageB = new OutboundMessage(subject, text, recipientsNonNormalized);
OutboundMessage outboundMessageC = new OutboundMessage(subject, text, recipientsNormalized);
OutboundMessage outboundMessageD = new OutboundMessage(subject, text, recipientsNonNormalized);
outboundMessages = Arrays.asList(outboundMessageA, outboundMessageB, outboundMessageC, outboundMessageD);
User userA = new User();
userA.setPhoneNumber("47401111111");
User userB = new User();
userB.setPhoneNumber("47402222222");
User userC = new User();
userC.setPhoneNumber("47403333333");
User userD = new User();
userD.setPhoneNumber("47404444444");
users = Sets.newHashSet(userA, userB, userC, userD);
sender = new User();
sender.setPhoneNumber("4740555555");
}
use of org.hisp.dhis.sms.config.BulkSmsGatewayConfig 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;
}
use of org.hisp.dhis.sms.config.BulkSmsGatewayConfig 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;
}
use of org.hisp.dhis.sms.config.BulkSmsGatewayConfig 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