diff --git a/phis2-ws/src/main/java/phis2ws/service/dao/sesame/RadiometricTargetDAOSesame.java b/phis2-ws/src/main/java/phis2ws/service/dao/sesame/RadiometricTargetDAOSesame.java index d8fd47c40..9112cfdc0 100644 --- a/phis2-ws/src/main/java/phis2ws/service/dao/sesame/RadiometricTargetDAOSesame.java +++ b/phis2-ws/src/main/java/phis2ws/service/dao/sesame/RadiometricTargetDAOSesame.java @@ -580,7 +580,7 @@ public int getLastId() { BindingSet bindingSet = result.next(); uri = bindingSet.getValue(URI).stringValue(); } - + if (uri == null) { return 0; } else { diff --git a/phis2-ws/src/main/java/phis2ws/service/dao/sesame/SensorProfileDAOSesame.java b/phis2-ws/src/main/java/phis2ws/service/dao/sesame/SensorProfileDAOSesame.java index 42173971d..5a8b7b78f 100644 --- a/phis2-ws/src/main/java/phis2ws/service/dao/sesame/SensorProfileDAOSesame.java +++ b/phis2-ws/src/main/java/phis2ws/service/dao/sesame/SensorProfileDAOSesame.java @@ -13,6 +13,14 @@ import java.util.ArrayList; import java.util.List; +import org.apache.jena.arq.querybuilder.UpdateBuilder; +import org.apache.jena.graph.Node; +import org.apache.jena.graph.NodeFactory; +import org.apache.jena.rdf.model.Literal; +import org.apache.jena.rdf.model.Resource; +import org.apache.jena.rdf.model.ResourceFactory; +import org.apache.jena.update.UpdateRequest; +import org.apache.jena.vocabulary.RDF; import org.eclipse.rdf4j.query.BindingSet; import org.eclipse.rdf4j.query.MalformedQueryException; import org.eclipse.rdf4j.query.QueryEvaluationException; @@ -30,12 +38,10 @@ import phis2ws.service.ontologies.Rdf; import phis2ws.service.ontologies.Rdfs; import phis2ws.service.ontologies.Vocabulary; -import phis2ws.service.resources.dto.rdfResourceDefinition.PropertyDTO; import phis2ws.service.resources.dto.SensorProfileDTO; import phis2ws.service.resources.dto.rdfResourceDefinition.PropertyPostDTO; import phis2ws.service.utils.POSTResultsReturn; import phis2ws.service.utils.sparql.SPARQLQueryBuilder; -import phis2ws.service.utils.sparql.SPARQLUpdateBuilder; import phis2ws.service.view.brapi.Status; import phis2ws.service.view.model.phis.Ask; import phis2ws.service.view.model.phis.Property; @@ -172,20 +178,28 @@ public POSTResultsReturn check(List sensorProfiles) { * } * } */ - private SPARQLUpdateBuilder prepareInsertQuery(SensorProfile sensorProfile) { - SPARQLUpdateBuilder query = new SPARQLUpdateBuilder(); + private UpdateRequest prepareInsertQuery(SensorProfile sensorProfile) { + UpdateBuilder spql = new UpdateBuilder(); - query.appendGraphURI(Contexts.SENSORS.toString()); + Node graph = NodeFactory.createURI(Contexts.SENSORS.toString()); + Resource sensorProfileUri = ResourceFactory.createResource(sensorProfile.getUri()); for (Property property : sensorProfile.getProperties()) { + org.apache.jena.rdf.model.Property propertyRelation = ResourceFactory.createProperty(property.getRelation()); + if (property.getRdfType() != null) { - query.appendTriplet(sensorProfile.getUri(), property.getRelation(), property.getValue(), null); - query.appendTriplet(property.getValue(), Rdf.RELATION_TYPE.toString(), property.getRdfType(), null); + Node propertyValue = NodeFactory.createURI(property.getValue()); + spql.addInsert(graph, sensorProfileUri, propertyRelation, propertyValue); + spql.addInsert(graph,propertyValue, RDF.type, property.getRdfType()); } else { - query.appendTriplet(sensorProfile.getUri(), property.getRelation(), "\"" + property.getValue() + "\"", null); + Literal propertyValue = ResourceFactory.createStringLiteral(property.getValue()); + spql.addInsert(graph, sensorProfileUri, propertyRelation, propertyValue); } } + + UpdateRequest query = spql.buildRequest(); LOGGER.debug(SPARQL_SELECT_QUERY + " " + query.toString()); + return query; } @@ -207,7 +221,7 @@ private POSTResultsReturn insert(List sensorsProfiles) { this.getConnection().begin(); for (SensorProfileDTO sensorProfileDTO : sensorsProfiles) { - SPARQLUpdateBuilder query = prepareInsertQuery(sensorProfileDTO.createObjectFromDTO()); + UpdateRequest query = prepareInsertQuery(sensorProfileDTO.createObjectFromDTO()); Update prepareUpdate = getConnection().prepareUpdate(QueryLanguage.SPARQL, query.toString()); prepareUpdate.execute();