00001 <?php
00002
00005
00026 class CrudCreate extends WebService
00027 {
00029 private $db;
00030
00032 private $conneg;
00033
00035 private $dtdURL;
00036
00038 public static $supportedSerializations =
00039 array ("application/json", "application/rdf+xml", "application/rdf+n3", "application/*", "text/xml", "text/*",
00040 "*/*");
00041
00043 private $registered_ip = "";
00044
00046 private $dataset;
00047
00049 private $document = array();
00050
00052 private $mime = "";
00053
00055 private $requester_ip = "";
00056
00058 private $errorMessenger =
00059 '{
00060 "ws": "/ws/crud/create/",
00061 "_200": {
00062 "id": "WS-CRUD-CREATE-200",
00063 "level": "Warning",
00064 "name": "No RDF document to index",
00065 "description": "No RDF document has been defined for this query"
00066 },
00067 "_201": {
00068 "id": "WS-CRUD-CREATE-201",
00069 "level": "Warning",
00070 "name": "Unknown MIME type for this RDF document",
00071 "description": "An unknown MIME type has been defined for this RDF document"
00072 },
00073 "_202": {
00074 "id": "WS-CRUD-CREATE-202",
00075 "level": "Warning",
00076 "name": "No dataset specified",
00077 "description": "No dataset URI defined for this query"
00078 },
00079 "_300": {
00080 "id": "WS-CRUD-CREATE-300",
00081 "level": "Fatal",
00082 "name": "Can\'t create data",
00083 "description": "Can\'t create data of the specified format"
00084 },
00085 "_301": {
00086 "id": "WS-CRUD-CREATE-301",
00087 "level": "Warning",
00088 "name": "Can\'t parse RDF document",
00089 "description": "Can\'t parse the specified RDF document"
00090 },
00091 "_302": {
00092 "id": "WS-CRUD-CREATE-302",
00093 "level": "Warning",
00094 "name": "Syntax error in the RDF document",
00095 "description": "A syntax error exists in the specified RDF document"
00096 },
00097 "_303": {
00098 "id": "WS-CRUD-CREATE-303",
00099 "level": "Fatal",
00100 "name": "Can\'t update the Solr index",
00101 "description": "An error occured when we tried to update the Solr index"
00102 },
00103 "_304": {
00104 "id": "WS-CRUD-CREATE-304",
00105 "level": "Fatal",
00106 "name": "Can\'t commit changes to the Solr index",
00107 "description": "An error occured when we tried to commit changes to the Solr index"
00108 }
00109 }';
00110
00111
00130 function __construct($document, $mime, $mode, $dataset, $registered_ip, $requester_ip)
00131 {
00132 parent::__construct();
00133
00134 $this->db = new DB_Virtuoso($this->db_username, $this->db_password, $this->db_dsn, $this->db_host);
00135
00136 $this->registered_ip = $registered_ip;
00137 $this->requester_ip = $requester_ip;
00138 $this->dataset = $dataset;
00139
00140 $this->document = utf8_encode($document);
00141 $this->mime = $mime;
00142 $this->mode = $mode;
00143
00144 if($this->registered_ip == "")
00145 {
00146 $this->registered_ip = $requester_ip;
00147 }
00148
00149 if(strtolower(substr($this->registered_ip, 0, 4)) == "self")
00150 {
00151 $pos = strpos($this->registered_ip, "::");
00152
00153 if($pos !== FALSE)
00154 {
00155 $account = substr($this->registered_ip, $pos + 2, strlen($this->registered_ip) - ($pos + 2));
00156
00157 $this->registered_ip = $requester_ip . "::" . $account;
00158 }
00159 else
00160 {
00161 $this->registered_ip = $requester_ip;
00162 }
00163 }
00164
00165 $this->uri = $this->wsf_base_url . "/wsf/ws/crud/create/";
00166 $this->title = "Crud Create Web Service";
00167 $this->crud_usage = new CrudUsage(TRUE, FALSE, FALSE, FALSE);
00168 $this->endpoint = $this->wsf_base_url . "/ws/crud/create/";
00169
00170 $this->dtdURL = "auth/CrudCreate.dtd";
00171
00172 $this->errorMessenger = json_decode($this->errorMessenger);
00173 }
00174
00175 function __destruct()
00176 {
00177 parent::__destruct();
00178
00179 if(isset($this->db))
00180 {
00181 @$this->db->close();
00182 }
00183 }
00184
00195 protected function validateQuery()
00196 {
00197
00198 $ws_av = new AuthValidator($this->requester_ip, $this->dataset, $this->uri);
00199
00200 $ws_av->pipeline_conneg($this->conneg->getAccept(), $this->conneg->getAcceptCharset(),
00201 $this->conneg->getAcceptEncoding(), $this->conneg->getAcceptLanguage());
00202
00203 $ws_av->process();
00204
00205 if($ws_av->pipeline_getResponseHeaderStatus() != 200)
00206 {
00207 $this->conneg->setStatus($ws_av->pipeline_getResponseHeaderStatus());
00208 $this->conneg->setStatusMsg($ws_av->pipeline_getResponseHeaderStatusMsg());
00209 $this->conneg->setStatusMsgExt($ws_av->pipeline_getResponseHeaderStatusMsgExt());
00210 $this->conneg->setError($ws_av->pipeline_getError()->id, $ws_av->pipeline_getError()->webservice,
00211 $ws_av->pipeline_getError()->name, $ws_av->pipeline_getError()->description,
00212 $ws_av->pipeline_getError()->debugInfo, $ws_av->pipeline_getError()->level);
00213
00214 return;
00215 }
00216
00217 unset($ws_av);
00218
00219
00220 $ws_av = new AuthValidator($this->registered_ip, $this->dataset, $this->uri);
00221
00222 $ws_av->pipeline_conneg($this->conneg->getAccept(), $this->conneg->getAcceptCharset(),
00223 $this->conneg->getAcceptEncoding(), $this->conneg->getAcceptLanguage());
00224
00225 $ws_av->process();
00226
00227 if($ws_av->pipeline_getResponseHeaderStatus() != 200)
00228 {
00229 $this->conneg->setStatus($ws_av->pipeline_getResponseHeaderStatus());
00230 $this->conneg->setStatusMsg($ws_av->pipeline_getResponseHeaderStatusMsg());
00231 $this->conneg->setStatusMsgExt($ws_av->pipeline_getResponseHeaderStatusMsgExt());
00232 $this->conneg->setError($ws_av->pipeline_getError()->id, $ws_av->pipeline_getError()->webservice,
00233 $ws_av->pipeline_getError()->name, $ws_av->pipeline_getError()->description,
00234 $ws_av->pipeline_getError()->debugInfo, $ws_av->pipeline_getError()->level);
00235 return;
00236 }
00237 }
00238
00249 public function pipeline_getError() { return ($this->conneg->error); }
00250
00251
00262 public function pipeline_getResultset() { return ""; }
00263
00276 public function injectDoctype($xmlDoc)
00277 {
00278 $posHeader = strpos($xmlDoc, '"?>') + 3;
00279 $xmlDoc = substr($xmlDoc, 0, $posHeader)
00280 . "\n<!DOCTYPE resultset PUBLIC \"-//Structured Dynamics LLC//Crud Create DTD 0.1//EN\" \"" . $this->dtdBaseURL
00281 . $this->dtdURL . "\">" . substr($xmlDoc, $posHeader, strlen($xmlDoc) - $posHeader);
00282
00283 return ($xmlDoc);
00284 }
00285
00304 public function ws_conneg($accept, $accept_charset, $accept_encoding, $accept_language)
00305 {
00306 $this->conneg =
00307 new Conneg($accept, $accept_charset, $accept_encoding, $accept_language, CrudCreate::$supportedSerializations);
00308
00309
00310
00311 if($this->document == "")
00312 {
00313 $this->conneg->setStatus(400);
00314 $this->conneg->setStatusMsg("Bad Request");
00315 $this->conneg->setStatusMsgExt($this->errorMessenger->_200->name);
00316 $this->conneg->setError($this->errorMessenger->_200->id, $this->errorMessenger->ws,
00317 $this->errorMessenger->_200->name, $this->errorMessenger->_200->description, "",
00318 $this->errorMessenger->_200->level);
00319 return;
00320 }
00321
00322 if($this->mime != "application/rdf+xml" && $this->mime != "application/rdf+n3")
00323 {
00324 $this->conneg->setStatus(400);
00325 $this->conneg->setStatusMsg("Bad Request");
00326 $this->conneg->setStatusMsgExt($this->errorMessenger->_201->name);
00327 $this->conneg->setError($this->errorMessenger->_201->id, $this->errorMessenger->ws,
00328 $this->errorMessenger->_201->name, $this->errorMessenger->_201->description, ($this->mime),
00329 $this->errorMessenger->_201->level);
00330 return;
00331 }
00332
00333 if($this->dataset == "")
00334 {
00335 $this->conneg->setStatus(400);
00336 $this->conneg->setStatusMsg("Bad Request");
00337 $this->conneg->setStatusMsgExt($this->errorMessenger->_202->name);
00338 $this->conneg->setError($this->errorMessenger->_202->id, $this->errorMessenger->ws,
00339 $this->errorMessenger->_202->name, $this->errorMessenger->_202->description, "",
00340 $this->errorMessenger->_202->level);
00341 return;
00342 }
00343
00344
00345
00346 $ws_dr = new DatasetRead($this->dataset, "false", "self",
00347 $this->wsf_local_ip);
00348
00349 $ws_dr->pipeline_conneg($this->conneg->getAccept(), $this->conneg->getAcceptCharset(),
00350 $this->conneg->getAcceptEncoding(), $this->conneg->getAcceptLanguage());
00351
00352 $ws_dr->process();
00353
00354 if($ws_dr->pipeline_getResponseHeaderStatus() != 200)
00355 {
00356 $this->conneg->setStatus($ws_dr->pipeline_getResponseHeaderStatus());
00357 $this->conneg->setStatusMsg($ws_dr->pipeline_getResponseHeaderStatusMsg());
00358 $this->conneg->setStatusMsgExt($ws_dr->pipeline_getResponseHeaderStatusMsgExt());
00359 $this->conneg->setError($ws_dr->pipeline_getError()->id, $ws_dr->pipeline_getError()->webservice,
00360 $ws_dr->pipeline_getError()->name, $ws_dr->pipeline_getError()->description,
00361 $ws_dr->pipeline_getError()->debugInfo, $ws_dr->pipeline_getError()->level);
00362 return;
00363 }
00364 }
00365
00384 public function pipeline_conneg($accept, $accept_charset, $accept_encoding, $accept_language)
00385 { $this->ws_conneg($accept, $accept_charset, $accept_encoding, $accept_language); }
00386
00397 public function pipeline_getResponseHeaderStatus() { return $this->conneg->getStatus(); }
00398
00409 public function pipeline_getResponseHeaderStatusMsg() { return $this->conneg->getStatusMsg(); }
00410
00423 public function pipeline_getResponseHeaderStatusMsgExt() { return $this->conneg->getStatusMsgExt(); }
00424
00435 public function pipeline_serialize() { return ""; }
00436
00445 public function pipeline_serialize_reification() { return ""; }
00446
00457 public function ws_serialize() { return ""; }
00458
00471 public function ws_respond($content)
00472 {
00473
00474 $this->conneg->respond();
00475
00476
00477
00478
00479 if($this->conneg->getStatus() == 200)
00480 {
00481 echo $content;
00482 }
00483
00484 $this->__destruct();
00485 }
00486
00487
00496 public function process()
00497 {
00498
00499 if($this->conneg->getStatus() == 200)
00500 {
00501 $this->validateQuery();
00502
00503
00504 if($this->conneg->getStatus() == 200)
00505 {
00506 if($this->mime != "application/rdf+xml" && $this->mime != "application/rdf+n3")
00507 {
00508 $this->conneg->setStatus(400);
00509 $this->conneg->setStatusMsg("Bad Request");
00510 $this->conneg->setStatusMsgExt($this->errorMessenger->_300->name);
00511 $this->conneg->setError($this->errorMessenger->_300->id, $this->errorMessenger->ws,
00512 $this->errorMessenger->_300->name, $this->errorMessenger->_300->description,
00513 "Can't create data of format: " . $this->mime, $this->errorMessenger->_300->level);
00514
00515 return;
00516 }
00517
00518
00519 $parser = ARC2::getRDFParser();
00520 $parser->parse($this->dataset, $this->document);
00521 $rdfxmlSerializer = ARC2::getRDFXMLSerializer();
00522
00523 $resourceIndex = $parser->getSimpleIndex(0);
00524
00525 if(count($parser->getErrors()) > 0)
00526 {
00527 $errorsOutput = "";
00528 $errors = $parser->getErrors();
00529
00530 foreach($errors as $key => $error)
00531 {
00532 $errorsOutput .= "[Error #$key] $error\n";
00533 }
00534
00535 $this->conneg->setStatus(400);
00536 $this->conneg->setStatusMsg("Bad Request");
00537 $this->conneg->setError($this->errorMessenger->_301->id, $this->errorMessenger->ws,
00538 $this->errorMessenger->_301->name, $this->errorMessenger->_301->description, $errorsOutput,
00539 $this->errorMessenger->_301->level);
00540
00541 return;
00542 }
00543
00544
00545 $break = FALSE;
00546 $datasetUri;
00547
00548 foreach($resourceIndex as $resource => $description)
00549 {
00550 foreach($description as $predicate => $values)
00551 {
00552 if($predicate == "http://www.w3.org/1999/02/22-rdf-syntax-ns#type")
00553 {
00554 foreach($values as $value)
00555 {
00556 if($value["type"] == "uri" && $value["value"] == "http://rdfs.org/ns/void#Dataset")
00557 {
00558 $datasetUri = $resource;
00559 break;
00560 }
00561 }
00562 }
00563
00564 if($break)
00565 {
00566 break;
00567 }
00568 }
00569
00570 if($break)
00571 {
00572 break;
00573 }
00574 }
00575
00576
00577
00578 $break = FALSE;
00579 $statementsUri = array();
00580
00581 foreach($resourceIndex as $resource => $description)
00582 {
00583 foreach($description as $predicate => $values)
00584 {
00585 if($predicate == "http://www.w3.org/1999/02/22-rdf-syntax-ns#type")
00586 {
00587 foreach($values as $value)
00588 {
00589 if($value["type"] == "uri" && $value["value"] == "http://www.w3.org/1999/02/22-rdf-syntax-ns#Statement")
00590 {
00591 array_push($statementsUri, $resource);
00592 break;
00593 }
00594 }
00595 }
00596
00597 if($break)
00598 {
00599 break;
00600 }
00601 }
00602
00603 if($break)
00604 {
00605 break;
00606 }
00607 }
00608
00609
00610 $irsUri = array();
00611
00612 foreach($resourceIndex as $resource => $description)
00613 {
00614 if($resource != $datasetUri && array_search($resource, $statementsUri) === FALSE)
00615 {
00616 array_push($irsUri, $resource);
00617 }
00618 }
00619
00620
00621 if($this->mode == "full" || $this->mode == "triplestore")
00622 {
00623 $irs = array();
00624
00625 foreach($irsUri as $uri)
00626 {
00627 $irs[$uri] = $resourceIndex[$uri];
00628 }
00629
00630 $this->db->query("DB.DBA.RDF_LOAD_RDFXML_MT('"
00631 . str_replace("'", "\'", $rdfxmlSerializer->getSerializedIndex($irs)) . "', '" . $this->dataset . "', '"
00632 . $this->dataset . "')");
00633
00634 if(odbc_error())
00635 {
00636 $this->conneg->setStatus(400);
00637 $this->conneg->setStatusMsg("Bad Request");
00638 $this->conneg->setError($this->errorMessenger->_302->id, $this->errorMessenger->ws,
00639 $this->errorMessenger->_302->name, $this->errorMessenger->_302->description, odbc_errormsg(),
00640 $this->errorMessenger->_302->level);
00641
00642 return;
00643 }
00644
00645 unset($irs);
00646
00647
00648 $statements = array();
00649
00650 foreach($statementsUri as $uri)
00651 {
00652 $statements[$uri] = $resourceIndex[$uri];
00653 }
00654
00655 $this->db->query("DB.DBA.RDF_LOAD_RDFXML_MT('"
00656 . str_replace("'", "\'", $rdfxmlSerializer->getSerializedIndex($statements)) . "', '" . $this->dataset
00657 . "reification/', '" . $this->dataset . "reification/')");
00658
00659 if(odbc_error())
00660 {
00661 $this->conneg->setStatus(400);
00662 $this->conneg->setStatusMsg("Bad Request");
00663 $this->conneg->setError($this->errorMessenger->_302->id, $this->errorMessenger->ws,
00664 $this->errorMessenger->_302->name, $this->errorMessenger->_302->description, odbc_errormsg(),
00665 $this->errorMessenger->_302->level);
00666 return;
00667 }
00668
00669 unset($statements);
00670
00671
00672 if($datasetUri != "")
00673 {
00674 $datasetRes[$datasetUri] = $resourceIndex[$datasetUri];
00675
00676 $datasetRes[$this->dataset] =
00677 array( "http://purl.org/ontology/wsf#meta" => array( array ("value" => $datasetUri, "type" => "uri") ) );
00678
00679 $datasetDescription = $resourceIndex[$datasetRes];
00680
00681
00682 $this->db->query("DB.DBA.RDF_LOAD_RDFXML_MT('"
00683 . str_replace("'", "\'", $rdfxmlSerializer->getSerializedIndex($datasetRes)) . "', '" . $this->wsf_graph
00684 . "datasets/', '" . $this->wsf_graph . "datasets/')");
00685
00686 if(odbc_error())
00687 {
00688 $this->conneg->setStatus(400);
00689 $this->conneg->setStatusMsg("Bad Request");
00690 $this->conneg->setError($this->errorMessenger->_302->id, $this->errorMessenger->ws,
00691 $this->errorMessenger->_302->name, $this->errorMessenger->_302->description, "",
00692 $this->errorMessenger->_302->level);
00693 return;
00694 }
00695
00696 unset($datasetRes);
00697 }
00698 }
00699
00700 if($this->mode == "full" || $this->mode == "searchindex")
00701 {
00702 $labelProperties = array (Namespaces::$iron . "prefLabel", Namespaces::$iron . "altLabel",
00703 Namespaces::$skos_2008 . "prefLabel", Namespaces::$skos_2008 . "altLabel",
00704 Namespaces::$skos_2004 . "prefLabel", Namespaces::$skos_2004 . "altLabel", Namespaces::$rdfs . "label",
00705 Namespaces::$dcterms . "title", Namespaces::$foaf . "name", Namespaces::$foaf . "givenName",
00706 Namespaces::$foaf . "family_name");
00707
00708 $descriptionProperties = array (Namespaces::$iron . "description", Namespaces::$dcterms . "description",
00709 Namespaces::$skos_2008 . "definition", Namespaces::$skos_2004 . "definition");
00710
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736 $filename = rtrim($this->ontological_structure_folder, "/") . "/classHierarchySerialized.srz";
00737
00738 $file = fopen($filename, "r");
00739 $classHierarchy = fread($file, filesize($filename));
00740 $classHierarchy = unserialize($classHierarchy);
00741 fclose($file);
00742
00743
00744
00745 $solr = new Solr($this->wsf_solr_core, $this->solr_host);
00746
00747 foreach($irsUri as $subject)
00748 {
00749
00750
00751
00752
00753 if(stripos($subject, "_:arc") !== FALSE)
00754 {
00755 continue;
00756 }
00757
00758 $add = "<add><doc><field name=\"uid\">" . md5($this->dataset . $subject) . "</field>";
00759 $add .= "<field name=\"uri\">$subject</field>";
00760 $add .= "<field name=\"dataset\">" . $this->dataset . "</field>";
00761
00762
00763 $types = array();
00764
00765 foreach($resourceIndex[$subject]["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"] as $value)
00766 {
00767 array_push($types, $value["value"]);
00768
00769 $add .= "<field name=\"type\">" . $value["value"] . "</field>";
00770 }
00771
00772
00773 $prefLabelFound = FALSE;
00774
00775 foreach($labelProperties as $property)
00776 {
00777 if(isset($resourceIndex[$subject][$property]) && !$prefLabelFound)
00778 {
00779 $prefLabelFound = TRUE;
00780 $add .= "<field name=\"prefLabel\">" . $this->xmlEncode($resourceIndex[$subject][$property][0]["value"])
00781 . "</field>";
00782 $add .= "<field name=\"attribute\">" . $this->xmlEncode(Namespaces::$iron . "prefLabel") . "</field>";
00783 }
00784 elseif(isset($resourceIndex[$subject][$property]))
00785 {
00786 foreach($resourceIndex[$subject][$property] as $value)
00787 {
00788 $add .= "<field name=\"altLabel\">" . $this->xmlEncode($value["value"]) . "</field>";
00789 $add .= "<field name=\"attribute\">" . $this->xmlEncode(Namespaces::$iron . "altLabel") . "</field>";
00790 }
00791 }
00792 }
00793
00794
00795 foreach($descriptionProperties as $property)
00796 {
00797 if(isset($resourceIndex[$subject][$property]))
00798 {
00799 $add .= "<field name=\"description\">"
00800 . $this->xmlEncode($resourceIndex[$subject][$property][0]["value"]) . "</field>";
00801 $add .= "<field name=\"attribute\">" . $this->xmlEncode(Namespaces::$iron . "description") . "</field>";
00802 break;
00803 }
00804 }
00805
00806
00807 if(isset($resourceIndex[$subject][$iron . "prefURL"]))
00808 {
00809 $add .= "<field name=\"prefURL\">"
00810 . $this->xmlEncode($resourceIndex[$subject][$iron . "prefURL"][0]["value"]) . "</field>";
00811 $add .= "<field name=\"attribute\">" . $this->xmlEncode(Namespaces::$iron . "prefURL") . "</field>";
00812 }
00813
00814
00815 foreach($resourceIndex[$subject] as $predicate => $values)
00816 {
00817 if(array_search($predicate, $labelProperties) === FALSE
00818 && array_search($predicate, $descriptionProperties) === FALSE && $predicate != Namespaces::$iron
00819 . "prefURL")
00820 {
00821 foreach($values as $value)
00822 {
00823 if($value["type"] == "literal")
00824 {
00825 $add .= "<field name=\"" . urlencode($predicate) . "_attr\">" . $this->xmlEncode($value["value"])
00826 . "</field>";
00827 $add .= "<field name=\"attribute\">" . $this->xmlEncode($predicate) . "</field>";
00828
00829
00830
00831
00832 foreach($statementsUri as $statementUri)
00833 {
00834 if($resourceIndex[$statementUri]["http://www.w3.org/1999/02/22-rdf-syntax-ns#subject"][0]["value"]
00835 == $subject
00836 && $resourceIndex[$statementUri]["http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate"][0][
00837 "value"] == $predicate
00838 && $resourceIndex[$statementUri]["http://www.w3.org/1999/02/22-rdf-syntax-ns#object"][0][
00839 "value"] == $value["value"])
00840 {
00841 foreach($resourceIndex[$statementUri] as $reiPredicate => $reiValues)
00842 {
00843 if($reiPredicate != "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
00844 && $reiPredicate != "http://www.w3.org/1999/02/22-rdf-syntax-ns#subject"
00845 && $reiPredicate != "http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate"
00846 && $reiPredicate != "http://www.w3.org/1999/02/22-rdf-syntax-ns#object")
00847 {
00848 foreach($reiValues as $reiValue)
00849 {
00850 if($reiValue["type"] == "literal")
00851 {
00852
00853 $add .= "<field name=\"" . urlencode($reiPredicate) . "_reify_attr\">"
00854 . $this->xmlEncode($predicate) .
00855 "</field>";
00856
00857 $add .= "<field name=\"" . urlencode($reiPredicate) . "_reify_obj\">"
00858 . $this->xmlEncode($value["value"]) .
00859 "</field>";
00860
00861 $add .= "<field name=\"" . urlencode($reiPredicate) . "_reify_value\">"
00862 . $this->xmlEncode($reiValue["value"]) .
00863 "</field>";
00864
00865 $add .= "<field name=\"attribute\">" . $this->xmlEncode($reiPredicate) . "</field>";
00866 }
00867 }
00868 }
00869 }
00870 }
00871 }
00872 }
00873 elseif($value["type"] == "uri")
00874 {
00875
00876
00877
00878 $query = $this->db->build_sparql_query("select ?p ?o from <" . $this->dataset . "> where {<"
00879 . $value["value"] . "> ?p ?o.}", array ('p', 'o'), FALSE);
00880
00881 $resultset3 = $this->db->query($query);
00882
00883 $subjectTriples = array();
00884
00885 while(odbc_fetch_row($resultset3))
00886 {
00887 $p = odbc_result($resultset3, 1);
00888 $o = odbc_result($resultset3, 2);
00889
00890 if(!isset($subjectTriples[$p]))
00891 {
00892 $subjectTriples[$p] = array();
00893 }
00894
00895 array_push($subjectTriples[$p], $o);
00896 }
00897
00898 unset($resultset3);
00899
00900
00901 $labels = "";
00902
00903 foreach($labelProperties as $property)
00904 {
00905 if(isset($subjectTriples[$property]))
00906 {
00907 $labels .= $subjectTriples[$property][0] . " ";
00908 }
00909 }
00910
00911 if($labels != "")
00912 {
00913 $add .= "<field name=\"" . urlencode($predicate) . "_attr_obj\">" . $this->xmlEncode($labels)
00914 . "</field>";
00915 $add .= "<field name=\"" . urlencode($predicate) . "_attr_obj_uri\">"
00916 . $this->xmlEncode($value["value"]) . "</field>";
00917 $add .= "<field name=\"attribute\">" . $this->xmlEncode($predicate) . "</field>";
00918 }
00919
00920
00921
00922
00923 $statementAdded = FALSE;
00924
00925 foreach($statementsUri as $statementUri)
00926 {
00927 if($resourceIndex[$statementUri]["http://www.w3.org/1999/02/22-rdf-syntax-ns#subject"][0]["value"]
00928 == $subject
00929 && $resourceIndex[$statementUri]["http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate"][0][
00930 "value"] == $predicate
00931 && $resourceIndex[$statementUri]["http://www.w3.org/1999/02/22-rdf-syntax-ns#object"][0][
00932 "value"] == $value["value"])
00933 {
00934 foreach($resourceIndex[$statementUri] as $reiPredicate => $reiValues)
00935 {
00936 if($reiPredicate != "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
00937 && $reiPredicate != "http://www.w3.org/1999/02/22-rdf-syntax-ns#subject"
00938 && $reiPredicate != "http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate"
00939 && $reiPredicate != "http://www.w3.org/1999/02/22-rdf-syntax-ns#object")
00940 {
00941 foreach($reiValues as $reiValue)
00942 {
00943 if($reiValue["type"] == "literal")
00944 {
00945
00946 $add .= "<field name=\"" . urlencode($reiPredicate) . "_reify_attr_obj\">"
00947 . $this->xmlEncode($predicate) .
00948 "</field>";
00949
00950 $add .= "<field name=\"" . urlencode($reiPredicate) . "_reify_obj\">"
00951 . $this->xmlEncode($value["value"]) .
00952 "</field>";
00953
00954 $add .= "<field name=\"" . urlencode($reiPredicate) . "_reify_value\">"
00955 . $this->xmlEncode($reiValue["value"]) .
00956 "</field>";
00957
00958 $add .= "<field name=\"attribute\">" . $this->xmlEncode($reiPredicate) . "</field>";
00959 $statementAdded = TRUE;
00960 break;
00961 }
00962 }
00963 }
00964
00965 if($statementAdded)
00966 {
00967 break;
00968 }
00969 }
00970 }
00971 }
00972 }
00973 }
00974 }
00975 }
00976
00977
00978 foreach($types as $type)
00979 {
00980 $superClasses = $classHierarchy->getSuperClasses($type);
00981
00982 foreach($superClasses as $sc)
00983 {
00984 $add .= "<field name=\"inferred_type\">" . $this->xmlEncode($sc->name) . "</field>";
00985 }
00986 }
00987
00988 $add .= "</doc></add>";
00989
00990 if(!$solr->update($add))
00991 {
00992 $this->conneg->setStatus(500);
00993 $this->conneg->setStatusMsg("Internal Error");
00994 $this->conneg->setError($this->errorMessenger->_303->id, $this->errorMessenger->ws,
00995 $this->errorMessenger->_303->name, $this->errorMessenger->_303->description, "",
00996 $this->errorMessenger->_303->level);
00997 return;
00998 }
00999 }
01000
01001 if($this->solr_auto_commit === FALSE)
01002 {
01003 if(!$solr->commit())
01004 {
01005 $this->conneg->setStatus(500);
01006 $this->conneg->setStatusMsg("Internal Error");
01007 $this->conneg->setError($this->errorMessenger->_304->id, $this->errorMessenger->ws,
01008 $this->errorMessenger->_304->name, $this->errorMessenger->_304->description, "",
01009 $this->errorMessenger->_304->level);
01010 return;
01011 }
01012 }
01013 }
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024 }
01025 }
01026 }
01027 }
01028
01029
01031
01032 ?>