2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021-2023 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.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;
86 private Boolean restarting;
90 private DeployState deployState;
94 private LockState lockState;
97 private String operationalState;
100 private String useState;
103 private String description;
106 private String message;
111 @Convert(converter = StringToMapConverter.class)
112 @Column(length = 100000)
113 private Map<String, Object> properties;
118 @Convert(converter = StringToMapConverter.class)
119 @Column(length = 100000)
120 private Map<String, Object> outProperties;
123 * The Default Constructor creates a {@link JpaAutomationCompositionElement} object with a null key.
125 public JpaAutomationCompositionElement() {
126 this(UUID.randomUUID().toString(), UUID.randomUUID().toString());
130 * The Key Constructor creates a {@link JpaAutomationCompositionElement} object with the given concept key.
132 * @param elementId The id of the automation composition instance Element
133 * @param instanceId The id of the automation composition instance
135 public JpaAutomationCompositionElement(@NonNull final String elementId, @NonNull final String instanceId) {
136 this(elementId, instanceId, new PfConceptKey(),
137 DeployState.UNDEPLOYED, LockState.LOCKED);
141 * The Key Constructor creates a {@link JpaAutomationCompositionElement} object with all mandatory fields.
143 * @param elementId The id of the automation composition instance Element
144 * @param instanceId The id of the automation composition instance
145 * @param definition the TOSCA definition of the automation composition element
146 * @param deployState the Deploy State of the automation composition
147 * @param lockState the Lock State of the automation composition
149 public JpaAutomationCompositionElement(@NonNull final String elementId, @NonNull final String instanceId,
150 @NonNull final PfConceptKey definition,
151 @NonNull final DeployState deployState, @NonNull final LockState lockState) {
152 this.elementId = elementId;
153 this.instanceId = instanceId;
154 this.definition = definition;
155 this.deployState = deployState;
156 this.lockState = lockState;
162 * @param copyConcept the concept to copy from
164 public JpaAutomationCompositionElement(@NonNull final JpaAutomationCompositionElement copyConcept) {
165 this.elementId = copyConcept.elementId;
166 this.instanceId = copyConcept.instanceId;
167 this.definition = new PfConceptKey(copyConcept.definition);
168 this.participantId = copyConcept.participantId;
169 this.description = copyConcept.description;
170 this.properties = (copyConcept.properties != null ? new LinkedHashMap<>(copyConcept.properties) : null);
172 (copyConcept.outProperties != null ? new LinkedHashMap<>(copyConcept.outProperties)
174 this.restarting = copyConcept.restarting;
175 this.deployState = copyConcept.deployState;
176 this.lockState = copyConcept.lockState;
177 this.operationalState = copyConcept.operationalState;
178 this.useState = copyConcept.useState;
179 this.message = copyConcept.message;
183 * Authorative constructor.
185 * @param authorativeConcept the authorative concept to copy from
187 public JpaAutomationCompositionElement(@NonNull final AutomationCompositionElement authorativeConcept) {
188 this.fromAuthorative(authorativeConcept);
192 public AutomationCompositionElement toAuthorative() {
193 var element = new AutomationCompositionElement();
195 element.setId(UUID.fromString(elementId));
196 element.setDefinition(new ToscaConceptIdentifier(definition));
197 element.setParticipantId(UUID.fromString(participantId));
198 element.setDescription(description);
199 element.setProperties(PfUtils.mapMap(properties, UnaryOperator.identity()));
200 element.setOutProperties(PfUtils.mapMap(outProperties, UnaryOperator.identity()));
201 element.setRestarting(restarting);
202 element.setDeployState(deployState);
203 element.setLockState(lockState);
204 element.setOperationalState(operationalState);
205 element.setUseState(useState);
206 element.setMessage(message);
212 public void fromAuthorative(@NonNull final AutomationCompositionElement element) {
213 this.definition = element.getDefinition().asConceptKey();
214 this.participantId = element.getParticipantId().toString();
215 this.description = element.getDescription();
216 this.properties = PfUtils.mapMap(element.getProperties(), UnaryOperator.identity());
217 this.outProperties = PfUtils.mapMap(element.getOutProperties(), UnaryOperator.identity());
218 this.restarting = element.getRestarting();
219 this.deployState = element.getDeployState();
220 this.lockState = element.getLockState();
221 this.operationalState = element.getOperationalState();
222 this.useState = element.getUseState();
223 this.message = element.getMessage();
227 public int compareTo(final JpaAutomationCompositionElement other) {
235 var result = ObjectUtils.compare(elementId, other.elementId);
240 result = ObjectUtils.compare(instanceId, other.instanceId);
245 result = definition.compareTo(other.definition);
250 result = participantId.compareTo(other.participantId);
255 result = ObjectUtils.compare(restarting, other.restarting);
260 result = ObjectUtils.compare(deployState, other.deployState);
265 result = ObjectUtils.compare(lockState, other.lockState);
270 result = ObjectUtils.compare(useState, other.useState);
275 result = ObjectUtils.compare(operationalState, other.operationalState);
280 result = ObjectUtils.compare(message, other.message);
284 return ObjectUtils.compare(description, other.description);