0218422342975e22469634ffa234de97ee9d0b8c
[policy/clamp.git] /
1 /*-
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
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 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;
32 import lombok.Data;
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;
40
41 @Entity
42 @Table(name = "ParticipantReplica")
43 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
44 @Data
45 @EqualsAndHashCode(callSuper = false)
46 public class JpaParticipantReplica extends Validated implements PfAuthorative<ParticipantReplica> {
47
48     @Id
49     @NotNull
50     private String replicaId;
51
52     @NotNull
53     @Column
54     private String participantId;
55
56     @Column
57     @NotNull
58     private ParticipantState participantState;
59
60     @Column
61     @NotNull
62     private Timestamp lastMsg;
63
64     public JpaParticipantReplica() {
65         this(UUID.randomUUID().toString(), UUID.randomUUID().toString());
66     }
67
68     public JpaParticipantReplica(@NonNull String replicaId, @NonNull String participantId) {
69         this.replicaId = replicaId;
70         this.participantId = participantId;
71     }
72
73     @Override
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;
80     }
81
82     @Override
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());
87     }
88 }