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;
85 private String participantId;
89 private DeployState deployState;
93 private LockState lockState;
96 private String operationalState;
99 private String useState;
102 private String description;
105 private String message;
110 @Convert(converter = StringToMapConverter.class)
111 private Map<String, Object> properties;
116 @Convert(converter = StringToMapConverter.class)
117 private Map<String, Object> outProperties;
120 * The Default Constructor creates a {@link JpaAutomationCompositionElement} object with a null key.
122 public JpaAutomationCompositionElement() {
123 this(UUID.randomUUID().toString(), UUID.randomUUID().toString());
127 * The Key Constructor creates a {@link JpaAutomationCompositionElement} object with the given concept key.
129 * @param elementId The id of the automation composition instance Element
130 * @param instanceId The id of the automation composition instance
132 public JpaAutomationCompositionElement(@NonNull final String elementId, @NonNull final String instanceId) {
133 this(elementId, instanceId, new PfConceptKey(),
134 DeployState.UNDEPLOYED, LockState.LOCKED);
138 * The Key Constructor creates a {@link JpaAutomationCompositionElement} object with all mandatory fields.
140 * @param elementId The id of the automation composition instance Element
141 * @param instanceId The id of the automation composition instance
142 * @param definition the TOSCA definition of the automation composition element
143 * @param deployState the Deploy State of the automation composition
144 * @param lockState the Lock State of the automation composition
146 public JpaAutomationCompositionElement(@NonNull final String elementId, @NonNull final String instanceId,
147 @NonNull final PfConceptKey definition,
148 @NonNull final DeployState deployState, @NonNull final LockState lockState) {
149 this.elementId = elementId;
150 this.instanceId = instanceId;
151 this.definition = definition;
152 this.deployState = deployState;
153 this.lockState = lockState;
159 * @param copyConcept the concept to copy from
161 public JpaAutomationCompositionElement(@NonNull final JpaAutomationCompositionElement copyConcept) {
162 this.elementId = copyConcept.elementId;
163 this.instanceId = copyConcept.instanceId;
164 this.definition = new PfConceptKey(copyConcept.definition);
165 this.participantId = copyConcept.participantId;
166 this.description = copyConcept.description;
167 this.properties = (copyConcept.properties != null ? new LinkedHashMap<>(copyConcept.properties) : null);
169 (copyConcept.outProperties != null ? new LinkedHashMap<>(copyConcept.outProperties)
171 this.deployState = copyConcept.deployState;
172 this.lockState = copyConcept.lockState;
173 this.operationalState = copyConcept.operationalState;
174 this.useState = copyConcept.useState;
175 this.message = copyConcept.message;
179 * Authorative constructor.
181 * @param authorativeConcept the authorative concept to copy from
183 public JpaAutomationCompositionElement(@NonNull final AutomationCompositionElement authorativeConcept) {
184 this.fromAuthorative(authorativeConcept);
188 public AutomationCompositionElement toAuthorative() {
189 var element = new AutomationCompositionElement();
191 element.setId(UUID.fromString(elementId));
192 element.setDefinition(new ToscaConceptIdentifier(definition));
193 element.setParticipantId(UUID.fromString(participantId));
194 element.setDescription(description);
195 element.setProperties(PfUtils.mapMap(properties, UnaryOperator.identity()));
196 element.setOutProperties(PfUtils.mapMap(outProperties, UnaryOperator.identity()));
197 element.setDeployState(deployState);
198 element.setLockState(lockState);
199 element.setOperationalState(operationalState);
200 element.setUseState(useState);
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.operationalState = element.getOperationalState();
216 this.useState = element.getUseState();
217 this.message = element.getMessage();
221 public int compareTo(final JpaAutomationCompositionElement other) {
229 var result = ObjectUtils.compare(elementId, other.elementId);
234 result = ObjectUtils.compare(instanceId, other.instanceId);
239 result = definition.compareTo(other.definition);
244 result = participantId.compareTo(other.participantId);
249 result = ObjectUtils.compare(deployState, other.deployState);
254 result = ObjectUtils.compare(lockState, other.lockState);
259 result = ObjectUtils.compare(useState, other.useState);
264 result = ObjectUtils.compare(operationalState, other.operationalState);
269 result = ObjectUtils.compare(message, other.message);
273 return ObjectUtils.compare(description, other.description);