From f89b6cceedde6ee2f0f38071c08cfb7cd10e3708 Mon Sep 17 00:00:00 2001 From: Robert Zondervan Date: Mon, 30 Dec 2024 15:58:46 +0100 Subject: [PATCH 1/4] Remove controllers in wrong folder --- src/Controller/JobController.php | 1 - src/Controller/LogController.php | 1 - src/Controller/SourceController.php | 1 - 3 files changed, 3 deletions(-) delete mode 100644 src/Controller/JobController.php delete mode 100644 src/Controller/LogController.php delete mode 100644 src/Controller/SourceController.php diff --git a/src/Controller/JobController.php b/src/Controller/JobController.php deleted file mode 100644 index 0519ecba..00000000 --- a/src/Controller/JobController.php +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/Controller/LogController.php b/src/Controller/LogController.php deleted file mode 100644 index 0519ecba..00000000 --- a/src/Controller/LogController.php +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/Controller/SourceController.php b/src/Controller/SourceController.php deleted file mode 100644 index 0519ecba..00000000 --- a/src/Controller/SourceController.php +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file From 1cf6e7059560093723fd2c0d42eb817615dd99fb Mon Sep 17 00:00:00 2001 From: Robert Zondervan Date: Mon, 30 Dec 2024 15:59:06 +0100 Subject: [PATCH 2/4] Add endpoint postfixes --- appinfo/routes.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index e8ee2bf2..0444f268 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -25,9 +25,9 @@ ['name' => 'mappings#saveObject', 'url' => '/api/mappings/objects', 'verb' => 'POST'], ['name' => 'mappings#getObjects', 'url' => '/api/mappings/objects', 'verb' => 'GET'], // Running endpoints - allow any path after /api/endpoints/ - ['name' => 'endpoints#handlePath', 'url' => '/api/endpoint/{_path}', 'verb' => 'GET', 'requirements' => ['_path' => '.+']], -// ['name' => 'endpoints#handlePath', 'url' => '/api/endpoint/{path}', 'verb' => 'PUT', 'requirements' => ['path' => '.+']], -// ['name' => 'endpoints#handlePath', 'url' => '/api/endpoint/{path}', 'verb' => 'POST', 'requirements' => ['path' => '.+']], -// ['name' => 'endpoints#handlePath', 'url' => '/api/endpoint/{path}', 'verb' => 'DELETE', 'requirements' => ['path' => '.+']], + ['name' => 'endpoints#handlePath', 'postfix' => 'read', 'url' => '/api/endpoint/{_path}', 'verb' => 'GET', 'requirements' => ['_path' => '.+']], + ['name' => 'endpoints#handlePath', 'postfix' => 'update', 'url' => '/api/endpoint/{_path}', 'verb' => 'PUT', 'requirements' => ['_path' => '.+']], + ['name' => 'endpoints#handlePath', 'postfix' => 'create', 'url' => '/api/endpoint/{_path}', 'verb' => 'POST', 'requirements' => ['_path' => '.+']], + ['name' => 'endpoints#handlePath', 'postfix' => 'destroy', 'url' => '/api/endpoint/{_path}', 'verb' => 'DELETE', 'requirements' => ['_path' => '.+']], ], ]; From 959c7806e05fed2e113beff7ebfcbc58a9b039d9 Mon Sep 17 00:00:00 2001 From: Robert Zondervan Date: Mon, 30 Dec 2024 15:59:19 +0100 Subject: [PATCH 3/4] Add query mapping --- lib/Db/Endpoint.php | 7 +++ lib/Migration/Version1Date20241230141628.php | 59 ++++++++++++++++++++ lib/Service/EndpointService.php | 8 +++ 3 files changed, 74 insertions(+) create mode 100644 lib/Migration/Version1Date20241230141628.php diff --git a/lib/Db/Endpoint.php b/lib/Db/Endpoint.php index 6f95cd72..aebd4961 100644 --- a/lib/Db/Endpoint.php +++ b/lib/Db/Endpoint.php @@ -23,6 +23,8 @@ class Endpoint extends Entity implements JsonSerializable protected array $conditions = []; protected ?DateTime $created = null; protected ?DateTime $updated = null; + protected ?string $inputMapping = null; + protected ?string $outputMapping = null; public function __construct() { $this->addType(fieldName:'uuid', type: 'string'); @@ -39,6 +41,9 @@ public function __construct() { $this->addType(fieldName:'conditions', type: 'json'); $this->addType(fieldName:'created', type: 'datetime'); $this->addType(fieldName:'updated', type: 'datetime'); + $this->addType(fieldName:'inputMapping', type: 'string'); + $this->addType(fieldName:'outputMapping', type: 'string'); + } public function getJsonFields(): array @@ -89,6 +94,8 @@ public function jsonSerialize(): array 'conditions' => $this->conditions, 'created' => isset($this->created) ? $this->created->format('c') : null, 'updated' => isset($this->updated) ? $this->updated->format('c') : null, + 'inputMapping' => $this->inputMapping, + 'outputMapping' => $this->outputMapping, ]; } diff --git a/lib/Migration/Version1Date20241230141628.php b/lib/Migration/Version1Date20241230141628.php new file mode 100644 index 00000000..33ef7463 --- /dev/null +++ b/lib/Migration/Version1Date20241230141628.php @@ -0,0 +1,59 @@ +hasTable(tableName: 'openconnector_endpoints') === true) { + $table = $schema->getTable(tableName: 'openconnector_endpoints'); + $table->addColumn('input_mapping', Types::STRING)->setNotnull(false)->setDefault(null); + $table->addColumn('output_mapping', Types::STRING)->setNotnull(false)->setDefault(null); + } + + return $schema; + } + + /** + * @param IOutput $output + * @param Closure(): ISchemaWrapper $schemaClosure + * @param array $options + */ + public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void { + } +} diff --git a/lib/Service/EndpointService.php b/lib/Service/EndpointService.php index ea778512..e44c2fba 100644 --- a/lib/Service/EndpointService.php +++ b/lib/Service/EndpointService.php @@ -46,6 +46,7 @@ public function __construct( private readonly CallService $callService, private readonly LoggerInterface $logger, private readonly IURLGenerator $urlGenerator, + private readonly MappingService $mappingService, ) { } @@ -228,10 +229,17 @@ private function handleSchemaRequest(Endpoint $endpoint, IRequest $request, stri $register = $target[0]; $schema = $target[1]; + $mapper = $this->objectService->getMapper(schema: $schema, register: $register); $parameters = $request->getParams(); + + if($endpoint->getInputMapping() !== null) { + $inputMapping = $this->mappingService->getMapping($endpoint->getInputMapping()); + $parameters = $this->mappingService->executeMapping(mapping: $inputMapping, input: $parameters); + } + $pathParams = $this->getPathParameters($endpoint->getEndpointArray(), $path); unset($parameters['_route'], $parameters['_path']); From 1a440b571e3d89fd12a0ddd9cbf4414653316996 Mon Sep 17 00:00:00 2001 From: Robert Zondervan Date: Mon, 6 Jan 2025 15:18:16 +0100 Subject: [PATCH 4/4] Set default value for conditions --- lib/Migration/Version1Date20241230141628.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Migration/Version1Date20241230141628.php b/lib/Migration/Version1Date20241230141628.php index 33ef7463..265443a0 100644 --- a/lib/Migration/Version1Date20241230141628.php +++ b/lib/Migration/Version1Date20241230141628.php @@ -44,6 +44,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt $table = $schema->getTable(tableName: 'openconnector_endpoints'); $table->addColumn('input_mapping', Types::STRING)->setNotnull(false)->setDefault(null); $table->addColumn('output_mapping', Types::STRING)->setNotnull(false)->setDefault(null); + $table->getColumn('conditions')->setDefault('[]'); } return $schema;