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

opensrp / opensrp-client-core / #175

pending completion
#175

push

github-actions

web-flow
Merge pull request #921 from opensrp/refactor-user-settings-task

Refactor user settings task

18309 of 26768 relevant lines covered (68.4%)

0.68 hits per line

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

92.05
opensrp-core/src/main/java/org/smartregister/Context.java
1
package org.smartregister;
2

3
import static androidx.preference.PreferenceManager.getDefaultSharedPreferences;
4

5
import android.content.SharedPreferences;
6
import android.content.res.Configuration;
7
import android.graphics.Typeface;
8
import android.graphics.drawable.Drawable;
9
import android.os.Build;
10

11
import androidx.security.crypto.EncryptedSharedPreferences;
12
import androidx.security.crypto.MasterKeys;
13

14
import org.apache.commons.lang3.StringUtils;
15
import org.json.JSONArray;
16
import org.json.JSONObject;
17
import org.smartregister.commonregistry.AllCommonsRepository;
18
import org.smartregister.commonregistry.CommonFtsObject;
19
import org.smartregister.commonregistry.CommonPersonObjectClients;
20
import org.smartregister.commonregistry.CommonRepository;
21
import org.smartregister.commonregistry.CommonRepositoryInformationHolder;
22
import org.smartregister.domain.ColumnDetails;
23
import org.smartregister.repository.AlertRepository;
24
import org.smartregister.repository.AllAlerts;
25
import org.smartregister.repository.AllBeneficiaries;
26
import org.smartregister.repository.AllEligibleCouples;
27
import org.smartregister.repository.AllReports;
28
import org.smartregister.repository.AllServicesProvided;
29
import org.smartregister.repository.AllSettings;
30
import org.smartregister.repository.AllSharedPreferences;
31
import org.smartregister.repository.AllTimelineEvents;
32
import org.smartregister.repository.CampaignRepository;
33
import org.smartregister.repository.ChildRepository;
34
import org.smartregister.repository.ClientFormRepository;
35
import org.smartregister.repository.ClientRelationshipRepository;
36
import org.smartregister.repository.DetailsRepository;
37
import org.smartregister.repository.DrishtiRepository;
38
import org.smartregister.repository.EligibleCoupleRepository;
39
import org.smartregister.repository.EventClientRepository;
40
import org.smartregister.repository.FormDataRepository;
41
import org.smartregister.repository.FormsVersionRepository;
42
import org.smartregister.repository.ImageRepository;
43
import org.smartregister.repository.LocationRepository;
44
import org.smartregister.repository.LocationTagRepository;
45
import org.smartregister.repository.ManifestRepository;
46
import org.smartregister.repository.MotherRepository;
47
import org.smartregister.repository.PlanDefinitionRepository;
48
import org.smartregister.repository.ReportRepository;
49
import org.smartregister.repository.ServiceProvidedRepository;
50
import org.smartregister.repository.SettingsRepository;
51
import org.smartregister.repository.StructureRepository;
52
import org.smartregister.repository.TaskNotesRepository;
53
import org.smartregister.repository.TaskRepository;
54
import org.smartregister.repository.TimelineEventRepository;
55
import org.smartregister.repository.UniqueIdRepository;
56
import org.smartregister.repository.ZeirIdCleanupRepository;
57
import org.smartregister.service.ANMService;
58
import org.smartregister.service.ActionService;
59
import org.smartregister.service.AlertService;
60
import org.smartregister.service.AllFormVersionSyncService;
61
import org.smartregister.service.BeneficiaryService;
62
import org.smartregister.service.ChildService;
63
import org.smartregister.service.DrishtiService;
64
import org.smartregister.service.EligibleCoupleService;
65
import org.smartregister.service.FormSubmissionService;
66
import org.smartregister.service.FormSubmissionSyncService;
67
import org.smartregister.service.HTTPAgent;
68
import org.smartregister.service.MotherService;
69
import org.smartregister.service.PendingFormSubmissionService;
70
import org.smartregister.service.ServiceProvidedService;
71
import org.smartregister.service.UserService;
72
import org.smartregister.service.ZiggyFileLoader;
73
import org.smartregister.service.ZiggyService;
74
import org.smartregister.service.formsubmissionhandler.ANCCloseHandler;
75
import org.smartregister.service.formsubmissionhandler.ANCInvestigationsHandler;
76
import org.smartregister.service.formsubmissionhandler.ANCRegistrationHandler;
77
import org.smartregister.service.formsubmissionhandler.ANCRegistrationOAHandler;
78
import org.smartregister.service.formsubmissionhandler.ANCVisitHandler;
79
import org.smartregister.service.formsubmissionhandler.ChildCloseHandler;
80
import org.smartregister.service.formsubmissionhandler.ChildIllnessHandler;
81
import org.smartregister.service.formsubmissionhandler.ChildImmunizationsHandler;
82
import org.smartregister.service.formsubmissionhandler.ChildRegistrationECHandler;
83
import org.smartregister.service.formsubmissionhandler.ChildRegistrationOAHandler;
84
import org.smartregister.service.formsubmissionhandler.DeliveryOutcomeHandler;
85
import org.smartregister.service.formsubmissionhandler.DeliveryPlanHandler;
86
import org.smartregister.service.formsubmissionhandler.ECCloseHandler;
87
import org.smartregister.service.formsubmissionhandler.ECEditHandler;
88
import org.smartregister.service.formsubmissionhandler.ECRegistrationHandler;
89
import org.smartregister.service.formsubmissionhandler.FPChangeHandler;
90
import org.smartregister.service.formsubmissionhandler.FPComplicationsHandler;
91
import org.smartregister.service.formsubmissionhandler.FormSubmissionRouter;
92
import org.smartregister.service.formsubmissionhandler.HBTestHandler;
93
import org.smartregister.service.formsubmissionhandler.IFAHandler;
94
import org.smartregister.service.formsubmissionhandler.PNCCloseHandler;
95
import org.smartregister.service.formsubmissionhandler.PNCRegistrationOAHandler;
96
import org.smartregister.service.formsubmissionhandler.PNCVisitHandler;
97
import org.smartregister.service.formsubmissionhandler.RenewFPProductHandler;
98
import org.smartregister.service.formsubmissionhandler.TTHandler;
99
import org.smartregister.service.formsubmissionhandler.VitaminAHandler;
100
import org.smartregister.sync.SaveANMLocationTask;
101
import org.smartregister.sync.SaveANMTeamTask;
102
import org.smartregister.sync.SaveUserInfoTask;
103
import org.smartregister.util.AppProperties;
104
import org.smartregister.util.Cache;
105
import org.smartregister.util.Session;
106
import org.smartregister.util.Utils;
107
import org.smartregister.view.activity.DrishtiApplication;
108
import org.smartregister.view.contract.ANCClients;
109
import org.smartregister.view.contract.ECClients;
110
import org.smartregister.view.contract.FPClients;
111
import org.smartregister.view.contract.HomeContext;
112
import org.smartregister.view.contract.SmartRegisterClients;
113
import org.smartregister.view.contract.Villages;
114
import org.smartregister.view.contract.pnc.PNCClients;
115
import org.smartregister.view.controller.ANMController;
116
import org.smartregister.view.controller.ANMLocationController;
117

118
import java.io.BufferedReader;
119
import java.io.InputStream;
120
import java.io.InputStreamReader;
121
import java.util.ArrayList;
122
import java.util.HashMap;
123
import java.util.List;
124
import java.util.Map;
125

126
import timber.log.Timber;
127

128
public class Context {
129

130
    ///////////////////common bindtypes///////////////
131

132
    private static final String SHARED_PREFERENCES_FILENAME = "%s_preferences";
133
    public static ArrayList<CommonRepositoryInformationHolder> bindtypes;
134
    private static Context context = new Context();
1✔
135
    protected DristhiConfiguration configuration;
136
    private android.content.Context applicationContext;
137
    private EligibleCoupleRepository eligibleCoupleRepository;
138
    private AlertRepository alertRepository;
139
    private SettingsRepository settingsRepository;
140
    private ChildRepository childRepository;
141
    private DetailsRepository detailsRepository;
142
    private MotherRepository motherRepository;
143
    private TimelineEventRepository timelineEventRepository;
144
    private ReportRepository reportRepository;
145
    private FormDataRepository formDataRepository;
146
    private ServiceProvidedRepository serviceProvidedRepository;
147
    private FormsVersionRepository formsVersionRepository;
148
    private AllSettings allSettings;
149
    private AllSharedPreferences allSharedPreferences;
150
    private AllAlerts allAlerts;
151
    private AllEligibleCouples allEligibleCouples;
152
    private AllBeneficiaries allBeneficiaries;
153
    private AllTimelineEvents allTimelineEvents;
154
    private AllReports allReports;
155
    private AllServicesProvided allServicesProvided;
156
    private AllCommonsRepository allCommonPersonObjectsRepository;
157
    private ImageRepository imageRepository;
158
    private DrishtiService drishtiService;
159
    private ActionService actionService;
160
    private FormSubmissionService formSubmissionService;
161
    private FormSubmissionSyncService formSubmissionSyncService;
162
    private ZiggyService ziggyService;
163
    private UserService userService;
164
    private AlertService alertService;
165
    private EligibleCoupleService eligibleCoupleService;
166
    private MotherService motherService;
167
    private ChildService childService;
168
    private ANMService anmService;
169
    private BeneficiaryService beneficiaryService;
170
    private ServiceProvidedService serviceProvidedService;
171
    private PendingFormSubmissionService pendingFormSubmissionService;
172
    private AllFormVersionSyncService allFormVersionSyncService;
173
    private Session session;
174
    private Cache<String> listCache;
175
    private Cache<SmartRegisterClients> smartRegisterClientsCache;
176
    private Cache<HomeContext> homeContextCache;
177
    private Cache<ECClients> ecClientsCache;
178
    private Cache<FPClients> fpClientsCache;
179
    private Cache<ANCClients> ancClientsCache;
180
    private Cache<PNCClients> pncClientsCache;
181
    private Cache<Villages> villagesCache;
182
    private Cache<Typeface> typefaceCache;
183
    private Cache<CommonPersonObjectClients> personObjectClientsCache;
184
    private HTTPAgent httpAgent;
185
    private ZiggyFileLoader ziggyFileLoader;
186
    private FormSubmissionRouter formSubmissionRouter;
187
    private ECRegistrationHandler ecRegistrationHandler;
188
    private FPComplicationsHandler fpComplicationsHandler;
189
    private FPChangeHandler fpChangeHandler;
190
    private RenewFPProductHandler renewFPProductHandler;
191
    private ECCloseHandler ecCloseHandler;
192
    private ANCRegistrationHandler ancRegistrationHandler;
193
    private ANCRegistrationOAHandler ancRegistrationOAHandler;
194
    private ANCVisitHandler ancVisitHandler;
195
    private ANCCloseHandler ancCloseHandler;
196
    private TTHandler ttHandler;
197
    private IFAHandler ifaHandler;
198
    private HBTestHandler hbTestHandler;
199
    private DeliveryOutcomeHandler deliveryOutcomeHandler;
200
    private DeliveryPlanHandler deliveryPlanHandler;
201
    private PNCRegistrationOAHandler pncRegistrationOAHandler;
202
    private PNCCloseHandler pncCloseHandler;
203
    private PNCVisitHandler pncVisitHandler;
204
    private ChildImmunizationsHandler childImmunizationsHandler;
205
    private ChildRegistrationECHandler childRegistrationECHandler;
206
    private ChildRegistrationOAHandler childRegistrationOAHandler;
207
    private ChildCloseHandler childCloseHandler;
208
    private ChildIllnessHandler childIllnessHandler;
209
    private VitaminAHandler vitaminAHandler;
210
    private ECEditHandler ecEditHandler;
211
    private ANCInvestigationsHandler ancInvestigationsHandler;
212
    private ANMController anmController;
213
    private ANMLocationController anmLocationController;
214
    private CommonFtsObject commonFtsObject;
215
    private Map<String, String> customHumanReadableConceptResponse;
216
    private HashMap<String, CommonRepository> MapOfCommonRepository;
217
    private EventClientRepository eventClientRepository;
218
    private EventClientRepository foreignEventClientRepository;
219
    private UniqueIdRepository uniqueIdRepository;
220
    private CampaignRepository campaignRepository;
221
    private TaskRepository taskRepository;
222
    private TaskNotesRepository taskNotesRepository;
223
    private LocationRepository locationRepository;
224
    private StructureRepository structureRepository;
225
    private PlanDefinitionRepository planDefinitionRepository;
226
    private AppProperties appProperties;
227
    private LocationTagRepository locationTagRepository;
228
    private ManifestRepository manifestRepository;
229
    private ClientFormRepository clientFormRepository;
230
    private ClientRelationshipRepository clientRelationshipRepository;
231
    private ZeirIdCleanupRepository zeirIdCleanupRepository;
232

233
    /////////////////////////////////////////////////
234

235
    protected Context() {
1✔
236
    }
1✔
237

238
    public static Context getInstance() {
239
        if (context == null) {
1✔
240
            context = new Context();
1✔
241
        }
242
        return context;
1✔
243
    }
244

245
    public static Context setInstance(Context mContext) {
246
        if (mContext != null) {
1✔
247
            context = mContext;
1✔
248
            return context;
1✔
249
        }
250
        return null;
1✔
251
    }
252

253
    public static void destroyInstance() {
254
        context = null;
1✔
255
    }
1✔
256

257
    public android.content.Context applicationContext() {
258
        if (applicationContext != null) {//Fix to enable Multi language support for this context
1✔
259
            try {
260
                Configuration configuration = applicationContext.getResources().getConfiguration();
1✔
261
                configuration.setLocale(configuration.locale);
1✔
262
                return applicationContext.createConfigurationContext(configuration);
1✔
263
            } catch (Exception e) {
1✔
264
                return applicationContext;
1✔
265
            }
266
        } else {
267
            return null;
1✔
268
        }
269
    }
270

271
    public BeneficiaryService beneficiaryService() {
272
        if (beneficiaryService == null) {
1✔
273
            beneficiaryService = new BeneficiaryService(allEligibleCouples(), allBeneficiaries());
1✔
274
        }
275
        return beneficiaryService;
1✔
276
    }
277

278
    public Context updateApplicationContext(android.content.Context applicationContext) {
279
        this.applicationContext = applicationContext;
1✔
280
        return this;
1✔
281
    }
282

283
    protected DrishtiService drishtiService() {
284
        if (drishtiService == null) {
1✔
285
            drishtiService = new DrishtiService(httpAgent(), configuration().dristhiBaseURL());
1✔
286
        }
287
        return drishtiService;
1✔
288
    }
289

290
    public ActionService actionService() {
291
        if (actionService == null) {
1✔
292
            actionService = new ActionService(drishtiService(), allSettings(),
1✔
293
                    allSharedPreferences(), allReports());
1✔
294
        }
295
        return actionService;
1✔
296
    }
297

298
    public FormSubmissionService formSubmissionService() {
299
        if (formSubmissionService == null) {
1✔
300
            if (commonFtsObject != null) {
1✔
301
                formSubmissionService = new FormSubmissionService(ziggyService(),
×
302
                        formDataRepository(), allSettings(), allCommonsRepositoryMap());
×
303
            } else {
304
                formSubmissionService = new FormSubmissionService(ziggyService(),
1✔
305
                        formDataRepository(), allSettings());
1✔
306
            }
307
        }
308
        return formSubmissionService;
1✔
309
    }
310

311
    public AllFormVersionSyncService allFormVersionSyncService() {
312
        if (allFormVersionSyncService == null) {
1✔
313
            allFormVersionSyncService = new AllFormVersionSyncService(httpAgent(), configuration(),
1✔
314
                    formsVersionRepository());
1✔
315
        }
316
        return allFormVersionSyncService;
1✔
317
    }
318

319
    public FormSubmissionRouter formSubmissionRouter() {
320
        if (formSubmissionRouter == null) {
1✔
321
            formSubmissionRouter = new FormSubmissionRouter(formDataRepository(),
1✔
322
                    ecRegistrationHandler(), fpComplicationsHandler(), fpChangeHandler(),
1✔
323
                    renewFPProductHandler(), ecCloseHandler(), ancRegistrationHandler(),
1✔
324
                    ancRegistrationOAHandler(), ancVisitHandler(), ancCloseHandler(), ttHandler(),
1✔
325
                    ifaHandler(), hbTestHandler(), deliveryOutcomeHandler(),
1✔
326
                    pncRegistrationOAHandler(), pncCloseHandler(), pncVisitHandler(),
1✔
327
                    childImmunizationsHandler(), childRegistrationECHandler(),
1✔
328
                    childRegistrationOAHandler(), childCloseHandler(), childIllnessHandler(),
1✔
329
                    vitaminAHandler(), deliveryPlanHandler(), ecEditHandler(),
1✔
330
                    ancInvestigationsHandler());
1✔
331
        }
332
        return formSubmissionRouter;
1✔
333
    }
334

335
    private ChildCloseHandler childCloseHandler() {
336
        if (childCloseHandler == null) {
1✔
337
            childCloseHandler = new ChildCloseHandler(childService());
1✔
338
        }
339
        return childCloseHandler;
1✔
340
    }
341

342
    private ECRegistrationHandler ecRegistrationHandler() {
343
        if (ecRegistrationHandler == null) {
1✔
344
            ecRegistrationHandler = new ECRegistrationHandler(eligibleCoupleService());
1✔
345
        }
346
        return ecRegistrationHandler;
1✔
347
    }
348

349
    private FPComplicationsHandler fpComplicationsHandler() {
350
        if (fpComplicationsHandler == null) {
1✔
351
            fpComplicationsHandler = new FPComplicationsHandler(eligibleCoupleService());
1✔
352
        }
353
        return fpComplicationsHandler;
1✔
354
    }
355

356
    private FPChangeHandler fpChangeHandler() {
357
        if (fpChangeHandler == null) {
1✔
358
            fpChangeHandler = new FPChangeHandler(eligibleCoupleService());
1✔
359
        }
360
        return fpChangeHandler;
1✔
361
    }
362

363
    private RenewFPProductHandler renewFPProductHandler() {
364
        if (renewFPProductHandler == null) {
1✔
365
            renewFPProductHandler = new RenewFPProductHandler(eligibleCoupleService());
1✔
366
        }
367
        return renewFPProductHandler;
1✔
368
    }
369

370
    private ECCloseHandler ecCloseHandler() {
371
        if (ecCloseHandler == null) {
1✔
372
            ecCloseHandler = new ECCloseHandler(eligibleCoupleService());
1✔
373
        }
374
        return ecCloseHandler;
1✔
375
    }
376

377
    private ANCRegistrationHandler ancRegistrationHandler() {
378
        if (ancRegistrationHandler == null) {
1✔
379
            ancRegistrationHandler = new ANCRegistrationHandler(motherService());
1✔
380
        }
381
        return ancRegistrationHandler;
1✔
382
    }
383

384
    private ANCRegistrationOAHandler ancRegistrationOAHandler() {
385
        if (ancRegistrationOAHandler == null) {
1✔
386
            ancRegistrationOAHandler = new ANCRegistrationOAHandler(motherService());
1✔
387
        }
388
        return ancRegistrationOAHandler;
1✔
389
    }
390

391
    private ANCVisitHandler ancVisitHandler() {
392
        if (ancVisitHandler == null) {
1✔
393
            ancVisitHandler = new ANCVisitHandler(motherService());
1✔
394
        }
395
        return ancVisitHandler;
1✔
396
    }
397

398
    private ANCCloseHandler ancCloseHandler() {
399
        if (ancCloseHandler == null) {
1✔
400
            ancCloseHandler = new ANCCloseHandler(motherService());
1✔
401
        }
402
        return ancCloseHandler;
1✔
403
    }
404

405
    private TTHandler ttHandler() {
406
        if (ttHandler == null) {
1✔
407
            ttHandler = new TTHandler(motherService());
1✔
408
        }
409
        return ttHandler;
1✔
410
    }
411

412
    private IFAHandler ifaHandler() {
413
        if (ifaHandler == null) {
1✔
414
            ifaHandler = new IFAHandler(motherService());
1✔
415
        }
416
        return ifaHandler;
1✔
417
    }
418

419
    private HBTestHandler hbTestHandler() {
420
        if (hbTestHandler == null) {
1✔
421
            hbTestHandler = new HBTestHandler(motherService());
1✔
422
        }
423
        return hbTestHandler;
1✔
424
    }
425

426
    private DeliveryOutcomeHandler deliveryOutcomeHandler() {
427
        if (deliveryOutcomeHandler == null) {
1✔
428
            deliveryOutcomeHandler = new DeliveryOutcomeHandler(motherService(), childService());
1✔
429
        }
430
        return deliveryOutcomeHandler;
1✔
431
    }
432

433
    private DeliveryPlanHandler deliveryPlanHandler() {
434
        if (deliveryPlanHandler == null) {
1✔
435
            deliveryPlanHandler = new DeliveryPlanHandler(motherService());
1✔
436
        }
437
        return deliveryPlanHandler;
1✔
438
    }
439

440
    private PNCRegistrationOAHandler pncRegistrationOAHandler() {
441
        if (pncRegistrationOAHandler == null) {
1✔
442
            pncRegistrationOAHandler = new PNCRegistrationOAHandler(childService());
1✔
443
        }
444
        return pncRegistrationOAHandler;
1✔
445
    }
446

447
    private PNCCloseHandler pncCloseHandler() {
448
        if (pncCloseHandler == null) {
1✔
449
            pncCloseHandler = new PNCCloseHandler(motherService());
1✔
450
        }
451
        return pncCloseHandler;
1✔
452
    }
453

454
    private PNCVisitHandler pncVisitHandler() {
455
        if (pncVisitHandler == null) {
1✔
456
            pncVisitHandler = new PNCVisitHandler(motherService(), childService());
1✔
457
        }
458
        return pncVisitHandler;
1✔
459
    }
460

461
    private ChildImmunizationsHandler childImmunizationsHandler() {
462
        if (childImmunizationsHandler == null) {
1✔
463
            childImmunizationsHandler = new ChildImmunizationsHandler(childService());
1✔
464
        }
465
        return childImmunizationsHandler;
1✔
466
    }
467

468
    private ChildIllnessHandler childIllnessHandler() {
469
        if (childIllnessHandler == null) {
1✔
470
            childIllnessHandler = new ChildIllnessHandler(childService());
1✔
471
        }
472
        return childIllnessHandler;
1✔
473
    }
474

475
    private VitaminAHandler vitaminAHandler() {
476
        if (vitaminAHandler == null) {
1✔
477
            vitaminAHandler = new VitaminAHandler(childService());
1✔
478
        }
479
        return vitaminAHandler;
1✔
480
    }
481

482
    private ChildRegistrationECHandler childRegistrationECHandler() {
483
        if (childRegistrationECHandler == null) {
1✔
484
            childRegistrationECHandler = new ChildRegistrationECHandler(childService());
1✔
485
        }
486
        return childRegistrationECHandler;
1✔
487
    }
488

489
    private ChildRegistrationOAHandler childRegistrationOAHandler() {
490
        if (childRegistrationOAHandler == null) {
1✔
491
            childRegistrationOAHandler = new ChildRegistrationOAHandler(childService());
1✔
492
        }
493
        return childRegistrationOAHandler;
1✔
494
    }
495

496
    private ECEditHandler ecEditHandler() {
497
        if (ecEditHandler == null) {
1✔
498
            ecEditHandler = new ECEditHandler();
1✔
499
        }
500
        return ecEditHandler;
1✔
501
    }
502

503
    private ANCInvestigationsHandler ancInvestigationsHandler() {
504
        if (ancInvestigationsHandler == null) {
1✔
505
            ancInvestigationsHandler = new ANCInvestigationsHandler();
1✔
506
        }
507
        return ancInvestigationsHandler;
1✔
508
    }
509

510
    public ZiggyService ziggyService() {
511
        if (ziggyService == null) {
1✔
512
            ziggyService = new ZiggyService(ziggyFileLoader(), formDataRepository(),
1✔
513
                    formSubmissionRouter());
1✔
514
        }
515
        return ziggyService;
1✔
516
    }
517

518
    public ZiggyFileLoader ziggyFileLoader() {
519
        if (ziggyFileLoader == null) {
1✔
520
            ziggyFileLoader = new ZiggyFileLoader("www/ziggy", "www/form",
1✔
521
                    applicationContext().getAssets());
1✔
522
        }
523
        return ziggyFileLoader;
1✔
524
    }
525

526
    public FormSubmissionSyncService formSubmissionSyncService() {
527
        if (formSubmissionSyncService == null) {
1✔
528
            formSubmissionSyncService = new FormSubmissionSyncService(formSubmissionService(),
1✔
529
                    httpAgent(), formDataRepository(), allSettings(), allSharedPreferences(),
1✔
530
                    configuration());
1✔
531
        }
532
        return formSubmissionSyncService;
1✔
533
    }
534

535
    public HTTPAgent httpAgent() {
536
        if (httpAgent == null) {
1✔
537
            httpAgent = new HTTPAgent(applicationContext, allSharedPreferences(), configuration());
1✔
538
        }
539
        return httpAgent;
1✔
540
    }
541

542
    public ArrayList<DrishtiRepository> sharedRepositories() {
543
        assignbindtypes();
1✔
544
        ArrayList<DrishtiRepository> drishtiRepositoryList = new ArrayList<DrishtiRepository>();
1✔
545
        drishtiRepositoryList.add(settingsRepository());
1✔
546
        drishtiRepositoryList.add(alertRepository());
1✔
547
        drishtiRepositoryList.add(eligibleCoupleRepository());
1✔
548
        drishtiRepositoryList.add(childRepository());
1✔
549
        drishtiRepositoryList.add(timelineEventRepository());
1✔
550
        drishtiRepositoryList.add(motherRepository());
1✔
551
        drishtiRepositoryList.add(reportRepository());
1✔
552
        drishtiRepositoryList.add(formDataRepository());
1✔
553
        drishtiRepositoryList.add(serviceProvidedRepository());
1✔
554
        drishtiRepositoryList.add(formsVersionRepository());
1✔
555
        drishtiRepositoryList.add(imageRepository());
1✔
556
        drishtiRepositoryList.add(detailsRepository());
1✔
557
        for (int i = 0; i < bindtypes.size(); i++) {
1✔
558
            drishtiRepositoryList.add(commonrepository(bindtypes.get(i).getBindtypename()));
1✔
559
        }
560
        return drishtiRepositoryList;
1✔
561

562
    }
563

564
    public DrishtiRepository[] sharedRepositoriesArray() {
565
        ArrayList<DrishtiRepository> drishtiRepositories = sharedRepositories();
1✔
566
        DrishtiRepository[] drishtiRepositoryArray = drishtiRepositories
1✔
567
                .toArray(new DrishtiRepository[drishtiRepositories.size()]);
1✔
568
        return drishtiRepositoryArray;
1✔
569
    }
570

571
    public AllEligibleCouples allEligibleCouples() {
572
        if (allEligibleCouples == null) {
1✔
573
            allEligibleCouples = new AllEligibleCouples(eligibleCoupleRepository(),
1✔
574
                    alertRepository(), timelineEventRepository());
1✔
575
        }
576
        return allEligibleCouples;
1✔
577
    }
578

579
    public AllAlerts allAlerts() {
580
        if (allAlerts == null) {
1✔
581
            allAlerts = new AllAlerts(alertRepository());
1✔
582
        }
583
        return allAlerts;
1✔
584
    }
585

586
    public AllSettings allSettings() {
587
        if (allSettings == null) {
1✔
588
            allSettings = new AllSettings(allSharedPreferences(), settingsRepository());
1✔
589
        }
590
        return allSettings;
1✔
591
    }
592

593
    public AllSharedPreferences allSharedPreferences() {
594
        if (allSharedPreferences == null) {
1✔
595
            allSharedPreferences = new AllSharedPreferences(createSharedPreferences(this.applicationContext));
1✔
596
        }
597
        return allSharedPreferences;
1✔
598
    }
599

600
    private SharedPreferences createSharedPreferences(android.content.Context context) {
601
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
1✔
602
                && Utils.getBooleanProperty(AllConstants.PROPERTY.ENCRYPT_SHARED_PREFERENCES)) {
1✔
603

604
            return createEncryptedSharedPreferences(context);
×
605
        } else {
606
            return getDefaultSharedPreferences(context);
1✔
607
        }
608
    }
609

610
    private SharedPreferences createEncryptedSharedPreferences(android.content.Context context) {
611
        SharedPreferences sharedPreferences = null;
×
612

613
        try {
614
            String masterKeyAlias = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC);
×
615

616
            sharedPreferences = EncryptedSharedPreferences.create(
×
617
                    String.format(SHARED_PREFERENCES_FILENAME, context.getPackageName()),
×
618
                    masterKeyAlias,
619
                    context,
620
                    EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
621
                    EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
622
            );
623
        } catch (Exception e) {
×
624
            Timber.e(e, "Error creating encrypted SharedPreferences");
×
625

626
            // fall back to unencrypted SharedPreferences
627
            sharedPreferences = getDefaultSharedPreferences(context);
×
628
        }
×
629

630
        return sharedPreferences;
×
631
    }
632

633
    public AllBeneficiaries allBeneficiaries() {
634
        if (allBeneficiaries == null) {
1✔
635
            allBeneficiaries = new AllBeneficiaries(motherRepository(), childRepository(),
1✔
636
                    alertRepository(), timelineEventRepository());
1✔
637
        }
638
        return allBeneficiaries;
1✔
639
    }
640

641
    public AllTimelineEvents allTimelineEvents() {
642
        if (allTimelineEvents == null) {
1✔
643
            allTimelineEvents = new AllTimelineEvents(timelineEventRepository());
1✔
644
        }
645
        return allTimelineEvents;
1✔
646
    }
647

648
    public AllReports allReports() {
649
        if (allReports == null) {
1✔
650
            allReports = new AllReports(reportRepository());
1✔
651
        }
652
        return allReports;
1✔
653
    }
654

655
    public AllServicesProvided allServicesProvided() {
656
        if (allServicesProvided == null) {
1✔
657
            allServicesProvided = new AllServicesProvided(serviceProvidedRepository());
1✔
658
        }
659
        return allServicesProvided;
1✔
660
    }
661

662
    private EligibleCoupleRepository eligibleCoupleRepository() {
663
        if (eligibleCoupleRepository == null) {
1✔
664
            eligibleCoupleRepository = new EligibleCoupleRepository();
1✔
665
        }
666
        return eligibleCoupleRepository;
1✔
667
    }
668

669
    protected AlertRepository alertRepository() {
670
        if (alertRepository == null) {
1✔
671
            alertRepository = new AlertRepository();
1✔
672
        }
673
        return alertRepository;
1✔
674
    }
675

676
    protected SettingsRepository settingsRepository() {
677
        if (settingsRepository == null) {
1✔
678
            settingsRepository = new SettingsRepository();
1✔
679
        }
680
        return settingsRepository;
1✔
681
    }
682

683
    private ChildRepository childRepository() {
684
        if (childRepository == null) {
1✔
685
            childRepository = new ChildRepository();
1✔
686
        }
687
        return childRepository;
1✔
688
    }
689

690
    public DetailsRepository detailsRepository() {
691
        if (detailsRepository == null) {
1✔
692
            detailsRepository = new DetailsRepository();
1✔
693
        }
694
        return detailsRepository;
1✔
695
    }
696

697
    private MotherRepository motherRepository() {
698
        if (motherRepository == null) {
1✔
699
            motherRepository = new MotherRepository();
1✔
700
        }
701
        return motherRepository;
1✔
702
    }
703

704
    protected TimelineEventRepository timelineEventRepository() {
705
        if (timelineEventRepository == null) {
1✔
706
            timelineEventRepository = new TimelineEventRepository();
1✔
707
        }
708
        return timelineEventRepository;
1✔
709
    }
710

711
    private ReportRepository reportRepository() {
712
        if (reportRepository == null) {
1✔
713
            reportRepository = new ReportRepository();
1✔
714
        }
715
        return reportRepository;
1✔
716
    }
717

718
    public FormDataRepository formDataRepository() {
719
        if (formDataRepository == null) {
1✔
720
            formDataRepository = new FormDataRepository();
1✔
721
        }
722
        return formDataRepository;
1✔
723
    }
724

725
    protected ServiceProvidedRepository serviceProvidedRepository() {
726
        if (serviceProvidedRepository == null) {
1✔
727
            serviceProvidedRepository = new ServiceProvidedRepository();
1✔
728
        }
729
        return serviceProvidedRepository;
1✔
730
    }
731

732
    protected FormsVersionRepository formsVersionRepository() {
733
        if (formsVersionRepository == null) {
1✔
734
            formsVersionRepository = new FormsVersionRepository();
1✔
735
        }
736
        return formsVersionRepository;
1✔
737
    }
738

739
    public ImageRepository imageRepository() {
740
        if (imageRepository == null) {
1✔
741
            imageRepository = new ImageRepository();
1✔
742
        }
743
        return imageRepository;
1✔
744
    }
745

746
    public UserService userService() {
747
        if (userService == null) {
1✔
748
            userService = new UserService(allSettings(), allSharedPreferences(),
1✔
749
                    httpAgent(), session(), configuration());
1✔
750
        }
751
        return userService;
1✔
752
    }
753

754
    public AlertService alertService() {
755
        if (alertService == null) {
1✔
756
            if (commonFtsObject() != null) {
1✔
757
                alertService = new AlertService(alertRepository(), commonFtsObject(),
1✔
758
                        allCommonsRepositoryMap());
1✔
759
            } else {
760
                alertService = new AlertService(alertRepository());
1✔
761
            }
762
        }
763
        return alertService;
1✔
764
    }
765

766
    public ServiceProvidedService serviceProvidedService() {
767
        if (serviceProvidedService == null) {
1✔
768
            serviceProvidedService = new ServiceProvidedService(allServicesProvided());
1✔
769
        }
770
        return serviceProvidedService;
1✔
771
    }
772

773
    public EligibleCoupleService eligibleCoupleService() {
774
        if (eligibleCoupleService == null) {
1✔
775
            eligibleCoupleService = new EligibleCoupleService(allEligibleCouples(),
1✔
776
                    allTimelineEvents(), allBeneficiaries());
1✔
777
        }
778
        return eligibleCoupleService;
1✔
779
    }
780

781
    public MotherService motherService() {
782
        if (motherService == null) {
1✔
783
            motherService = new MotherService(allBeneficiaries(), allEligibleCouples(),
1✔
784
                    allTimelineEvents(), serviceProvidedService());
1✔
785
        }
786
        return motherService;
1✔
787
    }
788

789
    public ChildService childService() {
790
        if (childService == null) {
1✔
791
            childService = new ChildService(allBeneficiaries(), motherRepository(),
1✔
792
                    childRepository(), allTimelineEvents(), serviceProvidedService(), allAlerts());
1✔
793
        }
794
        return childService;
1✔
795
    }
796

797
    public Session session() {
798
        if (session == null) {
1✔
799
            session = new Session();
1✔
800
        }
801
        return session;
1✔
802
    }
803

804
    public ANMService anmService() {
805
        if (anmService == null) {
1✔
806
            anmService = new ANMService(allSharedPreferences(), allBeneficiaries(),
1✔
807
                    allEligibleCouples());
1✔
808
        }
809
        return anmService;
1✔
810
    }
811

812
    public Cache<String> listCache() {
813
        if (listCache == null) {
1✔
814
            listCache = new Cache<String>();
1✔
815
        }
816
        return listCache;
1✔
817
    }
818

819
    public Cache<SmartRegisterClients> smartRegisterClientsCache() {
820
        if (smartRegisterClientsCache == null) {
1✔
821
            smartRegisterClientsCache = new Cache<SmartRegisterClients>();
1✔
822
        }
823
        return smartRegisterClientsCache;
1✔
824
    }
825

826
    public Cache<HomeContext> homeContextCache() {
827
        if (homeContextCache == null) {
1✔
828
            homeContextCache = new Cache<>();
1✔
829
        }
830
        return homeContextCache;
1✔
831
    }
832

833
    public Boolean IsUserLoggedOut() {
834
        return userService().hasSessionExpired();
1✔
835
    }
836

837
    public DristhiConfiguration configuration() {
838
        if (configuration == null) {
1✔
839
            configuration = new DristhiConfiguration();
1✔
840
        }
841
        return configuration;
1✔
842
    }
843

844
    public PendingFormSubmissionService pendingFormSubmissionService() {
845
        if (pendingFormSubmissionService == null) {
1✔
846
            pendingFormSubmissionService = new PendingFormSubmissionService(formDataRepository());
1✔
847
        }
848
        return pendingFormSubmissionService;
1✔
849
    }
850

851
    public ANMController anmController() {
852
        if (anmController == null) {
1✔
853
            anmController = new ANMController(anmService(), listCache(), homeContextCache());
1✔
854
        }
855
        return anmController;
1✔
856
    }
857

858
    public ANMLocationController anmLocationController() {
859
        if (anmLocationController == null) {
1✔
860
            anmLocationController = new ANMLocationController(allSettings(), listCache());
1✔
861
        }
862
        return anmLocationController;
1✔
863
    }
864

865
    //#TODO: Refactor to use one cache object
866
    public Cache<ECClients> ecClientsCache() {
867
        if (ecClientsCache == null) {
1✔
868
            ecClientsCache = new Cache<ECClients>();
1✔
869
        }
870
        return ecClientsCache;
1✔
871

872
    }
873

874
    //#TODO: Refactor to use one cache object
875

876
    //#TODO: Refactor to use one cache object
877
    public Cache<FPClients> fpClientsCache() {
878
        if (fpClientsCache == null) {
1✔
879
            fpClientsCache = new Cache<FPClients>();
1✔
880
        }
881
        return fpClientsCache;
1✔
882

883
    }
884

885
    public Cache<ANCClients> ancClientsCache() {
886
        if (ancClientsCache == null) {
1✔
887
            ancClientsCache = new Cache<ANCClients>();
1✔
888
        }
889
        return ancClientsCache;
1✔
890
    }
891

892
    public Cache<PNCClients> pncClientsCache() {
893
        if (pncClientsCache == null) {
1✔
894
            pncClientsCache = new Cache<PNCClients>();
1✔
895
        }
896
        return pncClientsCache;
1✔
897
    }
898

899
    public Cache<Villages> villagesCache() {
900
        if (villagesCache == null) {
1✔
901
            villagesCache = new Cache<Villages>();
1✔
902
        }
903
        return villagesCache;
1✔
904
    }
905

906
    public Cache<Typeface> typefaceCache() {
907
        if (typefaceCache == null) {
1✔
908
            typefaceCache = new Cache<Typeface>();
1✔
909
        }
910
        return typefaceCache;
1✔
911
    }
912

913
    public String getStringResource(int id) {
914
        return applicationContext().getResources().getString(id);
1✔
915
    }
916

917
    public int getColorResource(int id) {
918
        return applicationContext().getResources().getColor(id);
1✔
919
    }
920

921
    public Drawable getDrawable(int id) {
922
        return applicationContext().getResources().getDrawable(id);
×
923
    }
924

925
    public Drawable getDrawableResource(int id) {
926
        return applicationContext().getResources().getDrawable(id);
×
927
    }
928

929
    ///////////////////////////////// common methods ///////////////////////////////
930
    public Cache<CommonPersonObjectClients> personObjectClientsCache() {
931
        this.personObjectClientsCache = null;
1✔
932
        personObjectClientsCache = new Cache<CommonPersonObjectClients>();
1✔
933
        return personObjectClientsCache;
1✔
934
    }
935

936
    public AllCommonsRepository allCommonsRepositoryobjects(String tablename) {
937
        allCommonPersonObjectsRepository = new AllCommonsRepository(commonrepository(tablename),
1✔
938
                alertRepository(), timelineEventRepository());
1✔
939
        return allCommonPersonObjectsRepository;
1✔
940
    }
941

942
    public long countofcommonrepositroy(String tablename) {
943
        return commonrepository(tablename).count();
×
944
    }
945

946
    public CommonRepository commonrepository(String tablename) {
947
        if (MapOfCommonRepository == null) {
1✔
948
            MapOfCommonRepository = new HashMap<String, CommonRepository>();
1✔
949
        }
950
        if (MapOfCommonRepository.get(tablename) == null) {
1✔
951
            for (CommonRepositoryInformationHolder bindType : bindtypes) {
1✔
952
                if (bindType.getBindtypename().equalsIgnoreCase(tablename)) {
1✔
953
                    if (commonFtsObject != null && commonFtsObject.containsTable(tablename)) {
1✔
954
                        MapOfCommonRepository.put(bindType.getBindtypename(),
1✔
955
                                new CommonRepository(commonFtsObject, bindType.getBindtypename(),
1✔
956
                                        bindType.getColumnNames()));
1✔
957
                        break;
1✔
958
                    } else {
959
                        MapOfCommonRepository.put(bindType.getBindtypename(),
1✔
960
                                new CommonRepository(bindType.getBindtypename(),
1✔
961
                                        bindType.getColumnNames()));
1✔
962
                        break;
1✔
963
                    }
964
                }
965
            }
×
966

967
        }
968
        return MapOfCommonRepository.get(tablename);
1✔
969
    }
970

971
    public void assignbindtypes() {
972
        bindtypes = new ArrayList<CommonRepositoryInformationHolder>();
1✔
973
        // create common repository definition for the ec models
974
        getEcBindtypes();
1✔
975
        try {
976
            if (this.applicationContext() == null) {
1✔
977
                return;
×
978
            }
979
            String str = ReadFromfile("bindtypes.json", this.applicationContext());
1✔
980
            if (StringUtils.isBlank(str)) {
1✔
981
                return;
1✔
982
            }
983
            JSONObject jsonObject = new JSONObject(str);
×
984
            JSONArray bindtypeObjects = jsonObject.getJSONArray("bindobjects");
×
985

986
            for (int i = 0; i < bindtypeObjects.length(); i++) {
×
987
                String bindname = bindtypeObjects.getJSONObject(i).getString(AllConstants.ClientProcessing.NAME);
×
988
                ColumnDetails[] columNames = new ColumnDetails[bindtypeObjects.getJSONObject(i)
×
989
                        .getJSONArray(AllConstants.ClientProcessing.COLUMNS).length()];
×
990

991
                for (int j = 0; j < columNames.length; j++) {
×
992
                    JSONObject columnObject = bindtypeObjects.getJSONObject(i).getJSONArray(AllConstants.ClientProcessing.COLUMNS)
×
993
                            .getJSONObject(j);
×
994

995
                    String name = columnObject.getString(AllConstants.ClientProcessing.NAME);
×
996
                    String dataType = columnObject.has(AllConstants.ClientProcessing.DATA_TYPES) ? columnObject.getString(AllConstants.ClientProcessing.DATA_TYPES) : AllConstants.ClientProcessing.VARCHAR;
×
997
                    columNames[j] =
×
998
                            ColumnDetails.builder().name(name).dataType(StringUtils.isBlank(dataType) ? AllConstants.ClientProcessing.VARCHAR : dataType).build();
×
999

1000
                }
1001
                bindtypes.add(new CommonRepositoryInformationHolder(bindname, columNames));
×
1002
                Timber.v("bind type logs %s", bindtypeObjects.getJSONObject(i).getString(AllConstants.ClientProcessing.NAME));
×
1003
            }
1004
        } catch (Exception e) {
×
1005
            Timber.e(e);
×
1006
        }
×
1007
    }
×
1008

1009
    public void getEcBindtypes() {
1010
        try {
1011
            if (this.applicationContext() == null) {
1✔
1012
                return;
1✔
1013
            }
1014
            String str = ReadFromfile(CoreLibrary.getInstance().getEcClientFieldsFile(), this.applicationContext());
1✔
1015
            if (StringUtils.isBlank(str)) {
1✔
1016
                return;
1✔
1017
            }
1018
            JSONObject jsonObject = new JSONObject(str);
1✔
1019
            JSONArray bindtypeObjects = jsonObject.getJSONArray("bindobjects");
1✔
1020

1021
            for (int i = 0; i < bindtypeObjects.length(); i++) {
1✔
1022
                JSONObject columnDefinitionObject = bindtypeObjects.getJSONObject(i);
1✔
1023
                String bindname = columnDefinitionObject.getString("name");
1✔
1024
                JSONArray columnsJsonArray = columnDefinitionObject.getJSONArray("columns");
1✔
1025
                List<ColumnDetails> columnNames = new ArrayList<>();
1✔
1026

1027
                // This adds the ability to have multiple mappings for one column and at the same time
1028
                // Prevents the app from crashing when creating the common repository
1029
                HashMap<String, ColumnDetails> uniqueColumnNames = new HashMap<>();
1✔
1030

1031
                for (int j = 0; j < columnsJsonArray.length(); j++) {
1✔
1032
                    JSONObject columnObject = columnsJsonArray.getJSONObject(j);
1✔
1033
                    String colName = columnObject.getString("column_name");
1✔
1034
                    String colType = columnObject.has("data_type") ? columnObject.getString("data_type") : "VARCHAR";
1✔
1035

1036
                    if (!uniqueColumnNames.containsKey(colName)) {
1✔
1037
                        ColumnDetails details = ColumnDetails.builder().name(colName).dataType(StringUtils.isBlank(colType) ? "VARCHAR" : colType).build();
1✔
1038
                        uniqueColumnNames.put(colName, details);
1✔
1039
                        columnNames.add(details);
1✔
1040
                    }
1041
                }
1042
                bindtypes.add(new CommonRepositoryInformationHolder(bindname, columnNames.toArray(new ColumnDetails[0])));
1✔
1043
                Timber.v("bind type logs %s", bindname);
1✔
1044
            }
1045
        } catch (Exception e) {
1✔
1046
            Timber.e(e);
1✔
1047
        }
1✔
1048

1049
    }
1✔
1050

1051
    public String ReadFromfile(String fileName, android.content.Context context) {
1052
        StringBuilder returnString = new StringBuilder();
1✔
1053
        InputStream fIn = null;
1✔
1054
        InputStreamReader isr = null;
1✔
1055
        BufferedReader input = null;
1✔
1056
        try {
1057
            fIn = context.getResources().getAssets()
1✔
1058
                    .open(fileName, android.content.Context.MODE_WORLD_READABLE);
1✔
1059
            isr = new InputStreamReader(fIn);
1✔
1060
            input = new BufferedReader(isr);
1✔
1061
            String line = "";
1✔
1062
            while ((line = input.readLine()) != null) {
1✔
1063
                returnString.append(line);
1✔
1064
            }
1065
        } catch (Exception e) {
1✔
1066
            Timber.e(e);
1✔
1067
        } finally {
1068
            try {
1069
                if (isr != null) {
1✔
1070
                    isr.close();
1✔
1071
                }
1072
                if (fIn != null) {
1✔
1073
                    fIn.close();
1✔
1074
                }
1075
                if (input != null) {
1✔
1076
                    input.close();
1✔
1077
                }
1078
            } catch (Exception e2) {
×
1079
                Timber.e(e2);
×
1080
            }
1✔
1081
        }
1082
        return returnString.toString();
1✔
1083
    }
1084

1085
    protected void setApplicationContext(android.content.Context applicationContext) {
1086
        this.applicationContext = applicationContext;
1✔
1087
    }
1✔
1088

1089
    public HTTPAgent getHttpAgent() {
1090
        return httpAgent();
1✔
1091
    }
1092

1093
    public Context updateCommonFtsObject(CommonFtsObject commonFtsObject) {
1094
        this.commonFtsObject = commonFtsObject;
1✔
1095
        return this;
1✔
1096
    }
1097

1098
    public CommonFtsObject commonFtsObject() {
1099
        return commonFtsObject;
1✔
1100
    }
1101

1102
    /**
1103
     * Linking generated concept with human readable values
1104
     *
1105
     * @param customHumanReadableConceptResponse
1106
     * @return
1107
     */
1108
    public Context updateCustomHumanReadableConceptResponse(Map<String, String>
1109
                                                                    customHumanReadableConceptResponse) {
1110
        this.customHumanReadableConceptResponse = customHumanReadableConceptResponse;
1✔
1111
        return this;
1✔
1112
    }
1113

1114
    public Map<String, String> customHumanReadableConceptResponse() {
1115
        if (customHumanReadableConceptResponse == null) {
1✔
1116
            return new HashMap<>();
1✔
1117
        }
1118
        return customHumanReadableConceptResponse;
1✔
1119
    }
1120

1121
    public Map<String, AllCommonsRepository> allCommonsRepositoryMap() {
1122
        Map<String, AllCommonsRepository> allCommonsRepositoryMap = new HashMap<String,
1✔
1123
                AllCommonsRepository>();
1124
        for (String ftsTable : commonFtsObject.getTables()) {
1✔
1125
            AllCommonsRepository allCommonsRepository = allCommonsRepositoryobjects(ftsTable);
1✔
1126
            allCommonsRepositoryMap.put(ftsTable, allCommonsRepository);
1✔
1127
        }
1128
        return allCommonsRepositoryMap;
1✔
1129
    }
1130

1131
    public void setDetailsRepository(DetailsRepository _detailsRepository) {
1132
        detailsRepository = _detailsRepository;
1✔
1133
    }
1✔
1134

1135
    public EventClientRepository getEventClientRepository() {
1136
        if (eventClientRepository == null) {
1✔
1137
            eventClientRepository = new EventClientRepository();
1✔
1138
        }
1139
        return eventClientRepository;
1✔
1140
    }
1141

1142
    public UniqueIdRepository getUniqueIdRepository() {
1143
        if (uniqueIdRepository == null) {
1✔
1144
            uniqueIdRepository = new UniqueIdRepository();
1✔
1145
        }
1146
        return uniqueIdRepository;
1✔
1147
    }
1148

1149
    public CampaignRepository getCampaignRepository() {
1150
        if (campaignRepository == null) {
1✔
1151
            campaignRepository = new CampaignRepository();
1✔
1152
        }
1153
        return campaignRepository;
1✔
1154
    }
1155

1156
    public TaskRepository getTaskRepository() {
1157
        if (taskRepository == null) {
1✔
1158
            taskNotesRepository = new TaskNotesRepository();
1✔
1159
            taskRepository = new TaskRepository(taskNotesRepository);
1✔
1160
        }
1161
        return taskRepository;
1✔
1162
    }
1163

1164
    public EventClientRepository getForeignEventClientRepository() {
1165
        if (foreignEventClientRepository == null) {
1✔
1166
            foreignEventClientRepository = new EventClientRepository(EventClientRepository.Table.foreignClient, EventClientRepository.Table.foreignEvent);
1✔
1167
        }
1168
        return foreignEventClientRepository;
1✔
1169
    }
1170

1171
    public boolean hasForeignEvents() {
1172
        return DrishtiApplication.getInstance().getP2PClassifier() != null;
1✔
1173
    }
1174

1175
    public LocationRepository getLocationRepository() {
1176
        if (locationRepository == null) {
1✔
1177
            locationRepository = new LocationRepository();
1✔
1178
        }
1179
        return locationRepository;
1✔
1180
    }
1181

1182
    public LocationTagRepository getLocationTagRepository() {
1183
        if (locationTagRepository == null) {
1✔
1184
            locationTagRepository = new LocationTagRepository();
1✔
1185
        }
1186
        return locationTagRepository;
1✔
1187
    }
1188

1189
    public StructureRepository getStructureRepository() {
1190
        if (structureRepository == null) {
1✔
1191
            structureRepository = new StructureRepository();
1✔
1192
        }
1193
        return structureRepository;
1✔
1194
    }
1195

1196
    public PlanDefinitionRepository getPlanDefinitionRepository() {
1197
        if (planDefinitionRepository == null) {
1✔
1198
            planDefinitionRepository = new PlanDefinitionRepository();
1✔
1199
        }
1200
        return planDefinitionRepository;
1✔
1201
    }
1202

1203
    public AppProperties getAppProperties() {
1204
        if (appProperties == null) {
1✔
1205
            appProperties = Utils.getProperties(this.applicationContext);
1✔
1206
        }
1207
        return appProperties;
1✔
1208
    }
1209

1210
    public ManifestRepository getManifestRepository() {
1211
        if (manifestRepository == null) {
1✔
1212
            manifestRepository = new ManifestRepository();
1✔
1213
        }
1214
        return manifestRepository;
1✔
1215
    }
1216

1217
    public ClientFormRepository getClientFormRepository() {
1218
        if (clientFormRepository == null) {
1✔
1219
            clientFormRepository = new ClientFormRepository();
1✔
1220
        }
1221
        return clientFormRepository;
1✔
1222
    }
1223

1224
    public ClientRelationshipRepository getClientRelationshipRepository() {
1225
        if (clientRelationshipRepository == null) {
1✔
1226
            clientRelationshipRepository = new ClientRelationshipRepository();
1✔
1227
        }
1228
        return clientRelationshipRepository;
1✔
1229
    }
1230

1231

1232
    public ZeirIdCleanupRepository zeirIdCleanupRepository() {
1233
        if (zeirIdCleanupRepository == null) {
1✔
1234
            zeirIdCleanupRepository = new ZeirIdCleanupRepository();
1✔
1235
        }
1236
        return zeirIdCleanupRepository;
1✔
1237
    }
1238

1239
    ///////////////////////////////////////////////////////////////////////////////
1240
}
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