O1 PM Bulk support in DataCollector RAPP - removing trafficModel

Issue-ID: INT-1947

Signed-off-by: Stanislav Marszalek <s.marszalek2@partner.samsung.com>
Change-Id: I02d3684c98d563d7f386de2fdf032e984ac74b3f
diff --git a/datacollector/src/main/java/org/onap/rapp/datacollector/entity/ves/MeasurementFields.java b/datacollector/src/main/java/org/onap/rapp/datacollector/entity/ves/MeasurementFields.java
index c11c490..7ed10b1 100644
--- a/datacollector/src/main/java/org/onap/rapp/datacollector/entity/ves/MeasurementFields.java
+++ b/datacollector/src/main/java/org/onap/rapp/datacollector/entity/ves/MeasurementFields.java
@@ -41,7 +41,7 @@
     private MeasurementFields(Long eventId, long measurementInterval, List<AdditionalMeasurements> additionalMeasurements) {
         this.eventId = eventId;
         this.measurementInterval = measurementInterval;
-        this.additionalMeasurements = Collections.unmodifiableList(additionalMeasurements);
+        this.additionalMeasurements = additionalMeasurements;
     }
 
     public static MeasurementFields  of(Long eventId) {
diff --git a/datacollector/src/main/java/org/onap/rapp/datacollector/service/PMService.java b/datacollector/src/main/java/org/onap/rapp/datacollector/service/PMService.java
index 1e2931c..bd0b439 100644
--- a/datacollector/src/main/java/org/onap/rapp/datacollector/service/PMService.java
+++ b/datacollector/src/main/java/org/onap/rapp/datacollector/service/PMService.java
@@ -13,6 +13,7 @@
 
 package org.onap.rapp.datacollector.service;
 
+import java.math.BigInteger;
 import java.time.OffsetDateTime;
 import java.util.List;
 import java.util.Map;
@@ -67,8 +68,8 @@
     }
 
     private long getTimeIntervalEndTime(int slot, int count, long startDate) {
-        int timeIntervalMicrosec = slot * count * MICRO_SECONDS_OF_SECOND;
-        return startDate + timeIntervalMicrosec;
+        BigInteger timeIntervalMicrosec = BigInteger.valueOf(slot).multiply(BigInteger.valueOf(count)).multiply(BigInteger.valueOf(MICRO_SECONDS_OF_SECOND));
+        return startDate + timeIntervalMicrosec.longValue();
     }
 
     private Map<String, List<Event>> groupByCell(List<EventAPI> events) {
diff --git a/datacollector/src/main/java/org/onap/rapp/datacollector/service/VesRetrievalService.java b/datacollector/src/main/java/org/onap/rapp/datacollector/service/VesRetrievalService.java
index a3825f6..1cdacd8 100644
--- a/datacollector/src/main/java/org/onap/rapp/datacollector/service/VesRetrievalService.java
+++ b/datacollector/src/main/java/org/onap/rapp/datacollector/service/VesRetrievalService.java
@@ -95,8 +95,8 @@
     }
 
     private void saveAllEvents(List<Event> events) {
-        persister.persistAll(events);
         saveUesOfVes(events);
+        persister.persistAll(removeTrafficModelFromEvents(events));
     }
 
     private void saveUesOfVes(List<Event> events) {
@@ -113,6 +113,13 @@
                 .collect(Collectors.toSet())).orElse(Collections.emptySet());
     }
 
+    private List<Event> removeTrafficModelFromEvents(List<Event> events) {
+        return events.stream().map(event -> {
+            event.getMeasurementFields().getAdditionalMeasurements()
+                    .removeIf(additionalMeasurements -> UE_FIELD_NAME.equalsIgnoreCase(additionalMeasurements.getName()));
+            return event;
+        }).collect(Collectors.toList());
+    }
 }
 
 
diff --git a/datacollector/src/test/java/org/onap/rapp/datacollector/entity/ves/MeasurementFieldsTest.java b/datacollector/src/test/java/org/onap/rapp/datacollector/entity/ves/MeasurementFieldsTest.java
index 1283bd5..9844694 100644
--- a/datacollector/src/test/java/org/onap/rapp/datacollector/entity/ves/MeasurementFieldsTest.java
+++ b/datacollector/src/test/java/org/onap/rapp/datacollector/entity/ves/MeasurementFieldsTest.java
@@ -15,8 +15,13 @@
 package org.onap.rapp.datacollector.entity.ves;
 
 import static org.junit.Assert.assertEquals;
+import static org.onap.rapp.datacollector.entity.ves.MeasurementFields.MEASUREMENT_FIELDS_VERSION;
+
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
+
 import org.junit.Test;
 
 public class MeasurementFieldsTest {
@@ -37,7 +42,7 @@
     static MeasurementFields createDummy(AdditionalMeasurements v) {
         return MeasurementFields.builder()
                 .measurementInterval(1234567L)
-                .additionalMeasurements(List.of(v))
+                .additionalMeasurements(new ArrayList<>(Arrays.asList(v)))
                 .build();
 
     }
@@ -48,7 +53,7 @@
         MeasurementFields actual = createDummy(v);
 
         assertEquals(1234567L, actual.measurementInterval);
-        assertEquals("4.0", actual.MEASUREMENT_FIELDS_VERSION);
+        assertEquals("4.0", MEASUREMENT_FIELDS_VERSION);
         assertEquals(List.of(v), actual.additionalMeasurements);
     }
 }