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;
24 import java.util.UUID;
25 import java.util.function.UnaryOperator;
26 import javax.persistence.AttributeOverride;
27 import javax.persistence.AttributeOverrides;
28 import javax.persistence.Column;
29 import javax.persistence.Convert;
30 import javax.persistence.Entity;
31 import javax.persistence.Id;
32 import javax.persistence.Inheritance;
33 import javax.persistence.InheritanceType;
34 import javax.persistence.Lob;
35 import javax.persistence.Table;
37 import lombok.EqualsAndHashCode;
38 import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
39 import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState;
40 import org.onap.policy.common.parameters.annotations.NotNull;
41 import org.onap.policy.common.parameters.annotations.Valid;
42 import org.onap.policy.models.base.PfAuthorative;
43 import org.onap.policy.models.base.PfConceptKey;
44 import org.onap.policy.models.base.PfUtils;
45 import org.onap.policy.models.base.Validated;
46 import org.onap.policy.models.base.validation.annotations.VerifyKey;
47 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
50 @Table(name = "NodeTemplateState")
51 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
53 @EqualsAndHashCode(callSuper = false)
54 public class JpaNodeTemplateState extends Validated implements PfAuthorative<NodeTemplateState> {
58 private String nodeTemplateStateId;
62 private String compositionId;
65 private String participantId;
70 @AttributeOverride(name = "name", column = @Column(name = "nodeTemplate_name")),
71 @AttributeOverride(name = "version", column = @Column(name = "nodeTemplate_version"))
73 private PfConceptKey nodeTemplateId;
76 private Boolean restarting;
80 private AcTypeState state;
83 private String message;
88 @Convert(converter = StringToMapConverter.class)
89 private Map<String, Object> outProperties;
92 * The Default Constructor.
94 public JpaNodeTemplateState() {
95 this(UUID.randomUUID().toString(), UUID.randomUUID().toString());
101 * @param nodeTemplateStateId the nodeTemplateStateId
102 * @param compositionId the compositionId
104 public JpaNodeTemplateState(@NotNull String nodeTemplateStateId, @NotNull String compositionId) {
105 this.nodeTemplateStateId = nodeTemplateStateId;
106 this.compositionId = compositionId;
110 public void fromAuthorative(NodeTemplateState copyConcept) {
111 this.nodeTemplateStateId = copyConcept.getNodeTemplateStateId().toString();
112 if (copyConcept.getParticipantId() != null) {
113 this.participantId = copyConcept.getParticipantId().toString();
115 this.nodeTemplateId = copyConcept.getNodeTemplateId().asConceptKey();
116 this.restarting = copyConcept.getRestarting();
117 this.state = copyConcept.getState();
118 this.message = copyConcept.getMessage();
119 this.outProperties = PfUtils.mapMap(copyConcept.getOutProperties(), UnaryOperator.identity());
123 public NodeTemplateState toAuthorative() {
124 var nodeTemplateState = new NodeTemplateState();
125 nodeTemplateState.setNodeTemplateStateId(UUID.fromString(this.nodeTemplateStateId));
126 if (this.participantId != null) {
127 nodeTemplateState.setParticipantId(UUID.fromString(this.participantId));
129 nodeTemplateState.setNodeTemplateId(new ToscaConceptIdentifier(this.nodeTemplateId));
130 nodeTemplateState.setRestarting(this.restarting);
131 nodeTemplateState.setState(this.state);
132 nodeTemplateState.setMessage(this.message);
133 nodeTemplateState.setOutProperties(PfUtils.mapMap(outProperties, UnaryOperator.identity()));
134 return nodeTemplateState;