use of org.mobicents.protocols.ss7.map.api.smstpdu.AbsoluteTimeStamp in project smscgateway by RestComm.
the class MoSbb method createSmsEvent.
private Sms createSmsEvent(SmsSubmitTpdu smsSubmitTpdu, TargetAddress ta, PersistenceRAInterface store, AddressString callingPartyAddress, int networkId, String originatorSccpAddress) throws SmscProcessingException {
UserData userData = smsSubmitTpdu.getUserData();
try {
userData.decode();
} catch (MAPException e) {
throw new SmscProcessingException("MO MAPException when decoding user data", SmppConstants.STATUS_SYSERR, MAPErrorCode.unexpectedDataValue, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
}
Sms sms = new Sms();
sms.setDbId(UUID.randomUUID());
sms.setOriginationType(OriginationType.SS7_MO);
// checking parameters first
if (callingPartyAddress == null || callingPartyAddress.getAddress() == null || callingPartyAddress.getAddress().isEmpty()) {
throw new SmscProcessingException("MO SourceAddress digits are absent", SmppConstants.STATUS_SYSERR, MAPErrorCode.unexpectedDataValue, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
}
if (callingPartyAddress.getAddressNature() == null) {
throw new SmscProcessingException("MO SourceAddress AddressNature is absent", SmppConstants.STATUS_SYSERR, MAPErrorCode.unexpectedDataValue, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
}
if (callingPartyAddress.getNumberingPlan() == null) {
throw new SmscProcessingException("MO SourceAddress NumberingPlan is absent", SmppConstants.STATUS_SYSERR, MAPErrorCode.unexpectedDataValue, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
}
sms.setSourceAddr(callingPartyAddress.getAddress());
sms.setOriginatorSccpAddress(originatorSccpAddress);
sms.setSourceAddrTon(callingPartyAddress.getAddressNature().getIndicator());
sms.setSourceAddrNpi(callingPartyAddress.getNumberingPlan().getIndicator());
sms.setOrigNetworkId(networkId);
sms.setSubmitDate(new Timestamp(System.currentTimeMillis()));
int messageingMode = (smscPropertiesManagement.getMoDefaultMessagingMode() & 0x03);
sms.setEsmClass(messageingMode | (smsSubmitTpdu.getUserDataHeaderIndicator() ? SmppConstants.ESM_CLASS_UDHI_MASK : 0) | (smsSubmitTpdu.getReplyPathExists() ? SmppConstants.ESM_CLASS_REPLY_PATH_MASK : 0));
sms.setProtocolId(smsSubmitTpdu.getProtocolIdentifier().getCode());
sms.setPriority(0);
// TODO: do we need somehow care with RegisteredDelivery ?
sms.setReplaceIfPresent(smsSubmitTpdu.getRejectDuplicates() ? 2 : 0);
sms.setStatusReportRequest(smsSubmitTpdu.getStatusReportRequest());
DataCodingScheme dataCodingScheme = smsSubmitTpdu.getDataCodingScheme();
int dcs = dataCodingScheme.getCode();
String err = MessageUtil.checkDataCodingSchemeSupport(dcs);
if (err != null) {
throw new SmscProcessingException("MO DataCoding scheme does not supported: " + dcs + " - " + err, SmppConstants.STATUS_SYSERR, MAPErrorCode.unexpectedDataValue, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
}
sms.setDataCoding(dcs);
sms.setShortMessageText(userData.getDecodedMessage());
UserDataHeader udh = userData.getDecodedUserDataHeader();
if (udh != null) {
sms.setShortMessageBin(udh.getEncodedData());
}
// ValidityPeriod processing
ValidityPeriod vp = smsSubmitTpdu.getValidityPeriod();
ValidityPeriodFormat vpf = smsSubmitTpdu.getValidityPeriodFormat();
Date validityPeriod = null;
if (vp != null && vpf != null && vpf != ValidityPeriodFormat.fieldNotPresent) {
switch(vpf) {
case fieldPresentAbsoluteFormat:
AbsoluteTimeStamp ats = vp.getAbsoluteFormatValue();
Date dt = new Date(ats.getYear(), ats.getMonth(), ats.getDay(), ats.getHour(), ats.getMinute(), ats.getSecond());
int i1 = ats.getTimeZone() * 15 * 60;
int i2 = -new Date().getTimezoneOffset() * 60;
long i3 = (i2 - i1) * 1000;
validityPeriod = new Date(dt.getTime() + i3);
break;
case fieldPresentRelativeFormat:
validityPeriod = new Date(new Date().getTime() + (long) (vp.getRelativeFormatHours() * 3600 * 1000));
break;
case fieldPresentEnhancedFormat:
this.logger.info("Recieved unsupported ValidityPeriodFormat: PresentEnhancedFormat - we skip it");
break;
}
}
MessageUtil.applyValidityPeriod(sms, validityPeriod, false, smscPropertiesManagement.getMaxValidityPeriodHours(), smscPropertiesManagement.getDefaultValidityPeriodHours());
SmsSet smsSet;
smsSet = new SmsSet();
smsSet.setDestAddr(ta.getAddr());
smsSet.setDestAddrNpi(ta.getAddrNpi());
smsSet.setDestAddrTon(ta.getAddrTon());
smsSet.setNetworkId(networkId);
smsSet.addSms(sms);
long messageId = store.c2_getNextMessageId();
SmscStatProvider.getInstance().setCurrentMessageId(messageId);
sms.setMessageId(messageId);
sms.setMoMessageRef(smsSubmitTpdu.getMessageReference());
return sms;
}
Aggregations