Neo4j Rest API datetime data types - neo4j

I am using neo4j REST API to create nodes and relationships. I refer following documentation.
https://neo4j.com/docs/http-api/3.5/actions/
The nodes that I am dealing with have dynamic properties. Therefore I am using following payload with parameters to create nodes.
{
"statements" : [ {
"statement" : "CREATE (n:Person $props) RETURN n",
"parameters" : {
"props" : {
"name" : "My Node",
"dob" : "datetime('20211229T153000')",
"age": 55,
"awsome": true
}
}
} ]
}
This is perfectly work with String, Integer, Boolean data types. However I need to use datetime data type for "dob" . If I use datetime function within double quotes (as in above example) neo4j treat it as string value and does not store as datatime data type.
Is there a solution for this?

You cannot put non-literal values inside the json data (props). However, you can change your cypher statement (create) to update the node and set the dob to a datetime field. But first you need to convert that string into datetime.
{
"statements" : [ {
"statement" : "CREATE (n:Person $props) SET n.dob = datetime({epochSeconds:apoc.date.parse(replace('20211229T153000','T', ' '),'s', 'yyyyMMDD HHmmss')}) RETURN n",
"parameters" : {
"props" : {
"name" : "My Node",
"age": 55,
"awsome": true
}
}
} ]
}
I replace the char 'T' into space so that it can be parsed. Then convert it into epoch seconds so that datetime will convert it properly. I tested it in my local neo4j so it should also work for you.
Result:

Related

Posting to a complex typed array

I have an ORDER structure in ABAP that has another ITEMS structure within it which will contain multiple items per order.
I'm populating this structure through a SAP Gateway service, which works for an ORDER + a single ITEM.
{
"d": {
"Venueid": "dsfgg",
"Items" : {
"__metadata" : {
"type" : "ZGW_XXXX_SRV.Items"},
"Venueid" : "dsd",
"Type" : ""
}
}
}
However, what would be the syntax to provide an array of more than one ITEM?
The issue was because multiples can only be handled with the DEEP_INSERT method, not the normal CREATE.

DDMathParser: Parsing dynamic formula which contain $ to refer objects value within dictionary

I am struggling a little bit to use DDMathParser framework for expression requirement I have. I have JSON of fields & based on expressions certain fields can be set required, hidden or set the value of it.
Expressions in required tag in sample JSON are not fixed & so not getting how to achieve dynamic approach for expression.
[
{
"name": "firstName",
"value": "Ameer",
**"required": true**
},
{
"name": "lastName",
"value": "Shaikh",
**"required": "$firstName != ‘’"**
},
{
"name": "designation",
"value": "",
**"required": "$firstName == ‘Ameer’ && $lastName == ‘Shaikh’"**
},
{
"name": "location",
"value": "",
**"hidden": false**
}
]
Actually, expression in JSON contains $ to represent one of the
dictionary objects value from JSON. Wherein framework internally
treats it as a local variable.
These expressions may have different combinations as well. There may be several expression apart from "required" parameters. I need to run all relevant expressions for any change in value in UI.
EDIT
let expression = "$firstName == ‘Ameer’ && $lastName == ‘Shaikh’"
let dict = ["firstName": "Amir", "lastName": ""]
let e = try! Expression(string: expression)
let result = try! Evaluator.default.evaluate(e, substitutions: dict)
Though it should parse a correct value from JSON, I have hard coded substitutions string to at least get a breakthrough. Here, substitutions expect String & Double & give error as "Cannot convert a value of type [String: String] to expected arg type substitutions (Dcitionary).
Is there any way to pass String: String substitutions?
DDMathParser is not built to do string evaluations. It's technically possible to make it work, but it's a bit beyond the scope of the framework.
For this situation, I think you'd be better off using NSPredicate, which does allow string comparisons and variable substitutions.

How to handle object list request

I am trying to read a list of objects
[
{
"name" : "Jhone",
"age" : 25
},
{
"name" : "Chris",
"age" : 24
}
]
How to handle that types of request?
You can loop through the array to access each object by its key. Assuming that array of objects is set to a variable called array
array.each { |element| puts element["name"] }
Btw, the objects are incorrectly formatted. You need a comma after each name value.

RestKit RKObjectMapping.. Nested & throwaway objects

So, I have an api call that'll output some raw json in the format below...
A bit messy, but I'm only interested in the Mapping portion of this json. If I had access to the raw data, I'd serialise the json cut to the dictionary / array I want to iterate through.. However the client is using restkit and this doesn't seem quite as easy as I'm imagining it....
Also What should I do with the Images section? Again, if was doing this with serialised json, I could open up the dictionary and set what's inside to an object with name description etc... can I do this as well?
{
"rsp": {
sn : "SerialNumber",
name : "Service Name",
from : "2000-01-01T00:00:00.000+01:00",
to : "2000-01-02T00:00:00.000+01:00",
mappings : {
"mapping" : {
"1" : {
from : 2000-06-01T00:01:00.000+01:00
to : 2000-06-01T01:02:00.000+01:00
content : {
name : "name"
description : "description"
images : {
image : "b47ab5a8.png"
}
}
},
"2" : {
from : 2000-06-01T00:01:00.000+01:00
to : 2000-06-01T01:02:00.000+01:00
content : {
name : "name"
description : "description"
images : {
image : "b47ab5a8.png"
}
}
},
// etc...
My question is
// what goes here
RKObjectMapping *itemMapping = [RKObjectMapping mappingForClass:[MYItem class]];
[itemMapping addAttributeMappingsFromDictionary:#{#"description":#"itemDescription",
#"name":#"name"}];
And how do I add the image to MYItem?
For the image your mapping is something like:
[itemMapping addAttributeMappingsFromDictionary:#{#"description":#"itemDescription",
#"name":#"name",
#"images.image":#"image"}];
i.e. key paths work
But, not that they only work for dictionaries. You can't index into arrays arbitrarily in the same way.
The key path is also in the response descriptor and that's how you drill down to the mapping, i.e. rsp.mappings.mapping (again, because it's dictionaries).

RestKit JSON Mapping

I have given JSON and cannot parse partial data. It seems dictionary into dictionary:
{
"products": [
{
"id": 6796,
"title": "my title",
"description": "desc",
"code": "12345",
"valueType": "null",
"discounts": [
{
"minPrice": null,
"maxPrice": null,
"value": 20,
"avail": false
}
]
}
]
}
I am using the latest version of RESTKit but I cannot properly parse under discounts.
my RestKit settings are:
responseMapping.addAttributeMappingsFromDictionary([
"id" : "id",
"code" : "code",
"title" : "title",
"valueType" : "valueType",
"description" : "desc",
"discounts.minPrice" : "minPrice",
"discounts.maxPrice" : "maxPrice",
"discounts.value" : "value",
"discounts.avail" : "avail",
])
but all values below discounts always return Nil. What I am doing wrong?
You can't directly map using discounts.XXX because discounts is an array and you have no way to index into that array and extract a single value.
You either need to change the source JSON to compress the values out of the dictionary, or create a custom object that you can map each item in the discounts array to.
Technically you could map the whole discounts array, which would give you an array of dictionaries, that you could then unpack in the setter method, but the array of custom objects is usually a better approach.

Resources