TrackerCreate.php
Go to the documentation of this file.
00001 <?php 00002 00005 00026 class TrackerCreate extends WebService 00027 { 00029 private $db; 00030 00032 private $conneg; 00033 00035 private $dtdURL; 00036 00038 public static $supportedSerializations = array ("text/xml", "text/*", "*/*"); 00039 00041 private $registered_ip = ""; 00042 00044 private $fromDataset = ""; 00045 00047 private $record = ""; 00048 00050 private $action = ""; 00051 00054 private $previousState = ""; 00055 00058 private $previousStateMime = ""; 00059 00061 private $performer = ""; 00062 00064 private $requester_ip = ""; 00065 00067 private $errorMessenger = 00068 '{ 00069 "ws": "/ws/tracker/create/", 00070 "_200": { 00071 "id": "WS-TRACKER-CREATE-200", 00072 "level": "Fatal", 00073 "name": "No dataset provenance defined.", 00074 "description": "The provenance of the record as to be specified." 00075 }, 00076 "_201": { 00077 "id": "WS-TRACKER-CREATE-201", 00078 "level": "Fatal", 00079 "name": "State serialization mime not supported.", 00080 "description": "Only the application/rdf+xml and application/rdf+n3 mime types are supported by the tracker." 00081 }, 00082 "_202": { 00083 "id": "WS-TRACKER-CREATE-202", 00084 "level": "Fatal", 00085 "name": "No record defined", 00086 "description": "No changed record has been defined for this query." 00087 }, 00088 "_203": { 00089 "id": "WS-TRACKER-CREATE-203", 00090 "level": "Fatal", 00091 "name": "No performer defined.", 00092 "description": "The performer of the action needs to be defined." 00093 }, 00094 "_204": { 00095 "id": "WS-TRACKER-CREATE-204", 00096 "level": "Fatal", 00097 "name": "Unsupported action", 00098 "description": "Only the actions \'delete\', \'create\' and \'update\' are supported by the tracker" 00099 } 00100 }'; 00101 00102 00125 function __construct($fromDataset, $record, $action, $previousState, $previousStateMime, $performer, $registered_ip, $requester_ip) 00126 { 00127 parent::__construct(); 00128 00129 $this->db = new DB_Virtuoso($this->db_username, $this->db_password, $this->db_dsn, $this->db_host); 00130 00131 $this->requester_ip = $requester_ip; 00132 00133 $this->fromDataset = $fromDataset; 00134 $this->record = $record; 00135 $this->action = $action; 00136 // $this->previousState = urlencode(gzencode($previousState)); 00137 $this->previousState = base64_encode(gzencode($previousState)); 00138 $this->previousStateMime = $previousStateMime; 00139 $this->performer = $performer; 00140 00141 if($registered_ip == "") 00142 { 00143 $this->registered_ip = $requester_ip; 00144 } 00145 else 00146 { 00147 $this->registered_ip = $registered_ip; 00148 } 00149 00150 if(strtolower(substr($this->registered_ip, 0, 4)) == "self") 00151 { 00152 $pos = strpos($this->registered_ip, "::"); 00153 00154 if($pos !== FALSE) 00155 { 00156 $account = substr($this->registered_ip, $pos + 2, strlen($this->registered_ip) - ($pos + 2)); 00157 00158 $this->registered_ip = $requester_ip . "::" . $account; 00159 } 00160 else 00161 { 00162 $this->registered_ip = $requester_ip; 00163 } 00164 } 00165 00166 $this->uri = $this->wsf_base_url . "/wsf/ws/tracker/create/"; 00167 $this->title = "Tracker Create Web Service"; 00168 $this->crud_usage = new CrudUsage(TRUE, FALSE, FALSE, FALSE); 00169 $this->endpoint = $this->wsf_base_url . "/ws/tracker/create/"; 00170 00171 $this->dtdURL = "auth/TrackerCreate.dtd"; 00172 00173 $this->errorMessenger = json_decode($this->errorMessenger); 00174 } 00175 00176 function __destruct() 00177 { 00178 parent::__destruct(); 00179 00180 if(isset($this->db)) 00181 { 00182 @$this->db->close(); 00183 } 00184 } 00185 00196 protected function validateQuery() 00197 { 00198 // Validation of the "requester_ip" to make sure the system that is sending the query as the rights. 00199 $ws_av = new AuthValidator($this->requester_ip, $this->wsf_graph."track/", $this->uri); 00200 00201 $ws_av->pipeline_conneg($this->conneg->getAccept(), $this->conneg->getAcceptCharset(), 00202 $this->conneg->getAcceptEncoding(), $this->conneg->getAcceptLanguage()); 00203 00204 $ws_av->process(); 00205 00206 if($ws_av->pipeline_getResponseHeaderStatus() != 200) 00207 { 00208 $this->conneg->setStatus($ws_av->pipeline_getResponseHeaderStatus()); 00209 $this->conneg->setStatusMsg($ws_av->pipeline_getResponseHeaderStatusMsg()); 00210 $this->conneg->setStatusMsgExt($ws_av->pipeline_getResponseHeaderStatusMsgExt()); 00211 $this->conneg->setError($ws_av->pipeline_getError()->id, $ws_av->pipeline_getError()->webservice, 00212 $ws_av->pipeline_getError()->name, $ws_av->pipeline_getError()->description, 00213 $ws_av->pipeline_getError()->debugInfo, $ws_av->pipeline_getError()->level); 00214 00215 return; 00216 } 00217 00218 unset($ws_av); 00219 00220 // If the system send a query on the behalf of another user, we validate that other user as well 00221 if($this->registered_ip != $this->requester_ip) 00222 { 00223 // Validation of the "registered_ip" to make sure the user of this system has the rights 00224 $ws_av = new AuthValidator($this->registered_ip, $this->wsf_graph."track/", $this->uri); 00225 00226 $ws_av->pipeline_conneg($this->conneg->getAccept(), $this->conneg->getAcceptCharset(), 00227 $this->conneg->getAcceptEncoding(), $this->conneg->getAcceptLanguage()); 00228 00229 $ws_av->process(); 00230 00231 if($ws_av->pipeline_getResponseHeaderStatus() != 200) 00232 { 00233 $this->conneg->setStatus($ws_av->pipeline_getResponseHeaderStatus()); 00234 $this->conneg->setStatusMsg($ws_av->pipeline_getResponseHeaderStatusMsg()); 00235 $this->conneg->setStatusMsgExt($ws_av->pipeline_getResponseHeaderStatusMsgExt()); 00236 $this->conneg->setError($ws_av->pipeline_getError()->id, $ws_av->pipeline_getError()->webservice, 00237 $ws_av->pipeline_getError()->name, $ws_av->pipeline_getError()->description, 00238 $ws_av->pipeline_getError()->debugInfo, $ws_av->pipeline_getError()->level); 00239 return; 00240 } 00241 } 00242 } 00243 00254 public function pipeline_getError() { return ($this->conneg->error); } 00255 00256 00267 public function pipeline_getResultset() { return ""; } 00268 00281 public function injectDoctype($xmlDoc) 00282 { 00283 $posHeader = strpos($xmlDoc, '"?>') + 3; 00284 $xmlDoc = substr($xmlDoc, 0, $posHeader) 00285 . "\n<!DOCTYPE resultset PUBLIC \"-//Structured Dynamics LLC//Tracker Create DTD 0.1//EN\" \"" . $this->dtdBaseURL 00286 . $this->dtdURL . "\">" . substr($xmlDoc, $posHeader, strlen($xmlDoc) - $posHeader); 00287 00288 return ($xmlDoc); 00289 } 00290 00309 public function ws_conneg($accept, $accept_charset, $accept_encoding, $accept_language) 00310 { 00311 $this->conneg = 00312 new Conneg($accept, $accept_charset, $accept_encoding, $accept_language, TrackerCreate::$supportedSerializations); 00313 00314 // Check for errors 00315 if($this->fromDataset == "") 00316 { 00317 $this->conneg->setStatus(400); 00318 $this->conneg->setStatusMsg("Bad Request"); 00319 $this->conneg->setStatusMsgExt($this->errorMessenger->_200->name); 00320 $this->conneg->setError($this->errorMessenger->_200->id, $this->errorMessenger->ws, 00321 $this->errorMessenger->_200->name, $this->errorMessenger->_200->description, "", 00322 $this->errorMessenger->_200->level); 00323 return; 00324 } 00325 00326 if($this->previousStateMime != "application/rdf+xml" && $this->previousStateMime != "application/rdf+n3") 00327 { 00328 $this->conneg->setStatus(400); 00329 $this->conneg->setStatusMsg("Bad Request"); 00330 $this->conneg->setStatusMsgExt($this->errorMessenger->_201->name); 00331 $this->conneg->setError($this->errorMessenger->_201->id, $this->errorMessenger->ws, 00332 $this->errorMessenger->_201->name, $this->errorMessenger->_201->description, ($this->mime), 00333 $this->errorMessenger->_201->level); 00334 return; 00335 } 00336 00337 if($this->record == "") 00338 { 00339 $this->conneg->setStatus(400); 00340 $this->conneg->setStatusMsg("Bad Request"); 00341 $this->conneg->setStatusMsgExt($this->errorMessenger->_202->name); 00342 $this->conneg->setError($this->errorMessenger->_202->id, $this->errorMessenger->ws, 00343 $this->errorMessenger->_202->name, $this->errorMessenger->_202->description, "", 00344 $this->errorMessenger->_202->level); 00345 return; 00346 } 00347 00348 if($this->performer == "") 00349 { 00350 $this->conneg->setStatus(400); 00351 $this->conneg->setStatusMsg("Bad Request"); 00352 $this->conneg->setStatusMsgExt($this->errorMessenger->_203->name); 00353 $this->conneg->setError($this->errorMessenger->_203->id, $this->errorMessenger->ws, 00354 $this->errorMessenger->_203->name, $this->errorMessenger->_203->description, "", 00355 $this->errorMessenger->_203->level); 00356 return; 00357 } 00358 00359 if($this->action != "delete" && $this->action != "update" && $this->action != "create") 00360 { 00361 $this->conneg->setStatus(400); 00362 $this->conneg->setStatusMsg("Bad Request"); 00363 $this->conneg->setStatusMsgExt($this->errorMessenger->_204->name); 00364 $this->conneg->setError($this->errorMessenger->_204->id, $this->errorMessenger->ws, 00365 $this->errorMessenger->_204->name, $this->errorMessenger->_204->description, "", 00366 $this->errorMessenger->_204->level); 00367 return; 00368 } 00369 } 00370 00389 public function pipeline_conneg($accept, $accept_charset, $accept_encoding, $accept_language) 00390 { $this->ws_conneg($accept, $accept_charset, $accept_encoding, $accept_language); } 00391 00402 public function pipeline_getResponseHeaderStatus() { return $this->conneg->getStatus(); } 00403 00414 public function pipeline_getResponseHeaderStatusMsg() { return $this->conneg->getStatusMsg(); } 00415 00428 public function pipeline_getResponseHeaderStatusMsgExt() { return $this->conneg->getStatusMsgExt(); } 00429 00440 public function pipeline_serialize() { return ""; } 00441 00450 public function pipeline_serialize_reification() { return ""; } 00451 00462 public function ws_serialize() { return ""; } 00463 00476 public function ws_respond($content) 00477 { 00478 // First send the header of the request 00479 $this->conneg->respond(); 00480 00481 // second, send the content of the request 00482 00483 // Make sure there is no error. 00484 if($this->conneg->getStatus() == 200) 00485 { 00486 echo $content; 00487 } 00488 00489 $this->__destruct(); 00490 } 00491 00492 00501 public function process() 00502 { 00503 // Make sure there was no conneg error prior to this process call 00504 if($this->conneg->getStatus() == 200) 00505 { 00506 $this->validateQuery(); 00507 00508 // If the query is still valid 00509 if($this->conneg->getStatus() == 200) 00510 { 00511 $dateTime = date("c"); 00512 00513 /* 00514 Ordered changes for a record using sparql and this part of the WSF ontology. 00515 00516 sparql select * from <http://.../wsf/track/> where 00517 { 00518 ?s <http://purl.org/ontology/wsf#record> <http://.../wsf/datasets/67/resource/Welfare> . 00519 00520 ?s <http://purl.org/ontology/wsf#changeTime> ?time. 00521 } 00522 ORDER BY asc(xsd:dateTime(?time)); 00523 */ 00524 00525 $trackRecord = "<".$this->wsf_graph."track/record/".md5($dateTime.$this->record.$this->fromDataset)."> 00526 a <http://purl.org/ontology/wsf#ChangeState> ;"; 00527 00528 $trackRecord .= "<http://purl.org/ontology/wsf#record> <".$this->record."> ;"; 00529 $trackRecord .= "<http://purl.org/ontology/wsf#fromDataset> <".$this->fromDataset."> ;"; 00530 $trackRecord .= "<http://purl.org/ontology/wsf#changeTime> \"".$dateTime."\"^^xsd:dateTime ;"; 00531 $trackRecord .= "<http://purl.org/ontology/wsf#action> \"".$this->action."\" ;"; 00532 $trackRecord .= "<http://purl.org/ontology/wsf#previousState> \"\"\"".$this->previousState."\"\"\" ;"; 00533 $trackRecord .= "<http://purl.org/ontology/wsf#previousStateMime> \"".$this->previousStateMime."\" ;"; 00534 $trackRecord .= "<http://purl.org/ontology/wsf#performer> \"".$this->performer."\" ."; 00535 00536 $this->db->query("DB.DBA.TTLP_MT('" 00537 . addslashes($trackRecord) . "', '" . $this->wsf_graph."track/" . "', '" 00538 . $this->wsf_graph."track/" . "')"); 00539 00540 if(odbc_error()) 00541 { 00542 $this->conneg->setStatus(400); 00543 $this->conneg->setStatusMsg("Bad Request"); 00544 $this->conneg->setError($this->errorMessenger->_302->id, $this->errorMessenger->ws, 00545 $this->errorMessenger->_302->name, $this->errorMessenger->_302->description, odbc_errormsg(), 00546 $this->errorMessenger->_302->level); 00547 00548 return; 00549 } 00550 } 00551 } 00552 } 00553 } 00554 00555 00557 00558 ?>
