|
|
@ -374,6 +374,7 @@ fn configure_and_evaluate_sparql_query( |
|
|
|
) -> Result<Response> { |
|
|
|
) -> Result<Response> { |
|
|
|
let mut default_graph_uris = Vec::new(); |
|
|
|
let mut default_graph_uris = Vec::new(); |
|
|
|
let mut named_graph_uris = Vec::new(); |
|
|
|
let mut named_graph_uris = Vec::new(); |
|
|
|
|
|
|
|
let mut use_default_graph_as_union = false; |
|
|
|
for (k, v) in form_urlencoded::parse(&encoded) { |
|
|
|
for (k, v) in form_urlencoded::parse(&encoded) { |
|
|
|
match k.as_ref() { |
|
|
|
match k.as_ref() { |
|
|
|
"query" => { |
|
|
|
"query" => { |
|
|
@ -383,12 +384,20 @@ fn configure_and_evaluate_sparql_query( |
|
|
|
query = Some(v.into_owned()) |
|
|
|
query = Some(v.into_owned()) |
|
|
|
} |
|
|
|
} |
|
|
|
"default-graph-uri" => default_graph_uris.push(v.into_owned()), |
|
|
|
"default-graph-uri" => default_graph_uris.push(v.into_owned()), |
|
|
|
|
|
|
|
"union-default-graph" => use_default_graph_as_union = true, |
|
|
|
"named-graph-uri" => named_graph_uris.push(v.into_owned()), |
|
|
|
"named-graph-uri" => named_graph_uris.push(v.into_owned()), |
|
|
|
_ => (), |
|
|
|
_ => (), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if let Some(query) = query { |
|
|
|
if let Some(query) = query { |
|
|
|
evaluate_sparql_query(store, query, default_graph_uris, named_graph_uris, request) |
|
|
|
evaluate_sparql_query( |
|
|
|
|
|
|
|
store, |
|
|
|
|
|
|
|
query, |
|
|
|
|
|
|
|
use_default_graph_as_union, |
|
|
|
|
|
|
|
default_graph_uris, |
|
|
|
|
|
|
|
named_graph_uris, |
|
|
|
|
|
|
|
request, |
|
|
|
|
|
|
|
) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
bail_status!(400, "You should set the 'query' parameter") |
|
|
|
bail_status!(400, "You should set the 'query' parameter") |
|
|
|
} |
|
|
|
} |
|
|
@ -397,28 +406,37 @@ fn configure_and_evaluate_sparql_query( |
|
|
|
fn evaluate_sparql_query( |
|
|
|
fn evaluate_sparql_query( |
|
|
|
store: Store, |
|
|
|
store: Store, |
|
|
|
query: String, |
|
|
|
query: String, |
|
|
|
|
|
|
|
use_default_graph_as_union: bool, |
|
|
|
default_graph_uris: Vec<String>, |
|
|
|
default_graph_uris: Vec<String>, |
|
|
|
named_graph_uris: Vec<String>, |
|
|
|
named_graph_uris: Vec<String>, |
|
|
|
request: Request, |
|
|
|
request: Request, |
|
|
|
) -> Result<Response> { |
|
|
|
) -> Result<Response> { |
|
|
|
let mut query = |
|
|
|
let mut query = |
|
|
|
Query::parse(&query, Some(base_url(&request)?.as_str())).map_err(bad_request)?; |
|
|
|
Query::parse(&query, Some(base_url(&request)?.as_str())).map_err(bad_request)?; |
|
|
|
let default_graph_uris = default_graph_uris |
|
|
|
|
|
|
|
|
|
|
|
if use_default_graph_as_union { |
|
|
|
|
|
|
|
if !default_graph_uris.is_empty() || !named_graph_uris.is_empty() { |
|
|
|
|
|
|
|
bail_status!( |
|
|
|
|
|
|
|
400, |
|
|
|
|
|
|
|
"default-graph-uri or named-graph-uri and union-default-graph should not be set at the same time" |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
query.dataset_mut().set_default_graph_as_union() |
|
|
|
|
|
|
|
} else if !default_graph_uris.is_empty() || !named_graph_uris.is_empty() { |
|
|
|
|
|
|
|
query.dataset_mut().set_default_graph( |
|
|
|
|
|
|
|
default_graph_uris |
|
|
|
.into_iter() |
|
|
|
.into_iter() |
|
|
|
.map(|e| Ok(NamedNode::new(e)?.into())) |
|
|
|
.map(|e| Ok(NamedNode::new(e)?.into())) |
|
|
|
.collect::<Result<Vec<GraphName>>>() |
|
|
|
.collect::<Result<_>>() |
|
|
|
.map_err(bad_request)?; |
|
|
|
.map_err(bad_request)?, |
|
|
|
let named_graph_uris = named_graph_uris |
|
|
|
); |
|
|
|
|
|
|
|
query.dataset_mut().set_available_named_graphs( |
|
|
|
|
|
|
|
named_graph_uris |
|
|
|
.into_iter() |
|
|
|
.into_iter() |
|
|
|
.map(|e| Ok(NamedNode::new(e)?.into())) |
|
|
|
.map(|e| Ok(NamedNode::new(e)?.into())) |
|
|
|
.collect::<Result<Vec<NamedOrBlankNode>>>() |
|
|
|
.collect::<Result<_>>() |
|
|
|
.map_err(bad_request)?; |
|
|
|
.map_err(bad_request)?, |
|
|
|
|
|
|
|
); |
|
|
|
if !default_graph_uris.is_empty() || !named_graph_uris.is_empty() { |
|
|
|
|
|
|
|
query.dataset_mut().set_default_graph(default_graph_uris); |
|
|
|
|
|
|
|
query |
|
|
|
|
|
|
|
.dataset_mut() |
|
|
|
|
|
|
|
.set_available_named_graphs(named_graph_uris); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let results = store.query(query)?; |
|
|
|
let results = store.query(query)?; |
|
|
@ -455,6 +473,7 @@ fn configure_and_evaluate_sparql_update( |
|
|
|
mut update: Option<String>, |
|
|
|
mut update: Option<String>, |
|
|
|
request: Request, |
|
|
|
request: Request, |
|
|
|
) -> Result<Response> { |
|
|
|
) -> Result<Response> { |
|
|
|
|
|
|
|
let mut use_default_graph_as_union = false; |
|
|
|
let mut default_graph_uris = Vec::new(); |
|
|
|
let mut default_graph_uris = Vec::new(); |
|
|
|
let mut named_graph_uris = Vec::new(); |
|
|
|
let mut named_graph_uris = Vec::new(); |
|
|
|
for (k, v) in form_urlencoded::parse(&encoded) { |
|
|
|
for (k, v) in form_urlencoded::parse(&encoded) { |
|
|
@ -466,12 +485,20 @@ fn configure_and_evaluate_sparql_update( |
|
|
|
update = Some(v.into_owned()) |
|
|
|
update = Some(v.into_owned()) |
|
|
|
} |
|
|
|
} |
|
|
|
"using-graph-uri" => default_graph_uris.push(v.into_owned()), |
|
|
|
"using-graph-uri" => default_graph_uris.push(v.into_owned()), |
|
|
|
|
|
|
|
"using-union-graph" => use_default_graph_as_union = true, |
|
|
|
"using-named-graph-uri" => named_graph_uris.push(v.into_owned()), |
|
|
|
"using-named-graph-uri" => named_graph_uris.push(v.into_owned()), |
|
|
|
_ => (), |
|
|
|
_ => (), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if let Some(update) = update { |
|
|
|
if let Some(update) = update { |
|
|
|
evaluate_sparql_update(store, update, default_graph_uris, named_graph_uris, request) |
|
|
|
evaluate_sparql_update( |
|
|
|
|
|
|
|
store, |
|
|
|
|
|
|
|
update, |
|
|
|
|
|
|
|
use_default_graph_as_union, |
|
|
|
|
|
|
|
default_graph_uris, |
|
|
|
|
|
|
|
named_graph_uris, |
|
|
|
|
|
|
|
request, |
|
|
|
|
|
|
|
) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
bail_status!(400, "You should set the 'update' parameter") |
|
|
|
bail_status!(400, "You should set the 'update' parameter") |
|
|
|
} |
|
|
|
} |
|
|
@ -480,12 +507,33 @@ fn configure_and_evaluate_sparql_update( |
|
|
|
fn evaluate_sparql_update( |
|
|
|
fn evaluate_sparql_update( |
|
|
|
store: Store, |
|
|
|
store: Store, |
|
|
|
update: String, |
|
|
|
update: String, |
|
|
|
|
|
|
|
use_default_graph_as_union: bool, |
|
|
|
default_graph_uris: Vec<String>, |
|
|
|
default_graph_uris: Vec<String>, |
|
|
|
named_graph_uris: Vec<String>, |
|
|
|
named_graph_uris: Vec<String>, |
|
|
|
request: Request, |
|
|
|
request: Request, |
|
|
|
) -> Result<Response> { |
|
|
|
) -> Result<Response> { |
|
|
|
let mut update = |
|
|
|
let mut update = |
|
|
|
Update::parse(&update, Some(base_url(&request)?.as_str())).map_err(bad_request)?; |
|
|
|
Update::parse(&update, Some(base_url(&request)?.as_str())).map_err(bad_request)?; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if use_default_graph_as_union { |
|
|
|
|
|
|
|
if !default_graph_uris.is_empty() || !named_graph_uris.is_empty() { |
|
|
|
|
|
|
|
bail_status!( |
|
|
|
|
|
|
|
400, |
|
|
|
|
|
|
|
"using-graph-uri or using-named-graph-uri and using-union-graph should not be set at the same time" |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for operation in &mut update.operations { |
|
|
|
|
|
|
|
if let GraphUpdateOperation::DeleteInsert { using, .. } = operation { |
|
|
|
|
|
|
|
if !using.is_default_dataset() { |
|
|
|
|
|
|
|
bail_status!( |
|
|
|
|
|
|
|
400, |
|
|
|
|
|
|
|
"using-union-graph must not be used with a SPARQL UPDATE containing USING", |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
using.set_default_graph_as_union(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if !default_graph_uris.is_empty() || !named_graph_uris.is_empty() { |
|
|
|
let default_graph_uris = default_graph_uris |
|
|
|
let default_graph_uris = default_graph_uris |
|
|
|
.into_iter() |
|
|
|
.into_iter() |
|
|
|
.map(|e| Ok(NamedNode::new(e)?.into())) |
|
|
|
.map(|e| Ok(NamedNode::new(e)?.into())) |
|
|
@ -496,11 +544,11 @@ fn evaluate_sparql_update( |
|
|
|
.map(|e| Ok(NamedNode::new(e)?.into())) |
|
|
|
.map(|e| Ok(NamedNode::new(e)?.into())) |
|
|
|
.collect::<Result<Vec<NamedOrBlankNode>>>() |
|
|
|
.collect::<Result<Vec<NamedOrBlankNode>>>() |
|
|
|
.map_err(bad_request)?; |
|
|
|
.map_err(bad_request)?; |
|
|
|
if !default_graph_uris.is_empty() || !named_graph_uris.is_empty() { |
|
|
|
|
|
|
|
for operation in &mut update.operations { |
|
|
|
for operation in &mut update.operations { |
|
|
|
if let GraphUpdateOperation::DeleteInsert { using, .. } = operation { |
|
|
|
if let GraphUpdateOperation::DeleteInsert { using, .. } = operation { |
|
|
|
if !using.is_default_dataset() { |
|
|
|
if !using.is_default_dataset() { |
|
|
|
bail_status!(400, |
|
|
|
bail_status!( |
|
|
|
|
|
|
|
400, |
|
|
|
"using-graph-uri and using-named-graph-uri must not be used with a SPARQL UPDATE containing USING", |
|
|
|
"using-graph-uri and using-named-graph-uri must not be used with a SPARQL UPDATE containing USING", |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
@ -786,6 +834,24 @@ mod tests { |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn get_query_union_graph() { |
|
|
|
|
|
|
|
ServerTest::new().test_status(Request::new( |
|
|
|
|
|
|
|
Method::Get, |
|
|
|
|
|
|
|
Url::parse("http://localhost/query?query=SELECT%20*%20WHERE%20{%20?s%20?p%20?o%20}&union-default-graph") |
|
|
|
|
|
|
|
.unwrap(), |
|
|
|
|
|
|
|
), StatusCode::Ok); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn get_query_union_graph_and_default_graph() { |
|
|
|
|
|
|
|
ServerTest::new().test_status(Request::new( |
|
|
|
|
|
|
|
Method::Get, |
|
|
|
|
|
|
|
Url::parse("http://localhost/query?query=SELECT%20*%20WHERE%20{%20?s%20?p%20?o%20}&union-default-graph&default-graph-uri=http://example.com") |
|
|
|
|
|
|
|
.unwrap(), |
|
|
|
|
|
|
|
), StatusCode::BadRequest); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn get_without_query() { |
|
|
|
fn get_without_query() { |
|
|
|
ServerTest::new().test_status( |
|
|
|
ServerTest::new().test_status( |
|
|
|