diff --git a/tx-backend/pom.xml b/tx-backend/pom.xml index 3d29fde5b0..f5c90181d0 100644 --- a/tx-backend/pom.xml +++ b/tx-backend/pom.xml @@ -17,11 +17,11 @@ - + @@ -221,6 +221,12 @@ ${commons-io.version} + + org.apache.commons + commons-collections4 + 4.4 + + org.apache.groovy groovy @@ -344,12 +350,6 @@ traceability-app-${project.version} - - org.apache.maven.plugins maven-resources-plugin @@ -587,35 +587,35 @@ spotbugs-check - - - com.github.spotbugs - spotbugs-maven-plugin - ${spotbugs-plugin.version} - - Max - Low - true - High - ci/spotbugs-excludes.xml - - - com.h3xstream.findsecbugs - findsecbugs-plugin - ${findsecbugs-plugin.version} - - - - - - validate - - check - - - - - + + + com.github.spotbugs + spotbugs-maven-plugin + ${spotbugs-plugin.version} + + Max + Low + true + High + ci/spotbugs-excludes.xml + + + com.h3xstream.findsecbugs + findsecbugs-plugin + ${findsecbugs-plugin.version} + + + + + + validate + + check + + + + + diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/domain/service/AssetService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/domain/service/AssetService.java index 9fd7116fd0..9557f81dbb 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/domain/service/AssetService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/domain/service/AssetService.java @@ -34,10 +34,15 @@ import org.springframework.stereotype.Component; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.function.Function; import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.apache.commons.collections4.CollectionUtils.emptyIfNull; @Component public class AssetService { @@ -75,11 +80,21 @@ public void synchronizeAssets(String globalAssetId) { } } + /** + * Combines the list of downward assets with the list of upward assets by merging the parent descriptions of + * matching child assets into the corresponding downward assets. If an upward asset has no matching downward asset, + * it is added to the result list as is. + * + * @param downwardAssets the list of downward assets to be combined with the upward assets + * @param upwardAssets the list of upward assets to be combined with the downward assets + * @return a new list of {@link Asset} objects that contains the combined assets with merged parent descriptions + */ public List combineAssetsAndMergeParentDescriptionIntoDownwardAssets(List downwardAssets, List upwardAssets) { - Map downwardAssetsMap = downwardAssets.stream() + + Map downwardAssetsMap = emptyIfNull(downwardAssets).stream() .collect(Collectors.toMap(Asset::getId, Function.identity())); - return upwardAssets.stream() + return emptyIfNull(upwardAssets).stream() .map(parentAsset -> { Asset matchingChildAsset = downwardAssetsMap.get(parentAsset.getId()); if (matchingChildAsset == null) {