diff --git a/extensions/kDBRobotics/Agents.cpp b/extensions/kDBRobotics/Agents.cpp index bd017583fac6da7f0e397c5c5814f13d88bd2af9..cbdfbc6cf9880c7ae6f1b11fb30efbcdbe811a7d 100644 --- a/extensions/kDBRobotics/Agents.cpp +++ b/extensions/kDBRobotics/Agents.cpp @@ -44,7 +44,7 @@ struct Agents::Private : public QSharedData typedef QHash<knowCore::Uri, QSharedPointer<Stream::Private::Definition>> Uri2StreamDefinition; QSharedPointer<Agent::Private::Definition> createAgentDefinition(const knowCore::Uri& _agentUri, const knowCore::Uri& _typeUri, const QString& _name); - QSharedPointer<Stream::Private::Definition> createStreamDefinition(const knowCore::Uri& _streamUri, const knowCore::Uri& _typeUri, const QString& _identifier); + QSharedPointer<Stream::Private::Definition> createStreamDefinition(const knowCore::Uri& _streamUri, const knowCore::Uri& _typeUri, const knowCore::Uri& _datatypeUri, const QString& _identifier); struct Static { @@ -74,11 +74,12 @@ QSharedPointer<Agent::Private::Definition> Agents::Private::createAgentDefinitio return ds_def; } -QSharedPointer<Stream::Private::Definition> Agents::Private::createStreamDefinition(const knowCore::Uri& _streamUri, const knowCore::Uri& _typeUri, const QString& _identifier) +QSharedPointer<Stream::Private::Definition> Agents::Private::createStreamDefinition(const knowCore::Uri& _streamUri, const knowCore::Uri& _typeUri, const knowCore::Uri& _datatypeUri, const QString& _identifier) { QSharedPointer<Stream::Private::Definition> ds_def(new Stream::Private::Definition); ds_def->identifier = _identifier; - ds_def->datatype = _typeUri; + ds_def->contentType = _typeUri; + ds_def->datatype = _datatypeUri; ds_def->uri = _streamUri; ds_def->serverUuid = connection.serverUuid(); ds_def->triplestores = definition->uri; @@ -339,7 +340,7 @@ knowCore::ReturnValue<Stream> Agents::stream(const knowCore::Uri& _streamUri) co } else if(r.data.size() > 1) { return kCrvError("Got more than one stream '{}' in database.", _streamUri); } else { - ds_def = d->createStreamDefinition(_streamUri, r.data.first().datatype(), r.data.first().identifier()); + ds_def = d->createStreamDefinition(_streamUri, r.data.first().contenttype(), r.data.first().datatype(), r.data.first().identifier()); } } else { return kCrvLogError("Error while querying for agent '{}': {}", _streamUri, r.errorMessage); @@ -440,17 +441,17 @@ knowCore::ReturnValue<QList<Agent>> Agents::agents(const QList<QPair<knowCore::U using foaf = knowCore::Uris::foaf; SB::Variable uri_variable("?uri"); - SB::Variable geometry_variable("?geometry"); + SB::Variable name_variable("?name"); SB::Variable type_variable("?type"); QHash<QString, QList<SA::NodeCSP>> path2node; path2node[askcore_agent::agent_uri].append(uri_variable); - path2node[foaf::name].append(geometry_variable); + path2node[foaf::name].append(name_variable); path2node[askcore_agent::agent_type].append(type_variable); SB::TriplesList triples_pattern; triples_pattern.append(uri_variable, knowCore::Uris::rdf::a, askcore_agent::agent); - triples_pattern.append(uri_variable, foaf::name, geometry_variable); + triples_pattern.append(uri_variable, foaf::name, name_variable); triples_pattern.append(uri_variable, askcore_agent::agent_type, type_variable); @@ -485,11 +486,12 @@ knowCore::ReturnValue<QList<Agent>> Agents::agents(const QList<QPair<knowCore::U SB::SelectQuery builder; builder.modifier(SA::SelectModifier::Distinct) - .variables(uri_variable, geometry_variable, type_variable ) + .variables(uri_variable, name_variable, type_variable ) .datasets(SB::Dataset().uri(d->definition->uri)) .where(SB::GroupGraphPattern().graphPatterns(triples_pattern).filters(filters)); auto const& [queryString, queryBindings] = builder.toQueryString(); + KNOWCORE_LOG_DEBUG_VN(queryString, queryBindings); knowDBC::Query q = d->connection.createSPARQLQuery({}, queryString); q.bindValues(queryBindings); @@ -512,7 +514,7 @@ knowCore::ReturnValue<QList<Agent>> Agents::agents(const QList<QPair<knowCore::U ds_def = QSharedPointer<Agent::Private::Definition>(new Agent::Private::Definition); knowCore::Value nameValue = r.value(i, "name"); - if(knowCore::ValueIs<QString> name_string = nameValue) + if(knowCore::ValueCast<QString> name_string = nameValue) { ds_def->name = name_string.value(); } else { @@ -553,6 +555,7 @@ knowCore::ReturnValue<QList<Agent>> Agents::agents(const QList<QPair<knowCore::U ds.d = new Agent::Private; ds.d->definition = ds_def; ds.d->connection = d->connection; + KNOWCORE_RETURN_VALUE_TRY_ASSIGN(ds.d->agents, get(d->connection, ds_def->triplestores)); dss.append(ds); } diff --git a/extensions/kDBRobotics/CMakeLists.txt b/extensions/kDBRobotics/CMakeLists.txt index 5ce6d863583bfba390a27d5c0c410ff949b65e3a..dfb0fe9fb0890ce88ecb8dd1f43cfa57051eb356 100644 --- a/extensions/kDBRobotics/CMakeLists.txt +++ b/extensions/kDBRobotics/CMakeLists.txt @@ -36,8 +36,11 @@ install( FILES ${CMAKE_CURRENT_BINARY_DIR}/Event.h ${CMAKE_CURRENT_BINARY_DIR}/FrameTransformation.h ${CMAKE_CURRENT_BINARY_DIR}/Sql.h + Agent.h + Agents.h Forward.h FramePose.h + Stream.h TypesDefinitions.h Initialise.h Test.h diff --git a/extensions/kDBRobotics/data/agents_queries.ttl b/extensions/kDBRobotics/data/agents_queries.ttl index 37db64dcbb792023745fb739aee0df00a376be6d..8cf6a2126cacb87909046f6fd93bb01f1d9ce214 100644 --- a/extensions/kDBRobotics/data/agents_queries.ttl +++ b/extensions/kDBRobotics/data/agents_queries.ttl @@ -19,7 +19,7 @@ BEGIN <http://askco.re/scripts#pl/sparql> { INSERT DATA { GRAPH %graph { %agent_uri a askcore_agent:agent ; - askcore_agent:type %type ; + askcore_agent:agent_type %type ; foaf:name %name . } } } @@ -38,7 +38,7 @@ PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?type ?name FROM %graph WHERE { %agent_uri a askcore_agent:agent ; - askcore_agent:type ?type ; + askcore_agent:agent_type ?type ; foaf:name ?name . }""" ; askcore_queries:binding [ foaf:name "graph" ; xsi:type xsd:anyURI ; dc:description "URI for the graph where to get all the agents." ] ; diff --git a/extensions/kDBRobotics/tests/TestAgents.cpp b/extensions/kDBRobotics/tests/TestAgents.cpp index 6f617cf26c7b37b8b33185cae43fdf344619fdde..8b99c9b076a804d3dda78081670b9198efae75e3 100644 --- a/extensions/kDBRobotics/tests/TestAgents.cpp +++ b/extensions/kDBRobotics/tests/TestAgents.cpp @@ -75,10 +75,11 @@ void TestAgents::testCreation() KNOWCORE_TEST_VERIFY_FAILURE(agnss2.agent("agnt.uav1"_kCu)); KNOWCORE_TEST_VERIFY_FAILURE(agnss2.createAgent(askcore_agent::uav, "uav1", "agnt.uav1"_kCu)); - kDBRobotics::Stream stream1 = KNOWCORE_TEST_VERIFY_SUCCESS(agnss1.createStream("stream_type"_kCu, "/stream", "agnt.stream1"_kCu)); + kDBRobotics::Stream stream1 = KNOWCORE_TEST_VERIFY_SUCCESS(agnss1.createStream("stream_type"_kCu, "/stream", "data_type"_kCu, "agnt.stream1"_kCu)); QVERIFY(stream1.isValid()); - QCOMPARE(stream1.datatype(), "stream_type"_kCu); + QCOMPARE(stream1.contentType(), "stream_type"_kCu); QCOMPARE(stream1.identifier(), "/stream"); + QCOMPARE(stream1.datatype(), "data_type"_kCu); QCOMPARE(stream1.uri(), "agnt.stream1"_kCu); KNOWCORE_TEST_VERIFY_FAILURE(agnss2.agent("agnt.stream1"_kCu)); @@ -103,8 +104,9 @@ void TestAgents::testCreation() stream1 = KNOWCORE_TEST_VERIFY_SUCCESS(agnss1.createStream("stream_type"_kCu, "/stream", "agnt.stream1"_kCu)); QVERIFY(stream1.isValid()); - QCOMPARE(stream1.datatype(), "stream_type"_kCu); + QCOMPARE(stream1.contentType(), "stream_type"_kCu); QCOMPARE(stream1.identifier(), "/stream"); + QCOMPARE(stream1.datatype(), "data_type"_kCu); QCOMPARE(stream1.uri(), "agnt.stream1"_kCu); agent1_streams = KNOWCORE_TEST_VERIFY_SUCCESS(agent1.streams());