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

Added pagination for AppGroups Apps-3x #307

Merged
merged 3 commits into from
Sep 15, 2023
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
53 changes: 53 additions & 0 deletions src/Api/ApigeeX/Controller/AppByOwnerController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Apigee\Edge\Api\ApigeeX\Controller;

use Apigee\Edge\Api\Management\Controller\AttributesAwareEntityControllerTrait;
use Apigee\Edge\Api\Management\Serializer\AppEntitySerializer;
use Apigee\Edge\ClientInterface;
use Apigee\Edge\Controller\EntityCrudOperationsControllerTrait;
use Apigee\Edge\Controller\EntityListingControllerTrait;
use Apigee\Edge\Controller\StatusAwareEntityControllerTrait;
use Apigee\Edge\Serializer\EntitySerializerInterface;

/**
* Common parent class for appgroup and developer app controllers.
*/
abstract class AppByOwnerController extends PaginatedEntityController implements AppByOwnerControllerInterface
{
use AttributesAwareEntityControllerTrait;
use EntityCrudOperationsControllerTrait;
use EntityListingControllerTrait;
use PaginatedEntityListingControllerTrait;
use PaginationHelperTrait;
use StatusAwareEntityControllerTrait;

/**
* AppByOwnerController constructor.
*
* @param string $organization
* @param ClientInterface $client
* @param EntitySerializerInterface|null $entitySerializer
*/
public function __construct(string $organization, ClientInterface $client, EntitySerializerInterface $entitySerializer = null)
{
$entitySerializer = $entitySerializer ?? new AppEntitySerializer();
parent::__construct($organization, $client, $entitySerializer);
}
}
46 changes: 46 additions & 0 deletions src/Api/ApigeeX/Controller/AppByOwnerControllerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Apigee\Edge\Api\ApigeeX\Controller;

use Apigee\Edge\Api\Management\Controller\AttributesAwareEntityControllerInterface;
use Apigee\Edge\Controller\EntityControllerInterface;
use Apigee\Edge\Controller\EntityCrudOperationsControllerInterface;
use Apigee\Edge\Controller\StatusAwareEntityControllerInterface;

/**
* Describes common operations for appgroup and developer apps.
*/
interface AppByOwnerControllerInterface extends
AttributesAwareEntityControllerInterface,
EntityControllerInterface,
EntityCrudOperationsControllerInterface,
StatusAwareEntityControllerInterface
{
/**
* Returns a list of entities from Apigee Edge.
*
* It only returns maximum 100 entities in case of developer- and appgroup
* apps. Check the related API documentation for more information.
* Use implementation of the AppControllerInterface to load _all_ apps
* from Apigee Edge.
*
* @return \Apigee\Edge\Entity\EntityInterface[]
*/
public function getEntities(): array;
}
27 changes: 3 additions & 24 deletions src/Api/ApigeeX/Controller/AppGroupAppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@

use Apigee\Edge\Api\ApigeeX\Entity\AppGroupApp;
use Apigee\Edge\Api\ApigeeX\Serializer\AppGroupEntitySerializer;
use Apigee\Edge\Api\Management\Controller\AppByOwnerController;
use Apigee\Edge\Api\ApigeeX\Structure\PagerInterface;
use Apigee\Edge\Api\Management\Controller\OrganizationController;
use Apigee\Edge\Api\Management\Controller\OrganizationControllerInterface;
use Apigee\Edge\ClientInterface;
use Apigee\Edge\Serializer\EntitySerializerInterface;
use Apigee\Edge\Structure\PagerInterface;
use Psr\Http\Message\UriInterface;

/**
Expand Down Expand Up @@ -53,35 +52,15 @@ public function __construct(
string $organization,
string $appGroup,
ClientInterface $client,
?EntitySerializerInterface $entitySerializer = null,
?OrganizationControllerInterface $organizationController = null
EntitySerializerInterface $entitySerializer = null,
OrganizationControllerInterface $organizationController = null
) {
$this->appGroup = $appGroup;
$entitySerializer = $entitySerializer ?? new AppGroupEntitySerializer();
$this->organizationController = $organizationController ?? new OrganizationController($client);
parent::__construct($organization, $client, $entitySerializer);
}

/**
* Override the getEntities() method, for AppGroup compatibility.
*
* AppGroup does not support the "expand=false" query parameter.
*
* {@inheritdoc}
*
* @return \Apigee\Edge\Entity\EntityInterface[]
*/
public function getEntities(): array
{
$uri = $this->getBaseEndpointUri();
$response = $this->getClient()->get($uri);
$responseArray = $this->responseToArray($response);
// Ignore entity type key from response, ex.: apiProduct.
$responseArray = reset($responseArray);

return $this->responseArrayToArrayOfEntities($responseArray);
}

/**
* Override the getEntityIds() method, for AppGroup compatibility.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@

namespace Apigee\Edge\Api\ApigeeX\Controller;

use Apigee\Edge\Api\Management\Controller\AppByOwnerControllerInterface;

/**
* Interface AppGroupAppControllerInterface.
*
* @see https://apidocs.apigee.com/api/apps-appgroup
* @see https://cloud.google.com/apigee/docs/reference/apis/apigee/rest/v1/organizations.appgroups.apps
*/
interface AppGroupAppControllerInterface extends AppByOwnerControllerInterface, AppGroupAwareControllerInterface
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"app": [
{
"appFamily": "default",
"appId": "b3e71cbb-7eb5-4444-b384-ac82bca1d9dc",
"attributes": [
{
"name": "DisplayName",
"value": "PHP Unit: Test app"
},
{
"name": "Notes",
"value": "This is a test app created by PHP Unit."
},
{
"name": "foo",
"value": "foo"
},
{
"name": "bar",
"value": "baz"
}
],
"callbackUrl": "http://example.com",
"createdAt": 648345600000,
"createdBy": "[email protected]",
"credentials": [
{
"apiProducts": [],
"attributes": [],
"consumerKey": "wAXAIiOr2oJOVGqFltnm3Jwr2LE0GEuY",
"consumerSecret": "S8YjnsjmdBqDAegR",
"issuedAt": 648345600000,
"scopes": [],
"status": "approved"
}
],
"appGroup": "phpunit",
"lastModifiedAt": 648345600000,
"lastModifiedBy": "[email protected]",
"name": "4phpunit_test_app",
"scopes": [],
"status": "approved"
},
{
"appFamily": "default",
"appId": "b3e71cbb-7eb5-3333-b384-ac82bca1d9dc",
"attributes": [
{
"name": "DisplayName",
"value": "PHP Unit: Test app"
},
{
"name": "Notes",
"value": "This is a test app created by PHP Unit."
},
{
"name": "foo",
"value": "bar"
}
],
"callbackUrl": "http://example.com",
"createdAt": 648345600000,
"createdBy": "[email protected]",
"credentials": [
{
"apiProducts": [],
"attributes": [],
"consumerKey": "wAXAIiOr2oJOVGqFltnm3Jwr2LE0GEuY",
"consumerSecret": "S8YjnsjmdBqDAegR",
"issuedAt": 648345600000,
"scopes": [],
"status": "approved"
}
],
"appGroup": "phpunit",
"lastModifiedAt": 648345600000,
"lastModifiedBy": "[email protected]",
"name": "5phpunit_test_app",
"scopes": [],
"status": "approved"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"app": [
{
"appFamily": "default",
"appId": "b3e71cbb-7eb5-3333-b384-ac82bca1d9dc",
"attributes": [
{
"name": "DisplayName",
"value": "PHP Unit: Test app"
},
{
"name": "Notes",
"value": "This is a test app created by PHP Unit."
},
{
"name": "foo",
"value": "bar"
}
],
"callbackUrl": "http://example.com",
"createdAt": 648345600000,
"createdBy": "[email protected]",
"credentials": [
{
"apiProducts": [],
"attributes": [],
"consumerKey": "wAXAIiOr2oJOVGqFltnm3Jwr2LE0GEuY",
"consumerSecret": "S8YjnsjmdBqDAegR",
"issuedAt": 648345600000,
"scopes": [],
"status": "approved"
}
],
"appGroup": "phpunit",
"lastModifiedAt": 648345600000,
"lastModifiedBy": "[email protected]",
"name": "5phpunit_test_app",
"scopes": [],
"status": "approved"
}
]
}
Loading