diff --git a/utilities/bulk-upload/src/main/java/org/egov/service/BulkUploadService.java b/utilities/bulk-upload/src/main/java/org/egov/service/BulkUploadService.java index 10711e7df9..1b5731499b 100644 --- a/utilities/bulk-upload/src/main/java/org/egov/service/BulkUploadService.java +++ b/utilities/bulk-upload/src/main/java/org/egov/service/BulkUploadService.java @@ -407,7 +407,45 @@ private void updateValidToDate(List sorIds, MdmsCriteriaReqV2 mdmsCriter } } + // Code for bulk update of SOR Definitions + private List> updateSorDescriptions(MdmsCriteriaReqV2 mdmsSearchCriteriaReqV2, List> fileData) { + // Create a HashMap to store sorId-description pairs + Map sorIdDescriptionMap = new HashMap<>(); + for (Map details : fileData) { + sorIdDescriptionMap.put(details.get("sorId"), (String) details.get("description")); + } + + List mdmsDataList = getMdmsV2Data(mdmsSearchCriteriaReqV2); + + for (Mdms mdms : mdmsDataList) { + ObjectNode data = (ObjectNode) mdms.getData(); + Object uniqueIdentifier = mdms.getUniqueIdentifier(); + + // Check if the sorId exists in the HashMap + if (sorIdDescriptionMap.containsKey(uniqueIdentifier)) { + String description = sorIdDescriptionMap.get(uniqueIdentifier); + data.put("description", description); + MdmsRequest mdmsRequest = MdmsRequest.builder().requestInfo(mdmsSearchCriteriaReqV2.getRequestInfo()).mdms(mdms).build(); + MdmsResponseV2 mdmsResponseV2 = bulkUploadUtil.update(mdmsRequest); + } + } + + return fileData; + } + + + public List> sorBulkUpdate(MultipartFile file, String mdmsSearchCriteria) throws IOException{ + + // Reading new SOR Definitions File + List> fileData = readFile(file); + + // Parsing mdmsSearchCriteria to MdmsSearchCrtiteria of MDMS-V2 + MdmsCriteriaReqV2 mdmsSearchCriteriaReqV2 = bulkUploadUtil.getMdmsV2Request(mdmsSearchCriteria); + + + return updateSorDescriptions(mdmsSearchCriteriaReqV2, fileData); + } diff --git a/utilities/bulk-upload/src/main/java/org/egov/web/controllers/BulkUploadController.java b/utilities/bulk-upload/src/main/java/org/egov/web/controllers/BulkUploadController.java index 3a0faefadc..e4e46aa7a7 100644 --- a/utilities/bulk-upload/src/main/java/org/egov/web/controllers/BulkUploadController.java +++ b/utilities/bulk-upload/src/main/java/org/egov/web/controllers/BulkUploadController.java @@ -29,6 +29,11 @@ public List> bulkUpdate(@RequestParam("file") MultipartFile return bulkUploadService.bulkUpdate(file, mdmsSearchCriteria, newValidToDate); } + @PostMapping("/_sorBulkUpdate") + public List> sorBulkUpdate(@RequestParam("file") MultipartFile file, @Valid @RequestParam("mdmsSearchCriteria") String mdmsSearchCriteria) throws Exception{ + return bulkUploadService.sorBulkUpdate(file, mdmsSearchCriteria); + } + }