Skip to content

Commit

Permalink
Update sync process
Browse files Browse the repository at this point in the history
Signed-off-by: Ephraim Muhia <emuhia@ona.io>
  • Loading branch information
Ephraim Muhia committed Feb 9, 2018
1 parent 581ce8c commit faba94c
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,6 @@ private void updateConfiguration(Configuration config) {
private static String[] getFtsSearchFields(String tableName) {
if (tableName.equals(PathConstants.CHILD_TABLE_NAME)) {
return new String[]{"zeir_id", "epi_card_number", "first_name", "last_name"};
} else if (tableName.equals(PathConstants.MOTHER_TABLE_NAME)) {
return new String[]{"zeir_id", "epi_card_number", "first_name", "last_name", "father_name", "husband_name", "contact_phone_number"};
}
return null;
}
Expand All @@ -196,14 +194,12 @@ private static String[] getFtsSortFields(String tableName) {
}

return names.toArray(new String[names.size()]);
} else if (tableName.equals(PathConstants.MOTHER_TABLE_NAME)) {
return new String[]{"first_name", "dob", "zeir_id", "last_interacted_with"};
}
return null;
}

private static String[] getFtsTables() {
return new String[]{PathConstants.CHILD_TABLE_NAME, PathConstants.MOTHER_TABLE_NAME};
return new String[]{PathConstants.CHILD_TABLE_NAME};
}

private static Map<String, Pair<String, Boolean>> getAlertScheduleMap() {
Expand Down Expand Up @@ -394,6 +390,10 @@ public void setLastModified(boolean lastModified) {
this.lastModified = lastModified;
}

public static CommonFtsObject getCommonFtsObject() {
return commonFtsObject;
}

@Override
public void onTimeChanged() {
Toast.makeText(this, R.string.device_time_changed, Toast.LENGTH_LONG).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,13 @@ public void getView(Cursor cursor, SmartRegisterClient client, final View conver
String lostToFollowUp = getValue(pc.getColumnmaps(), PathConstants.KEY.LOST_TO_FOLLOW_UP, false);
String inactive = getValue(pc.getColumnmaps(), PathConstants.KEY.INACTIVE, false);

try {
Utils.startAsyncTask(new WeightAsyncTask(convertView, pc.entityId(), lostToFollowUp, inactive, client, cursor), null);
Utils.startAsyncTask(new VaccinationAsyncTask(convertView, pc.entityId(), dobString, lostToFollowUp, inactive, client, cursor), null);
} catch (Exception e) {
Log.e(getClass().getName(), e.getMessage(), e);
if (!SyncStatusBroadcastReceiver.getInstance().isSyncing()) {
try {
Utils.startAsyncTask(new WeightAsyncTask(convertView, pc.entityId(), lostToFollowUp, inactive, client, cursor), null);
Utils.startAsyncTask(new VaccinationAsyncTask(convertView, pc.entityId(), dobString, lostToFollowUp, inactive, client, cursor), null);
} catch (Exception e) {
Log.e(getClass().getName(), e.getMessage(), e);
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
import org.joda.time.DateTime;
import org.smartregister.domain.FetchStatus;
import org.smartregister.path.application.VaccinatorApplication;
import org.smartregister.path.service.intent.ClientProcessorIntentService;
import org.smartregister.path.service.intent.ExtendedSyncIntentService;
import org.smartregister.sync.DrishtiSyncScheduler;

import java.io.Serializable;
import java.util.ArrayList;

import util.ServiceTools;

import static org.smartregister.util.Log.logError;

/**
Expand Down Expand Up @@ -88,7 +91,7 @@ public void onReceive(Context context, Intent intent) {
started();
} else {
boolean isComplete = data.getBoolean(EXTRA_COMPLETE_STATUS);
if (isComplete) {
if (isComplete && !ServiceTools.isServiceRunning(ClientProcessorIntentService.class)) {
complete(fetchStatus);
startExtendedSyncAndAlarms(context);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,10 @@ private void processClient(long start, long end) {
try {
final ECSyncUpdater ecUpdater = ECSyncUpdater.getInstance(context);
List<JSONObject> events = ecUpdater.allEvents(start, end);
for (int i = 0; i < events.size(); i++) {
fetchAndInsertClient(events.get(i));
}

PathClientProcessor.getInstance(context).processClient(events);
} catch (Exception e) {
Log.e(getClass().getName(), "Process Client Exception: " + e.getMessage(), e);
}

}

private void fetchAndInsertClient(JSONObject event) {
final String BASE_ENTITY_ID = "baseEntityId";
final String CLIENT = "client";
try {
if (!event.has(CLIENT) && event.has(BASE_ENTITY_ID)) {
String baseEntityId = event.getString(BASE_ENTITY_ID);
JSONObject client = fetchClientRetry(baseEntityId);
if (client != null) {
event.put(CLIENT, client);
}
}
} catch (JSONException e) {
Log.e(getClass().getName(), "Fetch Client Exception: " + e.getMessage(), e.getCause());
}
}

private JSONObject fetchClientRetry(String baseEntityId) {
Expand Down

0 comments on commit faba94c

Please sign in to comment.