00001 <?php
00002
00005
00026 class CrudUpdate 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/update/",
00061 "_200": {
00062 "id": "WS-CRUD-UPDATE-200",
00063 "level": "Warning",
00064 "name": "No RDF document to index",
00065 "description": "No RDF document defined for this query"
00066 },
00067 "_201": {
00068 "id": "WS-CRUD-UPDATE-201",
00069 "level": "Warning",
00070 "name": "Unknown MIME type for this RDF document",
00071 "description": "Unknown MIME type defined for the target RDF document for this query"
00072 },
00073 "_202": {
00074 "id": "WS-CRUD-UPDATE-202",
00075 "level": "Warning",
00076 "name": "No dataset specified",
00077 "description": "No dataset URI has been defined for this query"
00078 },
00079 "_300": {
00080 "id": "WS-CRUD-UPDATE-300",
00081 "level": "Warning",
00082 "name": "Syntax error in the RDF document",
00083 "description": "A syntax error has been detected in the RDF document"
00084 },
00085 "_301": {
00086 "id": "WS-CRUD-UPDATE-301",
00087 "level": "Fatal",
00088 "name": "Can\'t update the record(s) in the triple store",
00089 "description": "An error occured when we tried to update the record(s) in the triple store"
00090 },
00091 "_302": {
00092 "id": "WS-CRUD-UPDATE-302",
00093 "level": "Fatal",
00094 "name": "Can\'t list the record(s) that have to be updated",
00095 "description": "An error occured when we tried to list all the record(s) that have to be updated"
00096 },
00097 "_303": {
00098 "id": "WS-CRUD-UPDATE-303",
00099 "level": "Fatal",
00100 "name": "Can\'t delete the temporary update graph",
00101 "description": "An error occured when we tried to delete the temporary update graph"
00102 },
00103 "_304": {
00104 "id": "WS-CRUD-UPDATE-304",
00105 "level": "Fatal",
00106 "name": "Can\'t update the Solr index",
00107 "description": "An error occured when we tried to update the Solr index"
00108 },
00109 "_305": {
00110 "id": "WS-CRUD-UPDATE-305",
00111 "level": "Fatal",
00112 "name": "Can\'t commit changes to the Solr index",
00113 "description": "An error occured when we tried to commit changes to the Solr index"
00114 },
00115 "_306": {
00116 "id": "WS-CRUD-CREATE-306",
00117 "level": "Fatal",
00118 "name": "Can\'t create data",
00119 "description": "Can\'t create data of the specified format"
00120 },
00121 "_307": {
00122 "id": "WS-CRUD-CREATE-307",
00123 "level": "Warning",
00124 "name": "Can\'t parse RDF document",
00125 "description": "Can\'t parse the specified RDF document"
00126 }
00127 }';
00128
00129
00141 function __construct($document, $mime, $dataset, $registered_ip, $requester_ip)
00142 {
00143 parent::__construct();
00144
00145 $this->db = new DB_Virtuoso($this->db_username, $this->db_password, $this->db_dsn, $this->db_host);
00146
00147 $this->registered_ip = $registered_ip;
00148 $this->requester_ip = $requester_ip;
00149 $this->dataset = $dataset;
00150 $this->document = $document;
00151 $this->mime = $mime;
00152
00153 if($this->registered_ip == "")
00154 {
00155 $this->registered_ip = $requester_ip;
00156 }
00157
00158 if(strtolower(substr($this->registered_ip, 0, 4)) == "self")
00159 {
00160 $pos = strpos($this->registered_ip, "::");
00161
00162 if($pos !== FALSE)
00163 {
00164 $account = substr($this->registered_ip, $pos + 2, strlen($this->registered_ip) - ($pos + 2));
00165
00166 $this->registered_ip = $requester_ip . "::" . $account;
00167 }
00168 else
00169 {
00170 $this->registered_ip = $requester_ip;
00171 }
00172 }
00173
00174 $this->uri = $this->wsf_base_url . "/wsf/ws/crud/update/";
00175 $this->title = "Crud Update Web Service";
00176 $this->crud_usage = new CrudUsage(TRUE, FALSE, FALSE, FALSE);
00177 $this->endpoint = $this->wsf_base_url . "/ws/crud/update/";
00178
00179 $this->dtdURL = "auth/CrudUpdate.dtd";
00180
00181 $this->errorMessenger = json_decode($this->errorMessenger);
00182 }
00183
00184 function __destruct()
00185 {
00186 parent::__destruct();
00187
00188 if(isset($this->db))
00189 {
00190 @$this->db->close();
00191 }
00192 }
00193
00204 protected function validateQuery()
00205 {
00206
00207 $ws_av = new AuthValidator($this->requester_ip, $this->dataset, $this->uri);
00208
00209 $ws_av->pipeline_conneg($this->conneg->getAccept(), $this->conneg->getAcceptCharset(),
00210 $this->conneg->getAcceptEncoding(), $this->conneg->getAcceptLanguage());
00211
00212 $ws_av->process();
00213
00214 if($ws_av->pipeline_getResponseHeaderStatus() != 200)
00215 {
00216 $this->conneg->setStatus($ws_av->pipeline_getResponseHeaderStatus());
00217 $this->conneg->setStatusMsg($ws_av->pipeline_getResponseHeaderStatusMsg());
00218 $this->conneg->setStatusMsgExt($ws_av->pipeline_getResponseHeaderStatusMsgExt());
00219 $this->conneg->setError($ws_av->pipeline_getError()->id, $ws_av->pipeline_getError()->webservice,
00220 $ws_av->pipeline_getError()->name, $ws_av->pipeline_getError()->description,
00221 $ws_av->pipeline_getError()->debugInfo, $ws_av->pipeline_getError()->level);
00222
00223 return;
00224 }
00225
00226 unset($ws_av);
00227
00228
00229 $ws_av = new AuthValidator($this->registered_ip, $this->dataset, $this->uri);
00230
00231 $ws_av->pipeline_conneg($this->conneg->getAccept(), $this->conneg->getAcceptCharset(),
00232 $this->conneg->getAcceptEncoding(), $this->conneg->getAcceptLanguage());
00233
00234 $ws_av->process();
00235
00236 if($ws_av->pipeline_getResponseHeaderStatus() != 200)
00237 {
00238 $this->conneg->setStatus($ws_av->pipeline_getResponseHeaderStatus());
00239 $this->conneg->setStatusMsg($ws_av->pipeline_getResponseHeaderStatusMsg());
00240 $this->conneg->setStatusMsgExt($ws_av->pipeline_getResponseHeaderStatusMsgExt());
00241 $this->conneg->setError($ws_av->pipeline_getError()->id, $ws_av->pipeline_getError()->webservice,
00242 $ws_av->pipeline_getError()->name, $ws_av->pipeline_getError()->description,
00243 $ws_av->pipeline_getError()->debugInfo, $ws_av->pipeline_getError()->level);
00244 return;
00245 }
00246 }
00247
00258 public function pipeline_getError() { return ($this->conneg->error); }
00259
00260
00271 public function pipeline_getResultset() { return ""; }
00272
00285 public function injectDoctype($xmlDoc)
00286 {
00287 $posHeader = strpos($xmlDoc, '"?>') + 3;
00288 $xmlDoc = substr($xmlDoc, 0, $posHeader)
00289 . "\n<!DOCTYPE resultset PUBLIC \"-//Structured Dynamics LLC//Crud Update DTD 0.1//EN\" \"" . $this->dtdBaseURL
00290 . $this->dtdURL . "\">" . substr($xmlDoc, $posHeader, strlen($xmlDoc) - $posHeader);
00291
00292 return ($xmlDoc);
00293 }
00294
00313 public function ws_conneg($accept, $accept_charset, $accept_encoding, $accept_language)
00314 {
00315 $this->conneg =
00316 new Conneg($accept, $accept_charset, $accept_encoding, $accept_language, CrudUpdate::$supportedSerializations);
00317
00318
00319
00320 if($this->document == "")
00321 {
00322 $this->conneg->setStatus(400);
00323 $this->conneg->setStatusMsg("Bad Request");
00324 $this->conneg->setStatusMsgExt($this->errorMessenger->_200->name);
00325 $this->conneg->setError($this->errorMessenger->_200->id, $this->errorMessenger->ws,
00326 $this->errorMessenger->_200->name, $this->errorMessenger->_200->description, "",
00327 $this->errorMessenger->_200->level);
00328
00329 return;
00330 }
00331
00332 if($this->mime != "application/rdf+xml" && $this->mime != "application/rdf+n3")
00333 {
00334 $this->conneg->setStatus(400);
00335 $this->conneg->setStatusMsg("Bad Request");
00336 $this->conneg->setStatusMsgExt($this->errorMessenger->_201->name);
00337 $this->conneg->setError($this->errorMessenger->_201->id, $this->errorMessenger->ws,
00338 $this->errorMessenger->_201->name, $this->errorMessenger->_201->description, "",
00339 $this->errorMessenger->_201->level);
00340
00341 return;
00342 }
00343
00344 if($this->dataset == "")
00345 {
00346 $this->conneg->setStatus(400);
00347 $this->conneg->setStatusMsg("Bad Request");
00348 $this->conneg->setStatusMsgExt($this->errorMessenger->_202->name);
00349 $this->conneg->setError($this->errorMessenger->_202->id, $this->errorMessenger->ws,
00350 $this->errorMessenger->_202->name, $this->errorMessenger->_202->description, "",
00351 $this->errorMessenger->_202->level);
00352 return;
00353 }
00354
00355
00356
00357 $ws_dr = new DatasetRead($this->dataset, "false", "self",
00358 $this->wsf_local_ip);
00359
00360
00361 $ws_dr->pipeline_conneg($this->conneg->getAccept(), $this->conneg->getAcceptCharset(),
00362 $this->conneg->getAcceptEncoding(), $this->conneg->getAcceptLanguage());
00363
00364 $ws_dr->process();
00365
00366 if($ws_dr->pipeline_getResponseHeaderStatus() != 200)
00367 {
00368 $this->conneg->setStatus($ws_dr->pipeline_getResponseHeaderStatus());
00369 $this->conneg->setStatusMsg($ws_dr->pipeline_getResponseHeaderStatusMsg());
00370 $this->conneg->setStatusMsgExt($ws_dr->pipeline_getResponseHeaderStatusMsgExt());
00371 $this->conneg->setError($ws_dr->pipeline_getError()->id, $ws_dr->pipeline_getError()->webservice,
00372 $ws_dr->pipeline_getError()->name, $ws_dr->pipeline_getError()->description,
00373 $ws_dr->pipeline_getError()->debugInfo, $ws_dr->pipeline_getError()->level);
00374 return;
00375 }
00376 }
00377
00396 public function pipeline_conneg($accept, $accept_charset, $accept_encoding, $accept_language)
00397 { $this->ws_conneg($accept, $accept_charset, $accept_encoding, $accept_language); }
00398
00409 public function pipeline_getResponseHeaderStatus() { return $this->conneg->getStatus(); }
00410
00421 public function pipeline_getResponseHeaderStatusMsg() { return $this->conneg->getStatusMsg(); }
00422
00435 public function pipeline_getResponseHeaderStatusMsgExt() { return $this->conneg->getStatusMsgExt(); }
00436
00447 public function pipeline_serialize() { return ""; }
00448
00457 public function pipeline_serialize_reification() { return ""; }
00458
00469 public function ws_serialize() { return ""; }
00470
00483 public function ws_respond($content)
00484 {
00485
00486 $this->conneg->respond();
00487
00488
00489
00490
00491 if($this->conneg->getStatus() == 200)
00492 {
00493 echo $content;
00494 }
00495
00496 $this->__destruct();
00497 }
00498
00499
00508 public function process()
00509 {
00510
00511 if($this->conneg->getStatus() == 200)
00512 {
00513 $this->validateQuery();
00514
00515
00516 if($this->conneg->getStatus() == 200)
00517 {
00518
00519 if($this->mime != "application/rdf+xml" && $this->mime != "application/rdf+n3")
00520 {
00521 $this->conneg->setStatus(400);
00522 $this->conneg->setStatusMsg("Bad Request");
00523 $this->conneg->setStatusMsgExt($this->errorMessenger->_306->name);
00524 $this->conneg->setError($this->errorMessenger->_306->id, $this->errorMessenger->ws,
00525 $this->errorMessenger->_306->name, $this->errorMessenger->_306->description,
00526 "Can't create data of format: " . $this->mime, $this->errorMessenger->_306->level);
00527
00528 return;
00529 }
00530
00531
00532 $parser = ARC2::getRDFParser();
00533 $parser->parse($this->dataset, $this->document);
00534 $rdfxmlSerializer = ARC2::getRDFXMLSerializer();
00535
00536 $resourceIndex = $parser->getSimpleIndex(0);
00537
00538 if(count($parser->getErrors()) > 0)
00539 {
00540 $this->conneg->setStatus(400);
00541 $this->conneg->setStatusMsg("Bad Request");
00542 $this->conneg->setError($this->errorMessenger->_307->id, $this->errorMessenger->ws,
00543 $this->errorMessenger->_307->name, $this->errorMessenger->_307->description, "",
00544 $this->errorMessenger->_307->level);
00545
00546 return;
00547 }
00548
00549
00550 $break = FALSE;
00551 $statementsUri = array();
00552
00553 foreach($resourceIndex as $resource => $description)
00554 {
00555 foreach($description as $predicate => $values)
00556 {
00557 if($predicate == "http://www.w3.org/1999/02/22-rdf-syntax-ns#type")
00558 {
00559 foreach($values as $value)
00560 {
00561 if($value["type"] == "uri" && $value["value"] == "http://www.w3.org/1999/02/22-rdf-syntax-ns#Statement")
00562 {
00563 array_push($statementsUri, $resource);
00564 break;
00565 }
00566 }
00567 }
00568
00569 if($break)
00570 {
00571 break;
00572 }
00573 }
00574
00575 if($break)
00576 {
00577 break;
00578 }
00579 }
00580
00581
00582 $irsUri = array();
00583
00584 foreach($resourceIndex as $resource => $description)
00585 {
00586 if($resource != $datasetUri && array_search($resource, $statementsUri) === FALSE)
00587 {
00588 array_push($irsUri, $resource);
00589 }
00590 }
00591
00592
00593 $tempGraphUri = "temp-graph-" . md5($this->document);
00594
00595 $irs = array();
00596
00597 foreach($irsUri as $uri)
00598 {
00599 $irs[$uri] = $resourceIndex[$uri];
00600 }
00601
00602 @$this->db->query("DB.DBA.RDF_LOAD_RDFXML_MT('"
00603 . str_replace("'", "\'", $rdfxmlSerializer->getSerializedIndex($irs))
00604 . "', '$tempGraphUri', '$tempGraphUri', 0)");
00605
00606 if(odbc_error())
00607 {
00608 $this->conneg->setStatus(400);
00609 $this->conneg->setStatusMsg("Bad Request");
00610 $this->conneg->setStatusMsgExt($this->errorMessenger->_300->name);
00611 $this->conneg->setError($this->errorMessenger->_300->id, $this->errorMessenger->ws,
00612 $this->errorMessenger->_300->name, $this->errorMessenger->_300->description, odbc_errormsg(),
00613 $this->errorMessenger->_300->level);
00614 return;
00615 }
00616
00617
00618 $query = "delete from <" . $this->dataset . ">
00619 {
00620 ?s ?p_original ?o_original.
00621 }
00622 where
00623 {
00624 graph <" . $tempGraphUri . ">
00625 {
00626 ?s ?p ?o.
00627 }
00628
00629 graph <" . $this->dataset . ">
00630 {
00631 ?s ?p_original ?o_original.
00632 }
00633 }
00634
00635 insert into <" . $this->dataset . ">
00636 {
00637 ?s ?p ?o.
00638 }
00639 where
00640 {
00641 graph <" . $tempGraphUri . ">
00642 {
00643 ?s ?p ?o.
00644 }
00645 }";
00646
00647 @$this->db->query($this->db->build_sparql_query(str_replace(array ("\n", "\r", "\t"), " ", $query), array(),
00648 FALSE));
00649
00650 if(odbc_error())
00651 {
00652 $this->conneg->setStatus(500);
00653 $this->conneg->setStatusMsg("Internal Error");
00654 $this->conneg->setStatusMsgExt($this->errorMessenger->_301->name);
00655 $this->conneg->setError($this->errorMessenger->_301->id, $this->errorMessenger->ws,
00656 $this->errorMessenger->_301->name, $this->errorMessenger->_301->description, odbc_errormsg(),
00657 $this->errorMessenger->_301->level);
00658
00659 return;
00660 }
00661
00662 if(count($statementsUri) > 0)
00663 {
00664 $tempGraphReificationUri = "temp-graph-reification-" . md5($this->document);
00665
00666 $statements = array();
00667
00668 foreach($statementsUri as $uri)
00669 {
00670 $statements[$uri] = $resourceIndex[$uri];
00671 }
00672
00673 @$this->db->query("DB.DBA.RDF_LOAD_RDFXML_MT('"
00674 . str_replace("'", "\'", $rdfxmlSerializer->getSerializedIndex($statements))
00675 . "', '$tempGraphReificationUri', '$tempGraphReificationUri', 0)");
00676
00677 if(odbc_error())
00678 {
00679 $this->conneg->setStatus(400);
00680 $this->conneg->setStatusMsg("Bad Request");
00681 $this->conneg->setStatusMsgExt($this->errorMessenger->_300->name);
00682 $this->conneg->setError($this->errorMessenger->_300->id, $this->errorMessenger->ws,
00683 $this->errorMessenger->_300->name, $this->errorMessenger->_300->description, odbc_errormsg(),
00684 $this->errorMessenger->_300->level);
00685 return;
00686 }
00687
00688
00689
00690 $query = "delete from <" . $this->dataset . "reification/>
00691 {
00692 ?s_original ?p_original ?o_original.
00693 }
00694 where
00695 {
00696 graph <" . $tempGraphReificationUri . ">
00697 {
00698 ?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#subject> ?rei_subject .
00699 ?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate> ?rei_predicate .
00700 ?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#object> ?rei_object .
00701
00702 ?s ?p ?o.
00703 }
00704
00705 graph <" . $this->dataset . "reification/>
00706 {
00707 ?s_original <http://www.w3.org/1999/02/22-rdf-syntax-ns#subject> ?rei_subject .
00708 ?s_original <http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate> ?rei_predicate .
00709 ?s_original <http://www.w3.org/1999/02/22-rdf-syntax-ns#object> ?rei_object .
00710
00711 ?s_original ?p_original ?o_original.
00712 }
00713 }
00714
00715 insert into <" . $this->dataset . "reification/>
00716 {
00717 ?s_original ?p2 ?o2.
00718 }
00719 where
00720 {
00721 graph <" . $tempGraphReificationUri . ">
00722 {
00723 ?s_original ?p2 ?o2.
00724 }
00725 }";
00726
00727 @$this->db->query($this->db->build_sparql_query(str_replace(array ("\n", "\r", "\t"), " ", $query), array(),
00728 FALSE));
00729
00730 if(odbc_error())
00731 {
00732 $this->conneg->setStatus(500);
00733 $this->conneg->setStatusMsg("Internal Error");
00734 $this->conneg->setStatusMsgExt($this->errorMessenger->_301->name);
00735 $this->conneg->setError($this->errorMessenger->_301->id, $this->errorMessenger->ws,
00736 $this->errorMessenger->_301->name, $this->errorMessenger->_301->description, odbc_errormsg(),
00737 $this->errorMessenger->_301->level);
00738
00739 return;
00740 }
00741
00742
00743 $query = "clear graph <" . $tempGraphReificationUri . ">";
00744
00745 @$this->db->query($this->db->build_sparql_query(str_replace(array ("\n", "\r", "\t"), "", $query), array(),
00746 FALSE));
00747
00748 if(odbc_error())
00749 {
00750 $this->conneg->setStatus(500);
00751 $this->conneg->setStatusMsg("Internal Error");
00752 $this->conneg->setStatusMsgExt($this->errorMessenger->_303->name);
00753 $this->conneg->setError($this->errorMessenger->_303->id, $this->errorMessenger->ws,
00754 $this->errorMessenger->_303->name, $this->errorMessenger->_303->description,
00755 odbc_errormsg() . " -- Query: [" . str_replace(array ("\n", "\r", "\t"), " ", $query) . "]",
00756 $this->errorMessenger->_303->level);
00757 return;
00758 }
00759 }
00760
00761
00762 $query = "clear graph <" . $tempGraphUri . ">";
00763
00764 @$this->db->query($this->db->build_sparql_query(str_replace(array ("\n", "\r", "\t"), "", $query), array(),
00765 FALSE));
00766
00767 if(odbc_error())
00768 {
00769 $this->conneg->setStatus(500);
00770 $this->conneg->setStatusMsg("Internal Error");
00771 $this->conneg->setStatusMsgExt($this->errorMessenger->_303->name);
00772 $this->conneg->setError($this->errorMessenger->_303->id, $this->errorMessenger->ws,
00773 $this->errorMessenger->_303->name, $this->errorMessenger->_303->description,
00774 odbc_errormsg() . " -- Query: [" . str_replace(array ("\n", "\r", "\t"), " ", $query) . "]",
00775 $this->errorMessenger->_303->level);
00776 return;
00777 }
00778
00779
00780
00781
00782
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808 $filename = rtrim($this->ontological_structure_folder, "/") . "/classHierarchySerialized.srz";
00809 $file = fopen($filename, "r");
00810 $classHierarchy = fread($file, filesize($filename));
00811 $classHierarchy = unserialize($classHierarchy);
00812 fclose($file);
00813
00814 $labelProperties =
00815 array (Namespaces::$iron . "prefLabel", Namespaces::$iron . "altLabel", Namespaces::$skos_2008 . "prefLabel",
00816 Namespaces::$skos_2008 . "altLabel", Namespaces::$skos_2004 . "prefLabel",
00817 Namespaces::$skos_2004 . "altLabel", Namespaces::$rdfs . "label", Namespaces::$dcterms . "title",
00818 Namespaces::$foaf . "name", Namespaces::$foaf . "givenName", Namespaces::$foaf . "family_name");
00819
00820 $descriptionProperties = array (Namespaces::$iron . "description", Namespaces::$dcterms . "description",
00821 Namespaces::$skos_2008 . "definition", Namespaces::$skos_2004 . "definition");
00822
00823
00824
00825
00826 $solr = new Solr($this->wsf_solr_core, $this->solr_host);
00827
00828 foreach($irsUri as $subject)
00829 {
00830
00831
00832
00833
00834 if(stripos($subject, "_:arc") !== FALSE)
00835 {
00836 continue;
00837 }
00838
00839 $add = "<add><doc><field name=\"uid\">" . md5($this->dataset . $subject) . "</field>";
00840 $add .= "<field name=\"uri\">$subject</field>";
00841 $add .= "<field name=\"dataset\">" . $this->dataset . "</field>";
00842
00843
00844 $types = array();
00845
00846 foreach($resourceIndex[$subject]["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"] as $value)
00847 {
00848 array_push($types, $value["value"]);
00849
00850 $add .= "<field name=\"type\">" . $value["value"] . "</field>";
00851 }
00852
00853
00854 $prefLabelFound = FALSE;
00855
00856 foreach($labelProperties as $property)
00857 {
00858 if(isset($resourceIndex[$subject][$property]) && !$prefLabelFound)
00859 {
00860 $prefLabelFound = TRUE;
00861 $add .= "<field name=\"prefLabel\">" . $this->xmlEncode($resourceIndex[$subject][$property][0]["value"])
00862 . "</field>";
00863 $add .= "<field name=\"attribute\">" . $this->xmlEncode(Namespaces::$iron . "prefLabel") . "</field>";
00864 }
00865 elseif(isset($resourceIndex[$subject][$property]))
00866 {
00867 foreach($resourceIndex[$subject][$property] as $value)
00868 {
00869 $add .= "<field name=\"altLabel\">" . $this->xmlEncode($value["value"]) . "</field>";
00870 $add .= "<field name=\"attribute\">" . $this->xmlEncode(Namespaces::$iron . "altLabel") . "</field>";
00871 }
00872 }
00873 }
00874
00875
00876 foreach($descriptionProperties as $property)
00877 {
00878 if(isset($resourceIndex[$subject][$property]))
00879 {
00880 $add .= "<field name=\"description\">" . $this->xmlEncode($resourceIndex[$subject][$property][0]["value"])
00881 . "</field>";
00882 $add .= "<field name=\"attribute\">" . $this->xmlEncode(Namespaces::$iron . "description") . "</field>";
00883 break;
00884 }
00885 }
00886
00887
00888 if(isset($resourceIndex[$subject][$iron . "prefURL"]))
00889 {
00890 $add .= "<field name=\"prefURL\">"
00891 . $this->xmlEncode($resourceIndex[$subject][$iron . "prefURL"][0]["value"]) . "</field>";
00892 $add .= "<field name=\"attribute\">" . $this->xmlEncode(Namespaces::$iron . "prefURL") . "</field>";
00893 }
00894
00895
00896 foreach($resourceIndex[$subject] as $predicate => $values)
00897 {
00898 if(array_search($predicate, $labelProperties) === FALSE
00899 && array_search($predicate, $descriptionProperties) === FALSE && $predicate != Namespaces::$iron
00900 . "prefURL")
00901 {
00902 foreach($values as $value)
00903 {
00904 if($value["type"] == "literal")
00905 {
00906 $add .= "<field name=\"" . urlencode($predicate) . "_attr\">" . $this->xmlEncode($value["value"])
00907 . "</field>";
00908 $add .= "<field name=\"attribute\">" . $this->xmlEncode($predicate) . "</field>";
00909
00910
00911
00912
00913 foreach($statementsUri as $statementUri)
00914 {
00915 if($resourceIndex[$statementUri]["http://www.w3.org/1999/02/22-rdf-syntax-ns#subject"][0]["value"]
00916 == $subject
00917 && $resourceIndex[$statementUri]["http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate"][0][
00918 "value"] == $predicate &&
00919 $resourceIndex[$statementUri]["http://www.w3.org/1999/02/22-rdf-syntax-ns#object"][0]["value"]
00920 == $value["value"])
00921 {
00922 foreach($resourceIndex[$statementUri] as $reiPredicate => $reiValues)
00923 {
00924 if($reiPredicate != "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
00925 && $reiPredicate != "http://www.w3.org/1999/02/22-rdf-syntax-ns#subject"
00926 && $reiPredicate != "http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate"
00927 && $reiPredicate != "http://www.w3.org/1999/02/22-rdf-syntax-ns#object")
00928 {
00929 foreach($reiValues as $reiValue)
00930 {
00931 if($reiValue["type"] == "literal")
00932 {
00933
00934 $add .= "<field name=\"" . urlencode($reiPredicate) . "_reify_attr\">"
00935 . $this->xmlEncode($predicate) .
00936 "</field>";
00937
00938 $add .= "<field name=\"" . urlencode($reiPredicate) . "_reify_obj\">"
00939 . $this->xmlEncode($value["value"]) .
00940 "</field>";
00941
00942 $add .= "<field name=\"" . urlencode($reiPredicate) . "_reify_value\">"
00943 . $this->xmlEncode($reiValue["value"]) .
00944 "</field>";
00945
00946 $add .= "<field name=\"attribute\">" . $this->xmlEncode($reiPredicate) . "</field>";
00947 }
00948 }
00949 }
00950 }
00951 }
00952 }
00953 }
00954 elseif($value["type"] == "uri")
00955 {
00956 $query = $this->db->build_sparql_query("select ?p ?o from <" . $this->dataset . "> where {<"
00957 . $value["value"] . "> ?p ?o.}", array ('p', 'o'), FALSE);
00958
00959 $resultset3 = $this->db->query($query);
00960
00961 $subjectTriples = array();
00962
00963 while(odbc_fetch_row($resultset3))
00964 {
00965 $p = odbc_result($resultset3, 1);
00966 $o = odbc_result($resultset3, 2);
00967
00968 if(!isset($subjectTriples[$p]))
00969 {
00970 $subjectTriples[$p] = array();
00971 }
00972
00973 array_push($subjectTriples[$p], $o);
00974 }
00975
00976 unset($resultset3);
00977
00978 $labels = "";
00979
00980 foreach($labelProperties as $property)
00981 {
00982 if(isset($subjectTriples[$property]))
00983 {
00984 $labels .= $subjectTriples[$property][0] . " ";
00985 }
00986 }
00987
00988 if($labels != "")
00989 {
00990 $add .= "<field name=\"" . urlencode($predicate) . "_attr_obj\">" . $this->xmlEncode($labels)
00991 . "</field>";
00992 $add .= "<field name=\"" . urlencode($predicate) . "_attr_obj_uri\">"
00993 . $this->xmlEncode($value["value"]) . "</field>";
00994 $add .= "<field name=\"attribute\">" . $this->xmlEncode($predicate) . "</field>";
00995 }
00996
00997
00998
00999
01000 $statementAdded = FALSE;
01001
01002 foreach($statementsUri as $statementUri)
01003 {
01004 if($resourceIndex[$statementUri]["http://www.w3.org/1999/02/22-rdf-syntax-ns#subject"][0]["value"]
01005 == $subject
01006 && $resourceIndex[$statementUri]["http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate"][0][
01007 "value"] == $predicate &&
01008 $resourceIndex[$statementUri]["http://www.w3.org/1999/02/22-rdf-syntax-ns#object"][0]["value"]
01009 == $value["value"])
01010 {
01011 foreach($resourceIndex[$statementUri] as $reiPredicate => $reiValues)
01012 {
01013 if($reiPredicate != "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
01014 && $reiPredicate != "http://www.w3.org/1999/02/22-rdf-syntax-ns#subject"
01015 && $reiPredicate != "http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate"
01016 && $reiPredicate != "http://www.w3.org/1999/02/22-rdf-syntax-ns#object")
01017 {
01018 foreach($reiValues as $reiValue)
01019 {
01020 if($reiValue["type"] == "literal")
01021 {
01022
01023 $add .= "<field name=\"" . urlencode($reiPredicate) . "_reify_attr_obj\">"
01024 . $this->xmlEncode($predicate) .
01025 "</field>";
01026
01027 $add .= "<field name=\"" . urlencode($reiPredicate) . "_reify_obj\">"
01028 . $this->xmlEncode($value["value"]) .
01029 "</field>";
01030
01031 $add .= "<field name=\"" . urlencode($reiPredicate) . "_reify_value\">"
01032 . $this->xmlEncode($reiValue["value"]) .
01033 "</field>";
01034
01035 $add .= "<field name=\"attribute\">" . $this->xmlEncode($reiPredicate) . "</field>";
01036 $statementAdded = TRUE;
01037 break;
01038 }
01039 }
01040 }
01041
01042 if($statementAdded)
01043 {
01044 break;
01045 }
01046 }
01047 }
01048 }
01049 }
01050 }
01051 }
01052 }
01053
01054
01055 foreach($types as $type)
01056 {
01057 $superClasses = $classHierarchy->getSuperClasses($type);
01058
01059 foreach($superClasses as $sc)
01060 {
01061 $add .= "<field name=\"inferred_type\">" . $this->xmlEncode($sc->name) . "</field>";
01062 }
01063 }
01064
01065 $add .= "</doc></add>";
01066
01067 if(!$solr->update($add))
01068 {
01069 $this->conneg->setStatus(500);
01070 $this->conneg->setStatusMsg("Internal Error");
01071 $this->conneg->setError($this->errorMessenger->_304->id, $this->errorMessenger->ws,
01072 $this->errorMessenger->_304->name, $this->errorMessenger->_304->description, "",
01073 $this->errorMessenger->_304->level);
01074 return;
01075 }
01076 }
01077
01078 if($this->solr_auto_commit === FALSE)
01079 {
01080 if(!$solr->commit())
01081 {
01082 $this->conneg->setStatus(500);
01083 $this->conneg->setStatusMsg("Internal Error");
01084 $this->conneg->setStatusMsgExt($this->errorMessenger->_305->name);
01085 $this->conneg->setError($this->errorMessenger->_305->id, $this->errorMessenger->ws,
01086 $this->errorMessenger->_305->name, $this->errorMessenger->_305->description, "",
01087 $this->errorMessenger->_305->level);
01088 return;
01089 }
01090 }
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101 }
01102 }
01103 }
01104 }
01105
01107
01108 ?>