use of org.hisp.dhis.sms.command.SMSCommand in project dhis2-core by dhis2.
the class SmsController method getSmsCommandTypes.
@PreAuthorize("hasRole('ALL') or hasRole('F_MOBILE_SENDSMS')")
@RequestMapping(value = "/commands/{commandName}", method = RequestMethod.GET, produces = "application/json")
public void getSmsCommandTypes(@PathVariable("commandName") String commandName, @RequestParam ParserType type, HttpServletRequest request, HttpServletResponse response) throws IOException, WebMessageException {
SMSCommand command = smsCommandService.getSMSCommand(commandName, type);
if (command == null) {
throw new WebMessageException(WebMessageUtils.notFound("No SMS command found"));
}
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
renderService.toJson(response.getOutputStream(), command);
}
use of org.hisp.dhis.sms.command.SMSCommand in project dhis2-core by dhis2.
the class CreateSMSCommandForm method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
SMSCommand command = new SMSCommand();
command.setName(name);
command.setParserType(parserType);
if (parserType.equals(ParserType.KEY_VALUE_PARSER) || parserType.equals(ParserType.J2ME_PARSER)) {
DataSet dataset = dataSetService.getDataSet(selectedDataSetID);
command.setDataset(dataset);
} else if (parserType.equals(ParserType.ALERT_PARSER) || parserType.equals(ParserType.UNREGISTERED_PARSER)) {
UserGroup userGroup = new UserGroup();
userGroup = userGroupService.getUserGroup(userGroupID);
command.setUserGroup(userGroup);
} else if (parserType.equals(ParserType.TRACKED_ENTITY_REGISTRATION_PARSER)) {
Program program = programService.getProgram(selectedProgramId);
command.setProgram(program);
} else if (parserType.equals(ParserType.EVENT_REGISTRATION_PARSER)) {
Program program = programService.getProgram(selectedProgramIdWithoutRegistration);
command.setProgram(program);
command.setProgramStage(program.getProgramStages().iterator().next());
}
smsCommandService.save(command);
return SUCCESS;
}
use of org.hisp.dhis.sms.command.SMSCommand in project dhis2-core by dhis2.
the class EditSMSCommandForm method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
Set<SMSCode> codeSet = new HashSet<>();
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readValue(codeDataelementOption, JsonNode.class);
JsonNode codes = root.get("codes");
if (codes != null && codes.size() > 0) {
codes.iterator().forEachRemaining(code -> {
if (code.get("code") != null && code.get("dataElementId") != null && code.get("optionId") != null && code.get("formula") != null) {
SMSCode c = new SMSCode();
c.setCode(code.get("code").asText());
c.setDataElement(dataElementService.getDataElement(code.get("dataElementId").asInt()));
c.setOptionId(code.get("optionId").asInt());
if (!StringUtils.isEmpty(code.get("formula").asText())) {
c.setFormula(code.get("formula").asText());
} else {
c.setFormula(null);
}
codeSet.add(c);
}
});
}
Set<SMSSpecialCharacter> specialCharacterSet = new HashSet<>();
root = mapper.readValue(specialCharactersInfo, JsonNode.class);
JsonNode specialChars = root.get("specialCharacters");
if (specialChars != null && StringUtils.isNoneEmpty(specialChars.toString())) {
specialCharacterSet = mapper.readValue(specialChars.toString(), new TypeReference<HashSet<SMSSpecialCharacter>>() {
});
smsCommandService.saveSpecialCharacterSet(specialCharacterSet);
}
SMSCommand command = getSMSCommand();
if (selectedDataSetID > -1 && command != null) {
if (command.getParserType() == ParserType.TRACKED_ENTITY_REGISTRATION_PARSER) {
root = mapper.readValue(trackedEntityAttributeCodes, JsonNode.class);
JsonNode regCodes = root.get("trackedEntityAttributeCodes");
if (regCodes != null && regCodes.size() > 0) {
regCodes.iterator().forEachRemaining(regCode -> {
if (regCode.get("code") != null && regCode.get("trackedEntityAttributeId") != null) {
SMSCode c = new SMSCode();
c.setCode(regCode.get("code").asText());
c.setTrackedEntityAttribute(trackedEntityAttributeService.getTrackedEntityAttribute(regCode.get("trackedEntityAttributeId").asInt()));
codeSet.add(c);
}
});
}
}
if (command.getParserType() == ParserType.EVENT_REGISTRATION_PARSER) {
root = mapper.readValue(programStageDataElementCodes, JsonNode.class);
JsonNode regCodes = root.get("programStageDataElementCodes");
if (regCodes != null && regCodes.size() > 0) {
regCodes.iterator().forEachRemaining(regCode -> {
if (regCode.get("code") != null && regCode.get("programStageDataElementId") != null) {
SMSCode c = new SMSCode();
c.setCode(regCode.get("code").asText());
c.setDataElement(dataElementService.getDataElement(regCode.get("programStageDataElementId").asInt()));
c.setCompulsory(regCode.get("compulsory").asBoolean());
codeSet.add(c);
}
});
}
}
}
if (codeSet.size() > 0) {
smsCommandService.save(codeSet);
}
if (selectedDataSetID > -1 && command != null) {
command.setCurrentPeriodUsedForReporting(currentPeriodUsedForReporting);
command.setName(name);
command.setSeparator(separator);
if (completenessMethod != null) {
command.setCompletenessMethod(completenessMethod);
}
// remove codes
Set<SMSCode> toRemoveCodes = command.getCodes();
smsCommandService.deleteCodeSet(toRemoveCodes);
// remove special characters
Set<SMSSpecialCharacter> toRemoveCharacters = command.getSpecialCharacters();
smsCommandService.deleteSpecialCharacterSet(toRemoveCharacters);
command.setCodes(codeSet);
// message
command.setDefaultMessage(defaultMessage);
command.setReceivedMessage(receivedMessage);
command.setMoreThanOneOrgUnitMessage(moreThanOneOrgUnitMessage);
command.setNoUserMessage(noUserMessage);
command.setWrongFormatMessage(wrongFormatMessage);
command.setSuccessMessage(successMessage);
if (userGroupID != null && userGroupID > -1) {
command.setUserGroup(userGroupService.getUserGroup(userGroupID));
}
command.setSpecialCharacters(specialCharacterSet);
smsCommandService.save(command);
}
return SUCCESS;
}
use of org.hisp.dhis.sms.command.SMSCommand in project dhis2-core by dhis2.
the class HibernateSMSCommandStore method getSMSCommand.
@Override
public SMSCommand getSMSCommand(String commandName, ParserType parserType) {
CriteriaBuilder builder = getCriteriaBuilder();
List<SMSCommand> list = getList(builder, newJpaParameters().addPredicate(root -> builder.equal(root.get("parserType"), parserType)).addPredicate(root -> JpaQueryUtils.stringPredicateIgnoreCase(builder, root.get("name"), commandName, JpaQueryUtils.StringSearchMode.ANYWHERE)));
if (list != null && !list.isEmpty()) {
return list.get(0);
}
return null;
}
use of org.hisp.dhis.sms.command.SMSCommand in project dhis2-core by dhis2.
the class SMSCommandServiceTest method testGetCommandById.
@Test
void testGetCommandById() {
smsCommandService.save(keyValueCommandA);
smsCommandService.save(keyValueCommandB);
List<SMSCommand> commands = smsCommandService.getSMSCommands();
long id = commands.iterator().next().getId();
SMSCommand fetched = smsCommandService.getSMSCommand(id);
assertNotNull(fetched);
}
Aggregations