2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021-2025 OpenInfra Foundation Europe. All rights reserved.
4 * ================================================================================
5 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.clamp.models.acm.persistence.concepts;
25 import jakarta.persistence.AttributeOverride;
26 import jakarta.persistence.Column;
27 import jakarta.persistence.Convert;
28 import jakarta.persistence.Entity;
29 import jakarta.persistence.Id;
30 import jakarta.persistence.Inheritance;
31 import jakarta.persistence.InheritanceType;
32 import jakarta.persistence.Table;
34 import java.util.UUID;
35 import java.util.function.UnaryOperator;
37 import lombok.EqualsAndHashCode;
38 import lombok.NonNull;
39 import org.apache.commons.lang3.ObjectUtils;
40 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
41 import org.onap.policy.clamp.models.acm.concepts.DeployState;
42 import org.onap.policy.clamp.models.acm.concepts.LockState;
43 import org.onap.policy.clamp.models.acm.concepts.MigrationState;
44 import org.onap.policy.clamp.models.acm.concepts.SubState;
45 import org.onap.policy.common.parameters.annotations.NotNull;
46 import org.onap.policy.common.parameters.annotations.Valid;
47 import org.onap.policy.models.base.PfAuthorative;
48 import org.onap.policy.models.base.PfConceptKey;
49 import org.onap.policy.models.base.PfUtils;
50 import org.onap.policy.models.base.Validated;
51 import org.onap.policy.models.base.validation.annotations.VerifyKey;
52 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
55 * Class to represent a participant automation composition element in the database.
57 * @author Liam Fallon (liam.fallon@est.tech)
60 @Table(name = "AutomationCompositionElement")
61 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
63 @EqualsAndHashCode(callSuper = false)
64 public class JpaAutomationCompositionElement extends Validated
65 implements PfAuthorative<AutomationCompositionElement>, Comparable<JpaAutomationCompositionElement> {
69 private String elementId;
73 private String instanceId;
77 @AttributeOverride(name = "name", column = @Column(name = "definition_name"))
78 @AttributeOverride(name = "version", column = @Column(name = "definition_version"))
79 private PfConceptKey definition;
83 private String participantId;
87 private DeployState deployState;
91 private LockState lockState;
95 private SubState subState;
99 private MigrationState migrationState;
102 private String operationalState;
105 private String useState;
108 private Integer stage;
111 private String description;
114 private String message;
118 @Convert(converter = StringToMapConverter.class)
119 @Column(length = 100000)
120 private Map<String, Object> properties;
124 @Convert(converter = StringToMapConverter.class)
125 @Column(length = 100000)
126 private Map<String, Object> outProperties;
129 * The Default Constructor creates a {@link JpaAutomationCompositionElement} object with a null key.
131 public JpaAutomationCompositionElement() {
132 this(UUID.randomUUID().toString(), UUID.randomUUID().toString());
136 * The Key Constructor creates a {@link JpaAutomationCompositionElement} object with the given concept key.
138 * @param elementId The id of the automation composition instance Element
139 * @param instanceId The id of the automation composition instance
141 public JpaAutomationCompositionElement(@NonNull final String elementId, @NonNull final String instanceId) {
142 this.elementId = elementId;
143 this.instanceId = instanceId;
144 this.definition = new PfConceptKey();
145 this.deployState = DeployState.UNDEPLOYED;
146 this.lockState = LockState.NONE;
147 this.subState = SubState.NONE;
148 this.migrationState = MigrationState.DEFAULT;
154 * @param copyConcept the concept to copy from
156 public JpaAutomationCompositionElement(@NonNull final JpaAutomationCompositionElement copyConcept) {
157 this.elementId = copyConcept.elementId;
158 this.instanceId = copyConcept.instanceId;
159 this.definition = new PfConceptKey(copyConcept.definition);
160 this.participantId = copyConcept.participantId;
161 this.description = copyConcept.description;
162 this.properties = PfUtils.mapMap(copyConcept.properties, UnaryOperator.identity());
163 this.outProperties = PfUtils.mapMap(copyConcept.outProperties, UnaryOperator.identity());
164 this.deployState = copyConcept.deployState;
165 this.lockState = copyConcept.lockState;
166 this.subState = copyConcept.subState;
167 this.migrationState = copyConcept.migrationState;
168 this.operationalState = copyConcept.operationalState;
169 this.useState = copyConcept.useState;
170 this.stage = copyConcept.stage;
171 this.message = copyConcept.message;
175 * Authorative constructor.
177 * @param authorativeConcept the authorative concept to copy from
179 public JpaAutomationCompositionElement(@NonNull final AutomationCompositionElement authorativeConcept) {
180 this.fromAuthorative(authorativeConcept);
184 public AutomationCompositionElement toAuthorative() {
185 var element = new AutomationCompositionElement();
187 element.setId(UUID.fromString(elementId));
188 element.setDefinition(new ToscaConceptIdentifier(definition));
189 element.setParticipantId(UUID.fromString(participantId));
190 element.setDescription(description);
191 element.setProperties(PfUtils.mapMap(properties, UnaryOperator.identity()));
192 element.setOutProperties(PfUtils.mapMap(outProperties, UnaryOperator.identity()));
193 element.setDeployState(deployState);
194 element.setLockState(lockState);
195 element.setSubState(subState);
196 element.setMigrationState(migrationState);
197 element.setOperationalState(operationalState);
198 element.setUseState(useState);
199 element.setStage(stage);
200 element.setMessage(message);
206 public void fromAuthorative(@NonNull final AutomationCompositionElement element) {
207 this.definition = element.getDefinition().asConceptKey();
208 this.participantId = element.getParticipantId().toString();
209 this.description = element.getDescription();
210 this.properties = PfUtils.mapMap(element.getProperties(), UnaryOperator.identity());
211 this.outProperties = PfUtils.mapMap(element.getOutProperties(), UnaryOperator.identity());
212 this.deployState = element.getDeployState();
213 this.lockState = element.getLockState();
214 this.subState = element.getSubState();
215 this.migrationState = element.getMigrationState();
216 this.operationalState = element.getOperationalState();
217 this.useState = element.getUseState();
218 this.stage = element.getStage();
219 this.message = element.getMessage();
223 public int compareTo(final JpaAutomationCompositionElement other) {
231 var result = ObjectUtils.compare(elementId, other.elementId);
236 result = ObjectUtils.compare(instanceId, other.instanceId);
241 result = definition.compareTo(other.definition);
246 result = participantId.compareTo(other.participantId);
251 result = ObjectUtils.compare(deployState, other.deployState);
256 result = ObjectUtils.compare(lockState, other.lockState);
261 result = ObjectUtils.compare(subState, other.subState);
266 result = ObjectUtils.compare(migrationState, other.migrationState);
271 result = ObjectUtils.compare(useState, other.useState);
276 result = ObjectUtils.compare(stage, other.stage);
281 result = ObjectUtils.compare(operationalState, other.operationalState);
286 result = ObjectUtils.compare(message, other.message);
290 return ObjectUtils.compare(description, other.description);