Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development' into feature/GW-176…
Browse files Browse the repository at this point in the history
…0/logging-postgresql
  • Loading branch information
rjzondervan committed Nov 20, 2024
2 parents e745ffd + 0c38374 commit 7493bf9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
21 changes: 16 additions & 5 deletions api/src/Repository/ObjectEntityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,29 @@ public function getOrderParameters(Entity $Entity, string $prefix = '', int $lev
* Finds object entities on their id or a sourceId of a synchronization this ObjectEntity has.
*
* @param string $identifier
*
* @throws NonUniqueResultException
* @param string|null $gatewayId The gateway (/source) id to use when searching for Synchronizations.
* @param string|null $entityId The entity id to use when searching for Synchronizations.
*
* @return ObjectEntity The found object entity
* @throws NonUniqueResultException
*/
public function findByAnyId(string $identifier): ?ObjectEntity
public function findByAnyId(string $identifier, ?string $gatewayId = null, ?string $entityId = null): ?ObjectEntity
{
$query = $this->createQueryBuilder('o')
->leftJoin('o.synchronizations', 's')
->where('s.sourceId = :identifier')
->setParameter('identifier', $identifier);

if ($gatewayId !== null) {
$query->andWhere('s.gateway = :gatewayId')
->setParameter('gatewayId', $gatewayId);
}

if ($entityId !== null) {
$query->andWhere('s.entity = :entityId')
->setParameter('entityId', $entityId);
}

if (Uuid::isValid($identifier)) {
$query->orWhere('o.id = :identifier');
}
Expand Down Expand Up @@ -977,9 +988,9 @@ private function makeKeySqlFriendly(string $key): string

/**
* Finds all object entities with references.
*
*
* @param array $references The entity references
*
*
* @return mixed ObjectEntities
*/
public function findByReferences(array $references)
Expand Down
27 changes: 17 additions & 10 deletions api/src/Service/SynchronizationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Entity\Gateway as Source;
use App\Entity\ObjectEntity;
use App\Entity\Synchronization;
use App\Entity\Mapping;
use App\Entity\User;
use App\Event\ActionEvent;
use App\Exception\AsynchronousException;
Expand Down Expand Up @@ -992,20 +993,25 @@ public function doesShaMatch(Synchronization $synchronization, string $sha): boo
* @param Synchronization $synchronization The synchronization to update
* @param array $sourceObject The object in the source
* @param bool $unsafe Unset attributes that are not included in the hydrator array when calling the hydrate function
* @param Mapping $mapping Pass a optional mapping to add to the synchronization.
*
* @throws GuzzleException
* @throws LoaderError
* @throws SyntaxError
*
* @return Synchronization The updated synchronization
*/
public function synchronize(Synchronization $synchronization, array $sourceObject = [], bool $unsafe = false): Synchronization
public function synchronize(Synchronization $synchronization, array $sourceObject = [], bool $unsafe = false, ?Mapping $mapping = null): Synchronization
{
if (isset($this->io)) {
$this->io->text("handleSync for Synchronization with id = {$synchronization->getId()->toString()}");
}
$this->logger->info("handleSync for Synchronization with id = {$synchronization->getId()->toString()}");

if ($mapping !== null) {
$synchronization->setMapping($mapping);
}

//create new object if no object exists
if (!$synchronization->getObject()) {
isset($this->io) && $this->io->text('creating new objectEntity');
Expand Down Expand Up @@ -1517,24 +1523,25 @@ private function syncThroughComparing(Synchronization $synchronization): Synchro
/**
* Find an object by URL, and synchronize it if it does not exist in the gateway.
*
* @param string $url The URL of the object
* @param Entity $entity The schema the object should fit into
* @param string $url The URL of the object.
* @param Entity $entity The schema the object should fit into.
* @param Mapping $mappping The mapping the object will be changed to.
*
* @throws GuzzleException|LoaderError|SyntaxError|UrlException
*
* @return ObjectEntity|null
*/
public function aquireObject(string $url, Entity $entity): ?ObjectEntity
public function aquireObject(string $url, Entity $entity, ?Mapping $mapping = null): ?ObjectEntity
{
$source = $this->resourceService->findSourceForUrl($url, 'conduction-nl/commonground-gateway', $endpoint);
$sourceId = $this->getSourceId($endpoint, $url);
$source = $this->resourceService->findSourceForUrl(url: $url, pluginName: 'conduction-nl/commonground-gateway', endpoint: $endpoint);
$sourceId = $this->getSourceId(endpoint: $endpoint, url: $url);

$synchronization = $this->findSyncBySource($source, $entity, $sourceId, $endpoint);
$synchronization = $this->findSyncBySource(source: $source, entity: $entity, sourceId: $sourceId, endpoint: $endpoint);

$this->synchronize($synchronization);
$this->synchronize(synchronization: $synchronization, sourceObject: [], unsafe: false, mapping: $mapping);

return $synchronization->getObject();
}
}//end aquireObject()

/**
* A function best used after resourceService->findSourceForUrl and/or before $this->findSyncBySource.
Expand All @@ -1560,5 +1567,5 @@ public function getSourceId(?string &$endpoint, ?string $url = null): ?string
}

return $sourceId;
}
}//end getSourceId
}

0 comments on commit 7493bf9

Please sign in to comment.