Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 1 addition & 31 deletions src/main/java/com/iemr/common/config/quartz/QuartzConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import java.io.IOException;
import java.util.Properties;



import org.quartz.Trigger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -97,8 +95,7 @@ public SchedulerFactoryBean quartzScheduler() {
Trigger[] triggers = { processMQTriggerForUnblock().getObject(), processMQTriggerForSMS().getObject(),
processMQTriggerForEmail().getObject(), processMQTriggerForRegistration().getObject(),
processMQTriggerForEverwellDataSync().getObject(), processMQTriggerForCtiDataSync().getObject(),
processMQTriggerForAvniRegistration().getObject(),
processMQTriggerForNHMDashboardData().getObject(), processMQTriggerForGrievanceDataSync().getObject() };
processMQTriggerForAvniRegistration().getObject(), processMQTriggerForNHMDashboardData().getObject() };

quartzScheduler.setTriggers(triggers);

Expand Down Expand Up @@ -227,33 +224,6 @@ public CronTriggerFactoryBean processMQTriggerForEverwellDataSync() {
return cronTriggerFactoryBean;
}

//-----------------Grievance Data Sync Scheduler----------------------------------------------

@Bean
public JobDetailFactoryBean processMQJobForGrievanceDataSync() {
JobDetailFactoryBean jobDetailFactory;
jobDetailFactory = new JobDetailFactoryBean();
jobDetailFactory.setJobClass(ScheduleForGrievanceDataSync.class);
jobDetailFactory.setGroup(quartzJobGroup);
return jobDetailFactory;
}

@Bean
public CronTriggerFactoryBean processMQTriggerForGrievanceDataSync() {
Boolean startJob = ConfigProperties.getBoolean("start-grievancedatasync-scheduler");
CronTriggerFactoryBean cronTriggerFactoryBean = new CronTriggerFactoryBean();
String scheduleConfig = quartzJobDefaultSchedule;
if (startJob) {
scheduleConfig = ConfigProperties.getPropertyByName("cron-scheduler-grievancedatasync");
}
cronTriggerFactoryBean.setJobDetail(processMQJobForGrievanceDataSync().getObject());
cronTriggerFactoryBean.setCronExpression(scheduleConfig);
cronTriggerFactoryBean.setGroup(quartzJobGroup);
return cronTriggerFactoryBean;
}



// --------------------------------------------------------------------------------------------------------------
@Bean
public JobDetailFactoryBean processMQJobForCtiDataSync() {
Expand Down
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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:

-logger.error("Grievance reallocation failed with error: " + e.getMessage(), e);
+logger.error("Grievance reallocation failed with error: {}", e.getMessage(), e);

-logger.error("Move to bin failed with error: " + e.getMessage(), e);
+logger.error("Move to bin failed with error: {}", e.getMessage(), e);

Also applies to: 115-115

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
Copy link
Contributor

@coderabbitai coderabbitai bot Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return "GrievanceAllocationRequest{" + "startDate=" + startDate + ", endDate=" + endDate + ", userID=" + userID
+ ", allocateNo=" + allocateNo + ", language=" + preferredLanguage + '}';
return "GrievanceAllocationRequest{" + "startDate=" + startDate + ", endDate=" + endDate + ", userID=" + userID
+ ", allocateNo=" + allocateNo + ", preferredLanguage=" + preferredLanguage + '}';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor

Choose a reason for hiding this comment

The 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?
Thank you for using CodeRabbit!

}

}
Loading
Loading