From 2dc2555dffd761b3795c7cfb018240bd47d79ef3 Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Mon, 6 Nov 2023 14:25:03 +0530 Subject: [PATCH] #640 - fixed checklist update query. use id map instead of title map for migration --- .../java/org/avni/server/dao/ChecklistItemRepository.java | 2 +- .../java/org/avni/server/dao/ChecklistRepository.java | 2 +- .../org/avni/server/web/SubjectMigrationController.java | 8 ++++---- .../avni/server/web/request/SubjectMigrationRequest.java | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/avni-server-api/src/main/java/org/avni/server/dao/ChecklistItemRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/ChecklistItemRepository.java index b710f251b..7554ab018 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/ChecklistItemRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/ChecklistItemRepository.java @@ -51,7 +51,7 @@ default boolean isEntityChanged(SyncParameters syncParameters){ @Modifying(clearAutomatically = true) @Query(value = "update checklist_item ci set last_modified_date_time = :lastModifiedDateTime, last_modified_by_id = :lastModifiedById" + - " from program_enrolment pe, checklist c where c.id = ci.checklist_id and pe.id = c.program_enrolment_id and pe.id = :individualId", nativeQuery = true) + " from program_enrolment pe, checklist c where c.id = ci.checklist_id and pe.id = c.program_enrolment_id and pe.individual_id = :individualId", nativeQuery = true) void setChangedForSync(Long individualId, Date lastModifiedDateTime, Long lastModifiedById); default void setChangedForSync(Individual individual) { this.setChangedForSync(individual.getId(), new Date(), UserContextHolder.getUserId()); diff --git a/avni-server-api/src/main/java/org/avni/server/dao/ChecklistRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/ChecklistRepository.java index 178810bd0..52ce8be44 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/ChecklistRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/ChecklistRepository.java @@ -54,7 +54,7 @@ default boolean isEntityChanged(SyncParameters syncParameters){ @Modifying(clearAutomatically = true) @Query(value = "update checklist c set last_modified_date_time = :lastModifiedDateTime, last_modified_by_id = :lastModifiedById" + - " from program_enrolment pe where pe.id = c.program_enrolment_id and pe.id = :individualId", nativeQuery = true) + " from program_enrolment pe where pe.id = c.program_enrolment_id and pe.individual_id = :individualId", nativeQuery = true) void setChangedForSync(Long individualId, Date lastModifiedDateTime, Long lastModifiedById); default void setChangedForSync(Individual individual) { this.setChangedForSync(individual.getId(), new Date(), UserContextHolder.getUserId()); diff --git a/avni-server-api/src/main/java/org/avni/server/web/SubjectMigrationController.java b/avni-server-api/src/main/java/org/avni/server/web/SubjectMigrationController.java index 2c7f4a623..7727ec31b 100644 --- a/avni-server-api/src/main/java/org/avni/server/web/SubjectMigrationController.java +++ b/avni-server-api/src/main/java/org/avni/server/web/SubjectMigrationController.java @@ -100,11 +100,11 @@ public Resource process(Resource resource) { @RequestMapping(value = "/subjectMigration/bulk", method = RequestMethod.POST) @PreAuthorize(value = "hasAnyAuthority('user')") public void migrate(@RequestBody SubjectMigrationRequest subjectMigrationRequest) { - Map destinationAddresses = subjectMigrationRequest.getDestinationAddresses(); + Map destinationAddresses = subjectMigrationRequest.getDestinationAddresses(); - for (Map.Entry destinationAddressEntry : destinationAddresses.entrySet()) { - Long source = destinationAddressEntry.getKey(); - Long dest = destinationAddressEntry.getValue(); + for (Map.Entry destinationAddressEntry : destinationAddresses.entrySet()) { + Long source = Long.parseLong(destinationAddressEntry.getKey()); + Long dest = Long.parseLong(destinationAddressEntry.getValue()); AddressLevel sourceAddressLevel = locationRepository.findOne(source); AddressLevel destAddressLevel = locationRepository.findOne(dest); diff --git a/avni-server-api/src/main/java/org/avni/server/web/request/SubjectMigrationRequest.java b/avni-server-api/src/main/java/org/avni/server/web/request/SubjectMigrationRequest.java index 85f50b95c..72932ae4a 100644 --- a/avni-server-api/src/main/java/org/avni/server/web/request/SubjectMigrationRequest.java +++ b/avni-server-api/src/main/java/org/avni/server/web/request/SubjectMigrationRequest.java @@ -4,7 +4,7 @@ import java.util.Map; public class SubjectMigrationRequest { - private Map destinationAddresses; + private Map destinationAddresses; private List subjectTypeIds; public List getSubjectTypeIds() { @@ -15,11 +15,11 @@ public void setSubjectTypeIds(List subjectTypeIds) { this.subjectTypeIds = subjectTypeIds; } - public Map getDestinationAddresses() { + public Map getDestinationAddresses() { return destinationAddresses; } - public void setDestinationAddresses(Map destinationAddresses) { + public void setDestinationAddresses(Map destinationAddresses) { this.destinationAddresses = destinationAddresses; } }