-
Notifications
You must be signed in to change notification settings - Fork 49
Grievances API changes #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4f0e01b
a6958fd
e3f1752
e10768e
b7c850c
0ca2f53
70cdc17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,38 +1,39 @@ | ||
| package com.iemr.common.config.quartz; | ||
|
|
||
| import org.quartz.Job; | ||
| import org.quartz.JobExecutionContext; | ||
| import org.quartz.JobExecutionException; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.scheduling.annotation.Scheduled; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
|
|
||
| import com.iemr.common.service.grievance.GrievanceDataSync; | ||
|
|
||
| @Service | ||
| @Transactional | ||
| public class ScheduleForGrievanceDataSync implements Job { | ||
| @Component | ||
| public class ScheduleForGrievanceDataSync { | ||
|
|
||
| @Value("${start-grievancedatasync-scheduler}") | ||
| private boolean grievanceFlag; | ||
|
|
||
| private final Logger logger = LoggerFactory.getLogger(this.getClass().getName()); | ||
|
|
||
|
|
||
|
|
||
| private final GrievanceDataSync grievanceDataSync; | ||
|
|
||
| @Autowired | ||
| public ScheduleForGrievanceDataSync(GrievanceDataSync grievanceDataSync) { | ||
| this.grievanceDataSync = grievanceDataSync; | ||
| } | ||
|
|
||
| @Override | ||
| public void execute(JobExecutionContext arg0) throws JobExecutionException | ||
| { | ||
| logger.info("Started job for grievance data sync {}", arg0.getClass().getName()); | ||
| grievanceDataSync.dataSyncToGrievance(); | ||
| logger.info("Completed job for grievance data sync {}" , arg0.getClass().getName()); | ||
| } | ||
|
|
||
|
|
||
| @Scheduled(cron = "${cron-scheduler-grievancedatasync}") | ||
| public void execute() { | ||
| if (grievanceFlag) { | ||
| logger.info("Started job for grievance data sync "); | ||
| grievanceDataSync.dataSyncToGrievance(); | ||
| logger.info("Completed job for grievance data sync "); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,83 +1,121 @@ | ||
| package com.iemr.common.controller.grievance; | ||
|
|
||
|
|
||
| import com.iemr.common.service.grievance.GrievanceDataSync; | ||
| import com.iemr.common.service.grievance.GrievanceHandlingService; | ||
| import com.iemr.common.utils.exception.IEMRException; | ||
| import com.iemr.common.utils.response.OutputResponse; | ||
| import io.lettuce.core.dynamic.annotation.Param; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import javax.ws.rs.core.MediaType; | ||
|
|
||
| import org.json.JSONException; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.web.bind.annotation.CrossOrigin; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestMethod; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import com.iemr.common.data.grievance.UnallocationRequest; | ||
| import com.iemr.common.service.grievance.GrievanceDataSync; | ||
| import com.iemr.common.service.grievance.GrievanceHandlingService; | ||
| import com.iemr.common.utils.exception.IEMRException; | ||
| import com.iemr.common.utils.response.OutputResponse; | ||
|
|
||
| import io.lettuce.core.dynamic.annotation.Param; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
|
|
||
| @RestController | ||
| public class GrievanceController { | ||
| final Logger logger = LoggerFactory.getLogger(this.getClass().getName()); | ||
|
|
||
|
|
||
| private GrievanceDataSync grievanceDataSync; | ||
|
|
||
| private final GrievanceHandlingService grievanceHandlingService; | ||
|
|
||
| @Autowired | ||
| public GrievanceController(GrievanceHandlingService grievanceHandlingService, GrievanceDataSync grievanceDataSync) { | ||
| this.grievanceDataSync = grievanceDataSync; | ||
| this.grievanceHandlingService = grievanceHandlingService; | ||
| } | ||
|
|
||
|
|
||
| @CrossOrigin() | ||
| @Operation(summary = "/unallocatedGrievanceCount") | ||
| @PostMapping(value = "/unallocatedGrievanceCount", consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, headers = "Authorization") | ||
| public String fetchUnallocatedGrievanceCount() { | ||
| OutputResponse responseData = new OutputResponse(); | ||
| try { | ||
| responseData.setResponse(grievanceDataSync.fetchUnallocatedGrievanceCount()); | ||
| } | ||
| catch (IEMRException e) { | ||
| logger.error("Business logic error in UnallocatedGrievanceCount" + e.getMessage(), e); | ||
| responseData.setError(e); | ||
| } | ||
| catch (JSONException e) { | ||
| logger.error("JSON processing error in UnallocatedGrievanceCount" + e.getMessage(), e); | ||
| responseData.setError(e); | ||
| } | ||
| catch (Exception e) { | ||
| logger.error("UnallocatedGrievanceCount failed with error" + e.getMessage(), e); | ||
| responseData.setError(e); | ||
| } | ||
| return responseData.toString(); | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
| @Operation(summary = "Allocate grievances to users") | ||
| @PostMapping(value = "/allocateGrievances", consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, headers = "Authorization") | ||
| public String allocateGrievances(@Param(value = "{\"startDate\":\"ISO-8601 format start date (e.g., 2022-12-01T07:49:00.000Z)\", " | ||
| + "\"endDate\":\"ISO-8601 format end date (e.g., 2025-01-16T07:49:30.561)\", " | ||
| + "\"userID\":\"Array list of User IDs (agents to be allocated grievances)\", " | ||
| + "\"allocateNo\":\"Integer - number of grievances to be allocated to each user\"," | ||
| + "\"language\":\"String - language to filter grievances by\"}") | ||
|
|
||
| @RequestBody String request) { | ||
| OutputResponse response = new OutputResponse(); | ||
| try { | ||
| // Call the service to allocate grievances based on the incoming JSON request | ||
| response.setResponse(grievanceHandlingService.allocateGrievances(request)); | ||
| } catch (Exception e) { | ||
| logger.error("Grievance allocation failed with error: " + e.getMessage(), e); | ||
| response.setError(e); | ||
| } | ||
| return response.toString(); | ||
| } | ||
|
|
||
| private GrievanceDataSync grievanceDataSync; | ||
|
|
||
| private final GrievanceHandlingService grievanceHandlingService; | ||
|
|
||
| @Autowired | ||
| public GrievanceController(GrievanceHandlingService grievanceHandlingService, GrievanceDataSync grievanceDataSync) { | ||
| this.grievanceDataSync = grievanceDataSync; | ||
| this.grievanceHandlingService = grievanceHandlingService; | ||
| } | ||
|
|
||
| @Operation(summary = "/unallocatedGrievanceCount") | ||
| @PostMapping(value = "/unallocatedGrievanceCount", consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, headers = "Authorization") | ||
| public String fetchUnallocatedGrievanceCount(@RequestBody UnallocationRequest request) { | ||
| OutputResponse responseData = new OutputResponse(); | ||
| try { | ||
| responseData.setResponse(grievanceDataSync.fetchUnallocatedGrievanceCount(request.getPreferredLanguageName())); | ||
| } catch (IEMRException e) { | ||
| logger.error("Business logic error in UnallocatedGrievanceCount" + e.getMessage(), e); | ||
| responseData.setError(e); | ||
| } catch (JSONException e) { | ||
| logger.error("JSON processing error in UnallocatedGrievanceCount" + e.getMessage(), e); | ||
| responseData.setError(e); | ||
| } catch (Exception e) { | ||
| logger.error("UnallocatedGrievanceCount failed with error" + e.getMessage(), e); | ||
| responseData.setError(e); | ||
| } | ||
| return responseData.toString(); | ||
|
|
||
| } | ||
|
|
||
| @Operation(summary = "Allocate grievances to users") | ||
| @PostMapping(value = "/allocateGrievances", consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, headers = "Authorization") | ||
| public String allocateGrievances( | ||
| @Param(value = "{\"startDate\":\"ISO-8601 format start date (e.g., 2022-12-01T07:49:00.000Z)\", " | ||
| + "\"endDate\":\"ISO-8601 format end date (e.g., 2025-01-16T07:49:30.561)\", " | ||
| + "\"userID\":\"Array list of User IDs (agents to be allocated grievances)\", " | ||
| + "\"allocateNo\":\"Integer - number of grievances to be allocated to each user\"," | ||
| + "\"language\":\"String - language to filter grievances by\"}") | ||
|
|
||
| @RequestBody String request) { | ||
| OutputResponse response = new OutputResponse(); | ||
| try { | ||
| // Call the service to allocate grievances based on the incoming JSON request | ||
| response.setResponse(grievanceHandlingService.allocateGrievances(request)); | ||
| } catch (Exception e) { | ||
| logger.error("Grievance allocation failed with error: " + e.getMessage(), e); | ||
| response.setError(e); | ||
| } | ||
| return response.toString(); | ||
| } | ||
|
|
||
| @Operation(summary = "Allocated Grievance Records Count") | ||
| @PostMapping(value = "/allocatedGrievanceRecordsCount", consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, headers = "Authorization") | ||
| public String allocatedGrievanceRecordsCount(@Param(value = "{\"providerServiceMapID\":\"Service ID integer\", " | ||
| + "\"assignedUserID\":\"Optional - Integer user ID to whom grievances are assigned\"}") @RequestBody String request) { | ||
| OutputResponse response = new OutputResponse(); | ||
| try { | ||
| response.setResponse(grievanceHandlingService.allocatedGrievanceRecordsCount(request)); | ||
| } catch (Exception e) { | ||
| logger.error("allocatedGrievanceRecordsCount failed with error " + e.getMessage(), e); | ||
| response.setError(e); | ||
| } | ||
| return response.toString(); | ||
| } | ||
|
|
||
| @Operation(summary = "Reallocate grievances to other users") | ||
| @PostMapping(value = "/reallocateGrievances", consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, headers = "Authorization") | ||
| public String reallocateGrievances(@RequestBody String request) { | ||
| OutputResponse response = new OutputResponse(); | ||
| try { | ||
| // Call the service to reallocate grievances based on the incoming JSON request | ||
| response.setResponse(grievanceHandlingService.reallocateGrievances(request)); | ||
| } catch (Exception e) { | ||
| logger.error("Grievance reallocation failed with error: " + e.getMessage(), e); | ||
| response.setError(e); | ||
| } | ||
| return response.toString(); | ||
| } | ||
|
|
||
| @Operation(summary = "Move grievances to bin (unassign from agent)") | ||
| @PostMapping(value = "/moveToBin", consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, headers = "Authorization") | ||
| public String moveToBin(@RequestBody String request) { | ||
|
|
||
| OutputResponse response = new OutputResponse(); | ||
| try { | ||
| response.setResponse(grievanceHandlingService.moveToBin(request)); | ||
| } catch (Exception e) { | ||
| logger.error("Move to bin failed with error: " + e.getMessage(), e); | ||
| response.setError(e); | ||
| } | ||
| return response.toString(); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,68 +1,23 @@ | ||||||||||
| package com.iemr.common.data.grievance; | ||||||||||
|
|
||||||||||
| import java.sql.Timestamp; | ||||||||||
| import java.util.List; | ||||||||||
|
|
||||||||||
| import java.time.LocalDateTime; | ||||||||||
| import java.util.List; | ||||||||||
| import lombok.Data; | ||||||||||
|
|
||||||||||
| public class GrievanceAllocationRequest { | ||||||||||
| @Data | ||||||||||
| public class GrievanceAllocationRequest { | ||||||||||
|
|
||||||||||
| private LocalDateTime startDate; // Start date for filtering grievances | ||||||||||
| private LocalDateTime endDate; // End date for filtering grievances | ||||||||||
| private List<Integer> userID; // List of user IDs (agents) to whom grievances will be allocated | ||||||||||
| private Integer allocateNo; // Number of grievances to be allocated to each user | ||||||||||
| private String language; | ||||||||||
| // Getters and Setters | ||||||||||
| private Timestamp startDate; // Start date for filtering grievances | ||||||||||
| private Timestamp endDate; // End date for filtering grievances | ||||||||||
| private List<Integer> userID; // List of user IDs (agents) to whom grievances will be allocated | ||||||||||
| private Integer allocateNo; // Number of grievances to be allocated to each user | ||||||||||
| private String preferredLanguage; | ||||||||||
|
|
||||||||||
| public LocalDateTime getStartDate() { | ||||||||||
| return startDate; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public void setStartDate(LocalDateTime startDate) { | ||||||||||
| this.startDate = startDate; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public LocalDateTime getEndDate() { | ||||||||||
| return endDate; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public void setEndDate(LocalDateTime endDate) { | ||||||||||
| this.endDate = endDate; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public List<Integer> getUserID() { | ||||||||||
| return userID; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public void setUserID(List<Integer> userID) { | ||||||||||
| this.userID = userID; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public Integer getAllocateNo() { | ||||||||||
| return allocateNo; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public void setAllocateNo(Integer allocateNo) { | ||||||||||
| this.allocateNo = allocateNo; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public String getLanguage() { | ||||||||||
| return language; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public void setLanguage(String language) { | ||||||||||
| this.language = language; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| @Override | ||||||||||
| public String toString() { | ||||||||||
| return "GrievanceAllocationRequest{" + | ||||||||||
| "startDate=" + startDate + | ||||||||||
| ", endDate=" + endDate + | ||||||||||
| ", userID=" + userID + | ||||||||||
| ", allocateNo=" + allocateNo + | ||||||||||
| ", language=" + language + | ||||||||||
| '}'; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| @Override | ||||||||||
| public String toString() { | ||||||||||
| return "GrievanceAllocationRequest{" + "startDate=" + startDate + ", endDate=" + endDate + ", userID=" + userID | ||||||||||
| + ", allocateNo=" + allocateNo + ", language=" + preferredLanguage + '}'; | ||||||||||
|
Comment on lines
+19
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix inconsistent field name in toString method. The toString method still references the old field name 'language' instead of 'preferredLanguage'. return "GrievanceAllocationRequest{" + "startDate=" + startDate + ", endDate=" + endDate + ", userID=" + userID
- + ", allocateNo=" + allocateNo + ", language=" + preferredLanguage + '}';
+ + ", allocateNo=" + allocateNo + ", preferredLanguage=" + preferredLanguage + '}';π Committable suggestion
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @indraniBan Thanks for fixing the inconsistency! π If you found this review helpful, would you consider giving us a shout-out on X? |
||||||||||
| } | ||||||||||
|
|
||||||||||
| } | ||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid logging user-controlled data.
The error logging statements contain user-controlled data which could lead to log injection attacks.
Apply this diff to sanitize the logged data:
Also applies to: 115-115