-
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.
- Loading branch information
Showing
32 changed files
with
808 additions
and
86 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
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
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
22 changes: 22 additions & 0 deletions
22
opensrp-core/src/main/java/org/smartregister/sync/wm/worker/BaseWorker.kt
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,22 @@ | ||
package org.smartregister.sync.wm.worker | ||
|
||
import android.content.Context | ||
import androidx.work.Worker | ||
import androidx.work.WorkerParameters | ||
import org.smartregister.CoreLibrary | ||
|
||
abstract class BaseWorker(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams){ | ||
|
||
fun beforeWork(){ | ||
val coreLibrary = CoreLibrary.getInstance() | ||
val syncConfiguration = coreLibrary.syncConfiguration | ||
if (syncConfiguration != null){ | ||
coreLibrary.context().httpAgent | ||
.apply { | ||
connectTimeout = syncConfiguration.connectTimeout | ||
readTimeout = syncConfiguration.readTimeout | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.