diff --git a/docs/implement-import.md b/docs/implement-import.md index 51972c56d..01066ca6b 100644 --- a/docs/implement-import.md +++ b/docs/implement-import.md @@ -1,4 +1,4 @@ ## Implement import -* Create a new class `lib/service/BoardImportService.php` where `` is the name of the source system. -* Use the `lib/service/BoardImportTrelloJsonService.php` class as inspiration \ No newline at end of file +* Create a new class `lib/Service/Importer/Systems/Service.php` where `` is the name of the source system. +* Use the `lib/Service/Importer/Systems/TrelloJsonService.php` class as inspiration \ No newline at end of file diff --git a/docs/resources/BoardImport.svg b/docs/resources/BoardImport.svg index 1d17034a8..167f85f1a 100644 --- a/docs/resources/BoardImport.svg +++ b/docs/resources/BoardImport.svg @@ -4,211 +4,211 @@ - + G - + A0 - - - -Classes used on -board import. -Methods just to -illustrate. + + + +Classes used on +board import. +Methods just to +illustrate. A1 - -ApiController + +ApiController A2 - -BoardImportApiController - -+import() -+getAllowedSystems() -+getConfigSchema() + +BoardImportApiController + ++import() ++getAllowedSystems() ++getConfigSchema() A1->A2 - - + + A3 - -BoardImportService - -+import() -+bootstrap() -+validateSystem() -#validateConfig() -#validateData() + +BoardImportService + ++import() ++bootstrap() ++validateSystem() +#validateConfig() +#validateData() A2->A3 - - -uses + + +uses A7 - -BoardImportTrelloApiService - -+name:string + +TrelloApiService + ++name:string A3->A7 - - -uses + + +uses A9 - -BoardImportTrelloJsonService - -+name:string -#needValidateData:true + +TrelloJsonService + ++name:string +#needValidateData:true A3->A9 - - -uses + + +uses A10 - - - -validateSystem is -public because is -used on Api. + + + +validateSystem is +public because is +used on Api. A3->A10 - + A4 - -Command + +Command A5 - -BoardImport - -+boardImportCommandService - -#configure() -#execute(input,output) + +BoardImport + ++boardImportCommandService + +#configure() +#execute(input,output) A4->A5 - - + + A6 - -BoardImportCommandService - -+bootstrap() -+import() -+validateSystem() -#validateConfig() -#validateData() + +BoardImportCommandService + ++bootstrap() ++import() ++validateSystem() +#validateConfig() +#validateData() A5->A6 - - -uses + + +uses A6->A3 - - + + A7->A3 - - -uses + + +uses A8 - -<<abstract>> -ABoardImportService - -#needValidateData:false - -+needValidateData():bool + +<<abstract>> +ABoardImportService + +#needValidateData:false + ++needValidateData():bool A7->A8 - - -implements + + +implements A9->A3 - - -uses + + +uses A9->A8 - - -implements + + +implements A11 - - - -To create an import -to another system, -create another class -similar to this. + + + +To create an import +to another system, +create another class +similar to this. A9->A11 - + diff --git a/docs/resources/BoardImport.yuml b/docs/resources/BoardImport.yuml index cbe89c829..4c681b79f 100644 --- a/docs/resources/BoardImport.yuml +++ b/docs/resources/BoardImport.yuml @@ -13,12 +13,12 @@ [BoardImport]uses-.->[BoardImportCommandService|+bootstrap();+import();+validateSystem();#validateConfig();#validateData()] [BoardImportCommandService]->[BoardImportService] -[BoardImportService]uses-.->[BoardImportTrelloApiService|+name:string] -[BoardImportTrelloApiService]uses-.->[BoardImportService] -[BoardImportTrelloApiService]implements-.-^[<> ABoardImportService|#needValidateData:false|+needValidateData():bool] +[BoardImportService]uses-.->[TrelloApiService|+name:string] +[TrelloApiService]uses-.->[BoardImportService] +[TrelloApiService]implements-.-^[<> ABoardImportService|#needValidateData:false|+needValidateData():bool] -[BoardImportService]uses-.->[BoardImportTrelloJsonService|+name:string;#needValidateData:true] -[BoardImportTrelloJsonService]uses-.->[BoardImportService] +[BoardImportService]uses-.->[TrelloJsonService|+name:string;#needValidateData:true] +[TrelloJsonService]uses-.->[BoardImportService] [BoardImportService]-[note: validateSystem is public because is used on Api. {bg:cornsilk}] -[BoardImportTrelloJsonService]-[note: To create an import to another system, create another class similar to this. {bg:cornsilk}] -[BoardImportTrelloJsonService]implements-.-^[<> ABoardImportService] +[TrelloJsonService]-[note: To create an import to another system, create another class similar to this. {bg:cornsilk}] +[TrelloJsonService]implements-.-^[<> ABoardImportService] diff --git a/lib/Command/BoardImport.php b/lib/Command/BoardImport.php index 0674b128a..15fec07b2 100644 --- a/lib/Command/BoardImport.php +++ b/lib/Command/BoardImport.php @@ -23,7 +23,7 @@ namespace OCA\Deck\Command; -use OCA\Deck\Service\BoardImportCommandService; +use OCA\Deck\Service\Importer\BoardImportCommandService; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; diff --git a/lib/Controller/BoardImportApiController.php b/lib/Controller/BoardImportApiController.php index 2d2545105..ec7e76cae 100644 --- a/lib/Controller/BoardImportApiController.php +++ b/lib/Controller/BoardImportApiController.php @@ -23,7 +23,7 @@ namespace OCA\Deck\Controller; -use OCA\Deck\Service\BoardImportService; +use OCA\Deck\Service\Importer\BoardImportService; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCSController; diff --git a/lib/Service/ABoardImportService.php b/lib/Service/Importer/ABoardImportService.php similarity index 98% rename from lib/Service/ABoardImportService.php rename to lib/Service/Importer/ABoardImportService.php index cbadca6b6..68a65cbdc 100644 --- a/lib/Service/ABoardImportService.php +++ b/lib/Service/Importer/ABoardImportService.php @@ -21,7 +21,7 @@ * */ -namespace OCA\Deck\Service; +namespace OCA\Deck\Service\Importer; use OCA\Deck\Db\Acl; use OCA\Deck\Db\Assignment; diff --git a/lib/Service/BoardImportCommandService.php b/lib/Service/Importer/BoardImportCommandService.php similarity index 96% rename from lib/Service/BoardImportCommandService.php rename to lib/Service/Importer/BoardImportCommandService.php index 1f09853da..8e25f417f 100644 --- a/lib/Service/BoardImportCommandService.php +++ b/lib/Service/Importer/BoardImportCommandService.php @@ -21,7 +21,7 @@ * */ -namespace OCA\Deck\Service; +namespace OCA\Deck\Service\Importer; use OCA\Deck\Exceptions\ConflictException; use OCA\Deck\NotFoundException; @@ -80,7 +80,7 @@ class BoardImportCommandService extends BoardImportService { $config = $this->getInput()->getOption('config'); if (is_string($config)) { if (!is_file($config)) { - throw new NotFoundException('It\'s not a file.'); + throw new NotFoundException('It\'s not a valid config file.'); } $config = json_decode(file_get_contents($config)); if (!$config instanceof \stdClass) { @@ -94,6 +94,7 @@ class BoardImportCommandService extends BoardImportService { $this->getOutput()->writeln('' . $e->getMessage() . ''); $helper = $this->getCommand()->getHelper('question'); $question = new Question( + "You can get more info on https://deck.readthedocs.io/en/latest/User_documentation_en/#6-import-boards\n" . 'Please inform a valid config json file: ', 'config.json' ); diff --git a/lib/Service/BoardImportService.php b/lib/Service/Importer/BoardImportService.php similarity index 95% rename from lib/Service/BoardImportService.php rename to lib/Service/Importer/BoardImportService.php index 7b6372ddf..d6de6cd80 100644 --- a/lib/Service/BoardImportService.php +++ b/lib/Service/Importer/BoardImportService.php @@ -21,7 +21,7 @@ * */ -namespace OCA\Deck\Service; +namespace OCA\Deck\Service\Importer; use JsonSchema\Constraints\Constraint; use JsonSchema\Validator; @@ -163,20 +163,10 @@ class BoardImportService { public function getAllowedImportSystems(): array { if (!$this->allowedSystems) { - $allowedSystems = glob(__DIR__ . '/BoardImport*Service.php'); - $allowedSystems = array_filter($allowedSystems, function (string $name) { - $name = basename($name); - switch ($name) { - case 'ABoardImportService.php': - case 'BoardImportService.php': - case 'BoardImportCommandService.php': - return false; - } - return true; - }); + $allowedSystems = glob(__DIR__ . '/Systems/*Service.php'); $allowedSystems = array_map(function ($filename) { - preg_match('/\/(?BoardImport(?\w+)Service)\.php$/', $filename, $matches); - $className = 'OCA\Deck\Service\\'.$matches['class']; + preg_match('/\/(?(?\w+)Service)\.php$/', $filename, $matches); + $className = 'OCA\Deck\Service\Importer\Systems\\'.$matches['class']; if (!class_exists($className)) { /** @psalm-suppress UnresolvableInclude */ require_once $className; diff --git a/lib/Service/BoardImportTrelloApiService.php b/lib/Service/Importer/Systems/TrelloApiService.php similarity index 98% rename from lib/Service/BoardImportTrelloApiService.php rename to lib/Service/Importer/Systems/TrelloApiService.php index 301daa6d4..e95afb6b7 100644 --- a/lib/Service/BoardImportTrelloApiService.php +++ b/lib/Service/Importer/Systems/TrelloApiService.php @@ -21,7 +21,7 @@ * */ -namespace OCA\Deck\Service; +namespace OCA\Deck\Service\Importer\Systems; use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; @@ -30,7 +30,7 @@ use OCP\IURLGenerator; use OCP\IUserManager; use Psr\Log\LoggerInterface; -class BoardImportTrelloApiService extends BoardImportTrelloJsonService { +class TrelloApiService extends TrelloJsonService { /** @var string */ public static $name = 'Trello API'; protected $needValidateData = false; diff --git a/lib/Service/BoardImportTrelloJsonService.php b/lib/Service/Importer/Systems/TrelloJsonService.php similarity index 98% rename from lib/Service/BoardImportTrelloJsonService.php rename to lib/Service/Importer/Systems/TrelloJsonService.php index 6645f0e76..49b02a71a 100644 --- a/lib/Service/BoardImportTrelloJsonService.php +++ b/lib/Service/Importer/Systems/TrelloJsonService.php @@ -21,7 +21,7 @@ * */ -namespace OCA\Deck\Service; +namespace OCA\Deck\Service\Importer\Systems; use OC\Comments\Comment; use OCA\Deck\BadRequestException; @@ -32,13 +32,14 @@ use OCA\Deck\Db\Board; use OCA\Deck\Db\Card; use OCA\Deck\Db\Label; use OCA\Deck\Db\Stack; +use OCA\Deck\Service\Importer\ABoardImportService; use OCP\Comments\IComment; use OCP\IL10N; use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; -class BoardImportTrelloJsonService extends ABoardImportService { +class TrelloJsonService extends ABoardImportService { /** @var string */ public static $name = 'Trello JSON'; /** @var IUserManager */ diff --git a/lib/Service/fixtures/config-trelloApi-schema.json b/lib/Service/Importer/fixtures/config-trelloApi-schema.json similarity index 100% rename from lib/Service/fixtures/config-trelloApi-schema.json rename to lib/Service/Importer/fixtures/config-trelloApi-schema.json diff --git a/lib/Service/fixtures/config-trelloJson-schema.json b/lib/Service/Importer/fixtures/config-trelloJson-schema.json similarity index 100% rename from lib/Service/fixtures/config-trelloJson-schema.json rename to lib/Service/Importer/fixtures/config-trelloJson-schema.json diff --git a/tests/unit/Command/BoardImportTest.php b/tests/unit/Command/BoardImportTest.php index 8c0c23119..32701811b 100644 --- a/tests/unit/Command/BoardImportTest.php +++ b/tests/unit/Command/BoardImportTest.php @@ -23,7 +23,7 @@ namespace OCA\Deck\Command; -use OCA\Deck\Service\BoardImportCommandService; +use OCA\Deck\Service\Importer\BoardImportCommandService; use Symfony\Component\Console\Helper\HelperSet; use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputInterface; @@ -37,7 +37,7 @@ class BoardImportTest extends \Test\TestCase { public function setUp(): void { parent::setUp(); - $this->boardImportCommandService = $this->createMock(boardImportCommandService::class); + $this->boardImportCommandService = $this->createMock(BoardImportCommandService::class); $this->boardImport = new BoardImport( $this->boardImportCommandService ); diff --git a/tests/unit/Service/BoardImportServiceTest.php b/tests/unit/Service/Importer/BoardImportServiceTest.php similarity index 88% rename from tests/unit/Service/BoardImportServiceTest.php rename to tests/unit/Service/Importer/BoardImportServiceTest.php index 9577d1654..787dfdd5f 100644 --- a/tests/unit/Service/BoardImportServiceTest.php +++ b/tests/unit/Service/Importer/BoardImportServiceTest.php @@ -20,7 +20,7 @@ * along with this program. If not, see . * */ -namespace OCA\Deck\Service; +namespace OCA\Deck\Service\Importer; use OC\Comments\Comment; use OCA\Deck\Db\Acl; @@ -35,6 +35,7 @@ use OCA\Deck\Db\Label; use OCA\Deck\Db\LabelMapper; use OCA\Deck\Db\Stack; use OCA\Deck\Db\StackMapper; +use OCA\Deck\Service\Importer\Systems\TrelloJsonService; use OCP\Comments\ICommentsManager; use OCP\IDBConnection; use OCP\IUser; @@ -62,8 +63,8 @@ class BoardImportServiceTest extends \Test\TestCase { private $attachmentMapper; /** @var ICommentsManager|MockObject */ private $commentsManager; - /** @var BoardImportTrelloJsonService|MockObject */ - private $importTrelloJsonService; + /** @var TrelloJsonService|MockObject */ + private $trelloJsonService; /** @var BoardImportService|MockObject */ private $boardImportService; public function setUp(): void { @@ -90,14 +91,14 @@ class BoardImportServiceTest extends \Test\TestCase { $this->boardImportService->setSystem('trelloJson'); - $data = json_decode(file_get_contents(__DIR__ . '/../../data/data-trelloJson.json')); + $data = json_decode(file_get_contents(__DIR__ . '/../../../data/data-trelloJson.json')); $this->boardImportService->setData($data); - $configInstance = json_decode(file_get_contents(__DIR__ . '/../../data/config-trelloJson.json')); + $configInstance = json_decode(file_get_contents(__DIR__ . '/../../../data/config-trelloJson.json')); $this->boardImportService->setConfigInstance($configInstance); - $this->importTrelloJsonService = $this->createMock(BoardImportTrelloJsonService::class); - $this->boardImportService->setImportSystem($this->importTrelloJsonService); + $this->trelloJsonService = $this->createMock(TrelloJsonService::class); + $this->boardImportService->setImportSystem($this->trelloJsonService); $owner = $this->createMock(IUser::class); $owner @@ -125,35 +126,35 @@ class BoardImportServiceTest extends \Test\TestCase { ->expects($this->once()) ->method('insert'); - $this->importTrelloJsonService + $this->trelloJsonService ->method('getAclList') ->willReturn([new Acl()]); $this->aclMapper ->expects($this->once()) ->method('insert'); - $this->importTrelloJsonService + $this->trelloJsonService ->method('getLabels') ->willReturn([new Label()]); $this->labelMapper ->expects($this->once()) ->method('insert'); - $this->importTrelloJsonService + $this->trelloJsonService ->method('getStacks') ->willReturn([new Stack()]); $this->stackMapper ->expects($this->once()) ->method('insert'); - $this->importTrelloJsonService + $this->trelloJsonService ->method('getCards') ->willReturn([new Card()]); $this->cardMapper ->expects($this->any()) ->method('insert'); - $this->importTrelloJsonService + $this->trelloJsonService ->method('getComments') ->willReturn([ 'fakecardid' => [new Comment()] @@ -162,7 +163,7 @@ class BoardImportServiceTest extends \Test\TestCase { ->expects($this->once()) ->method('save'); - $this->importTrelloJsonService + $this->trelloJsonService ->method('getCardAssignments') ->willReturn([ 'fakecardid' => [new Assignment()] diff --git a/tests/unit/Service/BoardImportTrelloServiceTest.php b/tests/unit/Service/Importer/Systems/TrelloJsonServiceTest.php similarity index 91% rename from tests/unit/Service/BoardImportTrelloServiceTest.php rename to tests/unit/Service/Importer/Systems/TrelloJsonServiceTest.php index b8df68359..6eec07a9b 100644 --- a/tests/unit/Service/BoardImportTrelloServiceTest.php +++ b/tests/unit/Service/Importer/Systems/TrelloJsonServiceTest.php @@ -20,19 +20,21 @@ * along with this program. If not, see . * */ -namespace OCA\Deck\Service; +namespace OCA\Deck\Service\Importer\Systems; +use OCA\Deck\Service\Importer\BoardImportService; use OCP\IL10N; use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; +use PHPUnit\Framework\MockObject\MockObject; -class BoardImportTrelloJsonServiceTest extends \Test\TestCase { - /** @var BoardImportTrelloJsonService */ +class TrelloJsonServiceTest extends \Test\TestCase { + /** @var TrelloJsonService */ private $service; - /** @var IURLGenerator */ + /** @var IURLGenerator|MockObject */ private $urlGenerator; - /** @var IUserManager */ + /** @var IUserManager|MockObject */ private $userManager; /** @var IL10N */ private $l10n; @@ -40,7 +42,7 @@ class BoardImportTrelloJsonServiceTest extends \Test\TestCase { $this->userManager = $this->createMock(IUserManager::class); $this->urlGenerator = $this->createMock(IURLGenerator::class); $this->l10n = $this->createMock(IL10N::class); - $this->service = new BoardImportTrelloJsonService( + $this->service = new TrelloJsonService( $this->userManager, $this->urlGenerator, $this->l10n @@ -128,10 +130,10 @@ class BoardImportTrelloJsonServiceTest extends \Test\TestCase { public function testGetBoardWithSuccess() { $importService = \OC::$server->get(BoardImportService::class); - $data = json_decode(file_get_contents(__DIR__ . '/../../data/data-trelloJson.json')); + $data = json_decode(file_get_contents(__DIR__ . '/../../../../data/data-trelloJson.json')); $importService->setData($data); - $configInstance = json_decode(file_get_contents(__DIR__ . '/../../data/config-trelloJson.json')); + $configInstance = json_decode(file_get_contents(__DIR__ . '/../../../../data/config-trelloJson.json')); $importService->setConfigInstance($configInstance); $owner = $this->createMock(IUser::class); diff --git a/tests/unit/controller/BoardImportApiControllerTest.php b/tests/unit/controller/BoardImportApiControllerTest.php index ef16cab26..926e4c473 100644 --- a/tests/unit/controller/BoardImportApiControllerTest.php +++ b/tests/unit/controller/BoardImportApiControllerTest.php @@ -1,23 +1,23 @@ + * @copyright Copyright (c) 2021 Vitor Mattos * - * @author Ryan Fletcher + * @author Vitor Mattos * * @license GNU AGPL version 3 or any later version * - * 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. + * 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. * - * 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. + * 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 - * along with this program. If not, see . + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . * */ namespace OCA\Deck\Controller; @@ -26,14 +26,14 @@ use OCA\Deck\Db\Board; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\IRequest; -use OCA\Deck\Service\BoardImportService; +use OCA\Deck\Service\Importer\BoardImportService; class BoardImportApiControllerTest extends \Test\TestCase { private $appName = 'deck'; private $userId = 'admin'; /** @var BoardImportApiController */ private $controller; - /** @var BoardImportService */ + /** @var BoardImportService|MockObject */ private $boardImportService; public function setUp(): void {