Android Open Source - nl.fhict.intellicloud.answers.android Review Data Source






From Project

Back to project page nl.fhict.intellicloud.answers.android.

License

The source code is released under:

Apache License

If you think the Android project nl.fhict.intellicloud.answers.android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package nl.fhict.intellicloud.answers.backendcommunication;
//from w ww.  ja  v a2 s.c  o  m
import java.util.ArrayList;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

import nl.fhict.intellicloud.answers.Answer;
import nl.fhict.intellicloud.answers.Review;
import nl.fhict.intellicloud.answers.ReviewState;
import nl.fhict.intellicloud.answers.User;
import nl.fhict.intellicloud.answers.UserType;
import nl.fhict.intellicloud.answers.backendcommunication.IntellicloudDbContract.*;


public class ReviewDataSource implements IReviewService {
  private SQLiteDatabase database;
  private LocalStorageSQLiteHelper dbHelper;
  private final String[] allColumns = { ReviewsEntry.COLUMN_ID, 
                    ReviewsEntry.COLUMN_BACKEND_ID,
                    ReviewsEntry.COLUMN_REVIEW,
                    ReviewsEntry.COLUMN_REVIEWER_ID,
                    ReviewsEntry.COLUMN_REVIEWSTATE,
                    ReviewsEntry.COLUMN_ANSWER_ID
                    };
  private IAnswerService answerDataSource;
                      
  
  
  public ReviewDataSource(Context context) {
    dbHelper = new LocalStorageSQLiteHelper(context);
    answerDataSource = new AnswerDataSource(context);
  }
  
  private void open() throws SQLException {
    database = dbHelper.getWritableDatabase();
  }
  
  private void close() {
    dbHelper.close();
  }
  @Override
  public void CreateReview(Review review) {
    ContentValues values = new ContentValues();
      
    values.put(ReviewsEntry.COLUMN_REVIEW, review.getReview());
    values.put(ReviewsEntry.COLUMN_REVIEWER_ID, review.getReviewer().getId());
    values.put(ReviewsEntry.COLUMN_REVIEWSTATE, review.getReviewState().toString());
    values.put(ReviewsEntry.COLUMN_ANSWER_ID, review.getAnswer().getId());
      
    open();
    database.insert(ReviewsEntry.TABLE_NAME, null, values);
    close();
      

  }

  @Override
  public ArrayList<Review> GetReviews(int answerId) {
    String answerFilter = null;
    ArrayList<Review> filteredReviews = new ArrayList<Review>();
    
    answerFilter = ReviewsEntry.COLUMN_ANSWER_ID + " = " + answerId;
        
    
    open();
    Cursor cursor = database.query(ReviewsEntry.TABLE_NAME, allColumns, answerFilter, null, null, null, null);
    cursor.moveToFirst();
    
    while (!cursor.isAfterLast()) {
      Review review = getNextReviewFromCursor(cursor);
      filteredReviews.add(review);
      
      cursor.moveToNext();
    }
    cursor.close();
    close();
    return filteredReviews;
  }

  @Override
  public void UpdateReview(Review review) {
    ContentValues values = new ContentValues();
    values.put(ReviewsEntry.COLUMN_REVIEWSTATE, review.getReviewState().toString());
  
    open();
    database.update(ReviewsEntry.TABLE_NAME, values, ReviewsEntry.COLUMN_BACKEND_ID + " = " + review.getId(), null);
    close();

  }
  
  private Review getNextReviewFromCursor(Cursor cursor)
  {
    User reviewer = UserDataSource.GetUser(cursor.getInt(3), database);
    ReviewState state = ReviewState.valueOf(cursor.getString(4));
    Answer answerForReview = answerDataSource.GetAnswer(cursor.getInt(5));
    
    Review review = new Review(
                cursor.getString(2),
                answerForReview,
                reviewer,
                state);
    review.setId(cursor.getInt(1));
                
    return review;      
                
        
  }
  

}




Java Source Code List

nl.fhict.intellicloud.answers.AddReviewActivity.java
nl.fhict.intellicloud.answers.AnswerState.java
nl.fhict.intellicloud.answers.Answer.java
nl.fhict.intellicloud.answers.AuthorizationActivity.java
nl.fhict.intellicloud.answers.FeedbackState.java
nl.fhict.intellicloud.answers.FeedbackType.java
nl.fhict.intellicloud.answers.Feedback.java
nl.fhict.intellicloud.answers.FilterList.java
nl.fhict.intellicloud.answers.GetUserIdTask.java
nl.fhict.intellicloud.answers.IUserFoundObserver.java
nl.fhict.intellicloud.answers.IncomingQuestionsListAdapter.java
nl.fhict.intellicloud.answers.ListFragment.java
nl.fhict.intellicloud.answers.MainActivity.java
nl.fhict.intellicloud.answers.OriginalAnswerActivity.java
nl.fhict.intellicloud.answers.QuestionListOnClickListener.java
nl.fhict.intellicloud.answers.QuestionState.java
nl.fhict.intellicloud.answers.Question.java
nl.fhict.intellicloud.answers.RejectedAnswerActivity.java
nl.fhict.intellicloud.answers.ReviewListAdapter.java
nl.fhict.intellicloud.answers.ReviewOverviewActivity.java
nl.fhict.intellicloud.answers.ReviewState.java
nl.fhict.intellicloud.answers.Review.java
nl.fhict.intellicloud.answers.SendAnswerActivity.java
nl.fhict.intellicloud.answers.SlidingMenuListAdapter.java
nl.fhict.intellicloud.answers.UserType.java
nl.fhict.intellicloud.answers.User.java
nl.fhict.intellicloud.answers.backendcommunication.AnswerDataSource.java
nl.fhict.intellicloud.answers.backendcommunication.AnswerSync.java
nl.fhict.intellicloud.answers.backendcommunication.AuthenticatorService.java
nl.fhict.intellicloud.answers.backendcommunication.Authenticator.java
nl.fhict.intellicloud.answers.backendcommunication.BackendContentProvider.java
nl.fhict.intellicloud.answers.backendcommunication.BackendSyncAdapter.java
nl.fhict.intellicloud.answers.backendcommunication.BackendSyncService.java
nl.fhict.intellicloud.answers.backendcommunication.DummyBackend.java
nl.fhict.intellicloud.answers.backendcommunication.IAnswerService.java
nl.fhict.intellicloud.answers.backendcommunication.IClaimService.java
nl.fhict.intellicloud.answers.backendcommunication.IQuestionService.java
nl.fhict.intellicloud.answers.backendcommunication.IReviewService.java
nl.fhict.intellicloud.answers.backendcommunication.IUserService.java
nl.fhict.intellicloud.answers.backendcommunication.IntellicloudDbContract.java
nl.fhict.intellicloud.answers.backendcommunication.LocalStorageSQLiteHelper.java
nl.fhict.intellicloud.answers.backendcommunication.QuestionDataSource.java
nl.fhict.intellicloud.answers.backendcommunication.QuestionsSync.java
nl.fhict.intellicloud.answers.backendcommunication.ReviewDataSource.java
nl.fhict.intellicloud.answers.backendcommunication.ReviewSync.java
nl.fhict.intellicloud.answers.backendcommunication.ServerAccessor.java
nl.fhict.intellicloud.answers.backendcommunication.SyncHelper.java
nl.fhict.intellicloud.answers.backendcommunication.UserDataSource.java
nl.fhict.intellicloud.answers.backendcommunication.UserSync.java
nl.fhict.intellicloud.answers.backendcommunication.oauth.AuthenticationManager.java