Search in sources :

Example 6 with AbsoluteTimeStamp

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;
}
Also used : DataCodingScheme(org.mobicents.protocols.ss7.map.api.smstpdu.DataCodingScheme) AbsoluteTimeStamp(org.mobicents.protocols.ss7.map.api.smstpdu.AbsoluteTimeStamp) UserData(org.mobicents.protocols.ss7.map.api.smstpdu.UserData) MAPException(org.mobicents.protocols.ss7.map.api.MAPException) ISDNAddressString(org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString) AddressString(org.mobicents.protocols.ss7.map.api.primitives.AddressString) Timestamp(java.sql.Timestamp) Date(java.util.Date) ValidityPeriodFormat(org.mobicents.protocols.ss7.map.api.smstpdu.ValidityPeriodFormat) MAPDialogSms(org.mobicents.protocols.ss7.map.api.service.sms.MAPDialogSms) ValidityPeriod(org.mobicents.protocols.ss7.map.api.smstpdu.ValidityPeriod) UserDataHeader(org.mobicents.protocols.ss7.map.api.smstpdu.UserDataHeader)

Aggregations

Date (java.util.Date)4 AbsoluteTimeStamp (org.mobicents.protocols.ss7.map.api.smstpdu.AbsoluteTimeStamp)4 SmsSignalInfo (org.mobicents.protocols.ss7.map.api.service.sms.SmsSignalInfo)3 AddressField (org.mobicents.protocols.ss7.map.api.smstpdu.AddressField)3 ProtocolIdentifier (org.mobicents.protocols.ss7.map.api.smstpdu.ProtocolIdentifier)3 SmsSignalInfoImpl (org.mobicents.protocols.ss7.map.service.sms.SmsSignalInfoImpl)3 AbsoluteTimeStampImpl (org.mobicents.protocols.ss7.map.smstpdu.AbsoluteTimeStampImpl)3 AddressFieldImpl (org.mobicents.protocols.ss7.map.smstpdu.AddressFieldImpl)3 DataCodingSchemeImpl (org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl)3 ProtocolIdentifierImpl (org.mobicents.protocols.ss7.map.smstpdu.ProtocolIdentifierImpl)3 UserDataImpl (org.mobicents.protocols.ss7.map.smstpdu.UserDataImpl)3 AddressString (org.mobicents.protocols.ss7.map.api.primitives.AddressString)2 ISDNAddressString (org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString)2 DataCodingScheme (org.mobicents.protocols.ss7.map.api.smstpdu.DataCodingScheme)2 UserData (org.mobicents.protocols.ss7.map.api.smstpdu.UserData)2 ValidityPeriod (org.mobicents.protocols.ss7.map.api.smstpdu.ValidityPeriod)2 SmsDeliverTpduImpl (org.mobicents.protocols.ss7.map.smstpdu.SmsDeliverTpduImpl)2 Test (org.testng.annotations.Test)2 ByteBuffer (java.nio.ByteBuffer)1 Charset (java.nio.charset.Charset)1