Exemple #1
0
 /**
  * @return this method returns an array which contains LocalId and Google Id.
  *     <p>It is used to know which localIds are already synced and hence have a GoogleId and which
  *     all are new localIds.
  */
 private long[][] getIdMapMatrix() {
   Uri idmapUri = Uri.parse(CloudSyncContentProvider.IDMAPS_CONTENT_URI.toString());
   Cursor idMapCursor =
       context
           .getContentResolver()
           .query(
               idmapUri,
               null,
               IdMapTable.PACKAGE_NAME + "=?",
               new String[] {NotepadSync.PACKAGE_NAME},
               null);
   long[][] idMapMatrix = null;
   if (debug) Log.d(TAG, "Going to make an Id map matrix");
   idMapMatrix = new long[idMapCursor.getCount()][2];
   idMapCursor.moveToFirst();
   for (int i = 0; i < idMapMatrix.length; i++) {
     idMapMatrix[i][ID_MAP_MATRIX_LOCAL_ID] = Long.valueOf(idMapCursor.getString(1));
     idMapMatrix[i][ID_MAP_MATRIX_GOOGLE_ID] = Long.valueOf(idMapCursor.getString(2));
     idMapCursor.moveToNext();
     if (debug) Log.d(TAG, "idmap local n google" + idMapMatrix[i][0] + " " + idMapMatrix[i][1]);
   }
   if (debug) Log.d(TAG, "length of the idmapmatrix is " + idMapMatrix.length);
   idMapCursor.close();
   return idMapMatrix;
 }
Exemple #2
0
  /**
   * This method takes a list of localIds and then gets a corresponding JSON data string. Uploads
   * that JSON data string along with Package Name and TimeStamp of this Sync.
   *
   * @param insertList This contains a list of localIDs.
   */
  private void insetNewNotes(LinkedList<Long> insertList) {

    // ------------------------------------------------------------------------------------
    //             Inserting the newly Created Notes into AppEngine
    // ------------------------------------------------------------------------------------

    // Persisting the new Notes on the Server
    OICloudSyncRequestFactory factory =
        Util.getRequestFactory(context, OICloudSyncRequestFactory.class);
    OICloudSyncRequest request = factory.taskRequest();
    if (insertList.size() == 0) {
      return;
    }
    if (insertList.size() > 0) {
      TaskProxy[] task = new TaskProxy[insertList.size()];
      if (debug) Log.d(TAG, "[main] made the taskproxy array");
      for (int i = 0; i < insertList.size(); i++) {
        task[i] = request.create(TaskProxy.class);
        String tempJString = SyncUtil.getJsonFromRDarray(insertList.get(i), rdArray);
        task[i].setJsonStringData(tempJString);
        task[i].setAppPackageName(NotepadSync.PACKAGE_NAME);
        task[i].setTimestamp(timeofThisSync);
        request.updateTask(task[i]);
      }
      request.fire();
    }

    // Going to update the IdMapTable with the GoogleIds of New notes which
    // were persisted on the server.
    // First fetch all the data with same timeStamp as timeOfThisSync
    // This will return the notes that were just now updated.
    final List<TaskProxy> listExact = new ArrayList<TaskProxy>();
    if (debug)
      Log.d(
          TAG,
          "going to do the query of newly created tasks to update the idMapTable with exact time: "
              + timeofThisSync);
    factory
        .taskRequest()
        .queryExactTimeStamp(NotepadSync.PACKAGE_NAME, timeofThisSync)
        .fire(
            new Receiver<List<TaskProxy>>() {
              @Override
              public void onSuccess(List<TaskProxy> arg0) {
                listExact.addAll(arg0);
                if (debug) Log.d(TAG, "[updateIdMapTable] Size of list" + listExact.size());
              }
            });

    int il = listExact.size();
    if (il == 0) {
      if (debug) Log.d(TAG, "size of taskList returned from server is 0");
    }

    // This saves the GoogleIds of the newly persisted notes into the idMap table.

    else {
      for (TaskProxy task : listExact) {
        String jsonString = task.getJsonStringData();
        long googleId = task.getId();
        long localId = SyncUtil.getIdFromRDarray(jsonString, rdArray);
        Uri idmapUri = Uri.parse(CloudSyncContentProvider.IDMAPS_CONTENT_URI.toString());
        ContentValues values = new ContentValues();
        values.put(IdMapTable.COLUMN_APPENG_ID, googleId);
        values.put(IdMapTable.COLUMN_LOCAL_ID, localId);
        values.put(IdMapTable.PACKAGE_NAME, NotepadSync.PACKAGE_NAME);
        Uri insertedUri = context.getContentResolver().insert(idmapUri, values);
        if (debug) Log.d(TAG, insertedUri.toString());
      }
    }
  }