Skip to content

Commit

Permalink
Merge pull request #1666 from ConductionNL/feature/KTB-3/map-object-s…
Browse files Browse the repository at this point in the history
…ynchronize

Pass mapping for synchronization added
  • Loading branch information
bbrands02 authored Oct 7, 2024
2 parents 9dbbbeb + 8160546 commit 0c38374
Showing 1 changed file with 17 additions and 10 deletions.
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 0c38374

Please sign in to comment.