Search in sources :

Example 1 with GatewayResponse

use of org.hisp.dhis.sms.outbound.GatewayResponse in project dhis2-core by dhis2.

the class SmsMessageSender method handleResponse.

private OutboundMessageResponse handleResponse(OutboundMessageResponse status) {
    Set<GatewayResponse> okCodes = Sets.newHashSet(GatewayResponse.RESULT_CODE_0, GatewayResponse.RESULT_CODE_200, GatewayResponse.RESULT_CODE_202);
    GatewayResponse gatewayResponse = (GatewayResponse) status.getResponseObject();
    if (okCodes.contains(gatewayResponse)) {
        log.info("SMS sent");
        return new OutboundMessageResponse(gatewayResponse.getResponseMessage(), gatewayResponse, true);
    } else {
        log.error("SMS failed, failure cause: " + gatewayResponse.getResponseMessage());
        return new OutboundMessageResponse(gatewayResponse.getResponseMessage(), gatewayResponse, false);
    }
}
Also used : GatewayResponse(org.hisp.dhis.sms.outbound.GatewayResponse) OutboundMessageResponse(org.hisp.dhis.outboundmessage.OutboundMessageResponse)

Example 2 with GatewayResponse

use of org.hisp.dhis.sms.outbound.GatewayResponse in project dhis2-core by dhis2.

the class SmsMessageSender method generateSummary.

private OutboundMessageResponseSummary generateSummary(List<OutboundMessageResponse> statuses, OutboundMessageBatch batch, SmsGateway smsGateway) {
    Set<GatewayResponse> okCodes = Sets.newHashSet(GatewayResponse.RESULT_CODE_0, GatewayResponse.RESULT_CODE_200, GatewayResponse.RESULT_CODE_202);
    OutboundMessageResponseSummary summary = new OutboundMessageResponseSummary();
    int total, sent = 0;
    boolean ok = true;
    String errorMessage = StringUtils.EMPTY;
    total = batch.getMessages().size();
    for (OutboundMessageResponse status : statuses) {
        if (okCodes.contains(status.getResponseObject())) {
            sent = (smsGateway instanceof BulkSmsGateway) ? total : sent + 1;
        } else {
            ok = false;
            errorMessage = status.getDescription();
        }
    }
    summary.setTotal(total);
    summary.setChannel(DeliveryChannel.SMS);
    summary.setSent(sent);
    summary.setFailed(total - sent);
    if (!ok) {
        summary.setBatchStatus(OutboundMessageBatchStatus.FAILED);
        summary.setErrorMessage(errorMessage);
        log.error(errorMessage);
    } else {
        summary.setBatchStatus(OutboundMessageBatchStatus.COMPLETED);
        summary.setResponseMessage("SENT");
        log.info("SMS batch processed successfully");
    }
    return summary;
}
Also used : GatewayResponse(org.hisp.dhis.sms.outbound.GatewayResponse) OutboundMessageResponseSummary(org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary) OutboundMessageResponse(org.hisp.dhis.outboundmessage.OutboundMessageResponse)

Example 3 with GatewayResponse

use of org.hisp.dhis.sms.outbound.GatewayResponse in project dhis2-core by dhis2.

the class BulkSmsGateway method getResponse.

private OutboundMessageResponse getResponse(ResponseEntity<String> responseEntity) {
    OutboundMessageResponse status = new OutboundMessageResponse();
    if (responseEntity == null) {
        status.setResponseObject(GatewayResponse.FAILED);
        status.setOk(false);
        return status;
    }
    String response = responseEntity.getBody();
    GatewayResponse gatewayResponse = BULKSMS_GATEWAY_RESPONSE_MAP.get(StringUtils.split(response, "|")[0]);
    gatewayResponse.setBatchId(StringUtils.split(response, "|")[2]);
    status.setResponseObject(gatewayResponse);
    status.setDescription(gatewayResponse.getResponseMessage());
    return status;
}
Also used : GatewayResponse(org.hisp.dhis.sms.outbound.GatewayResponse) OutboundMessageResponse(org.hisp.dhis.outboundmessage.OutboundMessageResponse)

Example 4 with GatewayResponse

use of org.hisp.dhis.sms.outbound.GatewayResponse in project dhis2-core by dhis2.

the class SmsMessageSender method generateSummary.

private OutboundMessageResponseSummary generateSummary(List<OutboundMessageResponse> statuses, OutboundMessageBatch batch) {
    Set<GatewayResponse> okCodes = Sets.newHashSet(GatewayResponse.RESULT_CODE_0, GatewayResponse.RESULT_CODE_200, GatewayResponse.RESULT_CODE_202);
    OutboundMessageResponseSummary summary = new OutboundMessageResponseSummary();
    int total, sent = 0;
    boolean ok = true;
    String errorMessage = StringUtils.EMPTY;
    total = batch.getMessages().size();
    for (OutboundMessageResponse status : statuses) {
        if (okCodes.contains(status.getResponseObject())) {
            sent++;
        } else {
            ok = false;
            errorMessage = status.getDescription();
        }
    }
    summary.setTotal(total);
    summary.setChannel(DeliveryChannel.SMS);
    summary.setSent(sent);
    summary.setFailed(total - sent);
    if (!ok) {
        summary.setBatchStatus(OutboundMessageBatchStatus.FAILED);
        summary.setErrorMessage(errorMessage);
        log.error(errorMessage);
    } else {
        summary.setBatchStatus(OutboundMessageBatchStatus.COMPLETED);
        summary.setResponseMessage("SENT");
        log.debug("SMS batch processed successfully");
    }
    return summary;
}
Also used : GatewayResponse(org.hisp.dhis.sms.outbound.GatewayResponse) OutboundMessageResponseSummary(org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary) OutboundMessageResponse(org.hisp.dhis.outboundmessage.OutboundMessageResponse)

Example 5 with GatewayResponse

use of org.hisp.dhis.sms.outbound.GatewayResponse in project dhis2-core by dhis2.

the class SmsMessageSender method handleResponse.

private void handleResponse(OutboundMessageResponse status, OutboundSms sms) {
    Set<GatewayResponse> okCodes = Sets.newHashSet(GatewayResponse.RESULT_CODE_0, GatewayResponse.RESULT_CODE_200, GatewayResponse.RESULT_CODE_202);
    GatewayResponse gatewayResponse = (GatewayResponse) status.getResponseObject();
    if (okCodes.contains(gatewayResponse)) {
        log.debug("SMS sent");
        status.setOk(true);
        sms.setStatus(OutboundSmsStatus.SENT);
    } else {
        log.error("SMS failed, failure cause: " + gatewayResponse.getResponseMessage());
        status.setOk(false);
        sms.setStatus(OutboundSmsStatus.FAILED);
    }
    outboundSmsService.save(sms);
    status.setDescription(gatewayResponse.getResponseMessage());
    status.setResponseObject(gatewayResponse);
}
Also used : GatewayResponse(org.hisp.dhis.sms.outbound.GatewayResponse)

Aggregations

GatewayResponse (org.hisp.dhis.sms.outbound.GatewayResponse)6 OutboundMessageResponse (org.hisp.dhis.outboundmessage.OutboundMessageResponse)5 OutboundMessageResponseSummary (org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary)2