We have a scenario where we need to replace the TargetOriginID of CacheBehaviour in the distribution of a json file. We need to replace the Existing TargetOriginID with New Values. I have tried with below jq command but not getting any closer
for targetoriginID in $(jq '(.CacheBehaviors.Items[].TargetOriginId)' distconfig.json);
do
echo "#######fetch the new value from change behaviour json file"#######
NewValue=$(jq -r "map(select(.targetoriginid == ""$targetoriginID""))[].targetorigindr" changebehaviour.json)
echo "#########replace value in dist config json file with new value from change behaviour###########"
jq -r '(.CacheBehaviors.Items[].TargetOriginId | select(. == "$targetoriginID")) = "$NewValue"' distconfig.json > "tmp" && mv "tmp" distconfig.json
{
"CachedMethods": {
"Quantity": 3,
"Items": [
"HEAD",
"GET",
"OPTIONS"
]
}
},
"SmoothStreaming": false,
"Compress": false,
"LambdaFunctionAssociations": {
"Quantity": 0
},
"FunctionAssociations": {
"Quantity": 0
},
"FieldLevelEncryptionId": "",
"ForwardedValues": {
"QueryString": true,
"Cookies": {
"Forward": "none"
},
"Headers": {
"Quantity": 9,
"Items": [
"Authorization",
"Origin",
"access-control-allow-credentials",
"expires",
"access-control-max-age",
"access-control-allow-headers",
"cache-control",
"access-control-allow-methods",
"pragma"
]
},
"QueryStringCacheKeys": {
"Quantity": 1,
"Items": [
"*"
]
}
},
"MinTTL": 0,
"DefaultTTL": 86400,
"MaxTTL": 31536000
},
"CacheBehaviors": {
"Quantity": 2,
"Items": [
{
"PathPattern": "jkl/*",
"TargetOriginId": "nkl/Prod",
"TrustedSigners": {
"Enabled": false,
"Quantity": 0
},
"TrustedKeyGroups": {
"Enabled": false,
"Quantity": 0
},
"ViewerProtocolPolicy": "redirect-to-https",
"AllowedMethods": {
"Quantity": 7,
"Items": [
"HEAD",
"DELETE",
"POST",
"GET",
"OPTIONS",
"PUT",
"PATCH"
],
"CachedMethods": {
"Quantity": 3,
"Items": [
"HEAD",
"GET",
"OPTIONS"
]
}
},
"SmoothStreaming": false,
"Compress": false,
"LambdaFunctionAssociations": {
"Quantity": 0
},
"FunctionAssociations": {
"Quantity": 0
},
"FieldLevelEncryptionId": "",
"ForwardedValues": {
"QueryString": true,
"Cookies": {
"Forward": "all"
},
"Headers": {
"Quantity": 9,
"Items": [
"Authorization",
"Origin",
"access-control-allow-credentials",
"access-control-max-age",
"access-control-allow-headers",
"cache-control",
"access-control-allow-methods",
"expirers",
"pragma"
]
},
"QueryStringCacheKeys": {
"Quantity": 1,
"Items": [
"*"
]
}
},
"MinTTL": 0,
"DefaultTTL": 86400,
"MaxTTL": 31536000
},
{
"PathPattern": "fgh/*",
"TargetOriginId":"xyz/Prod",
"TrustedSigners": {
"Enabled": false,
"Quantity": 0
},
"TrustedKeyGroups": {
"Enabled": false,
"Quantity": 0
},
"ViewerProtocolPolicy": "redirect-to-https",
"AllowedMethods": {
"Quantity": 7,
"Items": [
"HEAD",
"DELETE",
"POST",
"GET",
"OPTIONS",
"PUT",
"PATCH"
],
"CachedMethods": {
"Quantity": 3,
"Items": [
"HEAD",
"GET",
"OPTIONS"
]
}
},
"SmoothStreaming": false,
"Compress": false,
"LambdaFunctionAssociations": {
"Quantity": 0
},
"FunctionAssociations": {
"Quantity": 0
},
"FieldLevelEncryptionId": "",
"ForwardedValues": {
"QueryString": true,
"Cookies": {
"Forward": "none"
},
"Headers": {
"Quantity": 10,
"Items": [
"access-control-allow-origin",
"authorization",
"Origin",
"access-control-allow-credentials",
"access-control-max-age",
"access-control-allow-headers",
"cache-control",
"access-control-allow-methods",
"expirers",
"pragma"
]
},
"QueryStringCacheKeys": {
"Quantity": 1,
"Items": [
"*"
]
}
},
"MinTTL": 0,
"DefaultTTL": 0,
"MaxTTL": 0
}
]
}
Looking for a solution to make bulk change in CacheBehaviour for all TargetOriginID's
Providing a second answer with some assumption. Let's start with a minimal example input:
{
"CacheBehaviors": {
"Quantity": 2,
"Items": [
{
"PathPattern": "jkl/*",
"TargetOriginId": [
"nkl",
"something else"
]
},
{
"PathPattern": "fgh/*",
"TargetOriginId": [
"xyz",
"abc"
]
}
]
},
"IsIPV6Enabled": true
}
Assuming you want to define a mapping "{old1: new1, old2: new2, old3: new3, …}", the following program could work and is easily extendable:
(.CacheBehaviors.Items[].TargetOriginId[]) |= ({
nkl: "wkl",
xyz: "123",
"something else": "is changed too",
"not found": "never replaced"
}[.] // .)
And if you like to have your mapping at the top/start of your program, bind it to a variable:
{
nkl: "wkl",
xyz: "123",
"something else": "is changed too",
"not found": "rever replaced"
} as $mapping
| (.CacheBehaviors.Items[].TargetOriginId[]) |= ($mapping[.] // .)
Output after running through above's program:
{
"CacheBehaviors": {
"Quantity": 2,
"Items": [
{
"PathPattern": "jkl/*",
"TargetOriginId": [
"wkl",
"is changed too"
]
},
{
"PathPattern": "fgh/*",
"TargetOriginId": [
"123",
"abc"
]
}
]
},
"IsIPV6Enabled": true
}
Is that what you are after? This chooses the new value by key from an object/dictionary/map and falls back to the current value if no mapping was found.
… |= ({ old: "new" }[.] // .)
The mapping itself could be provided as an argument to jq from a separate file:
jq --slurpfile mapping old_to_new_ids.json \
'(.CacheBehaviors.Items[].TargetOriginId[]) |= ($mapping[0][.] // .)'
With the contents of file old_to_new_ids.json simply being:
{
"nkl": "wkl",
"xyz": "123",
"something else": "is changed too",
"not found": "never replaced"
}
As of this writing, the posted JSON is invalid, so it's not clear exactly what is needed, but the following is illustrative:
jq --arg newvalue xyz '
(.. | objects | select(has("TargetOriginId")) | .TargetOriginId) |= $newvalue
'
Fixed (i.e. made valid) and reduced your JSON input down to the necessary minimum (the M in MRE), that is 50 lines.
{
"CacheBehaviors": {
"Quantity": 2,
"Items": [
{
"PathPattern": "jkl/*",
"TargetOriginId": [
"nkl"
],
"TrustedSigners": {
"Enabled": false,
"Quantity": 0
},
"TrustedKeyGroups": {
"Enabled": false,
"Quantity": 0
},
"ViewerProtocolPolicy": "redirect-to-https"
},
{
"PathPattern": "fgh/*",
"TargetOriginId": [
"xyz"
],
"TrustedSigners": {
"Enabled": false,
"Quantity": 0
},
"TrustedKeyGroups": {
"Enabled": false,
"Quantity": 0
},
"ViewerProtocolPolicy": "redirect-to-https"
}
]
},
"CustomErrorResponses": {
"Quantity": 0
},
"Comment": "vvvv",
"Logging": {
"Enabled": true,
"IncludeCookies": false,
"Bucket": "abc.s3.amazonaws.com",
"Prefix": "std"
},
"WebACLId": "",
"HttpVersion": "http2",
"IsIPV6Enabled": true
}
You probably want to run a jq program similar to the following:
(.CacheBehaviors.Items[].TargetOriginId | select(. as $id | "nkl" | IN($id[]))) = ["wkl"]
It selects all TargetOriginIds which contain the value "nkl" and changes the list to only contain "wkl".
Output:
{
"CacheBehaviors": {
"Quantity": 2,
"Items": [
{
"PathPattern": "jkl/*",
"TargetOriginId": [
"wkl"
],
"TrustedSigners": {
"Enabled": false,
"Quantity": 0
},
"TrustedKeyGroups": {
"Enabled": false,
"Quantity": 0
},
"ViewerProtocolPolicy": "redirect-to-https"
},
{
"PathPattern": "fgh/*",
"TargetOriginId": [
"xyz"
],
"TrustedSigners": {
"Enabled": false,
"Quantity": 0
},
"TrustedKeyGroups": {
"Enabled": false,
"Quantity": 0
},
"ViewerProtocolPolicy": "redirect-to-https"
}
]
},
"CustomErrorResponses": {
"Quantity": 0
},
"Comment": "vvvv",
"Logging": {
"Enabled": true,
"IncludeCookies": false,
"Bucket": "abc.s3.amazonaws.com",
"Prefix": "std"
},
"WebACLId": "",
"HttpVersion": "http2",
"IsIPV6Enabled": true
}
From the question it is unclear if "TargetOriginId": ["nkl", "xyz"] should become ["wkl"] or ["wkl", "xyz"]. Or whether ["nkl", "xyz"] is a match because it contains different values too. Maybe you only want to select those where the full TargetOriginId array matches?
If you only want to match items with single-valued target origin ids, the program becomes a bit simpler:
(.CacheBehaviors.Items[].TargetOriginId | select(. == ["nkl"])) = ["wkl"]
If your target origin ids are always an array and you want to change say "[abc,nkl,xyz]" to "[abc,REPLACED,xyz]", then select only those array elements and assign them the new value.
New input (as I understood it, the Q is quite vague on this):
{
"CacheBehaviors": {
"Quantity": 2,
"Items": [
{
"PathPattern": "jkl/*",
"TargetOriginId": [
"nkl",
"something else"
]
},
{
"PathPattern": "fgh/*",
"TargetOriginId": [
"xyz",
"abc"
]
}
]
},
"IsIPV6Enabled": true
}
jq:
(.CacheBehaviors.Items[].TargetOriginId[] | select(. == "nkl")) = "wkl"
Output:
{
"CacheBehaviors": {
"Quantity": 2,
"Items": [
{
"PathPattern": "jkl/*",
"TargetOriginId": [
"wkl",
"something else"
]
},
{
"PathPattern": "fgh/*",
"TargetOriginId": [
"xyz",
"abc"
]
}
]
},
"IsIPV6Enabled": true
}
The column definition is:
{
"columns": [
{
"cellAttributes": {
"alignment": "left"
},
"editable": false,
"fieldName": "aiq_BandNumber__c",
"label": "Tier Band",
"sortable": false,
"typeAttributes": {}
},
{
"cellAttributes": {
"alignment": "left"
},
"editable": true,
"fieldName": "aiq_LowerBound__c",
"label": "Lower Bound",
"sortable": false,
"type": "currency",
"typeAttributes": {
"currencyCode": {
"fieldName": "CurrencyIsoCode"
},
"currencyDisplayAs": "code",
"step": "0.01",
"maximumFractionDigits": "2"
}
},
{
"cellAttributes": {
"alignment": "left"
},
"editable": false,
"fieldName": "aiq_UpperBound__c",
"label": "Upper Bound",
"sortable": false,
"type": "currency",
"typeAttributes": {
"currencyCode": {
"fieldName": "CurrencyIsoCode"
},
"currencyDisplayAs": "code",
"step": "0.01",
"maximumFractionDigits": "2"
}
}
]
}
Datatable with multicurrency
Once we click to edit cell
Once editing a cell Dollar Sign appears for a moment ($), no matter which currency code is (USD, EUR, PLN etc.) and then Currency displays how it should
Nobody knows how to avoid that?
Many thanks
I have a project which uses Particle.JS to create a canvas with moving image particles. The problem i am currently having is that every image is being reloaded constantly after a certain amount of time while it's already loaded.
config.json
"particles": {
"number": {
"value": 10,
"density": {
"enable": false,
"value_area": 100
}
},
"color": {
"value": "#ffffff"
},
"shape": {
"type": ["image0", "image1", "image2", "image3", "image4", "image5"],
"stroke": {
"width": 0,
"color": "#000000"
},
"polygon": {
"nb_sides": 5
},
"image": {
"src": "images/0.png",
"width": 100,
"height": 100
}
},
I used this case to filter out all image types in the switch.(pJS.fn.particle.prototype.draw)
particles.js
case (p.shape.match(/image/) || {}).input:
if(pJS.tmp.img_type == 'svg'){
var img_obj = p.img.obj;
}else{
var img_obj = pJS.tmp.img_obj;
}
var element = document.createElement('img');
var number = p.shape.replace("image", "")
element.src = './styles/eles/theme/images/particlelogo/'+number+'.png';
img_obj = element;
if(img_obj){
draw();
}
break;
Original particle.js github link
"shape": {
"type": "images",
"stroke": {
"width": 0,
"color": "#000"
},
"polygon": {
"nb_sides": 6
},
"images": [
{
"src": "img/shapes/0.svg",
"width": 100,
"height": 100
},
{
"src": "img/shapes/1.svg",
"width": 100,
"height": 100
}
]
},
how can i make a column default to SYS_GUID()using liquibase? i tried
{
"column": {
"name": "ID",
"type": "varchar(32)",
"constraints": {
"nullable": false,
"primariKey": true,
"unique": true,
"defaultValueComputed": "SYS_GUID()"
}
}
},
also tried changing sys guid to uuid
"column": {
"name": "ID",
"type": "varchar(32)"
"constraints": {
"nullable": false,
"primariKey": true,
"unique": true,
"defaultValueComputed": "UUID"
}
}
sorry for the dumb question, it was like this:
"column": {
"name": "ID",
"type": "varchar(32)",
"defaultValueComputed": "SYS_GUID()",
"constraints": {
"nullable": false,
"primariKey": true,
"unique": true
}
}
i was dumb enough to put the default in the constraints
My sample Json object is shown below:
{
"o": [
{
"level": 0,
"outlineItemId": 8,
"parentItemId": null,
"parentItem": null,
"order": 0,
"text": "section 1",
"isLeaf": "false",
"expanded": "true"
},
{
"level": 1,
"outlineItemId": 9,
"parentItemId": 8,
"parentItem": {
"level": 0,
"outlineItemId": 8,
"parentItemId": null,
"parentItem": null,
"order": 0,
"text": "section 1",
"isLeaf": "false",
"expanded": "true"
},
"order": 0,
"text": "sub 1",
"isLeaf": "false",
"expanded": "true"
},
{
"level": 2,
"outlineItemId": 10,
"parentItemId": 9,
"parentItem": {
"level": 1,
"outlineItemId": 9,
"parentItemId": 8,
"parentItem": {
"level": 0,
"outlineItemId": 8,
"parentItemId": null,
"parentItem": null,
"order": 0,
"text": "section 1",
"isLeaf": "false",
"expanded": "true"
},
"order": 0,
"text": "sub 1",
"isLeaf": "false",
"negateDevice": null,
"expanded": "true"
},
"order": 0,
"text": "sub sub 1",
"isLeaf": "true",
"expanded": "true"
}
]
}
Earlier when the tree was configured as:
treeReader: {
level_field: "level",
parent_id_field: "parentItemId",
leaf_field: "isLeaf",
expanded_field: "expanded"
},
I was displaying the correct indentation and image icons, however they were not expanded when the json obj always had "expanded":"true" so i tried the below code.
treeReader: {
level_field: "o.level",
parent_id_field: "o.parentItemId",
leaf_field: "o.isLeaf",
expanded_field: "o.expanded"
},
Now I am not getting the Image icons and the tree which was expanded earlier is now flat.
My Json reader just in case i goofed up..
jsonReader: {
root: 'o',
id: 'o.outlineItemId',
parentItemId: 'o.parentItem.outlineItemId',
text: 'o.text',
repeatitems: false,
page: function(obj) { return 1; },
total: function(obj) { return 1; },
records: function(obj) { return obj.o.length; },
},
Any help will be appreciated.
Shah
Got it!
For the reader i had to include cell:'' and remove the o. references. and also loaded:true in the json object.