--- /dev/null
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ * SPDX-License-Identifier: Apache-2.0\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.onap.policy.clamp.models.acm.concepts;\r
+\r
+import java.util.LinkedHashMap;\r
+import java.util.Map;\r
+import java.util.UUID;\r
+import java.util.function.UnaryOperator;\r
+import lombok.Data;\r
+import lombok.NoArgsConstructor;\r
+import lombok.NonNull;\r
+import lombok.ToString;\r
+import org.onap.policy.models.base.PfUtils;\r
+\r
+@NoArgsConstructor\r
+@Data\r
+public class AutomationCompositionRollback {\r
+\r
+ @NonNull\r
+ private UUID instanceId;\r
+\r
+ @NonNull\r
+ private UUID compositionId;\r
+\r
+ @NonNull\r
+ private Map<String, Object> elements = new LinkedHashMap<>();\r
+\r
+ /**\r
+ * Copy constructor, does a deep copy.\r
+ *\r
+ * @param otherAcmRollback the other element to copy from\r
+ */\r
+ public AutomationCompositionRollback(final AutomationCompositionRollback otherAcmRollback) {\r
+ this.instanceId = otherAcmRollback.instanceId;\r
+ this.compositionId = otherAcmRollback.compositionId;\r
+ this.elements = PfUtils.mapMap(otherAcmRollback.elements, UnaryOperator.identity());\r
+ }\r
+}\r
--- /dev/null
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ * SPDX-License-Identifier: Apache-2.0\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.onap.policy.clamp.models.acm.persistence.concepts;\r
+\r
+import jakarta.persistence.Column;\r
+import jakarta.persistence.Convert;\r
+import jakarta.persistence.Entity;\r
+import jakarta.persistence.Id;\r
+import jakarta.persistence.Inheritance;\r
+import jakarta.persistence.InheritanceType;\r
+import jakarta.persistence.Table;\r
+import jakarta.validation.Valid;\r
+import jakarta.validation.constraints.NotNull;\r
+import java.util.LinkedHashMap;\r
+import java.util.Map;\r
+import java.util.UUID;\r
+import java.util.function.UnaryOperator;\r
+import lombok.Data;\r
+import lombok.EqualsAndHashCode;\r
+import lombok.NonNull;\r
+import org.apache.commons.lang3.ObjectUtils;\r
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionRollback;\r
+import org.onap.policy.models.base.PfAuthorative;\r
+import org.onap.policy.models.base.PfUtils;\r
+import org.onap.policy.models.base.Validated;\r
+\r
+@Entity\r
+@Table(name = "AutomationCompositionRollback")\r
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)\r
+@Data\r
+@EqualsAndHashCode(callSuper = false)\r
+public class JpaAutomationCompositionRollback extends Validated\r
+ implements PfAuthorative<AutomationCompositionRollback>, Comparable<JpaAutomationCompositionRollback> {\r
+\r
+ @Id\r
+ @NotNull\r
+ private String instanceId;\r
+\r
+ @NotNull\r
+ @Column\r
+ private String compositionId;\r
+\r
+ @NotNull\r
+ @Valid\r
+ @Convert(converter = StringToMapConverter.class)\r
+ @Column(length = 100000)\r
+ private Map<String, Object> elements = new LinkedHashMap<>();\r
+\r
+ /**\r
+ * The Default Constructor creates a {@link JpaAutomationComposition} object with an empty hashmap.\r
+ */\r
+ public JpaAutomationCompositionRollback() {\r
+ this(UUID.randomUUID().toString(), UUID.randomUUID().toString(), new LinkedHashMap<>());\r
+ }\r
+\r
+ /**\r
+ * The Key Constructor creates a {@link JpaAutomationCompositionRollback} object with all mandatory fields.\r
+ *\r
+ * @param instanceId The UUID of the automation composition rollback instance\r
+ * @param compositionId the TOSCA compositionId of the automation composition rollback definition\r
+ * @param elements the elements of the automation composition rollback\r
+ */\r
+ public JpaAutomationCompositionRollback(@NonNull final String instanceId, @NonNull final String compositionId,\r
+ @NonNull final Map<String, Object> elements) {\r
+ this.instanceId = instanceId;\r
+ this.compositionId = compositionId;\r
+ this.elements = PfUtils.mapMap(elements, UnaryOperator.identity());\r
+ }\r
+\r
+ /**\r
+ * Copy constructor.\r
+ *\r
+ * @param copyConcept the concept to copy from\r
+ */\r
+ public JpaAutomationCompositionRollback(@NonNull final JpaAutomationCompositionRollback copyConcept) {\r
+ this.instanceId = copyConcept.instanceId;\r
+ this.compositionId = copyConcept.compositionId;\r
+ this.elements = PfUtils.mapMap(copyConcept.elements, UnaryOperator.identity());\r
+ }\r
+\r
+ /**\r
+ * Authorative constructor.\r
+ *\r
+ * @param authorativeConcept the authorative concept to copy from\r
+ */\r
+ public JpaAutomationCompositionRollback(@NonNull final AutomationCompositionRollback authorativeConcept) {\r
+ this.fromAuthorative(authorativeConcept);\r
+ }\r
+\r
+ @Override\r
+ public AutomationCompositionRollback toAuthorative() {\r
+ var acmRollback = new AutomationCompositionRollback();\r
+ acmRollback.setInstanceId(UUID.fromString(this.instanceId));\r
+ acmRollback.setCompositionId(UUID.fromString(this.compositionId));\r
+ acmRollback.setElements(PfUtils.mapMap(this.elements, UnaryOperator.identity()));\r
+ return acmRollback;\r
+ }\r
+\r
+ @Override\r
+ public void fromAuthorative(@NonNull final AutomationCompositionRollback acmRollback) {\r
+ this.instanceId = acmRollback.getInstanceId().toString();\r
+ this.compositionId = acmRollback.getCompositionId().toString();\r
+ this.elements = PfUtils.mapMap(acmRollback.getElements(), UnaryOperator.identity());\r
+ }\r
+\r
+ @Override\r
+ public int compareTo(final JpaAutomationCompositionRollback other) {\r
+ if (other == null) {\r
+ return -1;\r
+ }\r
+ if (this == other) {\r
+ return 0;\r
+ }\r
+\r
+ var result = ObjectUtils.compare(instanceId, other.instanceId);\r
+ if (result != 0) {\r
+ return result;\r
+ }\r
+\r
+ result = ObjectUtils.compare(compositionId, other.compositionId);\r
+ if (result != 0) {\r
+ return result;\r
+ }\r
+\r
+ return PfUtils.compareObjects(elements, other.elements);\r
+ }\r
+\r
+}\r
--- /dev/null
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ * SPDX-License-Identifier: Apache-2.0\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.onap.policy.clamp.models.acm.persistence.repository;\r
+\r
+import java.util.List;\r
+import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionRollback;\r
+import org.springframework.data.jpa.repository.JpaRepository;\r
+\r
+public interface AutomationCompositionRollbackRepository\r
+ extends JpaRepository<JpaAutomationCompositionRollback, String> {\r
+\r
+ List<JpaAutomationCompositionRollback> findByCompositionId(String compositionId);\r
+}\r
--- /dev/null
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ * SPDX-License-Identifier: Apache-2.0\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.onap.policy.clamp.models.acm.concepts;\r
+\r
+import static org.junit.jupiter.api.Assertions.assertEquals;\r
+\r
+import java.util.HashMap;\r
+import java.util.LinkedHashMap;\r
+import java.util.Map;\r
+import java.util.UUID;\r
+import java.util.function.UnaryOperator;\r
+import org.junit.jupiter.api.Test;\r
+import org.onap.policy.models.base.PfUtils;\r
+\r
+class AutomationCompositionRollbackTest {\r
+ @Test\r
+ void testAutomationCompositionRollback() {\r
+ var acr0 = new AutomationCompositionRollback();\r
+ acr0.setInstanceId(UUID.randomUUID());\r
+ acr0.setCompositionId(UUID.randomUUID());\r
+ Map<String, Object> map = new LinkedHashMap<>();\r
+ map.put("test", "test");\r
+ acr0.setElements(PfUtils.mapMap(map, UnaryOperator.identity()));\r
+\r
+ var acr1 = new AutomationCompositionRollback(acr0);\r
+ assertEquals(acr0, acr1);\r
+ }\r
+}\r
--- /dev/null
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ * SPDX-License-Identifier: Apache-2.0\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.onap.policy.clamp.models.acm.persistence.concepts;\r
+\r
+import static org.assertj.core.api.Assertions.assertThatThrownBy;\r
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;\r
+import static org.junit.jupiter.api.Assertions.assertEquals;\r
+\r
+import java.util.HashMap;\r
+import java.util.LinkedHashMap;\r
+import java.util.Map;\r
+import java.util.UUID;\r
+import java.util.function.UnaryOperator;\r
+import org.junit.jupiter.api.Test;\r
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionRollback;\r
+import org.onap.policy.models.base.PfUtils;\r
+\r
+\r
+public class JpaAutomationCompositionRollbackTest {\r
+\r
+ private static final String NULL_INSTANCE_ID_ERROR = "instanceId is marked .*ull but is null";\r
+ private static final String NULL_ERROR = " is marked .*ull but is null";\r
+ private static final String INSTANCE_ID = "709c62b3-8918-41b9-a747-d21eb79c6c20";\r
+ private static final String COMPOSITION_ID = "709c62b3-8918-41b9-a747-e21eb79c6c41";\r
+\r
+ @Test\r
+ void testJpaAutomationCompositionRollbackConstructor() {\r
+ assertThatThrownBy(() -> {\r
+ new JpaAutomationCompositionRollback((JpaAutomationCompositionRollback) null);\r
+ }).hasMessageMatching("copyConcept" + NULL_ERROR);\r
+\r
+ assertThatThrownBy(() -> {\r
+ new JpaAutomationCompositionRollback((AutomationCompositionRollback) null);\r
+ }).hasMessageMatching("authorativeConcept" + NULL_ERROR);\r
+\r
+ assertThatThrownBy(() -> {\r
+ new JpaAutomationCompositionRollback(null, null, null);\r
+ }).hasMessageMatching(NULL_INSTANCE_ID_ERROR);\r
+\r
+ assertThatThrownBy(() -> {\r
+ new JpaAutomationCompositionRollback(INSTANCE_ID, null, null);\r
+ }).hasMessageMatching("compositionId" + NULL_ERROR);\r
+\r
+ assertThatThrownBy(() -> {\r
+ new JpaAutomationCompositionRollback(INSTANCE_ID, COMPOSITION_ID, null);\r
+ }).hasMessageMatching("elements" + NULL_ERROR);\r
+\r
+ assertDoesNotThrow(() -> new JpaAutomationCompositionRollback());\r
+ Map<String, Object> map = new LinkedHashMap<>();\r
+ map.put("test", "test");\r
+ assertDoesNotThrow(() -> new JpaAutomationCompositionRollback(INSTANCE_ID, COMPOSITION_ID, map));\r
+ }\r
+\r
+ @Test\r
+ void testJpaAutomationCompositionRollback() {\r
+ var automationCompositionRollback = createAutomationCompositionRollbackInstance();\r
+ var jpaAutomationCompositionRollback = new JpaAutomationCompositionRollback(automationCompositionRollback);\r
+\r
+\r
+ assertEquals(automationCompositionRollback, jpaAutomationCompositionRollback.toAuthorative());\r
+ assertDoesNotThrow(() -> new JpaAutomationCompositionRollback(jpaAutomationCompositionRollback));\r
+ }\r
+\r
+ @Test\r
+ void testJpaCompositionRollbackCompareTo() {\r
+ var jpaAutomationCompositionRollback =\r
+ new JpaAutomationCompositionRollback(createAutomationCompositionRollbackInstance());\r
+\r
+ var otherJpaAutomationComposition =\r
+ new JpaAutomationCompositionRollback(jpaAutomationCompositionRollback);\r
+\r
+ assertEquals(0, jpaAutomationCompositionRollback.compareTo(otherJpaAutomationComposition));\r
+ assertEquals(-1, jpaAutomationCompositionRollback.compareTo(null));\r
+ assertEquals(0, jpaAutomationCompositionRollback.compareTo(jpaAutomationCompositionRollback));\r
+ }\r
+\r
+ private AutomationCompositionRollback createAutomationCompositionRollbackInstance() {\r
+ var testAcmRollback = new AutomationCompositionRollback();\r
+ testAcmRollback.setInstanceId(UUID.fromString(INSTANCE_ID));\r
+ testAcmRollback.setCompositionId(UUID.fromString(COMPOSITION_ID));\r
+ Map<String, Object> map = new HashMap<>();\r
+ map.put("test", "test");\r
+ testAcmRollback.setElements(PfUtils.mapMap(map, UnaryOperator.identity()));\r
+\r
+ return testAcmRollback;\r
+ }\r
+}\r