From 7ed52ed744927c41f0a8c03d02814f003cc6d32a Mon Sep 17 00:00:00 2001 From: Naveen Renati <154230258+naveenr-egov@users.noreply.github.com> Date: Wed, 18 Dec 2024 19:35:33 +0530 Subject: [PATCH] code rabbit comments resolved --- .../data/repositories/local/localization.dart | 3 +- .../lib/data/sync_registry.dart | 149 ++++++++++-------- .../lib/pages/login.dart | 2 +- .../lib/utils/localization_delegates.dart | 1 - .../lib/utils/utils.dart | 2 +- .../network_manager_provider_wrapper.dart | 6 - 6 files changed, 87 insertions(+), 76 deletions(-) diff --git a/apps/health_campaign_field_worker_app/lib/data/repositories/local/localization.dart b/apps/health_campaign_field_worker_app/lib/data/repositories/local/localization.dart index 0d8244287..ca1667f14 100644 --- a/apps/health_campaign_field_worker_app/lib/data/repositories/local/localization.dart +++ b/apps/health_campaign_field_worker_app/lib/data/repositories/local/localization.dart @@ -104,9 +104,10 @@ class LocalizationLocalRepository { FutureOr create( List result, LocalSqlDataStore sql) async { + if (result.isEmpty) return; return retryLocalCallOperation(() async { return sql.batch((batch) { - batch.insertAll(sql.localization, result); + batch.insertAllOnConflictUpdate(sql.localization, result); }); }); } diff --git a/apps/health_campaign_field_worker_app/lib/data/sync_registry.dart b/apps/health_campaign_field_worker_app/lib/data/sync_registry.dart index 518f786b5..331e08373 100644 --- a/apps/health_campaign_field_worker_app/lib/data/sync_registry.dart +++ b/apps/health_campaign_field_worker_app/lib/data/sync_registry.dart @@ -3,6 +3,7 @@ import 'package:complaints/models/pgr_complaints.dart'; import 'package:complaints/models/pgr_complaints_response.dart'; import 'package:digit_components/utils/app_logger.dart'; import 'package:digit_data_model/data_model.dart'; +import 'package:flutter/cupertino.dart'; import 'package:sync_service/data/repositories/sync/sync_up.dart'; class CustomSyncRegistry implements SyncUpOperation { @@ -12,17 +13,29 @@ class CustomSyncRegistry implements SyncUpOperation { @override Future update(List entities, LocalRepository local) async { - await remote.bulkUpdate(entities); + try { + await remote.bulkUpdate(entities); + } catch (e) { + debugPrint('$e'); + } } @override Future delete(List entities, LocalRepository local) async { - await remote.bulkDelete(entities); + try { + await remote.bulkDelete(entities); + } catch (e) { + debugPrint('$e'); + } } @override Future singleCreate(EntityModel entity, LocalRepository local) async { - await remote.singleCreate(entity); + try { + await remote.singleCreate(entity); + } catch (e) { + debugPrint('$e'); + } } @override @@ -34,76 +47,80 @@ class CustomSyncRegistry implements SyncUpOperation { operationGroupedEntity, required MapEntry>> typeGroupedEntity}) async { - switch (typeGroupedEntity.key) { - case DataModelType.complaints: - for (final entity in entities) { - if (remote is PgrServiceRemoteRepository && - entity is PgrServiceModel) { - final response = await remote.create(entity); - final responseData = response.data; - if (responseData is! Map) { - AppLogger.instance.error( - title: 'NetworkManager : PgrServiceRemoteRepository', - message: responseData, - stackTrace: StackTrace.current, - ); - continue; - } + try { + switch (typeGroupedEntity.key) { + case DataModelType.complaints: + for (final entity in entities) { + if (remote is PgrServiceRemoteRepository && + entity is PgrServiceModel) { + final response = await remote.create(entity); + final responseData = response.data; + if (responseData is! Map) { + AppLogger.instance.error( + title: 'NetworkManager : PgrServiceRemoteRepository', + message: responseData, + stackTrace: StackTrace.current, + ); + continue; + } - PgrServiceCreateResponseModel pgrServiceCreateResponseModel; - PgrComplaintResponseModel pgrComplaintModel; - try { - pgrServiceCreateResponseModel = - PgrServiceCreateResponseModelMapper.fromMap( - responseData, - ); - pgrComplaintModel = - pgrServiceCreateResponseModel.serviceWrappers.first; - } catch (e) { - rethrow; - } + PgrServiceCreateResponseModel pgrServiceCreateResponseModel; + PgrComplaintResponseModel pgrComplaintModel; + try { + pgrServiceCreateResponseModel = + PgrServiceCreateResponseModelMapper.fromMap( + responseData, + ); + pgrComplaintModel = + pgrServiceCreateResponseModel.serviceWrappers.first; + } catch (e) { + rethrow; + } - final service = pgrComplaintModel.service; - final serviceRequestId = service.serviceRequestId; + final service = pgrComplaintModel.service; + final serviceRequestId = service.serviceRequestId; - if (serviceRequestId == null || serviceRequestId.isEmpty) { - AppLogger.instance.error( - title: 'NetworkManager : PgrServiceRemoteRepository', - message: 'Service Request ID is null', - stackTrace: StackTrace.current, - ); - continue; - } - - await local.markSyncedUp( - entry: entry.firstWhere((element) => - element.clientReferenceId == entity.clientReferenceId), - clientReferenceId: entity.clientReferenceId, - nonRecoverableError: entity.nonRecoverableError, - ); + if (serviceRequestId == null || serviceRequestId.isEmpty) { + AppLogger.instance.error( + title: 'NetworkManager : PgrServiceRemoteRepository', + message: 'Service Request ID is null', + stackTrace: StackTrace.current, + ); + continue; + } - await local.opLogManager.updateServerGeneratedIds( - model: UpdateServerGeneratedIdModel( + await local.markSyncedUp( + entry: entry.firstWhere((element) => + element.clientReferenceId == entity.clientReferenceId), clientReferenceId: entity.clientReferenceId, - serverGeneratedId: serviceRequestId, - dataOperation: operationGroupedEntity.key, - rowVersion: entity.rowVersion, - ), - ); + nonRecoverableError: entity.nonRecoverableError, + ); - await local.update( - entity.copyWith( - serviceRequestId: serviceRequestId, - id: service.id, - applicationStatus: service.applicationStatus, - accountId: service.accountId, - ), - createOpLog: false, - ); + await local.opLogManager.updateServerGeneratedIds( + model: UpdateServerGeneratedIdModel( + clientReferenceId: entity.clientReferenceId, + serverGeneratedId: serviceRequestId, + dataOperation: operationGroupedEntity.key, + rowVersion: entity.rowVersion, + ), + ); + + await local.update( + entity.copyWith( + serviceRequestId: serviceRequestId, + id: service.id, + applicationStatus: service.applicationStatus, + accountId: service.accountId, + ), + createOpLog: false, + ); + } } - } - default: - await remote.bulkCreate(entities); + default: + await remote.bulkCreate(entities); + } + } catch (e) { + debugPrint('$e'); } } diff --git a/apps/health_campaign_field_worker_app/lib/pages/login.dart b/apps/health_campaign_field_worker_app/lib/pages/login.dart index cfba689e7..cb1277d20 100644 --- a/apps/health_campaign_field_worker_app/lib/pages/login.dart +++ b/apps/health_campaign_field_worker_app/lib/pages/login.dart @@ -234,7 +234,7 @@ class _LoginPageState extends LocalizedState { ), _password: FormControl( validators: [Validators.required], - value: 'eGov@123', + value: '', ), _privacyCheck: FormControl( value: false, diff --git a/apps/health_campaign_field_worker_app/lib/utils/localization_delegates.dart b/apps/health_campaign_field_worker_app/lib/utils/localization_delegates.dart index 3ac69b4c7..4da7c38a1 100644 --- a/apps/health_campaign_field_worker_app/lib/utils/localization_delegates.dart +++ b/apps/health_campaign_field_worker_app/lib/utils/localization_delegates.dart @@ -20,7 +20,6 @@ import 'package:referral_reconciliation/blocs/app_localization.dart' as referral_reconciliation_localization; import 'package:registration_delivery/blocs/app_localization.dart' as registration_delivery_localization; -import 'package:digit_components/blocs/localization.dart' as component_localization; import 'package:survey_form/blocs/app_localization.dart' as survey_form_localization; diff --git a/apps/health_campaign_field_worker_app/lib/utils/utils.dart b/apps/health_campaign_field_worker_app/lib/utils/utils.dart index fbcdb809f..fe1c005f5 100644 --- a/apps/health_campaign_field_worker_app/lib/utils/utils.dart +++ b/apps/health_campaign_field_worker_app/lib/utils/utils.dart @@ -100,7 +100,7 @@ performBackgroundService({ if (stopService) { if (isRunning) { - if (!isBackground && context != null) { + if (!isBackground && context != null && context.mounted) { if (context.mounted) { DigitToast.show( context, diff --git a/apps/health_campaign_field_worker_app/lib/widgets/network_manager_provider_wrapper.dart b/apps/health_campaign_field_worker_app/lib/widgets/network_manager_provider_wrapper.dart index 0e0af70d8..7b00ea572 100644 --- a/apps/health_campaign_field_worker_app/lib/widgets/network_manager_provider_wrapper.dart +++ b/apps/health_campaign_field_worker_app/lib/widgets/network_manager_provider_wrapper.dart @@ -15,15 +15,9 @@ import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:inventory_management/inventory_management.dart'; -import 'package:inventory_management/inventory_management.dart'; -import 'package:inventory_management/inventory_management.dart'; import 'package:isar/isar.dart'; import 'package:provider/provider.dart'; import 'package:referral_reconciliation/referral_reconciliation.dart'; -import 'package:referral_reconciliation/referral_reconciliation.dart'; -import 'package:referral_reconciliation/referral_reconciliation.dart'; -import 'package:registration_delivery/registration_delivery.dart'; -import 'package:registration_delivery/registration_delivery.dart'; import 'package:registration_delivery/registration_delivery.dart'; import 'package:survey_form/survey_form.dart';