00001 <?php
00002
00005
00026 class DatasetUpdate extends WebService
00027 {
00029 private $db;
00030
00032 private $conneg;
00033
00035 private $dtdURL;
00036
00038 private $requester_ip = "";
00039
00041 private $datasetUri = "";
00042
00044 private $datasetTitle = "";
00045
00047 private $description = "";
00048
00050 private $contributors = "";
00051
00053 private $modified = "";
00054
00056 public static $supportedSerializations =
00057 array ("application/json", "application/rdf+xml", "application/rdf+n3", "application/*", "text/xml", "text/*",
00058 "*/*");
00059
00061 private $errorMessenger =
00062 '{
00063 "ws": "/ws/dataset/update/",
00064 "_200": {
00065 "id": "WS-DATASET-UPDATE-200",
00066 "level": "Warning",
00067 "name": "No unique identifier specified for this dataset",
00068 "description": "No URI defined for this new dataset"
00069 },
00070 "_201": {
00071 "id": "WS-DATASET-UPDATE-201",
00072 "level": "Fatal",
00073 "name": "Can\'t check if the dataset is existing",
00074 "description": "An error occured when we tried to check if the dataset was existing"
00075 },
00076 "_202": {
00077 "id": "WS-DATASET-UPDATE-202",
00078 "level": "Warning",
00079 "name": "This dataset doesn\'t exist in this WSF",
00080 "description": "The target dataset is not existing in the web service framework"
00081 },
00082 "_300": {
00083 "id": "WS-DATASET-UPDATE-300",
00084 "level": "Fatal",
00085 "name": "Can\'t update the title of the dataset in the triple store",
00086 "description": "An error occured when we tried to update the title of the dataset in the triple store"
00087 },
00088 "_301": {
00089 "id": "WS-DATASET-UPDATE-301",
00090 "level": "Fatal",
00091 "name": "Can\'t update the description of the dataset in the triple store",
00092 "description": "An error occured when we tried to update the description of the dataset in the triple store"
00093 },
00094 "_302": {
00095 "id": "WS-DATASET-UPDATE-302",
00096 "level": "Fatal",
00097 "name": "Can\'t update the last modification date of the dataset in the triple store",
00098 "description": "An error occured when we tried to update the last modification date of the dataset in the triple store"
00099 },
00100 "_303": {
00101 "id": "WS-DATASET-UPDATE-303",
00102 "level": "Fatal",
00103 "name": "Can\'t update the contributors of the dataset in the triple store",
00104 "description": "An error occured when we tried to update the contributors of the dataset in the triple store"
00105 }
00106 }';
00107
00108
00127 function __construct($uri, $title, $description, $contributors, $modified, $requester_ip)
00128 {
00129 parent::__construct();
00130
00131 $this->db = new DB_Virtuoso($this->db_username, $this->db_password, $this->db_dsn, $this->db_host);
00132
00133 $this->datasetUri = $uri;
00134 $this->datasetTitle = $title;
00135 $this->description = $description;
00136 $this->contributors = $contributors;
00137 $this->modified = $modified;
00138 $this->requester_ip = $requester_ip;
00139
00140 $this->uri = $this->wsf_base_url . "/wsf/ws/dataset/update/";
00141 $this->title = "Dataset Update Web Service";
00142 $this->crud_usage = new CrudUsage(FALSE, FALSE, TRUE, FALSE);
00143 $this->endpoint = $this->wsf_base_url . "/ws/dataset/update/";
00144
00145 $this->dtdURL = "dataset/datasetUpdate.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
00181 protected function validateQuery()
00182 {
00183
00184 $ws_av = new AuthValidator($this->requester_ip, $this->wsf_graph . "datasets/", $this->uri);
00185
00186 $ws_av->pipeline_conneg($this->conneg->getAccept(), $this->conneg->getAcceptCharset(),
00187 $this->conneg->getAcceptEncoding(), $this->conneg->getAcceptLanguage());
00188
00189 $ws_av->process();
00190
00191 if($ws_av->pipeline_getResponseHeaderStatus() != 200)
00192 {
00193
00194 $ws_av2 = new AuthValidator($this->requester_ip, $this->datasetUri, $this->uri);
00195
00196 $ws_av2->pipeline_conneg($this->conneg->getAccept(), $this->conneg->getAcceptCharset(),
00197 $this->conneg->getAcceptEncoding(), $this->conneg->getAcceptLanguage());
00198
00199 $ws_av2->process();
00200
00201 if($ws_av2->pipeline_getResponseHeaderStatus() != 200)
00202 {
00203 $this->conneg->setStatus($ws_av2->pipeline_getResponseHeaderStatus());
00204 $this->conneg->setStatusMsg($ws_av2->pipeline_getResponseHeaderStatusMsg());
00205 $this->conneg->setStatusMsgExt($ws_av2->pipeline_getResponseHeaderStatusMsgExt());
00206 $this->conneg->setError($ws_av2->pipeline_getError()->id, $ws_av2->pipeline_getError()->webservice,
00207 $ws_av2->pipeline_getError()->name, $ws_av2->pipeline_getError()->description,
00208 $ws_av2->pipeline_getError()->debugInfo, $ws_av2->pipeline_getError()->level);
00209
00210 return;
00211 }
00212 }
00213 }
00214
00225 public function pipeline_getError() { return ($this->conneg->error); }
00226
00227
00238 public function pipeline_getResultset() { return ""; }
00239
00252 public function injectDoctype($xmlDoc) { return ""; }
00253
00272 public function ws_conneg($accept, $accept_charset, $accept_encoding, $accept_language)
00273 {
00274 $this->conneg =
00275 new Conneg($accept, $accept_charset, $accept_encoding, $accept_language, DatasetUpdate::$supportedSerializations);
00276
00277
00278 $this->validateQuery();
00279
00280
00281 if($this->conneg->getStatus() == 200)
00282 {
00283
00284 if($this->datasetUri == "")
00285 {
00286 $this->conneg->setStatus(400);
00287 $this->conneg->setStatusMsg("Bad Request");
00288 $this->conneg->setStatusMsgExt($this->errorMessenger->_200->name);
00289 $this->conneg->setError($this->errorMessenger->_200->id, $this->errorMessenger->ws,
00290 $this->errorMessenger->_200->name, $this->errorMessenger->_200->description, "",
00291 $this->errorMessenger->_200->level);
00292
00293 return;
00294 }
00295
00296
00297 $query .= " select ?dataset
00298 from <" . $this->wsf_graph . "datasets/>
00299 where
00300 {
00301 <$this->datasetUri> a ?dataset .
00302 }";
00303
00304 $resultset = @$this->db->query($this->db->build_sparql_query(str_replace(array ("\n", "\r", "\t"), " ", $query),
00305 array( "dataset" ), FALSE));
00306
00307 if(odbc_error())
00308 {
00309 $this->conneg->setStatus(500);
00310 $this->conneg->setStatusMsg("Internal Error");
00311 $this->conneg->setStatusMsgExt($this->errorMessenger->_201->name);
00312 $this->conneg->setError($this->errorMessenger->_201->id, $this->errorMessenger->ws,
00313 $this->errorMessenger->_201->name, $this->errorMessenger->_201->description, odbc_errormsg(),
00314 $this->errorMessenger->_201->level);
00315
00316 return;
00317 }
00318 elseif(odbc_fetch_row($resultset) === FALSE)
00319 {
00320 $this->conneg->setStatus(400);
00321 $this->conneg->setStatusMsg("Bad Request");
00322 $this->conneg->setStatusMsgExt($this->errorMessenger->_202->name);
00323 $this->conneg->setError($this->errorMessenger->_202->id, $this->errorMessenger->ws,
00324 $this->errorMessenger->_202->name, $this->errorMessenger->_202->description, "",
00325 $this->errorMessenger->_202->level);
00326
00327 unset($resultset);
00328 }
00329
00330 unset($resultset);
00331 }
00332 }
00333
00352 public function pipeline_conneg($accept, $accept_charset, $accept_encoding, $accept_language)
00353 { $this->ws_conneg($accept, $accept_charset, $accept_encoding, $accept_language); }
00354
00365 public function pipeline_getResponseHeaderStatus() { return $this->conneg->getStatus(); }
00366
00377 public function pipeline_getResponseHeaderStatusMsg() { return $this->conneg->getStatusMsg(); }
00378
00391 public function pipeline_getResponseHeaderStatusMsgExt() { return $this->conneg->getStatusMsgExt(); }
00392
00403 public function pipeline_serialize() { return ""; }
00404
00413 public function pipeline_serialize_reification() { return ""; }
00414
00425 public function ws_serialize() { return ""; }
00426
00439 public function ws_respond($content)
00440 {
00441
00442 $this->conneg->respond();
00443
00444
00445
00446
00447 if($this->conneg->getStatus() == 200)
00448 {
00449 echo $content;
00450 }
00451
00452 $this->__destruct();
00453 }
00454
00455
00464 public function process()
00465 {
00466
00467 if($this->conneg->getStatus() == 200)
00468 {
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508 if($this->datasetTitle != "")
00509 {
00510
00511 $query = "delete from <" . $this->wsf_graph . "datasets/>
00512 {
00513 <$this->datasetUri> <http://purl.org/dc/terms/title> ?datasetTitle .
00514 }
00515 where
00516 {
00517 graph <" . $this->wsf_graph . "datasets/>
00518 {
00519 <$this->datasetUri> a <http://rdfs.org/ns/void#Dataset> .
00520 <$this->datasetUri> <http://purl.org/dc/terms/title> ?datasetTitle .
00521 }
00522 }
00523 " . ($this->datasetTitle != "-delete-" ? "
00524 insert into <" . $this->wsf_graph . "datasets/>
00525 {
00526 <$this->datasetUri> <http://purl.org/dc/terms/title> \"\"\"" . str_replace("'", "\'", $this->datasetTitle) . "\"\"\" .
00527 }" : "");
00528 }
00529
00530 @$this->db->query($this->db->build_sparql_query(str_replace(array ("\n", "\r", "\t"), " ", $query), array(),
00531 FALSE));
00532
00533 if(odbc_error())
00534 {
00535 $this->conneg->setStatus(500);
00536 $this->conneg->setStatusMsg("Internal Error");
00537 $this->conneg->setStatusMsgExt($this->errorMessenger->_300->name);
00538 $this->conneg->setError($this->errorMessenger->_300->id, $this->errorMessenger->ws,
00539 $this->errorMessenger->_300->name, $this->errorMessenger->_300->description, odbc_errormsg(),
00540 $this->errorMessenger->_300->level);
00541
00542 return;
00543 }
00544
00545
00546 if($this->description != "")
00547 {
00548 $query = "delete from <" . $this->wsf_graph . "datasets/>
00549 {
00550 <$this->datasetUri> <http://purl.org/dc/terms/description> ?description .
00551 }
00552 where
00553 {
00554 graph <" . $this->wsf_graph . "datasets/>
00555 {
00556 <$this->datasetUri> a <http://rdfs.org/ns/void#Dataset> .
00557 <$this->datasetUri> <http://purl.org/dc/terms/description> ?description .
00558 }
00559 }
00560 " . ($this->description != "-delete-" ? "
00561 insert into <" . $this->wsf_graph . "datasets/>
00562 {
00563 <$this->datasetUri> <http://purl.org/dc/terms/description> \"\"\"" . str_replace("'", "\'", $this->description) . "\"\"\" .
00564 }" : "");
00565 }
00566
00567 @$this->db->query($this->db->build_sparql_query(str_replace(array ("\n", "\r", "\t"), " ", $query), array(),
00568 FALSE));
00569
00570 if(odbc_error())
00571 {
00572 $this->conneg->setStatus(500);
00573 $this->conneg->setStatusMsg("Internal Error");
00574 $this->conneg->setStatusMsgExt($this->errorMessenger->_301->name);
00575 $this->conneg->setError($this->errorMessenger->_301->id, $this->errorMessenger->ws,
00576 $this->errorMessenger->_301->name, $this->errorMessenger->_301->description, odbc_errormsg(),
00577 $this->errorMessenger->_301->level);
00578
00579 return;
00580 }
00581
00582
00583 if($this->modified != "")
00584 {
00585 $query = "delete from <" . $this->wsf_graph . "datasets/>
00586 {
00587 <$this->datasetUri> <http://purl.org/dc/terms/modified> ?modified .
00588 }
00589 where
00590 {
00591 graph <" . $this->wsf_graph . "datasets/>
00592 {
00593 <$this->datasetUri> a <http://rdfs.org/ns/void#Dataset> .
00594 <$this->datasetUri> <http://purl.org/dc/terms/modified> ?modified .
00595 }
00596 }
00597 " . ($this->modified != "-delete-" ? "
00598 insert into <" . $this->wsf_graph . "datasets/>
00599 {
00600 <$this->datasetUri> <http://purl.org/dc/terms/modified> \"\"\"" . str_replace("'", "\'", $this->modified) . "\"\"\" .
00601 }" : "");
00602 }
00603
00604 @$this->db->query($this->db->build_sparql_query(str_replace(array ("\n", "\r", "\t"), " ", $query), array(),
00605 FALSE));
00606
00607 if(odbc_error())
00608 {
00609 $this->conneg->setStatus(500);
00610 $this->conneg->setStatusMsg("Internal Error");
00611 $this->conneg->setStatusMsgExt($this->errorMessenger->_302->name);
00612 $this->conneg->setError($this->errorMessenger->_302->id, $this->errorMessenger->ws,
00613 $this->errorMessenger->_302->name, $this->errorMessenger->_302->description, odbc_errormsg(),
00614 $this->errorMessenger->_302->level);
00615
00616 return;
00617 }
00618
00619
00620 if($this->contributors != "")
00621 {
00622 $query = "delete from <" . $this->wsf_graph . "datasets/>
00623 {
00624 <$this->datasetUri> <http://purl.org/dc/terms/contributor> ?contributor .
00625 }
00626 where
00627 {
00628 graph <"
00629 . $this->wsf_graph
00630 . "datasets/>
00631 {
00632 <$this->datasetUri> a <http://rdfs.org/ns/void#Dataset> .
00633 <$this->datasetUri> <http://purl.org/dc/terms/contributor> ?contributor .
00634 }
00635 }";
00636
00637 if($this->contributors != "-delete-")
00638 {
00639 $cons = array();
00640
00641 if(strpos($this->contributors, ";") !== FALSE)
00642 {
00643 $cons = explode(";", $this->contributors);
00644 }
00645
00646 $query .= "insert into <" . $this->wsf_graph . "datasets/>
00647 {";
00648
00649 foreach($cons as $contributor)
00650 {
00651 $query .= "<$this->datasetUri> <http://purl.org/dc/terms/contributor> <$contributor> .";
00652 }
00653
00654 if(count($cons) == 0)
00655 {
00656 $query .= "<$this->datasetUri> <http://purl.org/dc/terms/contributor> <$this->contributors> .";
00657 }
00658 $query .= "}";
00659 }
00660 }
00661
00662 @$this->db->query($this->db->build_sparql_query(str_replace(array ("\n", "\r", "\t"), " ", $query), array(),
00663 FALSE));
00664
00665 if(odbc_error())
00666 {
00667 $this->conneg->setStatus(500);
00668 $this->conneg->setStatusMsg("Internal Error");
00669 $this->conneg->setStatusMsgExt($this->errorMessenger->_303->name);
00670 $this->conneg->setError($this->errorMessenger->_303->id, $this->errorMessenger->ws,
00671 $this->errorMessenger->_303->name, $this->errorMessenger->_303->description, odbc_errormsg(),
00672 $this->errorMessenger->_303->level);
00673
00674 return;
00675 }
00676 }
00677 }
00678 }
00679
00681
00682 ?>