Alexandre Lision | aad014e | 2014-01-14 17:45:49 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2014 Savoir-Faire Linux Inc. |
| 3 | * |
| 4 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | * |
| 20 | * Additional permission under GNU GPL version 3 section 7: |
| 21 | * |
| 22 | * If you modify this program, or any covered work, by linking or |
| 23 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 24 | * modified version of that library), containing parts covered by the |
| 25 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 26 | * grants you additional permission to convey the resulting work. |
| 27 | * Corresponding Source for a non-source form of such a combination |
| 28 | * shall include the source code for the parts of OpenSSL used as well |
| 29 | * as that of the covered work. |
| 30 | */ |
| 31 | |
| 32 | package org.sflphone.history; |
| 33 | |
| 34 | import android.content.Context; |
| 35 | import com.j256.ormlite.android.apptools.OpenHelperManager; |
Alexandre Lision | 67c70b4 | 2014-01-16 13:57:15 -0500 | [diff] [blame] | 36 | import com.j256.ormlite.stmt.QueryBuilder; |
| 37 | import com.j256.ormlite.table.TableUtils; |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 38 | import org.sflphone.model.Conference; |
| 39 | import org.sflphone.model.SipCall; |
Alexandre Lision | aad014e | 2014-01-14 17:45:49 -0500 | [diff] [blame] | 40 | |
| 41 | import java.sql.SQLException; |
Alexandre Lision | aad014e | 2014-01-14 17:45:49 -0500 | [diff] [blame] | 42 | import java.util.List; |
Alexandre Lision | aad014e | 2014-01-14 17:45:49 -0500 | [diff] [blame] | 43 | |
| 44 | public class HistoryManager { |
| 45 | |
| 46 | private Context mContext; |
| 47 | private DatabaseHelper historyDBHelper = null; |
| 48 | |
| 49 | public HistoryManager(Context context) { |
Alexandre Lision | aad014e | 2014-01-14 17:45:49 -0500 | [diff] [blame] | 50 | mContext = context; |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 51 | getHelper(); |
| 52 | } |
| 53 | |
| 54 | public boolean insertNewEntry(Conference toInsert){ |
| 55 | for (SipCall call : toInsert.getParticipants()) { |
| 56 | call.setTimestampEnd_(System.currentTimeMillis() * 1000); |
| 57 | HistoryCall persistent = new HistoryCall(call); |
| 58 | try { |
| 59 | getHelper().getHistoryDao().create(persistent); |
| 60 | } catch (SQLException e) { |
| 61 | e.printStackTrace(); |
| 62 | return false; |
| 63 | } |
| 64 | } |
| 65 | return true; |
| 66 | } |
| 67 | |
Alexandre Lision | 183bf45 | 2014-01-17 11:21:59 -0500 | [diff] [blame^] | 68 | /* |
| 69 | * Necessary when user hang up a call in a Conference |
| 70 | * The call creates an HistoryCall, but the conference still goes on |
| 71 | */ |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 72 | public boolean insertNewEntry(SipCall toInsert){ |
| 73 | return true; |
Alexandre Lision | aad014e | 2014-01-14 17:45:49 -0500 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Retrieve helper for our DB |
| 78 | */ |
| 79 | private DatabaseHelper getHelper() { |
| 80 | if (historyDBHelper == null) { |
| 81 | historyDBHelper = OpenHelperManager.getHelper(mContext, DatabaseHelper.class); |
| 82 | } |
| 83 | return historyDBHelper; |
| 84 | } |
| 85 | |
| 86 | public List<HistoryCall> getAll() throws SQLException { |
Alexandre Lision | 67c70b4 | 2014-01-16 13:57:15 -0500 | [diff] [blame] | 87 | |
| 88 | QueryBuilder<HistoryCall, Integer> qb = getHelper().getHistoryDao().queryBuilder(); |
| 89 | qb.orderBy("TIMESTAMP_START", true); |
| 90 | |
| 91 | return getHelper().getHistoryDao().query(qb.prepare()); |
| 92 | } |
| 93 | |
| 94 | public boolean clearDB() { |
| 95 | try { |
| 96 | TableUtils.clearTable(getHelper().getConnectionSource(), HistoryCall.class); |
| 97 | } catch (SQLException e) { |
| 98 | e.printStackTrace(); |
| 99 | return false; |
| 100 | } |
| 101 | return true; |
Alexandre Lision | aad014e | 2014-01-14 17:45:49 -0500 | [diff] [blame] | 102 | } |
| 103 | } |