improved creating Connection from Model
instead of relying on base uri of model, search for the
connection resource by searching for the rdf:type won:Connection triple
@@ -16,12 +16,10 @@ import java.net.URI;
* Date: 09.04.13
* T ime: 15:38
*/
-public class ConnectionModelMapper implements ModelMapper<Connection>
-{
+public class ConnectionModelMapper implements ModelMapper<Connection> {
@Override
- public Model toModel(Connection connection)
- {
+ public Model toModel(Connection connection) {
Model model = ModelFactory.createDefaultModel();
Resource connectionMember = model.createResource(connection.getConnectionURI().toString())
.addProperty(WON.HAS_CONNECTION_STATE, WON.toResource(connection.getState()))
@@ -40,11 +38,12 @@ public class ConnectionModelMapper implements ModelMapper<Connection>
}
@Override
- public Connection fromModel(Model model)
- {
+ public Connection fromModel(Model model) {
+ URI connectionURI = RdfUtils.findFirstSubjectUri(model, RDF.type, WON.CONNECTION, false, true);
+ if (connectionURI == null) return null;
+ Resource connectionRes = model.getResource(connectionURI.toString());
Connection connection = new Connection();
- Resource connectionRes = RdfUtils.getBaseResource(model);
connection.setConnectionURI(URI.create(connectionRes.getURI()));
URI connectionStateURI = URI.create(connectionRes.getProperty(WON.HAS_CONNECTION_STATE).getResource().getURI());
