*/
public synchronized URI updateElement(KeywordBean keyword, boolean replace) throws AccessDeniedException, IOException,
MalformedQueryException, QueryEvaluationException, GraphException {
// Get thesaurus graph
Graph myGraph = repository.getGraph();
// Set namespace skos and predicates
ValueFactory myFactory = myGraph.getValueFactory();
String namespaceSkos = "http://www.w3.org/2004/02/skos/core#";
URI predicatePrefLabel = myFactory .createURI(namespaceSkos, "prefLabel");
URI predicateScopeNote = myFactory.createURI(namespaceSkos, "scopeNote");
// Get subject (URI)
URI subject = myFactory.createURI(keyword.getUriCode());
// Remove old labels
StatementIterator iter = myGraph.getStatements(subject, predicatePrefLabel, null);
removeMatchingLiterals(replace, myGraph, iter, keyword.getValues().keySet());
// remove old scopeNote
iter = myGraph.getStatements(subject, predicateScopeNote, null);
removeMatchingLiterals(replace, myGraph, iter, keyword.getDefinitions().keySet());
// add updated Labels
Set<Entry<String, String>> values = keyword.getValues().entrySet();
for (Entry<String, String> entry : values) {
String language = toiso639_1_Lang(entry.getKey());
Value valueObj = myFactory.createLiteral(entry.getValue(), language);
myGraph.add(subject, predicatePrefLabel, valueObj );
}
// add updated Definitions/Notes
Set<Entry<String, String>> definitions = keyword.getDefinitions().entrySet();
for (Entry<String, String> entry : definitions) {
String language = toiso639_1_Lang(entry.getKey());
Value definitionObj = myFactory.createLiteral(entry.getValue(), language);
myGraph.add(subject, predicateScopeNote, definitionObj );
}
// update bbox
if(replace || !(keyword.getCoordEast() + keyword.getCoordNorth() + keyword.getCoordWest() + keyword.getCoordSouth()).trim().isEmpty()) {
String namespaceGml = "http://www.opengis.net/gml#";
URI predicateBoundedBy = myFactory.createURI(namespaceGml, "BoundedBy");
URI predicateLowerCorner = myFactory.createURI(namespaceGml, "lowerCorner");
URI predicateUpperCorner = myFactory.createURI(namespaceGml, "upperCorner");
BNode subjectGml = null;
iter = myGraph.getStatements(subject, predicateBoundedBy, null);
while (iter.hasNext()) {
AtomicReference<Statement> st = new AtomicReference<Statement>(iter.next());
if (st.get().getObject() instanceof BNode) {
subjectGml = (BNode) st.get().getObject();
}
}
if (subjectGml != null) {
// lowerCorner
iter = myGraph.getStatements(subjectGml, predicateLowerCorner, null);
while (true) {
if (!(iter.hasNext())) {
break;
}
AtomicReference<Statement> st = new AtomicReference<Statement>(iter.next());
myGraph.remove(st.get());
break;
}
// upperCorner
iter = myGraph.getStatements(subjectGml, predicateUpperCorner, null);
while (true) {
if (!(iter.hasNext())) {
break;
}
AtomicReference<Statement> st = new AtomicReference<Statement>(iter.next());
myGraph.remove(st.get());
break;
}
// create the new statements
Literal lowerCorner = myFactory.createLiteral(keyword.getCoordWest() + " " + keyword.getCoordSouth());
Literal upperCorner = myFactory.createLiteral(keyword.getCoordEast() + " " + keyword.getCoordNorth());
// Add the new statements
myGraph.add(subjectGml, predicateLowerCorner, lowerCorner);
myGraph.add(subjectGml, predicateUpperCorner, upperCorner);
}
}
return subject;
}