2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021-2024 Nordix Foundation.
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.Lob;
33 import jakarta.persistence.Table;
34 import java.util.LinkedHashMap;
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.SubState;
46 import org.onap.policy.common.parameters.annotations.NotNull;
47 import org.onap.policy.common.parameters.annotations.Valid;
48 import org.onap.policy.models.base.PfAuthorative;
49 import org.onap.policy.models.base.PfConceptKey;
50 import org.onap.policy.models.base.PfUtils;
51 import org.onap.policy.models.base.Validated;
52 import org.onap.policy.models.base.validation.annotations.VerifyKey;
53 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
56 * Class to represent a participant automation composition element in the database.
58 * @author Liam Fallon (liam.fallon@est.tech)
61 @Table(name = "AutomationCompositionElement")
62 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
64 @EqualsAndHashCode(callSuper = false)
65 public class JpaAutomationCompositionElement extends Validated
66 implements PfAuthorative<AutomationCompositionElement>, Comparable<JpaAutomationCompositionElement> {
70 private String elementId;
74 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;
87 private Boolean restarting;
91 private DeployState deployState;
95 private LockState lockState;
99 private SubState subState;
102 private String operationalState;
105 private String useState;
108 private String description;
111 private String message;
116 @Convert(converter = StringToMapConverter.class)
117 @Column(length = 100000)
118 private Map<String, Object> properties;
123 @Convert(converter = StringToMapConverter.class)
124 @Column(length = 100000)
125 private Map<String, Object> outProperties;
128 * The Default Constructor creates a {@link JpaAutomationCompositionElement} object with a null key.
130 public JpaAutomationCompositionElement() {
131 this(UUID.randomUUID().toString(), UUID.randomUUID().toString());
135 * The Key Constructor creates a {@link JpaAutomationCompositionElement} object with the given concept key.
137 * @param elementId The id of the automation composition instance Element
138 * @param instanceId The id of the automation composition instance
140 public JpaAutomationCompositionElement(@NonNull final String elementId, @NonNull final String instanceId) {
141 this(elementId, instanceId, new PfConceptKey(),
142 DeployState.UNDEPLOYED, LockState.NONE, SubState.NONE);
146 * The Key Constructor creates a {@link JpaAutomationCompositionElement} object with all mandatory fields.
148 * @param elementId The id of the automation composition instance Element
149 * @param instanceId The id of the automation composition instance
150 * @param definition the TOSCA definition of the automation composition element
151 * @param deployState the Deploy State of the automation composition
152 * @param lockState the Lock State of the automation composition
153 * @param subState the Sub State of the automation composition
155 public JpaAutomationCompositionElement(@NonNull final String elementId, @NonNull final String instanceId,
156 @NonNull final PfConceptKey definition,
157 @NonNull final DeployState deployState, @NonNull final LockState lockState,
158 @NonNull final SubState subState) {
159 this.elementId = elementId;
160 this.instanceId = instanceId;
161 this.definition = definition;
162 this.deployState = deployState;
163 this.lockState = lockState;
164 this.subState = subState;
170 * @param copyConcept the concept to copy from
172 public JpaAutomationCompositionElement(@NonNull final JpaAutomationCompositionElement copyConcept) {
173 this.elementId = copyConcept.elementId;
174 this.instanceId = copyConcept.instanceId;
175 this.definition = new PfConceptKey(copyConcept.definition);
176 this.participantId = copyConcept.participantId;
177 this.description = copyConcept.description;
178 this.properties = (copyConcept.properties != null ? new LinkedHashMap<>(copyConcept.properties) : null);
180 (copyConcept.outProperties != null ? new LinkedHashMap<>(copyConcept.outProperties)
182 this.restarting = copyConcept.restarting;
183 this.deployState = copyConcept.deployState;
184 this.lockState = copyConcept.lockState;
185 this.subState = copyConcept.subState;
186 this.operationalState = copyConcept.operationalState;
187 this.useState = copyConcept.useState;
188 this.message = copyConcept.message;
192 * Authorative constructor.
194 * @param authorativeConcept the authorative concept to copy from
196 public JpaAutomationCompositionElement(@NonNull final AutomationCompositionElement authorativeConcept) {
197 this.fromAuthorative(authorativeConcept);
201 public AutomationCompositionElement toAuthorative() {
202 var element = new AutomationCompositionElement();
204 element.setId(UUID.fromString(elementId));
205 element.setDefinition(new ToscaConceptIdentifier(definition));
206 element.setParticipantId(UUID.fromString(participantId));
207 element.setDescription(description);
208 element.setProperties(PfUtils.mapMap(properties, UnaryOperator.identity()));
209 element.setOutProperties(PfUtils.mapMap(outProperties, UnaryOperator.identity()));
210 element.setRestarting(restarting);
211 element.setDeployState(deployState);
212 element.setLockState(lockState);
213 element.setSubState(subState);
214 element.setOperationalState(operationalState);
215 element.setUseState(useState);
216 element.setMessage(message);
222 public void fromAuthorative(@NonNull final AutomationCompositionElement element) {
223 this.definition = element.getDefinition().asConceptKey();
224 this.participantId = element.getParticipantId().toString();
225 this.description = element.getDescription();
226 this.properties = PfUtils.mapMap(element.getProperties(), UnaryOperator.identity());
227 this.outProperties = PfUtils.mapMap(element.getOutProperties(), UnaryOperator.identity());
228 this.restarting = element.getRestarting();
229 this.deployState = element.getDeployState();
230 this.lockState = element.getLockState();
231 this.subState = element.getSubState();
232 this.operationalState = element.getOperationalState();
233 this.useState = element.getUseState();
234 this.message = element.getMessage();
238 public int compareTo(final JpaAutomationCompositionElement other) {
246 var result = ObjectUtils.compare(elementId, other.elementId);
251 result = ObjectUtils.compare(instanceId, other.instanceId);
256 result = definition.compareTo(other.definition);
261 result = participantId.compareTo(other.participantId);
266 result = ObjectUtils.compare(restarting, other.restarting);
271 result = ObjectUtils.compare(deployState, other.deployState);
276 result = ObjectUtils.compare(lockState, other.lockState);
281 result = ObjectUtils.compare(subState, other.subState);
286 result = ObjectUtils.compare(useState, other.useState);
291 result = ObjectUtils.compare(operationalState, other.operationalState);
296 result = ObjectUtils.compare(message, other.message);
300 return ObjectUtils.compare(description, other.description);