Skip to content
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

AMM-1140 | API for fetching unallocated grievance record count for allocation screen #152

Merged
merged 28 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 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
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
2 changes: 1 addition & 1 deletion src/main/java/com/iemr/common/config/PrimaryDBConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(entityManagerFactoryRef = "entityManagerFactory", basePackages = { "com.iemr.common.repository",
"com.iemr.common.repo", "com.iemr.common.notification.agent", "com.iemr.common.covidVaccination", "com.iemr.common.repository.everwell.*", " com.iemr.common.repository.users" })
"com.iemr.common.repo", "com.iemr.common.notification.agent", "com.iemr.common.covidVaccination", "com.iemr.common.repository.everwell.*", "com.iemr.common.data.grievance", "com.iemr.common.repository.users" })
public class PrimaryDBConfig {

Logger logger = LoggerFactory.getLogger(this.getClass().getName());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.iemr.common.controller.grievance;


import com.iemr.common.service.grievance.GrievanceDataSync;
import com.iemr.common.utils.exception.IEMRException;
import com.iemr.common.utils.response.OutputResponse;

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.RestController;

@RestController
public class GrievanceController {
final Logger logger = LoggerFactory.getLogger(this.getClass().getName());


private GrievanceDataSync grievanceDataSync;

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

@CrossOrigin()
@Operation(summary = "/unallocatedGrievanceCount")
@PostMapping(value = "/unallocatedGrievanceCount", consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, headers = "Authorization")
Comment on lines +33 to +35
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

Restrict CORS and add rate limiting.

The unrestricted @CrossOrigin() annotation could pose a security risk. Consider:

  1. Explicitly specify allowed origins
  2. Add rate limiting for this endpoint to prevent abuse

Apply this diff:

-@CrossOrigin()
+@CrossOrigin(origins = "${app.allowed-origins}")
+@RateLimiter(name = "grievanceCount")

Add to application.properties:

app.allowed-origins=https://example.com,https://admin.example.com

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

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
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;

@Repository
Expand All @@ -18,6 +15,8 @@ public interface GrievanceDataRepo extends CrudRepository<GrievanceDetails, Lon
@Query("SELECT COUNT(g) > 0 FROM GrievanceDetails g WHERE g.complaintId = :complaintId")
boolean existsByComplaintId(@Param("complaintId") String complaintId);


@Query("select count(request) "
+ "from GrievanceDetails request where request.isAllocated = false")
public Long fetchUnallocatedGrievanceCount();

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
import java.util.List;
import java.util.Map;

import org.json.JSONException;

import com.iemr.common.utils.exception.IEMRException;

public interface GrievanceDataSync {
public List<Map<String, Object>> dataSyncToGrievance();

public String fetchUnallocatedGrievanceCount() throws IEMRException, JSONException;
srishtigrp78 marked this conversation as resolved.
Show resolved Hide resolved

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import java.util.List;
import java.util.Map;

import org.json.JSONObject;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -37,7 +38,8 @@
import com.iemr.common.repository.grievance.GrievanceFetchBenDetailsRepo;
import com.iemr.common.repository.grievance.GrievanceTransactionRepo;
import com.iemr.common.repository.location.LocationStateRepository;
import com.iemr.common.utils.mapper.InputMapper;
import com.iemr.common.utils.exception.IEMRException;
import com.iemr.common.utils.mapper.InputMapper;

@Service
@PropertySource("classpath:application.properties")
Expand Down Expand Up @@ -371,5 +373,19 @@ private void generateGrievanceAuthToken() {
}
}
}

public String fetchUnallocatedGrievanceCount() throws IEMRException, JSONException {
logger.debug("Request received for fetchUnallocatedGrievanceCount");

Long unallocatedCount = grievanceDataRepo.fetchUnallocatedGrievanceCount();

if (unallocatedCount == null) {
throw new IEMRException("Failed to fetch unallocated grievance count");
}

JSONObject result = new JSONObject();
result.put("count", unallocatedCount);
return result.toString();
}
srishtigrp78 marked this conversation as resolved.
Show resolved Hide resolved

}
Loading