2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2024-2026 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.Column;
24 import jakarta.persistence.Entity;
25 import jakarta.persistence.Id;
26 import jakarta.persistence.Inheritance;
27 import jakarta.persistence.InheritanceType;
28 import jakarta.persistence.Table;
29 import jakarta.validation.constraints.NotNull;
30 import java.sql.Timestamp;
31 import java.util.UUID;
33 import lombok.EqualsAndHashCode;
34 import lombok.NonNull;
35 import org.onap.policy.clamp.models.acm.concepts.ParticipantReplica;
36 import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
37 import org.onap.policy.clamp.models.acm.utils.TimestampHelper;
38 import org.onap.policy.models.base.PfAuthorative;
39 import org.onap.policy.models.base.Validated;
42 @Table(name = "ParticipantReplica")
43 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
45 @EqualsAndHashCode(callSuper = false)
46 public class JpaParticipantReplica extends Validated implements PfAuthorative<ParticipantReplica> {
50 private String replicaId;
54 private String participantId;
58 private ParticipantState participantState;
62 private Timestamp lastMsg;
64 public JpaParticipantReplica() {
65 this(UUID.randomUUID().toString(), UUID.randomUUID().toString());
68 public JpaParticipantReplica(@NonNull String replicaId, @NonNull String participantId) {
69 this.replicaId = replicaId;
70 this.participantId = participantId;
74 public ParticipantReplica toAuthorative() {
75 var participantReplica = new ParticipantReplica();
76 participantReplica.setReplicaId(UUID.fromString(replicaId));
77 participantReplica.setParticipantState(participantState);
78 participantReplica.setLastMsg(lastMsg.toString());
79 return participantReplica;
83 public void fromAuthorative(@NonNull ParticipantReplica participantReplica) {
84 this.replicaId = participantReplica.getReplicaId().toString();
85 this.participantState = participantReplica.getParticipantState();
86 this.lastMsg = TimestampHelper.toTimestamp(participantReplica.getLastMsg());