Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2x -Fix for Team 1000+ listing, AppGroup edit error and custom attribute update issues - 2x branch #353

Merged
merged 5 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/Api/ApigeeX/Controller/AppGroupMembersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use Apigee\Edge\Api\ApigeeX\Serializer\AppGroupMembershipSerializer;
use Apigee\Edge\Api\ApigeeX\Structure\AppGroupMembership;
use Apigee\Edge\Api\Management\Serializer\AttributesPropertyAwareEntitySerializer;
use Apigee\Edge\ClientInterface;
use Apigee\Edge\Controller\AbstractController;
use Apigee\Edge\Controller\OrganizationAwareControllerTrait;
Expand Down Expand Up @@ -47,7 +48,7 @@ class AppGroupMembersController extends AbstractController implements AppGroupMe
*
* @param string $appGroup
* @param string $organization
* @param \Apigee\Edge\ClientInterface $client
* @param ClientInterface $client
*/
public function __construct(string $appGroup, string $organization, ClientInterface $client)
{
Expand All @@ -73,8 +74,10 @@ public function getMembers(): AppGroupMembership
public function setMembers(AppGroupMembership $members): AppGroupMembership
{
$members = $this->serializer->normalize($members);
$apigeeReservedMembers = new AttributesProperty();

// We don't have a separate API to get appgroup attributes,
// that is why we are calling getAppGroupAttributes() method.
$apigeeReservedMembers = $this->getAppGroupAttributes();
// Adding the new members into the attribute.
$apigeeReservedMembers->add('__apigee_reserved__developer_details', json_encode($members));
$response = $this->client->put(
Expand All @@ -101,6 +104,23 @@ public function removeMember(string $email): void
$this->client->delete($this->getBaseEndpointUri()->withPath("{$this->getBaseEndpointUri()->getPath()}/{$encoded}"));
}

/**
* Helper function for getting all attributes in AppGroup.
*
* @return AttributesProperty
*/
public function getAppGroupAttributes(): AttributesProperty
{
$appGroup = $this->responseToArray($this->client->get($this->getBaseEndpointUri()));
$serializer = new AttributesPropertyAwareEntitySerializer();
$appGroupAttributes = $serializer->denormalize(
$appGroup['attributes'],
AttributesProperty::class
);

return $appGroupAttributes;
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface AppGroupMembersControllerInterface extends AppGroupAwareControllerInte
/**
* List all developers associated with a appgroup.
*
* @return \Apigee\Edge\Api\ApigeeX\Structure\AppGroupMembership
* @return AppGroupMembership
* Array of developers with their optional roles in the appgroup.
*/
public function getMembers(): AppGroupMembership;
Expand All @@ -39,10 +39,10 @@ public function getMembers(): AppGroupMembership;
* WARNING! If you pass en empty membership object you remove all developers
* from the appgroup.
*
* @param \Apigee\Edge\Api\ApigeeX\Structure\AppGroupMembership $members
* @param AppGroupMembership $members
* Membership object with the changes to be applied.
*
* @return \Apigee\Edge\Api\ApigeeX\Structure\AppGroupMembership
* @return AppGroupMembership
* Membership object with the applied changes, it does not contain all
* members. Use getMembers() to retrieve them.
*/
Expand Down
45 changes: 23 additions & 22 deletions src/Api/ApigeeX/Controller/PaginationHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,14 @@ protected function listEntities(PagerInterface $pager = null, array $query_param

return $this->responseArrayToArrayOfEntities($responseArray, $key_provider);
} else {
// Default page size set to 1000, because the AppGroupApps endpoint
// does not return nextPageToken unless a pageSize is specified
// in the request parameters.
$pageSize = 1000;
// Pass an empty pager to load all entities.
$responseArray = $this->getResultsInRange($this->createPager(), $query_params);
$responseArray = $this->getResultsInRange($this->createPager($pageSize), $query_params);
// Check flag 'nextPageToken' to get next items from the list.
$nextPageToken = array_key_exists('nextPageToken', $responseArray) ? $responseArray['nextPageToken'] : false;
// Ignore entity type key from response, ex.: developer, apiproduct,
// etc.
$responseArray = reset($responseArray);
Expand All @@ -122,30 +128,25 @@ protected function listEntities(PagerInterface $pager = null, array $query_param
return [];
}
$entities = $this->responseArrayToArrayOfEntities($responseArray, $key_provider);
$lastEntity = end($entities);
$lastId = $lastEntity->{$key_provider}();
do {
$tmp = $this->getResultsInRange($this->createPager(0, $lastId), $query_params);
// Ignore entity type key from response, ex.: developer,
// apiproduct, etc.
$tmp = reset($tmp);
// Remove the first item from the list because it is the same
// as the last item of $entities at this moment.
// Apigee X response always starts with the requested entity
// (pageToken).
array_shift($tmp);
$tmpEntities = $this->responseArrayToArrayOfEntities($tmp, $key_provider);

if (count($tmpEntities) > 0) {
if ($nextPageToken) {
do {
$tmp = $this->getResultsInRange($this->createPager($pageSize, $nextPageToken), $query_params);
// Check the flag 'nextPageToken' to get next items from the list.
$nextPageToken = array_key_exists('nextPageToken', $tmp) ? $tmp['nextPageToken'] : false;
// Ignore entity type key from response, ex.: developer,
// apiproduct, etc.
$tmp = reset($tmp);
// Remove the first item from the list because it is the same
// as the last item of $entities at this moment.
// Apigee X response always starts with the requested entity
// (pageToken).
array_shift($tmp);
$tmpEntities = $this->responseArrayToArrayOfEntities($tmp, $key_provider);
// The returned entity array is keyed by entity id which
// is unique so we can do this.
$entities += $tmpEntities;
$lastEntity = end($tmpEntities);
$lastId = $lastEntity->{$key_provider}();
} else {
$lastId = false;
}
} while ($lastId);
} while ($nextPageToken);
}

return $entities;
}
Expand Down
10 changes: 8 additions & 2 deletions src/Api/ApigeeX/Entity/AppGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,24 @@

namespace Apigee\Edge\Api\ApigeeX\Entity;

use Apigee\Edge\Api\Management\Entity\AppOwner;
use Apigee\Edge\Entity\CommonEntityPropertiesAwareTrait;
use Apigee\Edge\Entity\Entity;
use Apigee\Edge\Entity\Property\AttributesPropertyAwareTrait;
use Apigee\Edge\Entity\Property\DisplayNamePropertyAwareTrait;
use Apigee\Edge\Entity\Property\NamePropertyAwareTrait;
use Apigee\Edge\Entity\Property\StatusPropertyAwareTrait;
use Apigee\Edge\Structure\AttributesProperty;

/**
* Describes an AppGroup entity.
*/
class AppGroup extends AppOwner implements AppGroupInterface
class AppGroup extends Entity implements AppGroupInterface
{
use DisplayNamePropertyAwareTrait;
use NamePropertyAwareTrait;
use AttributesPropertyAwareTrait;
use CommonEntityPropertiesAwareTrait;
use StatusPropertyAwareTrait;

/** @var string|null */
protected $channelUri;
Expand Down
10 changes: 7 additions & 3 deletions src/Api/ApigeeX/Entity/AppGroupInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@

namespace Apigee\Edge\Api\ApigeeX\Entity;

use Apigee\Edge\Api\Management\Entity\AppOwnerInterface;
use Apigee\Edge\Entity\CommonEntityPropertiesInterface;
use Apigee\Edge\Entity\Property\AttributesPropertyInterface;
use Apigee\Edge\Entity\Property\DisplayNamePropertyInterface;
use Apigee\Edge\Entity\Property\NamePropertyInterface;
use Apigee\Edge\Entity\Property\StatusPropertyInterface;

/**
* Interface AppGroupInterface.
*/
interface AppGroupInterface extends AppOwnerInterface,
interface AppGroupInterface extends AttributesPropertyInterface,
DisplayNamePropertyInterface,
NamePropertyInterface
NamePropertyInterface,
StatusPropertyInterface,
CommonEntityPropertiesInterface
{
/**
* @param string $channelUri
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

namespace Apigee\Edge\Tests\Api\ApigeeX\Controller;

use Apigee\Edge\Api\ApigeeX\Entity\AppGroup;
use Apigee\Edge\Api\Management\Controller\AppCredentialControllerInterface;
use Apigee\Edge\Api\Management\Entity\AppCredentialInterface;
use Apigee\Edge\Api\Management\Entity\AppInterface;
use Apigee\Edge\Api\Management\Entity\AppOwnerInterface;
use Apigee\Edge\Structure\CredentialProductInterface;
use Apigee\Edge\Tests\Api\Management\Entity\ApiProductTestEntityProviderTrait;
use Apigee\Edge\Tests\Test\Controller\DefaultAPIClientAwareTrait;
Expand Down Expand Up @@ -330,9 +330,9 @@ public function testDelete(): void
$this->assertFalse($found, 'Credential credential has not been deleted.');
}

abstract protected static function setupTestApp(AppOwnerInterface $appOwner): AppInterface;
abstract protected static function setupTestApp(AppGroup $appOwner): AppInterface;

abstract protected static function setupTestAppOwner(): AppOwnerInterface;
abstract protected static function setupTestAppOwner(): AppGroup;

/**
* @return \Apigee\Edge\Tests\Test\Controller\EntityControllerTesterInterface|\Apigee\Edge\Api\Management\Controller\AppByOwnerControllerInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
namespace Apigee\Edge\Tests\Api\ApigeeX\Controller;

use Apigee\Edge\Api\ApigeeX\Controller\AppGroupAppCredentialController;
use Apigee\Edge\Api\ApigeeX\Entity\AppGroup;
use Apigee\Edge\Api\ApigeeX\Entity\AppGroupInterface;
use Apigee\Edge\Api\Management\Entity\AppInterface;
use Apigee\Edge\Api\Management\Entity\AppOwnerInterface;
use Apigee\Edge\ClientInterface;
use Apigee\Edge\Entity\EntityInterface;
use Apigee\Edge\Tests\Api\ApigeeX\Entity\AppGroupAppTestEntityProviderTrait;
Expand Down Expand Up @@ -54,15 +54,15 @@ protected static function entityController(ClientInterface $client = null): Enti
return new EntityControllerTester(new AppGroupAppCredentialController(static::defaultTestOrganization($client), static::$testAppOwner->id(), static::$testApp->id(), $client));
}

protected static function setupTestApp(AppOwnerInterface $appOwner): AppInterface
protected static function setupTestApp(AppGroup $appOwner): AppInterface
{
$app = static::getNewAppGroupApp();
static::appGroupAppController()->create($app);

return $app;
}

protected static function setupTestAppOwner(): AppOwnerInterface
protected static function setupTestAppOwner(): AppGroup
{
$appGroup = static::getNewAppGroup();
static::appGroupController()->create($appGroup);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"appGroups": [
{
"name": "phpunit",
"displayName": "A PHPUnit appgroup",
"status": "active",
"attributes": [
{
"name": "foo",
"value": "bar"
}
],
"createdAt": 1691588699000,
"lastModifiedAt": 1691588699617
},
{
"name": "1phpunit",
"displayName": "A PHPUnit appgroup",
"status": "active",
"attributes": [
{
"name": "foo",
"value": "bar"
}
],
"createdAt": 1691588699000,
"lastModifiedAt": 1691588699617
},
{
"name": "2phpunit",
"displayName": "A PHPUnit appgroup",
"status": "active",
"attributes": [
{
"name": "foo",
"value": "bar"
}
],
"createdAt": 1691588699000,
"lastModifiedAt": 1691588699617
},
{
"name": "3phpunit",
"displayName": "A PHPUnit appgroup",
"status": "active",
"attributes": [
{
"name": "foo",
"value": "bar"
}
],
"createdAt": 1691588699000,
"lastModifiedAt": 1691588699617
},
{
"name": "4phpunit",
"displayName": "A PHPUnit appgroup",
"status": "active",
"attributes": [
{
"name": "foo",
"value": "bar"
}
],
"createdAt": 1691588699000,
"lastModifiedAt": 1691588699617
}
]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"apps": [],
"channelUri": "http:\/\/example.com",
"channelId": "devportal",
"name": "phpunit",
"displayName": "A PHPUnit appgroup",
"status": "active",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"apps": [],
"channelUri": "http:\/\/example.com",
"channelId": "devportal",
"name": "phpunit",
"displayName": "(Edited) A PHPUnit appgroup",
"status": "active",
Expand All @@ -21,4 +22,4 @@
"createdBy": "[email protected]",
"lastModifiedAt": 1691588699000,
"lastModifiedBy": "[email protected]"
}
}
Loading
Loading