How to mask all values with a certain key name in a nested hierarchical object using the DataWeave update operator? - mask

I'm trying to selectively update some values in a nested hierarchical data structure.
I have nested input data such as
var flights =
{
"flights": {
"flight": {
"airline-name": "american",
"flight-code": "AA103",
"plane-type": null,
"longitude": "33.94250107",
"price": "+750.00",
"destination": {
"airport-name": "los angeles international airport",
"city": "los angeles",
"altitude": "125",
"longitude":"33.94250107"
}
},
"flight": {
"available-seats": "+18.00",
"longitude": "33.94250107",
"airline-name": "delta",
"plane-type": "boeing 747",
"destination": {
"airport-name": "los angeles international airport",
"longitude": "33.94250107"
}
}
}
}
I want to mask all the longitudes at all levels with one case statement.
flights dw::util::Values::update {
case dest at .flights.*flight.*destination.longitude -> "******"
case ptype at .flights.*flight.*"plane-type" if((ptype ~= null)) -> "*******"
}
only matches inside the destination value.
{
"flights": {
"flight": {
"airline-name": "american",
"flight-code": "AA103",
"plane-type": "*******",
"longitude": "33.94250107",
"price": "+750.00",
"destination": {
"airport-name": "los angeles international airport",
"city": "los angeles",
"altitude": "125",
"longitude": "******"
}
},
"flight": {
"available-seats": "+18.00",
"longitude": "33.94250107",
"airline-name": "delta",
"plane-type": "boeing 747",
"destination": {
"airport-name": "los angeles international airport",
"longitude": "******"
}
}
}
}
Also, is there a way to do something like flights..*destination instead of hardcoding the path?

You can try using the mask function:
%dw 2.0
output application/json
import * from dw::util::Values
var flights =
{
"flights": {
"flight": {
"airline-name": "american",
"flight-code": "AA103",
"plane-type": null,
"longitude": "33.94250107",
"price": "+750.00",
"destination": {
"airport-name": "los angeles international airport",
"city": "los angeles",
"altitude": "125",
"longitude":"33.94250107"
}
},
"flight": {
"available-seats": "+18.00",
"longitude": "33.94250107",
"airline-name": "delta",
"plane-type": "boeing 747",
"destination": {
"airport-name": "los angeles international airport",
"longitude": "33.94250107"
}
}
}
}
---
(flights mask "longitude" with "****") mask "plane-type" with "****"
Output:
{
"flights": {
"flight": {
"airline-name": "american",
"flight-code": "AA103",
"plane-type": "****",
"longitude": "****",
"price": "+750.00",
"destination": {
"airport-name": "los angeles international airport",
"city": "los angeles",
"altitude": "125",
"longitude": "****"
}
},
"flight": {
"available-seats": "+18.00",
"longitude": "****",
"airline-name": "delta",
"plane-type": "****",
"destination": {
"airport-name": "los angeles international airport",
"longitude": "****"
}
}
}
}

Related

Rest API returning wrong result

I was planning to migrate from the json API to the rest API, however, the results are not matching, the reverse geocode of the rest API is returning the wrong result. has anyone faced that issue before? Find sample below:
https://revgeocode.search.hereapi.com/v1/revgeocode?at=-32.05786%2C115.93382&lang=en-US&apiKey={KEY}
enter code here {
"items": [
{
"title": "Reece Australia",
"id": "here:pds:place:036qd63w-93b4e78634c7482aa36a7140fde9701b",
"resultType": "place",
"address": {
"label": "Reece Australia, Thornlie WA 6108, Australia",
"countryCode": "AUS",
"countryName": "Australia",
"state": "Western Australia",
"city": "Perth",
"district": "Thornlie",
"postalCode": "6108"
},
"position": {
"lat": -32.05779,
"lng": 115.93393
},
"access": [
{
"lat": -32.05779,
"lng": 115.93393
}
],
"distance": 13,
"categories": [
{
"id": "700-7400-0366",
"primary": true
}
]
}
]
}
https://reverse.geocoder.ls.hereapi.com/6.2/reversegeocode.json?apiKey={APIKEY}&mode=retrieveAddresses&prox=-32.05786,115.93382&maxresults=1
enter code here {
"Response": {
"MetaInfo": {
"Timestamp": "2020-06-25T05:17:32.232+0000",
"NextPageInformation": "2"
},
"View": [
{
"_type": "SearchResultsViewType",
"ViewId": 0,
"Result": [
{
"Relevance": 1.0,
"Distance": 2.1,
"MatchLevel": "street",
"MatchQuality": {
"Country": 1.0,
"State": 1.0,
"City": 1.0,
"District": 1.0,
"Street": [
1.0
],
"PostalCode": 1.0
},
"Location": {
"LocationId": "NT_K800C2SShmW5hJiQktPlsB_l_133454375_L",
"LocationType": "point",
"DisplayPosition": {
"Latitude": -32.0578752,
"Longitude": 115.9338325
},
"MapView": {
"TopLeft": {
"Latitude": -32.05782,
"Longitude": 115.9337
},
"BottomRight": {
"Latitude": -32.05798,
"Longitude": 115.9339
}
},
"Address": {
"Label": "Bannister Rd, Canning Vale WA 6155, Australia",
"Country": "AUS",
"State": "WA",
"City": "Perth",
"District": "Canning Vale",
"Street": "Bannister Rd",
"PostalCode": "6155",
"AdditionalData": [
{
"value": "Australia",
"key": "CountryName"
},
{
"value": "Western Australia",
"key": "StateName"
}
]
},
"MapReference": {
"ReferenceId": "133454375",
"Spot": 0.66,
"SideOfStreet": "neither",
"CountryId": "1469256839",
"StateId": "1469256834",
"CityId": "1469263736",
"DistrictId": "1469282231"
}
}
}
]
}
]
}
}
Result given by Rest API is correct as you are getting accurate result at that coordinate.
while in JSON API you are passing proximities with retrieveAddresses which always search for the closest street address or addresses in the given proximities.
for more details you can visit the documentations for both API.
https://developer.here.com/documentation/geocoding-search-api/api-reference-swagger.html
https://developer.here.com/documentation/geocoder/dev_guide/topics/resource-reverse-geocode.html

Why is averageRating always 0?

I am using the 'Explore Popular Places by Category' API and it always returns averageRating as 0 for all items in the result.
I made this call with various categories such as restaurants and sights-museums, but it always returns 0 for averageRating. Does HERE not provide this detail, and if so, why is it returned in the response?
Some details:
I am making a call to this url:
https://places.ls.hereapi.com/places/v1/discover/explore?at=52.5159%2C13.3777&cat=sights-museums&apiKey={api_key}
and it returns something like this:
{
"results": {
"next": "https://places.ls.hereapi.com/places/v1/discover/explore;context=Y2F0PXNpZ2h0cy1tdXNldW1zJmZsb3ctaWQ9Mjk0ZjU1NTgtMmY0Mi01Y2FiLWJlYWUtOGEyM2ViY2EzMzgzXzE1ODMyNjMyNjEwMzZfMF84NTcyJm9mZnNldD0yMCZzaXplPTIw?at=52.5159%2C13.3777&app_id=LKO34glU2MBEVbcOD5mQ&app_code=A2ta_nQ8HRYwenju5HFG5Q",
"items": [
{
"position": [
52.51629,
13.37817
],
"distance": 54,
"title": "Brandenburg Gate",
"averageRating": 0,
"category": {
"id": "landmark-attraction",
"title": "Landmark/Attraction",
"href": "https://places.ls.hereapi.com/places/v1/categories/places/landmark-attraction?app_id=LKO34glU2MBEVbcOD5mQ&app_code=A2ta_nQ8HRYwenju5HFG5Q",
"type": "urn:nlp-types:category",
"system": "places"
},
"icon": "https://download.vcdn.data.here.com/p/d/places2/icons/categories/38.icon",
"vicinity": "Pariser Platz<br/>Mitte, 10117 Berlin",
"having": [],
"type": "urn:nlp-types:place",
"href": "https://places.ls.hereapi.com/places/v1/places/276u33db-8ee2e0de906e459cbade0593986debe9;context=Zmxvdy1pZD0yOTRmNTU1OC0yZjQyLTVjYWItYmVhZS04YTIzZWJjYTMzODNfMTU4MzI2MzI2MTAzNl8wXzg1NzImcmFuaz0w?app_id=LKO34glU2MBEVbcOD5mQ&app_code=A2ta_nQ8HRYwenju5HFG5Q",
"id": "276u33db-8ee2e0de906e459cbade0593986debe9",
"alternativeNames": [
{
"name": "Brandenburger Tor",
"language": "de"
}
]
},
{
"position": [
52.51373,
13.37976
],
"distance": 279,
"title": "Holocaust Memorial",
"averageRating": 0,
"category": {
"id": "museum",
"title": "Museum",
"href": "https://places.ls.hereapi.com/places/v1/categories/places/museum?app_id=LKO34glU2MBEVbcOD5mQ&app_code=A2ta_nQ8HRYwenju5HFG5Q",
"type": "urn:nlp-types:category",
"system": "places"
},
"icon": "https://download.vcdn.data.here.com/p/d/places2/icons/categories/10.icon",
"vicinity": "Cora-Berliner-Straße 1<br/>Mitte, 10117 Berlin",
"having": [],
"type": "urn:nlp-types:place",
"href": "https://places.ls.hereapi.com/places/v1/places/276u33de-df7d57fd38494a93b2018fe549a0fd75;context=Zmxvdy1pZD0yOTRmNTU1OC0yZjQyLTVjYWItYmVhZS04YTIzZWJjYTMzODNfMTU4MzI2MzI2MTAzNl8wXzg1NzImcmFuaz0x?app_id=LKO34glU2MBEVbcOD5mQ&app_code=A2ta_nQ8HRYwenju5HFG5Q",
"id": "276u33de-df7d57fd38494a93b2018fe549a0fd75",
"openingHours": {
"text": "Tue-Sun: 10:00 - 20:00",
"label": "Opening hours",
"isOpen": false,
"structured": [
{
"start": "T100000",
"duration": "PT10H00M",
"recurrence": "FREQ:DAILY;BYDAY:TU,WE,TH,FR,SA,SU"
}
]
},
"alternativeNames": [
{
"name": "Memorial to the Murdered European Jews",
"language": "en"
},
{
"name": "Memorial to the Murdered Jews of Europe",
"language": "en"
},
{
"name": "Denkmal für die ermordeten Juden Europas",
"language": "de"
}
]
},
{
"position": [
52.51666,
13.40784
],
"distance": 2041,
"title": "Nicholas Quarter",
"averageRating": 0,
"category": {
"id": "museum",
"title": "Museum",
"href": "https://places.ls.hereapi.com/places/v1/categories/places/museum?app_id=LKO34glU2MBEVbcOD5mQ&app_code=A2ta_nQ8HRYwenju5HFG5Q",
"type": "urn:nlp-types:category",
"system": "places"
},
"icon": "https://download.vcdn.data.here.com/p/d/places2/icons/categories/10.icon",
"vicinity": "Nikolaikirchplatz<br/>Mitte, 10178 Berlin",
"having": [],
"type": "urn:nlp-types:place",
"href": "https://places.ls.hereapi.com/places/v1/places/276u33dc-049683d3c6be4bdba823808678a1b164;context=Zmxvdy1pZD0yOTRmNTU1OC0yZjQyLTVjYWItYmVhZS04YTIzZWJjYTMzODNfMTU4MzI2MzI2MTAzNl8wXzg1NzImcmFuaz0xOQ?app_id=LKO34glU2MBEVbcOD5mQ&app_code=A2ta_nQ8HRYwenju5HFG5Q",
"id": "276u33dc-049683d3c6be4bdba823808678a1b164",
"alternativeNames": [
{
"name": "Nikolaiviertel",
"language": "en"
},
{
"name": "Nikolaiviertel",
"language": "de"
}
]
}
]
},
"search": {
"context": {
"location": {
"position": [
52.5159,
13.3777
],
"address": {
"text": "Ebertstraße 22<br/>Mitte, 10117 Berlin<br/>Germany",
"house": "22",
"street": "Ebertstraße",
"postalCode": "10117",
"district": "Mitte",
"city": "Berlin",
"county": "Berlin",
"stateCode": "Berlin",
"country": "Germany",
"countryCode": "DEU"
}
},
"type": "urn:nlp-types:place",
"href": "https://places.ls.hereapi.com/places/v1/places/loc-dmVyc2lvbj0xO3RpdGxlPUViZXJ0c3RyYSVDMyU5RmUrMjI7bGF0PTUyLjUxNTk7bG9uPTEzLjM3Nzc7c3RyZWV0PUViZXJ0c3RyYSVDMyU5RmU7aG91c2U9MjI7Y2l0eT1CZXJsaW47cG9zdGFsQ29kZT0xMDExNztjb3VudHJ5PURFVTtkaXN0cmljdD1NaXR0ZTtzdGF0ZUNvZGU9QmVybGluO2NvdW50eT1CZXJsaW47Y2F0ZWdvcnlJZD1idWlsZGluZztzb3VyY2VTeXN0ZW09aW50ZXJuYWw;context=c2VhcmNoQ29udGV4dD0x?app_id=LKO34glU2MBEVbcOD5mQ&app_code=A2ta_nQ8HRYwenju5HFG5Q"
}
}
}
Does HERE not provide the averageRatings of restaurants or sights-museums?
From the docs it appears if the place hasn't received a rating it'll be 0
Note: If the place has no ratings (yet), both the average and the count values are zero. But if the place cannot be rated (i.e. a street), the whole rating object is not present.
https://developer.here.com/documentation/places/dev_guide/topics/object-rating.html

HERE Maps matchLevel parameter not working

I am trying to filter only cities in HERE Map's autocomplete API. I read on their documentation that there is matchLevel parameter...
However, nothing changes if I include it.
This is my call:
http://autocomplete.geocoder.api.here.com/6.2/suggest.json?app_id=MY_APP_ID&app_code=MY_APP_CODE&matchLevel=city&query=New York
I still get responses which are not city type.
{
"suggestions": [
{
"label": "United States, New York",
"language": "en",
"countryCode": "USA",
"locationId": "NT_rNsDLtnazM.kjVC-K6YWOA",
"address": {
"country": "United States",
"state": "New York"
},
"matchLevel": "state"
},
{
"label": "United States, New York, New York, New York",
"language": "en",
"countryCode": "USA",
"locationId": "NT_YpQcXqbaOb.I4m5EW8BHEC",
"address": {
"country": "United States",
"state": "New York",
"county": "New York",
"city": "New York",
"postalCode": "10007"
},
"matchLevel": "city"
},
{
"label": "United States, New York, New York",
"language": "en",
"countryCode": "USA",
"locationId": "NT_ABhedB4xGEL83YY5az47iD",
"address": {
"country": "United States",
"state": "New York",
"county": "New York"
},
"matchLevel": "county"
},
...
Any help is appreciated.
matchLevel is a response field, not a query parameter.
use postprocessing of the answer, like array.filter() to keep only elements of the answer which match "city"

Here Maps autocomplete geocode has some strange issue with language translation

Using the here maps autocomplete.geocoder.api v6.2 and passing &language=en parameter, a search returns results with the "label" instead of English language with French language.
This is GET endpoint I'm calling with all the other parameters i use
https://autocomplete.geocoder.api.here.com/6.2/suggest.json
?query=c
&mapview=51.756414,-0.652059,51.309901,0.331888
&app_code=MY_APP_CODE
&app_id=MY_APP_ID
maxresults=15
&country=GBR
&prox=51.508530,-0.076132,30000
&language=en
The result of the above GET endpoint call is this json
{
"suggestions": [
{
"label": "United Kingdom, Comté d'Oxford",
"language": "en",
"countryCode": "GBR",
"locationId": "NT_HTKAfbquVEou80WZXdrniC",
"address": {
"country": "United Kingdom",
"state": "England",
"county": "Comté d'Oxford"
},
"distance": 86196,
"matchLevel": "county"
},
{
"label": "United Kingdom, Comté de Hertford",
"language": "en",
"countryCode": "GBR",
"locationId": "NT_szH9Ci92RVY5reHH1VSa6A",
"address": {
"country": "United Kingdom",
"state": "England",
"county": "Comté de Hertford"
},
"distance": 26970,
"matchLevel": "county"
},
{
"label": "United Kingdom, Comté de Hampshire",
"language": "en",
"countryCode": "GBR",
"locationId": "NT_IBS0mvpblzLbehAjAMG7.C",
"address": {
"country": "United Kingdom",
"state": "England",
"county": "Comté de Hampshire"
},
"distance": 114129,
"matchLevel": "county"
},
{
"label": "United Kingdom, Comté de Berk",
"language": "en",
"countryCode": "GBR",
"locationId": "NT_n-TkgE8S4qt9kGGUkawVGB",
"address": {
"country": "United Kingdom",
"state": "England",
"county": "Comté de Berk"
},
"distance": 61719,
"matchLevel": "county"
},
{
"label": "United Kingdom, Comté de Buckingham",
"language": "en",
"countryCode": "GBR",
"locationId": "NT_vX7N0mZ1b4HC5V1DXwy3iA",
"address": {
"country": "United Kingdom",
"state": "England",
"county": "Comté de Buckingham"
},
"distance": 75626,
"matchLevel": "county"
},
{
"label": "United Kingdom, CR0 1, Croydon",
"language": "en",
"countryCode": "GBR",
"locationId": "NT_gbk1f7HBWIP8q34qF94w6A",
"address": {
"country": "United Kingdom",
"state": "England",
"county": "Surrey",
"city": "Croydon",
"postalCode": "CR0 1"
},
"distance": 15228,
"matchLevel": "city"
},
{
"label": "United Kingdom, London, City of London",
"language": "en",
"countryCode": "GBR",
"locationId": "NT_OIY4l1Ys6bIUnZCJo8RQ7B",
"address": {
"country": "United Kingdom",
"state": "England",
"county": "London",
"city": "London",
"district": "City of London",
"postalCode": "EC1A 4"
},
"distance": 1986,
"matchLevel": "district"
},
{
"label": "United Kingdom, CR0 1, Croydon, Croydon",
"language": "en",
"countryCode": "GBR",
"locationId": "NT_A-KWPtq3xkU9R1OFqELWpA",
"address": {
"country": "United Kingdom",
"state": "England",
"county": "Surrey",
"city": "Croydon",
"district": "Croydon",
"postalCode": "CR0 1"
},
"distance": 15228,
"matchLevel": "district"
},
{
"label": "United Kingdom, Comté de Bedford",
"language": "en",
"countryCode": "GBR",
"locationId": "NT_ajXmsYY9XFqUFqvj1ba7wA",
"address": {
"country": "United Kingdom",
"state": "England",
"county": "Comté de Bedford"
},
"distance": 47643,
"matchLevel": "county"
},
{
"label": "United Kingdom, Comté de Warwick",
"language": "en",
"countryCode": "GBR",
"locationId": "NT_9PDEEpbiURmpFWb9vPQpeD",
"address": {
"country": "United Kingdom",
"state": "England",
"county": "Comté de Warwick"
},
"distance": 147331,
"matchLevel": "county"
},
{
"label": "United Kingdom, CT1 2, Canterbury",
"language": "en",
"countryCode": "GBR",
"locationId": "NT_VD8YPCI.JUqDjxD8sP84AC",
"address": {
"country": "United Kingdom",
"state": "England",
"county": "Kent",
"city": "Canterbury",
"postalCode": "CT1 2"
},
"distance": 83989,
"matchLevel": "city"
},
{
"label": "United Kingdom, Comté de Northampton",
"language": "en",
"countryCode": "GBR",
"locationId": "NT_zORnAshlbaC1KPrAO3l7xB",
"address": {
"country": "United Kingdom",
"state": "England",
"county": "Comté de Northampton"
},
"distance": 98330,
"matchLevel": "county"
},
{
"label": "United Kingdom, CT1 2, Canterbury, Canterbury",
"language": "en",
"countryCode": "GBR",
"locationId": "NT_jqhKXfcVudUg4b2WGi6teB",
"address": {
"country": "United Kingdom",
"state": "England",
"county": "Kent",
"city": "Canterbury",
"district": "Canterbury",
"postalCode": "CT1 2"
},
"distance": 83989,
"matchLevel": "district"
},
{
"label": "United Kingdom, Comté d'Oxford, OX3 0, Oxford, Cheney Student Village",
"language": "en",
"countryCode": "GBR",
"locationId": "NT_Q2z9awYLuQ7mVhvrPipzjC",
"address": {
"country": "United Kingdom",
"state": "England",
"county": "Comté d'Oxford",
"city": "Oxford",
"district": "Oxford",
"street": "Cheney Student Village",
"postalCode": "OX3 0"
},
"distance": 84092,
"matchLevel": "street"
},
{
"label": "United Kingdom, Comté d'Oxford, OX1 3, Oxford, Catte Street",
"language": "en",
"countryCode": "GBR",
"locationId": "NT_bQFSMkK5C8pdIWfOI.zTZB",
"address": {
"country": "United Kingdom",
"state": "England",
"county": "Comté d'Oxford",
"city": "Oxford",
"district": "Oxford",
"street": "Catte Street",
"postalCode": "OX1 3"
},
"distance": 85769,
"matchLevel": "street"
}
]
}
Notice that the "label":"United Kingdom, Comté d'Oxford" is in French language instead of the one expected that is English since I'm using the language:en parameter
Regarding documentation on scroll please to language parameter : The preferred language of address elements in the result.
The language parameter must be provided as 2-letter ISO language code. The plural form of the parameter (languages) is not supported and ignored. Only one language can be provided. The language setting changes the language of result elements where available in the map data. The language setting has no impact on matching or ranking and it does not express any regional preference.
The default response language is the language that is most relevant to the query.
Also, the language parameter has no impact on which results are returned because is a preferred(not required), in other words to say the "query" parameter has higher priority(has more impact on matching) unlike the "language" parameter.

How to get only the road names on a route, with google maps

For a project im doing, I need to get the road names on a route.
So when i go from Amsterdam to Eindhoven, i pass for example the following roads, A4, A5, A27
My question is, how can i get these roads from the google maps api by giving my departure and destination?
All help is very appreciated.
Thanks in advance
Where are you using the Google Maps API you get a JSON format return.
like this;
{
"status": "OK",
"results": [ {
"types": street_address,
"formatted_address": "275-291 Bedford Ave, Brooklyn, NY 11211, USA",
"address_components": [ {
"long_name": "275-291",
"short_name": "275-291",
"types": street_number
}, {
"long_name": "Bedford Ave",
"short_name": "Bedford Ave",
"types": route
}, {
"long_name": "New York",
"short_name": "New York",
"types": [ "locality", "political" ]
}, {
"long_name": "Brooklyn",
"short_name": "Brooklyn",
"types": [ "administrative_area_level_3", "political" ]
}, {
"long_name": "Kings",
"short_name": "Kings",
"types": [ "administrative_area_level_2", "political" ]
}, {
"long_name": "New York",
"short_name": "NY",
"types": [ "administrative_area_level_1", "political" ]
}, {
"long_name": "United States",
"short_name": "US",
"types": [ "country", "political" ]
}, {
"long_name": "11211",
"short_name": "11211",
"types": postal_code
} ],
"geometry": {
"location": {
"lat": 40.7142298,
"lng": -73.9614669
},
"location_type": "RANGE_INTERPOLATED",
"viewport": {
"southwest": {
"lat": 40.7110822,
"lng": -73.9646145
},
"northeast": {
"lat": 40.7173774,
"lng": -73.9583193
}
}
}
},
Pick the long_name, and short_name from address.

Resources