36 // We just continue the current transaction |
37 // We just continue the current transaction |
37 return false; |
38 return false; |
38 } |
39 } |
39 //Log::debug('http_client base uri: ' . $this->getHttpClient()->getConfig('base_uri')); |
40 //Log::debug('http_client base uri: ' . $this->getHttpClient()->getConfig('base_uri')); |
40 $sesameRepository = config('corpusparole.sesame_repository'); |
41 $sesameRepository = config('corpusparole.sesame_repository'); |
41 $resp = $this->getHttpClient()->post("$sesameRepository/transactions"); |
42 $resp = $this->getHttpClient()->post("$sesameRepository/transactions", ['query' => ['isolation-level' => 'http://www.openrdf.org/schema/sesame#SNAPSHOT_READ']]); |
42 //$resp = $this->getHttpClient()->post('transactions'); |
43 //$resp = $this->getHttpClient()->post('transactions'); |
43 //TODO check errors |
44 //TODO check errors |
44 if($resp->getStatusCode() != 201) { |
45 if($resp->getStatusCode() != 201) { |
45 throw new CorpusParoleException("Error when starting transaction : " |
46 throw new CorpusParoleException("Error when starting transaction : " |
46 . $resp->getStatusCode() . " - " |
47 . $resp->getStatusCode() . " - " |
95 } |
96 } |
96 |
97 |
97 protected function updateData($operation, Graph $graph) |
98 protected function updateData($operation, Graph $graph) |
98 { |
99 { |
99 $graphUri = $graph->getUri(); |
100 $graphUri = $graph->getUri(); |
100 $query = "$operation DATA {"; |
101 |
|
102 $query = $graph->serialise('ntriples'); |
101 if ($graphUri) { |
103 if ($graphUri) { |
102 $query .= "GRAPH <$graphUri> {"; |
104 $query = "GRAPH <$graphUri> { $query }"; |
103 } |
105 } |
104 $query .= $graph->serialise('ntriples'); |
106 $query = "$operation DATA { $query }"; |
105 if ($graphUri) { |
|
106 $query .= "}"; |
|
107 } |
|
108 $query .= '}'; |
|
109 |
107 |
|
108 |
|
109 // doc : http://rdf4j.org/doc/4/articles/REST-API/transaction-operations.docbook?view |
|
110 // cf. bug : https://openrdf.atlassian.net/browse/SES-2295 |
|
111 // and PR https://bitbucket.org/openrdf/sesame/commits/62b680d8650caca7bc1673f6aaac48a5b6e85d23?at=2.8.x |
|
112 // The put form has been chosen over the post, because it seems that this is the form choosed in the sesame http client |
110 $resp = $this->getHttpClient()->put( |
113 $resp = $this->getHttpClient()->put( |
111 $this->currentTransactionUrl, [ |
114 $this->currentTransactionUrl, [ |
|
115 'headers' => ["Content-Type" => "application/sparql-update; charset=utf-8"], |
112 'query' => ['action' => 'UPDATE'], |
116 'query' => ['action' => 'UPDATE'], |
113 'form_params'=> ['update' => $query], |
117 'body' => $query, |
114 ] |
118 ] |
115 ); |
119 ); |
116 if($resp->getStatusCode() != 204) { |
120 |
117 throw new CorpusParoleException("Could not update in transaction with operation $operation: " |
|
118 . $resp->getStatusCode() . " - " |
|
119 . $resp->getReasonPhrase() . " : " . $resp->getBody() |
|
120 . " : $query" , 1); |
|
121 } |
|
122 } |
121 } |
123 |
122 |
124 public function add(Graph $graph) { |
123 public function add(Graph $graph) { |
125 $this->updateData('INSERT', $graph); |
124 $this->updateData('INSERT', $graph); |
126 } |
125 } |