• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

opensrp / opensrp-client-core / #181

06 Aug 2024 05:51AM UTC coverage: 68.398% (+0.003%) from 68.395%
#181

Pull #925

github

web-flow
Merge 605302deb into 4fcf06cf5
Pull Request #925: migrate SyncserviceJob to work manager

18313 of 26774 relevant lines covered (68.4%)

0.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.5
opensrp-core/src/main/java/org/smartregister/sync/intent/SettingsSyncIntentService.java
1
package org.smartregister.sync.intent;
2

3
import android.content.Intent;
4

5
import org.json.JSONException;
6
import org.smartregister.AllConstants;
7
import org.smartregister.Context;
8
import org.smartregister.CoreLibrary;
9
import org.smartregister.job.SyncSettingsServiceWorker;
10
import org.smartregister.sync.helper.SyncSettingsServiceHelper;
11

12
import timber.log.Timber;
13

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

16
import androidx.work.OneTimeWorkRequest;
17
import androidx.work.WorkManager;
18

19
/**
20
 * Created by ndegwamartin on 14/09/2018.
21
 */
22
public class SettingsSyncIntentService extends BaseSyncIntentService {
23
    public static final String SETTINGS_URL = "/rest/settings/sync";
24

25
    private static final String TAG = SettingsSyncIntentService.class.getCanonicalName();
1✔
26

27
    protected SyncSettingsServiceHelper syncSettingsServiceHelper;
28

29
    public static final String EVENT_SYNC_COMPLETE = "event_sync_complete";
30

31
    public SettingsSyncIntentService() {
32
        super(TAG);
1✔
33
    }
1✔
34

35
    @Override
36
    protected void onHandleIntent(Intent intent) {
37
        boolean isSuccessfulSync = processSettings(intent);
1✔
38
        if (isSuccessfulSync) {
1✔
39
            // Schedule the sync job using WorkManager
40
            OneTimeWorkRequest syncWorkRequest = new OneTimeWorkRequest.Builder(SyncSettingsServiceWorker.class).build();
1✔
41
            WorkManager.getInstance(this).enqueue(syncWorkRequest);
1✔
42
        }
43
    }
1✔
44

45
    protected boolean processSettings(Intent intent) {
46
        Timber.d("In Settings Sync Intent Service...");
1✔
47
        boolean isSuccessfulSync = true;
1✔
48
        if (intent != null) {
1✔
49
            try {
50
                super.onHandleIntent(intent);
1✔
51
                int count = syncSettingsServiceHelper.processIntent();
1✔
52
                if (count > 0) {
1✔
53
                    intent.putExtra(AllConstants.INTENT_KEY.SYNC_TOTAL_RECORDS, count);
1✔
54
                }
55
            } catch (JSONException e) {
×
56
                isSuccessfulSync = false;
×
57
                logError(TAG + " Error fetching client settings");
×
58
            }
1✔
59
        }
60
        return isSuccessfulSync;
1✔
61
    }
62

63
    @Override
64
    public void onCreate() {
65
        super.onCreate();
1✔
66
        Context context = CoreLibrary.getInstance().context();
1✔
67
        syncSettingsServiceHelper = new SyncSettingsServiceHelper(context.configuration().dristhiBaseURL(), context.getHttpAgent());
1✔
68
    }
1✔
69

70
}
71

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc