From 0d575910fb5705c97651ac49b7b4cd14d4777b36 Mon Sep 17 00:00:00 2001 From: kanishq-egov Date: Wed, 28 Aug 2024 17:01:02 +0530 Subject: [PATCH] HCMPRE-203: removed duplicate entry while inserting the record, also changed the id value while was incorrectly set --- ...tionLocationCaptureAggregationService.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/health-services/transformer/src/main/java/org/egov/transformer/service/UserActionLocationCaptureAggregationService.java b/health-services/transformer/src/main/java/org/egov/transformer/service/UserActionLocationCaptureAggregationService.java index dea9b6ca590..591fc140219 100644 --- a/health-services/transformer/src/main/java/org/egov/transformer/service/UserActionLocationCaptureAggregationService.java +++ b/health-services/transformer/src/main/java/org/egov/transformer/service/UserActionLocationCaptureAggregationService.java @@ -85,6 +85,9 @@ public void processUserActionLocationCapture(List userActionPayloadL }); } + private Boolean isExistingRecord(ElasticsearchHit esHit) { + return esHit.getPrimaryTerm() != 0L && esHit.getSeqNo() != 0L; + } /** * Updates an existing location capture entry or initializes a new one if it doesn't exist. * @@ -98,13 +101,11 @@ private void updateAggregateLocationCaptureEntry( List userActionList ) { // Existing record fetched from Elasticsearch - UserActionLocationCaptureIndexRecord existingRecord = esHit.getSource(); - UserActionLocationCaptureIndexRecord updatedRecord; + UserActionLocationCaptureIndexRecord esRecord = esHit.getSource(); - if (existingRecord != null) { + if (Boolean.TRUE.equals(isExistingRecord(esHit)) && esRecord != null) { // If the entry already exists, update the geoJson with new coordinates and accuracy - updatedRecord = existingRecord; - JsonNode existingGeoJson = existingRecord.getGeoJson(); + JsonNode existingGeoJson = esRecord.getGeoJson(); // Extract existing coordinates and accuracy arrays List> existingCoordinates = objectMapper.convertValue( @@ -138,21 +139,17 @@ private void updateAggregateLocationCaptureEntry( try { // Update the GeoJSON in the record - updatedRecord.setGeoJson(objectMapper.readTree(updatedJsonString)); + esRecord.setGeoJson(objectMapper.readTree(updatedJsonString)); log.info("Updated GeoJSON for user action location capture entry with ID: {}", userActionCompositeKey.getId()); } catch (Exception e) { log.error("Failed to update GeoJSON for user action location capture entry: ", e); } - } else { - // If no existing entry, initialize a new record - updatedRecord = initLocationCaptureEntry(userActionCompositeKey, userActionList); - log.info("Initialized new user action location capture entry for composite key: {}", userActionCompositeKey.getId()); } // Update or create the record in Elasticsearch elasticSearchRepository.createOrUpdateDocument( - updatedRecord, config.getUserActionLocationCaptureIndex(), USER_LOCATION_CAPTURE_ID, esHit.getSeqNo(), esHit.getPrimaryTerm() + esRecord, config.getUserActionLocationCaptureIndex(), esRecord.getId(), esHit.getSeqNo(), esHit.getPrimaryTerm() ); log.info("Updated/Created user action location capture entry in Elasticsearch for composite key: {}", userActionCompositeKey.getId()); }