Skip to content
Snippets Groups Projects
Commit c05a5f05 authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

Remove person code and rename to relay-base-organization-bundle

parent c92db122
No related branches found
No related tags found
No related merge requests found
Pipeline #58182 passed
Showing
with 267 additions and 461 deletions
# DbpRelayBaseBundle # DbpRelayBaseOrganizationBundle
[GitLab](https://gitlab.tugraz.at/dbp/relay/dbp-relay-base-bundle) | [Packagist](https://packagist.org/packages/dbp/relay-base-bundle) [GitLab](https://gitlab.tugraz.at/dbp/relay/dbp-relay-base-organization-bundle) | [Packagist](https://packagist.org/packages/dbp/relay-base-organization-bundle)
This Symfony bundle contains entities required by many bundles for the DBP Relay project.
## Integration into the Relay API Server
* Add the bundle package as a dependency:
```
composer require dbp/relay-base-bundle
```
* Add the bundle to your `config/bundles.php` in front of `DbpRelayCoreBundle`:
```php
...
Dbp\Relay\BaseBundle\DbpRelayBaseBundle::class => ['all' => true],
Dbp\Relay\CoreBundle\DbpRelayCoreBundle => ['all' => true],
];
```
* Run `composer install` to clear caches
## PersonProvider service
For this bundle to work you need to create a service that implements
[PersonProviderInterface](https://gitlab.tugraz.at/dbp/relay/dbp-relay-base-bundle/-/blob/main/src/API/PersonProviderInterface.php)
in your application.
### Example
#### Service class
You can for example put below code into `src/Service/PersonProvider.php`:
```php
<?php
declare(strict_types=1);
namespace YourUniversity\Service;
use Dbp\Relay\BaseBundle\API\PersonProviderInterface;
use Dbp\Relay\BaseBundle\Entity\Person;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
class PersonProvider implements PersonProviderInterface
{
/**
* @param array $filters $filters['search'] can be a string to search for people (e.g. part of the name)
* @return Person[]
*/
public function getPersons(array $filters): array
{
$people = some_method_to_fetch_persons($filters);
return $people;
}
public function getPersonsByNameAndBirthDate(string $givenName, string $familyName, string $birthDate): array
{
$people = some_method_to_fetch_persons_by_name_and_birthday($givenName, $familyName, $birthDate);
return $people;
}
public function getPerson(string $id): Person
{
return some_method_to_fetch_person_by_id($id);
}
/**
* This is only used by external services (e.g. the alma bundle) to translate external persons to internal persons
*
* @param string $service identifies the service that wants to fetch a person
* @param string $serviceID identifies person by an external id
* @return Person
*/
public function getPersonForExternalService(string $service, string $serviceID): Person
{
switch($service) {
case "some-service":
return some_method_to_fetch_person_from_external_service($serviceID);
break;
default:
throw new BadRequestHttpException("Unknown service: $service");
}
}
/**
* Returns the Person matching the current user. Or null if there is no associated person
* like when the client is another server.
*/
public function getCurrentPerson(): ?Person
{
return some_method_to_fetch_current_person();
}
}
```
#### Services configuration
For above class you need to add this to your `src/Resources/config/services.yaml`:
```yaml
Dbp\Relay\BaseBundle\API\PersonProviderInterface:
'@YourUniversity\Service\PersonProvider'
```
## OrganizationProvider service
For services that need to fetch organizations you need to create a service that implements
[OrganizationProviderInterface](https://gitlab.tugraz.at/dbp/relay/dbp-relay-base-bundle/-/blob/main/src/API/OrganizationProviderInterface.php)
in your application.
### Example
#### Service class
You can for example put below code into `src/Service/OrganizationProvider.php`:
```php
<?php
declare(strict_types=1);
namespace YourUniversity\Service;
use Dbp\Relay\BaseBundle\API\OrganizationProviderInterface;
use Dbp\Relay\BaseBundle\Entity\Organization;
class OrganizationProvider implements OrganizationProviderInterface
{
public function getOrganizationById(string $identifier, string $lang): Organization
{
return some_method_that_fetches_an_organization_by_id($identifier, $lang);
}
/**
* @return Organization[]
*/
public function getOrganizationsByPerson(Person $person, string $context, string $lang): array
{
return some_method_that_fetches_an_organization_by_person($person, $context, $lang);
}
/**
* @return Organization[]
*/
public function getOrganizations(string $lang): array
{
return some_method_that_fetches_all_organizations($lang);
}
}
```
#### Services configuration
For above class you need to add this to your `src/Resources/config/services.yaml`:
```yaml
Dbp\Relay\BaseBundle\API\OrganizationProviderInterface:
'@YourUniversity\Service\OrganizationProvider'
```
{ {
"name": "dbp/relay-base-bundle", "name": "dbp/relay-base-organization-bundle",
"type": "symfony-bundle", "type": "symfony-bundle",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"require": { "require": {
"php": "^7.3", "php": "^7.3",
"ext-json": "*", "ext-json": "*",
"api-platform/core": "^2.6.3", "api-platform/core": "^2.6.3",
"dbp/relay-base-person-bundle": "^0.1.3",
"dbp/relay-core-bundle": "^0.1.11", "dbp/relay-core-bundle": "^0.1.11",
"guzzlehttp/guzzle": "^7.0", "guzzlehttp/guzzle": "^7.0",
"nelmio/cors-bundle": "^2.1.0", "nelmio/cors-bundle": "^2.1.0",
...@@ -32,12 +33,12 @@ ...@@ -32,12 +33,12 @@
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Dbp\\Relay\\BaseBundle\\": "src/" "Dbp\\Relay\\BaseOrganizationBundle\\": "src/"
} }
}, },
"autoload-dev": { "autoload-dev": {
"psr-4": { "psr-4": {
"Dbp\\Relay\\BaseBundle\\Tests\\": "tests/" "Dbp\\Relay\\BaseOrganizationBundle\\Tests\\": "tests/"
} }
}, },
"config": { "config": {
......
This diff is collapsed.
...@@ -11,5 +11,4 @@ parameters: ...@@ -11,5 +11,4 @@ parameters:
- vendor/bin/.phpunit/phpunit-9-0/vendor/autoload.php - vendor/bin/.phpunit/phpunit-9-0/vendor/autoload.php
excludes_analyse: excludes_analyse:
- tests/bootstrap.php - tests/bootstrap.php
- src/Swagger/DocumentationNormalizer.php
ignoreErrors: ignoreErrors:
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<server name="SYMFONY_PHPUNIT_REMOVE" value=""/> <server name="SYMFONY_PHPUNIT_REMOVE" value=""/>
<server name="SYMFONY_PHPUNIT_VERSION" value="9"/> <server name="SYMFONY_PHPUNIT_VERSION" value="9"/>
<server name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/> <server name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
<server name="KERNEL_CLASS" value="Dbp\Relay\BaseBundle\Tests\Kernel"/> <server name="KERNEL_CLASS" value="Dbp\Relay\BaseOrganizationBundle\Tests\Kernel"/>
</php> </php>
<testsuites> <testsuites>
<testsuite name="Project Test Suite"> <testsuite name="Project Test Suite">
......
*.private.env.json
# HTTP Requests
This request files work with PhpStorm. You can use them to test api requests.
You need to create a `http-client.private.env.json` (use `http-client.private.env.exam.json`)
for tokens like the current bearer token.
\ No newline at end of file
# Get information about one organization
GET http://127.0.0.1:8000/organizations/1190-F2050?lang=de
accept: application/ld+json
Authorization: Bearer {{bearer_token}}
###
# Search for users with name "Hands"
GET {{entry_point_url}}/people?search=Hans&page=1
accept: application/ld+json
Authorization: Bearer {{bearer_token}}
###
{
"local-dev": {
"entry_point_url": "http://127.0.0.1:8000",
// private stuff goes to http-client.private.env.json
"bearer_token": ""
},
"dev": {
"entry_point_url": "https://mw-dev.tugraz.at",
// private stuff goes to http-client.private.env.json
"bearer_token": ""
}
}
\ No newline at end of file
{
"local-dev": {
"bearer_token": "eyJhbGciOiJS_and_the_rest_of_it"
},
"dev": {
"bearer_token": "eyJhbGciOiJS_and_the_rest_of_it"
}
}
\ No newline at end of file
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
declare(strict_types=1); declare(strict_types=1);
namespace Dbp\Relay\BaseBundle\API; namespace Dbp\Relay\BaseOrganizationBundle\API;
use Dbp\Relay\BaseBundle\Entity\Organization; use Dbp\Relay\BaseOrganizationBundle\Entity\Organization;
use Dbp\Relay\BaseBundle\Entity\Person; use Dbp\Relay\BasePersonBundle\Entity\Person;
interface OrganizationProviderInterface interface OrganizationProviderInterface
{ {
......
<?php
declare(strict_types=1);
namespace Dbp\Relay\BaseBundle\API;
use Dbp\Relay\BaseBundle\Entity\Person;
interface PersonProviderInterface
{
/**
* @param array $filters $filters['search'] can be a string to search for people (e.g. part of the name)
* @return Person[]
*/
public function getPersons(array $filters): array;
/**
* @return Person[]
*/
public function getPersonsByNameAndBirthDate(string $givenName, string $familyName, string $birthDate): array;
public function getPerson(string $id): Person;
/**
* This is only used by external services (e.g. the alma bundle) to translate external persons to internal persons
*
* @param string $service identifies the service that wants to fetch a person
* @param string $serviceID identifies person by an external id
* @return Person
*/
public function getPersonForExternalService(string $service, string $serviceID): Person;
/**
* Returns the Person matching the current user. Or null if there is no associated person
* like when the client is another server.
*/
public function getCurrentPerson(): ?Person;
}
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
declare(strict_types=1); declare(strict_types=1);
namespace Dbp\Relay\BaseBundle\Controller; namespace Dbp\Relay\BaseOrganizationBundle\Controller;
use ApiPlatform\Core\DataProvider\PaginatorInterface; use ApiPlatform\Core\DataProvider\PaginatorInterface;
use Dbp\Relay\BaseBundle\API\OrganizationProviderInterface; use Dbp\Relay\BaseOrganizationBundle\API\OrganizationProviderInterface;
use Dbp\Relay\BaseBundle\API\PersonProviderInterface; use Dbp\Relay\BasePersonBundle\API\PersonProviderInterface;
use Dbp\Relay\CoreBundle\Exception\ApiError; use Dbp\Relay\CoreBundle\Exception\ApiError;
use Dbp\Relay\CoreBundle\Helpers\ArrayFullPaginator; use Dbp\Relay\CoreBundle\Helpers\ArrayFullPaginator;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
......
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
declare(strict_types=1); declare(strict_types=1);
namespace Dbp\Relay\BaseBundle\DataProvider; namespace Dbp\Relay\BaseOrganizationBundle\DataProvider;
use ApiPlatform\Core\DataProvider\ContextAwareCollectionDataProviderInterface; use ApiPlatform\Core\DataProvider\ContextAwareCollectionDataProviderInterface;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
use Dbp\Relay\BaseBundle\API\OrganizationProviderInterface; use Dbp\Relay\BaseOrganizationBundle\API\OrganizationProviderInterface;
use Dbp\Relay\BaseBundle\Entity\Organization; use Dbp\Relay\BaseOrganizationBundle\Entity\Organization;
use Dbp\Relay\CoreBundle\Helpers\ArrayFullPaginator; use Dbp\Relay\CoreBundle\Helpers\ArrayFullPaginator;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
......
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
declare(strict_types=1); declare(strict_types=1);
namespace Dbp\Relay\BaseBundle\DataProvider; namespace Dbp\Relay\BaseOrganizationBundle\DataProvider;
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
use Dbp\Relay\BaseBundle\API\OrganizationProviderInterface; use Dbp\Relay\BaseOrganizationBundle\API\OrganizationProviderInterface;
use Dbp\Relay\BaseBundle\Entity\Organization; use Dbp\Relay\BaseOrganizationBundle\Entity\Organization;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
final class OrganizationDataProvider extends AbstractController implements ItemDataProviderInterface, RestrictedDataProviderInterface final class OrganizationDataProvider extends AbstractController implements ItemDataProviderInterface, RestrictedDataProviderInterface
......
<?php
declare(strict_types=1);
namespace Dbp\Relay\BaseBundle\DataProvider;
use ApiPlatform\Core\DataProvider\CollectionDataProviderInterface;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
use Dbp\Relay\BaseBundle\API\PersonProviderInterface;
use Dbp\Relay\BaseBundle\Entity\Person;
use Dbp\Relay\CoreBundle\Helpers\ArrayFullPaginator;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
final class PersonCollectionDataProvider extends AbstractController implements CollectionDataProviderInterface, RestrictedDataProviderInterface
{
public const ITEMS_PER_PAGE = 250;
private $api;
public function __construct(PersonProviderInterface $api)
{
$this->api = $api;
}
public function supports(string $resourceClass, string $operationName = null, array $context = []): bool
{
return Person::class === $resourceClass;
}
public function getCollection(string $resourceClass, string $operationName = null, array $context = []): ArrayFullPaginator
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$perPage = self::ITEMS_PER_PAGE;
$page = 1;
$api = $this->api;
$filters = $context['filters'] ?? [];
if (isset($context['filters']['page'])) {
$page = (int) $context['filters']['page'];
}
if (isset($context['filters']['perPage'])) {
$perPage = (int) $context['filters']['perPage'];
}
$persons = $api->getPersons($filters);
// TODO: do pagination via API
$pagination = new ArrayFullPaginator($persons, $page, $perPage);
return $pagination;
}
}
<?php
declare(strict_types=1);
namespace Dbp\Relay\BaseBundle\DataProvider;
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
use Dbp\Relay\BaseBundle\API\PersonProviderInterface;
use Dbp\Relay\BaseBundle\Entity\Person;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
final class PersonItemDataProvider extends AbstractController implements ItemDataProviderInterface, RestrictedDataProviderInterface
{
private $api;
public function __construct(PersonProviderInterface $api)
{
$this->api = $api;
}
public function supports(string $resourceClass, string $operationName = null, array $context = []): bool
{
return Person::class === $resourceClass;
}
public function getItem(string $resourceClass, $id, string $operationName = null, array $context = []): ?Person
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$person = null;
$api = $this->api;
$person = $api->getPerson($id);
return $person;
}
}
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
declare(strict_types=1); declare(strict_types=1);
namespace Dbp\Relay\BaseBundle; namespace Dbp\Relay\BaseOrganizationBundle;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\HttpKernel\Bundle\Bundle;
class DbpRelayBaseBundle extends Bundle class DbpRelayBaseOrganizationBundle extends Bundle
{ {
public function build(ContainerBuilder $container) public function build(ContainerBuilder $container)
{ {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace Dbp\Relay\BaseBundle\DependencyInjection; namespace Dbp\Relay\BaseOrganizationBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\Config\Definition\ConfigurationInterface;
...@@ -11,7 +11,7 @@ class Configuration implements ConfigurationInterface ...@@ -11,7 +11,7 @@ class Configuration implements ConfigurationInterface
{ {
public function getConfigTreeBuilder() public function getConfigTreeBuilder()
{ {
$treeBuilder = new TreeBuilder('dbp_relay_base'); $treeBuilder = new TreeBuilder('dbp_relay_base_organization');
return $treeBuilder; return $treeBuilder;
} }
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
declare(strict_types=1); declare(strict_types=1);
namespace Dbp\Relay\BaseBundle\DependencyInjection; namespace Dbp\Relay\BaseOrganizationBundle\DependencyInjection;
use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension; use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension;
class DbpRelayBaseExtension extends ConfigurableExtension class DbpRelayBaseOrganizationExtension extends ConfigurableExtension
{ {
public function loadInternal(array $mergedConfig, ContainerBuilder $container) public function loadInternal(array $mergedConfig, ContainerBuilder $container)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment