Search in sources :

Example 1 with SmsMessageStatus

use of org.hisp.dhis.sms.incoming.SmsMessageStatus in project dhis2-core by dhis2.

the class BaseSMSListener method sendSMSResponse.

protected void sendSMSResponse(SmsResponse resp, IncomingSms sms, int messageID) {
    // A response code < 100 is either success or just a warning
    SmsMessageStatus status = resp.getCode() < 100 ? SmsMessageStatus.PROCESSED : SmsMessageStatus.FAILED;
    update(sms, status, true);
    if (smsSender.isConfigured()) {
        String msg = String.format("%d:%s", messageID, resp.toString());
        smsSender.sendMessage(null, msg, sms.getOriginator());
        return;
    }
    LOGGER.getOrDefault(WARNING, log::info).accept(NO_SMS_CONFIG);
}
Also used : SmsMessageStatus(org.hisp.dhis.sms.incoming.SmsMessageStatus)

Example 2 with SmsMessageStatus

use of org.hisp.dhis.sms.incoming.SmsMessageStatus 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;
}
Also used : SmsMessageStatus(org.hisp.dhis.sms.incoming.SmsMessageStatus) IncomingSms(org.hisp.dhis.sms.incoming.IncomingSms) User(org.hisp.dhis.user.User) Iterator(java.util.Iterator) UserQueryParams(org.hisp.dhis.user.UserQueryParams)

Aggregations

SmsMessageStatus (org.hisp.dhis.sms.incoming.SmsMessageStatus)2 Iterator (java.util.Iterator)1 IncomingSms (org.hisp.dhis.sms.incoming.IncomingSms)1 User (org.hisp.dhis.user.User)1 UserQueryParams (org.hisp.dhis.user.UserQueryParams)1