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;
33 import java.util.LinkedHashMap;
35 import java.util.UUID;
36 import java.util.function.UnaryOperator;
38 import lombok.EqualsAndHashCode;
39 import lombok.NonNull;
40 import org.apache.commons.lang3.ObjectUtils;
41 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
42 import org.onap.policy.clamp.models.acm.concepts.DeployState;
43 import org.onap.policy.clamp.models.acm.concepts.LockState;
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;
98 private String operationalState;
101 private String useState;
104 private Integer stage;
107 private String description;
110 private String message;
114 @Convert(converter = StringToMapConverter.class)
115 @Column(length = 100000)
116 private Map<String, Object> properties;
120 @Convert(converter = StringToMapConverter.class)
121 @Column(length = 100000)
122 private Map<String, Object> outProperties;
125 * The Default Constructor creates a {@link JpaAutomationCompositionElement} object with a null key.
127 public JpaAutomationCompositionElement() {
128 this(UUID.randomUUID().toString(), UUID.randomUUID().toString());
132 * The Key Constructor creates a {@link JpaAutomationCompositionElement} object with the given concept key.
134 * @param elementId The id of the automation composition instance Element
135 * @param instanceId The id of the automation composition instance
137 public JpaAutomationCompositionElement(@NonNull final String elementId, @NonNull final String instanceId) {
138 this(elementId, instanceId, new PfConceptKey(),
139 DeployState.UNDEPLOYED, LockState.NONE, SubState.NONE);
143 * The Key Constructor creates a {@link JpaAutomationCompositionElement} object with all mandatory fields.
145 * @param elementId The id of the automation composition instance Element
146 * @param instanceId The id of the automation composition instance
147 * @param definition the TOSCA definition of the automation composition element
148 * @param deployState the Deploy State of the automation composition
149 * @param lockState the Lock State of the automation composition
150 * @param subState the Sub State of the automation composition
152 public JpaAutomationCompositionElement(@NonNull final String elementId, @NonNull final String instanceId,
153 @NonNull final PfConceptKey definition,
154 @NonNull final DeployState deployState, @NonNull final LockState lockState,
155 @NonNull final SubState subState) {
156 this.elementId = elementId;
157 this.instanceId = instanceId;
158 this.definition = definition;
159 this.deployState = deployState;
160 this.lockState = lockState;
161 this.subState = subState;
167 * @param copyConcept the concept to copy from
169 public JpaAutomationCompositionElement(@NonNull final JpaAutomationCompositionElement copyConcept) {
170 this.elementId = copyConcept.elementId;
171 this.instanceId = copyConcept.instanceId;
172 this.definition = new PfConceptKey(copyConcept.definition);
173 this.participantId = copyConcept.participantId;
174 this.description = copyConcept.description;
175 this.properties = PfUtils.mapMap(copyConcept.properties, UnaryOperator.identity());
176 this.outProperties = PfUtils.mapMap(copyConcept.outProperties, UnaryOperator.identity());
177 this.deployState = copyConcept.deployState;
178 this.lockState = copyConcept.lockState;
179 this.subState = copyConcept.subState;
180 this.operationalState = copyConcept.operationalState;
181 this.useState = copyConcept.useState;
182 this.stage = copyConcept.stage;
183 this.message = copyConcept.message;
187 * Authorative constructor.
189 * @param authorativeConcept the authorative concept to copy from
191 public JpaAutomationCompositionElement(@NonNull final AutomationCompositionElement authorativeConcept) {
192 this.fromAuthorative(authorativeConcept);
196 public AutomationCompositionElement toAuthorative() {
197 var element = new AutomationCompositionElement();
199 element.setId(UUID.fromString(elementId));
200 element.setDefinition(new ToscaConceptIdentifier(definition));
201 element.setParticipantId(UUID.fromString(participantId));
202 element.setDescription(description);
203 element.setProperties(PfUtils.mapMap(properties, UnaryOperator.identity()));
204 element.setOutProperties(PfUtils.mapMap(outProperties, UnaryOperator.identity()));
205 element.setDeployState(deployState);
206 element.setLockState(lockState);
207 element.setSubState(subState);
208 element.setOperationalState(operationalState);
209 element.setUseState(useState);
210 element.setStage(stage);
211 element.setMessage(message);
217 public void fromAuthorative(@NonNull final AutomationCompositionElement element) {
218 this.definition = element.getDefinition().asConceptKey();
219 this.participantId = element.getParticipantId().toString();
220 this.description = element.getDescription();
221 this.properties = PfUtils.mapMap(element.getProperties(), UnaryOperator.identity());
222 this.outProperties = PfUtils.mapMap(element.getOutProperties(), UnaryOperator.identity());
223 this.deployState = element.getDeployState();
224 this.lockState = element.getLockState();
225 this.subState = element.getSubState();
226 this.operationalState = element.getOperationalState();
227 this.useState = element.getUseState();
228 this.stage = element.getStage();
229 this.message = element.getMessage();
233 public int compareTo(final JpaAutomationCompositionElement other) {
241 var result = ObjectUtils.compare(elementId, other.elementId);
246 result = ObjectUtils.compare(instanceId, other.instanceId);
251 result = definition.compareTo(other.definition);
256 result = participantId.compareTo(other.participantId);
261 result = ObjectUtils.compare(deployState, other.deployState);
266 result = ObjectUtils.compare(lockState, other.lockState);
271 result = ObjectUtils.compare(subState, other.subState);
276 result = ObjectUtils.compare(useState, other.useState);
281 result = ObjectUtils.compare(stage, other.stage);
286 result = ObjectUtils.compare(operationalState, other.operationalState);
291 result = ObjectUtils.compare(message, other.message);
295 return ObjectUtils.compare(description, other.description);