2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023,2025 OpenInfra Foundation Europe. All rights reserved.
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;
23 import jakarta.persistence.AttributeOverride;
24 import jakarta.persistence.Column;
25 import jakarta.persistence.Convert;
26 import jakarta.persistence.Entity;
27 import jakarta.persistence.Id;
28 import jakarta.persistence.Inheritance;
29 import jakarta.persistence.InheritanceType;
30 import jakarta.persistence.Table;
32 import java.util.UUID;
33 import java.util.function.UnaryOperator;
35 import lombok.EqualsAndHashCode;
36 import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
37 import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState;
38 import org.onap.policy.common.parameters.annotations.NotNull;
39 import org.onap.policy.common.parameters.annotations.Valid;
40 import org.onap.policy.models.base.PfAuthorative;
41 import org.onap.policy.models.base.PfConceptKey;
42 import org.onap.policy.models.base.PfUtils;
43 import org.onap.policy.models.base.Validated;
44 import org.onap.policy.models.base.validation.annotations.VerifyKey;
45 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
48 @Table(name = "NodeTemplateState")
49 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
51 @EqualsAndHashCode(callSuper = false)
52 public class JpaNodeTemplateState extends Validated implements PfAuthorative<NodeTemplateState> {
56 private String nodeTemplateStateId;
60 private String compositionId;
63 private String participantId;
67 @AttributeOverride(name = "name", column = @Column(name = "nodeTemplate_name"))
68 @AttributeOverride(name = "version", column = @Column(name = "nodeTemplate_version"))
69 private PfConceptKey nodeTemplateId;
72 private Boolean restarting;
76 private AcTypeState state;
79 private String message;
83 @Convert(converter = StringToMapConverter.class)
84 @Column(length = 100000)
85 private Map<String, Object> outProperties;
88 * The Default Constructor.
90 public JpaNodeTemplateState() {
91 this(UUID.randomUUID().toString(), UUID.randomUUID().toString());
97 * @param nodeTemplateStateId the nodeTemplateStateId
98 * @param compositionId the compositionId
100 public JpaNodeTemplateState(@NotNull String nodeTemplateStateId, @NotNull String compositionId) {
101 this.nodeTemplateStateId = nodeTemplateStateId;
102 this.compositionId = compositionId;
106 public void fromAuthorative(NodeTemplateState copyConcept) {
107 this.nodeTemplateStateId = copyConcept.getNodeTemplateStateId().toString();
108 if (copyConcept.getParticipantId() != null) {
109 this.participantId = copyConcept.getParticipantId().toString();
111 this.nodeTemplateId = copyConcept.getNodeTemplateId().asConceptKey();
112 this.restarting = copyConcept.getRestarting();
113 this.state = copyConcept.getState();
114 this.message = copyConcept.getMessage();
115 this.outProperties = PfUtils.mapMap(copyConcept.getOutProperties(), UnaryOperator.identity());
119 public NodeTemplateState toAuthorative() {
120 var nodeTemplateState = new NodeTemplateState();
121 nodeTemplateState.setNodeTemplateStateId(UUID.fromString(this.nodeTemplateStateId));
122 if (this.participantId != null) {
123 nodeTemplateState.setParticipantId(UUID.fromString(this.participantId));
125 nodeTemplateState.setNodeTemplateId(new ToscaConceptIdentifier(this.nodeTemplateId));
126 nodeTemplateState.setRestarting(this.restarting);
127 nodeTemplateState.setState(this.state);
128 nodeTemplateState.setMessage(this.message);
129 nodeTemplateState.setOutProperties(PfUtils.mapMap(outProperties, UnaryOperator.identity()));
130 return nodeTemplateState;