public function save($extraData = null, $commit = null)
 {
     $document = OpenSKOS_Rdf_Parser::DomNode2SolrDocument($this->toRDF()->documentElement->firstChild, $extraData);
     $this->solr()->add($document, $commit);
     return $this;
 }
Beispiel #2
0
     if (null !== $OPTS->verbose) {
         fwrite(STDOUT, "FAILED\n");
     }
     fwrite(STDERR, "Recieved RDF-XML of record `{$record->identifier}`  is not valid: expected <rdf:RDF/> rootnode, got <{$doc->documentElement->nodeName}/>\n");
     continue;
 }
 $Descriptions = $doc->documentElement->getElementsByTagNameNs(OpenSKOS_Rdf_Parser::$namespaces['rdf'], 'Description');
 if ($Descriptions->length != 1) {
     if (null !== $OPTS->verbose) {
         fwrite(STDOUT, "FAILED\n");
     }
     fwrite(STDERR, "Expected exactly one /rdf:RDF/rdf:Description, got {$Descriptions->length}\n");
     continue;
 }
 try {
     $solrDocument = OpenSKOS_Rdf_Parser::DomNode2SolrDocument($Descriptions->item(0), $data);
 } catch (OpenSKOS_Rdf_Parser_Exception $e) {
     if (null !== $OPTS->verbose) {
         fwrite(STDOUT, "FAILED\n");
     }
     fwrite(STDERR, "record {$record->identifier}: " . $e->getMessage() . "\n");
     continue;
 }
 try {
     $solrDocument->save();
 } catch (OpenSKOS_Solr_Exception $e) {
     if (null !== $OPTS->verbose) {
         fwrite(STDOUT, "FAILED\n");
     }
     fwrite(STDERR, 'Failed to save Concept `' . $solrDocument['uri'][0] . '`: ' . $e->getMessage() . "\n");
     continue;
 public function postAction()
 {
     $this->getHelper('layout')->disableLayout();
     $this->getHelper('viewRenderer')->setNoRender(true);
     $this->view->errorOnly = true;
     $xml = $this->getRequest()->getRawBody();
     if (!$xml) {
         throw new Zend_Controller_Action_Exception('No RDF-XML recieved', 412);
     }
     $doc = new DOMDocument();
     if (!@$doc->loadXML($xml)) {
         throw new Zend_Controller_Action_Exception('Recieved RDF-XML is not valid XML', 412);
     }
     //do some basic tests
     if ($doc->documentElement->nodeName != 'rdf:RDF') {
         throw new Zend_Controller_Action_Exception('Recieved RDF-XML is not valid: expected <rdf:RDF/> rootnode, got <' . $doc->documentElement->nodeName . '/>', 412);
     }
     $Descriptions = $doc->documentElement->getElementsByTagNameNs(OpenSKOS_Rdf_Parser::$namespaces['rdf'], 'Description');
     if ($Descriptions->length != 1) {
         throw new Zend_Controller_Action_Exception('Expected exactly one /rdf:RDF/rdf:Description, got ' . $Descriptions->length, 412);
     }
     //is a tenant, collection or api key set in the XML?
     foreach (array('tenant', 'collection', 'key') as $attributeName) {
         $value = $doc->documentElement->getAttributeNS(OpenSKOS_Rdf_Parser::$namespaces['openskos'], $attributeName);
         if ($value) {
             $this->getRequest()->setParam($attributeName, $value);
         }
     }
     $tenant = $this->_getTenant();
     $collection = $this->_getCollection();
     $user = $this->_getUser();
     $data = array('tenant' => $tenant->code, 'collection' => $collection->id);
     try {
         $solrDocument = OpenSKOS_Rdf_Parser::DomNode2SolrDocument($Descriptions->item(0), $data);
     } catch (OpenSKOS_Rdf_Parser_Exception $e) {
         throw new Zend_Controller_Action_Exception($e->getMessage(), 400);
     }
     //get the Concept based on it's URI:
     $concept = $this->model->getConcept($solrDocument['uri'][0]);
     //modify the UUID of the Solr Document:
     if (null !== $concept) {
         $solrDocument->offsetUnset('uuid');
         $solrDocument->offsetSet('uuid', $concept['uuid']);
         // Preserve any old data which is not part of the rdf.
         if (isset($concept['created_by'])) {
             $solrDocument->offsetSet('created_by', $concept['created_by']);
         }
         if (isset($concept['modified_by'])) {
             $solrDocument->offsetSet('modified_by', $concept['modified_by']);
         }
         if (isset($concept['approved_by'])) {
             $solrDocument->offsetSet('approved_by', $concept['approved_by']);
         }
         if (isset($concept['deleted_by'])) {
             $solrDocument->offsetSet('deleted_by', $concept['deleted_by']);
         }
         if (isset($concept['toBeChecked'])) {
             $solrDocument->offsetSet('toBeChecked', $concept['toBeChecked']);
         }
     }
     if ($this->getRequest()->getActionName() == 'put') {
         if (!$concept) {
             throw new Zend_Controller_Action_Exception('Concept `' . $solrDocument['uri'][0] . '` does not exists, try POST-ing it to create it as a new concept.', 404);
         }
     } else {
         if ($concept) {
             throw new Zend_Controller_Action_Exception('Concept `' . $solrDocument['uri'][0] . '` already exists', 409);
         }
     }
     try {
         $solrDocument->save(true);
     } catch (OpenSKOS_Solr_Exception $e) {
         throw new Zend_Controller_Action_Exception('Failed to save Concept `' . $solrDocument['uri'][0] . '`: ' . $e->getMessage(), 400);
     }
     $location = $this->view->serverUrl() . $this->view->url(array('controller' => 'concept', 'action' => 'get', 'module' => 'api', 'id' => $solrDocument['uuid'][0]), 'rest', true);
     $this->getResponse()->setHeader('Content-Type', 'text/xml; charset="utf-8"', true)->setHeader('Location', $location)->setHttpResponseCode(201);
     echo $doc->saveXml($Descriptions->item(0));
 }