Data source/VIES/data model/record/mapping/CDQ/ES/transformation
Jump to navigation
Jump to search
Part of Hierarchical relation between two concepts of the CDQ Data Model. | Data source VIES |
---|---|
Mapping source The source of a data model mapping. | VIES record ↣ THOROUGHFARE_VALUE , THOROUGHFARE_TYPE , POST_CODE_VALUE , POST_CODE_TYPE , LOCALITY_VALUE , LOCALITY_TYPE
|
Transformation type A type of a transformation applied to a data model mapping. | CUSTOM_TRANSFORMATION"CUSTOM_TRANSFORMATION" is not in the list (UPPER_CASE, LOWER_CASE, CUSTOM) of allowed values for the "Has transformation type" property.
|
Transformation parameter A transformation parameter is an action proccessed by a data model transformation. | n/a |
Description Informal and comprehensive human-readable definition of a concept. | n/a |
Transformation code Any code (in Python, JAVA or other) that will transform values for a given data source attributes.
import json
def transform(raw_data):
json_object = json.loads(raw_data)
result = {}
if 'response' in json_object:
response = json_object.get('response')
add_if_valid_for_rest_response(response, 'traderStreet', 'addresses[0].thoroughfares[0]', 'STREET', result)
add_if_valid_for_rest_response(response, 'traderPostalCode', 'addresses[0].postCodes[0]', 'REGULAR', result)
add_if_valid_for_rest_response(response, 'traderCity', 'addresses[0].localities[0]', 'CITY', result)
else:
add_if_valid(json_object, 'traderStreet', 'addresses[0].thoroughfares[0]', 'STREET', result)
add_if_valid(json_object, 'traderPostcode', 'addresses[0].postCodes[0]', 'REGULAR', result)
add_if_valid(json_object, 'traderCity', 'addresses[0].localities[0]', 'CITY', result)
return result
def add_if_valid(json_object, param, prefix, type, result):
if json_object.get('countryCode', {}).get('value', {}) != 'ES' or json_object.get(param + 'Match', {}).get('value', {}) == '1':
value = json_object.get(param, {}).get('value', {})
if value:
result.update({
prefix + '.type.technicalKey': type,
prefix + '.value': value
})
def add_if_valid_for_rest_response(json_object, param, prefix, type, result):
if json_object.get(param + 'Match', {}) == 'VALID':
value = json_object.get(param, {})
if value:
result.update({
prefix + '.type.technicalKey': type,
prefix + '.value': value
})
def transform(raw_data):
json_object = json.loads(raw_data)
result = {}
if 'response' in json_object:
response = json_object.get('response')
add_if_valid_for_rest_response(response, 'traderStreet', 'addresses[0].thoroughfares[0]', 'STREET', result)
add_if_valid_for_rest_response(response, 'traderPostalCode', 'addresses[0].postCodes[0]', 'REGULAR', result)
add_if_valid_for_rest_response(response, 'traderCity', 'addresses[0].localities[0]', 'CITY', result)
else:
add_if_valid(json_object, 'traderStreet', 'addresses[0].thoroughfares[0]', 'STREET', result)
add_if_valid(json_object, 'traderPostcode', 'addresses[0].postCodes[0]', 'REGULAR', result)
add_if_valid(json_object, 'traderCity', 'addresses[0].localities[0]', 'CITY', result)
return result
def add_if_valid(json_object, param, prefix, type, result):
if json_object.get('countryCode', {}).get('value', {}) != 'ES' or json_object.get(param + 'Match', {}).get('value', {}) == '1':
value = json_object.get(param, {}).get('value', {})
if value:
result.update({
prefix + '.type.technicalKey': type,
prefix + '.value': value
})
def add_if_valid_for_rest_response(json_object, param, prefix, type, result):
if json_object.get(param + 'Match', {}) == 'VALID':
value = json_object.get(param, {})
if value:
result.update({
prefix + '.type.technicalKey': type,
prefix + '.value': value
})