PREFIX dri: <http://nationalarchives.gov.uk/terms/dri#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX status:
<http://nationalarchives.gov.uk/dri/catalogue/transferAssetStatus#>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
DELETE {
?transfer dri:transferAsset ?transferAsset .
}
INSERT {
?transfer dri:transferAsset _:b0 .
_:b0 dct:subject ?subject .
_:b0 dri:transferAssetStatus status:SENT .
_:b0 dct:modified "2013-06-13T11:58:23.468Z"^^xsd:dateTime .
}
WHERE
{ ?transfer dct:identifier "201305241200"^^xsd:string .
?subject dct:identifier
"dff82497-f161-4afd-8e38-f31a8b475b43"^^xsd:string
OPTIONAL
{ ?transfer dri:transferAsset ?transferAsset .
?transferAsset dct:subject ?subject .
?transferAsset dct:modified ?transferAssetModified
FILTER ( ?transferAssetModified <
"2013-06-13T11:58:23.468Z"^^xsd:dateTime )
}
}
Rob,
(which version of the software?)
The example data does not look like the DELETE was applied - there is
still a dri:transferAsset link to the old state. I would have expected
the bnode still to be there but the triple connecting it should have gone.
If so, then the OPTIONAL is not matching -- it sets ?transferAsset.
In your example, the
?subject dct:identifier ...
does not match either but an INSERT does seem to have happened.
Could you delete all ?transferAsset completely? The new state only
depends on the new status if it's a legal state transition for the status.
To cope with the fact that COMPLETED can come before SENDING, test the
status.
DELETE {
?transfer dri:transferAsset ?transferAsset .
?transferAsset ?p ?o .
}
INSERT {
?transfer dri:transferAsset _:b0 .
_:b0 dct:subject ?subject .
_:b0 dri:transferAssetStatus status:SENT .
_:b0 dct:modified "2013-06-13T11:58:23.468Z"^^xsd:dateTime .
}
WHERE {
?transfer dct:identifier "201305241200"^^xsd:string ;
dri:transferAssetStatus ?status ;
dri:transferAsset ?transferAsset .
FILTER (?status != status:COMPLETED)
?transferAsset ?p ?o .
} ;
SPARQL Updates can be several operations in one request. It may be
easier to have two operations
DELETE { ... } WHERE { ... } ;
INSERT { ... } WHERE { ... }
Andy