summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2024-04-16 11:44:13 +0100
committerFrancescoFioraEst <francesco.fiora@est.tech>2024-04-16 15:21:46 +0100
commit519334f314bd68085148a83dca0f5172276884df (patch)
tree33ad97ca18e25149d804665bc8df45bfe9da620a /models
parent32bc41230740115ec079f3780820bbd5ae07e6d3 (diff)
Fix AutomationCompositionElement copy constructor
Issue-ID: POLICY-4961 Change-Id: I81256e2b0ecb82e7b313ad8b203b1bcf4468dd72 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'models')
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java9
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java7
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java13
3 files changed, 24 insertions, 5 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java
index 95ee55f8d..5afa7e0bb 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,13 +23,12 @@ package org.onap.policy.clamp.models.acm.concepts;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;
-import java.util.function.UnaryOperator;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.ToString;
+import org.onap.policy.clamp.models.acm.utils.AcmUtils;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
@@ -77,8 +76,8 @@ public class AutomationCompositionElement {
this.definition = new ToscaConceptIdentifier(otherElement.definition);
this.participantId = otherElement.participantId;
this.description = otherElement.description;
- this.properties = PfUtils.mapMap(otherElement.properties, UnaryOperator.identity());
- this.outProperties = PfUtils.mapMap(otherElement.outProperties, UnaryOperator.identity());
+ this.properties = AcmUtils.cloneMap(otherElement.properties);
+ this.outProperties = AcmUtils.cloneMap(otherElement.outProperties);
this.restarting = otherElement.restarting;
this.deployState = otherElement.deployState;
this.lockState = otherElement.lockState;
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java
index 1155bd4f4..0293bd3c5 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java
@@ -52,6 +52,7 @@ import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition;
import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder;
+import org.onap.policy.clamp.models.acm.persistence.concepts.StringToMapConverter;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.ObjectValidationResult;
import org.onap.policy.common.parameters.ValidationResult;
@@ -70,6 +71,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class AcmUtils {
public static final String ENTRY = "entry ";
+ private static StringToMapConverter MAP_CONVERTER = new StringToMapConverter();
/**
* Get the Policy information in the service template for the deploy message to participants.
@@ -490,4 +492,9 @@ public final class AcmUtils {
}
}
}
+
+ public static Map<String, Object> cloneMap(Map<String, Object> map) {
+ var str = MAP_CONVERTER.convertToDatabaseColumn(map);
+ return MAP_CONVERTER.convertToEntityAttribute(str);
+ }
}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java
index 1561533e8..a5c93e86a 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java
@@ -24,6 +24,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -363,4 +364,16 @@ class AcmUtilsTest {
assertNull(subMap.get("myParameterToRemove"));
assertEquals("I am new", subMap.get("myParameter"));
}
+
+ @Test
+ void testCopyMap() {
+ Map<String, Object> map = new HashMap<>();
+ Map<String, Object> subMap = new HashMap<>();
+ subMap.put("test", "value");
+ map.put("sub", subMap);
+ var result = AcmUtils.cloneMap(map);
+ var subMap2 = (Map<String, Object>) result.get("sub");
+ subMap2.put("test", "value2");
+ assertNotEquals(subMap.get("test"), subMap2.get("test"));
+ }
}