Skip to content

Commit

Permalink
BS-232 Expire correlation between an SmsMessage and SmppMessageId for…
Browse files Browse the repository at this point in the history
… all messages that are at most three days old
  • Loading branch information
hrosa committed Jun 7, 2018
1 parent 972c96c commit 79a2dd3
Showing 1 changed file with 17 additions and 12 deletions.
Expand Up @@ -23,6 +23,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.List;

Expand All @@ -33,6 +34,7 @@

import org.apache.commons.configuration.Configuration;
import org.joda.time.DateTime;
import org.joda.time.Instant;
import org.restcomm.connect.commons.configuration.RestcommConfiguration;
import org.restcomm.connect.commons.configuration.sets.RcmlserverConfigurationSet;
import org.restcomm.connect.commons.dao.Sid;
Expand All @@ -45,10 +47,7 @@
import org.restcomm.connect.dao.NotificationsDao;
import org.restcomm.connect.dao.SmsMessagesDao;
import org.restcomm.connect.dao.common.OrganizationUtil;
import org.restcomm.connect.dao.entities.Application;
import org.restcomm.connect.dao.entities.IncomingPhoneNumber;
import org.restcomm.connect.dao.entities.Notification;
import org.restcomm.connect.dao.entities.SmsMessage;
import org.restcomm.connect.dao.entities.*;
import org.restcomm.connect.extension.api.ExtensionResponse;
//import org.restcomm.connect.extension.api.ExtensionRequest;
//import org.restcomm.connect.extension.api.ExtensionResponse;
Expand Down Expand Up @@ -186,16 +185,22 @@ public void onReceive(Object message) throws Exception {
Object ref = pduAsyncResponse.getRequest().getReferenceObject();

if (ref != null && ref instanceof Sid) {
// BS-230: Ensure there is no other message sharing same SMPP Message ID
SmsMessage existingMessage = this.storage.getSmsMessagesDao().getSmsMessageBySmppMessageId(smppMessageId);
if (existingMessage != null) {
// Cut correlation between SMS and SMPP Message ID and update message to a final state
existingMessage = existingMessage.setSmppMessageId(null);
logger.warning("Correlation between SmsMessage " + existingMessage.getSid() + " and SMPP Message " + smppMessageId + " expired.");
this.storage.getSmsMessagesDao().updateSmsMessage(existingMessage);
final Sid sid = (Sid) ref;

// BS-230, BS-232: Ensure there is no other message sharing same SMPP Message ID in last 3 days
final Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, -3);
final SmsMessageFilter filter = SmsMessageFilter.builer().smppMessageId(smppMessageId).startTime(calendar.getTime()).build();

final List<SmsMessage> smsMessages = this.storage.getSmsMessagesDao().getSmsMessages(filter);
for (SmsMessage sms: smsMessages) {
if(!sid.equals(sms.getSid())) {
// Cut correlation between SMS and SMPP Message ID and update message to a final state
this.storage.getSmsMessagesDao().updateSmsMessage(sms.setSmppMessageId(null).setStatus(SmsMessage.Status.SENT));
logger.warning("Correlation between SmsMessage " + sms.getSid() + " and SMPP Message " + smppMessageId + " expired. Marked status as SENT");
}
}

Sid sid = (Sid) ref;
SmsMessage smsMessage = storage.getSmsMessagesDao().getSmsMessage(sid);
if (submitSmResp.getCommandStatus() != 0) {
logger.warning(String.format("SubmitSmResp Failure! Message could not be sent Status Code %s Result Messages: %s", submitSmResp.getCommandStatus(), submitSmResp.getResultMessage()));
Expand Down

0 comments on commit 79a2dd3

Please sign in to comment.