Migrate Hive box To IsolatedHive box
Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
@@ -1,118 +1,61 @@
|
||||
import 'package:tmail_ui_user/features/caching/clients/recent_login_url_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/caching/clients/recent_login_username_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/cleanup/data/local/recent_login_url_cache_manager.dart';
|
||||
import 'package:tmail_ui_user/features/cleanup/data/local/recent_login_username_cache_manager.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/datasource/login_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/model/recent_login_url_cache.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/model/recent_login_username_cache.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/extensions/list_recent_login_url_extension.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/extensions/list_recent_login_username_extension.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/model/recent_login_url.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/model/recent_login_username.dart';
|
||||
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
|
||||
|
||||
class HiveLoginDataSourceImpl implements LoginDataSource {
|
||||
|
||||
final RecentLoginUrlCacheClient _recentLoginUrlCacheClient;
|
||||
final RecentLoginUsernameCacheClient _recentLoginUsernameCacheClient;
|
||||
final RecentLoginUrlCacheManager _recentLoginUrlCacheManager;
|
||||
final RecentLoginUsernameCacheManager _recentLoginUsernameCacheManager;
|
||||
final ExceptionThrower _exceptionThrower;
|
||||
|
||||
HiveLoginDataSourceImpl(
|
||||
this._recentLoginUrlCacheClient,
|
||||
this._recentLoginUsernameCacheClient,
|
||||
this._recentLoginUrlCacheManager,
|
||||
this._recentLoginUsernameCacheManager,
|
||||
this._exceptionThrower
|
||||
);
|
||||
|
||||
@override
|
||||
Future<void> saveLoginUrl(RecentLoginUrl recentLoginUrl) {
|
||||
return Future.sync(() async {
|
||||
if (await _recentLoginUrlCacheClient.isExistItem(recentLoginUrl.url)) {
|
||||
return await _recentLoginUrlCacheClient.updateItem(
|
||||
recentLoginUrl.url,
|
||||
recentLoginUrl.toRecentLoginUrlCache()
|
||||
);
|
||||
} else {
|
||||
return await _recentLoginUrlCacheClient.insertItem(
|
||||
recentLoginUrl.url,
|
||||
recentLoginUrl.toRecentLoginUrlCache()
|
||||
);
|
||||
}
|
||||
return await _recentLoginUrlCacheManager.saveLoginUrl(
|
||||
recentLoginUrl.toRecentLoginUrlCache(),
|
||||
);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<RecentLoginUrl>> getAllRecentLoginUrlLatest({int? limit, String? pattern}) {
|
||||
return Future.sync(() async {
|
||||
final listRecentUrlCache = await _recentLoginUrlCacheClient.getAll();
|
||||
final listRecentUrl = listRecentUrlCache
|
||||
.where((recentCache) => _filterRecentUrlCache(recentCache, pattern))
|
||||
.map((recentCache) => recentCache.toRecentLoginUrl())
|
||||
.toList();
|
||||
listRecentUrl.sortByCreationDate();
|
||||
|
||||
final newLimit = limit ?? 5;
|
||||
|
||||
final newListRecentSUrl = listRecentUrl.length > newLimit
|
||||
? listRecentUrl.sublist(0, newLimit)
|
||||
: listRecentUrl;
|
||||
|
||||
return newListRecentSUrl;
|
||||
return await _recentLoginUrlCacheManager.getAllRecentLoginUrlLatest(
|
||||
limit: limit,
|
||||
pattern: pattern,
|
||||
);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
bool _filterRecentUrlCache(RecentLoginUrlCache recentLoginUrlCache, String? pattern) {
|
||||
if (pattern == null || pattern.trim().isEmpty) {
|
||||
return true;
|
||||
} else {
|
||||
return recentLoginUrlCache.matchUrl(pattern);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<RecentLoginUsername>> getAllRecentLoginUsernamesLatest({int? limit, String? pattern}) {
|
||||
return Future.sync(() async {
|
||||
final listRecentUsernameCache = await _recentLoginUsernameCacheClient.getAll();
|
||||
final listValidRecentUsername = listRecentUsernameCache
|
||||
.where((recentCache) => _filterRecentLoginUsernameCache(recentCache, pattern))
|
||||
.map((recentCache) => recentCache.toRecentLoginUsername())
|
||||
.toList();
|
||||
|
||||
listValidRecentUsername.sortByCreationDate();
|
||||
|
||||
final newLimit = limit ?? 5;
|
||||
|
||||
return listValidRecentUsername.length > newLimit
|
||||
? listValidRecentUsername.sublist(0, newLimit)
|
||||
: listValidRecentUsername;
|
||||
return await _recentLoginUsernameCacheManager.getAllRecentLoginUsernamesLatest(
|
||||
limit: limit,
|
||||
pattern: pattern,
|
||||
);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> saveLoginUsername(RecentLoginUsername recentLoginUsername) {
|
||||
return Future.sync(() async {
|
||||
if (await _recentLoginUsernameCacheClient.isExistItem(recentLoginUsername.username)) {
|
||||
return await _recentLoginUsernameCacheClient.updateItem(
|
||||
recentLoginUsername.username,
|
||||
recentLoginUsername.toRecentLoginUsernameCache()
|
||||
);
|
||||
} else {
|
||||
return await _recentLoginUsernameCacheClient.insertItem(
|
||||
recentLoginUsername.username,
|
||||
recentLoginUsername.toRecentLoginUsernameCache()
|
||||
);
|
||||
}
|
||||
return await _recentLoginUsernameCacheManager.saveLoginUsername(
|
||||
recentLoginUsername,
|
||||
);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
bool _filterRecentLoginUsernameCache(
|
||||
RecentLoginUsernameCache recentLoginUsernameCache,
|
||||
String? pattern
|
||||
) {
|
||||
if (pattern == null || pattern.trim().isEmpty) {
|
||||
return true;
|
||||
} else {
|
||||
return recentLoginUsernameCache.matchUsername(pattern);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String> dnsLookupToGetJmapUrl(String emailAddress) {
|
||||
throw UnimplementedError();
|
||||
|
||||
@@ -2,12 +2,13 @@ import 'package:collection/collection.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:model/account/personal_account.dart';
|
||||
import 'package:tmail_ui_user/features/caching/clients/account_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/caching/interaction/cache_manager_interaction.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/extensions/account_cache_extensions.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/extensions/list_account_cache_extensions.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/extensions/personal_account_extension.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/exceptions/authentication_exception.dart';
|
||||
|
||||
class AccountCacheManager {
|
||||
class AccountCacheManager extends CacheManagerInteraction {
|
||||
final AccountCacheClient _accountCacheClient;
|
||||
|
||||
AccountCacheManager(this._accountCacheClient);
|
||||
@@ -47,4 +48,20 @@ class AccountCacheManager {
|
||||
log('AccountCacheManager::deleteCurrentAccount(): $hashId');
|
||||
return _accountCacheClient.deleteItem(hashId);
|
||||
}
|
||||
|
||||
Future<void> clear() => _accountCacheClient.clearAllData();
|
||||
|
||||
@override
|
||||
Future<void> migrateHiveToIsolatedHive() async {
|
||||
try {
|
||||
final legacyMapItems = await _accountCacheClient.getMapItems(
|
||||
isolated: false,
|
||||
);
|
||||
log('$runtimeType::migrateHiveToIsolatedHive(): Length of legacyMapItems: ${legacyMapItems.length}');
|
||||
await _accountCacheClient.insertMultipleItem(legacyMapItems);
|
||||
log('$runtimeType::migrateHiveToIsolatedHive(): ✅ Migrate Hive box "${_accountCacheClient.tableName}" → IsolatedHive DONE');
|
||||
} catch (e) {
|
||||
logError('$runtimeType::migrateHiveToIsolatedHive(): ❌ Migrate Hive box "${_accountCacheClient.tableName}" → IsolatedHive FAILED, Error: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:tmail_ui_user/features/caching/clients/authentication_info_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/caching/interaction/cache_manager_interaction.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/model/authentication_info_cache.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/exceptions/authentication_exception.dart';
|
||||
|
||||
class AuthenticationInfoCacheManager {
|
||||
class AuthenticationInfoCacheManager extends CacheManagerInteraction {
|
||||
final AuthenticationInfoCacheClient _authenticationInfoCacheClient;
|
||||
|
||||
AuthenticationInfoCacheManager(this._authenticationInfoCacheClient);
|
||||
@@ -25,4 +27,18 @@ class AuthenticationInfoCacheManager {
|
||||
Future<void> removeAuthenticationInfo() {
|
||||
return _authenticationInfoCacheClient.deleteItem(AuthenticationInfoCache.keyCacheValue);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> migrateHiveToIsolatedHive() async {
|
||||
try {
|
||||
final legacyMapItems = await _authenticationInfoCacheClient.getMapItems(
|
||||
isolated: false,
|
||||
);
|
||||
log('$runtimeType::migrateHiveToIsolatedHive(): Length of legacyMapItems: ${legacyMapItems.length}');
|
||||
await _authenticationInfoCacheClient.insertMultipleItem(legacyMapItems);
|
||||
log('$runtimeType::migrateHiveToIsolatedHive(): ✅ Migrate Hive box "${_authenticationInfoCacheClient.tableName}" → IsolatedHive DONE');
|
||||
} catch (e) {
|
||||
logError('$runtimeType::migrateHiveToIsolatedHive(): ❌ Migrate Hive box "${_authenticationInfoCacheClient.tableName}" → IsolatedHive FAILED, Error: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:tmail_ui_user/features/caching/clients/encryption_key_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/caching/interaction/cache_manager_interaction.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/model/encryption_key_cache.dart';
|
||||
|
||||
class EncryptionKeyCacheManager {
|
||||
class EncryptionKeyCacheManager extends CacheManagerInteraction {
|
||||
final EncryptionKeyCacheClient _encryptionKeyCacheClient;
|
||||
|
||||
EncryptionKeyCacheManager(this._encryptionKeyCacheClient);
|
||||
@@ -15,4 +17,18 @@ class EncryptionKeyCacheManager {
|
||||
Future<EncryptionKeyCache?> getEncryptionKeyStored() {
|
||||
return _encryptionKeyCacheClient.getItem(EncryptionKeyCache.keyCacheValue);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> migrateHiveToIsolatedHive() async {
|
||||
try {
|
||||
final legacyMapItems = await _encryptionKeyCacheClient.getMapItems(
|
||||
isolated: false,
|
||||
);
|
||||
log('$runtimeType::migrateHiveToIsolatedHive(): Length of legacyMapItems: ${legacyMapItems.length}');
|
||||
await _encryptionKeyCacheClient.insertMultipleItem(legacyMapItems);
|
||||
log('$runtimeType::migrateHiveToIsolatedHive(): ✅ Migrate Hive box "${_encryptionKeyCacheClient.tableName}" → IsolatedHive DONE');
|
||||
} catch (e) {
|
||||
logError('$runtimeType::migrateHiveToIsolatedHive(): ❌ Migrate Hive box "${_encryptionKeyCacheClient.tableName}" → IsolatedHive FAILED, Error: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import 'package:core/utils/app_logger.dart';
|
||||
import 'package:model/oidc/oidc_configuration.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:tmail_ui_user/features/caching/clients/oidc_configuration_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/caching/interaction/cache_manager_interaction.dart';
|
||||
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/extensions/oidc_configutation_cache_extension.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/network/config/oidc_constant.dart';
|
||||
@@ -9,7 +10,7 @@ import 'package:tmail_ui_user/features/login/data/network/oidc_error.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/extensions/oidc_configuration_extensions.dart';
|
||||
import 'package:tmail_ui_user/main/utils/app_config.dart';
|
||||
|
||||
class OidcConfigurationCacheManager {
|
||||
class OidcConfigurationCacheManager extends CacheManagerInteraction {
|
||||
final SharedPreferences _sharedPreferences;
|
||||
final OidcConfigurationCacheClient _oidcConfigurationCacheClient;
|
||||
|
||||
@@ -51,4 +52,18 @@ class OidcConfigurationCacheManager {
|
||||
_sharedPreferences.remove(OIDCConstant.keyAuthorityOidc),
|
||||
]);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> migrateHiveToIsolatedHive() async {
|
||||
try {
|
||||
final legacyMapItems = await _oidcConfigurationCacheClient.getMapItems(
|
||||
isolated: false,
|
||||
);
|
||||
log('$runtimeType::migrateHiveToIsolatedHive(): Length of legacyMapItems: ${legacyMapItems.length}');
|
||||
await _oidcConfigurationCacheClient.insertMultipleItem(legacyMapItems);
|
||||
log('$runtimeType::migrateHiveToIsolatedHive(): ✅ Migrate Hive box "${_oidcConfigurationCacheClient.tableName}" → IsolatedHive DONE');
|
||||
} catch (e) {
|
||||
logError('$runtimeType::migrateHiveToIsolatedHive(): ❌ Migrate Hive box "${_oidcConfigurationCacheClient.tableName}" → IsolatedHive FAILED, Error: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:model/oidc/token_oidc.dart';
|
||||
import 'package:tmail_ui_user/features/caching/clients/token_oidc_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/caching/interaction/cache_manager_interaction.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/extensions/token_oidc_cache_extension.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/extensions/token_oidc_extension.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/exceptions/authentication_exception.dart';
|
||||
|
||||
class TokenOidcCacheManager {
|
||||
class TokenOidcCacheManager extends CacheManagerInteraction {
|
||||
final TokenOidcCacheClient _tokenOidcCacheClient;
|
||||
|
||||
TokenOidcCacheManager(this._tokenOidcCacheClient);
|
||||
@@ -34,4 +35,18 @@ class TokenOidcCacheManager {
|
||||
Future<void> deleteTokenOidc() async {
|
||||
await _tokenOidcCacheClient.clearAllData();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> migrateHiveToIsolatedHive() async {
|
||||
try {
|
||||
final legacyMapItems = await _tokenOidcCacheClient.getMapItems(
|
||||
isolated: false,
|
||||
);
|
||||
log('$runtimeType::migrateHiveToIsolatedHive(): Length of legacyMapItems: ${legacyMapItems.length}');
|
||||
await _tokenOidcCacheClient.insertMultipleItem(legacyMapItems);
|
||||
log('$runtimeType::migrateHiveToIsolatedHive(): ✅ Migrate Hive box "${_tokenOidcCacheClient.tableName}" → IsolatedHive DONE');
|
||||
} catch (e) {
|
||||
logError('$runtimeType::migrateHiveToIsolatedHive(): ❌ Migrate Hive box "${_tokenOidcCacheClient.tableName}" → IsolatedHive FAILED, Error: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user