/** * The entire purpose of this function is to recover the issues that were in the old version of * the library and then to delete the remaining file when we are done with it. A user should never * need to call this function, this gets automatically run for them in {@link * Api#init(android.app.Application)}. */ public void recoverOldIssues() { Log.d(TAG, "Attempting to recover old feeback for the benefit of the user."); FileInputStream oldCacheFile = null; try { // Load the old data from a file oldCacheFile = context.openFileInput(OLD_ISSUES_CACHE_FILE); final String oldIssuesWithCommentsJSON = IOUtils.toString(oldCacheFile); // Parse the Data - The old json save contained IssuesWithComments final IssuesWithComments oldIssues = new IssueParser(TAG).parseIssues(oldIssuesWithCommentsJSON); // Save the data in the new database. for (Issue issue : oldIssues.issues()) { addCreatedIssue(issue); } } catch (FileNotFoundException e) { Log.i( TAG, "There was no old version of the issues cache lying around. Don't need to recover anything."); } catch (IOException e) { Log.i(TAG, "Encountered problems handling the old cache file", e); } finally { if (oldCacheFile != null) { try { oldCacheFile.close(); oldCacheFile = null; } catch (IOException e) { Log.wtf(TAG, "Could not close a file that we already had opened.", e); } // Remove the file now that we are done with it. context.deleteFile(OLD_ISSUES_CACHE_FILE); } } }
public void updateUsingIssuesWithComments(IssuesWithComments issuesWithComments) { SQLiteDatabase db = issuePersisterDatabase.getWritableDatabase(); if (db != null) { for (Issue issue : issuesWithComments.issues()) { String issueID = getIssueId(db, issue.getKey()); if (issueID == null) { saveIssue(db, issue); issueID = getIssueId(db, issue.getKey()); if (issueID == null) { Log.e( TAG, "Created an issue and it still did not exist after I created it. Aborting and reporting error."); // TODO Perform CONNECT-173 here } } if (issueID != null && issue.getComments() != null) { for (Comment comment : issue.getComments()) { if (!commentExists(db, comment)) saveComment(db, issueID, comment); } } } db.close(); } }