Search in sources :

Example 6 with IncomingSms

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);
}
Also used : IncomingSms(org.hisp.dhis.sms.incoming.IncomingSms) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with IncomingSms

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;
}
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

IncomingSms (org.hisp.dhis.sms.incoming.IncomingSms)7 Criteria (org.hibernate.Criteria)2 Session (org.hibernate.Session)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Iterator (java.util.Iterator)1 IncomingSmsListener (org.hisp.dhis.sms.incoming.IncomingSmsListener)1 SmsMessageStatus (org.hisp.dhis.sms.incoming.SmsMessageStatus)1 User (org.hisp.dhis.user.User)1 UserQueryParams (org.hisp.dhis.user.UserQueryParams)1