use of org.hisp.dhis.sms.incoming.IncomingSms in project dhis2-core by dhis2.
the class SmsController method importUnparsedSMSMessages.
@RequestMapping(value = "/import", method = RequestMethod.POST, consumes = "application/json")
@PreAuthorize("hasRole('ALL') or hasRole('F_MOBILE_SETTINGS')")
public void importUnparsedSMSMessages(HttpServletRequest request, HttpServletResponse response) throws WebMessageException, ParseException, IOException {
List<IncomingSms> importMessageList = incomingSMSService.getAllUnparsedMessages();
for (IncomingSms sms : importMessageList) {
incomingSMSService.update(sms);
}
webMessageService.send(WebMessageUtils.ok("Import successful"), response, request);
}
use of org.hisp.dhis.sms.incoming.IncomingSms in project dhis2-core by dhis2.
the class ReceivingSMSAction method execute.
// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
this.user = currentUserService.getCurrentUser();
if (keyword == null) {
keyword = "";
}
if (smsStatus == null || smsStatus.trim().equals("")) {
total = incomingSmsService.getSmsByStatus(null, keyword.trim()).size();
this.paging = createPaging(total);
listIncomingSms = new ArrayList<>(incomingSmsService.getSmsByStatus(null, keyword, this.paging.getStartPos(), this.paging.getPageSize()));
} else {
SmsMessageStatus[] statusArray = SmsMessageStatus.values();
for (SmsMessageStatus aStatusArray : statusArray) {
if (aStatusArray.toString().equalsIgnoreCase(smsStatus)) {
total = incomingSmsService.getSmsByStatus(aStatusArray, keyword).size();
this.paging = createPaging(total);
listIncomingSms = new ArrayList<>(incomingSmsService.getSmsByStatus(aStatusArray, keyword.trim(), this.paging.getStartPos(), this.paging.getPageSize()));
break;
}
}
}
// Get the name of senders
senderNames = new ArrayList<>();
senderNames.add("");
String tempString;
for (IncomingSms incomingSms : listIncomingSms) {
tempString = "";
String phoneNumber = incomingSms.getOriginator();
if (!phoneNumber.isEmpty()) {
UserQueryParams params = new UserQueryParams();
params.setPhoneNumber(phoneNumber);
List<User> users = userService.getUsers(params);
if (users == null || users.size() == 0) {
tempString += "[unknown]";
} else if (users.size() > 0) {
Iterator<User> usersIterator = users.iterator();
while (usersIterator.hasNext()) {
User user = usersIterator.next();
tempString += "[" + user.getUsername() + "]";
}
}
} else {
tempString += "[unknown]";
}
senderNames.add(tempString);
}
return SUCCESS;
}
Aggregations