Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add validation to golden record process in pool #621

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,18 @@ fun <T> Collection<T>.findDuplicates(): Set<T> =
this.groupBy { it }
.filter { it.value.size > 1 }
.keys

/**
* Merge Maps with collections as values.
* The collections with the same key in the different maps are concatenated
*/
fun <KEY, VALUE> mergeMapsWithCollectionInValue(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe name it mergeMultiMaps?
https://en.wikipedia.org/wiki/Multimap

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core of the functionality is that the collections in the value part of the map are concatenated.
This should be expressed in the name.

vararg inputMaps: Map<out KEY, Collection<VALUE>>
): Map<KEY, Collection<VALUE>> {
return inputMaps
.map { inputMap ->
inputMap.flatMap { (key, values) -> values.map { value -> Pair(key, value) } }
}
.reduce { entries1, entries2 -> entries1 + entries2 }
.groupBy({ it.first }, { it.second })
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.eclipse.tractusx.bpdm.common.util

import org.assertj.core.api.Assertions
import org.junit.jupiter.api.Test

class CollectionUtilsKtTest {

@Test
fun mergeMapsWithCollectionInValue() {

val key1 = "Task1"
val key2 = "Task2"
val key3 = "Task3"

val firstMap = mapOf(
key1 to listOf("value1", "value2"),
key2 to listOf("value3", "value2", "value1")
)
val secondMap = mapOf(
key1 to listOf("value4", "value5"),
key3 to listOf("value4", "value1")
)
val thirdMap = mapOf(
key1 to listOf("value6"),
key3 to listOf("value7")
)

val result = mergeMapsWithCollectionInValue(firstMap, secondMap, thirdMap)
Assertions.assertThat(result[key1]).containsExactlyInAnyOrder("value1", "value2", "value4", "value5", "value6")
Assertions.assertThat(result[key2]).containsExactlyInAnyOrder("value3", "value2", "value1")
Assertions.assertThat(result[key3]).containsExactlyInAnyOrder("value4", "value1", "value7")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class BusinessPartnerBuildService(
logger.info { "Create ${requests.size} new legal entities" }


val errorsByRequest = requestValidationService.validateLegalEntityCreates(requests)
val errorsByRequest = requestValidationService.validateLegalEntitiesToCreateFromController(requests)
val errors = errorsByRequest.flatMap { it.value }
val validRequests = requests.filterNot { errorsByRequest.containsKey(it) }

Expand Down Expand Up @@ -103,7 +103,7 @@ class BusinessPartnerBuildService(
fun createSites(requests: Collection<SitePartnerCreateRequest>): SitePartnerCreateResponseWrapper {
logger.info { "Create ${requests.size} new sites" }

val errorsByRequest = requestValidationService.validateSiteCreates(requests)
val errorsByRequest = requestValidationService.validateSitesToCreateFromController(requests)
val errors = errorsByRequest.flatMap { it.value }
val validRequests = requests.filterNot { errorsByRequest.containsKey(it) }

Expand Down Expand Up @@ -145,7 +145,7 @@ class BusinessPartnerBuildService(
fun createAddresses(requests: Collection<AddressPartnerCreateRequest>): AddressPartnerCreateResponseWrapper {
logger.info { "Create ${requests.size} new addresses" }

val errorsByRequest = requestValidationService.validateAddressCreates(requests)
val errorsByRequest = requestValidationService.validateAddressesToCreateFromController(requests)
val errors = errorsByRequest.flatMap { it.value }
val validRequests = requests.filterNot { errorsByRequest.containsKey(it) }

Expand Down Expand Up @@ -177,7 +177,7 @@ class BusinessPartnerBuildService(
fun updateLegalEntities(requests: Collection<LegalEntityPartnerUpdateRequest>): LegalEntityPartnerUpdateResponseWrapper {
logger.info { "Update ${requests.size} legal entities" }

val errorsByRequest = requestValidationService.validateLegalEntityUpdates(requests)
val errorsByRequest = requestValidationService.validateLegalEntitiesToUpdateFromController(requests)
val errors = errorsByRequest.flatMap { it.value }
val validRequests = requests.filterNot { errorsByRequest.containsKey(it) }

Expand Down Expand Up @@ -212,7 +212,7 @@ class BusinessPartnerBuildService(
fun updateSites(requests: Collection<SitePartnerUpdateRequest>): SitePartnerUpdateResponseWrapper {
logger.info { "Update ${requests.size} sites" }

val errorsByRequest = requestValidationService.validateSiteUpdates(requests)
val errorsByRequest = requestValidationService.validateSitesToUpdateFromController(requests)
val errors = errorsByRequest.flatMap { it.value }
val validRequests = requests.filterNot { errorsByRequest.containsKey(it) }

Expand Down Expand Up @@ -244,7 +244,7 @@ class BusinessPartnerBuildService(
fun updateAddresses(requests: Collection<AddressPartnerUpdateRequest>): AddressPartnerUpdateResponseWrapper {
logger.info { "Update ${requests.size} business partner addresses" }

val errorsByRequest = requestValidationService.validateAddressUpdates(requests)
val errorsByRequest = requestValidationService.validateAddressesToUpdateFromController(requests)
val errors = errorsByRequest.flatMap { it.value }
val validRequests = requests.filterNot { errorsByRequest.containsKey(it) }

Expand Down