Skip to content

Commit

Permalink
Checking ApigeeX org from OrganizationController and removed from SDK…
Browse files Browse the repository at this point in the history
…Controller (#832)
  • Loading branch information
shishir-intelli authored Mar 29, 2023
1 parent ad9abbe commit ee24714
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
16 changes: 2 additions & 14 deletions modules/apigee_edge_teams/src/Entity/Form/TeamForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand All @@ -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;
}

Expand All @@ -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')
);
}
Expand All @@ -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 {
Expand Down
18 changes: 15 additions & 3 deletions modules/apigee_edge_teams/src/Entity/Storage/TeamAppStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*
Expand All @@ -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;
}

/**
Expand All @@ -76,15 +87,16 @@ 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')
);
}

/**
* {@inheritdoc}
*/
protected function entityController(): EdgeEntityControllerInterface {
if ($this->appController->isOrgApigeeX()) {
if ($this->orgController->isOrganizationApigeeX()) {
$teamAppEntityControllerProxy = new TeamAppApigeeXEntityControllerProxy($this->teamAppControllerFactory, $this->appController);
}
else {
Expand Down
54 changes: 17 additions & 37 deletions modules/apigee_edge_teams/src/Entity/TeamApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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();
}

/**
Expand All @@ -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 {
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/Entity/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/Entity/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 0 additions & 11 deletions src/Entity/Controller/AppControllerBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
16 changes: 14 additions & 2 deletions src/Entity/Controller/DeveloperAppEdgeEntityControllerProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -47,17 +48,28 @@ final class DeveloperAppEdgeEntityControllerProxy implements EdgeEntityControlle
*/
private $appController;


/**
* The organization controller service.
*
* @var \Drupal\apigee_edge\Entity\Controller\OrganizationControllerInterface
*/
private $orgController;

/**
* DeveloperAppEntityControllerProxy constructor.
*
* @param \Drupal\apigee_edge\Entity\Controller\DeveloperAppControllerFactoryInterface $developer_app_controller_factory
* 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;
}

/**
Expand All @@ -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;
}

Expand Down
10 changes: 7 additions & 3 deletions src/Entity/Storage/DeveloperAppStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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')
);
}

Expand Down
13 changes: 0 additions & 13 deletions src/SDKConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
8 changes: 0 additions & 8 deletions src/SDKConnectorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit ee24714

Please sign in to comment.