Orbeon: Static dropdown in repeated grid - xpath

I have a problem in repeated grid, I have a drop-down list where the users will choose what model they want.
Then I also have a JSON array which contains the model and other description of different cars.
How can I auto fill the appropriate JSON value to textField according to the chosen value in the drop-down list?
Like for example: The user chose the model Toyota, only the Toyota car model present in the JSON will be displayed at textField.
The form I've created is available at https://demo.orbeon.com/demo/fr/orbeon/builder/edit/3b1ebd5340007f245b34ccd468c36c188b376bd6. And here is the JSON:
{
"corppassUser": {
"corppassData": null,
"corppassEntity": {
"primaryActiviyDesc": "Marine insurance ",
"companyType": "A1",
"corppassPreviousNames": [],
"entityType": "LC",
"primaryActivityCode": "65121",
"businessExpiryDate": "",
"secondaryActivityCode": "93202",
"corppassShareholders": [
{
"allocation": 20000,
"personRef": {
"personName": "ANDY",
"nationality": "SG",
"id": 8,
"idno": "S6001111A"
},
"currency": "SGD",
"id": 3,
"entityRef": null,
"category": "1",
"shareType": "1"
},
{
"allocation": 10000,
"personRef": {
"personName": "TIMOTHY TAN",
"nationality": "SP",
"id": 6,
"idno": "S1112374E "
},
"currency": "SGD",
"id": 1,
"entityRef": null,
"category": "1",
"shareType": "1"
},
{
"allocation": 10000,
"personRef": {
"personName": "CLARISSA LIN",
"nationality": "SG",
"id": 7,
"idno": "S3212386E"
},
"currency": "SGD",
"id": 2,
"entityRef": null,
"category": "1",
"shareType": "1"
}
],
"uen": "T15LP0005A"
},
"id": 1
}
}

Related

Laravel createMany error on nested relation

This is in relation to this question. I'm having this error:
TypeError
Illuminate\Database\Grammar::parameterize(): Argument #1 ($values) must be of type array, int given, called in /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/Grammar.php on line 920
While inserting data using createMany. This is the form request data:
{
"name": "My Order",
"orders": [
{
"date": "2022-05-17",
"product_id": [1],
"price": 1
},
{
"start_date": "2022-05-18",
"product_id": [2],
"price": 2
}
]
}
This is the store method:
$order = auth()->user()->orders()->create($request->validated());
$order_subs = $order->subOrders()->createMany($request->orders);
$order_sub_items = $request->only('orders')['orders'];
foreach ($order_subs as $key => $value) {
$value->subOrderProducts()->createMany([$order_sub_items[$key]);
}
However, if the product_id is not an array, it will store properly. Sample form request data:
{
"name": "My Order",
"orders": [
{
"date": "2022-05-17",
"product_id": 1,
"price": 1
},
{
"start_date": "2022-05-18",
"product_id": 2,
"price": 2
}
]
}
How to fix this error?

NiFi: ReplaceText alternatives to modify JSON

My NiFi application receives two kinda different types of JSON's.
First of them looks like:
[
{
"campaign": {
"resourceName": "customers/8952771329/campaigns/11381694617",
"status": "ENABLED",
"name": "Saint_Spring_Active Minerals_oct-nov_2020_trueview_skip_5766500views",
"id": "11381694617"
},
"metrics": {
"interactionEventTypes": [
"VIDEO_VIEW"
],
"clicks": "6",
"videoQuartileP100Rate": 0.44493171079034244,
"videoQuartileP25Rate": 0.9747718298919024,
"videoQuartileP50Rate": 0.7339309987701469,
"videoQuartileP75Rate": 0.5337562301767105,
"videoViewRate": 0.4471109114825628,
"videoViews": "27872",
"viewThroughConversions": "0",
"contentBudgetLostImpressionShare": 0.0000013066088274492382,
"contentImpressionShare": 0.0999,
"contentRankLostImpressionShare": 0.9001,
"conversionsValue": 0,
"conversions": 0,
"costMicros": "9338700950",
"ctr": 0.00009624947864865732,
"currentModelAttributedConversions": 0,
"currentModelAttributedConversionsValue": 0,
"engagementRate": 0,
"engagements": "0",
},
"segments": {
"device": "CONNECTED_TV",
"date": "2020-12-20"
}
}
]
And second:
[
{
"adGroup": {
"resourceName": "customers/5404177717/adGroups/110501283582",
"campaign": "customers/5404177717/campaigns/11628802542"
},
"metrics": {
"interactionEventTypes": [
"CLICK"
],
"clicks": "1",
"averageCpm": 95497428.02172929,
"gmailForwards": "0",
"gmailSaves": "0",
"gmailSecondaryClicks": "0",
"impressions": "4418",
"interactionRate": 0.00022634676324128565,
"interactions": "1"
},
"adGroupAd": {
"resourceName": "customers/5404177717/adGroupAds/110501283582~480227690139",
"status": "ENABLED",
"ad": {
"resourceName": "customers/5404177717/ads/480227690139",
"id": "480227690139",
"name": "20 sec perek"
},
"adGroup": "customers/5404177717/adGroups/110501283582"
},
"segments": {
"device": "DESKTOP",
"date": "2020-11-21"
}
}
]
I already have 2 tables in my database to save this data. I have an attribute table.name just to not create same block where's only table name is different.
My next block is FlattenJson. After this i'm using ReplaceText with search value (replacement value is empty string): (customers\\\/${client.customer.id}\\\/campaigns\\\/|customers\\\/${client.customer.id}\\\/adGroups\\\/).
Why this? From this line: "adGroup": "customers/5404177717/adGroups/110501283582" i only need last value 110501283582 as ad_group_id. And from this line: "campaign": "customers/5404177717/campaigns/11628802542" i only need 11628802542. ${client.customer.id} can be different, so i'm using EL features.
Also i need to change json value name adGroup to ad.group.id, for this i'm also using ReplaceText.
Can i do it faster without two ReplaceText processors?
Look at the following processors...I think using them can be an alternative:
JoltTransformJSON:
https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.5.0/org.apache.nifi.processors.standard.JoltTransformJSON/
UpdateRecord:
https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.5.0/org.apache.nifi.processors.standard.UpdateRecord/index.html

.Net MongoDB.Driver on Azure Cosmos DB error

IList<FilterDefinition<Family>> filters = new List<FilterDefinition<Family>>();
var filter = Builders<Family>
.Filter.Eq(e=>e.id, "Andersen.1");
filters.Add(filter);
var filterPartiion = Builders<Family>
.Filter.Eq(e => e.LastName, "Andersen");
filters.Add(filterPartiion);
var update = Builders<Family>.Update
.Set<Boolean>(e=>e.IsRegistered, true);
var searchOn = Builders<Family>.Filter.And(filters);
collection.UpdateOne(searchOn, update);
Using .net MongoDB.Driver on Azure Cosmos DB, I would like to do an update on the IsRegistered element of the document based on the the filter of id="Andersen.1" and LastName="Andersen", in which LastName is partition key. I am new to MongoDB, is my code correct?
I got an error:
"query in command must target a single shard key"
[
{
"id": "Andersen.1",
"LastName": "Andersen",
"Parents": [
{
"FamilyName": null,
"FirstName": "Thomas"
},
{
"FamilyName": null,
"FirstName": "Mary Kay"
}
],
"Children": [
{
"FamilyName": null,
"FirstName": "Henriette Thaulow",
"Gender": "female",
"Grade": 6,
"Pets": [
{
"GivenName": "Fluffy"
}
]
}
],
"Address": {
"State": "WA",
"County": "King",
"City": "Seattle"
},
"IsRegistered": false,
"_rid": "S4UzAMRFRAABAAAAAAAAAA==",
"_self": "dbs/S4UzAA==/colls/S4UzAMRFRAA=/docs/S4UzAMRFRAABAAAAAAAAAA==/",
"_etag": "\"0100d5a1-0000-0000-0000-59b9d8cd0000\"",
"_attachments": "attachments/",
"_ts": 1505351885
},
...
...
]

How to join output of models in Laravel?

I have the following code:
$orders = OrderProduct::where(function ($query) use ($request) {
})->with('order_products')->orderBy('status', 'desc')->paginate(50)->toArray();
And order_products function is:
public function order_products()
{
return $this->hasMany("App\Order", "order_id", "order_id");
}
It gives me output result:
{
"user_id": "1",
"created_at": "2016-12-18 14:06:11",
"status": "2",
"note": "34535345",
"order_id": "2",
"address": "Kiev",
"courier_id": null,
"payment_type": "0",
"order_products": [
{
"id": 73,
"product_id": "1265",
"amount": "1"
},
{
"id": 74,
"product_id": "1266",
"amount": "1"
}
]
I need to join order_products with products_details, that to give title of product for each order like as:
"order_products": [
{
"id": 73,
"product_id": "1265",
"amount": "1",
"title": "Product name"
},
{
"id": 74,
"product_id": "1266",
"amount": "1",
"title": "Product name"
}
]
Instead this I get a new model output in response:
"products_details": [
{}, {}
]
How can I join two with models?
without joining, just using your first code:
in order_products, override the toArray() method.
function toArray() {
return [
id => $this->id,
product_id => $this->product_id,
amount => $this->amount,
title => $this->details->name
];
}
wich $this->details->name is the relation between order_products and products_details

Laravel 5: LengthAwarePaginator returned JSON not array

I'm returning JSON from LengthAwarePaginator but the JSON's data property is not an array. I need it to be an array. Any ideas?
// grab query parameters
$pageNumber = $request->input('page');
$pageSize = $request->input('pageSize');
// if query params do not exist call with defaults
if(!$pageNumber) {
$pageNumber = 1;
}
if(!$pageSize) {
$pageSize = 5;
}
$offset = ($pageNumber * $pageSize) - $pageSize;
// slice full array data based on page number and page size
$itemsForCurrentPage = array_slice($arrayOfData, $offset, $pageSize, true);
return new LengthAwarePaginator($itemsForCurrentPage, count($this->orgUsers), $pageSize, $pageNumber);
Returned data:
{
"total": 30,
"per_page": 5,
"current_page": 2,
"last_page": 6,
"next_page_url": "/?page=3",
"prev_page_url": "/?page=1",
"from": 6,
"to": 10,
"data": {
"5": {
"userId": "564110eadcb39832268ea873",
"email": "dsdfgdfg#il.com",
"isActive": true,
"firstName": "dsdfgdfg",
"lastName": "dsdfgdfg",
"permissionType": "dsdfgdfg"
},
"6": {
"userId": "564110ea2169bc358a3b65c2",
"email": "dsdfgdfg#d.com",
"isActive": false,
"firstName": "dsdfgdfg",
"lastName": "dsdfgdfg",
"permissionType": "dsdfgdfg"
},
"7": {
"userId": "564110eaee662f30c4bd6772",
"email": "dsdfgdfg#dsdfgdfg.com",
"isActive": true,
"firstName": "dsdfgdfg",
"lastName": "dsdfgdfg",
"permissionType": "dsdfgdfg"
},
"8": {
"userId": "dsdfgdfg",
"email": "dsdfgdfg#dsdfgdfg.com",
"isActive": true,
"firstName": "dsdfgdfg",
"lastName": "dsdfgdfg"
},
"9": {
"userId": "564110eaf9526eb5ddd673a4",
"email": "dsdfgdfg#dsdfgdfg.com",
"isActive": true,
"firstName": "dsdfgdfg",
"lastName": "dsdfgdfg"
}
}
}
TIA
The problem is that the ids remain the keys of your array when array_slice-ing. But since some keys are missing, especially 0, 1, 2, … the array is henceforth treated as associative (['key1'=>'value1', 'key2'=>'value2', …]) rather than numerically indexed (['value1', 'value2', …]) when encoding to json.
The solution is to succeed your array_slice(…) with an array_values() call.
return new LengthAwarePaginator(array_values($itemsForCurrentPage), count($this->orgUsers), $pageSize, $pageNumber);
Edit: In case your $arrayOfData is an Eloquent/Illuminate Collection, you can use the methods ->slice($offset, $pageSize)->values() on it. Looks nicer!

Resources