code/api/MetadataPushApi.php
/**
     * Does the push to the catalogue.
     *
     * @param Array $fields Associative array fields to include in the XML sent to the catalogue.
     *
     * @return String
     */
Does the push to the catalogue.
@param Array $fields Associative array fields to include in the XML sent to the catalogue.

@return String
Does the push to the catalogue . @param Array $fields Associative array fields to include in the XML sent to the catalogue . @return String
public function execute($fields)
    {
        $identifier = null;
        $headers = array('Content-Type: application/xml', 'User-Agent: Metadata-postcard-entry');
        $data = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
                '<csw:Transaction xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" version="2.0.2" service="CSW">' . "\n" .
                '<csw:Insert>' . "\n" .
                '<simpledc xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dct="http://purl.org/dc/terms/" xmlns:geonet="http://www.fao.org/geonetwork" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="xml/schemas/dublin-core/schema.xsd">' . "\n";
        foreach($fields as $field) {
            $data .= '<' . strtolower($field['xmlname']) . '>' . htmlspecialchars($field['value']) . '</' . strtolower($field['xmlname']) . '>' . "\n";
        }
        $data .= '</simpledc>' . "\n" .
                 '</csw:Insert>' . "\n" .
                 '</csw:Transaction>';
        list($response, $httpStatus, $curlError) = $this->makeCurlRequest($headers, $data);
        if ($httpStatus != 200) {
            throw new Exception('The catalogue responsed with the following HTTP code: ' . $httpStatus . ' - ' . $curlError);
        }
        $doc = new DOMDocument();
        try {
            $doc->loadXML($response);
        }
        catch (Exception $e) {
            throw new Exception('The response from the catalogue was not valid XML so this tool could not parse it.');
        }
        $xpath = new DOMXPath($doc);
        $idList = $xpath->query('//csw:InsertResult/csw:BriefRecord/identifier');
        if (($idList) && ($idList->length > 0)) {
            $identifier = $idList->item(0)->nodeValue;
        }
        if (!isset($identifier)) {
            throw new Exception('Identifier for the new record not found. No record must have been created.');
        }
        return $identifier;
    }
public function execute ( $ fields ) { $ identifier = null ; $ headers = array ( 'Content-Type: application/xml' , 'User-Agent: Metadata-postcard-entry' ) ; $ data = '<?xml version="1.0" encoding="UTF-8"?>' . " \n " . '<csw:Transaction xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" version="2.0.2" service="CSW">' . " \n " . '<csw:Insert>' . " \n " . '<simpledc xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dct="http://purl.org/dc/terms/" xmlns:geonet="http://www.fao.org/geonetwork" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="xml/schemas/dublin-core/schema.xsd">' . " \n " ; foreach ( $ fields as $ field ) { $ data .= '<' . strtolower ( $ field [ 'xmlname' ] ) . '>' . htmlspecialchars ( $ field [ 'value' ] ) . '</' . strtolower ( $ field [ 'xmlname' ] ) . '>' . " \n " ; } $ data .= '</simpledc>' . " \n " . '</csw:Insert>' . " \n " . '</csw:Transaction>' ; list ( $ response , $ httpStatus , $ curlError ) = $ this -> makeCurlRequest ( $ headers , $ data ) ; if ( $ httpStatus != 200 ) { throw new Exception ( 'The catalogue responsed with the following HTTP code: ' . $ httpStatus . ' - ' . $ curlError ) ; } $ doc = new DOMDocument ( ) ; try { $ doc -> loadXML ( $ response ) ; } catch ( Exception $ e ) { throw new Exception ( 'The response from the catalogue was not valid XML so this tool could not parse it.' ) ; } $ xpath = new DOMXPath ( $ doc ) ; $ idList = $ xpath -> query ( '//csw:InsertResult/csw:BriefRecord/identifier' ) ; if ( ( $ idList ) && ( $ idList -> length > 0 ) ) { $ identifier = $ idList -> item ( 0 ) -> nodeValue ; } if ( ! isset ( $ identifier ) ) { throw new Exception ( 'Identifier for the new record not found. No record must have been created.' ) ; } return $ identifier ; }
Does the push to the catalogue.
Does the push to the catalogue .
// Set up the headers, according to the CSW this is XML. // Also it appears that the newer version of geocatalogue needs the user agent set. // Put together the data to send, this must be XML. // These starting tags are from this CSW docs... // http://geonetwork-opensource.org/manuals/2.10.4/eng/developer/xml_services/csw_services.html#transaction // see also http://dublincore.org/documents/dc-xml-guidelines/ // Now loop though all the form fields passed in and add them to the XML. The fields should be an assosiative array // of xmlnames and values. The dc: prefix should be included in the xmlname for the field. // Dublin core field names should all be lower case so ensure this. // Also encode the value to ensure that any less or greater than symbols do not break the XML. // Close the XML insert. // Make the post request and get the response. // We expect a status code of 200 for the insert/getrecords and getrecordsbyid requests. // Check the response which should be XML if all was fine and get the identifier for the new record. // Return the identifier of the new record.