Android Open Source - unicef_gis_mobile Pending Sync Reports

From Project

Back to project page unicef_gis_mobile.


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.model.couchdb.views;
/*from  www.  ja*/
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.unicef.gis.model.Report;

import android.annotation.SuppressLint;
import com.couchbase.cblite.CBLDatabase;
import com.couchbase.cblite.CBLQueryOptions;
import com.couchbase.cblite.CBLStatus;
import com.couchbase.cblite.CBLViewMapBlock;
import com.couchbase.cblite.CBLViewMapEmitBlock;

public class PendingSyncReports extends UnicefGisView {
  private static final String VIEW_NAME = "pendingSyncReports";
  private static final String VIEW_VERSION = "2.0";
  public PendingSyncReports(CBLDatabase db, String designDoc) {
    super(db, designDoc);
  protected String getViewName() {
    return VIEW_NAME;
  protected String getViewVersion() {
    return VIEW_VERSION;
  protected CBLViewMapBlock getViewMapBlock() {
    return new CBLViewMapBlock() {      
      public void map(Map<String, Object> doc, CBLViewMapEmitBlock emitter) {
        if (isReport(doc)){
          Report r = Report.fromMap(doc);
          String viewKey = paddedAttempts(r) + "-" + r.getTimestamp(); 
          if (!r.getSyncedData() || !r.getSyncedImage())          
            emitter.emit(viewKey, doc);

  public List<Map<String, Object>> query() {
    CBLQueryOptions options = new CBLQueryOptions();    
    CBLStatus status = new CBLStatus();
    return view.queryWithOptions(options, status);

  private String paddedAttempts(Report r) {
    return String.format(Locale.ENGLISH, "%06d", r.getAttempts());

Java Source Code List