# Necessary plugins
[use]
plugin = basics
plugin = analytics
plugin = storage

# Load concept form URI
[load]
location = env('location')
domain = env('loterreID').prepend('loterre-').append('concepts')
path = value
target = value

# transcribe broaderConcept
[assign]
path = value.skos$broader
value = get('value.skos$broader').castArray().filter(Boolean)

[map]
path = value.skos$broader

[map/load]
location = env('location')
domain = env('loterreID').prepend('loterre-').append('concepts')
path = rdf$resource

[map/exchange]
value = self().pick(['skos$prefLabel', 'rdf$about'])

# transcribe narrowerConcept
[assign]
path = value.skos$narrower
value = get('value.skos$narrower').castArray().filter(Boolean)

[map]
path = value.skos$narrower

[map/load]
location = env('location')
domain = env('loterreID').prepend('loterre-').append('concepts')
path = rdf$resource

[map/exchange]
value = self().pick(['skos$prefLabel', 'rdf$about'])


# Prevent keys from containing dot path notation or start with a dollar character (which is forbidden by nodeJS mongoDB driver)
# use map is trick to apply stamtement only on the value field
[map]
path = value

[map/OBJFlatten]
separator = fix('.')
safe = false
[map/exchange]
value = self().mapKeys((value, key) => key.replace(/\.\$/g, '.xml$').replace(/\/\$/g, '/xml$'))
[map/OBJFlatten]
separator = fix('.')
reverse = true
safe = false

[assign]
path = value
value = get('value').pop()

