00001 <?php
00002
00005
00027 class CrudDelete extends WebService
00028 {
00030 private $db;
00031
00033 private $conneg;
00034
00036 private $dtdURL;
00037
00039 public static $supportedSerializations =
00040 array ("application/json", "application/rdf+xml", "application/rdf+n3", "application/*", "text/xml", "text/*",
00041 "*/*");
00042
00044 private $registered_ip = "";
00045
00047 private $dataset;
00048
00050 private $resourceUri;
00051
00053 private $requester_ip = "";
00054
00056 private $errorMessenger =
00057 '{
00058 "ws": "/ws/crud/delete/",
00059 "_200": {
00060 "id": "WS-CRUD-DELETE-200",
00061 "level": "Warning",
00062 "name": "No resource URI to delete specified",
00063 "description": "No resource URI has been defined for this query"
00064 },
00065 "_201": {
00066 "id": "WS-CRUD-DELETE-201",
00067 "level": "Warning",
00068 "name": "No dataset specified",
00069 "description": "No dataset URI defined for this query"
00070 },
00071 "_300": {
00072 "id": "WS-CRUD-DELETE-300",
00073 "level": "Fatal",
00074 "name": "Can\'t delete the record in the triple store",
00075 "description": "An error occured when we tried to delete that record in the triple store"
00076 },
00077 "_301": {
00078 "id": "WS-CRUD-DELETE-301",
00079 "level": "Fatal",
00080 "name": "Can\'t delete the record in Solr",
00081 "description": "An error occured when we tried to delete that record in Solr"
00082 },
00083 "_302": {
00084 "id": "WS-CRUD-DELETE-302",
00085 "level": "Fatal",
00086 "name": "Can\'t commit changes to the Solr index",
00087 "description": "An error occured when we tried to commit changes to the Solr index"
00088 }
00089 }';
00090
00091
00108 function __construct($uri, $dataset, $registered_ip, $requester_ip)
00109 {
00110 parent::__construct();
00111
00112 $this->db = new DB_Virtuoso($this->db_username, $this->db_password, $this->db_dsn, $this->db_host);
00113
00114 $this->registered_ip = $registered_ip;
00115 $this->requester_ip = $requester_ip;
00116 $this->dataset = $dataset;
00117 $this->resourceUri = $uri;
00118
00119 if($this->registered_ip == "")
00120 {
00121 $this->registered_ip = $requester_ip;
00122 }
00123
00124 if(strtolower(substr($this->registered_ip, 0, 4)) == "self")
00125 {
00126 $pos = strpos($this->registered_ip, "::");
00127
00128 if($pos !== FALSE)
00129 {
00130 $account = substr($this->registered_ip, $pos + 2, strlen($this->registered_ip) - ($pos + 2));
00131
00132 $this->registered_ip = $requester_ip . "::" . $account;
00133 }
00134 else
00135 {
00136 $this->registered_ip = $requester_ip;
00137 }
00138 }
00139
00140 $this->uri = $this->wsf_base_url . "/wsf/ws/crud/delete/";
00141 $this->title = "Crud Delete Web Service";
00142 $this->crud_usage = new CrudUsage(FALSE, FALSE, FALSE, TRUE);
00143 $this->endpoint = $this->wsf_base_url . "/ws/crud/delete/";
00144
00145 $this->dtdURL = "auth/CrudDelete.dtd";
00146
00147 $this->errorMessenger = json_decode($this->errorMessenger);
00148 }
00149
00150 function __destruct()
00151 {
00152 parent::__destruct();
00153
00154 if(isset($this->db))
00155 {
00156 @$this->db->close();
00157 }
00158 }
00159
00170 protected function validateQuery()
00171 {
00172
00173 $ws_av = new AuthValidator($this->requester_ip, $this->dataset, $this->uri);
00174
00175 $ws_av->pipeline_conneg($this->conneg->getAccept(), $this->conneg->getAcceptCharset(),
00176 $this->conneg->getAcceptEncoding(), $this->conneg->getAcceptLanguage());
00177
00178 $ws_av->process();
00179
00180 if($ws_av->pipeline_getResponseHeaderStatus() != 200)
00181 {
00182 $this->conneg->setStatus($ws_av->pipeline_getResponseHeaderStatus());
00183 $this->conneg->setStatusMsg($ws_av->pipeline_getResponseHeaderStatusMsg());
00184 $this->conneg->setStatusMsgExt($ws_av->pipeline_getResponseHeaderStatusMsgExt());
00185 $this->conneg->setError($ws_av->pipeline_getError()->id, $ws_av->pipeline_getError()->webservice,
00186 $ws_av->pipeline_getError()->name, $ws_av->pipeline_getError()->description,
00187 $ws_av->pipeline_getError()->debugInfo, $ws_av->pipeline_getError()->level);
00188
00189 return;
00190 }
00191
00192 unset($ws_av);
00193
00194
00195 $ws_av = new AuthValidator($this->registered_ip, $this->dataset, $this->uri);
00196
00197 $ws_av->pipeline_conneg($this->conneg->getAccept(), $this->conneg->getAcceptCharset(),
00198 $this->conneg->getAcceptEncoding(), $this->conneg->getAcceptLanguage());
00199
00200 $ws_av->process();
00201
00202 if($ws_av->pipeline_getResponseHeaderStatus() != 200)
00203 {
00204 $this->conneg->setStatus($ws_av->pipeline_getResponseHeaderStatus());
00205 $this->conneg->setStatusMsg($ws_av->pipeline_getResponseHeaderStatusMsg());
00206 $this->conneg->setStatusMsgExt($ws_av->pipeline_getResponseHeaderStatusMsgExt());
00207 $this->conneg->setError($ws_av->pipeline_getError()->id, $ws_av->pipeline_getError()->webservice,
00208 $ws_av->pipeline_getError()->name, $ws_av->pipeline_getError()->description,
00209 $ws_av->pipeline_getError()->debugInfo, $ws_av->pipeline_getError()->level);
00210 return;
00211 }
00212 }
00213
00224 public function pipeline_getError() { return ($this->conneg->error); }
00225
00226
00237 public function pipeline_getResultset() { return ""; }
00238
00251 public function injectDoctype($xmlDoc)
00252 {
00253 $posHeader = strpos($xmlDoc, '"?>') + 3;
00254 $xmlDoc = substr($xmlDoc, 0, $posHeader)
00255 . "\n<!DOCTYPE resultset PUBLIC \"-//Structured Dynamics LLC//Crud Delete DTD 0.1//EN\" \"" . $this->dtdBaseURL
00256 . $this->dtdURL . "\">" . substr($xmlDoc, $posHeader, strlen($xmlDoc) - $posHeader);
00257
00258 return ($xmlDoc);
00259 }
00260
00279 public function ws_conneg($accept, $accept_charset, $accept_encoding, $accept_language)
00280 {
00281 $this->conneg =
00282 new Conneg($accept, $accept_charset, $accept_encoding, $accept_language, CrudDelete::$supportedSerializations);
00283
00284
00285
00286 if($this->uri == "")
00287 {
00288 $this->conneg->setStatus(400);
00289 $this->conneg->setStatusMsg("Bad Request");
00290 $this->conneg->setStatusMsgExt($this->errorMessenger->_200->name);
00291 $this->conneg->setError($this->errorMessenger->_200->id, $this->errorMessenger->ws,
00292 $this->errorMessenger->_200->name, $this->errorMessenger->_200->description, "",
00293 $this->errorMessenger->_200->level);
00294
00295 return;
00296 }
00297
00298 if($this->dataset == "")
00299 {
00300 $this->conneg->setStatus(400);
00301 $this->conneg->setStatusMsg("Bad Request");
00302 $this->conneg->setStatusMsgExt($this->errorMessenger->_201->name);
00303 $this->conneg->setError($this->errorMessenger->_201->id, $this->errorMessenger->ws,
00304 $this->errorMessenger->_201->name, $this->errorMessenger->_201->description, "",
00305 $this->errorMessenger->_201->level);
00306
00307 return;
00308 }
00309
00310
00311
00312 $ws_dr = new DatasetRead($this->dataset, "false", "self",
00313 $this->wsf_local_ip);
00314
00315 $ws_dr->pipeline_conneg($this->conneg->getAccept(), $this->conneg->getAcceptCharset(),
00316 $this->conneg->getAcceptEncoding(), $this->conneg->getAcceptLanguage());
00317
00318 $ws_dr->process();
00319
00320 if($ws_dr->pipeline_getResponseHeaderStatus() != 200)
00321 {
00322 $this->conneg->setStatus($ws_dr->pipeline_getResponseHeaderStatus());
00323 $this->conneg->setStatusMsg($ws_dr->pipeline_getResponseHeaderStatusMsg());
00324 $this->conneg->setStatusMsgExt($ws_dr->pipeline_getResponseHeaderStatusMsgExt());
00325 $this->conneg->setError($ws_av->pipeline_getError()->id, $ws_av->pipeline_getError()->webservice,
00326 $ws_av->pipeline_getError()->name, $ws_av->pipeline_getError()->description,
00327 $ws_av->pipeline_getError()->debugInfo, $ws_av->pipeline_getError()->level);
00328
00329 return;
00330 }
00331 }
00332
00351 public function pipeline_conneg($accept, $accept_charset, $accept_encoding, $accept_language)
00352 { $this->ws_conneg($accept, $accept_charset, $accept_encoding, $accept_language); }
00353
00364 public function pipeline_getResponseHeaderStatus() { return $this->conneg->getStatus(); }
00365
00376 public function pipeline_getResponseHeaderStatusMsg() { return $this->conneg->getStatusMsg(); }
00377
00390 public function pipeline_getResponseHeaderStatusMsgExt() { return $this->conneg->getStatusMsgExt(); }
00391
00402 public function pipeline_serialize() { return ""; }
00403
00412 public function pipeline_serialize_reification() { return ""; }
00413
00424 public function ws_serialize() { return ""; }
00425
00438 public function ws_respond($content)
00439 {
00440
00441 $this->conneg->respond();
00442
00443
00444
00445
00446 if($this->conneg->getStatus() == 200)
00447 {
00448 echo $content;
00449 }
00450
00451 $this->__destruct();
00452 }
00453
00454
00463 public function process()
00464 {
00465
00466 if($this->conneg->getStatus() == 200)
00467 {
00468 $this->validateQuery();
00469
00470
00471 if($this->conneg->getStatus() == 200)
00472 {
00473
00474 $query = "delete from <" . $this->dataset . ">
00475 {
00476 <" . $this->resourceUri . "> ?p ?o.
00477 }
00478 where
00479 {
00480 <" . $this->resourceUri . "> ?p ?o.
00481 }";
00482
00483 @$this->db->query($this->db->build_sparql_query(str_replace(array ("\n", "\r", "\t"), " ", $query), array(),
00484 FALSE));
00485
00486 if(odbc_error())
00487 {
00488 $this->conneg->setStatus(500);
00489 $this->conneg->setStatusMsg("Internal Error");
00490 $this->conneg->setStatusMsgExt($this->errorMessenger->_300->name);
00491 $this->conneg->setError($this->errorMessenger->_300->id, $this->errorMessenger->ws,
00492 $this->errorMessenger->_300->name, $this->errorMessenger->_300->description, odbc_errormsg(),
00493 $this->errorMessenger->_300->level);
00494
00495 return;
00496 }
00497
00498
00499 $solr = new Solr($this->wsf_solr_core, $this->solr_host);
00500
00501 if(!$solr->deleteInstanceRecord($this->resourceUri, $this->dataset))
00502 {
00503 $this->conneg->setStatus(500);
00504 $this->conneg->setStatusMsg("Internal Error");
00505 $this->conneg->setStatusMsgExt($this->errorMessenger->_301->name);
00506 $this->conneg->setError($this->errorMessenger->_301->id, $this->errorMessenger->ws,
00507 $this->errorMessenger->_301->name, $this->errorMessenger->_301->description, odbc_errormsg(),
00508 $this->errorMessenger->_301->level);
00509
00510 return;
00511 }
00512
00513 if($this->solr_auto_commit === FALSE)
00514 {
00515 if(!$solr->commit())
00516 {
00517 $this->conneg->setStatus(500);
00518 $this->conneg->setStatusMsg("Internal Error");
00519 $this->conneg->setStatusMsgExt($this->errorMessenger->_302->name);
00520 $this->conneg->setError($this->errorMessenger->_302->id, $this->errorMessenger->ws,
00521 $this->errorMessenger->_302->name, $this->errorMessenger->_302->description, odbc_errormsg(),
00522 $this->errorMessenger->_302->level);
00523
00524 return;
00525 }
00526 }
00527 }
00528 }
00529 }
00530 }
00531
00533
00534 ?>