From cdbb6fd6bb1561ff58678ae98522bc553088f6d5 Mon Sep 17 00:00:00 2001 From: Sarai Misidjan Date: Fri, 8 Sep 2023 15:51:21 +0200 Subject: [PATCH 1/4] Added from en toSchema for a Template --- api/migrations/Version20230907115512.php | 43 +++++++++ api/src/Entity/Template.php | 113 ++++++++++++++++++++++- 2 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 api/migrations/Version20230907115512.php diff --git a/api/migrations/Version20230907115512.php b/api/migrations/Version20230907115512.php new file mode 100644 index 000000000..f3d300bb3 --- /dev/null +++ b/api/migrations/Version20230907115512.php @@ -0,0 +1,43 @@ +addSql('ALTER TABLE template ADD reference VARCHAR(255) DEFAULT NULL'); + $this->addSql('ALTER TABLE template ADD version VARCHAR(255) DEFAULT NULL'); + $this->addSql('ALTER TABLE template ALTER id TYPE UUID'); + $this->addSql('ALTER TABLE template ALTER id DROP DEFAULT'); + $this->addSql('ALTER TABLE template ALTER organization_id TYPE UUID'); + $this->addSql('ALTER TABLE template ALTER organization_id DROP DEFAULT'); + $this->addSql('ALTER TABLE template ALTER organization_id DROP NOT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE template DROP reference'); + $this->addSql('ALTER TABLE template DROP version'); + $this->addSql('ALTER TABLE template ALTER id TYPE UUID'); + $this->addSql('ALTER TABLE template ALTER id DROP DEFAULT'); + $this->addSql('ALTER TABLE template ALTER organization_id TYPE UUID'); + $this->addSql('ALTER TABLE template ALTER organization_id DROP DEFAULT'); + $this->addSql('ALTER TABLE template ALTER organization_id SET NOT NULL'); + } +} diff --git a/api/src/Entity/Template.php b/api/src/Entity/Template.php index 470316928..77c156245 100644 --- a/api/src/Entity/Template.php +++ b/api/src/Entity/Template.php @@ -111,7 +111,7 @@ class Template * * @ORM\ManyToOne(targetEntity=Organization::class, inversedBy="templates") * - * @ORM\JoinColumn(nullable=false) + * @ORM\JoinColumn(nullable=true) */ private ?Organization $organization = null; @@ -122,7 +122,21 @@ class Template * * @ORM\Column(type="array") */ - private $supportedSchemas = []; + private array $supportedSchemas = []; + + /** + * @Groups({"read", "write"}) + * + * @ORM\Column(type="string", length=255, nullable=true) + */ + private ?string $reference = null; + + /** + * @Groups({"read", "write"}) + * + * @ORM\Column(type="string", length=255, nullable=true) + */ + private ?string $version = null; /** * @var Datetime|null The moment this resource was created @@ -146,6 +160,77 @@ class Template */ private ?DateTime $dateModified = null; + + /** + * Constructor for creating an Template. + * + * @param array|null $configuration A configuration array used to correctly create a Template. The following keys are supported: + * + */ + public function __construct(?array $configuration = []) + { + if ($configuration) { + $this->fromSchema($configuration); + } + } + + /** + * Uses given $configuration array to set the properties of this Template. + * + * @param array $schema The schema to load. + * + * @return void + */ + public function fromSchema(array $schema) + { + if (key_exists('$id', $schema) === true) { + $this->setReference($schema['$id']); + } + if (key_exists('version', $schema) === true) { + $this->setVersion($schema['version']); + } + + if (key_exists('name', $schema) === true) { + $this->setName($schema['name']); + } + + if (key_exists('description', $schema) === true) { + $this->setDescription($schema['description']); + } + + if (key_exists('content', $schema) === true) { + $this->setContent($schema['content']); + } + + if (key_exists('organization', $schema) === true) { + $this->setOrganization($schema['organization']); + } + + // @TODO set the supported schemas from the given reference. + if (key_exists('supportedSchemas', $schema) === true) { + $this->setSupportedSchemas($schema['supportedSchemas']); + } + } + + /** + * Convert this Template to a schema. + * + * @return array Schema array. + */ + public function toSchema(): array + { + return [ + '$id' => $this->getReference(), //@todo dit zou een interne uri verwijzing moeten zijn maar hebben we nog niet + '$schema' => 'https://docs.commongateway.nl/schemas/Template.schema.json', + 'name' => $this->getName(), + 'description' => $this->getDescription(), + 'content' => $this->getContent(), + 'version' => $this->getVersion(), + 'organization' => $this->getOrganization(), + 'supportedSchemas' => $this->getSupportedSchemas(), + ]; + } + public function setId(UuidInterface $id): self { $this->id = $id; @@ -218,6 +303,30 @@ public function setSupportedSchemas(array $supportedSchemas): self return $this; } + public function getReference(): ?string + { + return $this->reference; + } + + public function setReference(?string $reference): self + { + $this->reference = $reference; + + return $this; + } + + public function getVersion(): ?string + { + return $this->version; + } + + public function setVersion(?string $version): self + { + $this->version = $version; + + return $this; + } + public function getDateCreated(): ?\DateTimeInterface { return $this->dateCreated; From 09b0f7b43ecf2223cc89d73806c9a14c22ae1892 Mon Sep 17 00:00:00 2001 From: Sarai Misidjan Date: Tue, 12 Sep 2023 15:29:11 +0200 Subject: [PATCH 2/4] fix template entity --- api/migrations/Version20230907115512.php | 2 -- api/src/Entity/Template.php | 13 ------------- 2 files changed, 15 deletions(-) diff --git a/api/migrations/Version20230907115512.php b/api/migrations/Version20230907115512.php index f3d300bb3..dc0f40e07 100644 --- a/api/migrations/Version20230907115512.php +++ b/api/migrations/Version20230907115512.php @@ -20,7 +20,6 @@ public function getDescription(): string public function up(Schema $schema): void { // this up() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE template ADD reference VARCHAR(255) DEFAULT NULL'); $this->addSql('ALTER TABLE template ADD version VARCHAR(255) DEFAULT NULL'); $this->addSql('ALTER TABLE template ALTER id TYPE UUID'); $this->addSql('ALTER TABLE template ALTER id DROP DEFAULT'); @@ -32,7 +31,6 @@ public function up(Schema $schema): void public function down(Schema $schema): void { // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE template DROP reference'); $this->addSql('ALTER TABLE template DROP version'); $this->addSql('ALTER TABLE template ALTER id TYPE UUID'); $this->addSql('ALTER TABLE template ALTER id DROP DEFAULT'); diff --git a/api/src/Entity/Template.php b/api/src/Entity/Template.php index 07a3a759b..a400d7a1a 100644 --- a/api/src/Entity/Template.php +++ b/api/src/Entity/Template.php @@ -206,7 +206,6 @@ public function fromSchema(array $schema) $this->setOrganization($schema['organization']); } - // @TODO set the supported schemas from the given reference. if (key_exists('supportedSchemas', $schema) === true) { $this->setSupportedSchemas($schema['supportedSchemas']); } @@ -350,16 +349,4 @@ public function setDateModified(?\DateTimeInterface $dateModified): self return $this; } - - public function getReference(): ?string - { - return $this->reference; - } - - public function setReference(?string $reference): self - { - $this->reference = $reference; - - return $this; - } } From 54ecb4b65372971a44a3b31059e4d6e28ea2fae2 Mon Sep 17 00:00:00 2001 From: Sarai Misidjan Date: Wed, 13 Sep 2023 10:31:15 +0200 Subject: [PATCH 3/4] BEL-10 added text/docx to getAcceptType --- api/src/Controller/ZZController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/src/Controller/ZZController.php b/api/src/Controller/ZZController.php index e011301c3..a39f51227 100644 --- a/api/src/Controller/ZZController.php +++ b/api/src/Controller/ZZController.php @@ -161,6 +161,8 @@ private function getAcceptType(Request $request): string return 'xml'; case 'text/html': return 'html'; + case 'text/docx': + return 'docx'; }//end switch throw new BadRequestHttpException('No proper accept could be determined'); From 10bcf68955c34d52fe7ab4bff6e9d7a2f9f1643c Mon Sep 17 00:00:00 2001 From: Sarai Misidjan Date: Wed, 13 Sep 2023 11:40:48 +0200 Subject: [PATCH 4/4] deleted unnecessary sql queries --- api/migrations/Version20230907115512.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/api/migrations/Version20230907115512.php b/api/migrations/Version20230907115512.php index dc0f40e07..5735ba4dd 100644 --- a/api/migrations/Version20230907115512.php +++ b/api/migrations/Version20230907115512.php @@ -21,10 +21,6 @@ public function up(Schema $schema): void { // this up() migration is auto-generated, please modify it to your needs $this->addSql('ALTER TABLE template ADD version VARCHAR(255) DEFAULT NULL'); - $this->addSql('ALTER TABLE template ALTER id TYPE UUID'); - $this->addSql('ALTER TABLE template ALTER id DROP DEFAULT'); - $this->addSql('ALTER TABLE template ALTER organization_id TYPE UUID'); - $this->addSql('ALTER TABLE template ALTER organization_id DROP DEFAULT'); $this->addSql('ALTER TABLE template ALTER organization_id DROP NOT NULL'); } @@ -32,10 +28,6 @@ public function down(Schema $schema): void { // this down() migration is auto-generated, please modify it to your needs $this->addSql('ALTER TABLE template DROP version'); - $this->addSql('ALTER TABLE template ALTER id TYPE UUID'); - $this->addSql('ALTER TABLE template ALTER id DROP DEFAULT'); - $this->addSql('ALTER TABLE template ALTER organization_id TYPE UUID'); - $this->addSql('ALTER TABLE template ALTER organization_id DROP DEFAULT'); $this->addSql('ALTER TABLE template ALTER organization_id SET NOT NULL'); } }