Search in sources :

Example 11 with XMLObjectWriter

use of javolution.xml.XMLObjectWriter in project smscgateway by RestComm.

the class HomeRoutingManagement method store.

/**
 * Persist
 */
public void store() {
    try {
        XMLObjectWriter writer = XMLObjectWriter.newInstance(new FileOutputStream(persistFile.toString()));
        writer.setBinding(binding);
        writer.setIndentation(TAB_INDENT);
        writer.write(ccMccmncCollection, CC_MCCMNS_COLLECTION, CcMccmncCollection.class);
        writer.close();
    } catch (Exception e) {
        logger.error("Error while persisting the ccMccmncCollection in file", e);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) XMLObjectWriter(javolution.xml.XMLObjectWriter) XMLStreamException(javolution.xml.stream.XMLStreamException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 12 with XMLObjectWriter

use of javolution.xml.XMLObjectWriter in project smscgateway by RestComm.

the class NN_DBOper method createRecord.

// SCHEMA 1 ************************
public void createRecord(long dueSlot, Sms sms) throws PersistenceException {
    PreparedStatementCollection2 psc = getStatementCollection(sms.getSubmitDate());
    try {
        PreparedStatement ps = psc.createRecordData;
        BoundStatement boundStatement = new BoundStatement(ps);
        boundStatement.setString(Schema.COLUMN_ADDR_DST_DIGITS, sms.getSmsSet().getDestAddr());
        boundStatement.setInt(Schema.COLUMN_ADDR_DST_TON, sms.getSmsSet().getDestAddrTon());
        boundStatement.setInt(Schema.COLUMN_ADDR_DST_NPI, sms.getSmsSet().getDestAddrNpi());
        boundStatement.setUUID(Schema.COLUMN_ID, sms.getDbId());
        boundStatement.setString(Schema.COLUMN_TARGET_ID, sms.getSmsSet().getTargetId());
        boundStatement.setLong(Schema.COLUMN_DUE_SLOT, dueSlot);
        if (sms.getSourceAddr() != null) {
            boundStatement.setString(Schema.COLUMN_ADDR_SRC_DIGITS, sms.getSourceAddr());
        }
        boundStatement.setInt(Schema.COLUMN_ADDR_SRC_TON, sms.getSourceAddrTon());
        boundStatement.setInt(Schema.COLUMN_ADDR_SRC_NPI, sms.getSourceAddrNpi());
        boundStatement.setInt(Schema.COLUMN_DUE_DELAY, sms.getSmsSet().getDueDelay());
        if (sms.getSmsSet().getStatus() != null)
            boundStatement.setInt(Schema.COLUMN_SM_STATUS, sms.getSmsSet().getStatus().getCode());
        boundStatement.setBool(Schema.COLUMN_ALERTING_SUPPORTED, sms.getSmsSet().isAlertingSupported());
        boundStatement.setLong(Schema.COLUMN_MESSAGE_ID, sms.getMessageId());
        boundStatement.setInt(Schema.COLUMN_MO_MESSAGE_REF, sms.getMoMessageRef());
        if (sms.getOrigEsmeName() != null) {
            boundStatement.setString(Schema.COLUMN_ORIG_ESME_NAME, sms.getOrigEsmeName());
        }
        if (sms.getOrigSystemId() != null) {
            boundStatement.setString(Schema.COLUMN_ORIG_SYSTEM_ID, sms.getOrigSystemId());
        }
        if (sms.getSubmitDate() != null) {
            DBOperations.setBoundStatementDate(boundStatement, Schema.COLUMN_SUBMIT_DATE, sms.getSubmitDate());
        }
        if (sms.getServiceType() != null) {
            boundStatement.setString(Schema.COLUMN_SERVICE_TYPE, sms.getServiceType());
        }
        boundStatement.setInt(Schema.COLUMN_ESM_CLASS, sms.getEsmClass());
        boundStatement.setInt(Schema.COLUMN_PROTOCOL_ID, sms.getProtocolId());
        boundStatement.setInt(Schema.COLUMN_PRIORITY, sms.getPriority());
        boundStatement.setInt(Schema.COLUMN_REGISTERED_DELIVERY, sms.getRegisteredDelivery());
        boundStatement.setInt(Schema.COLUMN_REPLACE, sms.getReplaceIfPresent());
        boundStatement.setInt(Schema.COLUMN_DATA_CODING, sms.getDataCoding());
        boundStatement.setInt(Schema.COLUMN_DEFAULT_MSG_ID, sms.getDefaultMsgId());
        if (sms.getShortMessage() != null) {
            boundStatement.setBytes(Schema.COLUMN_MESSAGE, ByteBuffer.wrap(sms.getShortMessage()));
        }
        if (sms.getScheduleDeliveryTime() != null) {
            DBOperations.setBoundStatementDate(boundStatement, Schema.COLUMN_SCHEDULE_DELIVERY_TIME, sms.getScheduleDeliveryTime());
        }
        if (sms.getValidityPeriod() != null) {
            DBOperations.setBoundStatementDate(boundStatement, Schema.COLUMN_VALIDITY_PERIOD, sms.getValidityPeriod());
        }
        boundStatement.setInt(Schema.COLUMN_DELIVERY_COUNT, sms.getDeliveryCount());
        if (sms.getTlvSet().getOptionalParameterCount() > 0) {
            try {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                XMLObjectWriter writer = XMLObjectWriter.newInstance(baos);
                writer.setIndentation("\t");
                writer.write(sms.getTlvSet(), TLV_SET, TlvSet.class);
                writer.close();
                byte[] rawData = baos.toByteArray();
                String serializedEvent = new String(rawData);
                boundStatement.setString(Schema.COLUMN_OPTIONAL_PARAMETERS, serializedEvent);
            } catch (XMLStreamException e) {
                String msg = "XMLStreamException when serializing optional parameters for '" + sms.getDbId() + "'!";
                throw new PersistenceException(msg, e);
            }
        }
        ResultSet res = session.execute(boundStatement);
        ps = psc.createRecordSlots;
        boundStatement = new BoundStatement(ps);
        boundStatement.setLong(Schema.COLUMN_DUE_SLOT, dueSlot);
        boundStatement.setString(Schema.COLUMN_TARGET_ID, sms.getSmsSet().getTargetId());
        res = session.execute(boundStatement);
        ps = psc.createRecordDests;
        boundStatement = new BoundStatement(ps);
        boundStatement.setString(Schema.COLUMN_TARGET_ID, sms.getSmsSet().getTargetId());
        boundStatement.setUUID(Schema.COLUMN_ID, sms.getDbId());
        boundStatement.setBool(Schema.COLUMN_SENT, false);
        res = session.execute(boundStatement);
    } catch (Exception e1) {
        String msg = "Failed createRecord !";
        throw new PersistenceException(msg, e1);
    }
}
Also used : XMLStreamException(javolution.xml.stream.XMLStreamException) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) ResultSet(com.datastax.driver.core.ResultSet) PreparedStatement(com.datastax.driver.core.PreparedStatement) XMLObjectWriter(javolution.xml.XMLObjectWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BoundStatement(com.datastax.driver.core.BoundStatement) XMLStreamException(javolution.xml.stream.XMLStreamException) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) InvalidQueryException(com.datastax.driver.core.exceptions.InvalidQueryException)

Aggregations

XMLObjectWriter (javolution.xml.XMLObjectWriter)12 XMLStreamException (javolution.xml.stream.XMLStreamException)10 FileNotFoundException (java.io.FileNotFoundException)6 FileOutputStream (java.io.FileOutputStream)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)3 InstanceNotFoundException (javax.management.InstanceNotFoundException)3 MBeanRegistrationException (javax.management.MBeanRegistrationException)3 MalformedObjectNameException (javax.management.MalformedObjectNameException)3 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)3 BoundStatement (com.datastax.driver.core.BoundStatement)2 PreparedStatement (com.datastax.driver.core.PreparedStatement)2 ResultSet (com.datastax.driver.core.ResultSet)2 InvalidQueryException (com.datastax.driver.core.exceptions.InvalidQueryException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 XMLObjectReader (javolution.xml.XMLObjectReader)2 PersistenceException (org.mobicents.smsc.cassandra.PersistenceException)2 Test (org.testng.annotations.Test)2 StringWriter (java.io.StringWriter)1