088bf2196a507317e7a9e5d6b5d81de4ca486c79
[policy/clamp.git] /
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.clamp.models.acm.persistence.concepts;
22
23 import java.util.UUID;
24 import javax.persistence.AttributeOverride;
25 import javax.persistence.Column;
26 import javax.persistence.Entity;
27 import javax.persistence.Id;
28 import javax.persistence.Inheritance;
29 import javax.persistence.InheritanceType;
30 import javax.persistence.Table;
31 import lombok.Data;
32 import lombok.EqualsAndHashCode;
33 import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
34 import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState;
35 import org.onap.policy.common.parameters.annotations.NotNull;
36 import org.onap.policy.models.base.PfAuthorative;
37 import org.onap.policy.models.base.PfConceptKey;
38 import org.onap.policy.models.base.Validated;
39 import org.onap.policy.models.base.validation.annotations.VerifyKey;
40 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
41
42 @Entity
43 @Table(name = "NodeTemplateState")
44 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
45 @Data
46 @EqualsAndHashCode(callSuper = false)
47 public class JpaNodeTemplateState extends Validated implements PfAuthorative<NodeTemplateState> {
48
49     @Id
50     @NotNull
51     private String nodeTemplateStateId;
52
53     @Column
54     @NotNull
55     private String compositionId;
56
57     @Column
58     private String participantId;
59
60     @VerifyKey
61     @NotNull
62     @AttributeOverride(name = "name",    column = @Column(name = "nodeTemplate_name"))
63     @AttributeOverride(name = "version", column = @Column(name = "nodeTemplate_version"))
64     private PfConceptKey nodeTemplateId;
65
66     @Column
67     @NotNull
68     private AcTypeState state;
69
70     /**
71      * The Default Constructor.
72      */
73     public JpaNodeTemplateState() {
74         this(UUID.randomUUID().toString(), UUID.randomUUID().toString());
75     }
76
77     /**
78      * Constructor.
79      *
80      * @param nodeTemplateStateId the nodeTemplateStateId
81      * @param compositionId the compositionId
82      */
83     public JpaNodeTemplateState(@NotNull String nodeTemplateStateId, @NotNull String compositionId) {
84         this.nodeTemplateStateId = nodeTemplateStateId;
85         this.compositionId = compositionId;
86     }
87
88     @Override
89     public void fromAuthorative(NodeTemplateState copyConcept) {
90         this.nodeTemplateStateId = copyConcept.getNodeTemplateStateId().toString();
91         if (copyConcept.getParticipantId() != null) {
92             this.participantId = copyConcept.getParticipantId().toString();
93         }
94         this.nodeTemplateId = copyConcept.getNodeTemplateId().asConceptKey();
95         this.state = copyConcept.getState();
96     }
97
98     @Override
99     public NodeTemplateState toAuthorative() {
100         var nodeTemplateState = new NodeTemplateState();
101         nodeTemplateState.setNodeTemplateStateId(UUID.fromString(this.nodeTemplateStateId));
102         if (this.participantId != null) {
103             nodeTemplateState.setParticipantId(UUID.fromString(this.participantId));
104         }
105         nodeTemplateState.setNodeTemplateId(new ToscaConceptIdentifier(this.nodeTemplateId));
106         nodeTemplateState.setState(this.state);
107         return nodeTemplateState;
108     }
109 }