[ad_1]
I am looking for a way to neatly filter the values from the event and create a map based on them.
What we need to know:
Event:
The event contains the dictionary data structure (its a map of <String, String> where key is a product parameter name.
For example:
a)
Key: Brand,
Value: Nike
b)
Key: Producer,
Value: Audi
- Filter:
Filter is a map <String, Set> and its configured in yml.
Example of values:
Key: Manufacturer,
Value: [Brand, Producer, Creator, Author]
- Entity:
data class Product( val id: String, val parameters: Map<String, Parameter> = emptyMap() ) data class Parameter( val parameterId: String?, val parameterValue: String)
How flow looks like:
1)An event comes with a list of parameters, e.g.
mapOf(
"brand" to "Nike",
"size" to "42",
"color" to "black
)
- Values are filtered. Lets pretend we have got only one filter – its key = Manufacturer, its values = [Brand, Producer, Creator, Author].
So from this event we have got only one position – its mapOf(“brand” to “Nike”)
During filtering, a map is created in the domain object [Product] with filled field- parameters: Map <String, Parameter>
e.g.
mapOf("Manufacturer" to Parameter(null, "Nike"))
As you can see – Manufacturer, not Brand, was selected as the key in the map in the Product object (i.e. the key of this parameter, not the value).
GOAL:
What should the method of filtering the event look like?How to do it in clever, Kotlin way (filter the data using the Map <String, Set > for the incoming map and create the target object based on it.)
Thanks in advance for help/advice!
[ad_2]