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;
 
  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;
 
  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;
 
  40 @Table(name = "NodeTemplateState")
 
  41 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
 
  43 @EqualsAndHashCode(callSuper = false)
 
  44 public class JpaNodeTemplateState extends Validated implements PfAuthorative<NodeTemplateState> {
 
  48     private String nodeTemplateStateId;
 
  52     private String compositionId;
 
  55     private String participantId;
 
  59     private ToscaConceptIdentifier nodeTemplateId;
 
  63     private AcTypeState state;
 
  66      * The Default Constructor.
 
  68     public JpaNodeTemplateState() {
 
  69         this(UUID.randomUUID().toString(), UUID.randomUUID().toString());
 
  75      * @param nodeTemplateStateId the nodeTemplateStateId
 
  76      * @param compositionId the compositionId
 
  78     public JpaNodeTemplateState(@NotNull String nodeTemplateStateId, @NotNull String compositionId) {
 
  79         this.nodeTemplateStateId = nodeTemplateStateId;
 
  80         this.compositionId = compositionId;
 
  84     public void fromAuthorative(NodeTemplateState copyConcept) {
 
  85         this.nodeTemplateStateId = copyConcept.getNodeTemplateStateId().toString();
 
  86         if (copyConcept.getParticipantId() != null) {
 
  87             this.participantId = copyConcept.getParticipantId().toString();
 
  89         this.nodeTemplateId = copyConcept.getNodeTemplateId();
 
  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));
 
  99         nodeTemplateState.setNodeTemplateId(this.nodeTemplateId);
 
 100         nodeTemplateState.setState(this.state);
 
 101         return nodeTemplateState;