Open Data Catalog v2.0.0
ImporterList.php
Go to the documentation of this file.
1 <?php
2 
4 
8 use FileFetcher\FileFetcher;
9 
13 class ImporterList {
14 
20  private $jobStoreFactory;
21 
22  private $resourceServiceFactory;
23  private $importServiceFactory;
24 
28  public function __construct(JobStoreFactory $jobStoreFactory, Resource $resrouceServiceFactory, Import $importServiceFactory) {
29  $this->jobStoreFactory = $jobStoreFactory;
30  $this->resourceServiceFactory = $resrouceServiceFactory;
31  $this->importServiceFactory = $importServiceFactory;
32  }
33 
40  private function buildList() {
41  $list = [];
42 
43  $fileFetchers = [];
44  $importers = [];
45 
46  $store = $this->jobStoreFactory->getInstance(FileFetcher::class);
47  foreach ($store->retrieveAll() as $id) {
48  try {
49  $fileFetchers[$id] = $this->resourceServiceFactory->getInstance($id)
50  ->getFileFetcher();
51 
52  /* @var $resource \Dkan\Datastore\Resource */
53  $resource = $this->resourceServiceFactory->getInstance($id)->get();
54  $importers[$id] = $this->importServiceFactory->getInstance($resource->getId(),
55  ['resource' => $resource])->getImporter();
56  }
57  catch (\Exception $e) {
58  // The file fetcher id is not a resource.
59  }
60  }
61 
62  foreach ($fileFetchers as $uuid => $fileFetcher) {
63  $importer = isset($importers[$uuid]) ? $importers[$uuid] : NULL;
64  $list[$uuid] = ImporterListItem::getItem($fileFetcher, $importer);
65  }
66 
67  return $list;
68  }
69 
73  public static function getList(JobStoreFactory $jobStoreFactory, Resource $resrouceServiceFactory, Import $importServiceFactory): array {
74  $importerLister = new ImporterList($jobStoreFactory, $resrouceServiceFactory, $importServiceFactory);
75  return $importerLister->buildList();
76  }
77 
78 }
Drupal\dkan_datastore\Service\Factory\Resource
Definition: Resource.php:16
Drupal\dkan_datastore\Service\ImporterList
Definition: ImporterList.php:3
Drupal\dkan_datastore\Service\ImporterList\ImporterList\__construct
__construct(JobStoreFactory $jobStoreFactory, Resource $resrouceServiceFactory, Import $importServiceFactory)
Definition: ImporterList.php:28
Drupal\dkan_datastore\Service\Factory\Import
Definition: Import.php:15
Drupal\dkan_datastore\Service\ImporterList\ImporterList\getList
static getList(JobStoreFactory $jobStoreFactory, Resource $resrouceServiceFactory, Import $importServiceFactory)
Definition: ImporterList.php:73
Drupal\dkan_datastore\Service\Factory\Import\getInstance
getInstance(string $identifier, array $config=[])
Definition: Import.php:34
Drupal\dkan_datastore\Service\ImporterList\ImporterList
Definition: ImporterList.php:13
Drupal\dkan_datastore\Service\ImporterList\ImporterListItem\getItem
static getItem(FileFetcher $fileFetcher, $importer=NULL)
Definition: ImporterListItem.php:110
Drupal\dkan_datastore\Storage\JobStoreFactory
Definition: JobStoreFactory.php:11