Need to remove an item from array based on condition in groovy - arrays

I am able to fetch the subscription id and name from azure cli. Need to remove the subscriptions which has a particular string in their names. How to achieve this in groovy?
My code is as below
az account list --query '[].{name:name,id:id}
It returns the below values
[
{
"id": "66666666666666",
"name": "sub-demo-1"
},
{
"id": "22222222222222",
"name": "sub-demo-2"
},
{
"id": "000000000000000",
"name": "sub-prod-1"
},
{
"id": "888888888888888",
"name": "sub-prod-2"
}
]
I need to remove all the subscriptions which has the name demo in it. Secondly it should save only the subscription ids to another array after removing the unwanted items.
I want the below output
[
000000000000000,
888888888888888
]

Related

How to create string variable from array in Azure LogicApps?

I have LogicApp which get HTTP Post from Azure Alerts.
I would like to create "DimensionNames" string variable, which includes all names in array.
DimensionNames value could be "name1,name2, name3, name4".
Finally I would use DimenstionNames string in "call Webhook".
How do it?
Request Body Json in "When a HTTP request is received"
{
"dimensions": {
"items": {
"properties": {
"name": {
"type": "string"
},
"value": {
"type": "string"
}
},
"required": [
"name",
"value"
],
"type": "object"
},
"type": "array"
}
}
Using variables and Join action you can convert array to a string variable. I have reproduced from my side and below are steps I followed,
Created an alert and configured a HTTP trigger logic app to it.
Designer of logic app will be,
The payload of http request is,
{
"dimensions": {
"items": {
"properties": {
"name": {
"type": "string"
},
"value": {
"type": "string"
}
},
"required": [
"name",
"value"
],
"type": "object"
},
"type": "array"
}
}
4. Next taken Initialize variable action as shown below,
Taken Join action to divide values from array with comma,
Next taken another initialize variable action to store value as a string,
In webhook action the value of string variable is used as body,
Outputs are shown below,
Http trigger:
Output of initialize variable,
Output if Join,
Output of initialize variable 2,
Reference link

In Azure Logic App how to iterate over a dictionary

I am having a Azure logic app where I want to iterate over a dictionary as shown below.
"test": {"text1":"qabdstw1234",
"text2":"vhry46578"
},
Here, in my Logic app I am able to iterate over a list of dictionary but here I want to iterate over a dictionary.
Does anybody knows how to do it?
I have used parse JSON inorder to fetch test1 data from the JSON which you have provided and then used compose connector to get the same. Here is my Logic app :-
Here is the generated schema while using the sample JSON Payload which you have provided I'm using:-
{
"type": "object",
"properties": {
"title": {
"type": "string"
},
"text1": {
"type": "array",
"items": {
"type": "string"
}
},
"id": {
"type": "string"
},
"status": {
"type": "string"
}
}
}
Add a new action, search for Control and select the For each:
To process an array in your logic app, you can create a "Foreach" loop. This loop repeats one or more actions on each item in the array.
Source: Create loops that repeat workflow actions or process arrays in Azure Logic Apps

Alexa Spelling Skill - How to trigger answer intent when a word is misspelledc

I am currently writing a alexa spelling skill to ask different spellings and to check user input according to the data we have. I created below intents & slots to do the expected work:
Intents:
SpellingIntent - Ask a random word from the list of words
AnswerIntent - Validate the user input
Slots:
Words - to keep track of all the words
Spellings - Spellings of words in dot separated format
For example if the word is apple, then spellings slot would have a.p.p.l.e
My app is working fine if the user spelled the word correctly, but if the user misspelled the word then I am not getting event till answerIntent to validate.
I researched about this and I found that amazon deprecated Amazon.LITERAL built in slot type to trigger any word spoken by user and I have to use SearchQuery. But I am not getting how to get the event fired to my answer intent whatever the user said.
Could anyone help me out to figure this?
I haven't tested this but I would suggest trying the following as a solution.
1 - Stop using AMAZON.SearchQuery, instead define a custom slot value like the below:
{
"types": [
{
"name": "LETTER",
"values": [
{
"name": {
"value": "a",
"synonyms": []
}
},
{
"name": {
"value": "b",
"synonyms": []
}
},
{
"name": {
"value": "c",
"synonyms": []
}
},
// ... and so on
]
}
]
}
2 - Redefine your AnswerIntent to accept varying quantities of the LETTER slot value, like the below:
{
"intents": [
{
"name": "AnswerIntent",
"slots": [
{
"name": "LetterOne",
"type": "LETTER"
},
{
"name": "LetterTwo",
"type": "LETTER"
},
{
"name": "LetterThree",
"type": "LETTER"
},
// ... and so on
],
"samples": [
"{LetterOne}",
"{LetterOne} {LetterTwo}",
"{LetterOne} {LetterTwo} {LetterThree}",
// ... and so on
]
}
]
}
In theory, this set up should trigger the AnswerIntent any time a user speaks a sequence of letters. You should then be able to collect the letters passed through in slot values and compare them against the correct spelling.
As a potential additional step you could try adding synonyms to the slot values for phonetically matching words such as the below. Then access the slots in your code via the key value.
{
"name": {
"value": "b",
"synonyms": [
"be",
"bee"
]
}
}

How to update a double nested value inside an array of multiple documents?

Imagine the following collection of city records:
{
"city": "London",
"inhabitants": [
{
"id": "34543534",
"user": {
"name": "Jonathan Deer",
"email": "john#btinternet.com"
}
},
{
"id": "0454534",
"user": {
"name": "Tanya Patel",
"email": "tanya#btinternet.com"
}
},
{
"id": "4345345",
"user": {
"name": "Catherine King",
"email": "catherine#gmail.com"
}
}
]
}
{
"city": "Manchester",
"inhabitants": [
{
"id": "980003",
"user": {
"name": "Benjamin Thaw",
"email": "benny#btinternet.com"
}
},
{
"id": "734488",
"user": {
"name": "Craig Longstone",
"email": "craig#gmail.com"
}
},
{
"id": "4400093",
"user": {
"name": "Arnold Greentree",
"email": "arnold#btinternet.com"
}
},
]
},
What I'm trying to do is loop through each inhabitants array of each city, and see if any of the people there has an email address containing btinternet.com in it. For those users I want to sent a new flag isBT: true and for everyone else (e.g., gmail.com users) isBT: false:
"user": {
"name": "Tanya Patel",
"email": "tanya#btinternet.com"
"isBT" true
}
I tried the following queries - first query sets all of them to isBT: false while the second one searches for "btinternet.com" in email address and sets isBT: true:
db.city.update({ "inhabitants.user.email": {$exists: true}}, {$set: { "inhabitants.$.user.isBT": false}}, {multi: true})
db.city.update({ "inhabitants.user.email": {$regex: "btinternet.com"}}, {$set: { "inhabitants.$.user.isBT": true}}, {multi: true})
The problem is that when I execute the second query, there are several inhabitants records that are left with isBT: false even though they contain the necessary "btinternet.com" email address. It almost seems like only the first user record that matches the criteria gets updated... Is there a way to update ALL user records for all "inhabitants" arrays?
I looked at using the positional operator $[], but our DB is on version 2.6.3 but this operator was introduced only in 3.6...
The short answer is "no".
The long answer is "no, because your MongoDB version doesn't support such an operation". You'll need to either...
1. retrieve all matching documents and perform a full array update through server-side processing of the data (e.g. use the MongoDB cursor.forEach()),
2. extend your match for "inhabitants.user.isBT": true (use
$elemMatch) and repeatedly perform the update query until the
number of modified documents is 0 (i.e. there are no more array
elements to update), or
3. update your MongoDB version and any
server-side code that relies on features of the current version that
have changed between 2.6 and 3.6.
Any solution to this problem will require more effort than a single query. There's no getting around it. It's a tough pill to swallow, but there really isn't a nice alternative.

Firebase retrieve all where child has specific object

I need some help with a Firebase query.
How can I retrieve all users where in the child "groups" a specific group exists?
Every user object in de database looks like this:
"067f010c-5580-450a-84ba-6e94880886c2": {
"goal":
{
"distance": "10",
"time": "20"
},
"groups":
{
"-KH0O99wyxT61xVfjnH5":
{
"group_id": "-KH0O99wyxT61xVfjnH5",
"name": "Test"
},
"-KH0OFDI9jjReE75y7Dj":
{
"group_id": "-KH0OFDI9jjReE75y7Dj",
"name": "Beest"
}
},
"name": "Arnoud",
"uid": "067f010c-5580-450a-84ba-6e94880886c2"
}
That could be an expensive query as your data set grows. What about having a separate child ('groups') that stores all of your groups and in each group object you keep a reference id to each member that is a part of that group? Then you can query the data from that direction.

Resources