2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.clamp.models.acm.persistence.concepts;
23 import java.util.UUID;
24 import javax.persistence.AttributeOverride;
25 import javax.persistence.AttributeOverrides;
26 import javax.persistence.Column;
27 import javax.persistence.Entity;
28 import javax.persistence.Id;
29 import javax.persistence.Inheritance;
30 import javax.persistence.InheritanceType;
31 import javax.persistence.Table;
33 import lombok.EqualsAndHashCode;
34 import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
35 import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState;
36 import org.onap.policy.common.parameters.annotations.NotNull;
37 import org.onap.policy.models.base.PfAuthorative;
38 import org.onap.policy.models.base.PfConceptKey;
39 import org.onap.policy.models.base.Validated;
40 import org.onap.policy.models.base.validation.annotations.VerifyKey;
41 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
44 @Table(name = "NodeTemplateState")
45 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
47 @EqualsAndHashCode(callSuper = false)
48 public class JpaNodeTemplateState extends Validated implements PfAuthorative<NodeTemplateState> {
52 private String nodeTemplateStateId;
56 private String compositionId;
59 private String participantId;
64 @AttributeOverride(name = "name", column = @Column(name = "nodeTemplate_name")),
65 @AttributeOverride(name = "version", column = @Column(name = "nodeTemplate_version"))
67 private PfConceptKey nodeTemplateId;
71 private AcTypeState state;
74 private String message;
77 * The Default Constructor.
79 public JpaNodeTemplateState() {
80 this(UUID.randomUUID().toString(), UUID.randomUUID().toString());
86 * @param nodeTemplateStateId the nodeTemplateStateId
87 * @param compositionId the compositionId
89 public JpaNodeTemplateState(@NotNull String nodeTemplateStateId, @NotNull String compositionId) {
90 this.nodeTemplateStateId = nodeTemplateStateId;
91 this.compositionId = compositionId;
95 public void fromAuthorative(NodeTemplateState copyConcept) {
96 this.nodeTemplateStateId = copyConcept.getNodeTemplateStateId().toString();
97 if (copyConcept.getParticipantId() != null) {
98 this.participantId = copyConcept.getParticipantId().toString();
100 this.nodeTemplateId = copyConcept.getNodeTemplateId().asConceptKey();
101 this.state = copyConcept.getState();
102 this.message = copyConcept.getMessage();
106 public NodeTemplateState toAuthorative() {
107 var nodeTemplateState = new NodeTemplateState();
108 nodeTemplateState.setNodeTemplateStateId(UUID.fromString(this.nodeTemplateStateId));
109 if (this.participantId != null) {
110 nodeTemplateState.setParticipantId(UUID.fromString(this.participantId));
112 nodeTemplateState.setNodeTemplateId(new ToscaConceptIdentifier(this.nodeTemplateId));
113 nodeTemplateState.setState(this.state);
114 nodeTemplateState.setMessage(this.message);
115 return nodeTemplateState;