Skip to content

Commit

Permalink
HCMPRE-203: added changes for Elastic search and update for location …
Browse files Browse the repository at this point in the history
…capture, removed UserLocationAction model
  • Loading branch information
kanishq-egov committed Aug 22, 2024
1 parent 31b5ab0 commit 51a6ff8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
@Data
@NoArgsConstructor
@AllArgsConstructor
@Setter
@Getter
@Import({TracerConfiguration.class})
@ComponentScan(basePackages = {"org.egov"})
public class ServiceConfiguration {
Expand Down Expand Up @@ -56,6 +54,9 @@ public class ServiceConfiguration {
@Value("${egov.individual.index}")
private String individualIndex;

@Value("${egov.project.user.action.location.capture.index}")
private String userActionLocationCaptureIndex;

@Value("${egov.search.index.parameters}")
private String searchParameter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,75 +115,4 @@ private JSONArray constructJsonArray(String json, String jsonPath) {
}
}


//TODO
//FIXME

public void upsertUserActionLocationCaptureEntry(String index, String locationCaptureId, UserActionLocationCaptureIndexRecord userActionLocationCaptureIndexRecord) {
try {

Map<String, Object> script = new HashMap<>();
script.put("source", """
if (ctx._source.householdMembers == null) {
ctx._source.householdMembers = [];
}
if (ctx._source.individuals == null) {
ctx._source.individuals = [];
}
for (newMember in params.newHousehold.householdMembers) {
boolean memberExists = false;
for (int i = 0; i < ctx._source.householdMembers.size(); i++) {
if (ctx._source.householdMembers[i].id == newMember.id) {
ctx._source.householdMembers[i] = newMember;
memberExists = true;
break;
}
}
if (!memberExists) {
ctx._source.householdMembers.add(newMember);
}
}
for (newIndividual in params.newHousehold.individuals) {
boolean individualExists = false;
for (int i = 0; i < ctx._source.individuals.size(); i++) {
if (ctx._source.individuals[i].id == newIndividual.id) {
ctx._source.individuals[i] = newIndividual;
individualExists = true;
break;
}
}
if (!individualExists) {
ctx._source.individuals.add(newIndividual);
}
}
""");
script.put("params", Map.of("newHousehold", household));

Map<String, Object> upsert = new HashMap<>(objectMapper.convertValue(household, Map.class));

Map<String, Object> payload = new HashMap<>();
payload.put("script", script);
payload.put("upsert", upsert);

HttpEntity<String> request = new HttpEntity<>(objectMapper.writeValueAsString(payload),
getHeaders());

ResponseEntity<String> response = restTemplate.exchange(
getUpdateWithQueryUri(index, householdId), HttpMethod.POST, request,
String.class);

if (response.getStatusCode().is2xxSuccessful()) {
JsonNode jsonResponse = objectMapper.readTree(response.getBody());
log.debug("Upsert operation result ::: {}", jsonResponse);
} else {
log.error("Failed to upsert document ::: {}", response.getStatusCode());
}

} catch (Exception e) {
log.error("Failed to upsert document ::: {}", e.getMessage(), e);
throw new CustomException("AGGREGATE_FAILED", e.getMessage());
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,13 @@ private void updateAggregateLocationCaptureEntry(
}

// Update or create the record in Elasticsearch
elasticSearchRepository.save(updatedRecord, esHit.getSeqNo(), esHit.getPrimaryTerm(), config.getAggregatedHouseholdIndex(), USER_LOCATION_CAPTURE_ID);
elasticSearchRepository.createOrUpdateDocument(
updatedRecord, config.getUserActionLocationCaptureIndex(), USER_LOCATION_CAPTURE_ID, esHit.getSeqNo(), esHit.getPrimaryTerm()
);
}



/**
* Convert a timestamp (in milliseconds) to a formatted date string (yyyyMMdd).
*/
Expand Down

0 comments on commit 51a6ff8

Please sign in to comment.