List of usage examples for org.json JSONObject getLong
public long getLong(String key) throws JSONException
From source file:com.newtifry.android.database.NewtifrySource.java
public ArrayList<NewtifrySource> syncFromJSONArray(Context context, JSONArray sourceList, String accountName) throws JSONException { ArrayList<NewtifrySource> result = new ArrayList<NewtifrySource>(); HashSet<Long> seenIds = new HashSet<Long>(); for (int i = 0; i < sourceList.length(); i++) { // See if we can find a local object with that ID. JSONObject object = sourceList.getJSONObject(i); Long serverId = object.getLong("id"); NewtifrySource source = NewtifrySource.FACTORY.getByServerId(context, serverId); if (source == null) { // We don't have that source locally. Create it. source = new NewtifrySource(); source.fromJSONObject(object); // It's only locally enabled if the server has it enabled. source.setLocalEnabled(source.getServerEnabled()); source.setAccountName(accountName); } else {//w ww . j ava 2 s .co m // Server already has it. Assume the server is the most up to date version. source.fromJSONObject(object); } // Save it in the database. source.save(context); seenIds.add(source.getId()); } // Now, find out the IDs that exist in our database but were not in our list. // Those have been deleted. ArrayList<NewtifrySource> allSources = NewtifrySource.FACTORY.listAll(context, accountName); HashSet<Long> allIds = new HashSet<Long>(); for (NewtifrySource source : allSources) { allIds.add(source.getId()); } allIds.removeAll(seenIds); for (Long sourceId : allIds) { NewtifrySource source = NewtifrySource.FACTORY.get(context, sourceId); NewtifryMessage.FACTORY.deleteMessagesBySource(context, source, false); source.delete(context); } return result; }
From source file:com.jennifer.ui.chart.ChartBuilder.java
@Override public void drawBefore() { JSONObject series = cloneObject("series"); JSONObject grid = cloneObject("grid"); Object brush = clone("brush"); Object widget = clone("widget"); JSONArray data = cloneArray("data"); // series ?? for (int i = 0, len = data.length(); i < len; i++) { JSONObject row = (JSONObject) data.getJSONObject(i); Iterator it = row.keys(); while (it.hasNext()) { String key = (String) it.next(); if (!series.has(key)) { series.put(key, new JSONObject()); }/* www.j av a2 s . c o m*/ JSONObject obj = JSONUtil.clone(series.getJSONObject(key)); if (obj == null) continue; Object valueObject = row.get(key); if (valueObject instanceof String) continue; if (valueObject instanceof Double || valueObject instanceof Integer) { double value = row.getDouble(key); if (!obj.has("min")) obj.put("min", value); if (!obj.has("max")) obj.put("max", value); if (value < obj.getDouble("min")) obj.put("min", value); if (value > obj.getDouble("max")) obj.put("max", value); } else if (row.get(key) instanceof Long) { long value = row.getLong(key); if (!obj.has("min")) obj.put("min", value); if (!obj.has("max")) obj.put("max", value); if (value < obj.getLong("min")) obj.put("min", value); if (value > obj.getLong("max")) obj.put("max", value); } series.put(key, obj); } } // series_list barray("brush", createBrushData(brush, series.names())); barray("widget", createBrushData(widget, series.names())); bobject("grid", grid); bobject("hash", null); barray("data", data); bobject("series", series); }
From source file:com.flowzr.budget.holo.export.flowzr.FlowzrSyncEngine.java
public static Object saveOrUpdateCurrencyRateFromJSON(JSONObject jsonObjectEntity) { if (!jsonObjectEntity.has("effective_date")) { //return null; }//from ww w. ja v a 2 s . c om try { long toCurrencyId = getLocalKey(DatabaseHelper.CURRENCY_TABLE, jsonObjectEntity.getString("to_currency")); long fromCurrencyId = getLocalKey(DatabaseHelper.CURRENCY_TABLE, jsonObjectEntity.getString("from_currency")); if (toCurrencyId > -1 && fromCurrencyId > -1) { Currency toCurrency = em.load(Currency.class, toCurrencyId); Currency fromCurrency = em.load(Currency.class, fromCurrencyId); long effective_date = jsonObjectEntity.getLong("effective_date") * 1000; double rate = jsonObjectEntity.getDouble("rate"); ExchangeRate exRate = new ExchangeRate(); exRate.toCurrencyId = toCurrency.id; exRate.fromCurrencyId = fromCurrency.id; exRate.rate = rate; exRate.date = effective_date; dba.saveRate(exRate); } } catch (Exception e) { Log.e(TAG, "unable to load a currency rate from server..."); e.printStackTrace(); } return null; }
From source file:com.flowzr.budget.holo.export.flowzr.FlowzrSyncEngine.java
public static Object saveOrUpdateBudgetFromJSON(long id, JSONObject jsonObjectEntity) throws JSONException { Budget tEntity = em.get(Budget.class, id); if (tEntity == null) { tEntity = new Budget(); tEntity.id = KEY_CREATE;/*from w w w . j a v a2s . co m*/ } try { tEntity.remoteKey = jsonObjectEntity.getString("key"); } catch (JSONException e2) { e2.printStackTrace(); } if (jsonObjectEntity.has("title")) { try { tEntity.title = jsonObjectEntity.getString("title"); } catch (JSONException e) { e.printStackTrace(); } } if (jsonObjectEntity.has("categories")) { try { String[] strArrCategories = jsonObjectEntity.getString("categories").split(","); tEntity.categories = ""; for (String key : strArrCategories) { tEntity.categories += getLocalKey(DatabaseHelper.CATEGORY_TABLE, key) + ","; } if (tEntity.categories.endsWith(",")) { tEntity.categories = tEntity.categories.substring(0, tEntity.categories.length() - 1); } } catch (Exception e) { Log.e(TAG, "Error parsing Budget categories"); e.printStackTrace(); } } if (jsonObjectEntity.has("projects")) { try { String[] strArrProjects = jsonObjectEntity.getString("projects").split(","); tEntity.projects = ""; for (String key : strArrProjects) { tEntity.projects += getLocalKey(DatabaseHelper.PROJECT_TABLE, key) + ","; } if (tEntity.projects.endsWith(",")) { tEntity.projects = tEntity.projects.substring(0, tEntity.projects.length() - 1); } } catch (Exception e) { Log.e(TAG, "Error parsing Budget.project_id "); e.printStackTrace(); } } // if (jsonObjectEntity.has("currency")) { // try { // tEntity.currencyId=getLocalKey(DatabaseHelper.CURRENCY_TABLE, jsonObjectEntity.getString("currency")); // } catch (Exception e) { // Log.e(TAG,"Error parsing Budget.currency "); // e.printStackTrace(); // } // } if (jsonObjectEntity.has("budget_account_id")) { try { tEntity.account = em.load(Account.class, getLocalKey(DatabaseHelper.ACCOUNT_TABLE, jsonObjectEntity.getString("budget_account_id"))); } catch (Exception e) { Log.e(TAG, "Error parsing Budget.budget_account_id "); e.printStackTrace(); } } else { if (jsonObjectEntity.has("budget_currency_id")) { try { tEntity.currency = em.load(Currency.class, getLocalKey(DatabaseHelper.CURRENCY_TABLE, jsonObjectEntity.getString("budget_currency_id"))); tEntity.currencyId = getLocalKey(DatabaseHelper.CURRENCY_TABLE, jsonObjectEntity.getString("budget_currency_id")); } catch (Exception e) { Log.e(TAG, "Error parsing Budget.budget_currency_id "); e.printStackTrace(); } } } if (jsonObjectEntity.has("amount2")) { try { tEntity.amount = jsonObjectEntity.getInt("amount2"); } catch (Exception e) { Log.e(TAG, "Error parsing Budget.amount"); e.printStackTrace(); } } if (jsonObjectEntity.has("includeSubcategories")) { tEntity.includeSubcategories = jsonObjectEntity.getBoolean("includeSubcategories"); } if (jsonObjectEntity.has("expanded")) { tEntity.expanded = jsonObjectEntity.getBoolean("expanded"); } if (jsonObjectEntity.has("includeCredit")) { tEntity.includeCredit = jsonObjectEntity.getBoolean("includeCredit"); } if (jsonObjectEntity.has("startDate")) { try { tEntity.startDate = jsonObjectEntity.getLong("startDate") * 1000; } catch (Exception e1) { Log.e(TAG, "Error parsing Budget.startDate"); e1.printStackTrace(); } } if (jsonObjectEntity.has("endDate")) { try { tEntity.endDate = jsonObjectEntity.getLong("endDate") * 1000; } catch (Exception e1) { Log.e(TAG, "Error parsing Budget.endDate"); e1.printStackTrace(); } } if (jsonObjectEntity.has("recurNum")) { try { tEntity.recurNum = jsonObjectEntity.getInt("recurNum"); } catch (JSONException e) { e.printStackTrace(); } } if (jsonObjectEntity.has("isCurrent")) { try { tEntity.isCurrent = jsonObjectEntity.getBoolean("isCurrent"); } catch (JSONException e) { e.printStackTrace(); } } if (jsonObjectEntity.has("parentBudgetId")) { try { tEntity.parentBudgetId = getLocalKey(DatabaseHelper.BUDGET_TABLE, jsonObjectEntity.getString("parentBudgetId")); } catch (Exception e) { Log.e(TAG, "Error parsing Budget.parentBudgetId "); e.printStackTrace(); } } if (jsonObjectEntity.has("recur")) { try { tEntity.recur = jsonObjectEntity.getString("recur"); } catch (JSONException e) { e.printStackTrace(); } } em.saveOrUpdate(tEntity); return tEntity; }
From source file:com.flowzr.budget.holo.export.flowzr.FlowzrSyncEngine.java
public static Object saveOrUpdateLocationFromJSON(long id, JSONObject jsonObjectEntity) { MyLocation tEntity = em.get(MyLocation.class, id); if (tEntity == null) { tEntity = new MyLocation(); tEntity.id = KEY_CREATE;//from w w w .j a va2 s. co m } try { tEntity.remoteKey = jsonObjectEntity.getString("key"); if (jsonObjectEntity.has("name")) { tEntity.name = jsonObjectEntity.getString("name"); } else { tEntity.name = "---"; } if (jsonObjectEntity.has("provider")) { tEntity.provider = jsonObjectEntity.getString("provider"); } if (jsonObjectEntity.has("accuracy")) { try { tEntity.accuracy = Float.valueOf(jsonObjectEntity.getString("accuracy")); } catch (Exception e) { Log.e(TAG, "Error parsing MyLocation.accuracy with : " + jsonObjectEntity.getString("accuracy")); } } if (jsonObjectEntity.has("lon")) { tEntity.longitude = jsonObjectEntity.getDouble("lon"); } if (jsonObjectEntity.has("lat")) { tEntity.latitude = jsonObjectEntity.getDouble("lat"); } if (jsonObjectEntity.has("is_payee")) { if (jsonObjectEntity.getBoolean("is_payee")) { tEntity.isPayee = true; } else { tEntity.isPayee = false; } } if (jsonObjectEntity.has("resolved_adress")) { tEntity.resolvedAddress = jsonObjectEntity.getString("resolved_adress"); } if (jsonObjectEntity.has("dateOfEmission")) { try { tEntity.dateTime = jsonObjectEntity.getLong("dateOfEmission"); } catch (Exception e1) { Log.e(TAG, "Error parsing MyLocation.dateTime with : " + jsonObjectEntity.getString("dateOfEmission")); } } if (jsonObjectEntity.has("count")) { tEntity.count = jsonObjectEntity.getInt("count"); } if (jsonObjectEntity.has("dateTime")) { tEntity.dateTime = jsonObjectEntity.getLong("dateTime"); } if (jsonObjectEntity.has("dateTime")) { tEntity.dateTime = jsonObjectEntity.getLong("dateTime"); } em.saveOrUpdate(tEntity); return tEntity; } catch (Exception e) { e.printStackTrace(); return e; } }
From source file:com.flowzr.budget.holo.export.flowzr.FlowzrSyncEngine.java
public static Object saveOrUpdateAccountFromJSON(long id, JSONObject jsonObjectAccount) { Account tEntity = em.get(Account.class, id); if (tEntity == null) { tEntity = new Account(); tEntity.id = KEY_CREATE;/*from w w w . j a v a2 s . c o m*/ } try { //title try { tEntity.title = jsonObjectAccount.getString("name"); } catch (Exception e) { tEntity.title = "---"; Log.e(TAG, "Error parsing Account.name with"); } tEntity.remoteKey = jsonObjectAccount.getString("key"); //creation_date try { tEntity.creationDate = jsonObjectAccount.getLong("created_on"); } catch (Exception e) { Log.e(TAG, "Error parsing Account.creationDate"); } //last_transaction_date if (jsonObjectAccount.has("dateOfLastTransaction")) { try { tEntity.lastTransactionDate = jsonObjectAccount.getLong("dateOfLastTransaction"); } catch (Exception e) { Log.e(TAG, "Error parsing Account.dateOfLastTransaction with : " + jsonObjectAccount.getString("dateOfLastTransaction")); } } //currency, currency_name, currency_symbol Currency c = null; Collection<Currency> currencies = CurrencyCache.getAllCurrencies(); if (jsonObjectAccount.has("currency_id")) { try { c = em.load(Currency.class, getLocalKey(DatabaseHelper.CURRENCY_TABLE, jsonObjectAccount.getString("currency_id"))); tEntity.currency = c; } catch (Exception e) { Log.e(TAG, "unable to load currency for account " + tEntity.title + " with " + jsonObjectAccount.getString("currency_id")); } //server created account don't have a currency_id but all the properties to build one. } if (tEntity.currency == null && jsonObjectAccount.has("currency")) { //try if provided currency is in user's currency for (Currency currency : currencies) { if (currency.name.equals(jsonObjectAccount.getString("currency"))) { tEntity.currency = currency; } } //load from data server if any if (tEntity.currency == null) { c = Currency.EMPTY; c.name = jsonObjectAccount.getString("currency"); if (jsonObjectAccount.has("currency_name")) { c.title = jsonObjectAccount.getString("currency_name"); } if (jsonObjectAccount.has("currency_symbol")) { c.symbol = jsonObjectAccount.getString("currency_symbol"); } tEntity.currency = c; c.id = -1; //db put! em.saveOrUpdate(c); } } else if (tEntity.currency == null) { //no currency provided use default for (Currency currency : currencies) { if (currency.isDefault) { tEntity.currency = currency; } } //still nothing : default set to empty if (tEntity.currency == null) { c = Currency.EMPTY; c.isDefault = true; tEntity.currency = c; //c.id=-1; //db put! //em.saveOrUpdate(c); } } CurrencyCache.initialize(em); //card_issuer if (jsonObjectAccount.has("card_issuer")) { tEntity.cardIssuer = jsonObjectAccount.getString("card_issuer"); } //issuer if (jsonObjectAccount.has(DatabaseHelper.AccountColumns.ISSUER)) { tEntity.issuer = jsonObjectAccount.getString(DatabaseHelper.AccountColumns.ISSUER); } //number if (jsonObjectAccount.has("code")) { tEntity.number = jsonObjectAccount.getString("code"); } //limit if (jsonObjectAccount.has("total_limit")) { tEntity.limitAmount = jsonObjectAccount.getLong("total_limit"); } //is_active if (jsonObjectAccount.has("closed")) { if (jsonObjectAccount.getBoolean("closed")) { tEntity.isActive = false; } else { tEntity.isActive = true; } } //is_include_into_totals if (jsonObjectAccount.has(DatabaseHelper.AccountColumns.IS_INCLUDE_INTO_TOTALS)) { if (jsonObjectAccount.getBoolean(DatabaseHelper.AccountColumns.IS_INCLUDE_INTO_TOTALS)) { tEntity.isIncludeIntoTotals = true; } else { tEntity.isIncludeIntoTotals = false; } } //closing_day try { tEntity.closingDay = jsonObjectAccount.getInt(DatabaseHelper.AccountColumns.CLOSING_DAY); } catch (Exception e) { } //payment_day try { tEntity.paymentDay = jsonObjectAccount.getInt(DatabaseHelper.AccountColumns.PAYMENT_DAY); } catch (Exception e) { } //note if (jsonObjectAccount.has("description")) { tEntity.note = jsonObjectAccount.getString("description"); } //sort_order if (jsonObjectAccount.has(DatabaseHelper.AccountColumns.SORT_ORDER)) { tEntity.sortOrder = jsonObjectAccount.getInt(DatabaseHelper.AccountColumns.SORT_ORDER); } if (jsonObjectAccount.has(DatabaseHelper.AccountColumns.TYPE)) { tEntity.type = jsonObjectAccount.getString(DatabaseHelper.AccountColumns.TYPE); } em.saveOrUpdate(tEntity); return tEntity; } catch (Exception e1) { e1.printStackTrace(); return e1; } }
From source file:com.flowzr.budget.holo.export.flowzr.FlowzrSyncEngine.java
public static Object saveOrUpdateTransactionFromJSON(long id, JSONObject jsonObjectResponse) throws JSONException, Exception { Transaction tEntity = em.get(Transaction.class, id); if (tEntity == null) { tEntity = new Transaction(); tEntity.id = KEY_CREATE;//from www .j a v a 2s . c o m } //from_account_id, try { tEntity.fromAccountId = getLocalKey(DatabaseHelper.ACCOUNT_TABLE, jsonObjectResponse.getString("account")); } catch (Exception e1) { Log.e("flowzr", "Error parsing Transaction.fromAccount"); return null; //REQUIRED } if (jsonObjectResponse.has("dateTime")) { tEntity.dateTime = jsonObjectResponse.getLong("dateTime") * 1000; } else { return null; //REQUIRED } //parent_tr if (jsonObjectResponse.has("parent_tr")) { long pid = getLocalKey(DatabaseHelper.TRANSACTION_TABLE, jsonObjectResponse.getString("parent_tr")); if (pid > KEY_CREATE) { tEntity.parentId = pid; Transaction parent_tr = em.load(Transaction.class, tEntity.parentId); if (parent_tr.categoryId != Category.SPLIT_CATEGORY_ID) { parent_tr.categoryId = Category.SPLIT_CATEGORY_ID; em.saveOrUpdate(parent_tr); } } else { try { String key = jsonObjectResponse.getString("parent_tr"); requery(DatabaseHelper.TRANSACTION_TABLE, Transaction.class, key); long pid2 = getLocalKey(DatabaseHelper.TRANSACTION_TABLE, jsonObjectResponse.getString("parent_tr")); tEntity.parentId = pid2; Transaction parent_tr = em.load(Transaction.class, tEntity.parentId); if (parent_tr.categoryId != Category.SPLIT_CATEGORY_ID) { parent_tr.categoryId = Category.SPLIT_CATEGORY_ID; em.saveOrUpdate(parent_tr); } } catch (Exception e) { //add to delete log ? e.printStackTrace(); //throw new Exception("Got key " + jsonObjectResponse.getString("parent_tr") + " but couldn't find related parent tr"); } } } //to_account_id, if (jsonObjectResponse.has("to_account")) { try { tEntity.toAccountId = getLocalKey(DatabaseHelper.ACCOUNT_TABLE, jsonObjectResponse.getString("to_account")); } catch (Exception e1) { Log.e("flowzr", "Error parsing Transaction.toAccount with : " + jsonObjectResponse.getString("to_account")); } } if (jsonObjectResponse.has("key")) { tEntity.remoteKey = jsonObjectResponse.getString("key"); } if (jsonObjectResponse.has("amount")) { tEntity.fromAmount = jsonObjectResponse.getLong("amount"); } if (jsonObjectResponse.has("to_amount")) { tEntity.toAmount = jsonObjectResponse.getLong("to_amount"); } if (jsonObjectResponse.has("original_currency_id")) { try { tEntity.originalCurrencyId = getLocalKey(DatabaseHelper.CURRENCY_TABLE, jsonObjectResponse.getString("original_currency_id")); } catch (Exception e) { Log.e("flowzr", "Error parsing Transaction.original_currency_id with : " + jsonObjectResponse.getString("original_currency_id")); } } if (jsonObjectResponse.has("original_from_amount")) { tEntity.originalFromAmount = (long) jsonObjectResponse.getDouble("original_from_amount"); } if (jsonObjectResponse.has("description")) { tEntity.note = jsonObjectResponse.getString("description"); } //category_id, if (jsonObjectResponse.has("cat")) { try { long l = getLocalKey(DatabaseHelper.CATEGORY_TABLE, jsonObjectResponse.getString("cat")); if (l >= KEY_CREATE) { tEntity.categoryId = l; } else { requery(DatabaseHelper.CATEGORY_TABLE, Category.class, jsonObjectResponse.getString("cat")); tEntity.categoryId = getLocalKey(DatabaseHelper.CATEGORY_TABLE, jsonObjectResponse.getString("cat")); } } catch (Exception e1) { tEntity.categoryId = Category.NO_CATEGORY_ID; e1.printStackTrace(); Log.e("flowzr", "Error parsing Transaction.categoryId with : " + jsonObjectResponse.getString("cat")); } } else { tEntity.categoryId = Category.NO_CATEGORY_ID; } //project_id, if (jsonObjectResponse.has("project")) { try { tEntity.projectId = getLocalKey(DatabaseHelper.PROJECT_TABLE, jsonObjectResponse.getString("project")); if (tEntity.projectId <= KEY_CREATE) { requery(DatabaseHelper.PROJECT_TABLE, Project.class, jsonObjectResponse.getString("project")); tEntity.projectId = getLocalKey(DatabaseHelper.PROJECT_TABLE, jsonObjectResponse.getString("project")); } } catch (Exception e1) { Log.e("flowzr", "Error parsing Transaction.ProjectId with : " + jsonObjectResponse.getString("project")); } } //payee_id, if (jsonObjectResponse.has("payee_id")) { try { tEntity.payeeId = getLocalKey(DatabaseHelper.PAYEE_TABLE, jsonObjectResponse.getString("payee_id")); if (tEntity.payeeId <= KEY_CREATE) { requery(DatabaseHelper.PAYEE_TABLE, Payee.class, jsonObjectResponse.getString("payee_id")); tEntity.payeeId = getLocalKey(DatabaseHelper.PAYEE_TABLE, jsonObjectResponse.getString("payee_id")); } } catch (Exception e1) { Log.e("flowzr", "Error parsing Transaction.PayeeId with : " + jsonObjectResponse.getString("payee_id")); } } //location_id if (jsonObjectResponse.has("location_id")) { try { long lid = getLocalKey(DatabaseHelper.LOCATIONS_TABLE, jsonObjectResponse.getString("location_id")); if (lid > 0) { tEntity.locationId = lid; } else { requery(DatabaseHelper.LOCATIONS_TABLE, MyLocation.class, jsonObjectResponse.getString("location_id")); tEntity.locationId = getLocalKey(DatabaseHelper.LOCATIONS_TABLE, jsonObjectResponse.getString("location_id")); } } catch (Exception e1) { Log.e("flowzr", "Error parsing Transaction.location_id with : " + jsonObjectResponse.getString("location_id")); } } //accuracy,provider,latitude,longitude if (jsonObjectResponse.has("provider")) { tEntity.provider = jsonObjectResponse.getString("provider"); } if (jsonObjectResponse.has("accuracy")) { try { tEntity.accuracy = jsonObjectResponse.getLong("accuracy"); } catch (Exception e) { Log.e("flowzr", "Error getting accuracy value for transaction with:" + jsonObjectResponse.getString("accuracy")); } } if (jsonObjectResponse.has("lat") && jsonObjectResponse.has("lon")) { try { tEntity.latitude = jsonObjectResponse.getDouble("lat"); tEntity.longitude = jsonObjectResponse.getDouble("lon"); } catch (Exception e) { Log.e("flowzr", "Error getting geo_point value for transaction with:" + jsonObjectResponse.getString("lat") + " " + jsonObjectResponse.getDouble("lon")); } } tEntity.status = TransactionStatus.UR; if (jsonObjectResponse.has("status")) { if (jsonObjectResponse.getString("status").equals("UR")) { tEntity.status = TransactionStatus.UR; } else if (jsonObjectResponse.getString("status").equals("RC")) { tEntity.status = TransactionStatus.RC; } else if (jsonObjectResponse.getString("status").equals("CL")) { tEntity.status = TransactionStatus.CL; } else if (jsonObjectResponse.getString("status").equals("PN")) { tEntity.status = TransactionStatus.PN; } else if (jsonObjectResponse.getString("status").equals("RS")) { tEntity.status = TransactionStatus.RS; } else { tEntity.status = TransactionStatus.UR; } } //is_ccard_payment, if (jsonObjectResponse.has("is_ccard_payment")) { tEntity.isCCardPayment = jsonObjectResponse.getInt("is_ccard_payment"); } List<TransactionAttribute> attributes = null; if (jsonObjectResponse.has("transaction_attribute")) { attributes = new LinkedList<TransactionAttribute>(); for (String pair : jsonObjectResponse.getString("transaction_attribute").split(";")) { String[] strArrAttr = pair.split("="); if (strArrAttr.length == 2) { TransactionAttribute a = new TransactionAttribute(); a.value = strArrAttr[1]; a.attributeId = getLocalKey(DatabaseHelper.ATTRIBUTES_TABLE, strArrAttr[0]); a.transactionId = tEntity.id; attributes.add(a); } } } //blob url, if (jsonObjectResponse.has("blob_url") && tEntity.attachedPicture == null) { tEntity.blobKey = jsonObjectResponse.getString("blob_url"); } id = em.saveOrUpdate(tEntity); if (attributes != null) { dba.db().delete(DatabaseHelper.TRANSACTION_ATTRIBUTE_TABLE, DatabaseHelper.TransactionAttributeColumns.TRANSACTION_ID + "=?", new String[] { String.valueOf(id) }); for (TransactionAttribute a : attributes) { a.transactionId = id; ContentValues values = a.toValues(); dba.db().insert(DatabaseHelper.TRANSACTION_ATTRIBUTE_TABLE, null, values); } } return tEntity; }
From source file:fr.immotronic.ubikit.pems.enocean.impl.item.data.EEP0503xxDataImpl.java
public static EEP0503xxDataImpl constructDataFromRecord(JSONObject lastKnownData) { if (lastKnownData == null) return new EEP0503xxDataImpl(null, null); try {/*from w w w . j a va2s . c o m*/ SwitchEvent[] switchEvents = new SwitchEvent[4]; for (int i = 0; i < switchEvents.length; i++) { JSONObject o = lastKnownData.optJSONObject("switchEvent" + i); if (o == null) switchEvents[i] = null; else switchEvents[i] = new SwitchEventImpl(o); } Date date = new Date(lastKnownData.getLong("date")); return new EEP0503xxDataImpl(switchEvents, date); } catch (JSONException e) { Logger.error(LC.gi(), null, "constructDataFromRecord(): An exception while building a sensorData from a JSONObject SHOULD never happen. Check the code !", e); return new EEP0503xxDataImpl(null, null); } }