diff --git a/api/migrations/Version20240311121033.php b/api/migrations/Version20240311121033.php new file mode 100644 index 000000000..54cc33f36 --- /dev/null +++ b/api/migrations/Version20240311121033.php @@ -0,0 +1,31 @@ +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'); + } +} diff --git a/api/migrations/Version20240311132843.php b/api/migrations/Version20240311132843.php new file mode 100644 index 000000000..39b2bfc04 --- /dev/null +++ b/api/migrations/Version20240311132843.php @@ -0,0 +1,36 @@ +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'); + } +} diff --git a/api/src/Entity/Endpoint.php b/api/src/Entity/Endpoint.php index 1eb7c2772..cf8ee5e4b 100644 --- a/api/src/Entity/Endpoint.php +++ b/api/src/Entity/Endpoint.php @@ -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. @@ -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; @@ -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; + } } diff --git a/api/src/Entity/Gateway.php b/api/src/Entity/Gateway.php index e3251a52c..25a0221b1 100644 --- a/api/src/Entity/Gateway.php +++ b/api/src/Entity/Gateway.php @@ -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. * @@ -781,6 +790,7 @@ public function __construct(?array $configuration = []) if ($configuration) { $this->fromSchema($configuration); } + $this->federationEndpoints = new ArrayCollection(); } /** @@ -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; + } }