Fix OutProperties message order in AMC monitoring 32/140732/2
authorFrancescoFioraEst <francesco.fiora@est.tech>
Fri, 18 Apr 2025 14:12:59 +0000 (15:12 +0100)
committerFrancescoFioraEst <francesco.fiora@est.tech>
Tue, 22 Apr 2025 08:46:46 +0000 (09:46 +0100)
Issue-ID: POLICY-5343
Change-Id: Ic523e0800b5bfff8115a40d249dd4839454ae816
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/MessageProvider.java
models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/MessageRepository.java
models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/MessageProviderTest.java

index 55da8e6..fee830f 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2025 Nordix Foundation.
+ * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -102,6 +102,7 @@ public class MessageProvider {
             for (var element : instance.getElements()) {
                 var jpa = new JpaMessage();
                 jpa.setIdentificationId(instance.getAutomationCompositionId().toString());
+                jpa.setLastMsg(Timestamp.from(message.getTimestamp()));
                 var doc = from(message);
                 doc.setInstanceId(instance.getAutomationCompositionId());
                 doc.setUseState(element.getUseState());
@@ -129,6 +130,7 @@ public class MessageProvider {
                 if (elementState != null && elementState.getParticipantId().equals(message.getParticipantId())) {
                     var jpa = new JpaMessage();
                     jpa.setIdentificationId(message.getCompositionId().toString());
+                    jpa.setLastMsg(Timestamp.from(message.getTimestamp()));
                     var doc = from(message);
                     doc.setOutProperties(element.getOutProperties());
                     doc.setAcElementDefinitionId(element.getAcElementDefinitionId());
@@ -162,7 +164,7 @@ public class MessageProvider {
 
     @Transactional(readOnly = true)
     public List<DocMessage> getAllMessages(UUID identificationId) {
-        var result = messageRepository.findByIdentificationIdOrderByLastMsgDesc(identificationId.toString());
+        var result = messageRepository.findByIdentificationIdOrderByLastMsgAsc(identificationId.toString());
         return result.stream().map(JpaMessage::toAuthorative).toList();
     }
 
index be3561e..4468caf 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2025 Nordix Foundation.
+ * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -26,5 +26,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
 
 public interface MessageRepository extends JpaRepository<JpaMessage, String> {
 
-    List<JpaMessage> findByIdentificationIdOrderByLastMsgDesc(String identificationId);
+    List<JpaMessage> findByIdentificationIdOrderByLastMsgAsc(String identificationId);
 }
index b95ba95..fe8c728 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2025 Nordix Foundation.
+ * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -148,7 +148,7 @@ class MessageProviderTest {
         var messageRepository = mock(MessageRepository.class);
         var instanceId = UUID.randomUUID();
         var jpaMessage = new JpaMessage();
-        when(messageRepository.findByIdentificationIdOrderByLastMsgDesc(instanceId.toString()))
+        when(messageRepository.findByIdentificationIdOrderByLastMsgAsc(instanceId.toString()))
                 .thenReturn(List.of(jpaMessage));
         var messageProvider = new MessageProvider(messageRepository, mock(MessageJobRepository.class));
         var result = messageProvider.getAllMessages(instanceId);