Search in sources :

Example 6 with SerializerException

use of de.janrufmonitor.util.io.SerializerException in project janrufmonitor by tbrandt77.

the class DatFileCallerExporter method doExport.

public boolean doExport() {
    File db = new File(m_filename);
    try {
        FileWriter dbWriter = new FileWriter(db);
        BufferedWriter bufWriter = new BufferedWriter(dbWriter);
        String aCaller = null;
        for (int i = 0; i < this.m_callerList.size(); i++) {
            try {
                aCaller = new String(Serializer.toByteArray(this.m_callerList.get(i), true));
                bufWriter.write(aCaller);
                bufWriter.newLine();
            } catch (SerializerException e) {
                this.m_logger.severe(e.getMessage());
            }
        }
        bufWriter.flush();
        bufWriter.close();
        dbWriter.close();
    } catch (FileNotFoundException ex) {
        this.m_logger.severe("File not found: " + m_filename);
        return false;
    } catch (IOException ex) {
        this.m_logger.severe("IOException on file " + m_filename);
        return false;
    }
    return true;
}
Also used : FileWriter(java.io.FileWriter) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File) SerializerException(de.janrufmonitor.util.io.SerializerException) BufferedWriter(java.io.BufferedWriter)

Example 7 with SerializerException

use of de.janrufmonitor.util.io.SerializerException in project janrufmonitor by tbrandt77.

the class DatFileCallerImporter method doImport.

public ICallerList doImport() {
    m_callerList = PIMRuntime.getInstance().getCallerFactory().createCallerList();
    Date startDate = new Date();
    File db = new File(m_filename);
    try {
        FileReader dbReader = new FileReader(db);
        BufferedReader bufReader = new BufferedReader(dbReader);
        ICaller aCaller = null;
        while (bufReader.ready()) {
            try {
                aCaller = Serializer.toCaller(bufReader.readLine().getBytes(), PIMRuntime.getInstance());
                if (aCaller == null) {
                    // file format is corrupted
                    return this.m_callerList;
                }
                this.m_callerList.add(aCaller);
            } catch (SerializerException e) {
                this.m_logger.warning("Caller was skipped: " + e.getMessage());
            }
        }
        bufReader.close();
        dbReader.close();
    } catch (FileNotFoundException ex) {
        this.m_logger.warning("Cannot find caller backup file " + m_filename);
        return this.m_callerList;
    } catch (IOException ex) {
        this.m_logger.severe("IOException on file " + m_filename);
        return this.m_callerList;
    }
    Date endDate = new Date();
    this.m_logger.info("Successfully imported caller file " + m_filename);
    this.m_logger.info("Found " + new Integer(this.m_callerList.size()).toString() + " caller items in " + new Float((endDate.getTime() - startDate.getTime()) / 1000).toString() + " secs.");
    return this.m_callerList;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File) SerializerException(de.janrufmonitor.util.io.SerializerException) Date(java.util.Date)

Example 8 with SerializerException

use of de.janrufmonitor.util.io.SerializerException in project janrufmonitor by tbrandt77.

the class DatFileCallExporter method doExport.

public boolean doExport() {
    File db = new File(this.m_filename);
    try {
        FileWriter dbWriter = new FileWriter(db);
        BufferedWriter bufWriter = new BufferedWriter(dbWriter);
        String aCall = null;
        for (int i = 0; i < this.m_callList.size(); i++) {
            try {
                aCall = new String(Serializer.toByteArray(this.m_callList.get(i)));
                bufWriter.write(aCall);
                bufWriter.newLine();
            } catch (SerializerException e) {
                this.m_logger.severe(e.getMessage());
            }
        }
        bufWriter.flush();
        bufWriter.close();
        dbWriter.close();
    } catch (FileNotFoundException ex) {
        this.m_logger.severe("File not found: " + m_filename);
        return false;
    } catch (IOException ex) {
        this.m_logger.severe("IOException on file " + m_filename);
        return false;
    }
    return true;
}
Also used : FileWriter(java.io.FileWriter) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File) SerializerException(de.janrufmonitor.util.io.SerializerException) BufferedWriter(java.io.BufferedWriter)

Example 9 with SerializerException

use of de.janrufmonitor.util.io.SerializerException in project janrufmonitor by tbrandt77.

the class DatFileCallImporter method doImport.

public ICallList doImport() {
    m_callList = PIMRuntime.getInstance().getCallFactory().createCallList();
    Date startDate = new Date();
    File db = new File(m_filename);
    try {
        FileReader dbReader = new FileReader(db);
        BufferedReader bufReader = new BufferedReader(dbReader);
        ICall aCall = null;
        boolean isNewDatFormat = false;
        String line = null;
        Transformator tf = null;
        while (bufReader.ready()) {
            line = bufReader.readLine();
            if (!isNewDatFormat && line != null && line.indexOf("***") > -1) {
                if (tf == null)
                    tf = new Transformator();
            } else {
                isNewDatFormat = true;
            }
            try {
                aCall = (isNewDatFormat ? Serializer.toCall(line.getBytes(), PIMRuntime.getInstance()) : tf.transform(line));
                // 2008/11/07: new call status introduced in 5.0.8
                migrateStatus(aCall);
                this.m_callList.add(aCall);
            } catch (SerializerException e) {
                this.m_logger.warning(e.getMessage());
            }
        }
        bufReader.close();
        dbReader.close();
    } catch (FileNotFoundException ex) {
        this.m_logger.warning("Cannot find call backup file " + m_filename);
        return this.m_callList;
    } catch (IOException ex) {
        this.m_logger.severe("IOException on file " + m_filename);
        return this.m_callList;
    } catch (NoSuchElementException ex) {
        this.m_logger.severe("Invalid format in file " + m_filename);
        return this.m_callList;
    }
    Date endDate = new Date();
    this.m_logger.info("Successfully imported call file " + m_filename);
    this.m_logger.info("Found " + new Integer(this.m_callList.size()).toString() + " call items in " + new Float((endDate.getTime() - startDate.getTime()) / 1000).toString() + " secs.");
    return m_callList;
}
Also used : ICall(de.janrufmonitor.framework.ICall) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) SerializerException(de.janrufmonitor.util.io.SerializerException) Date(java.util.Date) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) NoSuchElementException(java.util.NoSuchElementException)

Example 10 with SerializerException

use of de.janrufmonitor.util.io.SerializerException in project janrufmonitor by tbrandt77.

the class AbstractCallDatabaseHandler method updateCallList.

/**
 * Updates all calls in the submitted list. The select criterion of teh call is its UUID.
 * @param cl
 * @throws SQLException
 */
public void updateCallList(ICallList cl) throws SQLException {
    if (!isConnected())
        try {
            this.connect();
        } catch (ClassNotFoundException e) {
            throw new SQLException(e.getMessage());
        }
    if (this.containsListAll(cl.size())) {
        this.createTables();
        this.setCallList(cl);
        return;
    }
    PreparedStatement ps = this.getStatement("UPDATE_CALL");
    PreparedStatement psa = this.getStatement("UPDATE_ATTRIBUTE");
    ps.clearBatch();
    psa.clearBatch();
    ICall c = null;
    IPhonenumber pn = null;
    for (int i = 0, j = cl.size(); i < j; i++) {
        c = cl.get(i);
        pn = c.getCaller().getPhoneNumber();
        try {
            this.updateCall(ps, c.getUUID(), c.getCaller().getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber(), c.getMSN().getMSN(), c.getCIP().getCIP(), c.getDate().getTime(), Serializer.toByteArray(c));
            this.updateAttributes(psa, c.getUUID(), c.getAttributes());
            this.updateAttributes(psa, c.getCaller().getUUID(), c.getCaller().getAttributes());
        } catch (SerializerException e) {
            this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        }
        if (i % this.commit_count == 0) {
            ps.executeBatch();
            ps.clearBatch();
            this.m_logger.info("Executed prepared statement: " + ps.toString());
            psa.executeBatch();
            psa.clearBatch();
            this.m_logger.info("Executed prepared statement: " + psa.toString());
        }
    }
    // execute the rest batch content
    ps.executeBatch();
    psa.executeBatch();
}
Also used : ICall(de.janrufmonitor.framework.ICall) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) SerializerException(de.janrufmonitor.util.io.SerializerException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Aggregations

SerializerException (de.janrufmonitor.util.io.SerializerException)14 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)7 PreparedStatement (java.sql.PreparedStatement)7 SQLException (java.sql.SQLException)6 ICaller (de.janrufmonitor.framework.ICaller)5 ICallerList (de.janrufmonitor.framework.ICallerList)5 ResultSet (java.sql.ResultSet)5 ICall (de.janrufmonitor.framework.ICall)4 UUID (de.janrufmonitor.util.uuid.UUID)4 File (java.io.File)4 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 IAttribute (de.janrufmonitor.framework.IAttribute)3 Statement (java.sql.Statement)3 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)2 ICallList (de.janrufmonitor.framework.ICallList)2 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)2 CallerNotFoundException (de.janrufmonitor.repository.CallerNotFoundException)2