aboutsummaryrefslogtreecommitdiffstats
path: root/models/src/main
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2024-05-28 14:28:52 +0100
committerFrancescoFioraEst <francesco.fiora@est.tech>2024-05-29 10:44:16 +0100
commitf2ed4877b7cfba7bcf224cbe9d7e739ec637a055 (patch)
tree3e1fbcc0321e73d99404837a1b911a3054d2e903 /models/src/main
parent6d8ebc3dfe0ee496e009eec4db39babcde51a289 (diff)
Remove Map in ACM-R for timeout Participant
Issue-ID: POLICY-5024 Change-Id: Ibb8a93be55380b110c84ec4580690f43e624d125 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'models/src/main')
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java6
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java17
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/utils/TimestampHelper.java50
3 files changed, 71 insertions, 2 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java
index c045c928b..5bdf4d312 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,6 +44,9 @@ public class Participant {
private ParticipantState participantState = ParticipantState.ON_LINE;
@NonNull
+ private String lastMsg;
+
+ @NonNull
private Map<UUID, ParticipantSupportedElementType> participantSupportedElementTypes = new HashMap<>();
/**
@@ -54,6 +57,7 @@ public class Participant {
public Participant(Participant otherParticipant) {
this.participantState = otherParticipant.participantState;
this.participantId = otherParticipant.participantId;
+ this.lastMsg = otherParticipant.lastMsg;
this.participantSupportedElementTypes = PfUtils.mapMap(otherParticipant.getParticipantSupportedElementTypes(),
ParticipantSupportedElementType::new);
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java
index e5eade3d7..cfde55767 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@ import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.io.Serializable;
+import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
@@ -42,6 +43,7 @@ import lombok.NonNull;
import org.apache.commons.lang3.ObjectUtils;
import org.onap.policy.clamp.models.acm.concepts.Participant;
import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
+import org.onap.policy.clamp.models.acm.utils.TimestampHelper;
import org.onap.policy.common.parameters.annotations.NotNull;
import org.onap.policy.common.parameters.annotations.Valid;
import org.onap.policy.models.base.PfAuthorative;
@@ -72,6 +74,10 @@ public class JpaParticipant extends Validated
@Column
private String description;
+ @Column
+ @NotNull
+ private Timestamp lastMsg;
+
@NotNull
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "participantId", referencedColumnName = "participantId",
@@ -96,6 +102,7 @@ public class JpaParticipant extends Validated
this.participantId = participantId;
this.participantState = participantState;
this.supportedElements = supportedElements;
+ this.lastMsg = TimestampHelper.nowTimestamp();
}
/**
@@ -108,6 +115,7 @@ public class JpaParticipant extends Validated
this.description = copyConcept.description;
this.participantId = copyConcept.participantId;
this.supportedElements = copyConcept.supportedElements;
+ this.lastMsg = copyConcept.lastMsg;
}
/**
@@ -125,6 +133,7 @@ public class JpaParticipant extends Validated
participant.setParticipantState(participantState);
participant.setParticipantId(UUID.fromString(participantId));
+ participant.setLastMsg(this.lastMsg.toString());
participant.setParticipantSupportedElementTypes(new LinkedHashMap<>(this.supportedElements.size()));
for (var element : this.supportedElements) {
participant.getParticipantSupportedElementTypes()
@@ -138,6 +147,7 @@ public class JpaParticipant extends Validated
public void fromAuthorative(@NonNull final Participant participant) {
this.setParticipantState(participant.getParticipantState());
this.participantId = participant.getParticipantId().toString();
+ this.lastMsg = TimestampHelper.toTimestamp(participant.getLastMsg());
this.supportedElements = new ArrayList<>(participant.getParticipantSupportedElementTypes().size());
for (var elementEntry : participant.getParticipantSupportedElementTypes().entrySet()) {
@@ -162,6 +172,11 @@ public class JpaParticipant extends Validated
return result;
}
+ result = lastMsg.compareTo(other.lastMsg);
+ if (result != 0) {
+ return result;
+ }
+
result = ObjectUtils.compare(participantState, other.participantState);
if (result != 0) {
return result;
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/TimestampHelper.java b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/TimestampHelper.java
new file mode 100644
index 000000000..d430f7687
--- /dev/null
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/TimestampHelper.java
@@ -0,0 +1,50 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2024 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.models.acm.utils;
+
+import java.sql.Timestamp;
+import java.time.Instant;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class TimestampHelper {
+
+ public static String now() {
+ return Timestamp.from(Instant.now()).toString();
+ }
+
+ public static Timestamp nowTimestamp() {
+ return Timestamp.from(Instant.now());
+ }
+
+ public static Timestamp toTimestamp(String time) {
+ return Timestamp.valueOf(time);
+ }
+
+ public static long nowEpochMilli() {
+ return Instant.now().toEpochMilli();
+ }
+
+ public static long toEpochMilli(String time) {
+ return Timestamp.valueOf(time).toInstant().toEpochMilli();
+ }
+}