diff --git a/src/PMGDQueryHandler.cc b/src/PMGDQueryHandler.cc index 368954be..f7a9b6f6 100644 --- a/src/PMGDQueryHandler.cc +++ b/src/PMGDQueryHandler.cc @@ -484,10 +484,12 @@ void PMGDQueryHandler::build_results(Iterator &ni, for (; ni; ni.next()) { for (int i = 0; i < keyids.size(); ++i) { Property j_p; - if (!ni->check_property(keyids[i], j_p)) - continue; PMGDPropList &list = rmap[qn.response_keys(i)]; PMGDProp *p_p = list.add_values(); + if (!ni->check_property(keyids[i], j_p)) { + construct_missing_property(p_p); + continue; + } construct_protobuf_property(j_p, p_p); } count++; @@ -584,3 +586,10 @@ void PMGDQueryHandler::construct_protobuf_property(const Property &j_p, PMGDProp p_p->set_blob_value(j_p.blob_value().value, j_p.blob_value().size); } } + +void PMGDQueryHandler::construct_missing_property(PMGDProp *p_p) +{ + // Assumes matching enum values! + p_p->set_type(PMGDProp::StringType); + p_p->set_string_value("Missing property"); +} diff --git a/src/PMGDQueryHandler.h b/src/PMGDQueryHandler.h index 22926922..e6cb03ef 100644 --- a/src/PMGDQueryHandler.h +++ b/src/PMGDQueryHandler.h @@ -92,6 +92,7 @@ namespace VDMS { const PMGDQueryNode &qn, PMGDCmdResponse *response); void construct_protobuf_property(const PMGD::Property &j_p, PMGDProp*p_p); + void construct_missing_property(PMGDProp *p_p); void set_response(PMGDCmdResponse *response, PMGDCmdErrorCode error_code, std::string error_msg) diff --git a/src/RSCommand.cc b/src/RSCommand.cc index d54d8ddc..48d116cd 100644 --- a/src/RSCommand.cc +++ b/src/RSCommand.cc @@ -154,9 +154,10 @@ int AddEntity::construct_protobuf(PMGDQuery& query, Json::Value& error) { const Json::Value& cmd = jsoncmd[_cmd_name]; + bool link = cmd.isMember("link"); int node_ref = get_value(cmd, "_ref", - query.get_available_reference()); + link ? query.get_available_reference() : -1); query.AddNode( node_ref, @@ -165,7 +166,7 @@ int AddEntity::construct_protobuf(PMGDQuery& query, cmd["constraints"] ); - if (cmd.isMember("link")) { + if (link) { add_link(query, cmd["link"], node_ref, VDMS_GENERIC_LINK); } diff --git a/tests/AddAndFind_query.json b/tests/AddAndFind_query.json index a96e8718..3b8a0dd7 100644 --- a/tests/AddAndFind_query.json +++ b/tests/AddAndFind_query.json @@ -190,7 +190,7 @@ "Age": [">", 0, "<=", 100 ] }, "results": { - "list":["Name","Age","Email"], + "list":["Name","Age","Email", "Study"], "sort" :"Age" } } diff --git a/tests/json_queries.cc b/tests/json_queries.cc index 53383eee..a93acceb 100644 --- a/tests/json_queries.cc +++ b/tests/json_queries.cc @@ -244,7 +244,15 @@ TEST(QueryHandler, AddAndFind){ if (cmd =="FindEntity") out_query_num++; - if (j == 12) { // Last FindEntiyu + if (j == 11) { // Second Last FindEntity + EXPECT_EQ(query["FindEntity"]["entities"][2]["Study"].asString(), + "Missing property"); + + EXPECT_EQ(query["FindEntity"]["entities"][3]["Study"].asString(), + "Missing property"); + } + + if (j == 12) { // Last FindEntiy EXPECT_EQ(query["FindEntity"]["entities"][0]["Birthday"].asString(), "1946-10-07T17:59:24-07:00"); diff --git a/utils/src/api_schema/api_schema.json b/utils/src/api_schema/api_schema.json index 4f9abef6..9af35aab 100644 --- a/utils/src/api_schema/api_schema.json +++ b/utils/src/api_schema/api_schema.json @@ -213,8 +213,6 @@ "results": { "type": "object" }, "unique": { "type": "boolean" } }, - - "required": ["class"], "additionalProperties": false },