Android Open Source - unicef_gis_mobile Couch Db Lite Store Adapter






From Project

Back to project page unicef_gis_mobile.

License

The source code is released under:

MIT License

If you think the Android project unicef_gis_mobile 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 org.unicef.gis.infrastructure.data;
/*from  w w w  .j ava  2 s  .  c  om*/
import java.io.IOException;
import java.util.List;

import org.ektorp.CouchDbConnector;
import org.ektorp.impl.StdCouchDbInstance;
import org.unicef.gis.model.Report;
import org.unicef.gis.model.couchdb.views.AllReportsByTimestampDesc;
import org.unicef.gis.model.couchdb.views.PendingSyncReports;
import org.unicef.gis.model.couchdb.views.UploadedReports;

import android.content.Context;
import android.location.Location;
import android.net.Uri;
import android.util.Log;

import com.couchbase.cblite.CBLDatabase;
import com.couchbase.cblite.CBLServer;
import com.couchbase.cblite.ektorp.CBLiteHttpClient;

public class CouchDbLiteStoreAdapter {
  public static final String TOUCH_DB_NAME = "unicef_gis_touch_db";
  private static final String DESIGN_DOC_NAME = "design_doc";
  
  private static CBLServer couchDbServer = null;
  private static CBLiteHttpClient couchDbClient = null;  
  
  private static StdCouchDbInstance couchDb = null;
  private static CBLDatabase db = null;
  
  private static CouchDbConnector conn;
  
  private static AllReportsByTimestampDesc allReports;
  private static PendingSyncReports pendingSyncReports;
  private static UploadedReports uploadedReports;
    
  public CouchDbLiteStoreAdapter(Context context) {
    if (couchDbServer == null) {
      String filesDir = context.getFilesDir().getAbsolutePath();
      try {
        couchDbServer = new CBLServer(filesDir);
        couchDbClient = new CBLiteHttpClient(couchDbServer);
        couchDb = new StdCouchDbInstance(couchDbClient);
        db = couchDbServer.getDatabaseNamed(TOUCH_DB_NAME, true);
        
        allReports = new AllReportsByTimestampDesc(db, DESIGN_DOC_NAME);
        pendingSyncReports = new PendingSyncReports(db, DESIGN_DOC_NAME);
        uploadedReports = new UploadedReports(db, DESIGN_DOC_NAME);
      } catch (IOException e) {
        Log.e("UnicefGisStore", "Error starting TDServer", e);
      }
    }
  }

  public void saveReport(Context context, String description,
      Location location, Uri imageUri, List<String> tags, boolean postToTwitter, boolean postToFacebook) {
    Report report = new Report(description, location, imageUri, tags);    
    report.setPostToFacebook(postToFacebook);
    report.setPostToTwitter(postToTwitter);
    
    ektorp().create(report);    
  }
  
  public void updateReport(Report report) {
    ektorp().update(report);
  }
  
  public void deleteReport(Report report) {
    ektorp().delete(report.getId(), report.getRevision());
  }

  public List<Report> getReports() {      
    return Report.collectionFromMap(allReports.query());
  }
  
  public List<Report> getPendingSyncReports() {    
    return Report.collectionFromMap(pendingSyncReports.query());
  }  
  
  public List<Report> getUploadedReports() {
    return Report.collectionFromMap(uploadedReports.query());
  }
  
  private CouchDbConnector ektorp() {
    if (conn == null)
      conn = couchDb.createConnector(TOUCH_DB_NAME, true);
    
    return conn;
  }
}




Java Source Code List

com.couchbase.cblite.ektorp.CBLiteHttpClient.java
com.couchbase.cblite.ektorp.CBLiteHttpResponse.java
edu.mit.mobile.android.utils.StreamUtils.java
org.unicef.gis.auth.AuthenticatorService.java
org.unicef.gis.auth.Authenticator.java
org.unicef.gis.infrastructure.CompileTimeSettings.java
org.unicef.gis.infrastructure.ILocationServiceConsumer.java
org.unicef.gis.infrastructure.LocationService.java
org.unicef.gis.infrastructure.Network.java
org.unicef.gis.infrastructure.Notificator.java
org.unicef.gis.infrastructure.RoutesResolver.java
org.unicef.gis.infrastructure.ServerUrlPreferenceNotSetException.java
org.unicef.gis.infrastructure.UnicefGisApi.java
org.unicef.gis.infrastructure.data.CouchDbLiteStoreAdapter.java
org.unicef.gis.infrastructure.data.UnicefGisContentProvider.java
org.unicef.gis.infrastructure.data.UnicefGisStore.java
org.unicef.gis.infrastructure.image.AsyncDrawable.java
org.unicef.gis.infrastructure.image.BitmapWorkerTask.java
org.unicef.gis.infrastructure.image.Camera.java
org.unicef.gis.model.Report.java
org.unicef.gis.model.Tag.java
org.unicef.gis.model.couchdb.NullReduce.java
org.unicef.gis.model.couchdb.ReportLoader.java
org.unicef.gis.model.couchdb.views.AllReportsByTimestampDesc.java
org.unicef.gis.model.couchdb.views.PendingSyncReports.java
org.unicef.gis.model.couchdb.views.UnicefGisView.java
org.unicef.gis.model.couchdb.views.UploadedReports.java
org.unicef.gis.sync.SyncAdapter.java
org.unicef.gis.sync.SyncService.java
org.unicef.gis.ui.AlertDialogFragment.java
org.unicef.gis.ui.AuthenticatorActivity.java
org.unicef.gis.ui.ConfigureServerUrlActivity.java
org.unicef.gis.ui.DeleteUploadedReportsTask.java
org.unicef.gis.ui.FetchTagsActivity.java
org.unicef.gis.ui.FetchTagsTask.java
org.unicef.gis.ui.MyReportsActivity.java
org.unicef.gis.ui.SettingsActivity.java
org.unicef.gis.ui.SettingsFragment.java
org.unicef.gis.ui.report.ChooseTagsFragment.java
org.unicef.gis.ui.report.CreateReportActivityConstants.java
org.unicef.gis.ui.report.CreateReportActivity.java
org.unicef.gis.ui.report.GetTagsTaskFragment.java
org.unicef.gis.ui.report.GetTagsTask.java
org.unicef.gis.ui.report.IChooseTagsCallbacks.java
org.unicef.gis.ui.report.IGetTagsCallback.java
org.unicef.gis.ui.report.IGetTagsTaskFragmentCallbacks.java
org.unicef.gis.ui.report.IReportSummaryCallbacks.java
org.unicef.gis.ui.report.ReportRowAdapter.java
org.unicef.gis.ui.report.ReportSummaryFragment.java
org.unicef.gis.ui.report.ReportViewModel.java
org.unicef.gis.ui.report.ToggleTagAdapter.java