Skip to content

Commit

Permalink
fix-loading-secondary-resources-data-v0.2.3-rc4
Browse files Browse the repository at this point in the history
  • Loading branch information
roywanyaga committed Jun 5, 2023
1 parent 1a6bb04 commit 818fcf9
Showing 1 changed file with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ constructor(
* flattened in a map for ease of usage in the rule engine.
*/
fun fireRules(rules: Rules, repositoryResourceData: RepositoryResourceData): Map<String, Any> {

with(repositoryResourceData) {
// Initialize new facts and fire rules in background
facts =
Expand All @@ -137,11 +136,28 @@ constructor(
relatedResourcesMap.addToFacts(this)
relatedResourcesCountMap.addToFacts(this)

// Populate the facts map with secondary resource data
secondaryRepositoryResourceData?.forEach {
put(it.resourceRulesEngineFactId ?: it.resource.resourceType.name, it.resource)
relatedResourcesMap.addToFacts(this)
relatedResourcesCountMap.addToFacts(this)
// Populate the facts map with secondary resource data flatten base and related resources
secondaryRepositoryResourceData
?.groupBy { it.resourceRulesEngineFactId ?: it.resource.resourceType.name }
?.forEach { entry -> put(entry.key, entry.value.map { it.resource }) }

secondaryRepositoryResourceData?.forEach { repoResourceData ->
repoResourceData.relatedResourcesMap.forEach { entry ->
val existingRelatedResourceList = get<MutableList<Resource>>(entry.key)
if (existingRelatedResourceList == null) {
put(entry.key, mutableListOf<Resource>())
}
get<MutableList<Resource>>(entry.key).addAll(entry.value)
}

repoResourceData.relatedResourcesCountMap.forEach { entry ->
val existingRelatedResourceCountList =
get<MutableList<RelatedResourceCount>>(entry.key)
if (existingRelatedResourceCountList == null) {
put(entry.key, mutableListOf<RelatedResourceCount>())
}
get<MutableList<RelatedResourceCount>>(entry.key).addAll(entry.value)
}
}
}

Expand Down

0 comments on commit 818fcf9

Please sign in to comment.