public void testDisplayAllChildren() throws JSONException {
   ChildRepository repository =
       RapidFtrApplication.getInstance().getInjector().getInstance(ChildRepository.class);
   repository.createOrUpdate(new Child("id1", "rapidftr", "{\"name\":\"Test1\"}"));
   repository.createOrUpdate(new Child("id2", "rapidftr", "{\"name\":\"Test2\"}"));
   assertTrue(viewAllChildrenPage.isChildPresent("id1", "Test1"));
   assertTrue(viewAllChildrenPage.isChildPresent("id2", "Test2"));
 }
  public void testClickOnChildShouldShowViewPage() throws JSONException {
    ChildRepository repository =
        RapidFtrApplication.getInstance().getInjector().getInstance(ChildRepository.class);
    Child child1 = new Child("id1", "rapidftr", "{\"name\":\"Test1\"}");
    repository.createOrUpdate(child1);
    Child child2 = new Child("id2", "rapidftr", "{\"name\":\"Test2\"}");
    repository.createOrUpdate(child2);

    viewAllChildrenPage.clickChild("id1");
    viewAllChildrenPage.verifyChildDetails(child1);
  }
 public void testClickOnChildShouldShowViewPage() throws JSONException {
   ChildRepository repository =
       RapidFtrApplication.getApplicationInstance()
           .getInjector()
           .getInstance(ChildRepository.class);
   Child child1 = new Child(getAlphaNumeric(4), "rapidftr", "{\"name\":\"Test1\"}");
   repository.createOrUpdate(child1);
   Child child2 = new Child(getAlphaNumeric(6), "rapidftr", "{\"name\":\"Test2\"}");
   repository.createOrUpdate(child2);
   viewAllChildrenPage.navigateToViewAllPage();
   viewAllChildrenPage.clickChild(child1.getUniqueId());
   viewAllChildrenPage.verifyChildDetails(child1);
 }
 private void saveIncomingChildren(ArrayList<String> idsToDownload)
     throws IOException, JSONException {
   for (String idToDownload : idsToDownload) {
     Child incomingChild = childService.getChild(idToDownload);
     if (isCancelled()) {
       break;
     }
     try {
       incomingChild.setSynced(true);
       if (childRepository.exists(incomingChild.getUniqueId())) {
         childRepository.update(incomingChild);
       } else {
         childRepository.createOrUpdate(incomingChild);
       }
       childService.setPhoto(incomingChild);
     } catch (Exception e) {
       Log.e("SyncAllDataTask", "Error syncing child", e);
       throw new RuntimeException(e);
     }
   }
 }
 public ArrayList<String> getAllIdsForDownload() throws IOException, JSONException {
   HashMap<String, String> serverIdsRevs = childService.getAllIdsAndRevs();
   HashMap<String, String> repoIdsAndRevs = childRepository.getAllIdsAndRevs();
   ArrayList<String> idsToDownload = new ArrayList<String>();
   for (Map.Entry<String, String> serverIdRev : serverIdsRevs.entrySet()) {
     if (!isServerIdExistingInRepository(repoIdsAndRevs, serverIdRev)
         || (repoIdsAndRevs.get(serverIdRev.getKey()) != null
             && isRevisionMismatch(repoIdsAndRevs, serverIdRev))) {
       idsToDownload.add(serverIdRev.getKey());
     }
   }
   return idsToDownload;
 }
Ejemplo n.º 6
0
 public void sync(Child child) throws IOException, JSONException {
   child.setSynced(true);
   fluentRequest
       .path(String.format("/children/%s", child.getUniqueId()))
       .context(context)
       .param("child", child.toString());
   if (child.opt("current_photo_key") != null
       && !child.optString("current_photo_key").equals("")) {
     fluentRequest.param("current_photo_key", child.optString("current_photo_key"));
   }
   fluentRequest.put();
   repository.update(child);
 }
Ejemplo n.º 7
0
 public List<Child> searchChildrenInDB(String subString) {
   List<Child> filteredList = new ArrayList<Child>();
   try {
     for (Child child : repository.getAllChildren()) {
       try {
         if (containsIgnoreCase(child.getUniqueId(), subString)
             || containsIgnoreCase((String) child.get("name"), subString)) {
           filteredList.add(child);
         }
       } catch (JSONException e) {
         Log.e("ChildService", "Error while Searching Children");
       }
     }
   } catch (JSONException e) {
     Log.e("ChildService", "Error while Searching Children");
   }
   return filteredList;
 }
 @Override
 protected Boolean doInBackground(Void... notRelevant) {
   try {
     if (!isCancelled()) {
       setProgressAndNotify("Step 1 of 3 - Syncing Form Sections...", 0);
       formService.getPublishedFormSections();
     }
     ArrayList<String> idsToDownload = getAllIdsForDownload();
     setProgressAndNotify("Step 2 of 3 - Sending records to server...", 10);
     List<Child> childrenToSyncWithServer = childRepository.toBeSynced();
     sendChildrenToServer(childrenToSyncWithServer);
     setProgressAndNotify("Step 3 of 3 - Bringing down records from server...", 20);
     saveIncomingChildren(idsToDownload);
     setProgressAndNotify("Sync complete.", 30);
   } catch (Exception e) {
     Log.e("SyncAllDataTask", "Error in sync", e);
     publishProgress("Error in syncing. Try again after some time.");
     return false;
   }
   return true;
 }