Source of file GnPublishMetadataCommand.php
Size: 3,376 Bytes - Last Modified: 2021-12-23T10:31:40+00:00
/var/www/docs.ssmods.com/process/src/code/commands/GnPublishMetadataCommand.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 | <?php /** * @author Rainer Spittel (rainer at silverstripe dot com) * @package geocatalog * @subpackage commands */ /** * Perform a insert request to a GeoNetwork node. */ class GnPublishMetadataCommand extends GnAuthenticationCommand { /** * @var string $api_url refers the the GeoNetwork action to perform the publish process. */ public static $api_url = 'srv/en/metadata.admin'; public static $RequireAuth = true; public static $xsl_path = '../geocatalogue/xslt/gnInsertResponse.xsl'; public static function get_api_url() { return self::$api_url; } public static function set_api_url($value) { self::$api_url = $value; } public static function get_xsl_path() { return self::$xsl_path; } public static function set_xsl_path($xsl_path) { self::$xsl_path = $xsl_path; } /** * Command execute * * Performs the command to insert/add new metadata. This command creates a * request (initiates a sub-command) and uses this to send of the * OGC request to GeoNetwork. * * @see CreateInsertCommand * * @return string OGC CSW response */ public function execute() { $data = $this->getParameters(); $gnID = $data['gnID']; try { $this->restfulService = new GeoNetworkRestfulService($this->getController()->getGeoNetworkBaseURL(), 0); if ($this->getUsername()) { $this->restfulService->setUsername($this->getUsername()); $this->restfulService->setPassword($this->getPassword()); $this->restfulService->setRequireAuthentication(true); } } catch (CataloguePage_Exception $e) { throw new GnPublishMetadataCommand_Exception($e->getMessage()); } // build the parameters for the publish request. It is a structure of // a geonetwork form to publish the data to non-registered users and // allow the download of assigned data sources. $data = array(); $data['id'] = $gnID; $data['_1_0'] = "on"; $data['_1_1'] = "on"; $params = GnCreateInsertCommand::implode_with_keys($data); $headers = array('Content-Type: application/x-www-form-urlencoded'); $response = $this->restfulService->request($this->get_api_url(), 'POST', $params, $headers); // @todo better error handling $responseXML = $response->getBody(); // parse catalogue response $data = array( 'xml' => $responseXML, 'xsl' => self::get_xsl_path() ); $cmd = $this->getController()->getCommand("TranslateXML", $data); $xml = $cmd->execute(); $id = $gnID; $gnID = null; // toDo: bad! use JSON eval(trim($xml)); if (!isset($gnID)) { throw new GnPublishMetadataCommand_Exception('GeoNetwork ID for the new dataset has not been created.'); } if ($gnID != $id) { throw new GnPublishMetadataCommand_Exception('GeoNetwork publication has failed.'); } return $gnID; } } /** * Customised Exception class. */ class GnPublishMetadataCommand_Exception extends Exception { } |