From c1abfb58c4de5ecbe71c42e34e89eeb9876eac62 Mon Sep 17 00:00:00 2001 From: Bas Strooband Date: Fri, 22 Feb 2019 10:56:55 +0100 Subject: [PATCH 1/3] Fix manage query state for prod All entities were fetched with the 'testaccepted' state. This resulted in entities not being fetched after they where published with 'prodaccepted'. This fix will get the entities based on the state configured in the parameters.yml. --- .../Application/Service/EntityService.php | 24 +++++++++++++++---- .../Repository/QueryEntityRepository.php | 5 ++-- .../Resources/config/services.yml | 2 ++ .../Manage/Client/QueryClient.php | 5 ++-- .../Application/Service/EntityServiceTest.php | 15 +++++++++--- 5 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/Surfnet/ServiceProviderDashboard/Application/Service/EntityService.php b/src/Surfnet/ServiceProviderDashboard/Application/Service/EntityService.php index f96030bad..2a332a5f3 100644 --- a/src/Surfnet/ServiceProviderDashboard/Application/Service/EntityService.php +++ b/src/Surfnet/ServiceProviderDashboard/Application/Service/EntityService.php @@ -65,13 +65,25 @@ class EntityService implements EntityServiceInterface */ private $oidcPlaygroundUriProd; + /** + * @var string + */ + private $testPublishedState; + + /** + * @var string + */ + private $prodPublishedState; + public function __construct( EntityQueryRepositoryProvider $entityQueryRepositoryProvider, TicketServiceInterface $ticketService, RouterInterface $router, LoggerInterface $logger, $oidcPlaygroundUriTest, - $oidcPlaygroundUriProd + $oidcPlaygroundUriProd, + $testPublishedState, + $prodPublishedState ) { Assert::stringNotEmpty($oidcPlaygroundUriTest, 'Please set "playground_uri_test" in parameters.yml'); Assert::stringNotEmpty($oidcPlaygroundUriProd, 'Please set "playground_uri_prod" in parameters.yml'); @@ -82,6 +94,8 @@ public function __construct( $this->logger = $logger; $this->oidcPlaygroundUriTest = $oidcPlaygroundUriTest; $this->oidcPlaygroundUriProd = $oidcPlaygroundUriProd; + $this->testPublishedState = $testPublishedState; + $this->prodPublishedState = $prodPublishedState; } public function createEntityUuid() @@ -144,12 +158,12 @@ public function getEntityListForService(Service $service) $entities[] = ViewObject\Entity::fromEntity($entity, $this->router); } - $testEntities = $this->findPublishedTestEntitiesByTeamName($service->getTeamName()); + $testEntities = $this->findPublishedTestEntitiesByTeamName($service->getTeamName(), $this->testPublishedState); foreach ($testEntities as $result) { $entities[] = ViewObject\Entity::fromManageTestResult($result, $this->router, $service->getId()); } - $productionEntities = $this->findPublishedProductionEntitiesByTeamName($service->getTeamName()); + $productionEntities = $this->findPublishedProductionEntitiesByTeamName($service->getTeamName(), $this->prodPublishedState); foreach ($productionEntities as $result) { $entities[] = ViewObject\Entity::fromManageProductionResult($result, $this->router, $service->getId()); } @@ -215,7 +229,7 @@ private function findPublishedTestEntitiesByTeamName($teamName) { return $this->queryRepositoryProvider ->getManageTestQueryClient() - ->findByTeamName($teamName); + ->findByTeamName($teamName, $this->testPublishedState); } /** @@ -232,7 +246,7 @@ private function findPublishedProductionEntitiesByTeamName($teamName) { $entities = $this->queryRepositoryProvider ->getManageProductionQueryClient() - ->findByTeamName($teamName); + ->findByTeamName($teamName, $this->prodPublishedState); // Try to find the tickets in Jira that match the manageIds. If Jira is down or otherwise unavailable, the // entities are returned without updating their status. This might result in a 're request for delete' diff --git a/src/Surfnet/ServiceProviderDashboard/Domain/Repository/QueryEntityRepository.php b/src/Surfnet/ServiceProviderDashboard/Domain/Repository/QueryEntityRepository.php index 568b0d49e..411587642 100644 --- a/src/Surfnet/ServiceProviderDashboard/Domain/Repository/QueryEntityRepository.php +++ b/src/Surfnet/ServiceProviderDashboard/Domain/Repository/QueryEntityRepository.php @@ -42,9 +42,10 @@ public function findByManageId($manageId); public function getMetadataXmlByManageId($manageId); /** - * @param string $teamname + * @param string $teamName + * @param string $state * * @return array|null */ - public function findByTeamName($teamName); + public function findByTeamName($teamName, $state); } diff --git a/src/Surfnet/ServiceProviderDashboard/Infrastructure/DashboardBundle/Resources/config/services.yml b/src/Surfnet/ServiceProviderDashboard/Infrastructure/DashboardBundle/Resources/config/services.yml index f2df528ad..e0d482e7d 100644 --- a/src/Surfnet/ServiceProviderDashboard/Infrastructure/DashboardBundle/Resources/config/services.yml +++ b/src/Surfnet/ServiceProviderDashboard/Infrastructure/DashboardBundle/Resources/config/services.yml @@ -255,6 +255,8 @@ services: - '@logger' - '%playground_uri_test%' - '%playground_uri_prod%' + - '%manage_test_publication_status_update%' + - '%manage_prod_publication_status_update%' Surfnet\ServiceProviderDashboard\Application\Service\LoadEntityService: arguments: diff --git a/src/Surfnet/ServiceProviderDashboard/Infrastructure/Manage/Client/QueryClient.php b/src/Surfnet/ServiceProviderDashboard/Infrastructure/Manage/Client/QueryClient.php index 057081de1..4425ee0c2 100644 --- a/src/Surfnet/ServiceProviderDashboard/Infrastructure/Manage/Client/QueryClient.php +++ b/src/Surfnet/ServiceProviderDashboard/Infrastructure/Manage/Client/QueryClient.php @@ -137,18 +137,19 @@ public function findByManageId($manageId) * Query manage for all test entities by given team name. * * @param string $teamName + * @param string $state * * @return ManageEntity[]|null * * @throws QueryServiceProviderException */ - public function findByTeamName($teamName) + public function findByTeamName($teamName, $state) { try { // Query manage to get the internal id of every SP entity with given team ID. $searchResults = $this->doSearchQuery([ 'metaDataFields.coin:service_team_id' => $teamName, - 'state' => 'testaccepted' + 'state' => $state ]); // For each search result, query manage to get the full SP entity data. diff --git a/tests/unit/Application/Service/EntityServiceTest.php b/tests/unit/Application/Service/EntityServiceTest.php index da6098d47..30dd98f64 100644 --- a/tests/unit/Application/Service/EntityServiceTest.php +++ b/tests/unit/Application/Service/EntityServiceTest.php @@ -75,7 +75,16 @@ public function setUp() $this->router = m::mock(RouterInterface::class); $logger = m::mock(LoggerInterface::class); $this->ticketService = m::mock(TicketServiceInterface::class); - $this->service = new EntityService($provider, $this->ticketService, $this->router, $logger, 'playgroundUriTest', 'playgroundUriProd'); + $this->service = new EntityService( + $provider, + $this->ticketService, + $this->router, + $logger, + 'playgroundUriTest', + 'playgroundUriProd', + 'testaccepted', + 'prodaccepted' + ); } public function test_it_can_search_manage_test_by_manage_id() @@ -133,12 +142,12 @@ public function test_get_entity_list_for_service() $this->manageTest ->shouldReceive('findByTeamName') - ->with($teamName) + ->with($teamName, 'testaccepted') ->andReturn([]); $this->manageProd ->shouldReceive('findByTeamName') - ->with($teamName) + ->with($teamName, 'prodaccepted') ->andReturn([]); $this->ticketService From cb2cb5bc7f83a31483ca2097ff85bc91d6116ae3 Mon Sep 17 00:00:00 2001 From: Michiel Kodde Date: Mon, 25 Feb 2019 10:33:31 +0100 Subject: [PATCH 2/3] Use the Manage Config in favor of parameter values The manage configuration can be retrieved from a value object that is loaded on the container during compile time. This was added in: https://github.com/SURFnet/sp-dashboard/pull/238 --- .../Application/Service/EntityService.php | 33 +++++++++++-------- .../Resources/config/services.yml | 4 +-- .../Application/Service/EntityServiceTest.php | 17 ++++++++-- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/Surfnet/ServiceProviderDashboard/Application/Service/EntityService.php b/src/Surfnet/ServiceProviderDashboard/Application/Service/EntityService.php index 2a332a5f3..fad6be2e7 100644 --- a/src/Surfnet/ServiceProviderDashboard/Application/Service/EntityService.php +++ b/src/Surfnet/ServiceProviderDashboard/Application/Service/EntityService.php @@ -26,6 +26,7 @@ use Surfnet\ServiceProviderDashboard\Application\Exception\InvalidArgumentException; use Surfnet\ServiceProviderDashboard\Application\Provider\EntityQueryRepositoryProvider; use Surfnet\ServiceProviderDashboard\Application\ViewObject; +use Surfnet\ServiceProviderDashboard\Application\ViewObject\Manage\Config; use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity; use Surfnet\ServiceProviderDashboard\Domain\Entity\Service; use Surfnet\ServiceProviderDashboard\Infrastructure\Manage\Dto\ManageEntity; @@ -66,24 +67,24 @@ class EntityService implements EntityServiceInterface private $oidcPlaygroundUriProd; /** - * @var string + * @var Config */ - private $testPublishedState; + private $testManageConfig; /** - * @var string + * @var Config */ - private $prodPublishedState; + private $prodManageConfig; public function __construct( EntityQueryRepositoryProvider $entityQueryRepositoryProvider, TicketServiceInterface $ticketService, + Config $testConfig, + Config $productionConfig, RouterInterface $router, LoggerInterface $logger, $oidcPlaygroundUriTest, - $oidcPlaygroundUriProd, - $testPublishedState, - $prodPublishedState + $oidcPlaygroundUriProd ) { Assert::stringNotEmpty($oidcPlaygroundUriTest, 'Please set "playground_uri_test" in parameters.yml'); Assert::stringNotEmpty($oidcPlaygroundUriProd, 'Please set "playground_uri_prod" in parameters.yml'); @@ -94,8 +95,8 @@ public function __construct( $this->logger = $logger; $this->oidcPlaygroundUriTest = $oidcPlaygroundUriTest; $this->oidcPlaygroundUriProd = $oidcPlaygroundUriProd; - $this->testPublishedState = $testPublishedState; - $this->prodPublishedState = $prodPublishedState; + $this->testManageConfig = $testConfig; + $this->prodManageConfig = $productionConfig; } public function createEntityUuid() @@ -158,12 +159,18 @@ public function getEntityListForService(Service $service) $entities[] = ViewObject\Entity::fromEntity($entity, $this->router); } - $testEntities = $this->findPublishedTestEntitiesByTeamName($service->getTeamName(), $this->testPublishedState); + $testEntities = $this->findPublishedTestEntitiesByTeamName( + $service->getTeamName(), + $this->testManageConfig->getPublicationStatus()->getCreateStatus() + ); foreach ($testEntities as $result) { $entities[] = ViewObject\Entity::fromManageTestResult($result, $this->router, $service->getId()); } - $productionEntities = $this->findPublishedProductionEntitiesByTeamName($service->getTeamName(), $this->prodPublishedState); + $productionEntities = $this->findPublishedProductionEntitiesByTeamName( + $service->getTeamName(), + $this->prodManageConfig->getPublicationStatus()->getCreateStatus() + ); foreach ($productionEntities as $result) { $entities[] = ViewObject\Entity::fromManageProductionResult($result, $this->router, $service->getId()); } @@ -229,7 +236,7 @@ private function findPublishedTestEntitiesByTeamName($teamName) { return $this->queryRepositoryProvider ->getManageTestQueryClient() - ->findByTeamName($teamName, $this->testPublishedState); + ->findByTeamName($teamName, $this->testManageConfig->getPublicationStatus()->getCreateStatus()); } /** @@ -246,7 +253,7 @@ private function findPublishedProductionEntitiesByTeamName($teamName) { $entities = $this->queryRepositoryProvider ->getManageProductionQueryClient() - ->findByTeamName($teamName, $this->prodPublishedState); + ->findByTeamName($teamName, $this->prodManageConfig->getPublicationStatus()->getCreateStatus()); // Try to find the tickets in Jira that match the manageIds. If Jira is down or otherwise unavailable, the // entities are returned without updating their status. This might result in a 're request for delete' diff --git a/src/Surfnet/ServiceProviderDashboard/Infrastructure/DashboardBundle/Resources/config/services.yml b/src/Surfnet/ServiceProviderDashboard/Infrastructure/DashboardBundle/Resources/config/services.yml index e0d482e7d..4340a1991 100644 --- a/src/Surfnet/ServiceProviderDashboard/Infrastructure/DashboardBundle/Resources/config/services.yml +++ b/src/Surfnet/ServiceProviderDashboard/Infrastructure/DashboardBundle/Resources/config/services.yml @@ -251,12 +251,12 @@ services: arguments: - '@Surfnet\ServiceProviderDashboard\Application\Provider\EntityQueryRepositoryProvider' - '@Surfnet\ServiceProviderDashboard\Application\Service\TicketService' + - '@surfnet.manage.configuration.test' + - '@surfnet.manage.configuration.production' - '@router' - '@logger' - '%playground_uri_test%' - '%playground_uri_prod%' - - '%manage_test_publication_status_update%' - - '%manage_prod_publication_status_update%' Surfnet\ServiceProviderDashboard\Application\Service\LoadEntityService: arguments: diff --git a/tests/unit/Application/Service/EntityServiceTest.php b/tests/unit/Application/Service/EntityServiceTest.php index 30dd98f64..95eca741a 100644 --- a/tests/unit/Application/Service/EntityServiceTest.php +++ b/tests/unit/Application/Service/EntityServiceTest.php @@ -26,6 +26,7 @@ use Surfnet\ServiceProviderDashboard\Application\Provider\EntityQueryRepositoryProvider; use Surfnet\ServiceProviderDashboard\Application\Service\EntityService; use Surfnet\ServiceProviderDashboard\Application\Service\TicketServiceInterface; +use Surfnet\ServiceProviderDashboard\Application\ViewObject\Manage\Config; use Surfnet\ServiceProviderDashboard\Domain\Entity\Service; use Surfnet\ServiceProviderDashboard\Domain\Repository\EntityRepository; use Surfnet\ServiceProviderDashboard\Infrastructure\Manage\Client\QueryClient as ManageQueryClient; @@ -71,6 +72,16 @@ public function setUp() $provider = new EntityQueryRepositoryProvider($this->repository, $this->manageTest, $this->manageProd); + $manageConfigTest = m::mock(Config::class); + $manageConfigTest + ->shouldReceive('getPublicationStatus->getCreateStatus') + ->andReturn('testaccepted'); + + $manageConfigProd = m::mock(Config::class); + $manageConfigProd + ->shouldReceive('getPublicationStatus->getCreateStatus') + ->andReturn('prodaccepted'); + $this->router = m::mock(RouterInterface::class); $this->router = m::mock(RouterInterface::class); $logger = m::mock(LoggerInterface::class); @@ -78,12 +89,12 @@ public function setUp() $this->service = new EntityService( $provider, $this->ticketService, + $manageConfigTest, + $manageConfigProd, $this->router, $logger, 'playgroundUriTest', - 'playgroundUriProd', - 'testaccepted', - 'prodaccepted' + 'playgroundUriProd' ); } From 2506efa8446b67417804ada0f78a1ca77e85e269 Mon Sep 17 00:00:00 2001 From: Michiel Kodde Date: Mon, 25 Feb 2019 10:46:16 +0100 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b9ccf722..089050ca5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Next release +## 2.0.7 +**Bugfix** + * Fix Manage query workflow state #242 + ## 2.0.6 **Bugfixes**