8ee1075f6e5c5e9b44afe0dfac0c2544de2d3573
[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     @NotNull
71     private AcTypeState state;
72
73     @Column
74     private String message;
75
76     /**
77      * The Default Constructor.
78      */
79     public JpaNodeTemplateState() {
80         this(UUID.randomUUID().toString(), UUID.randomUUID().toString());
81     }
82
83     /**
84      * Constructor.
85      *
86      * @param nodeTemplateStateId the nodeTemplateStateId
87      * @param compositionId the compositionId
88      */
89     public JpaNodeTemplateState(@NotNull String nodeTemplateStateId, @NotNull String compositionId) {
90         this.nodeTemplateStateId = nodeTemplateStateId;
91         this.compositionId = compositionId;
92     }
93
94     @Override
95     public void fromAuthorative(NodeTemplateState copyConcept) {
96         this.nodeTemplateStateId = copyConcept.getNodeTemplateStateId().toString();
97         if (copyConcept.getParticipantId() != null) {
98             this.participantId = copyConcept.getParticipantId().toString();
99         }
100         this.nodeTemplateId = copyConcept.getNodeTemplateId().asConceptKey();
101         this.state = copyConcept.getState();
102         this.message = copyConcept.getMessage();
103     }
104
105     @Override
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));
111         }
112         nodeTemplateState.setNodeTemplateId(new ToscaConceptIdentifier(this.nodeTemplateId));
113         nodeTemplateState.setState(this.state);
114         nodeTemplateState.setMessage(this.message);
115         return nodeTemplateState;
116     }
117 }