Example #1
0
  private long getTimeFromServer() {

    final List<Long> tempArray = new ArrayList<Long>();
    // using this temparray as i dont know how use only long and value out.
    OICloudSyncRequestFactory timeFactory =
        Util.getRequestFactory(context, OICloudSyncRequestFactory.class);
    timeFactory
        .taskRequest()
        .getAppEngineTime()
        .fire(
            new Receiver<Long>() {

              @Override
              public void onSuccess(Long time) {
                if (debug) Log.d(TAG, "long time of this sync:_> " + time.toString());
                tempArray.add(time);
                if (debug) Log.d(TAG, "time from server:-> " + time.toString());
                // new calendar inside the appEngine doesnot work
                // use new Date() or System.getmilliseconds
                // if (debug) Log.d(TAG, "time of this sync: "+tempArray.get(0));
              }

              @Override
              public void onFailure(ServerFailure error) {
                if (debug) Log.d(TAG, "[main] it has failed");
                super.onFailure(error);
              }
            });

    timeofThisSync = tempArray.get(0);
    return timeofThisSync;
  }
Example #2
0
  /**
   * This takes a list of localIds and from them gets list of GoogleIds. Using them it gets the
   * Entities from the cloud. In those Entities it puts the Tag='D'. And then persists them again to
   * the AppEngine. With updated time and package Name.
   *
   * @param deleteList
   */
  private void deleteNotes(LinkedList<Long> deleteList) {
    if (deleteList.size() == 0) {
      return;
    }
    List<Long> gIdList = new ArrayList<Long>();
    for (Long localId : deleteList) {
      long googleId =
          SyncUtil.mapTheMatrix(
              idMapMatrix,
              idMapMatrix.length,
              localId,
              ID_MAP_MATRIX_LOCAL_ID,
              ID_MAP_MATRIX_GOOGLE_ID); // getGoogleIdFromMapMatrix(localId, idMapMatrix);
      gIdList.add(googleId);
    }

    final List<TaskProxy> list = new ArrayList<TaskProxy>();
    OICloudSyncRequestFactory factory =
        Util.getRequestFactory(context, OICloudSyncRequestFactory.class);
    OICloudSyncRequest request1 = factory.taskRequest();

    request1
        .queryGoogleIdList(NotepadSync.PACKAGE_NAME, gIdList)
        .fire(
            new Receiver<List<TaskProxy>>() {

              @Override
              public void onSuccess(List<TaskProxy> arg0) {

                list.addAll(arg0);
                if (debug)
                  Log.d(TAG, "Delete Size of list to be deleted from Engine: " + list.size());
              }
            });

    int il = list.size();
    Ulg.d("[asyncsync] Size of list to be del tagged: " + il);
    // the above returned beans are frozen
    // check the blog
    // http://fascynacja.wordpress.com/tag/autobean-has-been-frozen/
    // for more details

    OICloudSyncRequest request = factory.taskRequest();

    // creating an array.
    TaskProxy[] task = new TaskProxy[list.size()];
    for (int i = 0; i < list.size(); i++) {

      task[i] = request.edit(list.get(i));
      task[i].setTag('D');
      task[i].setAppPackageName(NotepadSync.PACKAGE_NAME);
      task[i].setTimestamp(timeofThisSync);
      request.updateTask(task[i]);
    }
    request.fire();
    // updated the Google App Engine with new Entities.

  }
Example #3
0
  private List<TaskProxy> fetchAllFromServer(long timeOfLastSync) {
    final List<TaskProxy> list = new ArrayList<TaskProxy>();
    OICloudSyncRequestFactory factory =
        Util.getRequestFactory(context, OICloudSyncRequestFactory.class);
    if (debug)
      Log.d(
          TAG,
          "[main] going to do the query of tasks with package name param, and timestamp greate than: "
              + timeOfLastSync);
    factory
        .taskRequest()
        .queryTasks(NotepadSync.PACKAGE_NAME, timeOfLastSync)
        .fire(
            new Receiver<List<TaskProxy>>() {

              @Override
              public void onSuccess(List<TaskProxy> arg0) {
                list.addAll(arg0);
                if (debug) Log.d(TAG, "Size of list" + list.size());
              }
            });
    return list;
  }
Example #4
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());
      }
    }
  }
Example #5
0
  private void updateChangedNotes(LinkedList<Long> updateList) {
    // Make the List<Long> of AppEngineIds
    if (updateList.size() == 0) {
      return;
    }
    List<Long> gIdList = new ArrayList<Long>();
    for (Long localId : updateList) {
      long googleId =
          SyncUtil.mapTheMatrix(
              idMapMatrix,
              idMapMatrix.length,
              localId,
              ID_MAP_MATRIX_LOCAL_ID,
              ID_MAP_MATRIX_GOOGLE_ID); // getGoogleIdFromMapMatrix(localId, idMapMatrix);
      gIdList.add(googleId);
    }

    final List<TaskProxy> list = new ArrayList<TaskProxy>();
    OICloudSyncRequestFactory factory =
        Util.getRequestFactory(context, OICloudSyncRequestFactory.class);
    OICloudSyncRequest request1 = factory.taskRequest();
    if (debug)
      Log.d(
          TAG,
          "[updateEntitiesInGoogleAppEngine] going to do the query for modification on AppEngine with this list: "
              + gIdList.toString());
    // if the list size of updateList is 0 there is nothing to be updated
    // just return
    request1
        .queryGoogleIdList(NotepadSync.PACKAGE_NAME, gIdList)
        .fire(
            new Receiver<List<TaskProxy>>() {

              @Override
              public void onSuccess(List<TaskProxy> arg0) {

                list.addAll(arg0);
                if (debug)
                  Log.d(
                      TAG,
                      "[updateEntitiesInGoogleAppEngine] Size of list to be modified returned from Engine: "
                          + list.size());
              }
            });

    int il = list.size();

    // the above returned beans are frozen
    // check the blog
    // http://fascynacja.wordpress.com/tag/autobean-has-been-frozen/
    // for more details

    OICloudSyncRequest request = factory.taskRequest();

    // creating an array.
    TaskProxy[] task = new TaskProxy[list.size()];
    for (int i = 0; i < list.size(); i++) {

      task[i] = request.edit(list.get(i));
      long gId = list.get(i).getId();
      long localId =
          SyncUtil.mapTheMatrix(
              idMapMatrix,
              idMapMatrix.length,
              gId,
              ID_MAP_MATRIX_GOOGLE_ID,
              ID_MAP_MATRIX_LOCAL_ID); // getLocalIdFromMapMatrix(gId, idMapMatrix);
      String jsonString = SyncUtil.getJsonFromRDarray(localId, rdArray);
      if (debug)
        Log.d(
            TAG,
            "[updateEntitiesInGoogleAppEngine] json data for Gid: " + gId + " ; " + jsonString);
      task[i].setJsonStringData(jsonString);
      task[i].setAppPackageName(NotepadSync.PACKAGE_NAME);
      task[i].setTimestamp(timeofThisSync);
      request.updateTask(task[i]);
    }
    request.fire();
    // updated the Google App Engine with new Entities.

  }