Skip to content

Commit

Permalink
#1607 - Unverified users should be able to download children modified…
Browse files Browse the repository at this point in the history
… from server
  • Loading branch information
Suganthi T committed Feb 28, 2013
1 parent 57d9d9f commit e2ba69b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ public List<Child> getChildrenByOwner() throws JSONException {
return toChildren(cursor);
}

public ArrayList<String> getIdsChildrenByOwner() throws JSONException {
ArrayList<String> ids = new ArrayList<String>();
@Cleanup Cursor cursor = session.rawQuery("SELECT _id FROM children WHERE child_owner = ? ", new String[]{userName});
while (cursor.moveToNext()){
ids.add(cursor.getString(0));
}
return ids;
}

public void deleteChildrenByOwner() throws JSONException {
session.execSQL("DELETE FROM children WHERE child_owner = '"+ userName +"';");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import static com.rapidftr.RapidFtrApplication.SERVER_URL_PREF;
Expand Down Expand Up @@ -59,13 +60,21 @@ protected void sync() throws JSONException, IOException, HttpException {
}
getFormSections();
sendChildrenToServer(childRepository.currentUsersUnsyncedRecords());
if(application.getCurrentUser().isVerified()) {
ArrayList<String> idsToDownload = getAllIdsForDownload();
List<Child> childrenToSyncWithServer = childRepository.toBeSynced();

if(!application.getCurrentUser().isVerified()) {
ArrayList<String> idsOfCurrentUser = childRepository.getIdsChildrenByOwner();
Iterator<String> idIterator = idsToDownload.iterator();
while (idIterator.hasNext()) {
String id = idIterator.next();
if(!idsOfCurrentUser.contains(id)) {
idIterator.remove();
}
}
}
int startProgressForDownloadingChildren = formSectionProgress + childrenToSyncWithServer.size();
saveIncomingChildren(idsToDownload, startProgressForDownloadingChildren);
}

setProgressAndNotify(context.getString(R.string.sync_complete), maxProgress);
}

Expand Down

0 comments on commit e2ba69b

Please sign in to comment.