Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes for federative requests #1623

Merged
merged 3 commits into from
Mar 14, 2024
Merged
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
31 changes: 31 additions & 0 deletions api/migrations/Version20240311121033.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240311121033 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER INDEX idx_8d93d6499e6b1585 RENAME TO IDX_8D93D64932C8A3DE');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER INDEX idx_8d93d64932c8a3de RENAME TO idx_8d93d6499e6b1585');
}
}
36 changes: 36 additions & 0 deletions api/migrations/Version20240311132843.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240311132843 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE endpoint_gateway (endpoint_id UUID NOT NULL, gateway_id UUID NOT NULL, PRIMARY KEY(endpoint_id, gateway_id))');
$this->addSql('CREATE INDEX IDX_39C1245121AF7E36 ON endpoint_gateway (endpoint_id)');
$this->addSql('CREATE INDEX IDX_39C12451577F8E00 ON endpoint_gateway (gateway_id)');
$this->addSql('ALTER TABLE endpoint_gateway ADD CONSTRAINT FK_39C1245121AF7E36 FOREIGN KEY (endpoint_id) REFERENCES endpoint (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE endpoint_gateway ADD CONSTRAINT FK_39C12451577F8E00 FOREIGN KEY (gateway_id) REFERENCES gateway (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');

}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE endpoint_gateway');
}
}
34 changes: 34 additions & 0 deletions api/src/Entity/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,15 @@ class Endpoint
*/
private string $version = '0.0.0';

/**
* @var Collection The proxies that can be used for federated calls.
*
* @MaxDepth(1)
* @Groups({"read", "write"})
* @ORM\ManyToMany(targetEntity=Gateway::class, inversedBy="federationEndpoints")
*/
private Collection $federationProxies;

/**
* Constructor for creating an Endpoint. Use $entity to create an Endpoint for an Entity or
* use $source to create an Endpoint for a source, a proxy Endpoint.
Expand All @@ -357,6 +366,7 @@ public function __construct(?Entity $entity = null, ?Source $source = null, ?arr
$this->collections = new ArrayCollection();
$this->properties = new ArrayCollection();
$this->entities = new ArrayCollection();
$this->federationProxies = new ArrayCollection();

if (!$entity && !$source && isset($configuration['entities']) === false) {
return;
Expand Down Expand Up @@ -962,4 +972,28 @@ public function setVersion(?string $version): self

return $this;
}

/**
* @return Collection|Gateway[]
*/
public function getFederationProxies(): Collection
{
return $this->federationProxies;
}

public function addFederationProxy(Gateway $federationProxy): self
{
if (!$this->federationProxies->contains($federationProxy)) {
$this->federationProxies[] = $federationProxy;
}

return $this;
}

public function removeFederationProxy(Gateway $federationProxy): self
{
$this->federationProxies->removeElement($federationProxy);

return $this;
}
}
37 changes: 37 additions & 0 deletions api/src/Entity/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,15 @@ class Gateway
*/
private $proxies;

/**
* @var Collection The endpoints for which this endpoint is a federated proxy.
*
* @MaxDepth(1)
* @Groups({"read", "write"})
* @ORM\ManyToMany(targetEntity=Endpoint::class, mappedBy="federationProxies")
*/
private Collection $federationEndpoints;

/**
* Constructor for Gateway.
*
Expand All @@ -781,6 +790,7 @@ public function __construct(?array $configuration = [])
if ($configuration) {
$this->fromSchema($configuration);
}
$this->federationEndpoints = new ArrayCollection();
}

/**
Expand Down Expand Up @@ -1411,4 +1421,31 @@ public function removeProxy(Endpoint $proxy): self

return $this;
}

/**
* @return Collection|Endpoint[]
*/
public function getFederationEndpoints(): Collection
{
return $this->federationEndpoints;
}

public function addFederationEndpoint(Endpoint $federationEndpoint): self
{
if (!$this->federationEndpoints->contains($federationEndpoint)) {
$this->federationEndpoints[] = $federationEndpoint;
$federationEndpoint->addFederationProxy($this);
}

return $this;
}

public function removeFederationEndpoint(Endpoint $federationEndpoint): self
{
if ($this->federationEndpoints->removeElement($federationEndpoint)) {
$federationEndpoint->removeFederationProxy($this);
}

return $this;
}
}
Loading