From 4014fbadcc8ef9baba944ffaa40f5daa7dd9e47e Mon Sep 17 00:00:00 2001 From: Sarai Misidjan Date: Thu, 9 Nov 2023 15:22:03 +0100 Subject: [PATCH] updated githubEventService --- .../EnrichPubliccodeFromGithubUrlService.php | 75 +-------- src/Service/GetResourcesService.php | 4 +- src/Service/GithubApiService.php | 144 ++++++++++++++---- src/Service/GithubEventService.php | 128 ++++------------ src/Service/GithubPubliccodeService.php | 53 ++++++- src/Service/ImportResourcesService.php | 38 ++++- 6 files changed, 240 insertions(+), 202 deletions(-) diff --git a/src/Service/EnrichPubliccodeFromGithubUrlService.php b/src/Service/EnrichPubliccodeFromGithubUrlService.php index a2794b7c..c9b555dd 100644 --- a/src/Service/EnrichPubliccodeFromGithubUrlService.php +++ b/src/Service/EnrichPubliccodeFromGithubUrlService.php @@ -102,35 +102,6 @@ public function setConfiguration(array $configuration): void }//end setConfiguration() - /** - * This function gets the publiccode file from the github user content. - * - * @param string $repositoryUrl The url of the repository - * - * @throws GuzzleException - * - * @return array|null - */ - public function getPubliccodeFromRawUserContent(string $repositoryUrl): ?array - { - $source = $this->resourceService->getSource($this->configuration['usercontentSource'], 'open-catalogi/open-catalogi-bundle'); - if ($source === null) { - return $this->data; - } - - // Get the path from the url to make the call. - $endpoint = \Safe\parse_url($repositoryUrl)['path']; - try { - $response = $this->callService->call($source, $endpoint); - } catch (Exception $e) { - $this->pluginLogger->error('Error found trying to fetch '.$repositoryUrl.' '.$e->getMessage()); - } - - return $this->callService->decodeResponse($source, $response, 'text/yaml'); - - }//end getPubliccodeFromRawUserContent() - - /** * This function gets and maps the publiccode file * @@ -148,50 +119,10 @@ public function enrichRepositoryWithPubliccode(ObjectEntity $repository, string if ($this->githubApiService->checkGithubAuth($source) === false) { return null; }//end if + + $repositories = $this->githubApiService->getPubliccodesFromRepo($repositoryUrl, $source); - $url = trim(\Safe\parse_url($repositoryUrl, PHP_URL_PATH), '/'); - - // Call the search/code endpoint for publiccode files in this repository. - $queryConfig['query'] = ['q' => "filename:publiccode extension:yaml extension:yml repo:{$url}"]; - - // Find the publiccode.yaml file(s). - try { - $response = $this->callService->call($source, '/search/code', 'GET', $queryConfig); - } catch (Exception $exception) { - $this->pluginLogger->error('Error found trying to fetch '.$source->getLocation().'/search/code'.' '.$exception->getMessage()); - } - - if (isset($response) === false) { - return null; - } - - $repositories = $this->callService->decodeResponse($source, $response); - - $this->pluginLogger->debug('Found '.count($repositories).' publiccode file(s).', ['plugin' => 'open-catalogi/open-catalogi-bundle']); - - $publiccodeUrls = []; - foreach ($repositories['items'] as $githubRepository) { - // Get the ref query from the url. This way we can get the publiccode file with the raw.gitgubusercontent - $publiccodeUrlQuery = \Safe\parse_url($githubRepository['url'])['query']; - $urlReference = explode('ref=', $publiccodeUrlQuery)[1]; - - $publiccodeUrls[] = $publiccodeUrl = "https://raw.githubusercontent.com/{$githubRepository['repository']['full_name']}/{$urlReference}/{$githubRepository['path']}"; - - // Get the publiccode through the raw.githubusercontent source - $publiccode = $this->getPubliccodeFromRawUserContent($publiccodeUrl); - - $this->pluginLogger->notice('Got publiccode from GitHub', $publiccode); - - if ($publiccode !== null) { - $repository = $this->githubService->mapPubliccode($repository, $publiccode, $this->configuration, $publiccodeUrl); - } - } - - $repository->setValue('publiccode_urls', $publiccodeUrls); - $this->entityManager->persist($repository); - $this->entityManager->flush(); - - return $repository; + return $this->githubService->mappPubliccodesFromRepo($repositories, $repository); }//end enrichRepositoryWithPubliccode() diff --git a/src/Service/GetResourcesService.php b/src/Service/GetResourcesService.php index d7645bb6..e5f973f8 100644 --- a/src/Service/GetResourcesService.php +++ b/src/Service/GetResourcesService.php @@ -94,7 +94,7 @@ public function getComponents(Source $source, string $endpoint, array $configura $result = []; foreach ($components as $component) { - $result[] = $this->importResourceService->importComponent($component, $configuration); + $result[] = $this->importResourceService->importCatalogusComponent($component, $configuration); } $this->entityManager->flush(); @@ -125,7 +125,7 @@ public function getComponent(Source $source, string $endpoint, string $component return null; } - $component = $this->importResourceService->importComponent($component, $configuration); + $component = $this->importResourceService->importCatalogusComponent($component, $configuration); if ($component === null) { return null; } diff --git a/src/Service/GithubApiService.php b/src/Service/GithubApiService.php index 85582979..661f04e0 100644 --- a/src/Service/GithubApiService.php +++ b/src/Service/GithubApiService.php @@ -38,6 +38,7 @@ class GithubApiService */ private MappingService $mappingService; + /** * @var array */ @@ -107,6 +108,34 @@ public function checkGithubAuth(Source $source): ?bool }//end checkGithubAuth() + /** + * This function gets the publiccode file from the github user content. + * + * @param string $repositoryUrl The url of the repository + * + * @throws GuzzleException + * + * @return array|null + */ + public function getPubliccodeFromRawUserContent(string $repositoryUrl): ?array + { + $source = $this->resourceService->getSource('https://opencatalogi.nl/source/oc.GitHubusercontent.source.json', 'open-catalogi/open-catalogi-bundle'); + if ($source === null) { + return $this->data; + } + + // Get the path from the url to make the call. + $endpoint = \Safe\parse_url($repositoryUrl)['path']; + try { + $response = $this->callService->call($source, $endpoint); + } catch (Exception $e) { + $this->pluginLogger->error('Error found trying to fetch '.$repositoryUrl.' '.$e->getMessage()); + } + + return $this->callService->decodeResponse($source, $response, 'text/yaml'); + + }//end getPubliccodeFromRawUserContent() + /** * Get a repository through the repositories of the given source @@ -142,44 +171,107 @@ public function getRepository(string $name, Source $source): ?array }//end getRepository() + /** + * Get a repository through the repositories of the given source + * + * @param string $repositoryUrl The url of the repository. + * @param Source $source The source to sync from. + * + * @return array|null The imported repository as array. + */ + public function getPubliccodesFromRepo(string $repositoryUrl, Source $source): ?array + { + $url = trim(\Safe\parse_url($repositoryUrl, PHP_URL_PATH), '/'); + + // Call the search/code endpoint for publiccode files in this repository. + $queryConfig['query'] = ['q' => "filename:publiccode extension:yaml extension:yml repo:{$url}"]; + + // Find the publiccode.yaml file(s). + try { + $response = $this->callService->call($source, '/search/code', 'GET', $queryConfig); + } catch (Exception $exception) { + $this->pluginLogger->error('Error found trying to fetch '.$source->getLocation().'/search/code'.' '.$exception->getMessage()); + } + + if (isset($response) === false) { + return null; + } + + $repositories = $this->callService->decodeResponse($source, $response); + + $this->pluginLogger->debug('Found '.count($repositories).' publiccode file(s).', ['plugin' => 'open-catalogi/open-catalogi-bundle']); + + return $repositories; + + }//end getRepository() /** - * This function create or get the component of the repository. + * Get a repository through the repositories of the given source * - * @param ObjectEntity $repository The repository object. - * @param string|null $publiccodeUrl The publiccode url. + * @param string $name The name of the repository. + * @param Source $source The source to sync from. * - * @return ObjectEntity|null + * @return array|null The imported repository as array. */ - public function connectComponent(ObjectEntity $repository, ?string $publiccodeUrl=null): ?ObjectEntity + public function getOrganisation(string $name, Source $source): ?array { - $componentEntity = $this->resourceService->getSchema('https://opencatalogi.nl/oc.component.schema.json', 'open-catalogi/open-catalogi-bundle'); - $cacheComponents = $this->cacheService->searchObjects(null, ['url' => $repository->getSelf()], [$componentEntity->getId()->toString()])['results']; - - if ($cacheComponents === []) { - $component = new ObjectEntity($componentEntity); - $component->hydrate( - [ - 'name' => $repository->getValue('name'), - 'url' => $repository, - 'publiccodeUrl' => $publiccodeUrl, - ] - ); - $this->entityManager->persist($component); - $this->entityManager->flush(); - }//end if + $this->pluginLogger->debug('Getting repository '.$name.'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); - if (count($cacheComponents) === 1) { - $component = $this->entityManager->find('App:ObjectEntity', $cacheComponents[0]['_self']['id']); + try { + $response = $this->callService->call($source, '/repos/'.$name); + } catch (ClientException $exception) { + $this->pluginLogger->error($exception->getMessage(), ['plugin' => 'open-catalogi/open-catalogi-bundle']); + } + + if (isset($response) === false) { + return null; + } + + $repository = \Safe\json_decode($response->getBody()->getContents(), true); + + if ($repository === null) { + $this->pluginLogger->error('Could not find a repository with name: '.$name.' and with source: '.$source->getName().'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); + + return null; }//end if - if (isset($component) === true) { - return $component; + return $repository; + + }//end getRepository() + + /** + * Get a repository through the repositories of the given source + * + * @param string $name The name of the repository. + * @param Source $source The source to sync from. + * + * @return array|null The imported repository as array. + */ + public function getOrganisationRepos(string $name, Source $source): ?array + { + $this->pluginLogger->debug('Getting repository '.$name.'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); + + try { + $response = $this->callService->call($source, '/repos/'.$name); + } catch (ClientException $exception) { + $this->pluginLogger->error($exception->getMessage(), ['plugin' => 'open-catalogi/open-catalogi-bundle']); + } + + if (isset($response) === false) { + return null; + } + + $repository = \Safe\json_decode($response->getBody()->getContents(), true); + + if ($repository === null) { + $this->pluginLogger->error('Could not find a repository with name: '.$name.' and with source: '.$source->getName().'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); + + return null; }//end if - return null; + return $repository; - }//end connectComponent() + }//end getRepository() /** diff --git a/src/Service/GithubEventService.php b/src/Service/GithubEventService.php index 0ac422d7..d1931f7e 100644 --- a/src/Service/GithubEventService.php +++ b/src/Service/GithubEventService.php @@ -59,6 +59,16 @@ class GithubEventService */ private GithubApiService $githubApiService; + /** + * @var GithubPubliccodeService + */ + private GithubPubliccodeService $publiccodeService; + + /** + * @var ImportResourcesService + */ + private ImportResourcesService $importResourcesService; + /** * @var EnrichPubliccodeFromGithubUrlService */ @@ -101,6 +111,8 @@ class GithubEventService * @param CallService $callService The Call Service. * @param CacheService $cacheService The Cache Service. * @param GithubApiService $githubApiService The Github Api Service. + * @param GithubPubliccodeService $publiccodeService The Github Publiccode Service. + * @param ImportResourcesService $importResourcesService The Import Resources Service. * @param EnrichPubliccodeFromGithubUrlService $enrichPubliccode The Enrich Publiccode From Github Url Service. * @param FindGithubRepositoryThroughOrganizationService $organizationService The find github repository through organization service. * @param GatewayResourceService $resourceService The Gateway Resource Service. @@ -113,6 +125,8 @@ public function __construct( CallService $callService, CacheService $cacheService, GithubApiService $githubApiService, + GithubPubliccodeService $publiccodeService, + ImportResourcesService $importResourcesService, EnrichPubliccodeFromGithubUrlService $enrichPubliccode, FindGithubRepositoryThroughOrganizationService $organizationService, GatewayResourceService $resourceService, @@ -124,6 +138,8 @@ public function __construct( $this->callService = $callService; $this->cacheService = $cacheService; $this->githubApiService = $githubApiService; + $this->publiccodeService = $publiccodeService; + $this->importResourcesService = $importResourcesService; $this->enrichPubliccode = $enrichPubliccode; $this->organizationService = $organizationService; $this->resourceService = $resourceService; @@ -134,77 +150,6 @@ public function __construct( }//end __construct() - - /** - * This function creates/updates the organization through the repository. - * - * @param Source $source The github api source - * @param array $repositoryArray The repository from github api - * @param string $repositoryUrl The url of the repository - * - * @throws GuzzleException|GatewayException|CacheException|InvalidArgumentException|ComponentException|LoaderError|SyntaxError|\Exception - * - * @return ObjectEntity|null The organization of the repository. - */ - public function importOrganizationThroughRepo(Source $source, array $repositoryArray, string $repositoryUrl): ?ObjectEntity - { - $organizationSchema = $this->resourceService->getSchema($this->configuration['organizationSchema'], 'open-catalogi/open-catalogi-bundle'); - $orgMapping = $this->resourceService->getMapping($this->configuration['organizationMapping'], 'open-catalogi/open-catalogi-bundle'); - - $ownerName = $repositoryArray['owner']['html_url']; - - $orgSync = $this->syncService->findSyncBySource($source, $organizationSchema, $repositoryArray['owner']['id']); - - $this->pluginLogger->debug('The mapping object '.$orgMapping.'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); - $this->pluginLogger->debug('Checking organization '.$ownerName.'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); - - $orgSync->setMapping($orgMapping); - - $orgSync = $this->syncService->synchronize($orgSync, $repositoryArray['owner']); - $this->pluginLogger->debug('Organization synchronization created with id: '.$orgSync->getId()->toString().'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); - - return $orgSync->getObject(); - - }//end importOrganizationThroughRepo() - - - /** - * This function gets the publiccode(s) of the repository. - * - * @param ObjectEntity $repository The repository - * @param string $repositoryUrl The url of the repository - * - * @throws GuzzleException|GatewayException|CacheException|InvalidArgumentException|ComponentException|LoaderError|SyntaxError|\Exception - * - * @return ObjectEntity The repository - */ - public function importComponentsThroughRepo(ObjectEntity $repository, string $repositoryUrl): ObjectEntity - { - $componentSchema = $this->resourceService->getSchema($this->configuration['componentSchema'], 'open-catalogi/open-catalogi-bundle'); - - // Get publiccode. - $action = $this->resourceService->getAction('https://opencatalogi.nl/action/oc.EnrichPubliccodeFromGithubUrlAction.action.json', 'open-catalogi/open-catalogi-bundle'); - $this->enrichPubliccode->setConfiguration($action->getConfiguration()); - $repository = $this->enrichPubliccode->enrichRepositoryWithPubliccode($repository, $repositoryUrl); - - // If there is no component create one. - if ($repository->getValue('components')->count() === 0) { - $component = new ObjectEntity($componentSchema); - $component->hydrate( - [ - 'name' => $repository->getValue('name'), - 'url' => $repository, - ] - ); - $this->entityManager->persist($component); - $this->entityManager->flush(); - } - - return $repository; - - }//end importComponentsThroughRepo() - - /** * This function creates/updates the repository with the github event response. * @@ -218,38 +163,31 @@ public function importComponentsThroughRepo(ObjectEntity $repository, string $re */ public function createRepository(Source $source, string $name, string $repositoryUrl): ?ObjectEntity { + $componentSchema = $this->resourceService->getSchema($this->configuration['componentSchema'], 'open-catalogi/open-catalogi-bundle'); $repositorySchema = $this->resourceService->getSchema($this->configuration['repositorySchema'], 'open-catalogi/open-catalogi-bundle'); $mapping = $this->resourceService->getMapping($this->configuration['repositoryMapping'], 'open-catalogi/open-catalogi-bundle'); - // Get repository from github. - $repositoryArray = $this->githubApiService->getRepository($name, $source); - if ($repositoryArray === null) { - // Return error if repository is not found. - $this->data['response'] = new Response('Cannot find repository with url: '.$repositoryUrl, 404); - - return $this->data; - }//end if - - $repositoryArray['name'] = str_replace('-', ' ', $repositoryArray['name']); - - $synchronization = $this->syncService->findSyncBySource($source, $repositorySchema, $repositoryArray['id']); - - $this->pluginLogger->debug('Mapping object '.$repositoryUrl.'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); - $this->pluginLogger->debug('The mapping object '.$mapping.'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); - $this->pluginLogger->debug('Checking repository '.$repositoryUrl.'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); + $this->configuration['organisationSchema'] = $this->configuration['organizationSchema']; + $this->configuration['organisationMapping'] = $this->configuration['organizationMapping']; - $synchronization->setMapping($mapping); - $synchronization = $this->syncService->synchronize($synchronization, $repositoryArray); - $this->pluginLogger->debug('Repository synchronization created with id: '.$synchronization->getId()->toString().'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); - - $repository = $synchronization->getObject(); + // Get the repository from the github api and import it. + $repositoryArray = $this->githubApiService->getRepository($name, $source); + $repository = $this->importResourcesService->importGithubRepository($repositoryArray, $this->configuration); - $repository = $this->importComponentsThroughRepo($repository, $repositoryUrl); + // If there is no component create one. + if ($repository->getValue('components')->count() === 0) { + $componentSync = $this->syncService->findSyncBySource($source, $componentSchema, $repositoryUrl); + $componentSync = $this->syncService->synchronize($componentSync, ['name' => $repository->getValue('name'), 'url' => $repository]); + } - $organization = $this->importOrganizationThroughRepo($source, $repositoryArray, $repositoryUrl); + // Get the publiccodes of the repository and mapp the components. + $repositories = $this->githubApiService->getPubliccodesFromRepo($name, $source); + if ($repositories['total_count'] !== 0) { + $repository = $this->publiccodeService->mappPubliccodesFromRepo($repositories, $repository); + } + $organization = $this->importResourcesService->importOrganisation($repositoryArray['owner'], $this->configuration); $repository->hydrate(['organisation' => $organization]); - $this->entityManager->persist($repository); $this->entityManager->flush(); diff --git a/src/Service/GithubPubliccodeService.php b/src/Service/GithubPubliccodeService.php index b0ab6563..47a38304 100644 --- a/src/Service/GithubPubliccodeService.php +++ b/src/Service/GithubPubliccodeService.php @@ -163,7 +163,7 @@ public function getRepositories(): ?array $result = []; $queryConfig = []; - $queryConfig['query'] = ['q' => 'filename:publiccode extension:yaml extension:yml repo:OpenCatalogi/OpenCatalogiBundle']; + $queryConfig['query'] = ['q' => 'filename:publiccode extension:yaml extension:yml']; // Find on publiccode.yaml. $repositories = $this->callService->getAllResults($source, '/search/code', $queryConfig); @@ -229,6 +229,49 @@ public function getRepository(string $repositoryId): ?array }//end getRepository() + /** + * Maps a repository object and creates/updates a Synchronization. + * + * @param array $repository The repository array that will be imported + * @param string $repositoryId The id of the repository to find the sync object + * @param Mapping $repositoryMapping The mapping of the repository + * @param string|null $publiccodeUrl The publiccode url + * + * @throws Exception + * + * @return ObjectEntity|null The repository object as array + */ + public function mappPubliccodesFromRepo(array $repositories, ObjectEntity $repository): ?ObjectEntity + { + $publiccodeUrls = []; + foreach ($repositories['items'] as $githubRepository) { + // Get the ref query from the url. This way we can get the publiccode file with the raw.gitgubusercontent + $publiccodeUrlQuery = \Safe\parse_url($githubRepository['url'])['query']; + $urlReference = explode('ref=', $publiccodeUrlQuery)[1]; + + $publiccodeUrls[] = $publiccodeUrl = "https://raw.githubusercontent.com/{$githubRepository['repository']['full_name']}/{$urlReference}/{$githubRepository['path']}"; + + // Get the publiccode through the raw.githubusercontent source + $publiccode = $this->githubApiService->getPubliccodeFromRawUserContent($publiccodeUrl); + + $this->pluginLogger->notice('Got publiccode from GitHub', $publiccode); + + if ($publiccode !== null) { + $repository = $this->mapPubliccode($repository, $publiccode, $this->configuration, $publiccodeUrl); + } + } + + if (isset($repository) === true) { + $repository->setValue('publiccode_urls', $publiccodeUrls); + $this->entityManager->persist($repository); + $this->entityManager->flush(); + + return $repository; + } + + return null; + } + /** * Maps a repository object and creates/updates a Synchronization. @@ -573,8 +616,8 @@ public function createContacts(array $publiccode, ObjectEntity $componentObject) */ public function findPubliccodeSync(ObjectEntity $repository, array $configuration, string $publiccodeUrl): ?Synchronization { - $usercontentSource = $this->resourceService->getSource($configuration['usercontentSource'], 'open-catalogi/open-catalogi-bundle'); - $componentEntity = $this->resourceService->getSchema($configuration['componentSchema'], 'open-catalogi/open-catalogi-bundle'); + $usercontentSource = $this->resourceService->getSource('https://opencatalogi.nl/source/oc.GitHubusercontent.source.json', 'open-catalogi/open-catalogi-bundle'); + $componentEntity = $this->resourceService->getSchema('https://opencatalogi.nl/oc.component.schema.json', 'open-catalogi/open-catalogi-bundle'); foreach ($repository->getValue('components') as $component) { if ($component->getValue('publiccodeUrl') === $publiccodeUrl) { @@ -623,8 +666,8 @@ public function findPubliccodeSync(ObjectEntity $repository, array $configuratio */ public function mapPubliccode(ObjectEntity $repository, array $publiccode, array $configuration, string $publiccodeUrl): ?ObjectEntity { - $githubSource = $this->resourceService->getSource($configuration['githubSource'], 'open-catalogi/open-catalogi-bundle'); - $componentMapping = $this->resourceService->getMapping($configuration['componentMapping'], 'open-catalogi/open-catalogi-bundle'); + $githubSource = $this->resourceService->getSource('https://opencatalogi.nl/source/oc.GitHubAPI.source.json', 'open-catalogi/open-catalogi-bundle'); + $componentMapping = $this->resourceService->getMapping('https://api.github.com/oc.githubPubliccodeComponent.mapping.json', 'open-catalogi/open-catalogi-bundle'); $sync = $this->findPubliccodeSync($repository, $configuration, $publiccodeUrl); diff --git a/src/Service/ImportResourcesService.php b/src/Service/ImportResourcesService.php index d479dd9d..298f75b3 100644 --- a/src/Service/ImportResourcesService.php +++ b/src/Service/ImportResourcesService.php @@ -254,7 +254,7 @@ public function importLegalRepoOwnerThroughComponent(array $componentArray, Obje * * @return ObjectEntity|null */ - public function importComponent(array $component, array $configuration): ?ObjectEntity + public function importCatalogusComponent(array $component, array $configuration): ?ObjectEntity { // Get the source, schema and mapping from the configuration array. $source = $this->resourceService->getSource($configuration['source'], 'open-catalogi/open-catalogi-bundle'); @@ -448,7 +448,7 @@ public function importApplication(array $application, array $configuration): ?Ob if ($application['components'] !== null) { $components = []; foreach ($application['components'] as $component) { - $componentObject = $this->importComponent($component, $configuration); + $componentObject = $this->importCatalogusComponent($component, $configuration); $components[] = $componentObject; }//end foreach @@ -462,6 +462,40 @@ public function importApplication(array $application, array $configuration): ?Ob }//end importApplication() + /** + * @param array $component The component that is being imported + * @param array $configuration The configuration array + * + * @return ObjectEntity|null + */ + public function importComponent(array $component, array $configuration): ?ObjectEntity + { + // Do we have a source? + $source = $this->resourceService->getSource($configuration['githubSource'], 'open-catalogi/open-catalogi-bundle'); + $componentSchema = $this->resourceService->getSchema($configuration['componentSchema'], 'open-catalogi/open-catalogi-bundle'); + $componentMapping = $this->resourceService->getMapping($configuration['componentMapping'], 'open-catalogi/open-catalogi-bundle'); + + if ($source === null + || $componentSchema === null + || $componentMapping === null + ) { + return null; + } + + $synchronization = $this->syncService->findSyncBySource($source, $componentSchema, $component['id']); + + $this->pluginLogger->debug('Mapping object'.$component['login'], ['plugin' => 'open-catalogi/open-catalogi-bundle']); + $this->pluginLogger->debug('The mapping object '.$componentMapping, ['plugin' => 'open-catalogi/open-catalogi-bundle']); + + $this->pluginLogger->debug('Checking organisation '.$component['login'], ['plugin' => 'open-catalogi/open-catalogi-bundle']); + $synchronization->setMapping($componentMapping); + $synchronization = $this->syncService->synchronize($synchronization, $component); + $this->pluginLogger->debug('Organisation synchronization created with id: '.$synchronization->getId()->toString(), ['plugin' => 'open-catalogi/open-catalogi-bundle']); + + return $synchronization->getObject(); + + }//end importOrganisation() + /** * @param array $organisation The organization that is being imported