I have in my asset "AirPollution" some concept e.g "CarbonMonoxide". But if i call rest-composer-server in terminal, it gives me some error:
REST server error
Here my code snippet:
asset AirPollutionData identified by airPollutionDataId {
o String airPollutionDataId
o String location
o DateTime datetime
o TransferStatus status default="FOR_SALE"
o CO co
o NO2 no2
o O3 o3
o PM10 pm10
o PM25 pm25
o SO2 so2
--> Member owner
}
concept CO {
o String pollutant_description default="Carbon monoxide"
o String units default="ppb"
o Double concentration
}
concept NO2 {
o String pollutant_description default="Nitrogen dioxide"
o String units default="ppb"
o Double concentration
}
concept O3 {
o String pollutant_description default="Ozone"
o String units default="ppb"
o Double concentration
}
concept PM10 {
o String pollutant_description default="Inhalable particulate matter (<10µm)"
o String units default="ug/m3"
o Double concentration
}
concept PM25 {
o String pollutant_description default="Fine particulate matter (<2.5µm)"
o String units default="ug/m3"
o Double concentration
}
concept SO2 {
o String pollutant_description default="Sulfur dioxide"
o String units default="ug/m3"
o Double concentration
}
What is gone wrong here? And in my primitive angular app, if i want to add asset, i don't see the default valeus from concepts e.g pollutant_description or units.
Here is what I meant:default values gone
It worked for me. See screenshots below of created AirPollutionData asset.
The Swagger messages are simply that Concepts are ignored (they are not resource endpoints).
The model you posted had errors:
You're missing definitions for these two below (I created these samples, just to get it to work):
concept TransferStatus {
o String id
}
participant Member identified by id {
o String id
}
{
"$class": "org.acme.trading.AirPollutionData",
"airPollutionDataId": "3941",
"location": "Labore nisi esse incididunt non.",
"datetime": "2018-03-05T16:59:23.239Z",
"status": {
"$class": "org.acme.trading.TransferStatus",
"id": "In aute."
},
"co": {
"$class": "org.acme.trading.CO",
"pollutant_description": "Carbon monoxide",
"units": "ppb",
"concentration": 248.394
},
"no2": {
"$class": "org.acme.trading.NO2",
"pollutant_description": "Nitrogen dioxide",
"units": "ppb",
"concentration": 50.636
},
"o3": {
"$class": "org.acme.trading.O3",
"pollutant_description": "Ozone",
"units": "ppb",
"concentration": 144.997
},
"pm10": {
"$class": "org.acme.trading.PM10",
"pollutant_description": "Inhalable particulate matter (<10µm)",
"units": "ug/m3",
"concentration": 0.595
},
"pm25": {
"$class": "org.acme.trading.PM25",
"pollutant_description": "Fine particulate matter (<2.5µm)",
"units": "ug/m3",
"concentration": 60.074
},
"so2": {
"$class": "org.acme.trading.SO2",
"pollutant_description": "Sulfur dioxide",
"units": "ug/m3",
"concentration": 189.644
},
"owner": "resource:org.acme.trading.Member#1"
}
As for defaults not showing in Angular generated fields - I will find out. The defaults are available in Playground for sure, but not sure these are available in the skeleton app (that's exactly what it is, something for the developer to take forth). Will edit this when I know more on this.
Related
I have an object like this,
{
"john": {
"number": "123"
},
"sarah": {
"number": "123"
}
}
It is an object where a persons name is the key for an object, like a map.
In restAssured how can I test for a ValidatableResponse that any number whether it belongs to john or sarah matches a certain value. In this case I know there will only be one person but an "any" matcher seems appepriate here.
I have tried assertThat().body("*.number"), Matchers.is("myValue)" but it does not work and gives an error
Your problem is extracting value from a json with dynamic key (the person name, in this case). There are NO built-in functions in Rest-Assured can help you.
To solve it
you can use JsonPath jayway to extract list of number by using deep-scan feature
then use hasItem assertion of Hamcrest.
import com.jayway.jsonpath.JsonPath;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItem;
#Test
void name() {
String json = "{\n" +
" \"john\": {\n" +
" \"number\": \"123\"\n" +
" },\n" +
" \"sarah\": {\n" +
" \"number\": \"123\"\n" +
" }\n" +
"}";
List<String> numbers = JsonPath.read(json, "$..number");
assertThat(numbers, hasItem("123"));
}
Note:
Please don't confused 2 JsonPath classes here. One is in Rest-Assured, one is in JsonPath jayway.
I have to say that I hate the json structure like this, it's better if using array to group items.
[
{
"name": "john",
"number": "123"
},
{
"name": "sarah",
"number": "123"
}
]
I have the nodes user and game with some relationships between them.
My REST API should return all relationships between the games and 1 user.
The cypher query i use is:
MATCH (u:User {id: '1234'} ) -[rel]- (game:Game) return game{.*, relationships: collect(DISTINCT rel)}
In my Neo4j Browser, everything works as expected and i see all properties i need.
But the GetMapping retuns everything except the relationship properties.
Neo4j Browser
{
"relationships": [
{
"identity": 54,
"start": 9,
"end": 8,
"type": "OWNED",
"properties": {
"ownedDate": "2021-07-03"
}
},
{
"identity": 45,
"start": 9,
"end": 8,
"type": "PLAYED",
"properties": {
"times": 5
}
}
],
"name": "Blood Rage",
"state": "ACTIVE",
"id": "1c152c91-4044-41f0-9208-0c436d6f6480",
"gameUrl": "https://asmodee.de/blood-rage"
}
GetMapping result (As you can see, the relationships are empty, but i have more empty JsonObjects, when there are more Relationships
{
"game": {
"relationships": [
{},
{}
],
"name": "Blood Rage",
"gameUrl": "https://asmodee.de/blood-rage",
"state": "ACTIVE",
"id": "1c152c91-4044-41f0-9208-0c436d6f6480"
}
}
The GetMapping is:
...
final ReactiveNeo4jClient client;
...
...
...
#GetMapping(value = { "/{id}/games"})
#RolesAllowed({"user", "admin"})
Flux<Map<String, Object>> findGamesByUser(#PathVariable String id){
String query = "MATCH (uuser:User {id: '" + id + "'} ) -[rel]- (game:Game) return game{.*, relationships: collect(DISTINCT rel)}";
return client.query(query).fetch().all();
}
A RelationshipProperty-Example
#RelationshipProperties
#Data
#Builder
public class PlayedGame {
#Id
#GeneratedValue
private Long relationshipId;
#Property
int times = 0;
#TargetNode private GameEntity game;
public int addPlay(){
this.times = this.times + 1;
return this.times;
}
}
What do i have to change in my GetMapping to show the relationship-properties?
Thank you,
Kevin
You need to return the actual nodes and relationships, otherwise you're missing the id-mapping.
There should be examples in the SDN docs.
Best if you have a small reproducible example (e.g. with the default movies graph).
Not sure if there is something off in your SDN setup, in general for such simple queries you should be able to just use a repository and not need to write cypher queries by hand.
The general information given by Michael is correct but there is more in you question:
First of all the meta domain model is completely ignored if you are using the Neo4jClient. It does not automatically map anything back but uses the driver's types.
As a result you will end up with an (current state of this answer) InternalRelationship which does not have any getter-methods.
I assume that you are serializing the result in the application with Jackson. This is the reason why you see objects that represent the relationships but without any content within.
If you want to get things mapped for you, create also the domain objects properly and use (at least) the Neo4jTemplate with your query.
If you model User, Game, and the relationship properties like PlayedGame correctly, a
neo4jTemplate.findAll("MATCH (u:User)<-[rel]-(g:Game) return u, collect(rel), collect(g)", User.class)
will map the results properly. Also if this is all you have, you could also skip the custom query at all and use
neo4jTemplate.findAll(User.class)
or
neo4jTemplate.findById(useId, User.class)
I have searched the web and particularly this:
Table Serialiazation
and none of them work.
I am trying the simplest of tables as follows:
THIS IS THE INPUT.LUA FILE
{
["customers"] =
{
["name"] = "John Smith",
["age"] = 45
},
{
["name"] = "Susan Jones",
["age"] = 34
},
}
Where x = input.lua
And I have in my Lua an:-
if(type (x) == "table" then
dostuff()
else
return "this is not a table"
end
And all I get with all the deserializers is the "this is not a table".
I am now writing my own deserializer, which will have to handle all the escaping characters, and the beginning of tables, and the tracking of nested tables and the typing of values - why????
Am I a moron - which part of the table serialiazion routines did I misunderstand??
As a follow up question for my question in Dealing arrays with hamcrest and rest assured
How can I use hamcrest with restassured so that I can test
{
"mobilenum": "+6519829340",
"firstname": "Allen",
"lastname": "Edwards",
"location": "Singapore"
"outbound": "YES"
"count" : 15
},
{
"mobilenum": "+6519829340",
"firstname": "Allen",
"lastname": "Edwards",
"location": "Singapore"
"outbound": "NO"
"count" : 9
}
That there exist two types of data, one containing mobilenum, firstname, etc having outbound equal to yes, and the other no.
It would be like having two objects having the same properties except the outbound property.
An answer by John, from the previous question is this:
.root("smsentries.find { it.mobilenum == '%s' }").
.body("firstname", withArgs("+6519829340"), equalTo("Allen")
.body("lastname", withArgs("+6519829340"), equalTo("Edwards").
.body("firstname", withArgs("+12345678"), equalTo("John")
.body("lastname", withArgs("+12345678"), equalTo("Doe").
I don't know how to add something like withArgs("Allen") and ("Edwards) .equalTo("outbound")
UPDATE
What I hope to happen is like this:
for (Map.Entry<String,JsonElement> entry : o.entrySet()) {
if (entry.getKey().equals("smsentries")) {
JsonArray array = entry.getValue().getAsJsonArray();
for (JsonElement elementJSON : array) {
SMSEntry smsEntry = mapper.readValue(elementJSON.toString(), SMSEntry.class);
if (smsEntry.getMobilenum().equals("+6519829340") &&
smsEntry.getOutbound().equals("YES")) {
assertThat(smsEntry.getLocation(), equalTo("Singapore"));
assertThat(smsEntry.getCount(), equalTo(15));
}
}
}
}
If I have a mobile number equal to +6519829340 and is outbound, assert that the location is in Singapore and has count of 15.
If I understand you correctly (and that the list of users(?) is called smsentries as it was in the previous question) you could do like this:
.root("smsentries.findAll { it.mobilenum == '%s' }").
.body("firstname", withArgs("+6519829340"), contains("Allen", "Allen"))
.body("lastname", withArgs("+6519829340"), contains("Edwards", "Edwards"))
.body("outbound", withArgs("+6519829340"), containsInAnyOrder("YES", "NO"))
// Additional body matchers
Update after clarification
If I have a mobile number equal to +6519829340 and is outbound, assert
that the location is in Singapore and has count of 15.
You can do like this:
.root("smsentries.find { it.mobilenum == '+6519829340' && it.outbound == 'YES'}").
.body("location", equalTo("Singapore"))
.body("count", equalTo(9))
CouchDB, version 0.10.0, using native erlang views.
I have a simple document of the form:
{
"_id": "user-1",
"_rev": "1-9ccf63b66b62d15d75daa211c5a7fb0d",
"type": "user",
"identifiers": [
"ABC",
"DEF",
"123"
],
"username": "monkey",
"name": "Monkey Man"
}
And a basic javascript design document:
{
"_id": "_design/user",
"_rev": "1-94bd8a0dbce5e2efd699d17acea1db0b",
"language": "javascript",
"views": {
"find_by_identifier": {
"map": "function(doc) {
if (doc.type == 'user') {
doc.identifiers.forEach(function(identifier) {
emit(identifier, {\"username\":doc.username,\"name\":doc.name});
});
}
}"
}
}
}
which emits:
{"total_rows":3,"offset":0,"rows":[
{"id":"user-1","key":"ABC","value":{"username":"monkey","name":"Monkey Man"}},
{"id":"user-1","key":"DEF","value":{"username":"monkey","name":"Monkey Man"}},
{"id":"user-1","key":"123","value":{"username":"monkey","name":"Monkey Man"}}
]}
I'm looking into building an Erlang view that does the same thing. Best attempt so far is:
%% Map Function
fun({Doc}) ->
case proplists:get_value(<<"type">>, Doc) of
undefined ->
ok;
Type ->
Identifiers = proplists:get_value(<<"identifiers">>, Doc),
ID = proplists:get_value(<<"_id">>, Doc),
Username = proplists:get_value(<<"username">>, Doc),
Name = proplists:get_value(<<"name">>, Doc),
lists:foreach(fun(Identifier) -> Emit(Identifier, [ID, Username, Name]) end, Identifiers);
_ ->
ok
end
end.
which emits:
{"total_rows":3,"offset":0,"rows":[
{"id":"user-1","key":"ABC","value":["monkey","Monkey Man"]},
{"id":"user-1","key":"DEF","value":["monkey","Monkey Man"]},
{"id":"user-1","key":"123","value":["monkey","Monkey Man"]}
]}
The question is - how can I get those values out as tuples, instead of as arrays? I don't imagine I can (or would want to) use records, but using atoms in a tuple doesn't seem to work.
lists:foreach(fun(Identifier) -> Emit(Identifier, {id, ID, username, Username, name, Name}) end, Identifiers);
Fails with the following error:
{"error":"json_encode","reason":"{bad_term,{<<\"user-1\">>,<<\"monkey\">>,<<\"Monkey Man\">>}}"}
Thoughts? I know that Erlang sucks for this specific kind of thing (named access) and that I can do it by convention (id at first position, username next, real name last), but that makes the client side code pretty ugly.
The JSON object {"foo":"bar","baz":1} is {[{<<"foo">>,<<"bar">>},{<<"baz">>,1}]}
In Erlang lingua it is a proplist wrapped in a tuple.
It's not pretty, but very efficient :)
To get a feel for it you can play with the JSON lib that ships with CouchDB:
Start CouchDB with the -i
(interactive) flag
On the resulting erlang shell, type: couch_util:json_decode(<<"{\"foo\":\"bar\"}">>).
Profit
// in later versions of CouchDB, this is ejson:decode()
For test_suite_reports bd, that has tests field:
[
{
"name": "basics",
"status": "success",
"duration": 21795
},
{
"name": "all_docs",
"status": "success",
"duration": 385
} ...
I have wrote this to get name and status:
fun({Doc}) ->
Name = fun(L) -> proplists:get_value(<<"name">>, L, null) end,
Status = fun(L) -> proplists:get_value(<<"status">>, L, null) end,
Tests = proplists:get_value(<<"tests">>, Doc, null),
lists:foreach(fun({L}) -> Emit(Name(L), Status(L)) end, Tests)
end.
If you like experimental features (that still work...), you might want to have a look to Erlang exprecs.
I found it extremely helpful in creating a sort of dynamic records for Erlang.