DataTime in Perseo CEP - fiware

I am using CEP to modify type date fields with update mode.
Entities:
{
"id":"controller",
"type":"control",
"lasmodify":{
"type":"DataTime",
"value":""
}
}
{
"id":"Device01",
"type":"device",
"id_controller":{
"type":"Text",
"value":"controller01"
}
"datemodify":{
"type":"DataTime",
"value":"2018-12-04T20:05:00.00Z"
}
}
I want that the Device01 subscription is shooted, the controller01 attribute lasmodify will be modified with datemodify of device01 entity.
Thank you very much in advance
Best regard.

If i have understood correctly, you want to update the controler when CEP recibes a device change notification.
The solution should be something similar to this rule:
{
"name":"update_rule",
"text":"select ev.controler? as controlerID, ev.datemodify? as newDate, \"update_rule\" as ruleName from pattern [every ev=iotEvent(type=\"device\")]",
"action":{
"type":"update",
"parameters":{
"id":"${controlerID}",
"type":"control",
"attributes": [
{
"name":"lasmodify",
"type":"DataTime"
"value":"${newDate}"
}
]
}
}
}
I don't know what version of Perseo you use, but using the latest fiware image for perseo-fe and perseo-core, you could omit the ruleName and use NGSIv2
{
"name":"update_rule",
"text":"select ev.controler? as controlerID, ev.datemodify? as newDate from pattern [every ev=iotEvent(type=\"device\")]",
"action":{
"type":"update",
"parameters":{
"id":"${controlerID}",
"type":"control",
"version": "2",
"attributes": [
{
"name":"lasmodify",
"type":"DataTime"
"value":"${newDate}"
}
]
}
}
}

Related

How best to work with arbitrary Javascript data objects in Typescript

I'm working on a Typescript tool for maintaining state that will receive data as JSON objects and updates to those objects. What I want to be able to do is to combine those objects. Most of the time I expect updates to existing properties but it will also be additions. I will not know the structure of these objects at design time.
So for example I might start from an object like:
{
"kitchen": {
"door": "closed",
"cooker": "off",
"objects": [ "saucepan", "fork", "chopping board", "fresh coriander"]
"people": {}
}
}
Then I get a series of updates that look like this:
// update 1
{
"kitchen": {
"door": "open";
}
}
// update 2
{
"kitchen" : {
"people": { "basil": { "wearing": ["hat", "glasses"], "carrying": [] } }
}
}
// update 3
{
"kitchen" : {
"people": { "basil": { "carrying": [ "fork" ] } }
"objects": [ "saucepan", "chopping board", "fresh coriander"]
}
}
And so on.
By the end of this process I want my object to look like this:
{
"kitchen": {
"door": "open",
"cooker": "off",
"people": { "basil": { "wearing": ["hat", "glasses"], "carrying": [ "fork" ] } }
"objects": [ "saucepan", "chopping board", "fresh coriander"]
}
}
I know these will be pure data objects that are coming into the system and leaving it as JSON.
What I want to be able to do is to walk the structure of the object and identify what has changed and what has been updated. This is super-easy to do in Javascript but TypeScript loves to have everything as a structured interface and I simply won't have those interfaces available in this module. Also they don't really matter, as long as properties get added when they are new and updated when they already exist.
My question is: What is the best way to approach this in Typescript? I'm looking for a way of parsing out the objects so I can treat them as nested dictionaries and compare them accordingly or a recommendation for an existing module in NPM that I can use. I wouldn't be surprised if there is an existing module for this purpose that I couldn't find.
The approach I have come to is pretty much just going into Javascript using any typed objects, so I have a function like this:
public deepUpdate(original: any, update: any): Object {
for (let attr in update) {
if (original.hasOwnProperty(attr)) {
let novel = update[attr];
let orig = original[attr];
if (orig instanceof Object) {
if (Array.isArray(orig)) {
original[attr] = novel;
} else {
original[attr] = this.deepUpdate(orig, novel);
}
} else {
original[attr] = novel;
}
} else {
original[attr] = update[attr];
}
}
return original;
}
It doesn't do any serious comparison of arrays - there's no kind of value-wise comparison, which works for my use case but might not suit everyone - but it solves the problem in a basic way.

How Can I filter my request to a certain cabin class in Sabre Bargain Finder Max REST API?

Looking to Filter my search to a certain cabin class, I put in "Economy" in the CabinPref section below but it is giving me an invalid request error.
This is my request:
{
"OTA_AirLowFareSearchRQ":{
"TPA_Extensions":{
"IntelliSellTransaction":{
"RequestType":{
"Name":"200ITINS"
}
}
},
"TravelPreferences":{
"TPA_Extensions":{
"NumTrips":{
},
"DataSources":{
"NDC":"Disable",
"LCC":"Disable",
"ATPCO":"Enable"
}
},
"CabinPref":{
"Cabin":"Economy",
"PreferLevel":"Preferred"
}
},
"OriginDestinationInformation":[
{
"RPH":"0",
"DepartureDateTime":"2019-11-21T00:00:00",
"OriginLocation":{
"LocationCode":"YHZ"
},
"DestinationLocation":{
"LocationCode":"YTO"
}
}
],
"POS":{
"Source":[
{
"RequestorID":{
"Type":"1",
"ID":"1",
"CompanyName":{
"Code":"TN"
}
},
"PseudoCityCode":"H78H"
}
]
},
"Version":"1",
"TravelerInfoSummary":{
"SeatsRequested":[
1
],
"PriceRequestInformation":{
"CurrencyCode":"INR"
},
"AirTravelerAvail":[
{
"PassengerTypeQuantity":[
{
"Code":"ADT",
"Quantity":1
}
]
}
]
}
}
}
Response:
{
"status":"NotProcessed",
"errorCode":"INVALIDREQ",
"message":"[{\"level\":\"error\",\"schema\":{\"loadingURI\":\"#\",\"pointer\":\"/definitions/org.opentravel.ota._2003._05.AirSearchPrefsType/properties/CabinPref\"},\"instance\":{\"pointer\":\"/OTA_AirLowFareSearchRQ/TravelPreferences/CabinPref\"},\"domain\":\"validation\",\"keyword\":\"type\",\"message\":\"instance type (object) does not match any allowed primitive type (allowed: [\\\"array\\\"])\",\"found\":\"object\",\"expected\":[\"array\"]}]",
"type":"Validation",
"timeStamp":"2019-07-23T10:00:54.624-05:00"
}
Any idea why this is invalid?
In "Cabin" you have "Economy".
You need to use the cabin code, not the cabin name. From the Sabre documentation:
This element specifies preferred cabin type for flexible fare leg. A cabin is either Premium First (P), First (F), Premium Business (J), Business (C), Premium Economy (S) or Economy (Y)
So in your case, you should use "Y" instead of "Economy"
CabinPref accepts array. Please try:
"CabinPref": [
{
"Cabin": "Economy"
}
],
Hope it helps

Aggregate two json payloads into one based on filter

i am trying to aggregate two json payloads into one.
below json is stored in payload,
{
"clients":[
{
"status":"IN",
"clientSoftDeleteIndicator":"N",
"roles":[
{
"clientRoleCodeDesc":"PRIMARY OWNER",
"clientRoleCode":"PO",
"roleEffDate":null,
"clientRoleStatusCode":"IN",
"clientRoleStatusCodeDesc":"INACTIVE",
"roleSoftDeleteIndicator":"N",
"contractID":"49006649"
},
{
"clientRoleCodeDesc":"PRIMARY INSURED",
"clientRoleCode":"PI",
"roleEffDate":"2014-11-05",
"clientRoleStatusCode":"IN",
"clientRoleStatusCodeDesc":"INACTIVE",
"roleSoftDeleteIndicator":"N",
"contractID":"49006649"
},
{
"clientRoleCodeDesc":"PRIMARY INSURED",
"clientRoleCode":"PI",
"roleEffDate":"2014-11-05",
"clientRoleStatusCode":"IN",
"clientRoleStatusCodeDesc":"INACTIVE",
"roleSoftDeleteIndicator":"N",
"contractID":"49006648"
}
],
"clientID":72341935,
"statusDate":"2014-11-05",
"party":{
"tin4":"0346",
"addresses":[
{
"addrSoftDeleteIndicator":"N",
"city":"HOLLYWOOD",
"addressType":null,
"zip":"104620000",
"country":"U",
"line3":null,
"line2":null,
"line1":"5 MODEL OFFICE",
"county":null,
"state":"CA",
"validIndicator":null,
"preferredIndicator":null
}
],
"firstName":"SALLONARO",
"middleName":null,
"lastName":"PARETO",
"personSoftDeleteIndicator":"N",
"birthDate":"1987-11-10",
"sufName":null,
"preName":"MR",
"tin":"103380346",
"taxIdSoftDeleteIndicator":"N",
"gender":"M",
"phones":[
],
"martialStatus":null,
"emails":[
],
"tinType":"U"
},
"statusDesc":"INACTIVE"
}
]
}
and below json is stored in flowVariable contractVariable
{
"contracts":[
{
"policyEffDate":null,
"productCode":"97",
"policyStatusDate":"2014-11-05",
"cntrctSoftDeleteIndicator":"N",
"contractID":"49006649",
"adminSysCode":"FCT",
"dataSourceCode":null,
"policyStatus":"B3",
"lobCode":null,
"contractIssuerCode":null
},
{
"policyEffDate":null,
"productCode":"98",
"policyStatusDate":"2015-11-05",
"cntrctSoftDeleteIndicator":"N",
"contractID":"49006648",
"adminSysCode":"FCT",
"dataSourceCode":null,
"policyStatus":"B4",
"lobCode":null,
"contractIssuerCode":null
}
]
}
i want to copy the attributes from flowVariable, into payload when contractId matches.
below is my code snippet but all i am getting is empty json
%dw 1.0
%output application/json
---
payload.clients.roles map ((role,index) ->
{
contracts: ((flowVars.contractVariable.contracts default []) filter (role.contractID == $.contractID))
map ((contract ,indexOf) -> {
policyEffDate: contract.policyEffDate,
productCode: contract.productCode,
policyStatusDate: contract.policyStatusDate,
cntrctSoftDeleteIndicator: contract.cntrctSoftDeleteIndicator,
contractID: contract.contractID,
adminSysCode: contract.adminSysCode,
dataSourceCode: contract.dataSourceCode,
policyStatus: contract.policyStatus,
lobCode: contract.lobCode,
contractIssuerCode: contract.contractIssuerCode,
clientRoleCodeDesc: role.clientRoleCodeDesc,
clientRoleCode: role.clientRoleCode,
roleEffDate: role.roleEffDate,
clientRoleStatusCode: role.clientRoleStatusCode,
clientRoleStatusCodeDesc: role.clientRoleStatusCodeDesc,
roleSoftDeleteIndicator: role.roleSoftDeleteIndicator,
contractID: role.contractID
})
})
and the output i am getting is
[
{
"contracts": [
]
}
]
Can please someone help me on what is going wrong, i tried multiple ways but couldn't make it work.
I also went through Aggregate two payloads in Mule ESB which is similar to my requirement but it didn't work as well.
any help is highly appreciated.

How to solve "error executing aggreation pipeline: variable 'XYZ' not bound" in MongoDB aggregation?

I am using Restheart and MongoDB and also new in these, I have to write aggregation in MongoDb. I written aggregation in mongoDb with $match.
Here Sample Code:
{
"aggrs": [{
"type": "pipeline",
"uri": "aggregation_by_time",
"stages": [{
"_$match": {
"bus::destination": {
"_$in": {
"_$var": "stand"
}
},
"bus::eta": {
"_$gte": {
"_$var": "fromDate"
},
"_$lte": {
"_$var": "toDate"
}
},
"tickets": {
"_$eq": {
"_$var": "isConfirmedTravel"
}
}
}
}]
}]
}
Here Sample Access Url:
http://..xyz../_aggrs/aggregation_by_time?avars={"stand":["A","B","C","D","E","F"]}
When I access this url then it is not working, displaying some error.
Error:
{"http status code":400,"http status description":"Bad
Request","message":"error executing aggreation pipeline: variable
isConfirmedTravel not bound"}
When I access below url Then it will work.
http://..xyz../_aggrs/aggregation_by_time?avars={"stand":["A","B","C","D","E","F"],"isConfirmedTravel":"true"}
So I want to make optional $match, Like if I don't mention as a parmater "isConfirmedTravel" in url, then it should work. And If I want to send as parameter "isConfirmedTravel" in url then It should also work. But In my case If put field in $match then you should have to mention in url. Thats why I want to set optional "isConfirmedTravel":"true" field. If I call then it should work and if I will not call then url should be work.

How to override "Selectors should not contain IDs" rule in SublimeLinter-CSSLint?

Entering csslint --list-rules into the terminal, I see the following rule:
ids
Selectors should not contain IDs.
So, in my SublimeLinter.sublime-settings user prefs file, I've tried setting "ids" to false, true, "none", "ignore", "exclude", and "" in the below code structure, but to no effect.
{
"user": {
"linters": {
"csslint": {
"ids": /* WHAT TO PUT HERE? */
}
}
}
}
I'm not easily finding documentation for how to calibrate the ids settings. Anyone know? Thanks!
I'm not sure if this is the way it's meant to be instead, but I found a solution by adding "ids" to the linter's "ignored" property, rather than by tuning an "ids" property itself:
{
"user": {
"linters": {
"csslint": {
"ignored": ["ids"]
}
}
}
}