a6d13a63882fec4e01abc4817e1688f6433d317d
[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.Column;
25 import javax.persistence.Entity;
26 import javax.persistence.Id;
27 import javax.persistence.Inheritance;
28 import javax.persistence.InheritanceType;
29 import javax.persistence.Table;
30 import lombok.Data;
31 import lombok.EqualsAndHashCode;
32 import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
33 import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState;
34 import org.onap.policy.common.parameters.annotations.NotNull;
35 import org.onap.policy.models.base.PfAuthorative;
36 import org.onap.policy.models.base.Validated;
37 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
38
39 @Entity
40 @Table(name = "NodeTemplateState")
41 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
42 @Data
43 @EqualsAndHashCode(callSuper = false)
44 public class JpaNodeTemplateState extends Validated implements PfAuthorative<NodeTemplateState> {
45
46     @Id
47     @NotNull
48     private String nodeTemplateStateId;
49
50     @Column
51     @NotNull
52     private String compositionId;
53
54     @Column
55     private String participantId;
56
57     @Column
58     @NotNull
59     private ToscaConceptIdentifier nodeTemplateId;
60
61     @Column
62     @NotNull
63     private AcTypeState state;
64
65     /**
66      * The Default Constructor.
67      */
68     public JpaNodeTemplateState() {
69         this(UUID.randomUUID().toString(), UUID.randomUUID().toString());
70     }
71
72     /**
73      * Constructor.
74      *
75      * @param nodeTemplateStateId the nodeTemplateStateId
76      * @param compositionId the compositionId
77      */
78     public JpaNodeTemplateState(@NotNull String nodeTemplateStateId, @NotNull String compositionId) {
79         this.nodeTemplateStateId = nodeTemplateStateId;
80         this.compositionId = compositionId;
81     }
82
83     @Override
84     public void fromAuthorative(NodeTemplateState copyConcept) {
85         this.nodeTemplateStateId = copyConcept.getNodeTemplateStateId().toString();
86         if (copyConcept.getParticipantId() != null) {
87             this.participantId = copyConcept.getParticipantId().toString();
88         }
89         this.nodeTemplateId = copyConcept.getNodeTemplateId();
90     }
91
92     @Override
93     public NodeTemplateState toAuthorative() {
94         var nodeTemplateState = new NodeTemplateState();
95         nodeTemplateState.setNodeTemplateStateId(UUID.fromString(this.nodeTemplateStateId));
96         if (this.participantId != null) {
97             nodeTemplateState.setParticipantId(UUID.fromString(this.participantId));
98         }
99         nodeTemplateState.setNodeTemplateId(this.nodeTemplateId);
100         nodeTemplateState.setState(this.state);
101         return nodeTemplateState;
102     }
103 }