|
|
|
@ -11,6 +11,9 @@ namespace Drupal\islandora_herbarium_object\DataParser; |
|
|
|
|
|
|
|
|
|
|
|
class NrcanParser extends DataParser |
|
|
|
class NrcanParser extends DataParser |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
public $nrcanUrlSearchPrefix = 'http://geogratis.gc.ca/services/geoname/en/geonames?q='; |
|
|
|
|
|
|
|
public $nrcanUrlPrefix = 'http://geogratis.gc.ca/services/geoname/en/geonames/'; |
|
|
|
|
|
|
|
|
|
|
|
public function parseData() |
|
|
|
public function parseData() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$arr = json_decode($this->data, TRUE); |
|
|
|
$arr = json_decode($this->data, TRUE); |
|
|
|
@ -22,11 +25,20 @@ class NrcanParser extends DataParser |
|
|
|
|
|
|
|
|
|
|
|
public function updateEntity($entity) { |
|
|
|
public function updateEntity($entity) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
$url = ''; |
|
|
|
$dwciri = $entity->get("field_dwciri_municipality")->getValue(); |
|
|
|
$dwciri = $entity->get("field_dwciri_municipality")->getValue(); |
|
|
|
if(empty($dwciri[0]['value'])) { |
|
|
|
if(empty($url = $dwciri[0]['value']) && !empty($entity->get("field_dwc_municipality")->getValue())) { |
|
|
|
throw new Exception("No URI provided, cannot look up location data."); |
|
|
|
//throw new Exception("No URI provided, cannot look up location data."); |
|
|
|
|
|
|
|
$value = array($this->getNrcanUrl($entity->get('field_dwc_municipality')->getValue()[0]['value'])); |
|
|
|
|
|
|
|
$dwciri[] = ['value' => $value[0]]; |
|
|
|
|
|
|
|
$url = $dwciri[0]['value']; |
|
|
|
|
|
|
|
if(empty($url)) { |
|
|
|
|
|
|
|
throw new \Exception("No Municipality URI or Municipality text provided, cannot look up taxon data."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$entity->set('field_dwciri_municipality', $url); |
|
|
|
} |
|
|
|
} |
|
|
|
$this->getRemoteData($dwciri[0]['value']); |
|
|
|
|
|
|
|
|
|
|
|
$this->getRemoteData($url); |
|
|
|
$this->parseData(); |
|
|
|
$this->parseData(); |
|
|
|
} catch (Exception $e) { |
|
|
|
} catch (Exception $e) { |
|
|
|
watchdog_exception('islandora_herbarium_object', $e, 'Error getting dwciri'); |
|
|
|
watchdog_exception('islandora_herbarium_object', $e, 'Error getting dwciri'); |
|
|
|
@ -59,4 +71,18 @@ class NrcanParser extends DataParser |
|
|
|
$geo_field_value = \Drupal::service('geofield.wkt_generator')->WktBuildPoint($point); |
|
|
|
$geo_field_value = \Drupal::service('geofield.wkt_generator')->WktBuildPoint($point); |
|
|
|
$entity->set('field_herb_geo_field', $geo_field_value); |
|
|
|
$entity->set('field_herb_geo_field', $geo_field_value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getNrcanUrl($municipality){ |
|
|
|
|
|
|
|
$url = $this->nrcanUrlSearchPrefix . $municipality . "&province=11"; |
|
|
|
|
|
|
|
$data = $this->getRemoteData($url, TRUE); |
|
|
|
|
|
|
|
$data_arr = json_decode($data, TRUE); |
|
|
|
|
|
|
|
$key = ''; |
|
|
|
|
|
|
|
foreach($data_arr['items'] as $item) { |
|
|
|
|
|
|
|
if($item['name'] === $municipality){ |
|
|
|
|
|
|
|
$key = $item['id']; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return $this->nrcanUrlPrefix . $key; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|