diff --git a/modules/apigee_edge_teams/src/Entity/Controller/TeamAppController.php b/modules/apigee_edge_teams/src/Entity/Controller/TeamAppController.php index 095d2baa1..9f7473385 100644 --- a/modules/apigee_edge_teams/src/Entity/Controller/TeamAppController.php +++ b/modules/apigee_edge_teams/src/Entity/Controller/TeamAppController.php @@ -37,9 +37,8 @@ final class TeamAppController extends AppByOwnerController implements TeamAppCon */ protected function decorated(): EdgeAppByOwnerControllerInterface { if (!isset($this->instances[$this->owner])) { - - // Checking if the Organisation is Hybrid/ApigeeX. - if ($this->isOrgApigeeX()) { + // Checks whether the organization is Edge or ApigeeX organization. + if ($this->organizationController->isOrganizationApigeeX()) { $this->instances[$this->owner] = new EdgeAppGroupAppController($this->connector->getOrganization(), $this->owner, $this->connector->getClient(), NULL, $this->organizationController); } else { diff --git a/modules/apigee_edge_teams/src/Entity/Controller/TeamController.php b/modules/apigee_edge_teams/src/Entity/Controller/TeamController.php index 814630941..b9243917e 100644 --- a/modules/apigee_edge_teams/src/Entity/Controller/TeamController.php +++ b/modules/apigee_edge_teams/src/Entity/Controller/TeamController.php @@ -158,7 +158,7 @@ public function __construct(SDKConnectorInterface $connector, OrganizationContro */ private function decorated(): EdgeCompanyControllerInterface|AppGroupControllerInterface { if ($this->instance === NULL) { - if ($this->connector->isOrganizationApigeeX($this->orgController)) { + if ($this->orgController->isOrganizationApigeeX()) { $this->instance = new AppGroupController($this->connector->getOrganization(), $this->connector->getClient(), NULL, $this->orgController); } else { @@ -186,7 +186,7 @@ protected function entityIdCache(): EntityIdCacheInterface { * {@inheritdoc} */ public function setStatus(string $entity_id, string $status): void { - if (!$this->connector->isOrganizationApigeeX($this->orgController)) { + if (!$this->orgController->isOrganizationApigeeX()) { $this->decorated()->setStatus($entity_id, $status); } // Enforce reload of entity from Apigee Edge. diff --git a/modules/apigee_edge_teams/src/Entity/Form/TeamForm.php b/modules/apigee_edge_teams/src/Entity/Form/TeamForm.php index 8c123b039..6bba4952c 100644 --- a/modules/apigee_edge_teams/src/Entity/Form/TeamForm.php +++ b/modules/apigee_edge_teams/src/Entity/Form/TeamForm.php @@ -24,7 +24,6 @@ use Drupal\apigee_edge\Entity\Controller\OrganizationControllerInterface; use Drupal\apigee_edge\Entity\Form\EdgeEntityFormInterface; use Drupal\apigee_edge\Entity\Form\FieldableEdgeEntityForm; -use Drupal\apigee_edge\SDKConnectorInterface; use Drupal\apigee_edge_teams\Entity\TeamRoleInterface; use Drupal\apigee_edge_teams\TeamMembershipManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; @@ -71,13 +70,6 @@ class TeamForm extends FieldableEdgeEntityForm implements EdgeEntityFormInterfac */ protected $logger; - /** - * The SDK connector service. - * - * @var \Drupal\apigee_edge\SDKConnectorInterface - */ - protected $sdkConnector; - /** * The organization controller service. * @@ -96,17 +88,14 @@ class TeamForm extends FieldableEdgeEntityForm implements EdgeEntityFormInterfac * The current user. * @param \Drupal\Core\Logger\LoggerChannelInterface $logger * The logger service. - * @param \Drupal\apigee_edge\SDKConnectorInterface $connector - * The SDK connector service. * @param \Drupal\apigee_edge\Entity\Controller\OrganizationControllerInterface $org_controller * The organization controller service. */ - public function __construct(EntityTypeManagerInterface $entity_type_manager, TeamMembershipManagerInterface $team_membership_manager, AccountProxyInterface $current_user, LoggerChannelInterface $logger, SDKConnectorInterface $connector, OrganizationControllerInterface $org_controller) { + public function __construct(EntityTypeManagerInterface $entity_type_manager, TeamMembershipManagerInterface $team_membership_manager, AccountProxyInterface $current_user, LoggerChannelInterface $logger, OrganizationControllerInterface $org_controller) { $this->entityTypeManager = $entity_type_manager; $this->teamMembershipManager = $team_membership_manager; $this->currentUser = $current_user; $this->logger = $logger; - $this->connector = $connector; $this->orgController = $org_controller; } @@ -119,7 +108,6 @@ public static function create(ContainerInterface $container) { $container->get('apigee_edge_teams.team_membership_manager'), $container->get('current_user'), $container->get('logger.channel.apigee_edge_teams'), - $container->get('apigee_edge.sdk_connector'), $container->get('apigee_edge.controller.organization') ); } @@ -134,7 +122,7 @@ public function buildEntity(array $form, FormStateInterface $form_state) { // ADMIN_EMAIL_ATTRIBUTE is a required field for monetization. // We add to any team to make sure team creation works for mint orgs even // if they do not enable the m10n teams module. - if ($this->connector->isOrganizationApigeeX($this->orgController)) { + if ($this->orgController->isOrganizationApigeeX()) { $team->setAttribute(static::APPGROUP_ADMIN_EMAIL_ATTRIBUTE, "[{'developer':'{$this->currentUser->getEmail()}','roles':['admin']}]"); } else { diff --git a/modules/apigee_edge_teams/src/Entity/Storage/TeamAppStorage.php b/modules/apigee_edge_teams/src/Entity/Storage/TeamAppStorage.php index e61aadce7..018fa4848 100644 --- a/modules/apigee_edge_teams/src/Entity/Storage/TeamAppStorage.php +++ b/modules/apigee_edge_teams/src/Entity/Storage/TeamAppStorage.php @@ -23,6 +23,7 @@ use Drupal\apigee_edge\Entity\AppInterface; use Drupal\apigee_edge\Entity\Controller\AppControllerInterface; use Drupal\apigee_edge\Entity\Controller\EdgeEntityControllerInterface; +use Drupal\apigee_edge\Entity\Controller\OrganizationControllerInterface; use Drupal\apigee_edge\Entity\Storage\AppStorage; use Drupal\apigee_edge_teams\Entity\Controller\TeamAppControllerFactoryInterface; use Drupal\apigee_edge_teams\Entity\Controller\TeamAppEdgeEntityControllerProxy; @@ -45,6 +46,13 @@ class TeamAppStorage extends AppStorage implements TeamAppStorageInterface { */ private $teamAppControllerFactory; + /** + * The organization controller service. + * + * @var \Drupal\apigee_edge\Entity\Controller\OrganizationControllerInterface + */ + private $orgController; + /** * AppStorage constructor. * @@ -60,10 +68,13 @@ class TeamAppStorage extends AppStorage implements TeamAppStorageInterface { * The team app controller factory service. * @param \Drupal\apigee_edge\Entity\Controller\AppControllerInterface $app_controller * The app controller service. + * @param \Drupal\apigee_edge\Entity\Controller\OrganizationControllerInterface $org_controller + * The organization controller service. */ - public function __construct(EntityTypeInterface $entity_type, CacheBackendInterface $cache_backend, MemoryCacheInterface $memory_cache, TimeInterface $system_time, TeamAppControllerFactoryInterface $team_app_controller_factory, AppControllerInterface $app_controller) { + public function __construct(EntityTypeInterface $entity_type, CacheBackendInterface $cache_backend, MemoryCacheInterface $memory_cache, TimeInterface $system_time, TeamAppControllerFactoryInterface $team_app_controller_factory, AppControllerInterface $app_controller, OrganizationControllerInterface $org_controller) { parent::__construct($entity_type, $cache_backend, $memory_cache, $system_time, $app_controller); $this->teamAppControllerFactory = $team_app_controller_factory; + $this->orgController = $org_controller; } /** @@ -76,7 +87,8 @@ public static function createInstance(ContainerInterface $container, EntityTypeI $container->get('entity.memory_cache'), $container->get('datetime.time'), $container->get('apigee_edge_teams.controller.team_app_controller_factory'), - $container->get('apigee_edge.controller.app') + $container->get('apigee_edge.controller.app'), + $container->get('apigee_edge.controller.organization') ); } @@ -84,7 +96,7 @@ public static function createInstance(ContainerInterface $container, EntityTypeI * {@inheritdoc} */ protected function entityController(): EdgeEntityControllerInterface { - if ($this->appController->isOrgApigeeX()) { + if ($this->orgController->isOrganizationApigeeX()) { $teamAppEntityControllerProxy = new TeamAppApigeeXEntityControllerProxy($this->teamAppControllerFactory, $this->appController); } else { diff --git a/modules/apigee_edge_teams/src/Entity/TeamApp.php b/modules/apigee_edge_teams/src/Entity/TeamApp.php index d04ad0862..ea0b896dc 100644 --- a/modules/apigee_edge_teams/src/Entity/TeamApp.php +++ b/modules/apigee_edge_teams/src/Entity/TeamApp.php @@ -123,26 +123,14 @@ public function id(): ?string { * {@inheritdoc} */ public function getAppOwner(): ?string { - $appController = \Drupal::service('apigee_edge.controller.app'); - if ($appController->isOrgApigeeX()) { - return $this->decorated->getAppGroup(); - } - else { - return $this->decorated->getCompanyName(); - } + return $this->isApigeeX() ? $this->decorated->getAppGroup() : $this->decorated->getCompanyName(); } /** * {@inheritdoc} */ public function setAppOwner(string $owner): void { - $appController = \Drupal::service('apigee_edge.controller.app'); - if ($appController->isOrgApigeeX()) { - $this->decorated->setAppGroup($owner); - } - else { - $this->decorated->setCompanyName($owner); - } + $this->isApigeeX() ? $this->decorated->setAppGroup($owner) : $this->decorated->setCompanyName($owner); } /** @@ -159,30 +147,29 @@ public function getAppGroup(): ?string { return $this->decorated->getAppGroup(); } + /** + * Checks whether the organization is Edge or ApigeeX organization. + * + * @return bool + * bool + */ + public static function isApigeeX(): bool { + $orgController = \Drupal::service('apigee_edge.controller.organization'); + return $orgController->isOrganizationApigeeX(); + } + /** * {@inheritdoc} */ protected static function decoratedClass(): string { - $appController = \Drupal::service('apigee_edge.controller.app'); - if ($appController->isOrgApigeeX()) { - return AppGroupApp::class; - } - else { - return CompanyApp::class; - } + return TeamApp::isApigeeX() ? AppGroupApp::class : CompanyApp::class; } /** * {@inheritdoc} */ public static function idProperty(): string { - $appController = \Drupal::service('apigee_edge.controller.app'); - if ($appController->isOrgApigeeX()) { - return AppGroupApp::idProperty(); - } - else { - return CompanyApp::idProperty(); - } + return TeamApp::isApigeeX() ? AppGroupApp::idProperty() : CompanyApp::idProperty(); } /** @@ -206,8 +193,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { } // Hide readonly properties from Manage form display list. - $appController = \Drupal::service('apigee_edge.controller.app'); - if ($appController->isOrgApigeeX()) { + if (TeamApp::isApigeeX()) { $definitions['appGroup']->setDisplayConfigurable('form', FALSE); } else { @@ -225,13 +211,7 @@ protected function urlRouteParameters($rel) { $link_templates = $this->linkTemplates(); if (isset($link_templates[$rel])) { if (strpos($link_templates[$rel], '{team}') !== FALSE) { - $appController = \Drupal::service('apigee_edge.controller.app'); - if ($appController->isOrgApigeeX()) { - $params['team'] = $this->getAppGroup(); - } - else { - $params['team'] = $this->getCompanyName(); - } + $params['team'] = $this->isApigeeX() ? $this->getAppGroup() : $this->getCompanyName(); } if (strpos($link_templates[$rel], '{app}') !== FALSE) { $params['app'] = $this->getName(); diff --git a/src/Entity/App.php b/src/Entity/App.php index 68941b450..556f2e0ea 100644 --- a/src/Entity/App.php +++ b/src/Entity/App.php @@ -139,8 +139,9 @@ public function getCredentials(): array { // App has not found in cache, we have to load it from Apigee Edge. /** @var \Drupal\apigee_edge\Entity\Controller\AppControllerInterface $app_controller */ $app_controller = \Drupal::service('apigee_edge.controller.app'); + $orgController = \Drupal::service('apigee_edge.controller.organization'); try { - $app = $app_controller->isOrgApigeeX() ? $app_controller->loadAppGroup($this->getAppId()) : $app_controller->loadApp($this->getAppId()); + $app = $orgController->isOrganizationApigeeX() ? $app_controller->loadAppGroup($this->getAppId()) : $app_controller->loadApp($this->getAppId()); } catch (ApiException $e) { // Just catch it and leave app to be NULL. diff --git a/src/Entity/Controller/AppController.php b/src/Entity/Controller/AppController.php index d9d9b30dd..578a39e45 100644 --- a/src/Entity/Controller/AppController.php +++ b/src/Entity/Controller/AppController.php @@ -93,8 +93,8 @@ public function __construct(SDKConnectorInterface $connector, OrganizationContro */ protected function decorated(): EdgeAppControllerInterface|EdgeAppGroupControllerInterface { if ($this->instance === NULL) { - // Checking if the Organisation is Hybrid/ApigeeX. - if ($this->isOrgApigeeX()) { + // Checking if the Organisation is ApigeeX. + if ($this->organizationController->isOrganizationApigeeX()) { $this->instance = new AppGroupController($this->connector->getOrganization(), $this->connector->getClient(), NULL, $this->organizationController); } else { diff --git a/src/Entity/Controller/AppControllerBase.php b/src/Entity/Controller/AppControllerBase.php index d27958b98..00871e6f1 100644 --- a/src/Entity/Controller/AppControllerBase.php +++ b/src/Entity/Controller/AppControllerBase.php @@ -77,15 +77,4 @@ public function entityCache(): EntityCacheInterface { return $this->appCache; } - /** - * Checking if the Organisation is ApigeeX. - * - * @return bool - * TRUE if given Organisation is ApigeeX. FALSE otherwise. - */ - public function isOrgApigeeX(): bool { - // Checking if the Organisation is ApigeeX. - return $this->connector->isOrganizationApigeeX($this->organizationController); - } - } diff --git a/src/Entity/Controller/DeveloperAppEdgeEntityControllerProxy.php b/src/Entity/Controller/DeveloperAppEdgeEntityControllerProxy.php index bee93e480..a21980977 100644 --- a/src/Entity/Controller/DeveloperAppEdgeEntityControllerProxy.php +++ b/src/Entity/Controller/DeveloperAppEdgeEntityControllerProxy.php @@ -23,6 +23,7 @@ use Apigee\Edge\Api\Management\Entity\AppInterface; use Apigee\Edge\Api\Management\Entity\DeveloperAppInterface; use Apigee\Edge\Entity\EntityInterface; +use Drupal\apigee_edge\Entity\Controller\OrganizationControllerInterface; use Drupal\apigee_edge\Exception\RuntimeException; /** @@ -47,6 +48,14 @@ final class DeveloperAppEdgeEntityControllerProxy implements EdgeEntityControlle */ private $appController; + + /** + * The organization controller service. + * + * @var \Drupal\apigee_edge\Entity\Controller\OrganizationControllerInterface + */ + private $orgController; + /** * DeveloperAppEntityControllerProxy constructor. * @@ -54,10 +63,13 @@ final class DeveloperAppEdgeEntityControllerProxy implements EdgeEntityControlle * The developer app controller factory service. * @param \Drupal\apigee_edge\Entity\Controller\AppControllerInterface $app_controller * The app controller service. + * @param \Drupal\apigee_edge\Entity\Controller\OrganizationControllerInterface $org_controller + * The organization controller service. */ - public function __construct(DeveloperAppControllerFactoryInterface $developer_app_controller_factory, AppControllerInterface $app_controller) { + public function __construct(DeveloperAppControllerFactoryInterface $developer_app_controller_factory, AppControllerInterface $app_controller, OrganizationControllerInterface $org_controller) { $this->devAppControllerFactory = $developer_app_controller_factory; $this->appController = $app_controller; + $this->orgController = $org_controller; } /** @@ -77,7 +89,7 @@ public function create(EntityInterface $entity): void { * {@inheritdoc} */ public function load(string $id): EntityInterface { - $app = $this->appController->isOrgApigeeX() ? $this->appController->loadAppGroup($id) : $this->appController->loadApp($id); + $app = $this->orgController->isOrganizationApigeeX() ? $this->appController->loadAppGroup($id) : $this->appController->loadApp($id); return $app; } diff --git a/src/Entity/Storage/DeveloperAppStorage.php b/src/Entity/Storage/DeveloperAppStorage.php index f101f2cbd..b18d634da 100644 --- a/src/Entity/Storage/DeveloperAppStorage.php +++ b/src/Entity/Storage/DeveloperAppStorage.php @@ -25,6 +25,7 @@ use Drupal\apigee_edge\Entity\Controller\DeveloperAppControllerFactoryInterface; use Drupal\apigee_edge\Entity\Controller\DeveloperAppEdgeEntityControllerProxy; use Drupal\apigee_edge\Entity\Controller\EdgeEntityControllerInterface; +use Drupal\apigee_edge\Entity\Controller\OrganizationControllerInterface; use Drupal\Component\Datetime\TimeInterface; use Drupal\Component\Utility\EmailValidatorInterface; use Drupal\Core\Cache\CacheBackendInterface; @@ -71,10 +72,12 @@ class DeveloperAppStorage extends AppStorage implements DeveloperAppStorageInter * Configuration factory. * @param \Drupal\Component\Utility\EmailValidatorInterface $email_validator * The email validator service. + * @param \Drupal\apigee_edge\Entity\Controller\OrganizationControllerInterface $org_controller + * The organization controller service. */ - public function __construct(EntityTypeInterface $entity_type, CacheBackendInterface $cache_backend, MemoryCacheInterface $memory_cache, TimeInterface $system_time, DeveloperAppControllerFactoryInterface $developer_app_controller_factory, AppControllerInterface $app_controller, ConfigFactoryInterface $config, EmailValidatorInterface $email_validator) { + public function __construct(EntityTypeInterface $entity_type, CacheBackendInterface $cache_backend, MemoryCacheInterface $memory_cache, TimeInterface $system_time, DeveloperAppControllerFactoryInterface $developer_app_controller_factory, AppControllerInterface $app_controller, ConfigFactoryInterface $config, EmailValidatorInterface $email_validator, OrganizationControllerInterface $org_controller) { parent::__construct($entity_type, $cache_backend, $memory_cache, $system_time, $app_controller); - $this->appEntityController = new DeveloperAppEdgeEntityControllerProxy($developer_app_controller_factory, $app_controller); + $this->appEntityController = new DeveloperAppEdgeEntityControllerProxy($developer_app_controller_factory, $app_controller, $org_controller); $this->cacheExpiration = $config->get('apigee_edge.developer_app_settings')->get('cache_expiration'); $this->emailValidator = $email_validator; } @@ -91,7 +94,8 @@ public static function createInstance(ContainerInterface $container, EntityTypeI $container->get('apigee_edge.controller.developer_app_controller_factory'), $container->get('apigee_edge.controller.app'), $container->get('config.factory'), - $container->get('email.validator') + $container->get('email.validator'), + $container->get('apigee_edge.controller.organization') ); } diff --git a/src/SDKConnector.php b/src/SDKConnector.php index d8810ea44..2c5d36409 100644 --- a/src/SDKConnector.php +++ b/src/SDKConnector.php @@ -159,19 +159,6 @@ public function getOrganization(): string { return $credentials->getKeyType()->getOrganization($credentials->getKey()); } - /** - * {@inheritdoc} - */ - public function isOrganizationApigeeX(EdgeOrganizationController $organizationController): bool { - try { - $this->organization = $organizationController->load($this->getOrganization()); - return ($this->organization && ('CLOUD' === $this->organization->getRuntimeType() || 'HYBRID' === $this->organization->getRuntimeType())); - } - catch (\Exception $e) { - return FALSE; - } - } - /** * {@inheritdoc} */ diff --git a/src/SDKConnectorInterface.php b/src/SDKConnectorInterface.php index 6b02620e3..081f250cb 100644 --- a/src/SDKConnectorInterface.php +++ b/src/SDKConnectorInterface.php @@ -37,14 +37,6 @@ interface SDKConnectorInterface { */ public function getOrganization(): string; - /** - * Checking if the Organisation is ApigeeX. - * - * @return bool - * TRUE if given Organisation is ApigeeX. FALSE otherwise. - */ - public function isOrganizationApigeeX(OrganizationController $organizationController): bool; - /** * Returns the http client. *