From 61807ac97daf4de168162671b658493e22e461ee Mon Sep 17 00:00:00 2001 From: Julian KOUNE Date: Thu, 2 Sep 2021 16:08:56 +0200 Subject: [PATCH] copy upload request entries to my space domain layer (#573) (cherry picked from commit 3b10a57b16aeeda1fafd8335d793f00ef2e2e522) --- domain/lib/domain.dart | 1 + domain/lib/src/model/copy/space_type.dart | 4 +- ...equest_entries_to_my_space_interactor.dart | 59 +++++++++ .../upload_request_entry_view_state.dart | 26 ++++ ...pload_request_entries_interactor_test.dart | 113 ++++++++++++++++++ lib/presentation/di/module/app_module.dart | 1 + 6 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 domain/lib/src/usecases/upload_request_entry/copy_multiple_files_from_upload_request_entries_to_my_space_interactor.dart create mode 100644 domain/test/usecases/upload_request_entry/copy_multiple_files_to_my_space_from_upload_request_entries_interactor_test.dart diff --git a/domain/lib/domain.dart b/domain/lib/domain.dart index 328ccd479..8ecb74e33 100644 --- a/domain/lib/domain.dart +++ b/domain/lib/domain.dart @@ -366,3 +366,4 @@ export 'src/usecases/upload_request_entry/download_multiple_upload_request_entry export 'src/usecases/upload_request_group/add_recipients_upload_request_group_interactor.dart'; export 'src/usecases/search_upload_request_inside/search_upload_request_entries_interactor.dart'; export 'src/usecases/search_upload_request_inside/search_upload_request_entries_view_state.dart'; +export 'src/usecases/upload_request_entry/copy_multiple_files_from_upload_request_entries_to_my_space_interactor.dart'; diff --git a/domain/lib/src/model/copy/space_type.dart b/domain/lib/src/model/copy/space_type.dart index 57201382c..10d752dd1 100644 --- a/domain/lib/src/model/copy/space_type.dart +++ b/domain/lib/src/model/copy/space_type.dart @@ -29,7 +29,7 @@ // 3 and for // the Additional Terms applicable to LinShare software. -enum SpaceType { PERSONAL_SPACE, RECEIVED_SHARE, SHARED_SPACE } +enum SpaceType { PERSONAL_SPACE, RECEIVED_SHARE, SHARED_SPACE, UPLOAD_REQUEST } extension SpaceTypeExtension on SpaceType { String get value { @@ -40,6 +40,8 @@ extension SpaceTypeExtension on SpaceType { return 'RECEIVED_SHARE'; case SpaceType.SHARED_SPACE: return 'SHARED_SPACE'; + case SpaceType.UPLOAD_REQUEST: + return 'UPLOAD_REQUEST'; default: return 'PERSONAL_SPACE'; } diff --git a/domain/lib/src/usecases/upload_request_entry/copy_multiple_files_from_upload_request_entries_to_my_space_interactor.dart b/domain/lib/src/usecases/upload_request_entry/copy_multiple_files_from_upload_request_entries_to_my_space_interactor.dart new file mode 100644 index 000000000..f9eed9a53 --- /dev/null +++ b/domain/lib/src/usecases/upload_request_entry/copy_multiple_files_from_upload_request_entries_to_my_space_interactor.dart @@ -0,0 +1,59 @@ +// LinShare is an open source filesharing software, part of the LinPKI software +// suite, developed by Linagora. +// +// Copyright (C) 2021 LINAGORA +// +// This program is free software: you can redistribute it and/or modify it under the +// terms of the GNU Affero General Public License as published by the Free Software +// Foundation, either version 3 of the License, or (at your option) any later version, +// provided you comply with the Additional Terms applicable for LinShare software by +// Linagora pursuant to Section 7 of the GNU Affero General Public License, +// subsections (b), (c), and (e), pursuant to which you must notably (i) retain the +// display in the interface of the “LinShare™” trademark/logo, the "Libre & Free" mention, +// the words “You are using the Free and Open Source version of LinShare™, powered by +// Linagora © 2009–2020. Contribute to Linshare R&D by subscribing to an Enterprise +// offer!”. You must also retain the latter notice in all asynchronous messages such as +// e-mails sent with the Program, (ii) retain all hypertext links between LinShare and +// http://www.linshare.org, between linagora.com and Linagora, and (iii) refrain from +// infringing Linagora intellectual property rights over its trademarks and commercial +// brands. Other Additional Terms apply, see +// +// for more details. +// This program is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for +// more details. +// You should have received a copy of the GNU Affero General Public License and its +// applicable Additional Terms for LinShare along with this program. If not, see +// for the GNU Affero General Public License version +// 3 and for +// the Additional Terms applicable to LinShare software. +// + +import 'package:dartz/dartz.dart'; +import 'package:domain/domain.dart'; + +class CopyMultipleFilesFromUploadRequestEntriesToMySpaceInteractor { + final CopyToMySpaceInteractor _copyToMySpaceInteractor; + + CopyMultipleFilesFromUploadRequestEntriesToMySpaceInteractor(this._copyToMySpaceInteractor); + + Future> execute(List entries) async { + final copyRequestsList = entries.map((entry) => + CopyRequest(entry.uploadRequestEntryId.uuid, SpaceType.UPLOAD_REQUEST)).toList(); + final listResult = await Future.wait(copyRequestsList.map((element) => + _copyToMySpaceInteractor.execute(element))); + if (listResult.length == 1) { + return listResult.first; + } else { + var failedFileCount = listResult.whereType().length; + + if (failedFileCount == 0) { + return Right(CopyMultipleToMySpaceFromUploadRequestEntriesAllSuccessViewState(listResult)); + } else if (failedFileCount == listResult.length) { + return Left(CopyMultipleToMySpaceFromUploadRequestEntriesAllFailure(listResult)); + } + return Right(CopyMultipleToMySpaceFromUploadRequestEntriesHasSomeFilesViewState(listResult)); + } + } +} diff --git a/domain/lib/src/usecases/upload_request_entry/upload_request_entry_view_state.dart b/domain/lib/src/usecases/upload_request_entry/upload_request_entry_view_state.dart index 3edafd482..3d49821bd 100644 --- a/domain/lib/src/usecases/upload_request_entry/upload_request_entry_view_state.dart +++ b/domain/lib/src/usecases/upload_request_entry/upload_request_entry_view_state.dart @@ -113,3 +113,29 @@ class DownloadEntryIOSAllFailureViewState extends FeatureFailure { List get props => [resultList]; } +class CopyMultipleToMySpaceFromUploadRequestEntriesAllSuccessViewState extends ViewState { + final List> resultList; + + CopyMultipleToMySpaceFromUploadRequestEntriesAllSuccessViewState(this.resultList); + + @override + List get props => [resultList]; +} + +class CopyMultipleToMySpaceFromUploadRequestEntriesHasSomeFilesViewState extends ViewState { + final List> resultList; + + CopyMultipleToMySpaceFromUploadRequestEntriesHasSomeFilesViewState(this.resultList); + + @override + List get props => [resultList]; +} + +class CopyMultipleToMySpaceFromUploadRequestEntriesAllFailure extends FeatureFailure { + final List> resultList; + + CopyMultipleToMySpaceFromUploadRequestEntriesAllFailure(this.resultList); + + @override + List get props => [resultList]; +} diff --git a/domain/test/usecases/upload_request_entry/copy_multiple_files_to_my_space_from_upload_request_entries_interactor_test.dart b/domain/test/usecases/upload_request_entry/copy_multiple_files_to_my_space_from_upload_request_entries_interactor_test.dart new file mode 100644 index 000000000..0869d8afa --- /dev/null +++ b/domain/test/usecases/upload_request_entry/copy_multiple_files_to_my_space_from_upload_request_entries_interactor_test.dart @@ -0,0 +1,113 @@ +// LinShare is an open source filesharing software, part of the LinPKI software +// suite, developed by Linagora. +// +// Copyright (C) 2020 LINAGORA +// +// This program is free software: you can redistribute it and/or modify it under the +// terms of the GNU Affero General Public License as published by the Free Software +// Foundation, either version 3 of the License, or (at your option) any later version, +// provided you comply with the Additional Terms applicable for LinShare software by +// Linagora pursuant to Section 7 of the GNU Affero General Public License, +// subsections (b), (c), and (e), pursuant to which you must notably (i) retain the +// display in the interface of the “LinShare™” trademark/logo, the "Libre & Free" mention, +// the words “You are using the Free and Open Source version of LinShare™, powered by +// Linagora © 2009–2020. Contribute to Linshare R&D by subscribing to an Enterprise +// offer!”. You must also retain the latter notice in all asynchronous messages such as +// e-mails sent with the Program, (ii) retain all hypertext links between LinShare and +// http://www.linshare.org, between linagora.com and Linagora, and (iii) refrain from +// infringing Linagora intellectual property rights over its trademarks and commercial +// brands. Other Additional Terms apply, see +// +// for more details. +// This program is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for +// more details. +// You should have received a copy of the GNU Affero General Public License and its +// applicable Additional Terms for LinShare along with this program. If not, see +// for the GNU Affero General Public License version +// 3 and for +// the Additional Terms applicable to LinShare software. +// + +import 'package:dartz/dartz.dart'; +import 'package:domain/domain.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/mockito.dart'; +import 'package:testshared/fixture/upload_request_entry_fixture.dart'; +import 'package:testshared/testshared.dart'; + +import '../../mock/repository/authentication/mock_document_repository.dart'; + +void main() { + group('copy_multiples_files_to_my_space_from_upload_request_entries_interactor tests', () { + late MockDocumentRepository documentRepository; + late CopyToMySpaceInteractor copyToMySpaceInteractor; + late CopyMultipleFilesFromUploadRequestEntriesToMySpaceInteractor _copyMultipleFilesFromUploadRequestEntriesToMySpaceInteractor; + + setUp(() { + documentRepository = MockDocumentRepository(); + copyToMySpaceInteractor = CopyToMySpaceInteractor(documentRepository); + _copyMultipleFilesFromUploadRequestEntriesToMySpaceInteractor = CopyMultipleFilesFromUploadRequestEntriesToMySpaceInteractor(copyToMySpaceInteractor); + }); + + test('copy multiples files to my space from upload request entries interactor should return success with valid data', () async { + when(documentRepository.copyToMySpace( + CopyRequest(uploadRequestEntry1.uploadRequestEntryId.uuid, SpaceType.UPLOAD_REQUEST))) + .thenAnswer((_) async => [document1]); + + when(documentRepository.copyToMySpace( + CopyRequest(uploadRequestEntry2.uploadRequestEntryId.uuid, SpaceType.UPLOAD_REQUEST))) + .thenAnswer((_) async => [document2]); + + final result = await _copyMultipleFilesFromUploadRequestEntriesToMySpaceInteractor.execute([uploadRequestEntry1, uploadRequestEntry2]); + final resultsList = result + .map((success) => (success as CopyMultipleToMySpaceFromUploadRequestEntriesAllSuccessViewState).resultList) + .getOrElse(() => []); + expect(resultsList, [Right(CopyToMySpaceViewState([document1])), Right(CopyToMySpaceViewState([document2]))]); + }); + + test('copy multiples files to my space from upload request entries interactor should return success with some failures', () async { + final exception = DocumentNotFound(); + when(documentRepository.copyToMySpace( + CopyRequest(uploadRequestEntry1.uploadRequestEntryId.uuid, SpaceType.UPLOAD_REQUEST))) + .thenThrow(exception); + + when(documentRepository.copyToMySpace( + CopyRequest(uploadRequestEntry2.uploadRequestEntryId.uuid, SpaceType.UPLOAD_REQUEST))) + .thenAnswer((_) async => [document2]); + + final result = await _copyMultipleFilesFromUploadRequestEntriesToMySpaceInteractor.execute([uploadRequestEntry1, uploadRequestEntry2]); + final resultsList = result + .map((success) => (success as CopyMultipleToMySpaceFromUploadRequestEntriesHasSomeFilesViewState).resultList) + .getOrElse(() => []); + expect(resultsList, [Left(CopyToMySpaceFailure(exception)), Right(CopyToMySpaceViewState([document2]))]); + }); + + test('copy multiples files to my space from upload request entries interactor should return success with one document', () async { + when(documentRepository.copyToMySpace( + CopyRequest(uploadRequestEntry1.uploadRequestEntryId.uuid, SpaceType.UPLOAD_REQUEST))) + .thenAnswer((_) async => [document1]); + + final result = await _copyMultipleFilesFromUploadRequestEntriesToMySpaceInteractor.execute([uploadRequestEntry1]); + final documentsList = result + .map((success) => (success as CopyToMySpaceViewState).documentsList) + .getOrElse(() => []); + expect(documentsList, [document1]); + }); + + test('copy multiples files to my space from upload request entries interactor should fail with only failures', () async { + final exception = DocumentNotFound(); + when(documentRepository.copyToMySpace( + CopyRequest(uploadRequestEntry1.uploadRequestEntryId.uuid, SpaceType.UPLOAD_REQUEST))) + .thenThrow(exception); + + when(documentRepository.copyToMySpace( + CopyRequest(uploadRequestEntry2.uploadRequestEntryId.uuid, SpaceType.UPLOAD_REQUEST))) + .thenThrow(exception); + + final result = await _copyMultipleFilesFromUploadRequestEntriesToMySpaceInteractor.execute([uploadRequestEntry1, uploadRequestEntry2]); + expect(result, Left(CopyMultipleToMySpaceFromUploadRequestEntriesAllFailure([Left(CopyToMySpaceFailure(exception)), Left(CopyToMySpaceFailure(exception))]))); + }); + }); +} diff --git a/lib/presentation/di/module/app_module.dart b/lib/presentation/di/module/app_module.dart index 16d454d59..9c26106f4 100644 --- a/lib/presentation/di/module/app_module.dart +++ b/lib/presentation/di/module/app_module.dart @@ -384,6 +384,7 @@ class AppModule { getIt.registerFactory(() => UpdateUploadRequestGroupStateInteractor(getIt())); getIt.registerFactory(() => UpdateMultipleUploadRequestGroupStateInteractor(getIt())); getIt.registerFactory(() => SearchUploadRequestEntriesInteractor()); + getIt.registerFactory(() => CopyMultipleFilesFromUploadRequestEntriesToMySpaceInteractor(getIt())); } void _provideSharePreference() {