Skip to content
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ An example repository for creating php symfony flex bundles


### Using this bundle

#### Installing with common-gateway admin user-interface
@todo!

Expand Down
5 changes: 1 addition & 4 deletions Schema/template-group.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@
"templates": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Template"
"$ref": "https://common-gateway.nl/template.schema.json"
}
},
"application": {
"type": "string"
},
"organization": {
"type": "string"
},
"": {
"type": "string"
}
},
"required": [
Expand Down
2 changes: 1 addition & 1 deletion Schema/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"templateGroups": {
"type": "array",
"items": {
"$ref": "#/components/schemas/TemplateGroup"
"$ref": "https://common-gateway.nl/template-group.schema.json"
}
}
},
Expand Down
92 changes: 34 additions & 58 deletions Service/InstallationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Entity\Endpoint;
use CommonGateway\CoreBundle\Installer\InstallerInterface;
use Doctrine\ORM\EntityManagerInterface;
use PhpParser\Parser\Multiple;
use Symfony\Component\Console\Style\SymfonyStyle;

class InstallationService implements InstallerInterface
Expand Down Expand Up @@ -51,66 +52,41 @@ public function checkDataConsistency()
{

// Lets create some genneric dashboard cards
// $objectsThatShouldHaveCards = ['https://common-gateway.nl/template-group.schema.json', 'https://common-gateway.nl/template.schema.json'];

// foreach ($objectsThatShouldHaveCards as $object) {
// (isset($this->io) ? $this->io->writeln('Looking for a dashboard card for: ' . $object) : '');
// $entity = $this->entityManager->getRepository('App:Entity')->findOneBy(['reference' => $object]);
// if (
// $entity &&
// !$dashboardCard = $this->entityManager->getRepository('App:DashboardCard')->findOneBy(['entityId' => $entity->getId()])
// ) {
// $dashboardCard = new DashboardCard($entity);
// $this->entityManager->persist($dashboardCard);
// (isset($this->io) ? $this->io->writeln('Dashboard card created') : '');
// continue;
// }
// (isset($this->io) ? $this->io->writeln('Dashboard card found') : '');
// }
$objectsThatShouldHaveCards = ['https://common-gateway.nl/template-group.schema.json', 'https://common-gateway.nl/template.schema.json'];

foreach ($objectsThatShouldHaveCards as $object) {
(isset($this->io) ? $this->io->writeln('Looking for a dashboard card for: ' . $object) : '');
$entity = $this->entityManager->getRepository('App:Entity')->findOneBy(['reference' => $object]);
if (
$entity &&
!$dashboardCard = $this->entityManager->getRepository('App:DashboardCard')->findOneBy(['entityId' => $entity->getId()])
) {
$dashboardCard = new DashboardCard($entity);
$this->entityManager->persist($dashboardCard);
(isset($this->io) ? $this->io->writeln('Dashboard card created') : '');
continue;
}
(isset($this->io) ? $this->io->writeln('Dashboard card found') : '');
}

// Let create some endpoints
// $objectsThatShouldHaveEndpoints = ['https://common-gateway.nl/template-group.schema.json', 'https://common-gateway.nl/template.schema.json'];

// foreach ($objectsThatShouldHaveEndpoints as $object) {
// (isset($this->io) ? $this->io->writeln('Looking for a endpoint for: ' . $object) : '');
// $entity = $this->entityManager->getRepository('App:Entity')->findOneBy(['reference' => $object]);

// if (
// $entity &&
// count($entity->getEndpoints()) == 0
// ) {
// $endpoint = new Endpoint($entity);
// $this->entityManager->persist($endpoint);
// (isset($this->io) ? $this->io->writeln('Endpoint created') : '');
// continue;
// }
// (isset($this->io) ? $this->io->writeln('Endpoint found') : '');
// }

$schemaRepository = $this->entityManager->getRepository('App:Entity');
$endpointRepository = $this->entityManager->getRepository('App:Endpoint');
$templateGroup = $schemaRepository->findOneBy(['name' => 'TemplateGroup']);

$endpoint = $endpointRepository->findOneBy(['name' => 'TemplateGroups collection']) ?? new Endpoint();
$endpoint->setName('TemplateGroups collection');
$endpoint->setPathRegex('^(template_groups)$');
$endpoint->setPath(['template_groups']);
$endpoint->setMethods(["POST", "GET"]);
$endpoint->setMethod("GET");
$endpoint->setEntity($templateGroup);
$endpoint->setOperationType('collection');
$this->entityManager->persist($endpoint);

$endpoint = $endpointRepository->findOneBy(['name' => 'TemplateGroups item']) ?? new Endpoint();
$endpoint->setName('TemplateGroups item');
$endpoint->setPathRegex('^(template_groups/[a-z0-9-]{36})$');
$endpoint->setPath(['template_groups', '[a-z0-9-]{36}']);
$endpoint->setMethods(["PUT", "GET"]);
$endpoint->setMethod("PUT");
$endpoint->setEntity($templateGroup);
$endpoint->setOperationType('item');
$this->entityManager->persist($endpoint);

$objectsThatShouldHaveEndpoints = [['ref' => 'https://common-gateway.nl/template-group.schema.json', 'path' => 'template_groups'], ['ref' => 'https://common-gateway.nl/template.schema.json', 'path' => 'templates']];

foreach ($objectsThatShouldHaveEndpoints as $object) {
(isset($this->io) ? $this->io->writeln('Looking for a endpoint for: ' . $object['ref']) : '');
$entity = $this->entityManager->getRepository('App:Entity')->findOneBy(['reference' => $object['ref']]);

if (
$entity &&
count($entity->getEndpoints()) == 0
) {
$endpoint = new Endpoint($entity, $object['path']);
$this->entityManager->persist($endpoint);
(isset($this->io) ? $this->io->writeln('Endpoint created') : '');
continue;
}
(isset($this->io) ? $this->io->writeln('Endpoint found') : '');
}

$this->entityManager->flush();

Expand Down