From 53dcc9fb804adf1a266a8e07b5a327fbee2f6a0a Mon Sep 17 00:00:00 2001 From: Wilco Louwerse Date: Thu, 31 Oct 2024 17:02:50 +0100 Subject: [PATCH 01/24] w.i.p. download schema as json file + set schema.source for upload --- lib/Controller/SchemasController.php | 37 +++---- lib/Migration/Version1Date20241030131427.php | 8 ++ lib/Service/DownloadService.php | 103 ++++++++++++++++--- lib/Service/UploadService.php | 4 +- 4 files changed, 114 insertions(+), 38 deletions(-) diff --git a/lib/Controller/SchemasController.php b/lib/Controller/SchemasController.php index 269e737..0cd7250 100644 --- a/lib/Controller/SchemasController.php +++ b/lib/Controller/SchemasController.php @@ -219,6 +219,8 @@ public function upload(?int $id = null): JSONResponse return $phpArray; } + //@todo Maybe check if Schema already exists? If uploaded with url, check if schema with this $phpArray['source'] exists? + // Set default title if not provided or empty if (empty($phpArray['title']) === true) { $phpArray['title'] = 'New Schema'; @@ -236,43 +238,30 @@ public function upload(?int $id = null): JSONResponse /** * Creates and return a json file for a Schema. - * @todo move most of this code to DownloadService and make it even more Abstract using Entity->jsonSerialize instead of Schema->jsonSerialize, etc. * * @NoAdminRequired * @NoCSRFRequired * * @param int $id The ID of the schema to return json file for * @return JSONResponse A json Response containing the json + * @throws \Exception */ public function download(int $id): JSONResponse { - try { - $schema = $this->schemaMapper->find($id); - } catch (DoesNotExistException $exception) { - return new JSONResponse(data: ['error' => 'Not Found'], statusCode: 404); - } - - $contentType = $this->request->getHeader('Content-Type'); + $accept = $this->request->getHeader('Accept'); - if (empty($contentType) === true) { - return new JSONResponse(data: ['error' => 'Request is missing header Content-Type'], statusCode: 400); + if (empty($accept) === true) { + return new JSONResponse(data: ['error' => 'Request is missing header Accept'], statusCode: 400); } - switch ($contentType) { - case 'application/json': - $type = 'json'; - $responseData = [ - 'jsonArray' => $schema->jsonSerialize(), - 'jsonString' => json_encode($schema->jsonSerialize()) - ]; - break; - default: - return new JSONResponse(data: ['error' => "The Content-Type $contentType is not supported."], statusCode: 400); - } + $responseData = $this->downloadService->download(objectType: 'schema', id: $id, accept: $accept); - // @todo Create a downloadable json file and return it. - $file = $this->downloadService->download(type: $type); + $statusCode = 200; + if (isset($responseData['statusCode']) === true) { + $statusCode = $responseData['statusCode']; + unset($responseData['statusCode']); + } - return new JSONResponse($responseData); + return new JSONResponse(data: $responseData, statusCode: $statusCode); } } diff --git a/lib/Migration/Version1Date20241030131427.php b/lib/Migration/Version1Date20241030131427.php index 6f820f6..a5ab5d4 100644 --- a/lib/Migration/Version1Date20241030131427.php +++ b/lib/Migration/Version1Date20241030131427.php @@ -44,6 +44,14 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt $table->addColumn(name: 'hard_validation', typeName: Types::BOOLEAN, options: ['notnull' => true])->setDefault(default: false); } + if ($table->hasColumn('archive') === false) { + $table->addColumn(name: 'archive', typeName: Types::JSON, options: ['notnull' => false])->setDefault(default: null); + } + + if ($table->hasColumn('source') === false) { + $table->addColumn(name: 'source', typeName: Types::STRING, options: ['notnull' => false])->setDefault(default: ''); + } + if ($schema->hasTable('openregister_object_audit_logs') === false) { $table = $schema->createTable('openregister_object_audit_logs'); $table->addColumn('id', Types::BIGINT, ['autoincrement' => true, 'notnull' => true]); diff --git a/lib/Service/DownloadService.php b/lib/Service/DownloadService.php index 981b62d..22a8c70 100644 --- a/lib/Service/DownloadService.php +++ b/lib/Service/DownloadService.php @@ -2,25 +2,102 @@ namespace OCA\OpenRegister\Service; -use GuzzleHttp\Client; -use GuzzleHttp\Promise\Utils; -use OCP\IURLGenerator; -use Symfony\Component\Uid\Uuid; +use Exception; +use InvalidArgumentException; +use JetBrains\PhpStorm\NoReturn; +use OCA\OpenRegister\Db\RegisterMapper; +use OCA\OpenRegister\Db\SchemaMapper; class DownloadService { - public function __construct() {} + public function __construct( + private SchemaMapper $schemaMapper, + private RegisterMapper $registerMapper + ) {} - public function download(string $type) + /** + * Download a DB entity as a file. Depending on given Accept-header the file type might differ. + * + * @param string $objectType The type of object to download. + * @param string|int $id The id of the object to download. + * @param string $accept The Accept-header from the download request. + * + * @return array The response data for the download request. + * @throws Exception + */ + public function download(string $objectType, string|int $id, string $accept) { - switch ($type) { - case 'json': - // @todo this is placeholder code - break; - default: - // @todo some logging - return null; + // Get the appropriate mapper for the object type + $mapper = $this->getMapper($objectType); + + try { + $object = $mapper->find($id); + } catch (Exception $exception) { + return ['error' => "Could not find $objectType with id $id.", 'statusCode' => 404]; + } + + $objectArray = $object->jsonSerialize(); + $filename = $objectArray['title'].ucfirst($objectType).'-v'.$objectArray['version']; + + if ($accept === 'application/json') { + // Convert the object data to JSON + $jsonData = json_encode($objectArray, JSON_PRETTY_PRINT); + + $this->downloadJson($jsonData, $filename); } + + return ['error' => "The Accept type $accept is not supported.", 'statusCode' => 400]; + } + + /** + * Generate a downloadable json file response. + * + * @param string $jsonData The json data to create a json file with. + * @param string $filename The filename, .json will be added after this filename in this function. + * + * @return void + */ + #[NoReturn] private function downloadJson(string $jsonData, string $filename): void + { + // Define the file name and path for the temporary JSON file + $fileName = $filename.'.json'; + $filePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileName; + + // Create and write the JSON data to the file + file_put_contents($filePath, $jsonData); + + // Set headers to download the file + header('Content-Type: application/json'); + header('Content-Disposition: attachment; filename="' . $fileName . '"'); + header('Content-Length: ' . filesize($filePath)); + + // Output the file contents + readfile($filePath); + + // Clean up: delete the temporary file + unlink($filePath); + exit; // Ensure no further script execution + } + + /** + * Gets the appropriate mapper based on the object type. + * + * @param string $objectType The type of object to retrieve the mapper for. + * + * @return mixed The appropriate mapper. + * @throws InvalidArgumentException If an unknown object type is provided. + * @throws Exception + */ + private function getMapper(string $objectType): mixed + { + $objectTypeLower = strtolower($objectType); + + // If the source is internal, return the appropriate mapper based on the object type + return match ($objectTypeLower) { + 'schema' => $this->schemaMapper, + 'register' => $this->registerMapper, + default => throw new InvalidArgumentException("Unknown object type: $objectType"), + }; } } diff --git a/lib/Service/UploadService.php b/lib/Service/UploadService.php index f14ae18..6fe6717 100644 --- a/lib/Service/UploadService.php +++ b/lib/Service/UploadService.php @@ -56,7 +56,9 @@ public function getUploadedJson(array $data): array|JSONResponse } if (empty($data['url']) === false) { - return $this->getJSONfromURL($data['url']); + $phpArray = $this->getJSONfromURL($data['url']); + $phpArray['source'] = $data['url']; + return $phpArray; } $phpArray = $data['json']; From b2733d5167240014ebf26d0529661e5ec53195c0 Mon Sep 17 00:00:00 2001 From: Wilco Louwerse Date: Thu, 7 Nov 2024 17:45:02 +0100 Subject: [PATCH 02/24] Fix fields for Register & change how download response is stuctured --- lib/Migration/Version1Date20241030131427.php | 18 ++++++++++++++---- lib/Service/DownloadService.php | 19 +++++++++++++++++-- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/lib/Migration/Version1Date20241030131427.php b/lib/Migration/Version1Date20241030131427.php index f80d748..dff2f06 100644 --- a/lib/Migration/Version1Date20241030131427.php +++ b/lib/Migration/Version1Date20241030131427.php @@ -47,14 +47,24 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt $table->addColumn(name: 'archive', typeName: Types::JSON, options: ['notnull' => false])->setDefault(default: '{}'); } - if ($table->hasColumn('archive') === false) { - $table->addColumn(name: 'archive', typeName: Types::JSON, options: ['notnull' => false])->setDefault(default: null); - } - if ($table->hasColumn('source') === false) { $table->addColumn(name: 'source', typeName: Types::STRING, options: ['notnull' => false])->setDefault(default: ''); } + // Update the openregister_registers table + $table = $schema->getTable('openregister_registers'); + if ($table->hasColumn('source') === true) { + $column = $table->getColumn('source'); + $column->setNotnull(false); + $column->setDefault(''); + } + + if ($table->hasColumn('table_prefix') === true) { + $column = $table->getColumn('table_prefix'); + $column->setNotnull(false); + $column->setDefault(''); + } + if ($schema->hasTable('openregister_object_audit_logs') === false) { $table = $schema->createTable('openregister_object_audit_logs'); $table->addColumn('id', Types::BIGINT, ['autoincrement' => true, 'notnull' => true]); diff --git a/lib/Service/DownloadService.php b/lib/Service/DownloadService.php index 22a8c70..51e42dd 100644 --- a/lib/Service/DownloadService.php +++ b/lib/Service/DownloadService.php @@ -7,10 +7,12 @@ use JetBrains\PhpStorm\NoReturn; use OCA\OpenRegister\Db\RegisterMapper; use OCA\OpenRegister\Db\SchemaMapper; +use OCP\IURLGenerator; class DownloadService { public function __construct( + private IURLGenerator $urlGenerator, private SchemaMapper $schemaMapper, private RegisterMapper $registerMapper ) {} @@ -39,9 +41,22 @@ public function download(string $objectType, string|int $id, string $accept) $objectArray = $object->jsonSerialize(); $filename = $objectArray['title'].ucfirst($objectType).'-v'.$objectArray['version']; - if ($accept === 'application/json') { + if (str_contains(haystack: $accept, needle: 'application/json') === true) { + $url = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute('openregister.'.ucfirst($objectType).'s.show', ['id' => $object->getId()])); + + // @todo: json+ld? str_contains($accept,'json+ld') === true, else: + // Json... + $objArray['title'] = $objectArray['title']; + $objArray['$id'] = $url; +// $objArray['$schema'] = 'https://json-schema.org/draft/2020-12/schema'; + $objArray['$schema'] = 'https://docs.commongateway.nl/schemas/'.ucfirst($objectType).'.schema.json'; + $objArray['version'] = $objectArray['version']; + $objArray['type'] = $objectType; + unset($objectArray['title'], $objectArray['version'], $objectArray['id'], $objectArray['uuid']); + $objArray = array_merge($objArray, $objectArray); + // Convert the object data to JSON - $jsonData = json_encode($objectArray, JSON_PRETTY_PRINT); + $jsonData = json_encode($objArray, JSON_PRETTY_PRINT); $this->downloadJson($jsonData, $filename); } From e60b07644c5a897ba86f057e41d93f6d1280865b Mon Sep 17 00:00:00 2001 From: Wilco Louwerse Date: Thu, 14 Nov 2024 12:45:38 +0100 Subject: [PATCH 03/24] Fixes downloadService --- lib/Db/ObjectAuditLogMapper.php | 9 ++++++--- lib/Db/ObjectEntityMapper.php | 9 ++++++--- lib/Db/RegisterMapper.php | 10 ++++++---- lib/Db/Schema.php | 33 ++++++++++++++++++--------------- lib/Db/SchemaMapper.php | 8 +++++--- lib/Db/SourceMapper.php | 10 ++++++---- lib/Service/DownloadService.php | 3 --- 7 files changed, 47 insertions(+), 35 deletions(-) diff --git a/lib/Db/ObjectAuditLogMapper.php b/lib/Db/ObjectAuditLogMapper.php index 2b27355..f31fdaf 100644 --- a/lib/Db/ObjectAuditLogMapper.php +++ b/lib/Db/ObjectAuditLogMapper.php @@ -76,9 +76,12 @@ public function updateFromArray(int $id, array $object): ObjectAuditLog $obj->hydrate($object); // Set or update the version - $version = explode('.', $obj->getVersion()); - $version[2] = (int)$version[2] + 1; - $obj->setVersion(implode('.', $version)); + if (isset($object['version']) === false) { + $version = explode('.', $obj->getVersion()); + $version[2] = (int)$version[2] + 1; + $obj->setVersion(implode('.', $version)); + } + return $this->update($obj); } diff --git a/lib/Db/ObjectEntityMapper.php b/lib/Db/ObjectEntityMapper.php index a64af65..606aea9 100644 --- a/lib/Db/ObjectEntityMapper.php +++ b/lib/Db/ObjectEntityMapper.php @@ -219,9 +219,12 @@ public function updateFromArray(int $id, array $object): ObjectEntity $obj->hydrate($object); // Set or update the version - $version = explode('.', $obj->getVersion()); - $version[2] = (int)$version[2] + 1; - $obj->setVersion(implode('.', $version)); + if (isset($object['version']) === false) { + $version = explode('.', $obj->getVersion()); + $version[2] = (int)$version[2] + 1; + $obj->setVersion(implode('.', $version)); + } + return $this->update($obj); } diff --git a/lib/Db/RegisterMapper.php b/lib/Db/RegisterMapper.php index 9dcdf83..569d8f5 100644 --- a/lib/Db/RegisterMapper.php +++ b/lib/Db/RegisterMapper.php @@ -13,7 +13,7 @@ /** * The RegisterMapper class - * + * * @package OCA\OpenRegister\Db */ class RegisterMapper extends QBMapper @@ -128,9 +128,11 @@ public function updateFromArray(int $id, array $object): Register $obj->hydrate($object); // Update the version - $version = explode('.', $obj->getVersion()); - $version[2] = (int)$version[2] + 1; - $obj->setVersion(implode('.', $version)); + if (isset($object['version']) === false) { + $version = explode('.', $obj->getVersion()); + $version[2] = (int)$version[2] + 1; + $obj->setVersion(implode('.', $version)); + } // Update the register and return it return $this->update($obj); diff --git a/lib/Db/Schema.php b/lib/Db/Schema.php index 314ed55..565e72d 100644 --- a/lib/Db/Schema.php +++ b/lib/Db/Schema.php @@ -79,27 +79,36 @@ public function hydrate(array $object): self */ public function jsonSerialize(): array { + $required = $this->required ?? []; $properties = []; if (isset($this->properties) === true) { foreach ($this->properties as $key => $property) { - $properties[$key] = $property; + $title = $property['title'] ?? $key; + if ($property['required'] === true && in_array($title, $required) === false) { + $required[] = $title; + } + unset($property['required']); +// unset($property['title'], $property['required']); + + // Remove empty fields with array_filter(). + $properties[$title] = array_filter($property); + if (isset($property['type']) === false) { - $properties[$key] = $property; continue; } switch ($property['format']) { case 'string': // For now array as string case 'array': - $properties[$key]['default'] = (string) $property; + $properties[$title]['default'] = (string) $property; break; case 'int': case 'integer': case 'number': - $properties[$key]['default'] = (int) $property; + $properties[$title]['default'] = (int) $property; break; case 'bool': - $properties[$key]['default'] = (bool) $property; + $properties[$title]['default'] = (bool) $property; break; } } @@ -112,7 +121,7 @@ public function jsonSerialize(): array 'description' => $this->description, 'version' => $this->version, 'summary' => $this->summary, - 'required' => $this->required, + 'required' => $required, 'properties' => $properties, 'archive' => $this->archive, 'source' => $this->source, @@ -144,16 +153,11 @@ public function getSchemaObject(IURLGenerator $urlGenerator): object unset($data['properties'], $data['id'], $data['uuid'], $data['summary'], $data['archive'], $data['source'], $data['updated'], $data['created']); - $data['required'] = []; - $data['type'] = 'object'; - foreach ($properties as $property) { - $title = $property['title']; - if ($property['required'] === true) { - $data['required'][] = $title; - } - unset($property['title'], $property['required']); + foreach ($properties as $key => $property) { + $title = $property['title'] ?? $key; + unset($property['title']); // Remove empty fields with array_filter(). $data['properties'][$title] = array_filter($property); @@ -162,7 +166,6 @@ public function getSchemaObject(IURLGenerator $urlGenerator): object $data['$schema'] = 'https://json-schema.org/draft/2020-12/schema'; $data['$id'] = $urlGenerator->getAbsoluteURL($urlGenerator->linkToRoute('openregister.Schemas.show', ['id' => $this->getUuid()])); - return json_decode(json_encode($data)); } } diff --git a/lib/Db/SchemaMapper.php b/lib/Db/SchemaMapper.php index 2b83986..35b22c3 100644 --- a/lib/Db/SchemaMapper.php +++ b/lib/Db/SchemaMapper.php @@ -133,9 +133,11 @@ public function updateFromArray(int $id, array $object): Schema $obj->hydrate($object); // Set or update the version - $version = explode('.', $obj->getVersion()); - $version[2] = (int)$version[2] + 1; - $obj->setVersion(implode('.', $version)); + if (isset($object['version']) === false) { + $version = explode('.', $obj->getVersion()); + $version[2] = (int)$version[2] + 1; + $obj->setVersion(implode('.', $version)); + } return $this->update($obj); } diff --git a/lib/Db/SourceMapper.php b/lib/Db/SourceMapper.php index 3dbfac3..02d0175 100644 --- a/lib/Db/SourceMapper.php +++ b/lib/Db/SourceMapper.php @@ -11,7 +11,7 @@ /** * The SourceMapper class - * + * * @package OCA\OpenRegister\Db */ class SourceMapper extends QBMapper @@ -116,9 +116,11 @@ public function updateFromArray(int $id, array $object): Source $obj->hydrate($object); // Set or update the version - $version = explode('.', $obj->getVersion()); - $version[2] = (int)$version[2] + 1; - $obj->setVersion(implode('.', $version)); + if (isset($object['version']) === false) { + $version = explode('.', $obj->getVersion()); + $version[2] = (int)$version[2] + 1; + $obj->setVersion(implode('.', $version)); + } return $this->update($obj); } diff --git a/lib/Service/DownloadService.php b/lib/Service/DownloadService.php index 51e42dd..11a874a 100644 --- a/lib/Service/DownloadService.php +++ b/lib/Service/DownloadService.php @@ -44,11 +44,8 @@ public function download(string $objectType, string|int $id, string $accept) if (str_contains(haystack: $accept, needle: 'application/json') === true) { $url = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute('openregister.'.ucfirst($objectType).'s.show', ['id' => $object->getId()])); - // @todo: json+ld? str_contains($accept,'json+ld') === true, else: - // Json... $objArray['title'] = $objectArray['title']; $objArray['$id'] = $url; -// $objArray['$schema'] = 'https://json-schema.org/draft/2020-12/schema'; $objArray['$schema'] = 'https://docs.commongateway.nl/schemas/'.ucfirst($objectType).'.schema.json'; $objArray['version'] = $objectArray['version']; $objArray['type'] = $objectType; From 0afb9c9c63c0ec2d17af701ff481705cba496cc5 Mon Sep 17 00:00:00 2001 From: Wilco Louwerse Date: Thu, 14 Nov 2024 15:08:48 +0100 Subject: [PATCH 04/24] More fixes for DownloadService --- lib/Db/Schema.php | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/lib/Db/Schema.php b/lib/Db/Schema.php index 565e72d..2c151a3 100644 --- a/lib/Db/Schema.php +++ b/lib/Db/Schema.php @@ -87,8 +87,7 @@ public function jsonSerialize(): array if ($property['required'] === true && in_array($title, $required) === false) { $required[] = $title; } - unset($property['required']); -// unset($property['title'], $property['required']); + unset($property['title'], $property['required']); // Remove empty fields with array_filter(). $properties[$title] = array_filter($property); @@ -149,20 +148,12 @@ public function jsonSerialize(): array public function getSchemaObject(IURLGenerator $urlGenerator): object { $data = $this->jsonSerialize(); - $properties = $data['properties']; - unset($data['properties'], $data['id'], $data['uuid'], $data['summary'], $data['archive'], $data['source'], + unset($data['id'], $data['uuid'], $data['summary'], $data['archive'], $data['source'], $data['updated'], $data['created']); $data['type'] = 'object'; - foreach ($properties as $key => $property) { - $title = $property['title'] ?? $key; - unset($property['title']); - - // Remove empty fields with array_filter(). - $data['properties'][$title] = array_filter($property); - } - + // Validator needs this specific $schema $data['$schema'] = 'https://json-schema.org/draft/2020-12/schema'; $data['$id'] = $urlGenerator->getAbsoluteURL($urlGenerator->linkToRoute('openregister.Schemas.show', ['id' => $this->getUuid()])); From 2fded415ce4b87bb9d5733a10db7d9572259a2c9 Mon Sep 17 00:00:00 2001 From: Wilco Louwerse Date: Thu, 14 Nov 2024 15:56:20 +0100 Subject: [PATCH 05/24] style fixes --- lib/Service/ObjectService.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/Service/ObjectService.php b/lib/Service/ObjectService.php index 4db3f80..4545350 100755 --- a/lib/Service/ObjectService.php +++ b/lib/Service/ObjectService.php @@ -2,6 +2,7 @@ namespace OCA\OpenRegister\Service; +use InvalidArgumentException; use OC\URLGenerator; use OCA\OpenRegister\Db\Source; use OCA\OpenRegister\Db\SourceMapper; @@ -408,10 +409,10 @@ public function deleteObject(Register $register, Schema $schema, string $uuid): * @param int|null $register Optional register ID * @param int|null $schema Optional schema ID * @return mixed The appropriate mapper - * @throws \InvalidArgumentException If unknown object type + * @throws InvalidArgumentException If unknown object type */ - public function getMapper(?string $objectType = null, ?int $register = null, ?int $schema = null) - { + public function getMapper(?string $objectType = null, ?int $register = null, ?int $schema = null): mixed + { // Return self if register and schema provided if ($register !== null && $schema !== null) { $this->setSchema($schema); @@ -428,7 +429,7 @@ public function getMapper(?string $objectType = null, ?int $register = null, ?in case 'objectEntity': return $this->objectEntityMapper; default: - throw new \InvalidArgumentException("Unknown object type: $objectType"); + throw new InvalidArgumentException("Unknown object type: $objectType"); } } @@ -438,7 +439,7 @@ public function getMapper(?string $objectType = null, ?int $register = null, ?in * @param string $objectType The type of objects to retrieve * @param array $ids The ids of the objects to retrieve * @return array The retrieved objects - * @throws \InvalidArgumentException If unknown object type + * @throws InvalidArgumentException If unknown object type */ public function getMultipleObjects(string $objectType, array $ids) { From 131dbf9a60d4e13e9ed0e6665435d83b2886eafb Mon Sep 17 00:00:00 2001 From: Wilco Louwerse Date: Thu, 21 Nov 2024 14:00:13 +0100 Subject: [PATCH 06/24] Removed some old code that didn't do anything --- lib/Db/Schema.php | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/lib/Db/Schema.php b/lib/Db/Schema.php index 2c151a3..679050b 100644 --- a/lib/Db/Schema.php +++ b/lib/Db/Schema.php @@ -91,25 +91,6 @@ public function jsonSerialize(): array // Remove empty fields with array_filter(). $properties[$title] = array_filter($property); - - if (isset($property['type']) === false) { - continue; - } - switch ($property['format']) { - case 'string': - // For now array as string - case 'array': - $properties[$title]['default'] = (string) $property; - break; - case 'int': - case 'integer': - case 'number': - $properties[$title]['default'] = (int) $property; - break; - case 'bool': - $properties[$title]['default'] = (bool) $property; - break; - } } } From f9d6be7e2cc24aa59b0ee6ee38aa513f6559247b Mon Sep 17 00:00:00 2001 From: Wilco Louwerse Date: Mon, 25 Nov 2024 12:47:53 +0100 Subject: [PATCH 07/24] Show empty schema property config unless used for validation / download --- lib/Db/Schema.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Db/Schema.php b/lib/Db/Schema.php index 679050b..8128f52 100644 --- a/lib/Db/Schema.php +++ b/lib/Db/Schema.php @@ -89,8 +89,7 @@ public function jsonSerialize(): array } unset($property['title'], $property['required']); - // Remove empty fields with array_filter(). - $properties[$title] = array_filter($property); + $properties[$title] = $property; } } @@ -129,6 +128,12 @@ public function jsonSerialize(): array public function getSchemaObject(IURLGenerator $urlGenerator): object { $data = $this->jsonSerialize(); + + foreach ($data['properties'] as $key => $property) { + // Remove empty fields with array_filter(). + $data['properties'][$key] = array_filter($property); + } + unset($data['id'], $data['uuid'], $data['summary'], $data['archive'], $data['source'], $data['updated'], $data['created']); From 3c42542a9b2f1b75a921913e98236db40096fb7c Mon Sep 17 00:00:00 2001 From: Wilco Louwerse Date: Thu, 28 Nov 2024 14:38:59 +0100 Subject: [PATCH 08/24] Small rename for variable --- lib/Db/Schema.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Db/Schema.php b/lib/Db/Schema.php index 8128f52..571618c 100644 --- a/lib/Db/Schema.php +++ b/lib/Db/Schema.php @@ -82,8 +82,8 @@ public function jsonSerialize(): array $required = $this->required ?? []; $properties = []; if (isset($this->properties) === true) { - foreach ($this->properties as $key => $property) { - $title = $property['title'] ?? $key; + foreach ($this->properties as $title => $property) { + $title = $property['title'] ?? $title; if ($property['required'] === true && in_array($title, $required) === false) { $required[] = $title; } @@ -129,9 +129,9 @@ public function getSchemaObject(IURLGenerator $urlGenerator): object { $data = $this->jsonSerialize(); - foreach ($data['properties'] as $key => $property) { + foreach ($data['properties'] as $title => $property) { // Remove empty fields with array_filter(). - $data['properties'][$key] = array_filter($property); + $data['properties'][$title] = array_filter($property); } unset($data['id'], $data['uuid'], $data['summary'], $data['archive'], $data['source'], From 072763560d0326987219cef80ccfb15087cf76ac Mon Sep 17 00:00:00 2001 From: Ruben van der Linde Date: Sat, 7 Dec 2024 16:02:42 +0100 Subject: [PATCH 09/24] Object and file tabs --- src/views/object/ObjectDetails.vue | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/views/object/ObjectDetails.vue b/src/views/object/ObjectDetails.vue index c072b79..0a12b8a 100644 --- a/src/views/object/ObjectDetails.vue +++ b/src/views/object/ObjectDetails.vue @@ -56,6 +56,16 @@ import { objectStore, navigationStore } from '../../store/store.js' -->{{ JSON.stringify(objectStore.objectItem.object, null, 2) }} + +
+ {{ JSON.stringify(objectStore.objectItem.relations, null, 2) }} +
+
+ +
+ {{ JSON.stringify(objectStore.objectItem.files, null, 2) }} +
+
No synchronizations found From a99799d857d43ef009dd36dbdf34a3f388fcf931 Mon Sep 17 00:00:00 2001 From: Ruben van der Linde Date: Sat, 7 Dec 2024 17:01:00 +0100 Subject: [PATCH 10/24] First draft for ui logic --- src/modals/schema/EditSchemaProperty.vue | 93 +++++++++++++++++++----- 1 file changed, 76 insertions(+), 17 deletions(-) diff --git a/src/modals/schema/EditSchemaProperty.vue b/src/modals/schema/EditSchemaProperty.vue index 1773de8..c0d52d3 100644 --- a/src/modals/schema/EditSchemaProperty.vue +++ b/src/modals/schema/EditSchemaProperty.vue @@ -39,9 +39,48 @@ import { navigationStore, schemaStore } from '../../store/store.js' :disabled="properties.type !== 'string'" />
- + +
+ + + +
+ + +
+ + + + +
+ +
@@ -151,10 +190,6 @@ import { navigationStore, schemaStore } from '../../store/store.js' label="Default value" :value.sync="properties.default" /> - - @@ -167,16 +202,6 @@ import { navigationStore, schemaStore } from '../../store/store.js' Deprecated - - - - @@ -331,6 +356,16 @@ export default { $ref: '', type: '', }, + objectConfiguration: { + handling: 'nested-object', + schema: '' + }, + fileConfiguration: { + handling: 'ignore', + allowedMimeTypes: [], + location: '', + maxSize: 0 + } }, typeOptions: { inputLabel: 'Type*', @@ -347,6 +382,30 @@ export default { multiple: false, options: ['date', 'time', 'duration', 'date-time', 'url', 'uri', 'uuid', 'email', 'idn-email', 'hostname', 'idn-hostname', 'ipv4', 'ipv6', 'uri-reference', 'iri', 'iri-reference', 'uri-template', 'json-pointer', 'regex', 'binary', 'byte', 'password', 'rsin', 'kvk', 'bsn', 'oidn', 'telephone'], }, + objectConfiguration: { + handling: { + inputLabel: 'Object Configuration', + multiple: false, + options: ['nested-object', 'nested-schema', 'related-schema', 'uri'] + }, + }, + fileConfiguration: { + handling: { + inputLabel: 'File Configuration', + multiple: false, + options: ['ignore','transform'] + }, + }, + availableSchemas: { + inputLabel: 'Select Schema', + multiple: false, + options: ['schema1', 'schema2', 'schema3'] // This should be populated with actual schemas + }, + mimeTypes: { + inputLabel: 'Allowed MIME Types', + multiple: true, + options: ['image/jpeg', 'image/png', 'application/pdf', 'text/plain'] // Add more MIME types as needed + }, loading: false, success: null, error: false, From 7f3da5d0866f879733f4ba063179886f052fd2d7 Mon Sep 17 00:00:00 2001 From: Ruben van der Linde Date: Sat, 7 Dec 2024 17:11:45 +0100 Subject: [PATCH 11/24] First fixes --- src/modals/schema/EditSchemaProperty.vue | 30 ++++++++++++++++++------ 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/modals/schema/EditSchemaProperty.vue b/src/modals/schema/EditSchemaProperty.vue index c0d52d3..abad207 100644 --- a/src/modals/schema/EditSchemaProperty.vue +++ b/src/modals/schema/EditSchemaProperty.vue @@ -42,16 +42,22 @@ import { navigationStore, schemaStore } from '../../store/store.js'
+ v-bind="objectConfiguration.handling" + :value.sync="properties.objectConfiguration.handling" /> + v-bind="availableSchemas" + :value.sync="properties.objectConfiguration.schema" />
- - + Date: Sun, 8 Dec 2024 10:49:21 +0100 Subject: [PATCH 12/24] Save sub schema as the proper schema --- lib/Service/ObjectService.php | 4 +++- src/modals/schema/EditSchemaProperty.vue | 12 ++++++++---- src/views/schema/SchemaDetails.vue | 8 ++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/Service/ObjectService.php b/lib/Service/ObjectService.php index a6f13bf..f953f70 100755 --- a/lib/Service/ObjectService.php +++ b/lib/Service/ObjectService.php @@ -498,12 +498,14 @@ private function handleObjectRelations(ObjectEntity $objectEntity, array $object } } } + // Handle single object type else if ($property['type'] === 'object') { $subSchema = $schema; - if(is_int($property['$ref']) === true) { + // $ref is a int, id or uuid + if(is_int($property['$ref']) === true || is_numeric($property['$ref']) || preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i', $property['$ref'])) { $subSchema = $property['$ref']; } else if (filter_var(value: $property['$ref'], filter: FILTER_VALIDATE_URL) !== false) { $parsedUrl = parse_url($property['$ref']); diff --git a/src/modals/schema/EditSchemaProperty.vue b/src/modals/schema/EditSchemaProperty.vue index abad207..344fa24 100644 --- a/src/modals/schema/EditSchemaProperty.vue +++ b/src/modals/schema/EditSchemaProperty.vue @@ -42,20 +42,24 @@ import { navigationStore, schemaStore } from '../../store/store.js'
- +
@@ -68,7 +72,7 @@ import { navigationStore, schemaStore } from '../../store/store.js' :value.sync="properties.fileConfiguration.maxSize" />
-