use of javolution.xml.XMLObjectReader in project smscgateway by RestComm.
the class DBOperations method createSms.
protected SmsSet createSms(final Row row, SmsSet smsSet, boolean shortMessageNewStringFormat, boolean addedCorrId, boolean addedNetworkId, boolean addedOrigNetworkId, boolean addedPacket1, boolean getMessageInProcessing) throws PersistenceException {
if (row == null) {
return smsSet;
}
int inSystem = row.getInt(Schema.COLUMN_IN_SYSTEM);
UUID smscUuid = row.getUUID(Schema.COLUMN_SMSC_UUID);
if (!getMessageInProcessing && (inSystem == IN_SYSTEM_SENT || inSystem == IN_SYSTEM_INPROCESS && smscUuid.equals(currentSessionUUID))) {
// inSystem it is in processing or processed - skip this
return smsSet;
}
Sms sms = new Sms();
sms.setStored(true);
sms.setDbId(row.getUUID(Schema.COLUMN_ID));
sms.setDueSlot(row.getLong(Schema.COLUMN_DUE_SLOT));
sms.setSourceAddr(row.getString(Schema.COLUMN_ADDR_SRC_DIGITS));
sms.setSourceAddrTon(row.getInt(Schema.COLUMN_ADDR_SRC_TON));
sms.setSourceAddrNpi(row.getInt(Schema.COLUMN_ADDR_SRC_NPI));
if (addedOrigNetworkId) {
sms.setOrigNetworkId(row.getInt(Schema.COLUMN_ORIG_NETWORK_ID));
}
sms.setMessageId(row.getLong(Schema.COLUMN_MESSAGE_ID));
sms.setMoMessageRef(row.getInt(Schema.COLUMN_MO_MESSAGE_REF));
sms.setOrigEsmeName(row.getString(Schema.COLUMN_ORIG_ESME_NAME));
sms.setOrigSystemId(row.getString(Schema.COLUMN_ORIG_SYSTEM_ID));
sms.setSubmitDate(getRowDate(row, Schema.COLUMN_SUBMIT_DATE));
sms.setServiceType(row.getString(Schema.COLUMN_SERVICE_TYPE));
sms.setEsmClass(row.getInt(Schema.COLUMN_ESM_CLASS));
sms.setProtocolId(row.getInt(Schema.COLUMN_PROTOCOL_ID));
sms.setPriority(row.getInt(Schema.COLUMN_PRIORITY));
sms.setRegisteredDelivery(row.getInt(Schema.COLUMN_REGISTERED_DELIVERY));
sms.setReplaceIfPresent(row.getInt(Schema.COLUMN_REPLACE));
sms.setDataCodingForDatabase(row.getInt(Schema.COLUMN_DATA_CODING));
sms.setDefaultMsgId(row.getInt(Schema.COLUMN_DEFAULT_MSG_ID));
if (shortMessageNewStringFormat) {
sms.setShortMessageText(row.getString(Schema.COLUMN_MESSAGE_TEXT));
ByteBuffer bb = row.getBytes(Schema.COLUMN_MESSAGE_BIN);
if (bb != null) {
byte[] buf = new byte[bb.limit() - bb.position()];
bb.get(buf);
sms.setShortMessageBin(buf);
}
} else {
ByteBuffer bb = row.getBytes(Schema.COLUMN_MESSAGE);
if (bb != null) {
byte[] buf = new byte[bb.limit() - bb.position()];
bb.get(buf);
sms.setShortMessage(buf);
// convert to a new format
byte[] shortMessage = sms.getShortMessage();
byte[] textPart = shortMessage;
byte[] udhData = null;
boolean udhExists = false;
DataCodingScheme dcs = new DataCodingSchemeImpl(sms.getDataCoding());
String msg = null;
if (dcs.getCharacterSet() == CharacterSet.GSM8) {
udhData = shortMessage;
} else {
if ((sms.getEsmClass() & SmppConstants.ESM_CLASS_UDHI_MASK) != 0) {
udhExists = true;
}
if (udhExists && shortMessage != null && shortMessage.length > 2) {
// UDH exists
int udhLen = (shortMessage[0] & 0xFF) + 1;
if (udhLen <= shortMessage.length) {
textPart = new byte[shortMessage.length - udhLen];
udhData = new byte[udhLen];
System.arraycopy(shortMessage, udhLen, textPart, 0, textPart.length);
System.arraycopy(shortMessage, 0, udhData, 0, udhLen);
}
}
switch(dcs.getCharacterSet()) {
case GSM7:
msg = new String(textPart);
break;
case UCS2:
Charset ucs2Charset = Charset.forName("UTF-16BE");
bb = ByteBuffer.wrap(textPart);
CharBuffer bf = ucs2Charset.decode(bb);
msg = bf.toString();
break;
default:
udhData = sms.getShortMessage();
break;
}
}
sms.setShortMessageText(msg);
sms.setShortMessageBin(udhData);
}
}
sms.setScheduleDeliveryTime(getRowDate(row, Schema.COLUMN_SCHEDULE_DELIVERY_TIME));
sms.setValidityPeriod(getRowDate(row, Schema.COLUMN_VALIDITY_PERIOD));
sms.setDeliveryCount(row.getInt(Schema.COLUMN_DELIVERY_COUNT));
if (addedPacket1) {
sms.setOriginatorSccpAddress(row.getString(Schema.COLUMN_ORIGINATOR_SCCP_ADDRESS));
// TODO: extra columns for further usage
sms.setStatusReportRequest(row.getBool(Schema.COLUMN_STATUS_REPORT_REQUEST));
sms.setDeliveryAttempt(row.getInt(Schema.COLUMN_DELIVERY_ATTEMPT));
sms.setUserData(row.getString(Schema.COLUMN_USER_DATA));
sms.setExtraData(row.getString(Schema.COLUMN_EXTRA_DATA));
sms.setExtraData_2(row.getString(Schema.COLUMN_EXTRA_DATA_2));
sms.setExtraData_3(row.getString(Schema.COLUMN_EXTRA_DATA_3));
sms.setExtraData_4(row.getString(Schema.COLUMN_EXTRA_DATA_4));
}
String s = row.getString(Schema.COLUMN_OPTIONAL_PARAMETERS);
if (s != null) {
try {
ByteArrayInputStream bais = new ByteArrayInputStream(s.getBytes());
XMLObjectReader reader = XMLObjectReader.newInstance(bais);
TlvSet copy = reader.read(TLV_SET, TlvSet.class);
sms.getTlvSet().clearAllOptionalParameter();
sms.getTlvSet().addAllOptionalParameter(copy.getOptionalParameters());
} catch (XMLStreamException e) {
String msg = "XMLStreamException when deserializing optional parameters for '" + sms.getDbId() + "'!";
throw new PersistenceException(msg, e);
}
}
if (smsSet == null) {
smsSet = new SmsSet();
String destAddr = null;
int destAddrTon = -1;
int destAddrNpi = -1;
destAddr = row.getString(Schema.COLUMN_ADDR_DST_DIGITS);
destAddrTon = row.getInt(Schema.COLUMN_ADDR_DST_TON);
destAddrNpi = row.getInt(Schema.COLUMN_ADDR_DST_NPI);
if (destAddr == null || destAddrTon == -1 || destAddrNpi == -1) {
throw new PersistenceException("destAddr or destAddrTon or destAddrNpi is absent for ID='" + sms.getDbId() + "'");
}
smsSet.setDestAddr(destAddr);
smsSet.setDestAddrTon(destAddrTon);
smsSet.setDestAddrNpi(destAddrNpi);
if (getMessageInProcessing) {
smsSet.setInSystem(inSystem);
smsSet.setStatus(ErrorCode.fromInt(row.getInt(Schema.COLUMN_SM_STATUS)));
}
if (addedNetworkId) {
smsSet.setNetworkId(row.getInt(Schema.COLUMN_NETWORK_ID));
} else {
String tagId = row.getString(Schema.COLUMN_TARGET_ID);
if (tagId != null) {
String[] ss = tagId.split("_");
if (ss.length == 4) {
String s1 = ss[3];
try {
int networkId = Integer.parseInt(s1);
smsSet.setNetworkId(networkId);
} catch (Exception e) {
}
}
}
}
if (addedCorrId)
smsSet.setCorrelationId(row.getString(Schema.COLUMN_CORR_ID));
else
smsSet.setCorrelationId(row.getString(Schema.COLUMN_IMSI));
}
int dueDelay = row.getInt(Schema.COLUMN_DUE_DELAY);
if (dueDelay > smsSet.getDueDelay())
smsSet.setDueDelay(dueDelay);
boolean alertingSupported = row.getBool(Schema.COLUMN_ALERTING_SUPPORTED);
if (alertingSupported)
smsSet.setAlertingSupported(true);
smsSet.addSms(sms);
return smsSet;
}
Aggregations