809e13911006db55f157782a5420dc1dcc63f796
[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.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;
32 import lombok.Data;
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;
42
43 @Entity
44 @Table(name = "NodeTemplateState")
45 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
46 @Data
47 @EqualsAndHashCode(callSuper = false)
48 public class JpaNodeTemplateState extends Validated implements PfAuthorative<NodeTemplateState> {
49
50     @Id
51     @NotNull
52     private String nodeTemplateStateId;
53
54     @Column
55     @NotNull
56     private String compositionId;
57
58     @Column
59     private String participantId;
60
61     @VerifyKey
62     @NotNull
63     @AttributeOverrides({
64         @AttributeOverride(name = "name",    column = @Column(name = "nodeTemplate_name")),
65         @AttributeOverride(name = "version", column = @Column(name = "nodeTemplate_version"))
66     })
67     private PfConceptKey nodeTemplateId;
68
69     @Column
70     private Boolean restarting;
71
72     @Column
73     @NotNull
74     private AcTypeState state;
75
76     @Column
77     private String message;
78
79     /**
80      * The Default Constructor.
81      */
82     public JpaNodeTemplateState() {
83         this(UUID.randomUUID().toString(), UUID.randomUUID().toString());
84     }
85
86     /**
87      * Constructor.
88      *
89      * @param nodeTemplateStateId the nodeTemplateStateId
90      * @param compositionId the compositionId
91      */
92     public JpaNodeTemplateState(@NotNull String nodeTemplateStateId, @NotNull String compositionId) {
93         this.nodeTemplateStateId = nodeTemplateStateId;
94         this.compositionId = compositionId;
95     }
96
97     @Override
98     public void fromAuthorative(NodeTemplateState copyConcept) {
99         this.nodeTemplateStateId = copyConcept.getNodeTemplateStateId().toString();
100         if (copyConcept.getParticipantId() != null) {
101             this.participantId = copyConcept.getParticipantId().toString();
102         }
103         this.nodeTemplateId = copyConcept.getNodeTemplateId().asConceptKey();
104         this.restarting = copyConcept.getRestarting();
105         this.state = copyConcept.getState();
106         this.message = copyConcept.getMessage();
107     }
108
109     @Override
110     public NodeTemplateState toAuthorative() {
111         var nodeTemplateState = new NodeTemplateState();
112         nodeTemplateState.setNodeTemplateStateId(UUID.fromString(this.nodeTemplateStateId));
113         if (this.participantId != null) {
114             nodeTemplateState.setParticipantId(UUID.fromString(this.participantId));
115         }
116         nodeTemplateState.setNodeTemplateId(new ToscaConceptIdentifier(this.nodeTemplateId));
117         nodeTemplateState.setRestarting(this.restarting);
118         nodeTemplateState.setState(this.state);
119         nodeTemplateState.setMessage(this.message);
120         return nodeTemplateState;
121     }
122 }