2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021-2026 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;
33 import jakarta.validation.Valid;
34 import jakarta.validation.constraints.NotNull;
36 import java.util.UUID;
37 import java.util.function.UnaryOperator;
39 import lombok.EqualsAndHashCode;
40 import lombok.NonNull;
41 import org.apache.commons.lang3.ObjectUtils;
42 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
43 import org.onap.policy.clamp.models.acm.concepts.DeployState;
44 import org.onap.policy.clamp.models.acm.concepts.LockState;
45 import org.onap.policy.clamp.models.acm.concepts.MigrationState;
46 import org.onap.policy.clamp.models.acm.concepts.SubState;
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;
78 @AttributeOverride(name = "name", column = @Column(name = "definition_name"))
79 @AttributeOverride(name = "version", column = @Column(name = "definition_version"))
80 private PfConceptKey definition;
84 private String participantId;
88 private DeployState deployState;
92 private LockState lockState;
96 private SubState subState;
100 private MigrationState migrationState;
103 private String operationalState;
106 private String useState;
109 private Integer stage;
112 private String description;
115 private String message;
119 @Convert(converter = StringToMapConverter.class)
120 @Column(length = 100000)
121 private Map<String, Object> properties;
125 @Convert(converter = StringToMapConverter.class)
126 @Column(length = 100000)
127 private Map<String, Object> outProperties;
130 * The Default Constructor creates a {@link JpaAutomationCompositionElement} object with a null key.
132 public JpaAutomationCompositionElement() {
133 this(UUID.randomUUID().toString(), UUID.randomUUID().toString());
137 * The Key Constructor creates a {@link JpaAutomationCompositionElement} object with the given concept key.
139 * @param elementId The id of the automation composition instance Element
140 * @param instanceId The id of the automation composition instance
142 public JpaAutomationCompositionElement(@NonNull final String elementId, @NonNull final String instanceId) {
143 this.elementId = elementId;
144 this.instanceId = instanceId;
145 this.definition = new PfConceptKey();
146 this.deployState = DeployState.UNDEPLOYED;
147 this.lockState = LockState.NONE;
148 this.subState = SubState.NONE;
149 this.migrationState = MigrationState.DEFAULT;
155 * @param copyConcept the concept to copy from
157 public JpaAutomationCompositionElement(@NonNull final JpaAutomationCompositionElement copyConcept) {
158 this.elementId = copyConcept.elementId;
159 this.instanceId = copyConcept.instanceId;
160 this.definition = new PfConceptKey(copyConcept.definition);
161 this.participantId = copyConcept.participantId;
162 this.description = copyConcept.description;
163 this.properties = PfUtils.mapMap(copyConcept.properties, UnaryOperator.identity());
164 this.outProperties = PfUtils.mapMap(copyConcept.outProperties, UnaryOperator.identity());
165 this.deployState = copyConcept.deployState;
166 this.lockState = copyConcept.lockState;
167 this.subState = copyConcept.subState;
168 this.migrationState = copyConcept.migrationState;
169 this.operationalState = copyConcept.operationalState;
170 this.useState = copyConcept.useState;
171 this.stage = copyConcept.stage;
172 this.message = copyConcept.message;
176 * Authorative constructor.
178 * @param authorativeConcept the authorative concept to copy from
180 public JpaAutomationCompositionElement(@NonNull final AutomationCompositionElement authorativeConcept) {
181 this.fromAuthorative(authorativeConcept);
185 public AutomationCompositionElement toAuthorative() {
186 var element = new AutomationCompositionElement();
188 element.setId(UUID.fromString(elementId));
189 element.setDefinition(new ToscaConceptIdentifier(definition));
190 element.setParticipantId(UUID.fromString(participantId));
191 element.setDescription(description);
192 element.setProperties(PfUtils.mapMap(properties, UnaryOperator.identity()));
193 element.setOutProperties(PfUtils.mapMap(outProperties, UnaryOperator.identity()));
194 element.setDeployState(deployState);
195 element.setLockState(lockState);
196 element.setSubState(subState);
197 element.setMigrationState(migrationState);
198 element.setOperationalState(operationalState);
199 element.setUseState(useState);
200 element.setStage(stage);
201 element.setMessage(message);
207 public void fromAuthorative(@NonNull final AutomationCompositionElement element) {
208 this.definition = element.getDefinition().asConceptKey();
209 this.participantId = element.getParticipantId().toString();
210 this.description = element.getDescription();
211 this.properties = PfUtils.mapMap(element.getProperties(), UnaryOperator.identity());
212 this.outProperties = PfUtils.mapMap(element.getOutProperties(), UnaryOperator.identity());
213 this.deployState = element.getDeployState();
214 this.lockState = element.getLockState();
215 this.subState = element.getSubState();
216 this.migrationState = element.getMigrationState();
217 this.operationalState = element.getOperationalState();
218 this.useState = element.getUseState();
219 this.stage = element.getStage();
220 this.message = element.getMessage();
224 public int compareTo(final JpaAutomationCompositionElement other) {
232 var result = ObjectUtils.compare(elementId, other.elementId);
237 result = ObjectUtils.compare(instanceId, other.instanceId);
242 result = definition.compareTo(other.definition);
247 result = participantId.compareTo(other.participantId);
252 result = ObjectUtils.compare(deployState, other.deployState);
257 result = ObjectUtils.compare(lockState, other.lockState);
262 result = ObjectUtils.compare(subState, other.subState);
267 result = ObjectUtils.compare(migrationState, other.migrationState);
272 result = ObjectUtils.compare(useState, other.useState);
277 result = ObjectUtils.compare(stage, other.stage);
282 result = ObjectUtils.compare(operationalState, other.operationalState);
287 result = ObjectUtils.compare(message, other.message);
291 return ObjectUtils.compare(description, other.description);