Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
a7a9518
adding changes related to encryption and decryption
Oct 16, 2024
e1b5318
making final field static
Oct 16, 2024
eddabe3
making enclosing method static
Oct 16, 2024
6e626bb
adding beneficiaryConsent param to createFeedback API
Dec 10, 2024
6cf8550
Merge pull request #6 from PSMRI/develop
srishtigrp78 Dec 10, 2024
2303d60
Update src/main/java/com/iemr/common/data/feedback/FeedbackDetails.java
srishtigrp78 Dec 10, 2024
68d0483
Merge pull request #7 from PSMRI/develop
srishtigrp78 Dec 10, 2024
b7718c0
adding beneficiary consent param feedbacklist response
Dec 11, 2024
f9feef6
adding space
Dec 11, 2024
019d315
Merge pull request #8 from PSMRI/develop
srishtigrp78 Dec 20, 2024
507f830
Merge pull request #9 from PSMRI/develop
srishtigrp78 Jan 8, 2025
21be52e
adding code for schedule for grievance data sync
Jan 9, 2025
0a90728
adding code rabbit code suggestions
Jan 16, 2025
ea9ff9e
adding code rabbit suggestions
Jan 16, 2025
8825473
code rabbit suggested changes to Model classes
Jan 16, 2025
2d639c4
adding sonar quality changes
Jan 16, 2025
b0e039b
adding sonar quality code suggestions
Jan 16, 2025
9831500
adding sonar quality check suggestions
Jan 17, 2025
5cb6886
adding code rabbit suggestions
Jan 17, 2025
9e8e1f2
adding constant instead of duplicate literals
Jan 17, 2025
67b2f86
Merge pull request #10 from PSMRI/develop
srishtigrp78 Jan 19, 2025
7b3b990
adding cod changs to fetch unallocated grievance count
Jan 19, 2025
d834aa9
adding changes suggested by sonar quality check
Jan 20, 2025
734551a
adding code rabbit suggested changes
Jan 20, 2025
47ceb56
fixing config file
Jan 21, 2025
f26b8ff
fixing space
Jan 21, 2025
d3534d9
fixing space issue
Jan 21, 2025
6b58965
adding package for PrimaryDBConfig
Jan 22, 2025
8d97517
Merge pull request #11 from PSMRI/develop
srishtigrp78 Jan 22, 2025
b5798d2
adding code changes for allocate API for allocating grievance to agents
Jan 22, 2025
abe5bd3
removing space
Jan 22, 2025
3c8fbb9
Merge pull request #12 from PSMRI/develop
srishtigrp78 Jan 23, 2025
ef1021e
adding language related changes
Jan 23, 2025
3451ad5
add language related changes
Jan 23, 2025
fa02a49
adding name convention related changes
Jan 24, 2025
822ec19
adding code rabbit changes
Jan 24, 2025
c8e85ab
adding sonar quality check suggested changes
Jan 24, 2025
6557199
removing unused imports
Jan 24, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@


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

@coderabbitai coderabbitai bot Jan 24, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Replace lettuce.core @param with OpenAPI @parameter annotation.

The @Param annotation from io.lettuce.core is intended for Redis operations, not API documentation. Since you're using OpenAPI/Swagger for documentation, use @Parameter from io.swagger.v3.oas.annotations instead.

-import io.lettuce.core.dynamic.annotation.Param;
+import io.swagger.v3.oas.annotations.Parameter;
πŸ“ 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
import io.lettuce.core.dynamic.annotation.Param;
import io.swagger.v3.oas.annotations.Parameter;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not required

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

import io.swagger.v3.oas.annotations.Operation;


import javax.ws.rs.core.MediaType;

import org.json.JSONException;
Expand All @@ -16,6 +15,7 @@
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.RestController;

@RestController
Expand All @@ -24,11 +24,15 @@ public class GrievanceController {


private GrievanceDataSync grievanceDataSync;

private final GrievanceHandlingService grievanceHandlingService;

@Autowired
public GrievanceController(GrievanceDataSync grievanceDataSync) {
public GrievanceController(GrievanceHandlingService grievanceHandlingService, GrievanceDataSync grievanceDataSync) {
this.grievanceDataSync = grievanceDataSync;
this.grievanceHandlingService = grievanceHandlingService;
}


@CrossOrigin()
@Operation(summary = "/unallocatedGrievanceCount")
Expand All @@ -53,4 +57,27 @@ public String fetchUnallocatedGrievanceCount() {
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) {
Comment on lines +63 to +71
Copy link
Contributor

@coderabbitai coderabbitai bot Jan 24, 2025

Choose a reason for hiding this comment

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

πŸ› οΈ Refactor suggestion

Enhance API documentation and request validation.

The endpoint documentation needs improvement:

  1. Replace the @param annotation with proper OpenAPI annotations
  2. Add response documentation
  3. Add explicit request validation
 @Operation(summary = "Allocate grievances to users")
+@ApiResponse(responseCode = "200", description = "Grievances allocated successfully")
+@ApiResponse(responseCode = "400", description = "Invalid request parameters")
+@ApiResponse(responseCode = "500", description = "Internal server error")
 @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)
+public ResponseEntity<OutputResponse> allocateGrievances(
+    @Parameter(description = "Start date in ISO-8601 format", required = true)
+    @RequestBody @Valid GrievanceAllocationRequest request)

Committable suggestion skipped: line range outside the PR's diff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not required

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

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();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.iemr.common.data.grievance;


import java.time.LocalDateTime;
import java.util.List;

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

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 +
'}';
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ public class GrievanceDetails {
@Expose
@Column(name = "callCounter")
private Integer callCounter;

@Expose
@Column(name = "PreferredLanguageId")
private Integer preferredLanguageId;

@Expose
@Column(name = "PreferredLanguage")
private String preferredLanguage;


@Column(name = "Deleted", insertable = false, updatable = true)
private Boolean deleted = false;
Expand Down Expand Up @@ -151,7 +160,7 @@ public class GrievanceDetails {
public GrievanceDetails(Long gwid, Long grievanceId, Long beneficiaryRegID, Long benCallID,
Integer providerServiceMapID, String complaintID, String subjectOfComplaint, String complaint,
String primaryNumber, String severety, String state, String agentID, String userid, Boolean isAllocated,
Boolean retryNeeded, Boolean isRegistered, Integer callCounter, Boolean deleted, Character processed,
Boolean retryNeeded, Boolean isRegistered, Integer callCounter, Integer preferredLanguageId, String preferredLanguage, Boolean deleted, Character processed,
String createdBy, Timestamp createdDate, String modifiedBy, Timestamp lastModDate, Integer vanSerialNo,
Integer vanID, String vehicalNo, Integer parkingPlaceID, String syncedBy, Timestamp syncedDate,
Boolean isCompleted) {
Expand All @@ -173,6 +182,8 @@ public GrievanceDetails(Long gwid, Long grievanceId, Long beneficiaryRegID, Long
this.retryNeeded = retryNeeded;
this.isRegistered = isRegistered;
this.callCounter = callCounter;
this.preferredLanguageId = preferredLanguageId;
this.preferredLanguage = preferredLanguage;
this.deleted = deleted;
this.processed = processed;
this.createdBy = createdBy;
Expand Down Expand Up @@ -324,6 +335,22 @@ public Integer getCallCounter() {
public void setCallCounter(Integer callCounter) {
this.callCounter = callCounter;
}

public Integer getPreferredLanguageId() {
return preferredLanguageId;
}

public void setPreferredLanguageId(Integer preferredLanguageId) {
this.preferredLanguageId = preferredLanguageId;
}

public String getPreferredLanguage() {
return preferredLanguage;
}

public void setPreferredLanguage(String preferredLanguage) {
this.preferredLanguage = preferredLanguage;
}

public Boolean getDeleted() {
return deleted;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package com.iemr.common.repository.grievance;


import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;


import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import com.iemr.common.data.grievance.GrievanceDetails;

import jakarta.transaction.Transactional;

@Repository
public interface GrievanceDataRepo extends CrudRepository<GrievanceDetails, Long>{

Expand All @@ -19,4 +24,21 @@ public interface GrievanceDataRepo extends CrudRepository<GrievanceDetails, Lon
+ "from GrievanceDetails request where request.isAllocated = false")
public Long fetchUnallocatedGrievanceCount();


@Query("SELECT g FROM GrievanceDetails g WHERE g.createdDate BETWEEN :startDate AND :endDate AND g.isAllocated = false AND g.preferredLanguage = :language")
List<GrievanceDetails> findGrievancesInDateRangeAndLanguage(
@Param("startDate") LocalDateTime startDate,
@Param("endDate") LocalDateTime endDate,
@Param("language") String language);


@Modifying
@Query("UPDATE GrievanceDetails g SET g.isAllocated = true, g.userid = :userId WHERE g.grievanceid = :grievanceId")
@Transactional
public int allocateGrievance(@Param("grievanceId") Long grievanceId, @Param("userId") Integer userId);


@Query(nativeQuery = true, value = "SELECT PreferredLanguageId, PreferredLanguage, VanSerialNo, VanID, ParkingPlaceId, VehicalNo FROM db_identity.i_beneficiarydetails WHERE BeneficiaryRegID = :benRegId")
public ArrayList<Object[]> getBeneficiaryGrievanceDetails(@Param("benRegId") Long benRegId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,22 @@ public List<Map<String, Object>> dataSyncToGrievance() {
grievance.setState(state);
}
}

//setting language related properties and other
ArrayList<Object[]> list1 = grievanceDataRepo.getBeneficiaryGrievanceDetails(grievance.getBeneficiaryRegId());
for (Object[] objects : list1) {
if (objects != null && objects.length >= 6) {
grievance.setPreferredLanguageId((Integer) objects[0]);
grievance.setPreferredLanguage((String) objects[1]);
grievance.setVanSerialNo((Integer) objects[2]);
grievance.setVanId((Integer) objects[3]);
grievance.setParkingPlaceId((Integer) objects[4]);
grievance.setVehicalNo((String) objects[5]);

}
}



// Setting remaining grievance properties (similar to the existing code)
grievance.setAgentId(grievance.getAgentId());
grievance.setDeleted(grievance.getDeleted());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.iemr.common.service.grievance;

import org.springframework.stereotype.Service;

@Service
public interface GrievanceHandlingService {
public String allocateGrievances(String request) throws Exception;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.iemr.common.service.grievance;

import java.util.Comparator;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Service;

import com.iemr.common.data.grievance.GrievanceAllocationRequest;
import com.iemr.common.data.grievance.GrievanceDetails;
import com.iemr.common.repository.grievance.GrievanceDataRepo;
import com.iemr.common.utils.mapper.InputMapper;

@Service
public class GrievanceHandlingServiceImpl implements GrievanceHandlingService {


private Logger logger = LoggerFactory.getLogger(GrievanceHandlingServiceImpl.class);


private final GrievanceDataRepo grievanceDataRepo;

@Autowired
public GrievanceHandlingServiceImpl(GrievanceDataRepo grievanceDataRepo) {
this.grievanceDataRepo = grievanceDataRepo;
}


@Override
public String allocateGrievances(String request) throws Exception {
// Step 1: Parse the request string into the appropriate GrievanceAllocationRequest object
GrievanceAllocationRequest allocationRequest = InputMapper.gson().fromJson(request, GrievanceAllocationRequest.class);

// Step 2: Fetch grievances based on the start date, end date range, and language
List<GrievanceDetails> grievances = grievanceDataRepo.findGrievancesInDateRangeAndLanguage(
allocationRequest.getStartDate(), allocationRequest.getEndDate(), allocationRequest.getLanguage());

if (grievances.isEmpty()) {
throw new Exception("No grievances found in the given date range and language.");
}

// Step 3: Sort grievances in ascending order based on creation date
grievances.sort(Comparator.comparing(GrievanceDetails::getCreatedDate));

// Step 4: Get the allocation parameters from the request
int totalAllocated = 0;
int userIndex = 0;
List<Integer> userIds = allocationRequest.getUserID();
int allocateNo = allocationRequest.getAllocateNo(); // Number of grievances to allocate per user


for (int i = 0; i < grievances.size(); i++) {
Integer userId = userIds.get(userIndex);
GrievanceDetails grievance = grievances.get(i);

int rowsAffected = grievanceDataRepo.allocateGrievance(grievance.getGrievanceId(), userId);
if (rowsAffected > 0) {
totalAllocated++;
logger.debug("Allocated grievance ID {} to user ID {}", grievance.getGrievanceId(), userId);
} else {
logger.error("Failed to allocate grievance ID {} to user ID {}", grievance.getGrievanceId(), userId);
}

// Move to the next user after allocateNo grievances
if ((i + 1) % allocateNo == 0) {
userIndex = (userIndex + 1) % userIds.size();
}
}

// Step 6: Return a message with the total number of grievances allocated
return "Successfully allocated " + totalAllocated + " grievances to users.";
}


}
Loading