How to structure get data from one array - angularjs-directive

My api results are showing this way. On my view i have one form section with many form group fields - like banner, logo, menu , footer. So how can i access banner section data for banner only and logo section data for logo only.
(10) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0: {id: "49ad6f11-d647-4947-b221-019322fe3f08", settingName: "Achievements", settingValue: null, dataType: "string", useFor: "Menu", …}
1: {id: "ed54f6e9-cd0c-47cf-b8f7-2f58bc65dcf5", settingName: "Footer", settingValue: null, dataType: "string", useFor: "Footer", …}
2: {id: "c6dc0c94-ae79-4150-b5ff-3efaf216dc56", settingName: "Logo", settingValue: null, dataType: "file", useFor: "Logo", …}
3: {id: "3a2f41eb-cf20-42a5-bdbd-593e38dc05f3", settingName: "Title", settingValue: null, dataType: "string", useFor: "Title", …}
4: {id: "87025725-b286-4013-b2de-6ee4c76b3393", settingName: "Banner Title", settingValue: null, dataType: "string", useFor: "Banner", …}
5: {id: "c079bd1c-d098-41da-9cd4-7bb7f6bdf131", settingName: "Banner Image", settingValue: null, dataType: "file", useFor: "Banner", …}
6: {id: "388d4d2b-e0bb-4e6a-8d61-ca6286e4f13c", settingName: "Banner Sub Title", settingValue: null, dataType: "string", useFor: "Banner", …}
7: {id: "7a8098b3-2a79-4b84-afde-e5ec105098de", settingName: "Store", settingValue: null, dataType: "string", useFor: "Menu", …}
8: {id: "e1efd155-867b-43be-8c82-ebcf48c0d3a0", settingName: "About", settingValue: null, dataType: "string", useFor: "Menu", …}
9: {id: "6896130f-2d9d-43c7-9c8e-ecb24395cb04", settingName: "?", settingValue: null, dataType: "string", useFor: "Menu", …}
[1]: https://i.stack.imgur.com/hLqPv.png

You need to define model in such way that it will hold your UI structure.
In this case, I think you can group your response based on useFor to group similar catagery objects.
e.g.
{group key: group objects}
For UI, You can have dynamic componenet which will have two inputs:
group key i.e. value of useFor
group objects i.e. list of setting object.
Based on value of dataType you will have different components rendered on UI.
Regardin form based implementation. You can use same data structure to created Reactive Form modules which will have "id" of some unique name for each key with validations.
On UI, you will use same keys for binding.

Related

How do i select multiple if display-name is equal to in json file

Json Outpt I have
{
"data": [
{
"agent-config": {
"are-all-plugins-disabled": false,
"is-management-disabled": false,
"is-monitoring-disabled": false,
"plugins-config": null
},
"availability-config": {
"is-live-migration-preferred": null,
"recovery-action": "RESTORE_INSTANCE"
},
"availability-domain": "RRSt1",
"capacity-reservation-id": null,
"compartment-id": "ocid1.compartmeiox33bbyq",
"dedicated-vm-host-id": null,
"defined-tags": {
"Oracle-Tags": {
"CreatedBy": "ops",
"CreatedOn": "2022-01-05T19:34:56.443Z"
}
},
"display-name": "Dnode0",
"extended-metadata": {},
"fault-domain": "FAULT-DOMAIN-2",
"freeform-tags": {
"Type": "TEST-mongo"
},
"id": "ocid1.instance.oc1.me-jeozlnq7t4eqkfjlaxyq6a",
"image-id": "ocid1.image.om3jrq4i5gf4k2kq",
"instance-options": {
"are-legacy-imds-endpoints-disabled": false
},
"ipxe-script": null,
"launch-mode": "PARAVIRTUALIZED",
"launch-options": {
"boot-volume-type": "PARAVIRTUALIZED",
"firmware": "UEFI_64",
"is-consistent-volume-naming-enabled": true,
"is-pv-encryption-in-transit-enabled": false,
"network-type": "PARAVIRTUALIZED",
"remote-data-volume-type": "PARAVIRTUALIZED"
},
"lifecycle-state": "RUNNING",
"metadata": {},
"platform-config": null,
"preemptible-instance-config": null,
"region": "me-1",
"shape": "VM1",
"shape-config": {
"baseline-ocpu-utilization": null,
"gpu-description": null,
"gpus": 0,
"local-disk-description": null,
"local-disks": 0,
"local-disks-total-size-in-gbs": null,
"max-vnic-attachments": 2,
"memory-in-gbs": 15.0,
"networking-bandwidth-in-gbps": 1.0,
"ocpus": 1.0,
"processor-description": "2.0 GHz Intel\u00ae Xeon\u00ae Platinum 8167M (Skylake)"
},
"source-details": {
"boot-volume-size-in-gbs": null,
"boot-volume-vpus-per-gb": null,
"image-id": "ocid1.image.oc1.me-j3jrq4i5gf4k2kq",
"kms-key-id": null,
"source-type": "image"
},
"system-tags": {},
"time-created": "2022-01-05T19:34:56.894000+00:00",
"time-maintenance-reboot-due": null
},
{
"agent-config": {
"are-all-plugins-disabled": false,
"is-management-disabled": false,
"is-monitoring-disabled": false,
"plugins-config": null
},
"availability-config": {
"is-live-migration-preferred": null,
"recovery-action": "RESTORE_INSTANCE"
},
"availability-domain": "RRS-1",
"capacity-reservation-id": null,
"compartment-id": "ocid1.compartmentselksvqyp2aiox33bbyq",
"dedicated-vm-host-id": null,
"defined-tags": {
"Oracle-Tags": {
"CreatedBy": "ops",
"CreatedOn": "2022-01-05T19:38:08.746Z"
}
},
"display-name": "Application-Sandbox-WEBSERVER-20220715T184918",
"extended-metadata": {},
"fault-domain": "FAULT-DOMAIN-2",
"freeform-tags": {
"Type": "TEST-mongo"
},
"id": "ocid1.instanceathpfbjo7le5iosl4oa",
"image-id": "ocid1.image.oc1.mekdzloqgdctm3jrq4i5gf4k2kq",
"instance-options": {
"are-legacy-imds-endpoints-disabled": false
},
"ipxe-script": null,
"launch-mode": "PARAVIRTUALIZED",
"launch-options": {
"boot-volume-type": "PARAVIRTUALIZED",
"firmware": "UEFI_64",
"is-consistent-volume-naming-enabled": true,
"is-pv-encryption-in-transit-enabled": false,
"network-type": "PARAVIRTUALIZED",
"remote-data-volume-type": "PARAVIRTUALIZED"
},
"lifecycle-state": "RUNNING",
"metadata": {},
"platform-config": null,
"preemptible-instance-config": null,
"region": "me-jh-1",
"shape": "VM.Standard2.1",
"shape-config": {
"baseline-ocpu-utilization": null,
"gpu-description": null,
"gpus": 0,
"local-disk-description": null,
"local-disks": 0,
"local-disks-total-size-in-gbs": null,
"max-vnic-attachments": 2,
"memory-in-gbs": 15.0,
"networking-bandwidth-in-gbps": 1.0,
"ocpus": 1.0,
"processor-description": "2.0 GHz Intel\u00ae Xeon\u00ae Platinum 8167M (Skylake)"
},
"source-details": {
"boot-volume-size-in-gbs": null,
"boot-volume-vpus-per-gb": null,
"image-id": "ocid1.image.oc1.me5vkdzloqgdctm3jrq4i5gf4k2kq",
"kms-key-id": null,
"source-type": "image"
},
"system-tags": {},
"time-created": "2022-01-05T19:38:09.186000+00:00",
"time-maintenance-reboot-due": null
}
]}
Ansible debug:
where jsondata.data returns the json output
ictimecreated: "{{ jsondata.data| selectattr('display-name', 'equalto', 'MasimoSafetyNet-Sandbox-*-*' ) | list}}"
Now this is actually huge list where I have Key value like "display-name": "Application-Sandbox-WEBSERVER-20220715T184918"
Now i want to create list form json object by selecting only if display-name has Application-Sandbox-(*wildcard)-(*wildcard)
This first two term remains same only rest should be wildcard which changes. How do i create list from json object. I try to search jmespath and jinja2 template, i also tried but didnt work for me.
After the list is return I should able to get list of image_id
[ imageid_1 , imageid2_]
Only image ids where display name has Application-Sandbox
*PS
If euqual to is "Application-Sandbox-WEBSERVER-20220715T184918" The element get selected but I want to add wildcard instead of WEBSERVER - 20222 So i can other similar elements
I also trying to
"{{ jsondata.data| (selectattr('display-name', 'search', 'Application-Sandbox--' ) ) and (selectattr('lifecycle-state', 'equalto', 'RUNNING' ) )| list}}"
Use tests search if you want to test a wildcard. For example,
selectattr('display-name', 'search', 'MasimoSafetyNet-Sandbox-*-*' )
Then map the attribute you want
map(attribute='image-id')
Example of a complete playbook for testing
shell> cat pb.yml
- hosts: localhost
vars:
ictimecreated: "{{ jsondata.data|
selectattr('display-name', 'search', 'Application-Sandbox-*-*' )|
map(attribute='image-id')|
list }}"
tasks:
- include_vars:
file: data7.json
name: jsondata
- debug:
var: ictimecreated
gives
ictimecreated:
- ocid1.image.oc1.mekdzloqgdctm3jrq4i5gf4k2kq
Q: "Make multiple conditions"
A: Simplify the data for testing. For example,
data:
- availability-domain: R1
display-name: a-s-node0
image-id: ocid1.image.a
lifecycle-state: RUNNING
- availability-domain: R2
display-name: a-s-node0
image-id: ocid1.image.b
lifecycle-state: STOPPED
- availability-domain: R3
display-name: n-s-node1
image-id: ocid1.image.c
lifecycle-state: STOPPED
- availability-domain: R4
display-name: n-s-node2
image-id: ocid1.image.d
lifecycle-state: RUNNING
Then, select the items by attribute display-name and pick the attribute image-id
d2: "{{ data|
selectattr('display-name', 'search', 'a-s-*' )|
map(attribute='image-id')|
list }}"
gives
d2:
- ocid1.image.a
- ocid1.image.b
You can pipe the selection. For example,
d3: "{{ data|
selectattr('display-name', 'search', 'a-s-*' )|
selectattr('lifecycle-state', 'eq', 'RUNNING' )|
map(attribute='image-id')|
list }}"
gives
d3:
- ocid1.image.a
You might want to simplify such complex structures before testing. For example, select keys from the dictionaries by using ansible.utils.keep_keys
test_keys: [availability-domain, display-name, image-id, lifecycle-state]
data: "{{ jsondata.data|map('ansible.utils.keep_keys', target=test_keys)|list }}"

Azure Table Storage JSON Returns Array Per Entry Instead of Single Array

I need to parse an output of JSON from Azure Table Storage. I am able to retrieve the data, but the JSON retuned appears to give me an array per entry of data instead of an expected single array. NOTE: a true array should have the [] around it, so I am unsure on how to output/display this data as I can't seem to reach the values nested.
My call to the table to get results is as follows:
var options = { payloadFormat: "application/json;odata=nometadata" };
tableService.queryEntities('myTable', tableQuery, null, options, function(error, result, response) {
if(!error) {
console.log(response.body.value);
}
Ex. I expect this per https://blogs.msdn.microsoft.com/windowsazurestorage/2013/12/05/windows-azure-tables-introducing-json/:
"value":[
{
"PartitionKey":"Jonathan",
"RowKey":"Foster",
"Timestamp":"2013-12-03T06:45:00.7254269Z",
"Address":"1234 SomeStreet St, Bellevue, WA 75001",
"Email":"Jonathan#fourthcoffee.com",
"PhoneNumber":"425-555-0101",
"CustomerSince":"2005-01-05T00:00:00Z",
"Rating":3
},
{
"PartitionKey":"Lisa",
"RowKey":"Miller",
"Timestamp":"2013-12-03T06:45:00.8834427Z",
"Address":"4567 NiceStreet St, Seattle, WA 54332",
"Email":"Lisa#northwindtraders.com",
"PhoneNumber":"425-555-0101",
"CustomerSince":"2003-01-05T00:00:00Z",
"Rating":2
},
{
"PartitionKey":"Walter",
"RowKey":"Harp",
"Timestamp":"2013-12-03T06:45:00.5384082Z",
"Address":"1345 Fictitious St, St Buffalo, NY 98052",
"Email":"Walter#contoso.com",
"PhoneNumber":"425-555-0101",
"CustomerSince":"2010-01-05T00:00:00Z",
"Rating":4
}
]
}
But I am getting this:
{value: Array(8)}
value: Array(8)
0: {PartitionKey: "Client1", RowKey: "1", Timestamp: "2019-06-05T14:07:08.5541163Z", Location: "eastus", OSType: "WindowsServer", …}
1: {PartitionKey: "Client1", RowKey: "2", Timestamp: "2019-06-04T21:23:42.1804373Z", PowerState: "VM deallocated", OSType: "WindowsServer", …}
2: {PartitionKey: "Client1", RowKey: "3", Timestamp: "2019-06-04T21:23:42.2394792Z", PowerState: "VM deallocated", OSType: "SQL2016SP1-WS2016", …}
3: {PartitionKey: "Client1", RowKey: "4", Timestamp: "2019-06-04T21:23:42.2104586Z", PowerState: "VM deallocated", OSType: "WindowsServer", …}
4: {PartitionKey: "Client1", RowKey: "5", Timestamp: "2019-06-04T21:23:42.2674991Z", PowerState: "VM running", OSType: "WindowsServer", …}
5: {PartitionKey: "Client1", RowKey: "6", Timestamp: "2019-06-04T21:23:42.3045253Z", PowerState: "VM deallocated", OSType: "WindowsServer", …}
6: {PartitionKey: "Client1", RowKey: "7", Timestamp: "2019-06-04T21:23:42.3325452Z", PowerState: "VM deallocated", OSType: "WindowsServer", …}
7: {PartitionKey: "Client1", RowKey: "8", Timestamp: "2019-06-04T21:23:42.3665693Z", PowerState: "VM deallocated", OSType: "SQL2017-WS2016", …}
length: 8
__proto__: Array(0)
__proto__: Object
You're asking for the raw json string, but that library call is giving you the parsed json object.
If you want the string, just call JSON.stringify() on the object:
var str = JSON.stringify(response.body.value);
The source for the TableService.queryEntities is at https://github.com/Azure/azure-storage-node/blob/1e315487b8801b8357b8974c7d925313cb143483/lib/services/table/tableservice.js#L811

Swagger: schema definition for two different objects

I have to create an API that can return JSON object in two different formats based on the input parameter. Suppose if we pass "report=monthly" in query string the output will be like:
[{
"Month": "Jan",
"Details": [{
"userId": 12345,
"userName": "ABC"
}]
}, {
"Month": "Feb",
"Details": [{
"userId": 12346,
"userName": "ABD"
}]
}]
If the above parameter is not passed the output will be like:
{
"Details": [{
"userId": 12345,
"userName": "ABC"
}, {
"userId": 12346,
"userName": "ABD"
}]
}
How can I define schema for a single API to return JSON in the above formats? I can not create 2 endpoints.
The easier way is to define Month as an optional property.
paths:
/report:
parameters:
...
get:
responses:
200:
description: OK
schema:
type: array
items:
$ref: '#/definitions/ReportEntry'
definitions:
ReportEntry:
type: object
properties:
Month:
type: string
example: Jan
Details:
type: array
items:
$ref: '#/definitions/UserInfo'
required:
- Details # <---- "Details" is required, "Month" is optional
UserInfo:
type: object
properties:
userId:
type: integer
example: 12345
userName:
type: string
example: ABC
required:
- userId
- userName

Swagger different definitions for JSON and XML

I'm currently documenting an API with Swagger 2.0.
The API produces application/json and application/xml.
The definition section is this:
definitions:
newsFeed:
type: object
description: the object is wrapped...
properties:
feedId:
type: string
example: '987654'
xml:
attribute: true
title:
type: string
description:
type: string
feedUrl:
type: string
example: http://heise.de.feedsportal.com/c/35207/f/653902/index.rss
logoUrl:
type: string
example: http://example.com/logo.png
language:
type: string
example: de_DE
pos:
type: string
example: '0'
active:
type: boolean
Swagger-UI generates this XML.
<?xml version="1.0" encoding="UTF-8"?>
<newsFeed feedId="987654">
<title>string</title>
<description>string</description>
<feedUrl>http://heise.de.feedsportal.com/c/35207/f/653902/index.rss</feedUrl>
<logoUrl>http://example.com/logo.png</logoUrl>
<language>de_DE</language>
<pos>0</pos>
<active>true</active>
</newsFeed>
And this JSON:
{
"feedId": "987654",
"title": "string",
"description": "string",
"feedUrl": "http://heise.de.feedsportal.com/c/35207/f/653902/index.rss",
"logoUrl": "http://example.com/logo.png",
"language": "de_DE",
"pos": "0",
"active": true
}
Both is correct, but the API deliveres a different JSON.
{
"newsFeed": {
"feedId": "987654",
"title": "string",
"description": "string",
"feedUrl": "http://heise.de.feedsportal.com/c/35207/f/653902/index.rss",
"logoUrl": "http://example.com/logo.png",
"language": "de_DE",
"pos": "0",
"active": true
}
}
How can I document this with Swagger?

Parsing Json in Groovy

I have a following json string:
[ { id: '123', name: 'bla bla', type: 'Source', isLeaf: true },
{ id: '3425', name: 'test test', type: 'Reference', isLeaf: false },
{ id: '12678', name: 'tags', type: 'Source', isLeaf: false },
]
I am trying to parse this using JsonSlurper but getting error:
groovy.json.JsonException: Lexing failed on line: 1, column: 5, while reading 'i', no possible valid JSON value or punctuation could be recognized.
How do I parse it and access the id:'3425'?
Your Json is invalid, you need to use double quote to delimit strings and you also need to put quotes around the keys in your Json like so:
[ { "id": "123", "name": "bla bla", "type": "Source", "isLeaf": true },
{ "id": "3425", "name": "test test", "type": "Reference", "isLeaf": false },
{ "id": "12678", "name": "tags", "type": "Source", "isLeaf": false },
]
You can then do:
def ids = new groovy.json.JsonSlurper().parseText( json ).id
assert ids[ 1 ] == '3425'