Skip to content

Commit

Permalink
copy upload request entries to my space domain layer (linagora#573)
Browse files Browse the repository at this point in the history
(cherry picked from commit 3b10a57)
  • Loading branch information
Julian KOUNE authored and hoangdat committed Sep 28, 2021
1 parent 9ba62bb commit 61807ac
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 1 deletion.
1 change: 1 addition & 0 deletions domain/lib/domain.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
4 changes: 3 additions & 1 deletion domain/lib/src/model/copy/space_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// 3 and <http://www.linshare.org/licenses/LinShare-License_AfferoGPL-v3.pdf> 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 {
Expand All @@ -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';
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
// <http://www.linshare.org/licenses/LinShare-License_AfferoGPL-v3.pdf>
// 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
// <http://www.gnu.org/licenses/> for the GNU Affero General Public License version
// 3 and <http://www.linshare.org/licenses/LinShare-License_AfferoGPL-v3.pdf> 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<Either<Failure, Success>> execute(List<UploadRequestEntry> 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<Left>().length;

if (failedFileCount == 0) {
return Right(CopyMultipleToMySpaceFromUploadRequestEntriesAllSuccessViewState(listResult));
} else if (failedFileCount == listResult.length) {
return Left(CopyMultipleToMySpaceFromUploadRequestEntriesAllFailure(listResult));
}
return Right(CopyMultipleToMySpaceFromUploadRequestEntriesHasSomeFilesViewState(listResult));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,29 @@ class DownloadEntryIOSAllFailureViewState extends FeatureFailure {
List<Object> get props => [resultList];
}

class CopyMultipleToMySpaceFromUploadRequestEntriesAllSuccessViewState extends ViewState {
final List<Either<Failure, Success>> resultList;

CopyMultipleToMySpaceFromUploadRequestEntriesAllSuccessViewState(this.resultList);

@override
List<Object> get props => [resultList];
}

class CopyMultipleToMySpaceFromUploadRequestEntriesHasSomeFilesViewState extends ViewState {
final List<Either<Failure, Success>> resultList;

CopyMultipleToMySpaceFromUploadRequestEntriesHasSomeFilesViewState(this.resultList);

@override
List<Object> get props => [resultList];
}

class CopyMultipleToMySpaceFromUploadRequestEntriesAllFailure extends FeatureFailure {
final List<Either<Failure, Success>> resultList;

CopyMultipleToMySpaceFromUploadRequestEntriesAllFailure(this.resultList);

@override
List<Object> get props => [resultList];
}
Original file line number Diff line number Diff line change
@@ -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
// <http://www.linshare.org/licenses/LinShare-License_AfferoGPL-v3.pdf>
// 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
// <http://www.gnu.org/licenses/> for the GNU Affero General Public License version
// 3 and <http://www.linshare.org/licenses/LinShare-License_AfferoGPL-v3.pdf> 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<Failure, Success>(CopyToMySpaceViewState([document1])), Right<Failure, Success>(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<Failure, Success>(CopyToMySpaceFailure(exception)), Right<Failure, Success>(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<Failure, Success>(CopyMultipleToMySpaceFromUploadRequestEntriesAllFailure([Left<Failure, Success>(CopyToMySpaceFailure(exception)), Left<Failure, Success>(CopyToMySpaceFailure(exception))])));
});
});
}
1 change: 1 addition & 0 deletions lib/presentation/di/module/app_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ class AppModule {
getIt.registerFactory(() => UpdateUploadRequestGroupStateInteractor(getIt<UploadRequestGroupRepository>()));
getIt.registerFactory(() => UpdateMultipleUploadRequestGroupStateInteractor(getIt<UpdateUploadRequestGroupStateInteractor>()));
getIt.registerFactory(() => SearchUploadRequestEntriesInteractor());
getIt.registerFactory(() => CopyMultipleFilesFromUploadRequestEntriesToMySpaceInteractor(getIt<CopyToMySpaceInteractor>()));
}

void _provideSharePreference() {
Expand Down

0 comments on commit 61807ac

Please sign in to comment.