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 java.util.LinkedHashMap;
27 import java.util.UUID;
28 import java.util.function.UnaryOperator;
29 import javax.persistence.AttributeOverride;
30 import javax.persistence.AttributeOverrides;
31 import javax.persistence.Column;
32 import javax.persistence.Convert;
33 import javax.persistence.Entity;
34 import javax.persistence.Id;
35 import javax.persistence.Inheritance;
36 import javax.persistence.InheritanceType;
37 import javax.persistence.Lob;
38 import javax.persistence.Table;
40 import lombok.EqualsAndHashCode;
41 import lombok.NonNull;
42 import org.apache.commons.lang3.ObjectUtils;
43 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
44 import org.onap.policy.clamp.models.acm.concepts.DeployState;
45 import org.onap.policy.clamp.models.acm.concepts.LockState;
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;
79 @AttributeOverride(name = "name", column = @Column(name = "definition_name")),
80 @AttributeOverride(name = "version", column = @Column(name = "definition_version"))
82 private PfConceptKey definition;
86 private String participantId;
89 private Boolean restarting;
93 private DeployState deployState;
97 private LockState lockState;
100 private String operationalState;
103 private String useState;
106 private String description;
109 private String message;
114 @Convert(converter = StringToMapConverter.class)
115 private Map<String, Object> properties;
120 @Convert(converter = StringToMapConverter.class)
121 private Map<String, Object> outProperties;
124 * The Default Constructor creates a {@link JpaAutomationCompositionElement} object with a null key.
126 public JpaAutomationCompositionElement() {
127 this(UUID.randomUUID().toString(), UUID.randomUUID().toString());
131 * The Key Constructor creates a {@link JpaAutomationCompositionElement} object with the given concept key.
133 * @param elementId The id of the automation composition instance Element
134 * @param instanceId The id of the automation composition instance
136 public JpaAutomationCompositionElement(@NonNull final String elementId, @NonNull final String instanceId) {
137 this(elementId, instanceId, new PfConceptKey(),
138 DeployState.UNDEPLOYED, LockState.LOCKED);
142 * The Key Constructor creates a {@link JpaAutomationCompositionElement} object with all mandatory fields.
144 * @param elementId The id of the automation composition instance Element
145 * @param instanceId The id of the automation composition instance
146 * @param definition the TOSCA definition of the automation composition element
147 * @param deployState the Deploy State of the automation composition
148 * @param lockState the Lock State of the automation composition
150 public JpaAutomationCompositionElement(@NonNull final String elementId, @NonNull final String instanceId,
151 @NonNull final PfConceptKey definition,
152 @NonNull final DeployState deployState, @NonNull final LockState lockState) {
153 this.elementId = elementId;
154 this.instanceId = instanceId;
155 this.definition = definition;
156 this.deployState = deployState;
157 this.lockState = lockState;
163 * @param copyConcept the concept to copy from
165 public JpaAutomationCompositionElement(@NonNull final JpaAutomationCompositionElement copyConcept) {
166 this.elementId = copyConcept.elementId;
167 this.instanceId = copyConcept.instanceId;
168 this.definition = new PfConceptKey(copyConcept.definition);
169 this.participantId = copyConcept.participantId;
170 this.description = copyConcept.description;
171 this.properties = (copyConcept.properties != null ? new LinkedHashMap<>(copyConcept.properties) : null);
173 (copyConcept.outProperties != null ? new LinkedHashMap<>(copyConcept.outProperties)
175 this.restarting = copyConcept.restarting;
176 this.deployState = copyConcept.deployState;
177 this.lockState = copyConcept.lockState;
178 this.operationalState = copyConcept.operationalState;
179 this.useState = copyConcept.useState;
180 this.message = copyConcept.message;
184 * Authorative constructor.
186 * @param authorativeConcept the authorative concept to copy from
188 public JpaAutomationCompositionElement(@NonNull final AutomationCompositionElement authorativeConcept) {
189 this.fromAuthorative(authorativeConcept);
193 public AutomationCompositionElement toAuthorative() {
194 var element = new AutomationCompositionElement();
196 element.setId(UUID.fromString(elementId));
197 element.setDefinition(new ToscaConceptIdentifier(definition));
198 element.setParticipantId(UUID.fromString(participantId));
199 element.setDescription(description);
200 element.setProperties(PfUtils.mapMap(properties, UnaryOperator.identity()));
201 element.setOutProperties(PfUtils.mapMap(outProperties, UnaryOperator.identity()));
202 element.setRestarting(restarting);
203 element.setDeployState(deployState);
204 element.setLockState(lockState);
205 element.setOperationalState(operationalState);
206 element.setUseState(useState);
207 element.setMessage(message);
213 public void fromAuthorative(@NonNull final AutomationCompositionElement element) {
214 this.definition = element.getDefinition().asConceptKey();
215 this.participantId = element.getParticipantId().toString();
216 this.description = element.getDescription();
217 this.properties = PfUtils.mapMap(element.getProperties(), UnaryOperator.identity());
218 this.outProperties = PfUtils.mapMap(element.getOutProperties(), UnaryOperator.identity());
219 this.restarting = element.getRestarting();
220 this.deployState = element.getDeployState();
221 this.lockState = element.getLockState();
222 this.operationalState = element.getOperationalState();
223 this.useState = element.getUseState();
224 this.message = element.getMessage();
228 public int compareTo(final JpaAutomationCompositionElement other) {
236 var result = ObjectUtils.compare(elementId, other.elementId);
241 result = ObjectUtils.compare(instanceId, other.instanceId);
246 result = definition.compareTo(other.definition);
251 result = participantId.compareTo(other.participantId);
256 result = ObjectUtils.compare(restarting, other.restarting);
261 result = ObjectUtils.compare(deployState, other.deployState);
266 result = ObjectUtils.compare(lockState, other.lockState);
271 result = ObjectUtils.compare(useState, other.useState);
276 result = ObjectUtils.compare(operationalState, other.operationalState);
281 result = ObjectUtils.compare(message, other.message);
285 return ObjectUtils.compare(description, other.description);