Backand - Add two filters to a GET request - backand

I'm doing a GET request to /objects/items and i want to filter the request on both:
[{ "fieldName": "title", "operator": "equals", "value": "someItem" }]
AND
[{ "fieldName": "description", "operator": "equals", "value": "someDescription" }]
Is this possible? Can only get it to work with one filter. Or any other way you can filter on the two in one api call?

The filter is an array that every item create an AND operator, so all you need is to join the {}, like this:
[{ "fieldName": "title", "operator": "equals", "value": "someItem" },
{ "fieldName": "description", "operator": "equals", "value":"someDescription" }]

You can also use the noSQL syntax in case you need to do OR:
{ "q": { "$or": [ { "title": "someItem" }, { "description": "someDescription" } ] } }
See more examples of advanced filters: http://docs.backand.com/en/latest/apidocs/nosql_query_language/index.html#examples

Related

Snowflake SQL - Dynamically turning irregular JSON data into "CASE WHEN" SQL clause

I feel compelled to specify from the very beginning that I am a total newbie to Snowflake and the idea of JSON data tables.
This being said I find myself faced with the following challenge:
I have a Snowflake table called ANIMALS which holds a JSON object with a semi irregular structure on the conditions part:
{
"animals": [
{
"name": "TIGER",
"id": 101,
"conditions": {
"and": [
{
"operator": "=",
"attribute": "ANIMAL_FAMILY",
"value": "feline"
},
{
"operator": "IN",
"attribute": "SUBSPECIES",
"value": ["Bengal", "Sumatran", "Siberian"]
},
{
"operator": "=",
"attribute": "ORDER",
"value": "carnivorous"
}
]
}
},
{
"name": "CAT",
"id": 102,
"conditions": {
"and": [
{
"operator": "=",
"attribute": "ANIMAL_FAMILY",
"value": "feline"
},
{
"or": [
{
"operator": "IN",
"attribute": "SUBSPECIES",
"value": ["Abyssinian", "Manx", "Siamese", "Sphynx"]
},
{
"operator": "=",
"attribute": "ENVIRONMENT",
"value": "domestic"
}
]
}
]
}
},
{
"name": "DOG",
"id": 103,
"conditions": {
"or": [
{
"operator": "=",
"attribute": "IS_MOST_BELOVED_PET",
"value": true
},
{
"and": [
{
"operator": "=",
"attribute": "ANIMAL_FAMILY",
"value": "canine"
},
{
"operator": "=",
"attribute": "ENVIRONMENT",
"value": "domestic"
}
]
},
{
"and": [
{
"operator": "=",
"attribute": "ENVIRONMENT",
"value": "domestic"
},
{
"or": [
{
"operator": "C",
"attribute": "ANIMAL_FAMILY",
"value": "%feline%"
},
{
"operator": "IN",
"attribute": "SUBSPECIES",
"value": ["Akita", "Beagle", "Border Collie", "Cane Corso", "Chihuahua"]
}
]
}
]
},
]
}
},
{
"name": "HORSE",
"id": 104,
"conditions": {
"operator": "=",
"attribute": "ANIMAL_FAMILY",
"value": "equine"
}
}
]
}
There is absolutely no limit for the degree of nesting the AND and OR operators, which unfortunately makes the conditions very irregular.
Given this JSON I need to dynamically generate a CASE WHEN [condition] THEN [value] clause which will look like this:
CASE WHEN ((ANIMAL_FAMILY = 'feline') AND (SUBSPECIES IN ('Bengal', 'Sumatran', 'Siberian')) AND (ORDER = 'carnivorous')) THEN 'TIGER'
WHEN ((ANIMAL_FAMILY = 'feline') AND ((SUBSPECIES IN ('Abyssinian', 'Manx', 'Siamese', 'Sphynx') OR (ENVIRONMENT = 'domestic')))) THEN 'CAT'
WHEN ((IS_MOST_BELOVED_PET = TRUE) OR ((ANIMAL_FAMILY = 'canine') AND (ENVIRONMENT = 'domestic')) OR ((ENVIRONMENT = 'domestic') AND ((ANIMAL_FAMILY NOT LIKE %feline%) OR (SUBSPECIES IN ('Akita', 'Beagle', 'Border Collie', 'Cane Corso', 'Chihuahua'))))) THEN 'DOG'
WHEN ANIMAL_FAMILY = 'equine' THEN 'HORSE'
END AS animal
Is this doable solely relying on Snowflake queries and no other third-party programming languages?
Any hints and pointers would be greatly appreciated.
Thank you in advance for your replies.

How do i define this jsonSchema rule

I have the jsonSchema like below
[{
"path": [
"General",
"label"
],
"type": "label",
"label": "Calculate Losses From Sub-Peril(s)",
"required": true
},
{
"path": [
"General",
"fire"
],
"type": "boolean",
"default": true,
"label": "Fire"
},
{
"path": [
"General",
"fireSmoke"
],
"type": "boolean",
"default": false,
"label": "Fire and Smoke"
}
],
I have the jsonSchema Rule as below. So if the user unchecks both fire and Fire and Smoke i want to fire a notification. How do i define JsonSchema Rule. Can some one fix this? I have the below rule but it gives me parser error. Atleast one checkbox has to be selected.
{
"path": [
"General",
"fire"
],
"effect": "fireNotification",
"notification": {
"type": "warning",
"message": "At least one Sub-Peril must be selected",
"notificationID": "fire",
"dismissible": "false"
},
"condition": {
"operator": "oneOf": {
"properties": {
"fire": {
"enum": [
true
]
},
"fireSmoke": {
"enum": [
true
]
}
}
}
}
}
Your JSON is invalid in two ways, both on the same line:
"operator": "oneOf": {
After "operator":, you need another opening brace ({) (and a matching closing brace later on.
The value of "oneOf": should be an array, so you need to add an opening bracket ([) there (and a matching closing bracket later on).
Further, you say "At least one checkbox has to be selected", but you are using a "oneOf" rule, not "anyOf". With "oneOf", if both properties are true, the validation will fail.

Angular6 JSON schema form for Array of Items

I am trying out Angular6 JSON form for my application and stuck in the issue of having array schema
The basic layout looks like
{
"schema": {
"type": "array",
"properties": {
"type": { "type": "string" },
"number": { "type": "string" },
}
},
"layout": [
{
"type": "array",
"items": [ {
"type": "div",
"displayFlex": true,
"flex-direction": "row",
"items": [
{ "key": "type", "flex": "1 1 50px",
"notitle": true, "placeholder": "Type"
},
{ "key": "number", "flex": "4 4 200px",
"notitle": true, "placeholder": "Phone Number"
}
]
} ]
}
],
"data": [
{ "type": "cell", "number": "702-123-4567" },
{ "type": "work", "number": "702-987-6543" }
]
}
But I am not getting the expected outcome, that is Form is prefilled with the data
[
{ "type": "cell", "number": "702-123-4567" },
{ "type": "work", "number": "702-987-6543" }
]
Refer: https://hamidihamza.com/Angular6-json-schema-form/
Based on your code there are some parts you may need to revisit.
The schema type should be either an object or boolean based on the documentation http://json-schema.org/latest/json-schema-core.html
Within the schema section, it seems that you want the type and number to be your properties of a JSON instance. Having this you can only pass one instance of data to the framework to fill in your properties because the framework cannot decide on which value to use for your property of type string.
In case of looking for having an array of type and number, you can have a property like "phone number" with the type array. below is an example from angular6-json-schema flex layout example which I think you had as your reference.
"schema": {
...
"phone_numbers": {
"type": "array",
"items": {
"type": "object",
"properties": {
"type": { "type": "string", "enum": [ "cell", "home", "work" ] },
"number": { "type": "string" }
},
"required": [ "type", "number" ]
}
And pass your data having something as follows:
"data": {
...
"phone_numbers": [
{ "type": "cell", "number": "702-123-4567" },
{ "type": "work", "number": "702-987-6543" }
],
}

How to do json schema validation on collection+json objects?

I would like to validate collection+json objects with schema that have different formats under the same array. For example:
{
"href": "https://example.com/whatnot",
"data": [
{
"name": "foo",
"value": "xyz:123:456"
},
{
"name": "bar",
"value": "8K"
},
{
"name": "baz",
"value": false
}
]
}
Here, the value is one of exactly pattern (\w+:\d+:\d+), one of exactly ([\w\d]+), and one of exactly boolean. There are no other variations.
Is there any way in json schema to have this list checked against these requirements?
I slept overnight and figured how to make the oneOf schema. I tried to use it inside "properties", but it turned out that cannot be done. For the perfect solution, I guess I'd need "explicitOf" kind of method. But, this is good enough for now.
{
"type": "object",
"required": [
"name",
"value"
],
"oneOf": [
{
"properties":
{
"name":
{
"type": "string",
"pattern": "foo"
},
"value":
{
"type": "string",
"pattern": "^(\\w+:\\d+:\\d+)$"
}
}
},
{
"properties":
{
"name":
{
"type": "string",
"pattern": "bar"
},
"value":
{
"type": "string",
"pattern": "^([\\w\\d]+)$"
}
}
},
{
"properties":
{
"name":
{
"type": "string",
"pattern": "baz"
},
"value":
{
"type": "boolean"
}
}
}
]
}

dojo how to get all tree node of specific type?

I wrote the following code to create a dojo tree.
store = new dojo.data.ItemFileWriteStore({url: link});
treeModel = new dijit.tree.TreeStoreModel({
store: store,
query: {
"type": "ROOT"
},
rootId: "newRoot",
childrenAttrs: ["children"]
});
tree= new dijit.Tree({model: treeModel},"treeOne");
Following is my JSON file structure :
{
identifier: "id",
label: "name",
items: [
{id: "ROOT",name: "Change Windows",type: "ROOT"},
]}
I want to get all the nodes (basically their 'id' part)of specific 'type',lets say type= "ROOT". Is there anyway to get all those node? I thought of doing this using tree._itemNodeMap, but don't know any way to iterate through this whole item map,because it need a id as a input to return any specific node.
If you're talking about obtaining the data items programatically, you can get them straight from the store using fetch.
Sample JSON for ItemFile*Store:
{
"identifier": "id",
"label": "name",
"items": [{
"id": "ROOT",
"name": "Root",
"type": "ROOT",
"children": [{
"id": "P1",
"name": "StackExchange",
"type": "website",
"children": [{
"id": "C1",
"name": "StackOverflow",
"type": "website"
},
{
"id": "C2",
"name": "ServerFault",
"type": "website"
}]
},
{
"id": "P2",
"name": "Sandwich",
"type": "food",
"children": [{
"id": "C3",
"name": "Ham",
"type": "food"
},
{
"id": "C4",
"name": "Cheese",
"type": "food"
}]
},
{
"id": "P3",
"name": "Potluck",
"type": "mixed",
"children": [{
"id": "C5",
"name": "Google",
"type": "website"
},
{
"id": "C6",
"name": "Banana",
"type": "food"
}]
}]
}]
}
Sample code:
dojo.require('dojo.data.ItemFileReadStore');
dojo.ready(function() {
var store = new dojo.data.ItemFileReadStore({
url: 'so-data.json'
});
store.fetch({
query: {
type: 'food'
},
queryOptions: {
deep: true
},
onItem: function(item) {
console.log(store.getLabel(item));
}
});
});
This will log Sandwich, Ham, Cheese, and Banana.