summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java
diff options
context:
space:
mode:
authorChris André <chris.andre@yoppworks.com>2020-04-21 14:40:07 -0400
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-04-28 12:19:02 +0000
commit08cb42224a5d20783e525cadbab1b7ae40a86f72 (patch)
tree4f8c31dcc56cb0d9b9dc01c33b965dbaec41db7c /catalog-be/src/main/java
parent33a4512b6eb6204e2209a788b06153a889629f4e (diff)
Handle null case in `GroupVersionUpdater`
- change in the final condition of `isGenerateGroupUUID` - Added tests related to modified code Issue-ID: SDC-2913 Signed-off-by: Chris Andre <chris.andre@yoppworks.com> Change-Id: I22738f9f4922467209a16a4d6b3b78d7bfac11c9
Diffstat (limited to 'catalog-be/src/main/java')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/group/GroupVersionUpdater.java38
1 files changed, 25 insertions, 13 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/group/GroupVersionUpdater.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/group/GroupVersionUpdater.java
index bb4d884811..8e9ba7a88b 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/group/GroupVersionUpdater.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/group/GroupVersionUpdater.java
@@ -20,7 +20,8 @@
package org.openecomp.sdc.be.components.impl.group;
-
+import java.util.Collections;
+import java.util.stream.Collectors;
import org.openecomp.sdc.be.components.impl.version.OnChangeVersionCommand;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.GroupTypeEnum;
@@ -37,7 +38,6 @@ import org.openecomp.sdc.common.log.wrappers.Logger;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
-import java.util.stream.Collectors;
import static org.apache.commons.collections.CollectionUtils.isEmpty;
@@ -84,27 +84,39 @@ public class GroupVersionUpdater implements OnChangeVersionCommand {
}
group.setVersion(String.valueOf(newVersion));
}
+ }
+ static <T> List<T> emptyIfNull(final List<T> list) {
+ return (list == null? Collections.emptyList() : list);
}
- private boolean isGenerateGroupUUID(GroupDefinition group, Component container) {
- if(GroupTypeEnum.VF_MODULE.getGroupTypeName().equals(group.getType())){
- List<String> artifactsUuid = group.getArtifactsUuid();
- List<String> heatArtifactUniqueIDs = group.getArtifacts().stream().filter(a->!a.endsWith("env")).collect(Collectors.toList());
- Map<String, ArtifactDefinition> deploymentArtifacts = container.getDeploymentArtifacts();
- for (String heatArtifactUniqueID : heatArtifactUniqueIDs){
- ArtifactDefinition artifactDefinition = deploymentArtifacts.get(heatArtifactUniqueID.split("\\.", -1)[1]);
- if((artifactDefinition == null || artifactDefinition.isEmpty())
- && !artifactsUuid.contains(artifactDefinition.getArtifactUUID()) ){
+ static <T, U> Map<T, U> emptyIfNull(final Map<T, U> list) {
+ return (list == null? Collections.emptyMap() : list);
+ }
+
+ static boolean isGenerateGroupUUID(GroupDefinition group, Component container) {
+ if (!GroupTypeEnum.VF_MODULE.getGroupTypeName().equals(group.getType())) {
+ return true;
+ } else {
+ List<String> artifactsUuid = emptyIfNull(group.getArtifactsUuid());
+ Map<String, ArtifactDefinition> deploymentArtifacts = emptyIfNull(container.getDeploymentArtifacts());
+ List<String> heatArtifactUniqueIDs = emptyIfNull(group.getArtifacts()).stream().filter(a -> !a.endsWith("env")).collect(
+ Collectors.toList());
+
+ for (String heatArtifactUniqueID : heatArtifactUniqueIDs) {
+ ArtifactDefinition artifactDefinition = deploymentArtifacts
+ .get(heatArtifactUniqueID.split("\\.", -1)[1]);
+
+ if ((artifactDefinition == null
+ || artifactDefinition.isEmpty())
+ || !artifactsUuid.contains(artifactDefinition.getArtifactUUID())) {
return true;
}
}
return false;
}
- return true;
}
-
private ActionStatus updateGroupsVersion(Component groupsContainer, Consumer<List<GroupDefinition>> updateGroupVersion) {
List<GroupDefinition> groups = groupsContainer.getGroups();
if (isEmpty(groups)) {