-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Worker alternatives to sync intent services
- Loading branch information
Showing
44 changed files
with
1,753 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
opensrp-core/src/main/java/org/smartregister/domain/db/EventClientQueryResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.smartregister.domain.db; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import java.util.List; | ||
|
||
public class EventClientQueryResult { | ||
|
||
private List<EventClient> eventClientList; | ||
private int maxRowId; | ||
|
||
public EventClientQueryResult(int maxRowId, @NonNull List<EventClient> eventClients) { | ||
this.maxRowId = maxRowId; | ||
this.eventClientList = eventClients; | ||
} | ||
|
||
public List<EventClient> getEventClientList() { | ||
return eventClientList; | ||
} | ||
|
||
public void setEventClientList(List<EventClient> eventClientList) { | ||
this.eventClientList = eventClientList; | ||
} | ||
|
||
public int getMaxRowId() { | ||
return maxRowId; | ||
} | ||
|
||
public void setMaxRowId(int maxRowId) { | ||
this.maxRowId = maxRowId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
opensrp-core/src/main/java/org/smartregister/sync/RequestParamsBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package org.smartregister.sync; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
import org.smartregister.AllConstants; | ||
import org.smartregister.CoreLibrary; | ||
import org.smartregister.sync.intent.BaseSyncIntentService; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
import timber.log.Timber; | ||
|
||
/** | ||
* A helper class for building the url request for intent services | ||
*/ | ||
public class RequestParamsBuilder { | ||
|
||
private final Map<String, Object> paramMap; | ||
private final StringBuilder getSyncParamsBuilder; | ||
private final JSONObject postSyncParamsBuilder; | ||
|
||
public RequestParamsBuilder() { | ||
this.paramMap = new LinkedHashMap<>(); | ||
this.getSyncParamsBuilder = new StringBuilder(); | ||
this.postSyncParamsBuilder = new JSONObject(); | ||
} | ||
|
||
public RequestParamsBuilder addServerVersion(long value) { | ||
paramMap.put(AllConstants.SERVER_VERSION, value); | ||
return this; | ||
} | ||
|
||
public RequestParamsBuilder addEventPullLimit(int value) { | ||
paramMap.put(AllConstants.LIMIT, value); | ||
return this; | ||
} | ||
|
||
public RequestParamsBuilder configureSyncFilter(String syncFilterParam, String syncFilterValue) { | ||
paramMap.put(syncFilterParam, syncFilterValue); | ||
return this; | ||
} | ||
|
||
public RequestParamsBuilder returnCount(boolean value) { | ||
paramMap.put(AllConstants.RETURN_COUNT, value); | ||
return this; | ||
} | ||
|
||
public RequestParamsBuilder addParam(String key, Object value) { | ||
paramMap.put(key, value); | ||
return this; | ||
} | ||
|
||
public RequestParamsBuilder removeParam(String key) { | ||
paramMap.remove(key); | ||
return this; | ||
} | ||
|
||
public String build() { | ||
|
||
for (Map.Entry<String, Object> entry : paramMap.entrySet()) { | ||
|
||
if (CoreLibrary.getInstance().getSyncConfiguration().isSyncUsingPost()) { | ||
|
||
try { | ||
postSyncParamsBuilder.put(entry.getKey(), entry.getValue()); | ||
} catch (JSONException e) { | ||
Timber.e(e); | ||
} | ||
|
||
} else { | ||
|
||
if (0 != getSyncParamsBuilder.length()) { | ||
getSyncParamsBuilder.append('&'); | ||
} | ||
|
||
getSyncParamsBuilder.append(entry.getKey()).append('=').append(entry.getValue()); | ||
} | ||
|
||
} | ||
|
||
return CoreLibrary.getInstance().getSyncConfiguration().isSyncUsingPost() ? postSyncParamsBuilder.toString() : getSyncParamsBuilder.toString(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
package org.smartregister.sync.intent; | ||
|
||
import android.content.Intent; | ||
import androidx.annotation.NonNull; | ||
|
||
import androidx.annotation.Nullable; | ||
import androidx.annotation.VisibleForTesting; | ||
|
||
import org.smartregister.CoreLibrary; | ||
import org.smartregister.domain.FetchStatus; | ||
import org.smartregister.domain.db.EventClient; | ||
import org.smartregister.domain.db.EventClientQueryResult; | ||
import org.smartregister.repository.AllSharedPreferences; | ||
import org.smartregister.repository.EventClientRepository; | ||
import org.smartregister.util.Utils; | ||
|
@@ -21,6 +22,7 @@ | |
* Created by Ephraim Kigamba - [email protected] on 10/05/2019 | ||
*/ | ||
|
||
@Deprecated | ||
public class P2pProcessRecordsService extends BaseSyncIntentService { | ||
|
||
/** | ||
|
@@ -57,12 +59,12 @@ protected void onHandleIntent(@Nullable Intent intent) { | |
DrishtiApplication.getInstance().getClientProcessor().processClient(eventClientList); | ||
int tableMaxRowId = eventClientRepository.getMaxRowId(EventClientRepository.Table.event); | ||
|
||
if (tableMaxRowId == eventClientQueryResult.maxRowId) { | ||
if (tableMaxRowId == eventClientQueryResult.getMaxRowId()) { | ||
eventsMaxRowId = -1; | ||
allSharedPreferences.resetLastPeerToPeerSyncProcessedEvent(); | ||
} else { | ||
eventsMaxRowId = eventClientQueryResult.maxRowId; | ||
allSharedPreferences.setLastPeerToPeerSyncProcessedEvent(eventClientQueryResult.maxRowId); | ||
eventsMaxRowId = eventClientQueryResult.getMaxRowId(); | ||
allSharedPreferences.setLastPeerToPeerSyncProcessedEvent(eventClientQueryResult.getMaxRowId()); | ||
} | ||
|
||
// Profile images do not have a foreign key to the clients and can therefore be saved during the sync. | ||
|
@@ -87,33 +89,6 @@ protected void sendSyncStatusBroadcastMessage(FetchStatus fetchStatus) { | |
CoreLibrary.getInstance().context().applicationContext().sendBroadcast(Utils.completeSync(fetchStatus)); | ||
} | ||
|
||
public static class EventClientQueryResult { | ||
|
||
private List<EventClient> eventClientList; | ||
private int maxRowId; | ||
|
||
public EventClientQueryResult(int maxRowId, @NonNull List<EventClient> eventClients) { | ||
this.maxRowId = maxRowId; | ||
this.eventClientList = eventClients; | ||
} | ||
|
||
public List<EventClient> getEventClientList() { | ||
return eventClientList; | ||
} | ||
|
||
public void setEventClientList(List<EventClient> eventClientList) { | ||
this.eventClientList = eventClientList; | ||
} | ||
|
||
public int getMaxRowId() { | ||
return maxRowId; | ||
} | ||
|
||
public void setMaxRowId(int maxRowId) { | ||
this.maxRowId = maxRowId; | ||
} | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
// This ensure that even if the `onHandleIntent` is closed prematurely, we remove the Snackbar since | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.