Esempio n. 1
0
  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();
    }
  }
Esempio n. 2
0
  /**
   * This persists a Comment in this Android App. It does no checking to make sure that the comment
   * has not been added before. It assumes that the given issueKey must belong to an {@link Issue}
   * that has already been persisted in this Android App via {@link
   * IssuePersister#addCreatedIssue(Issue)}.
   *
   * @param issueKey The issue that this comment will be persisted against.
   * @param comment The comment to be saved.
   */
  public void addCreatedComment(String issueKey, Comment comment) {
    SQLiteDatabase db = issuePersisterDatabase.getWritableDatabase();

    String issueID = getIssueId(db, issueKey);
    if (issueID != null) {
      saveComment(db, issueID, comment);
    } else {
      Log.e(
          TAG,
          "We could not find the issue for the key '"
              + issueKey
              + "' in the JMC Database. Regretfully ignoring the comment made on the issue.");
    }
    db.close();
  }
Esempio n. 3
0
 /**
  * This function adds an issue to persistent storage and also performs duplicate checking to make
  * sure that it does not overwrite anything.
  *
  * @param issue The issue that you wish to persist in this Android Application.
  */
 public void addCreatedIssue(Issue issue) {
   SQLiteDatabase db = issuePersisterDatabase.getWritableDatabase();
   if (issueKeyExists(db, issue.getKey())) {
     Log.i(
         TAG,
         "This issue has already been added to the local JMC Database before. Ignoring the addition of '"
             + issue.getKey()
             + "'.");
   } else {
     saveIssue(db, issue);
     List<Comment> issueComments = issue.getComments();
     if (issueComments != null) {
       String issueId = getIssueId(db, issue.getKey());
       for (Comment comment : issue.getComments()) {
         saveComment(db, issueId, comment);
       }
     }
   }
   if (db != null) db.close();
 }
Esempio n. 4
0
  public IssuesWithComments getIssues() {
    SQLiteDatabase db = issuePersisterDatabase.getReadableDatabase();
    String issuesQuery =
        "SELECT id, key, title, status, description, dateUpdated FROM "
            + IssuePersisterDatabase.ISSUES_TABLE_NAME;
    String commentQuery =
        "SELECT username, text, date, systemUser FROM issue_comments WHERE issue_id = ?";
    Cursor issueCursor = db.rawQuery(issuesQuery, new String[] {});

    List<Issue.Builder> issues = new ArrayList<Issue.Builder>();
    issueCursor.moveToFirst();
    DateFormat dateFormat = new SimpleDateFormat(dateFormatString, Locale.US);
    while (!issueCursor.isAfterLast()) {
      Issue.Builder issue = new Issue.Builder(issueCursor.getString(1));
      issue.title(issueCursor.getString(2));
      issue.status(issueCursor.getString(3));
      issue.description(issueCursor.getString(4));
      try {
        issue.dateUpdated(dateFormat.parse(issueCursor.getString(5)));
      } catch (ParseException e1) {
        // TODO Perform CONNECT-173 here
        issue.dateUpdated(new Date());
        Log.w(
            TAG,
            "Attempted to parse the issue date out of the database and failed. Setting to the current date.",
            e1);
        e1.printStackTrace();
      }
      Cursor commentCursor = db.rawQuery(commentQuery, new String[] {issueCursor.getString(0)});
      commentCursor.moveToFirst();
      while (!commentCursor.isAfterLast()) {
        try {
          final String commentUsername = commentCursor.getString(0);
          final String commentText = commentCursor.getString(1);
          final Date commentCreatedDate = dateFormat.parse(commentCursor.getString(2));
          final boolean isSystemUser = commentCursor.getInt(3) != 0;
          final Comment comment =
              new Comment(commentUsername, commentText, commentCreatedDate, isSystemUser);
          issue.addComment(comment);
        } catch (ParseException e) {
          // TODO Perform CONNECT-173 here
          Log.e(TAG, "Encountered a problem parsing an issue from the database.", e);
          e.printStackTrace();
        }
        commentCursor.moveToNext();
      }
      commentCursor.close();
      issues.add(issue);
      issueCursor.moveToNext();
    }

    if (issueCursor != null) issueCursor.close();

    if (db != null) db.close();

    return new IssuesWithComments(
        Lists.transform(
            issues,
            new Function<Issue.Builder, Issue>() {
              @Override
              public Issue apply(Builder issueBuilder) {
                return issueBuilder.build();
              }
            }),
        System.currentTimeMillis());
  }