From d287d1187f20bf5bf627be3c10dcdf157628a41f Mon Sep 17 00:00:00 2001 From: emuroni Date: Wed, 2 Aug 2023 13:29:31 +0200 Subject: [PATCH] fixed problem with nested keys --- .../data_sources/mappers/filter_mapper.dart | 10 ++++++- .../mappers/proof_request_filters_mapper.dart | 28 ++++++++++++++----- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/lib/common/data/data_sources/mappers/filter_mapper.dart b/lib/common/data/data_sources/mappers/filter_mapper.dart index 9d5175e3..a959a58c 100644 --- a/lib/common/data/data_sources/mappers/filter_mapper.dart +++ b/lib/common/data/data_sources/mappers/filter_mapper.dart @@ -20,7 +20,15 @@ class FilterMapper extends ToMapper { case FilterOperator.lesserEqual: return Filter.lessThanOrEquals(to.name, to.value); case FilterOperator.inList: - return Filter.inList(to.name, to.value as List); + try { + List dynamicList = to.value as List; + List objectList = dynamicList.map((item) => item as Object) + .toList(); + Filter filter = Filter.inList(to.name, objectList); + return filter; + } catch (e) { + return Filter.inList(to.name, to.value as List); + } case FilterOperator.or: return Filter.or((to.value as List) .map((filter) => mapTo(filter)) diff --git a/lib/iden3comm/data/mappers/proof_request_filters_mapper.dart b/lib/iden3comm/data/mappers/proof_request_filters_mapper.dart index 1e573d98..8e2a50ac 100644 --- a/lib/iden3comm/data/mappers/proof_request_filters_mapper.dart +++ b/lib/iden3comm/data/mappers/proof_request_filters_mapper.dart @@ -43,13 +43,8 @@ class ProofRequestFiltersMapper if (query.credentialSubject != null) { Map request = query.credentialSubject!; request.forEach((key, map) { - if (map != null && - map is Map && - map.isNotEmpty && - context != null && - context[key] != null && - context[key]["@type"] != null) { - String type = context[key]["@type"]; + if (map != null && map is Map && map.isNotEmpty && context != null) { + String type = getValueFromNestedString(context, key); map.forEach((operator, value) { if (type.contains("boolean")) { FilterEntity? booleanFilter = @@ -78,6 +73,25 @@ class ProofRequestFiltersMapper return filters; } + /// + String getValueFromNestedString( + Map contextMap, String nestedKey) { + List keys = nestedKey.split('.'); + dynamic value = contextMap; + for (String key in keys) { + if (value is Map && value[key].containsKey("@context")) { + value = value[key]["@context"]; + } else if (value is Map && + value[key].containsKey("@type")) { + value = value[key]["@type"]; + break; + } else { + break; + } + } + return value; + } + List _getFilterByOperator(field, operator, value) { switch (operator) { case '\$eq':