DatasetDelete.php
Go to the documentation of this file.
00001 <?php 00002 00005 00026 class DatasetDelete extends WebService 00027 { 00029 private $db; 00030 00032 private $conneg; 00033 00035 private $dtdURL; 00036 00038 private $registered_ip = ""; 00039 00041 private $datasetUri = ""; 00042 00044 public static $supportedSerializations = 00045 array ("application/json", "application/rdf+xml", "application/rdf+n3", "application/*", "text/xml", "text/*", 00046 "*/*"); 00047 00049 private $errorMessenger = 00050 '{ 00051 "ws": "/ws/dataset/delete/", 00052 "_200": { 00053 "id": "WS-DATASET-DELETE-200", 00054 "level": "Warning", 00055 "name": "No unique identifier specified for this dataset", 00056 "description": "No URI defined for this new dataset" 00057 }, 00058 "_300": { 00059 "id": "WS-DATASET-DELETE-300", 00060 "level": "Fatal", 00061 "name": "Can\'t delete meta-data information about the dataset", 00062 "description": "An error occured when we tried to remove any meta-information about this dataset in our system" 00063 }, 00064 "_301": { 00065 "id": "WS-DATASET-DELETE-301", 00066 "level": "Fatal", 00067 "name": "Can\'t unregister the dataset in the system", 00068 "description": "An error occured when we tried to delete the description of the dataset in the system" 00069 }, 00070 "_302": { 00071 "id": "WS-DATASET-DELETE-302", 00072 "level": "Fatal", 00073 "name": "Can\'t delete the graph in the triple store", 00074 "description": "An error occured when we tried to delete the graph in the triple store" 00075 }, 00076 "_303": { 00077 "id": "WS-DATASET-DELETE-303", 00078 "level": "Fatal", 00079 "name": "Can\'t delete the reification graph in the system", 00080 "description": "An error occured when we tried to delete the reification graph in the triple store" 00081 }, 00082 "_304": { 00083 "id": "WS-DATASET-DELETE-304", 00084 "level": "Fatal", 00085 "name": "Can\'t delete the dataset in Solr", 00086 "description": "An error occured when we tried to delete that dataset in Solr" 00087 }, 00088 "_305": { 00089 "id": "WS-DATASET-DELETE-305", 00090 "level": "Fatal", 00091 "name": "Can\'t commit changes to the Solr index", 00092 "description": "An error occured when we tried to commit changes to the Solr index" 00093 } 00094 }'; 00095 00096 00112 function __construct($uri, $registered_ip, $requester_ip) 00113 { 00114 parent::__construct(); 00115 00116 $this->db = new DB_Virtuoso($this->db_username, $this->db_password, $this->db_dsn, $this->db_host); 00117 00118 $this->datasetUri = $uri; 00119 00120 if($registered_ip == "") 00121 { 00122 $this->registered_ip = $requester_ip; 00123 } 00124 else 00125 { 00126 $this->registered_ip = $registered_ip; 00127 } 00128 00129 if(strtolower(substr($this->registered_ip, 0, 4)) == "self") 00130 { 00131 $pos = strpos($this->registered_ip, "::"); 00132 00133 if($pos !== FALSE) 00134 { 00135 $account = substr($this->registered_ip, $pos + 2, strlen($this->registered_ip) - ($pos + 2)); 00136 00137 $this->registered_ip = $requester_ip . "::" . $account; 00138 } 00139 else 00140 { 00141 $this->registered_ip = $requester_ip; 00142 } 00143 } 00144 00145 $this->uri = $this->wsf_base_url . "/wsf/ws/dataset/delete/"; 00146 $this->title = "Dataset Delete Web Service"; 00147 $this->crud_usage = new CrudUsage(FALSE, FALSE, FALSE, TRUE); 00148 $this->endpoint = $this->wsf_base_url . "/ws/dataset/delete/"; 00149 00150 $this->dtdURL = "dataset/datasetDelete.dtd"; 00151 00152 $this->errorMessenger = json_decode($this->errorMessenger); 00153 } 00154 00155 function __destruct() 00156 { 00157 parent::__destruct(); 00158 00159 if(isset($this->db)) 00160 { 00161 @$this->db->close(); 00162 } 00163 } 00164 00186 protected function validateQuery() 00187 { 00188 // Check if the requester has access to the main "http://.../wsf/datasets/" graph. 00189 $ws_av = new AuthValidator($this->registered_ip, $this->wsf_graph . "datasets/", $this->uri); 00190 00191 $ws_av->pipeline_conneg($this->conneg->getAccept(), $this->conneg->getAcceptCharset(), 00192 $this->conneg->getAcceptEncoding(), $this->conneg->getAcceptLanguage()); 00193 00194 $ws_av->process(); 00195 00196 if($ws_av->pipeline_getResponseHeaderStatus() != 200) 00197 { 00198 // If he doesn't, then check if he has access to the dataset itself 00199 $ws_av2 = new AuthValidator($this->requester_ip, $this->datasetUri, $this->uri); 00200 00201 $ws_av2->pipeline_conneg($this->conneg->getAccept(), $this->conneg->getAcceptCharset(), 00202 $this->conneg->getAcceptEncoding(), $this->conneg->getAcceptLanguage()); 00203 00204 $ws_av2->process(); 00205 00206 if($ws_av2->pipeline_getResponseHeaderStatus() != 200) 00207 { 00208 $this->conneg->setStatus($ws_av2->pipeline_getResponseHeaderStatus()); 00209 $this->conneg->setStatusMsg($ws_av2->pipeline_getResponseHeaderStatusMsg()); 00210 $this->conneg->setStatusMsgExt($ws_av2->pipeline_getResponseHeaderStatusMsgExt()); 00211 $this->conneg->setError($ws_av2->pipeline_getError()->id, $ws_av2->pipeline_getError()->webservice, 00212 $ws_av2->pipeline_getError()->name, $ws_av2->pipeline_getError()->description, 00213 $ws_av2->pipeline_getError()->debugInfo, $ws_av2->pipeline_getError()->level); 00214 00215 return; 00216 } 00217 } 00218 00219 // If the system send a query on the behalf of another user, we validate that other user as well 00220 if($this->registered_ip != $this->requester_ip) 00221 { 00222 // Check if the requester has access to the main "http://.../wsf/datasets/" graph. 00223 $ws_av = new AuthValidator($this->registered_ip, $this->wsf_graph . "datasets/", $this->uri); 00224 00225 $ws_av->pipeline_conneg($this->conneg->getAccept(), $this->conneg->getAcceptCharset(), 00226 $this->conneg->getAcceptEncoding(), $this->conneg->getAcceptLanguage()); 00227 00228 $ws_av->process(); 00229 00230 if($ws_av->pipeline_getResponseHeaderStatus() != 200) 00231 { 00232 // If he doesn't, then check if he has access to the dataset itself 00233 $ws_av2 = new AuthValidator($this->registered_ip, $this->datasetUri, $this->uri); 00234 00235 $ws_av2->pipeline_conneg($this->conneg->getAccept(), $this->conneg->getAcceptCharset(), 00236 $this->conneg->getAcceptEncoding(), $this->conneg->getAcceptLanguage()); 00237 00238 $ws_av2->process(); 00239 00240 if($ws_av2->pipeline_getResponseHeaderStatus() != 200) 00241 { 00242 $this->conneg->setStatus($ws_av2->pipeline_getResponseHeaderStatus()); 00243 $this->conneg->setStatusMsg($ws_av2->pipeline_getResponseHeaderStatusMsg()); 00244 $this->conneg->setStatusMsgExt($ws_av2->pipeline_getResponseHeaderStatusMsgExt()); 00245 $this->conneg->setError($ws_av2->pipeline_getError()->id, $ws_av2->pipeline_getError()->webservice, 00246 $ws_av2->pipeline_getError()->name, $ws_av2->pipeline_getError()->description, 00247 $ws_av2->pipeline_getError()->debugInfo, $ws_av2->pipeline_getError()->level); 00248 00249 return; 00250 } 00251 } 00252 } 00253 } 00254 00265 public function pipeline_getError() { return ($this->conneg->error); } 00266 00267 00278 public function pipeline_getResultset() { return ""; } 00279 00292 public function injectDoctype($xmlDoc) { return ""; } 00293 00312 public function ws_conneg($accept, $accept_charset, $accept_encoding, $accept_language) 00313 { 00314 $this->conneg = 00315 new Conneg($accept, $accept_charset, $accept_encoding, $accept_language, DatasetDelete::$supportedSerializations); 00316 00317 // Validate query 00318 $this->validateQuery(); 00319 00320 // If the query is still valid 00321 if($this->conneg->getStatus() == 200) 00322 { 00323 // Check for errors 00324 if($this->datasetUri == "") 00325 { 00326 $this->conneg->setStatus(400); 00327 $this->conneg->setStatusMsg("Bad Request"); 00328 $this->conneg->setStatusMsgExt($this->errorMessenger->_200->name); 00329 $this->conneg->setError($this->errorMessenger->_200->id, $this->errorMessenger->ws, 00330 $this->errorMessenger->_200->name, $this->errorMessenger->_200->description, "", 00331 $this->errorMessenger->_200->level); 00332 00333 return; 00334 } 00335 } 00336 } 00337 00356 public function pipeline_conneg($accept, $accept_charset, $accept_encoding, $accept_language) 00357 { $this->ws_conneg($accept, $accept_charset, $accept_encoding, $accept_language); } 00358 00369 public function pipeline_getResponseHeaderStatus() { return $this->conneg->getStatus(); } 00370 00381 public function pipeline_getResponseHeaderStatusMsg() { return $this->conneg->getStatusMsg(); } 00382 00395 public function pipeline_getResponseHeaderStatusMsgExt() { return $this->conneg->getStatusMsgExt(); } 00396 00407 public function pipeline_serialize() { return ""; } 00408 00417 public function pipeline_serialize_reification() { return ""; } 00418 00429 public function ws_serialize() { return ""; } 00430 00443 public function ws_respond($content) 00444 { 00445 // First send the header of the request 00446 $this->conneg->respond(); 00447 00448 // second, send the content of the request 00449 00450 // Make sure there is no error. 00451 if($this->conneg->getStatus() == 200) 00452 { 00453 echo $content; 00454 } 00455 00456 $this->__destruct(); 00457 } 00458 00459 00468 public function process() 00469 { 00470 // Make sure there was no conneg error prior to this process call 00471 if($this->conneg->getStatus() == 200) 00472 { 00473 // Remove all the possible other meta descriptions 00474 // of the dataset introduced by the wsf:meta property. 00475 00476 $query = " delete from <" . $this->wsf_graph . "datasets/> 00477 { 00478 ?meta ?p_meta ?o_meta. 00479 } 00480 where 00481 { 00482 graph <" 00483 . $this->wsf_graph 00484 . "datasets/> 00485 { 00486 <$this->datasetUri> <http://purl.org/ontology/wsf#meta> ?meta. 00487 ?meta ?p_meta ?o_meta. 00488 } 00489 }"; 00490 00491 @$this->db->query($this->db->build_sparql_query(str_replace(array ("\n", "\r", "\t"), " ", $query), array(), 00492 FALSE)); 00493 00494 if(odbc_error()) 00495 { 00496 $this->conneg->setStatus(500); 00497 $this->conneg->setStatusMsg("Internal Error"); 00498 $this->conneg->setStatusMsgExt($this->errorMessenger->_300->name); 00499 $this->conneg->setError($this->errorMessenger->_300->id, $this->errorMessenger->ws, 00500 $this->errorMessenger->_300->name, $this->errorMessenger->_300->description, odbc_errormsg(), 00501 $this->errorMessenger->_300->level); 00502 00503 return; 00504 } 00505 00506 00507 // Remove the Graph description in the ".../datasets/" 00508 00509 $query = " delete from <" . $this->wsf_graph . "datasets/> 00510 { 00511 <$this->datasetUri> ?p ?o. 00512 } 00513 where 00514 { 00515 graph <" . $this->wsf_graph . "datasets/> 00516 { 00517 <$this->datasetUri> ?p ?o. 00518 } 00519 }"; 00520 00521 @$this->db->query($this->db->build_sparql_query(str_replace(array ("\n", "\r", "\t"), " ", $query), array(), 00522 FALSE)); 00523 00524 if(odbc_error()) 00525 { 00526 $this->conneg->setStatus(500); 00527 $this->conneg->setStatusMsg("Internal Error"); 00528 $this->conneg->setStatusMsgExt($this->errorMessenger->_301->name); 00529 $this->conneg->setError($this->errorMessenger->_301->id, $this->errorMessenger->ws, 00530 $this->errorMessenger->_301->name, $this->errorMessenger->_301->description, odbc_errormsg(), 00531 $this->errorMessenger->_301->level); 00532 return; 00533 } 00534 00535 // Removing all accesses for this graph 00536 $ws_ara = new AuthRegistrarAccess("", "", $this->datasetUri, "delete_all", "", "", $this->registered_ip); 00537 00538 $ws_ara->pipeline_conneg($this->conneg->getAccept(), $this->conneg->getAcceptCharset(), 00539 $this->conneg->getAcceptEncoding(), $this->conneg->getAcceptLanguage()); 00540 00541 $ws_ara->process(); 00542 00543 if($ws_ara->pipeline_getResponseHeaderStatus() != 200) 00544 { 00545 $this->conneg->setStatus($ws_ara->pipeline_getResponseHeaderStatus()); 00546 $this->conneg->setStatusMsg($ws_ara->pipeline_getResponseHeaderStatusMsg()); 00547 $this->conneg->setStatusMsgExt($ws_ara->pipeline_getResponseHeaderStatusMsgExt()); 00548 $this->conneg->setError($ws_ara->pipeline_getError()->id, $ws_ara->pipeline_getError()->webservice, 00549 $ws_ara->pipeline_getError()->name, $ws_ara->pipeline_getError()->description, 00550 $ws_ara->pipeline_getError()->debugInfo, $ws_ara->pipeline_getError()->level); 00551 return; 00552 } 00553 00554 // Drop the entire graph 00555 $query = "exst('select * from (sparql clear graph <" . $this->datasetUri . ">) sub')"; 00556 00557 @$this->db->query($query); 00558 00559 if(odbc_error()) 00560 { 00561 $this->conneg->setStatus(500); 00562 $this->conneg->setStatusMsg("Internal Error"); 00563 $this->conneg->setStatusMsgExt($this->errorMessenger->_302->name); 00564 $this->conneg->setError($this->errorMessenger->_302->id, $this->errorMessenger->ws, 00565 $this->errorMessenger->_302->name, $this->errorMessenger->_302->description, odbc_errormsg(), 00566 $this->errorMessenger->_302->level); 00567 00568 return; 00569 } 00570 00571 // Drop the reification graph related to this dataset 00572 $query = "exst('select * from (sparql clear graph <" . $this->datasetUri . "reification/>) sub')"; 00573 00574 @$this->db->query($query); 00575 00576 if(odbc_error()) 00577 { 00578 $this->conneg->setStatus(500); 00579 $this->conneg->setStatusMsg("Internal Error"); 00580 $this->conneg->setStatusMsgExt("Error #dataset-delete-105"); 00581 $this->conneg->setError($this->errorMessenger->_303->id, $this->errorMessenger->ws, 00582 $this->errorMessenger->_303->name, $this->errorMessenger->_303->description, odbc_errormsg(), 00583 $this->errorMessenger->_303->level); 00584 00585 return; 00586 } 00587 00588 00589 // Remove all documents from the solr index for this Dataset 00590 $solr = new Solr($this->wsf_solr_core, $this->solr_host, $this->solr_port); 00591 00592 if(!$solr->flushDataset($this->datasetUri)) 00593 { 00594 $this->conneg->setStatus(500); 00595 $this->conneg->setStatusMsg("Internal Error"); 00596 $this->conneg->setStatusMsgExt($this->errorMessenger->_304->name); 00597 $this->conneg->setError($this->errorMessenger->_304->id, $this->errorMessenger->ws, 00598 $this->errorMessenger->_304->name, $this->errorMessenger->_304->description, odbc_errormsg(), 00599 $this->errorMessenger->_304->level); 00600 00601 return; 00602 } 00603 00604 if($this->solr_auto_commit === FALSE) 00605 { 00606 if(!$solr->commit()) 00607 { 00608 $this->conneg->setStatus(500); 00609 $this->conneg->setStatusMsg("Internal Error"); 00610 $this->conneg->setStatusMsgExt($this->errorMessenger->_305->name); 00611 $this->conneg->setError($this->errorMessenger->_305->id, $this->errorMessenger->ws, 00612 $this->errorMessenger->_305->name, $this->errorMessenger->_305->description, odbc_errormsg(), 00613 $this->errorMessenger->_305->level); 00614 00615 return; 00616 } 00617 } 00618 00619 00620 /* 00621 if(!$solr->optimize()) 00622 { 00623 $this->conneg->setStatus(500); 00624 $this->conneg->setStatusMsg("Internal Error"); 00625 $this->conneg->setStatusMsgExt("Error #dataset-delete-104"); 00626 return; 00627 } 00628 */ 00629 } 00630 } 00631 } 00632 00634 00635 ?>
