From a7a9518b7a432a1e31270df03bc49239befc73d6 Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Tue, 15 Oct 2024 23:34:46 -0700 Subject: [PATCH 01/23] adding changes related to encryption and decryption --- .../AESEncryptionDecryption.java | 113 ++++++++++++------ 1 file changed, 77 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/iemr/common/utils/aesencryption/AESEncryptionDecryption.java b/src/main/java/com/iemr/common/utils/aesencryption/AESEncryptionDecryption.java index bd78368..d0a730a 100644 --- a/src/main/java/com/iemr/common/utils/aesencryption/AESEncryptionDecryption.java +++ b/src/main/java/com/iemr/common/utils/aesencryption/AESEncryptionDecryption.java @@ -1,73 +1,114 @@ package com.iemr.common.utils.aesencryption; import java.io.UnsupportedEncodingException; + import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; import java.util.Arrays; import java.util.Base64; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; +import javax.crypto.spec.GCMParameterSpec; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; -import com.iemr.common.encryption.exception.DecryptionException; -import com.iemr.common.encryption.exception.EncryptionException; import com.iemr.common.utils.aesencryption.AESEncryptionDecryption; @Component public class AESEncryptionDecryption { - private static Logger logger = LoggerFactory.getLogger(AESEncryptionDecryption.class); + + private Logger logger = LoggerFactory.getLogger(AESEncryptionDecryption.class); + private static SecretKeySpec secretKey; - private static byte[] key; - static final String SECRET = "amrith$%2022@&*piramal@@swasthya!#"; - public static void setKey(String myKey) { - MessageDigest sha = null; + private byte[] key; + + private final String secret = "amrith$%2022@&*piramal@@swasthya!#"; + + private static final int IV_SIZE = 12; + + private static final int TAG_SIZE = 128; + + private final String UTF_8 = "UTF-8"; + + public void setKey(String myKey) { + try { - key = myKey.getBytes("UTF-8"); - sha = MessageDigest.getInstance("SHA-512"); + + key = myKey.getBytes(UTF_8); + + MessageDigest sha = MessageDigest.getInstance("SHA-512"); + key = sha.digest(key); + key = Arrays.copyOf(key, 16); + secretKey = new SecretKeySpec(key, "AES"); + } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) { - logger.error("context", e); + + logger.error("context", e); + } + } + + public String encrypt(String strToEncrypt) throws Exception { + if (secretKey == null) + + setKey(secret); + + Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding"); + + // Generate IV + + byte[] iv = new byte[IV_SIZE]; + + SecureRandom random = new SecureRandom(); + + random.nextBytes(iv); + + cipher.init(Cipher.ENCRYPT_MODE, secretKey, new GCMParameterSpec(TAG_SIZE, iv)); + + byte[] encryptedBytes = cipher.doFinal(strToEncrypt.getBytes(UTF_8)); + + byte[] encryptedIvAndText = new byte[IV_SIZE + encryptedBytes.length]; + + System.arraycopy(iv, 0, encryptedIvAndText, 0, IV_SIZE); + + System.arraycopy(encryptedBytes, 0, encryptedIvAndText, IV_SIZE, encryptedBytes.length); + + return Base64.getEncoder().encodeToString(encryptedIvAndText); - public String encrypt(String strToEncrypt) throws EncryptionException { - String encryptedString=null; - try { - if (secretKey == null) - setKey(SECRET); - Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding"); - cipher.init(Cipher.ENCRYPT_MODE, secretKey); - encryptedString= Base64.getEncoder().encodeToString(cipher.doFinal(strToEncrypt.getBytes("UTF-8"))); - } catch (Exception e) { - logger.error("Error while encrypting: {}", e.toString()); - throw new EncryptionException("Error while encrypting: "+e.toString(), e); - } - return encryptedString; } + + public String decrypt(String strToDecrypt) throws Exception { + if (secretKey == null) + + setKey(secret); + + byte[] encryptedIvAndText = Base64.getDecoder().decode(strToDecrypt); + + byte[] iv = Arrays.copyOfRange(encryptedIvAndText, 0, IV_SIZE); + + byte[] encryptedBytes = Arrays.copyOfRange(encryptedIvAndText, IV_SIZE, encryptedIvAndText.length); + + Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding"); + + cipher.init(Cipher.DECRYPT_MODE, secretKey, new GCMParameterSpec(TAG_SIZE, iv)); + + byte[] decryptedBytes = cipher.doFinal(encryptedBytes); + + return new String(decryptedBytes, UTF_8); - public String decrypt(String strToDecrypt) throws DecryptionException { - String decryptedString=null; - try { - if (secretKey == null) - setKey(SECRET); - Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding"); - cipher.init(Cipher.DECRYPT_MODE, secretKey); - decryptedString= new String(cipher.doFinal(Base64.getDecoder().decode(strToDecrypt))); - } catch (Exception e) { - logger.error("Error while decrypting: {}",e.toString()); - throw new DecryptionException("Error while decrypting: "+e.toString(), e); - } - return decryptedString; } + } From e1b53189a6a8dc8f1aa347fd50bd4e2c726c26a9 Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Tue, 15 Oct 2024 23:42:56 -0700 Subject: [PATCH 02/23] making final field static --- .../common/utils/aesencryption/AESEncryptionDecryption.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/iemr/common/utils/aesencryption/AESEncryptionDecryption.java b/src/main/java/com/iemr/common/utils/aesencryption/AESEncryptionDecryption.java index d0a730a..0fab324 100644 --- a/src/main/java/com/iemr/common/utils/aesencryption/AESEncryptionDecryption.java +++ b/src/main/java/com/iemr/common/utils/aesencryption/AESEncryptionDecryption.java @@ -29,13 +29,13 @@ public class AESEncryptionDecryption { private byte[] key; - private final String secret = "amrith$%2022@&*piramal@@swasthya!#"; + private static final String secret = "amrith$%2022@&*piramal@@swasthya!#"; private static final int IV_SIZE = 12; private static final int TAG_SIZE = 128; - private final String UTF_8 = "UTF-8"; + private static final String UTF_8 = "UTF-8"; public void setKey(String myKey) { From eddabe303a59b4d9f181d22139db1319bc374542 Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Tue, 15 Oct 2024 23:48:30 -0700 Subject: [PATCH 03/23] making enclosing method static --- .../utils/aesencryption/AESEncryptionDecryption.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/iemr/common/utils/aesencryption/AESEncryptionDecryption.java b/src/main/java/com/iemr/common/utils/aesencryption/AESEncryptionDecryption.java index 0fab324..2c337d3 100644 --- a/src/main/java/com/iemr/common/utils/aesencryption/AESEncryptionDecryption.java +++ b/src/main/java/com/iemr/common/utils/aesencryption/AESEncryptionDecryption.java @@ -23,13 +23,13 @@ public class AESEncryptionDecryption { - private Logger logger = LoggerFactory.getLogger(AESEncryptionDecryption.class); + private static Logger logger = LoggerFactory.getLogger(AESEncryptionDecryption.class); private static SecretKeySpec secretKey; - private byte[] key; + private static byte[] key; - private static final String secret = "amrith$%2022@&*piramal@@swasthya!#"; + private static final String SECRET = "amrith$%2022@&*piramal@@swasthya!#"; private static final int IV_SIZE = 12; @@ -37,7 +37,7 @@ public class AESEncryptionDecryption { private static final String UTF_8 = "UTF-8"; - public void setKey(String myKey) { + public static void setKey(String myKey) { try { @@ -63,7 +63,7 @@ public String encrypt(String strToEncrypt) throws Exception { if (secretKey == null) - setKey(secret); + setKey(SECRET); Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding"); @@ -93,7 +93,7 @@ public String decrypt(String strToDecrypt) throws Exception { if (secretKey == null) - setKey(secret); + setKey(SECRET); byte[] encryptedIvAndText = Base64.getDecoder().decode(strToDecrypt); From 6e626bb73d41436b6fe4939546635728e5b22686 Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Mon, 9 Dec 2024 23:55:33 -0800 Subject: [PATCH 04/23] adding beneficiaryConsent param to createFeedback API --- .../common/data/feedback/FeedbackDetails.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/iemr/common/data/feedback/FeedbackDetails.java b/src/main/java/com/iemr/common/data/feedback/FeedbackDetails.java index 40111eb..b09c5de 100644 --- a/src/main/java/com/iemr/common/data/feedback/FeedbackDetails.java +++ b/src/main/java/com/iemr/common/data/feedback/FeedbackDetails.java @@ -100,6 +100,10 @@ public class FeedbackDetails { @Transient private String instituteName = ""; + + @Column(name = "BeneficiaryConsent") + @Expose + private Boolean beneficiaryConsent; @Column(name = "DesignationID") @Expose @@ -304,7 +308,7 @@ public FeedbackDetails() { public FeedbackDetails(Long feedbackID, Long institutionID,String instiName, Integer designationID, Integer severityID, Integer feedbackTypeID, Integer feedbackStatusID, String feedback, Long beneficiaryRegID, Integer serviceID, Integer userID, String sMSPhoneNo, Timestamp serviceAvailDate, Boolean deleted, String createdBy, - Timestamp createdDate, String modifiedBy, Timestamp lastModDate, String feedbackAgainst) { + Timestamp createdDate, String modifiedBy, Timestamp lastModDate, String feedbackAgainst, Boolean beneficiaryConsent) { super(); this.feedbackID = feedbackID; this.institutionID = institutionID; @@ -325,7 +329,8 @@ public FeedbackDetails(Long feedbackID, Long institutionID,String instiName, Int this.modifiedBy = modifiedBy; this.lastModDate = lastModDate; this.feedbackAgainst = feedbackAgainst; - } + this.beneficiaryConsent = beneficiaryConsent; + } public FeedbackDetails(Long feedbackID, Integer severityID, Integer feedbackTypeID, Integer feedbackStatusID, String feedback, String createdBy, String feedbackAgainst) { @@ -466,6 +471,16 @@ public Boolean getDeleted() { public void setDeleted(Boolean deleted) { this.deleted = deleted; } + + public Boolean getbeneficiaryConsent() { + return beneficiaryConsent; + } + + public void setbeneficiaryConsent(Boolean beneficiaryConsent) { + this.beneficiaryConsent = beneficiaryConsent; + } + + public String getCreatedBy() { return createdBy; @@ -555,7 +570,7 @@ public static FeedbackDetails initializeFeedbackDetailsWithAllFeilds(Long feedba Integer stateID, States state, Integer districtID, Districts district, Integer blockID, DistrictBlock districtBlock, Integer districtBranchID, DistrictBranchMapping districtBranchMapping, Integer instituteTypeID, InstituteType instituteType, Integer feedbackNatureID, - FeedbackNatureDetail feedbackNatureDetail, String feedbackAgainst) { + FeedbackNatureDetail feedbackNatureDetail, String feedbackAgainst, Boolean beneficiaryConsent) { FeedbackDetails feedbackDetails = new FeedbackDetails(); feedbackDetails.feedbackID = feedbackID; feedbackDetails.mUser = mUser; @@ -624,6 +639,7 @@ public static FeedbackDetails initializeFeedbackDetailsWithAllFeilds(Long feedba feedbackDetails.feedbackNatureID = feedbackNatureID; feedbackDetails.feedbackNatureDetail = feedbackNatureDetail; feedbackDetails.feedbackAgainst = feedbackAgainst; + feedbackDetails.beneficiaryConsent = beneficiaryConsent; return feedbackDetails; } From 2303d6011ddde25e254908bf6519167eca36c0b7 Mon Sep 17 00:00:00 2001 From: Srishti gupta <76839176+srishtigrp78@users.noreply.github.com> Date: Tue, 10 Dec 2024 00:08:54 -0800 Subject: [PATCH 05/23] Update src/main/java/com/iemr/common/data/feedback/FeedbackDetails.java Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../java/com/iemr/common/data/feedback/FeedbackDetails.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/iemr/common/data/feedback/FeedbackDetails.java b/src/main/java/com/iemr/common/data/feedback/FeedbackDetails.java index b09c5de..5ab9ea6 100644 --- a/src/main/java/com/iemr/common/data/feedback/FeedbackDetails.java +++ b/src/main/java/com/iemr/common/data/feedback/FeedbackDetails.java @@ -471,12 +471,11 @@ public Boolean getDeleted() { public void setDeleted(Boolean deleted) { this.deleted = deleted; } - - public Boolean getbeneficiaryConsent() { + public Boolean getBeneficiaryConsent() { return beneficiaryConsent; } - public void setbeneficiaryConsent(Boolean beneficiaryConsent) { + public void setBeneficiaryConsent(Boolean beneficiaryConsent) { this.beneficiaryConsent = beneficiaryConsent; } From b7718c06d52ce206f5eb951d6074f79ffee5ef33 Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Tue, 10 Dec 2024 22:59:29 -0800 Subject: [PATCH 06/23] adding beneficiary consent param feedbacklist response --- .../com/iemr/common/model/feedback/FeedbackDetailsModel.java | 1 + .../iemr/common/model/feedback/FeedbackListResponseModel.java | 1 + .../com/iemr/common/model/feedback/FeedbackResponseModel.java | 1 + 3 files changed, 3 insertions(+) diff --git a/src/main/java/com/iemr/common/model/feedback/FeedbackDetailsModel.java b/src/main/java/com/iemr/common/model/feedback/FeedbackDetailsModel.java index 4f13209..9bb2bfd 100644 --- a/src/main/java/com/iemr/common/model/feedback/FeedbackDetailsModel.java +++ b/src/main/java/com/iemr/common/model/feedback/FeedbackDetailsModel.java @@ -99,4 +99,5 @@ public class FeedbackDetailsModel private String modifiedBy; private Timestamp lastModDate; private String feedbackAgainst; + private Boolean beneficiaryConsent; } diff --git a/src/main/java/com/iemr/common/model/feedback/FeedbackListResponseModel.java b/src/main/java/com/iemr/common/model/feedback/FeedbackListResponseModel.java index f5d1428..6f2873c 100644 --- a/src/main/java/com/iemr/common/model/feedback/FeedbackListResponseModel.java +++ b/src/main/java/com/iemr/common/model/feedback/FeedbackListResponseModel.java @@ -100,6 +100,7 @@ public class FeedbackListResponseModel { private String modifiedBy; private Timestamp lastModDate; private String feedbackAgainst; + private Boolean beneficiaryConsent; private String requestType; private EpidemicOutbreak epidemicOutbreak; diff --git a/src/main/java/com/iemr/common/model/feedback/FeedbackResponseModel.java b/src/main/java/com/iemr/common/model/feedback/FeedbackResponseModel.java index 27a92a2..00c3a2a 100644 --- a/src/main/java/com/iemr/common/model/feedback/FeedbackResponseModel.java +++ b/src/main/java/com/iemr/common/model/feedback/FeedbackResponseModel.java @@ -49,4 +49,5 @@ private Timestamp createdDate; private String modifiedBy; private Timestamp lastModDate; + private Boolean beneficiaryConsent; } From f9feef6d0a58715756a635d2abc96a0f78a57473 Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Tue, 10 Dec 2024 23:01:00 -0800 Subject: [PATCH 07/23] adding space --- .../iemr/common/model/feedback/FeedbackListResponseModel.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/iemr/common/model/feedback/FeedbackListResponseModel.java b/src/main/java/com/iemr/common/model/feedback/FeedbackListResponseModel.java index 6f2873c..eca4ec4 100644 --- a/src/main/java/com/iemr/common/model/feedback/FeedbackListResponseModel.java +++ b/src/main/java/com/iemr/common/model/feedback/FeedbackListResponseModel.java @@ -105,4 +105,5 @@ public class FeedbackListResponseModel { private String requestType; private EpidemicOutbreak epidemicOutbreak; private BalVivahComplaint balVivahComplaint; + } From 21be52e9b1aaa78b16c6736ca7b4249faceffe64 Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Wed, 8 Jan 2025 22:49:47 -0800 Subject: [PATCH 08/23] adding code for schedule for grievance data sync --- .../common/config/quartz/QuartzConfig.java | 30 +- .../quartz/ScheduleForGrievanceDataSync.java | 33 ++ .../data/grievance/GrievanceDetails.java | 441 ++++++++++++++++++ .../data/grievance/GrievanceTransaction.java | 235 ++++++++++ .../grievance/GrievanceDataRepo.java | 23 + .../GrievanceFetchBenDetailsRepo.java | 20 + .../grievance/GrievanceTransactionRepo.java | 11 + .../location/LocationStateRepository.java | 5 + .../service/grievance/GrievanceDataSync.java | 8 + .../grievance/GrievanceDataSyncImpl.java | 402 ++++++++++++++++ 10 files changed, 1207 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/iemr/common/config/quartz/ScheduleForGrievanceDataSync.java create mode 100644 src/main/java/com/iemr/common/data/grievance/GrievanceDetails.java create mode 100644 src/main/java/com/iemr/common/data/grievance/GrievanceTransaction.java create mode 100644 src/main/java/com/iemr/common/repository/grievance/GrievanceDataRepo.java create mode 100644 src/main/java/com/iemr/common/repository/grievance/GrievanceFetchBenDetailsRepo.java create mode 100644 src/main/java/com/iemr/common/repository/grievance/GrievanceTransactionRepo.java create mode 100644 src/main/java/com/iemr/common/service/grievance/GrievanceDataSync.java create mode 100644 src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java diff --git a/src/main/java/com/iemr/common/config/quartz/QuartzConfig.java b/src/main/java/com/iemr/common/config/quartz/QuartzConfig.java index 7c80991..468e9a4 100644 --- a/src/main/java/com/iemr/common/config/quartz/QuartzConfig.java +++ b/src/main/java/com/iemr/common/config/quartz/QuartzConfig.java @@ -97,7 +97,8 @@ public SchedulerFactoryBean quartzScheduler() { Trigger[] triggers = { processMQTriggerForUnblock().getObject(), processMQTriggerForSMS().getObject(), processMQTriggerForEmail().getObject(), processMQTriggerForRegistration().getObject(), processMQTriggerForEverwellDataSync().getObject(), processMQTriggerForCtiDataSync().getObject(), - processMQTriggerForAvniRegistration().getObject(), processMQTriggerForNHMDashboardData().getObject() }; + processMQTriggerForAvniRegistration().getObject(), + processMQTriggerForNHMDashboardData().getObject(), processMQTriggerForGrievanceDataSync().getObject() }; quartzScheduler.setTriggers(triggers); @@ -226,6 +227,33 @@ 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() { diff --git a/src/main/java/com/iemr/common/config/quartz/ScheduleForGrievanceDataSync.java b/src/main/java/com/iemr/common/config/quartz/ScheduleForGrievanceDataSync.java new file mode 100644 index 0000000..f1d5a7d --- /dev/null +++ b/src/main/java/com/iemr/common/config/quartz/ScheduleForGrievanceDataSync.java @@ -0,0 +1,33 @@ +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 com.iemr.common.service.grievance.GrievanceDataSync; + +@Service +@Transactional +public class ScheduleForGrievanceDataSync implements Job { + + private final Logger logger = LoggerFactory.getLogger(this.getClass().getName()); + + @Autowired + 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()); + } + + + +} diff --git a/src/main/java/com/iemr/common/data/grievance/GrievanceDetails.java b/src/main/java/com/iemr/common/data/grievance/GrievanceDetails.java new file mode 100644 index 0000000..70d1c15 --- /dev/null +++ b/src/main/java/com/iemr/common/data/grievance/GrievanceDetails.java @@ -0,0 +1,441 @@ +package com.iemr.common.data.grievance; + +import java.sql.Timestamp; +import java.util.List; + +import com.google.gson.annotations.Expose; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.Data; + +@Entity +@Table(name = "t_grievanceworklist") +@Data +public class GrievanceDetails { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Expose + @Column(name = "GWID") + private Long gwid; + + @Expose + @Column(name = "Grievanceid") + private Long grievanceId; + + @Expose + @Column(name = "BeneficiaryRegID") + private Long beneficiaryRegID; + + @Column(name = "BenCallid") + @Expose + private Long benCallID; + + @Column(name = "ProviderServiceMapID") + @Expose + private Integer providerServiceMapID; + + @Expose + @Column(name = "ComplaintID") + private String complaintID; + + @Expose + @Column(name = "SubjectOfComplaint") + private String subjectOfComplaint; + + @Expose + @Column(name = "Complaint") + private String complaint; + + @Expose + @Column(name = "primaryNumber") + private String primaryNumber; + + @Expose + @Column(name = "Severety") + private String severety; + + @Expose + @Column(name = "Level") + private String level; + @Expose + @Column(name = "State") + private String state; + + @Expose + @Column(name = "Agentid") + private String agentid; + + @Expose + @Column(name = "userid") + private String userid; + + @Expose + @Column(name = "isAllocated") + private Boolean isAllocated = false; + + @Expose + @Column(name = "retryNeeded") + private Boolean retryNeeded; + + @Expose + @Column(name = "isRegistered") + private Boolean isRegistered = false; + + @Expose + @Column(name = "callCounter") + private Integer callCounter; + + @Column(name = "Deleted", insertable = false, updatable = true) + private Boolean deleted = false; + + @Expose + @Column(name = "Processed") + private Character Processed = 'N'; + + @Column(name = "CreatedBy") + @Expose + private String createdBy; + + @Expose + @Column(name = "CreatedDate", insertable = false, updatable = false) + private Timestamp createdDate; + + @Column(name = "ModifiedBy") + private String modifiedBy; + + @Column(name = "LastModDate", insertable = false, updatable = false) + private Timestamp lastModDate; + + @Expose + @Column(name = "VanSerialNo") + private Integer VanSerialNo; + @Expose + @Column(name = "VanID") + private Integer VanID; + + @Expose + @Column(name = "VehicalNo") + private String VehicalNo; + @Expose + @Column(name = "ParkingPlaceID") + private Integer ParkingPlaceID; + @Expose + @Column(name = "SyncedBy") + private String syncedBy; + + @Expose + @Column(name = "SyncedDate") + private Timestamp syncedDate; + + @Expose + @Column(name = "isCompleted") + private Boolean isCompleted = false; + + private List grievanceTransactionDetails; + + + 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, + String createdBy, Timestamp createdDate, String modifiedBy, Timestamp lastModDate, Integer vanSerialNo, + Integer vanID, String vehicalNo, Integer parkingPlaceID, String syncedBy, Timestamp syncedDate, + Boolean isCompleted) { + super(); + this.gwid = gwid; + this.grievanceId = grievanceId; + this.beneficiaryRegID = beneficiaryRegID; + this.benCallID = benCallID; + this.providerServiceMapID = providerServiceMapID; + this.complaintID = complaintID; + this.subjectOfComplaint = subjectOfComplaint; + this.complaint = complaint; + this.primaryNumber = primaryNumber; + this.severety = severety; + this.state = state; + this.agentid = agentID; + this.userid = userid; + this.isAllocated = isAllocated; + this.retryNeeded = retryNeeded; + this.isRegistered = isRegistered; + this.callCounter = callCounter; + this.deleted = deleted; + this.Processed = processed; + this.createdBy = createdBy; + this.createdDate = createdDate; + this.modifiedBy = modifiedBy; + this.lastModDate = lastModDate; + this.VanSerialNo = vanSerialNo; + this.VanID = vanID; + this.VehicalNo = vehicalNo; + this.ParkingPlaceID = parkingPlaceID; + this.syncedBy = syncedBy; + this.syncedDate = syncedDate; + this.isCompleted = isCompleted; + } + + // Getters and Setters + public Long getGwid() { + return gwid; + } + + public void setGwid(Long gwid) { + this.gwid = gwid; + } + + public Long getGrievanceId() { + return grievanceId; + } + + public void setGrievanceId(Long grievanceId) { + this.grievanceId = grievanceId; + } + + public Long getBeneficiaryRegId() { + return beneficiaryRegID; + } + + public void setBeneficiaryRegId(Long beneficiaryRegId) { + this.beneficiaryRegID = beneficiaryRegId; + } + + public Long getBencallId() { + return benCallID; + } + + public void setBencallId(Long bencallId) { + this.benCallID = bencallId; + } + + public Integer getProviderServiceMapId() { + return providerServiceMapID; + } + + public void setProviderServiceMapId(Integer providerServiceMapId) { + this.providerServiceMapID = providerServiceMapId; + } + + public String getComplaintId() { + return complaintID; + } + + public void setComplaintId(String complaintId) { + this.complaintID = complaintId; + } + + public String getSubjectOfComplaint() { + return subjectOfComplaint; + } + + public void setSubjectOfComplaint(String subjectOfComplaint) { + this.subjectOfComplaint = subjectOfComplaint; + } + + public String getComplaint() { + return complaint; + } + + public void setComplaint(String complaint) { + this.complaint = complaint; + } + + public String getPrimaryNumber() { + return primaryNumber; + } + + public void setPrimaryNumber(String primaryNumber) { + this.primaryNumber = primaryNumber; + } + + public String getSeverety() { + return severety; + } + + public void setSeverity(String severety) { + this.severety = severety; + } + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + public String getAgentId() { + return agentid; + } + + public void setAgentId(String agentId) { + this.agentid = agentId; + } + + public Boolean getIsRegistered() { + return isRegistered; + } + + public void setIsRegistered(Boolean isRegistered) { + this.isRegistered = isRegistered; + } + + public String getUserId() { + return userid; + } + + public void setUserId(String userId) { + this.userid = userId; + } + + public Boolean getIsAllocated() { + return isAllocated; + } + + public void setIsAllocated(Boolean isAllocated) { + this.isAllocated = isAllocated; + } + + public Boolean getRetryNeeded() { + return retryNeeded; + } + + public void setRetryNeeded(Boolean retryNeeded) { + this.retryNeeded = retryNeeded; + } + + public Integer getCallCounter() { + return callCounter; + } + + public void setCallCounter(Integer callCounter) { + this.callCounter = callCounter; + } + + public Boolean getDeleted() { + return deleted; + } + + public void setDeleted(Boolean deleted) { + this.deleted = deleted; + } + + public Character getProcessed() { + return Processed; + } + + public void setProcessed(Character processed) { + this.Processed = processed; + } + + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + public Timestamp getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(Timestamp createdDate) { + this.createdDate = createdDate; + } + + public String getModifiedBy() { + return modifiedBy; + } + + public void setModifiedBy(String modifiedBy) { + this.modifiedBy = modifiedBy; + } + + public Timestamp getLastModDate() { + return lastModDate; + } + + public void setLastModDate(Timestamp lastModDate) { + this.lastModDate = lastModDate; + } + + public Integer getVanSerialNo() { + return VanSerialNo; + } + + public void setVanSerialNo(Integer vanSerialNo) { + this.VanSerialNo = vanSerialNo; + } + + public Integer getVanId() { + return VanID; + } + + public void setVanId(Integer vanId) { + this.VanID = vanId; + } + + public String getVehicleNo() { + return VehicalNo; + } + + public void setVehicleNo(String vehicleNo) { + this.VehicalNo = vehicleNo; + } + + public Integer getParkingPlaceId() { + return ParkingPlaceID; + } + + public void setParkingPlaceId(Integer parkingPlaceId) { + this.ParkingPlaceID = parkingPlaceId; + } + + public String getSyncedBy() { + return syncedBy; + } + + public void setSyncedBy(String syncedBy) { + this.syncedBy = syncedBy; + } + + public Timestamp getSyncedDate() { + return syncedDate; + } + + public void setSyncedDate(Timestamp syncedDate) { + this.syncedDate = syncedDate; + } + + public Boolean getIsCompleted() { + return isCompleted; + } + + public void setIsCompleted(Boolean isCompleted) { + this.isCompleted = isCompleted; + } + + + + // Getter for grievanceTransactionDetails + public List getGrievanceTransactionDetails() { + return grievanceTransactionDetails; + } + + // Setter for grievanceTransactionDetails + public void setGrievanceTransactionDetails(List grievanceTransactionDetails) { + this.grievanceTransactionDetails = grievanceTransactionDetails; + } + + + + +} + + \ No newline at end of file diff --git a/src/main/java/com/iemr/common/data/grievance/GrievanceTransaction.java b/src/main/java/com/iemr/common/data/grievance/GrievanceTransaction.java new file mode 100644 index 0000000..e734f16 --- /dev/null +++ b/src/main/java/com/iemr/common/data/grievance/GrievanceTransaction.java @@ -0,0 +1,235 @@ +package com.iemr.common.data.grievance; + + +import javax.persistence.*; + +import com.google.gson.annotations.Expose; + +import lombok.Data; + +import java.util.Date; + +@Entity +@Data +@Table(name = "t_grievancetransaction") +public class GrievanceTransaction { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "gtid") + private Long gtid; + + @Column(name = "gwid", nullable = false) + @Expose + private Long gwid; + + @Column(name = "FileName", nullable = false, length = 500) + @Expose + private String fileName; + + @Column(name = "FileType", nullable = false, length = 300) + @Expose + private String fileType; + + @Column(name = "Redressed", nullable = false) + @Expose + private String redressed; + + @Column(name = "createdAt", nullable = false) + @Expose + private Date createdAt; + + @Column(name = "updatedAt", nullable = false) + @Expose + private Date updatedAt; + + @Column(name = "Comments", length = 500) + private String comments; + + @Column(name = "ProviderServiceMapID") + @Expose + private Integer providerServiceMapID; + + @Column(name = "Deleted", insertable = false, updatable = true) + @Expose + private Boolean deleted; + + @Column(name = "Processed", nullable = false) + @Expose + private String processed; + + + @Column(name = "ActionTakenBy") + @Expose + private String actionTakenBy; + + @Column(name = "Status") + @Expose + private String status; + + @Column(name = "Comment") + @Expose + private String comment; + + @Column(name = "CreatedBy", nullable = false) + @Expose + private String createdBy; + + @Column(name = "CreatedDate", nullable = false) + private Date createdDate; + + @Column(name = "ModifiedBy") + @Expose + private String modifiedBy; + + @Column(name = "LastModDate") + @Expose + private Date lastModDate; + + // Getters and Setters + + public Long getGtid() { + return gtid; + } + + public void setGtid(Long gtid) { + this.gtid = gtid; + } + + public Long getGwid() { + return gwid; + } + + public void setGwid(Long gwid) { + this.gwid = gwid; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public String getFileType() { + return fileType; + } + + public void setFileType(String fileType) { + this.fileType = fileType; + } + + public String getRedressed() { + return redressed; + } + + public void setRedressed(String redressed) { + this.redressed = redressed; + } + + public Date getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } + + public Date getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(Date updatedAt) { + this.updatedAt = updatedAt; + } + + public String getComments() { + return comments; + } + + public void setComments(String comments) { + this.comments = comments; + } + + public Integer getProviderServiceMapID() { + return providerServiceMapID; + } + + public void setProviderServiceMapID(Integer providerServiceMapID) { + this.providerServiceMapID = providerServiceMapID; + } + + public Boolean getDeleted() { + return deleted; + } + + public void setDeleted(Boolean deleted) { + this.deleted = deleted; + } + + public String getProcessed() { + return processed; + } + + public void setProcessed(String processed) { + this.processed = processed; + } + + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + public Date getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public String getModifiedBy() { + return modifiedBy; + } + + public void setModifiedBy(String modifiedBy) { + this.modifiedBy = modifiedBy; + } + + public Date getLastModDate() { + return lastModDate; + } + + public void setLastModDate(Date lastModDate) { + this.lastModDate = lastModDate; + } + + public String getActionTakenBy( ) { + return actionTakenBy; + } + + public void setActionTakenBy(String actionTakenBy) { + this.actionTakenBy = actionTakenBy; + } + + public String getStatus( ) { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String comment( ) { + return comment; + } + + public void setComment(String comment ) { + this.comment = comment; + } +} + diff --git a/src/main/java/com/iemr/common/repository/grievance/GrievanceDataRepo.java b/src/main/java/com/iemr/common/repository/grievance/GrievanceDataRepo.java new file mode 100644 index 0000000..a428c74 --- /dev/null +++ b/src/main/java/com/iemr/common/repository/grievance/GrievanceDataRepo.java @@ -0,0 +1,23 @@ +package com.iemr.common.repository.grievance; + + + + +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; + +@Repository +public interface GrievanceDataRepo extends CrudRepository{ + + @Query("SELECT COUNT(g) > 0 FROM GrievanceDetails g WHERE g.complaintId = :complaintId") + boolean existsByComplaintId(@Param("complaintId") String complaintId); + + + +} diff --git a/src/main/java/com/iemr/common/repository/grievance/GrievanceFetchBenDetailsRepo.java b/src/main/java/com/iemr/common/repository/grievance/GrievanceFetchBenDetailsRepo.java new file mode 100644 index 0000000..09ce5a8 --- /dev/null +++ b/src/main/java/com/iemr/common/repository/grievance/GrievanceFetchBenDetailsRepo.java @@ -0,0 +1,20 @@ +package com.iemr.common.repository.grievance; + +import java.util.ArrayList; + +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.feedback.FeedbackDetails; + + +@Repository +public interface GrievanceFetchBenDetailsRepo extends CrudRepository { + + @Query("select requestID, benCallID, beneficiaryRegID, providerServiceMapID, stateID " + + " from FeedbackDetails where requestID = :requestID order by requestID desc") + public ArrayList findByComplaintId(@Param("requestID") String requestID); + +} diff --git a/src/main/java/com/iemr/common/repository/grievance/GrievanceTransactionRepo.java b/src/main/java/com/iemr/common/repository/grievance/GrievanceTransactionRepo.java new file mode 100644 index 0000000..2c51383 --- /dev/null +++ b/src/main/java/com/iemr/common/repository/grievance/GrievanceTransactionRepo.java @@ -0,0 +1,11 @@ +package com.iemr.common.repository.grievance; + +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import com.iemr.common.data.grievance.GrievanceTransaction; + +@Repository +public interface GrievanceTransactionRepo extends CrudRepository { + +} diff --git a/src/main/java/com/iemr/common/repository/location/LocationStateRepository.java b/src/main/java/com/iemr/common/repository/location/LocationStateRepository.java index 1685b46..0555a46 100644 --- a/src/main/java/com/iemr/common/repository/location/LocationStateRepository.java +++ b/src/main/java/com/iemr/common/repository/location/LocationStateRepository.java @@ -50,4 +50,9 @@ public interface LocationStateRepository extends CrudRepository public String getStateLanguage(@Param("stateName") String stateName); States findByStateID(Integer stateID); + + @Query("select state from States state where state.stateID = :id") + public String findByStateIDForGrievance(@Param("id") int id); + + } diff --git a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSync.java b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSync.java new file mode 100644 index 0000000..188e1cb --- /dev/null +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSync.java @@ -0,0 +1,8 @@ +package com.iemr.common.service.grievance; + +import java.util.List; +import java.util.Map; + +public interface GrievanceDataSync { + public List> dataSyncToGrievance(); +} diff --git a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java new file mode 100644 index 0000000..8b3d384 --- /dev/null +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java @@ -0,0 +1,402 @@ +package com.iemr.common.service.grievance; + + + + import java.sql.Timestamp; + import java.util.ArrayList; + import java.util.Arrays; + import java.util.Calendar; + import java.util.Date; + import java.util.HashMap; + import java.util.List; + import java.util.Map; + + import org.json.JSONObject; + 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.http.HttpEntity; + import org.springframework.http.HttpHeaders; + import org.springframework.http.HttpMethod; + import org.springframework.http.MediaType; + import org.springframework.http.ResponseEntity; + import org.springframework.stereotype.Service; + import org.springframework.util.LinkedMultiValueMap; + import org.springframework.util.MultiValueMap; + import org.springframework.web.client.RestTemplate; + + import com.google.gson.JsonElement; + import com.google.gson.JsonObject; + import com.google.gson.JsonParser; + import com.iemr.common.data.grievance.GrievanceDetails; + import com.iemr.common.data.grievance.GrievanceTransaction; + + import com.iemr.common.repository.grievance.GrievanceDataRepo; + 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; + +@Service +@PropertySource("classpath:application.properties") +public class GrievanceDataSyncImpl { + Logger logger = LoggerFactory.getLogger(this.getClass().getName()); + + RestTemplate restTemplateLogin = new RestTemplate(); + + @Autowired + private GrievanceDataRepo grievanceDataRepo; + + @Autowired + private GrievanceTransactionRepo grievanceTransactionRepo; + + @Autowired + private GrievanceFetchBenDetailsRepo grievanceFetchBenDetailsRepo; + + @Autowired + private LocationStateRepository locationStateRepository; + + @Value("${greivanceUserAuthenticate}") + private String grievanceUserAuthenticate; + + @Value("${updateGrievanceDetails}") + private String updateGrievanceDetails; + + @Value("${updateGrievanceTransactionDetails}") + private String updateGrievanceTransactionDetails; + + @Value("${grievanceUserName}") + private String grievanceUserName; + + @Value("${grievancePassword}") + private String grievancePassword; + + @Value("${grievanceDataSyncDuration}") + private String grievanceDataSyncDuration; + + private static String GRIEVANCE_AUTH_TOKEN; + private static Long GRIEVANCE_TOKEN_EXP; + + public List> dataSyncToGrievance(String grievanceAuthorization, String registeringUser, + String Authorization) { + + int count = 0; + List> responseData = new ArrayList<>(); + List grievanceDetailsListAS = null; + try { + // Loop to fetch data for multiple pages + while (count >= 0) { + RestTemplate restTemplate = new RestTemplate(); + + if (GRIEVANCE_AUTH_TOKEN != null && GRIEVANCE_TOKEN_EXP != null + && GRIEVANCE_TOKEN_EXP > System.currentTimeMillis()) { + // no need of calling auth API + } else { + // call method to generate Auth Token at Everwell end + generateGrievanceAuthToken(); + } + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + headers.add("user-agent", + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"); + headers.add("AUTHORIZATION", GRIEVANCE_AUTH_TOKEN); + + Date date = new Date(); + java.sql.Date sqlDate = new java.sql.Date(date.getTime()); + String text = sqlDate.toString(); + Timestamp currentDate = new Timestamp(sqlDate.getTime()); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(sqlDate); + calendar.add(Calendar.DATE, -Integer.parseInt(grievanceDataSyncDuration)); + Date beforeDate = calendar.getTime(); + Timestamp lastDate = new Timestamp(beforeDate.getTime()); + + // Request object + HttpEntity request = new HttpEntity(headers); + + // Call rest-template to call API to download master data for given table + ResponseEntity response = restTemplate.exchange(updateGrievanceDetails, HttpMethod.POST, request, + String.class); + + if (response != null && response.hasBody()) { + JSONObject obj = new JSONObject(response.getBody()); + if (obj != null && obj.has("data") && obj.has("statusCode") && obj.getInt("statusCode") == 200) { + logger.info("Grievance data details response: " + response.getBody()); + + String responseStr = response.getBody(); + JsonObject jsnOBJ = new JsonObject(); + JsonParser jsnParser = new JsonParser(); + JsonElement jsnElmnt = jsnParser.parse(responseStr); + jsnOBJ = jsnElmnt.getAsJsonObject(); + JsonObject grievanceJsonData = jsnOBJ.getAsJsonObject("data"); + + if (Integer.parseInt(jsnOBJ.get("TotalRecords").toString()) > 0) { + GrievanceDetails[] grievanceDetailsArray = InputMapper.gson().fromJson(jsnOBJ.get("Data").toString(), GrievanceDetails[].class); + List grievanceDetailsList = Arrays.asList(grievanceDetailsArray); + + // Fetch transaction details and integrate them with the grievance details +// for (GrievanceDetails grievance : grievanceDetailsList) { +// String complaintId = grievance.getGrievanceId(); +// String formattedComplaintId = complaintId.replace("\\/", "/"); +// grievance.setGrievanceId(formattedComplaintId); +// +// // Fetch related grievance transaction details +// List transactionDetailsList = fetchGrievanceTransactions(formattedComplaintId); +// +// if (transactionDetailsList != null && !transactionDetailsList.isEmpty()) { +// // Save transactions to the t_grievance_transaction table +// grievanceTransactionRepo.saveAll(transactionDetailsList); +// // Add the transaction list to the grievance object +// grievance.setGrievanceTransactionDetails(transactionDetailsList); +// } +// +// // Adding other grievance-related fields +// grievance.setSubjectOfComplaint(grievanceJsonData.get("subject").getAsString()); +// ArrayList lists = grievanceFetchBenDetailsRepo.findByComplaintId(formattedComplaintId); +// +// for (Object[] objects : lists) { +// if (objects != null && objects.length <= 4) { +// grievance.setComplaintId((String) objects[0]); +// grievance.setBeneficiaryRegId((Long) objects[1]); +// grievance.setBencallId((Long) objects[2]); +// grievance.setProviderServiceMapId((Integer) objects[3]); +// String state = locationStateRepository.findByStateIDForGrievance((Integer) objects[4]); +// grievance.setState(state); +// } +// } +// +// grievance.setAgentId(grievance.getAgentId()); +// grievance.setDeleted(grievance.getDeleted()); +// grievance.setCreatedBy(registeringUser); +// grievance.setProcessed('N'); +// grievance.setIsAllocated(false); +// grievance.setCallCounter(0); +// grievance.setRetryNeeded(true); +// } + + ////////////////////// + // Loop through the fetched grievance list and integrate transaction details + for (GrievanceDetails grievance : grievanceDetailsList) { + String complaintId = grievanceJsonData.get("complainId").getAsString(); + String formattedComplaintId = complaintId.replace("\\/", "/"); + + // Check if the complaintId is already present in the t_grievance_worklist table + boolean complaintExists = grievanceDataRepo.existsByComplaintId(formattedComplaintId); + if (complaintExists) { + throw new RuntimeException("Complaint ID " + formattedComplaintId + " already exists in the grievance worklist table."); + } + + + grievance.setComplaintId(formattedComplaintId); + + // Fetch related grievance transaction details + List transactionDetailsList = fetchGrievanceTransactions(formattedComplaintId); + + if (transactionDetailsList != null && !transactionDetailsList.isEmpty()) { + // Loop through each transaction and set individual properties + for (GrievanceTransaction transactionDetails : transactionDetailsList) { + + // Assuming transactionDetailsJson is the JSON object representing a single transaction from the API response + JsonObject transactionDetailsJson = grievanceJsonData.getAsJsonObject("transactionDetails"); // or another relevant path + + // Adding properties for each transaction detail + // transactionDetails.setComplaintId(formattedComplaintId); + // Assuming these fields are coming from your API response + transactionDetails.setActionTakenBy(transactionDetailsJson.get("actionTakenBy").getAsString()); + transactionDetails.setStatus(transactionDetailsJson.get("status").getAsString()); + transactionDetails.setFileName(transactionDetailsJson.has("fileName") ? transactionDetailsJson.get("fileName").getAsString() : null); + transactionDetails.setFileType(transactionDetailsJson.has("fileType") ? transactionDetailsJson.get("fileType").getAsString() : null); + transactionDetails.setRedressed(transactionDetailsJson.get("redressed").getAsString()); + transactionDetails.setCreatedAt(Timestamp.valueOf(transactionDetailsJson.get("createdAt").getAsString())); + transactionDetails.setUpdatedAt(Timestamp.valueOf(transactionDetailsJson.get("updatedAt").getAsString())); + transactionDetails.setComment(transactionDetailsJson.get("comment").getAsString()); + + // Save individual transaction detail in the t_grievance_transaction table + grievanceTransactionRepo.save(transactionDetails); + } + + // Add the transaction list to the grievance object + grievance.setGrievanceTransactionDetails(transactionDetailsList); + } + + // Adding other grievance-related fields (similar to the existing code) + grievance.setSubjectOfComplaint(grievanceJsonData.get("subject").getAsString()); + ArrayList lists = grievanceFetchBenDetailsRepo.findByComplaintId(formattedComplaintId); + + for (Object[] objects : lists) { + if (objects != null && objects.length <= 4) { + grievance.setComplaintId((String) objects[0]); + grievance.setBeneficiaryRegId((Long) objects[1]); + grievance.setBencallId((Long) objects[2]); + grievance.setProviderServiceMapId((Integer) objects[3]); + String state = locationStateRepository.findByStateIDForGrievance((Integer) objects[4]); + grievance.setState(state); + } + } + + // Setting remaining grievance properties (similar to the existing code) + grievance.setAgentId(grievance.getAgentId()); + grievance.setDeleted(grievance.getDeleted()); + grievance.setCreatedBy(registeringUser); + grievance.setProcessed('N'); + grievance.setIsAllocated(false); + grievance.setCallCounter(0); + grievance.setRetryNeeded(true); + } + + // Save the grievance details to the t_grievance table + grievanceDetailsListAS = (List) grievanceDataRepo.saveAll(grievanceDetailsList); + + // Combine grievance and transaction data for response + + for (GrievanceDetails grievance : grievanceDetailsListAS) { + Map combinedData = new HashMap<>(); + combinedData.put("complaintID", grievance.getGrievanceId()); + combinedData.put("subjectOfComplaint", grievance.getSubjectOfComplaint()); + combinedData.put("complaint", grievance.getComplaint()); + combinedData.put("beneficiaryRegID", grievance.getBeneficiaryRegId()); + combinedData.put("providerServiceMapId", grievance.getProviderServiceMapId()); + // combinedData.put("firstName", grievance.getFirstName()); + // combinedData.put("lastName", grievance.getLastName()); + combinedData.put("primaryNumber", grievance.getPrimaryNumber()); + + // Add transaction data + List> transactions = new ArrayList<>(); + for (GrievanceTransaction transaction : grievance.getGrievanceTransactionDetails()) { + Map transactionData = new HashMap<>(); + transactionData.put("actionTakenBy", transaction.getActionTakenBy()); + transactionData.put("status", transaction.getStatus()); + transactionData.put("fileName", transaction.getFileName()); + transactionData.put("fileType", transaction.getFileType()); + transactionData.put("redressed", transaction.getRedressed()); + transactionData.put("createdAt", transaction.getCreatedAt().toString()); + transactionData.put("updatedAt", transaction.getUpdatedAt().toString()); + transactionData.put("comment", transaction.getComment()); + transactions.add(transactionData); + } + + combinedData.put("transaction", transactions); + combinedData.put("severity", grievance.getSeverety()); + combinedData.put("state", grievance.getState()); + combinedData.put("agentId", grievance.getAgentId()); + combinedData.put("deleted", grievance.getDeleted()); + combinedData.put("createdBy", grievance.getCreatedBy()); + combinedData.put("createdDate", grievance.getCreatedDate()); + combinedData.put("lastModDate", grievance.getLastModDate()); + combinedData.put("isCompleted", grievance.getIsCompleted()); + // combinedData.put("gender", grievance.getGender()); + // combinedData.put("district", grievance.getDistrict()); + // combinedData.put("beneficiaryID", grievance.getBeneficiaryId()); + // combinedData.put("age", grievance.getAge()); + combinedData.put("retryNeeded", grievance.getRetryNeeded()); + combinedData.put("callCounter", grievance.getCallCounter()); + // combinedData.put("lastCall", grievance.getLastCall()); + + responseData.add(combinedData); + } + + + // Return the combined response as required + // return responseData; + + } else { + logger.info("No records found for page = " + count); + count = -1; + } + } + } + } + } catch (Exception e) { + logger.error("Error in saving data into t_grievanceworklist: ", e); + } + return responseData; + } + + private List fetchGrievanceTransactions(String complaintId) { + List transactionDetailsList = new ArrayList<>(); + try { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + headers.add("user-agent", + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"); + headers.add("AUTHORIZATION", GRIEVANCE_AUTH_TOKEN); + + HttpEntity request = new HttpEntity(headers); + RestTemplate restTemplate = new RestTemplate(); + ResponseEntity response = restTemplate.exchange(updateGrievanceTransactionDetails, HttpMethod.POST, request, String.class); + + if (response != null && response.hasBody()) { + JSONObject obj = new JSONObject(response.getBody()); + if (obj != null && obj.has("data") && obj.has("statusCode") && obj.getInt("statusCode") == 200) { + JsonObject jsnOBJ = new JsonObject(); + JsonParser jsnParser = new JsonParser(); + JsonElement jsnElmnt = jsnParser.parse(response.getBody()); + jsnOBJ = jsnElmnt.getAsJsonObject(); + GrievanceTransaction[] transactionDetailsArray = InputMapper.gson().fromJson(jsnOBJ.get("Data").toString(), GrievanceTransaction[].class); + transactionDetailsList = Arrays.asList(transactionDetailsArray); + } + } + } catch (Exception e) { + logger.error("Error fetching grievance transaction details for complaintId " + complaintId, e); + } + return transactionDetailsList; + } + + private void generateGrievanceAuthToken() { + String Authorization = ""; + String registeringUser = ""; + MultiValueMap requestData = new LinkedMultiValueMap(); + requestData.add("username", grievanceUserName); + requestData.add("password", grievancePassword); + requestData.add("grant_type", "password"); + HttpHeaders httpHeaders = new HttpHeaders(); + httpHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + httpHeaders.add("user-agent", + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"); + + HttpEntity> httpRequestEntity = new HttpEntity>( + requestData, httpHeaders); + ResponseEntity responseEntity = restTemplateLogin.exchange(grievanceUserAuthenticate, HttpMethod.POST, + httpRequestEntity, String.class); + + if (responseEntity != null && responseEntity.getStatusCodeValue() == 200 && responseEntity.hasBody()) { + String responseBody = responseEntity.getBody(); + JsonObject jsnOBJ = new JsonObject(); + JsonParser jsnParser = new JsonParser(); + JsonElement jsnElmnt = jsnParser.parse(responseBody); + jsnOBJ = jsnElmnt.getAsJsonObject(); + GRIEVANCE_AUTH_TOKEN = jsnOBJ.get("token_type").getAsString() + " " + + jsnOBJ.get("access_token").getAsString(); + + JsonObject grievanceLoginJsonData = jsnOBJ.getAsJsonObject("data"); + Authorization = grievanceLoginJsonData.get("key").getAsString(); + registeringUser = grievanceLoginJsonData.get("userName").getAsString(); + + logger.info("Auth key generated at : " + System.currentTimeMillis() + ", Key : " + GRIEVANCE_AUTH_TOKEN); + + Date date = new Date(); + java.sql.Date sqlDate = new java.sql.Date(date.getTime()); + Calendar grievanceCalendar = Calendar.getInstance(); + grievanceCalendar.setTime(sqlDate); + grievanceCalendar.add(Calendar.DATE, 29); + Date grievanceTokenEndDate = grievanceCalendar.getTime(); + // setting Token expiry - 29 days + GRIEVANCE_TOKEN_EXP = grievanceTokenEndDate.getTime(); + + int count = 3; + while (count > 0) { + List> savedGrievanceData = dataSyncToGrievance(GRIEVANCE_AUTH_TOKEN, registeringUser, + Authorization); + if (savedGrievanceData != null) + break; + else + count--; + } + } + } + } + + From 0a90728019942e7066e6feedf9cd07d03bba8c92 Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Thu, 16 Jan 2025 04:23:52 -0800 Subject: [PATCH 09/23] adding code rabbit code suggestions --- .../data/grievance/GrievanceDetails.java | 6 ++++++ .../data/grievance/GrievanceTransaction.java | 4 ++++ .../GrievanceFetchBenDetailsRepo.java | 4 ++-- .../location/LocationStateRepository.java | 2 +- .../service/grievance/GrievanceDataSync.java | 3 ++- .../grievance/GrievanceDataSyncImpl.java | 21 ++++++++++++------- 6 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/iemr/common/data/grievance/GrievanceDetails.java b/src/main/java/com/iemr/common/data/grievance/GrievanceDetails.java index 70d1c15..2e26201 100644 --- a/src/main/java/com/iemr/common/data/grievance/GrievanceDetails.java +++ b/src/main/java/com/iemr/common/data/grievance/GrievanceDetails.java @@ -3,13 +3,17 @@ import java.sql.Timestamp; import java.util.List; +import com.fasterxml.jackson.annotation.JsonManagedReference; import com.google.gson.annotations.Expose; + +import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; import jakarta.persistence.Table; import lombok.Data; @@ -137,6 +141,8 @@ public class GrievanceDetails { @Column(name = "isCompleted") private Boolean isCompleted = false; + @OneToMany(mappedBy = "grievanceDetails", cascade = CascadeType.ALL, fetch = FetchType.LAZY) + @JsonManagedReference private List grievanceTransactionDetails; diff --git a/src/main/java/com/iemr/common/data/grievance/GrievanceTransaction.java b/src/main/java/com/iemr/common/data/grievance/GrievanceTransaction.java index e734f16..c6ebcd8 100644 --- a/src/main/java/com/iemr/common/data/grievance/GrievanceTransaction.java +++ b/src/main/java/com/iemr/common/data/grievance/GrievanceTransaction.java @@ -85,6 +85,10 @@ public class GrievanceTransaction { @Column(name = "LastModDate") @Expose private Date lastModDate; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "gwid", insertable = false, updatable = false) + private GrievanceDetails grievanceDetails; // Getters and Setters diff --git a/src/main/java/com/iemr/common/repository/grievance/GrievanceFetchBenDetailsRepo.java b/src/main/java/com/iemr/common/repository/grievance/GrievanceFetchBenDetailsRepo.java index 09ce5a8..19b470f 100644 --- a/src/main/java/com/iemr/common/repository/grievance/GrievanceFetchBenDetailsRepo.java +++ b/src/main/java/com/iemr/common/repository/grievance/GrievanceFetchBenDetailsRepo.java @@ -13,8 +13,8 @@ @Repository public interface GrievanceFetchBenDetailsRepo extends CrudRepository { - @Query("select requestID, benCallID, beneficiaryRegID, providerServiceMapID, stateID " - + " from FeedbackDetails where requestID = :requestID order by requestID desc") + @Query("select f.requestID, f.benCallID, f.beneficiaryRegID, f.providerServiceMapID, f.stateID " + + " from FeedbackDetails f where f.requestID = :requestID order by f.requestID desc") public ArrayList findByComplaintId(@Param("requestID") String requestID); } diff --git a/src/main/java/com/iemr/common/repository/location/LocationStateRepository.java b/src/main/java/com/iemr/common/repository/location/LocationStateRepository.java index 0555a46..b6c7e8f 100644 --- a/src/main/java/com/iemr/common/repository/location/LocationStateRepository.java +++ b/src/main/java/com/iemr/common/repository/location/LocationStateRepository.java @@ -51,7 +51,7 @@ public interface LocationStateRepository extends CrudRepository States findByStateID(Integer stateID); - @Query("select state from States state where state.stateID = :id") + @Query("select state.state from States state where state.stateID = :id") public String findByStateIDForGrievance(@Param("id") int id); diff --git a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSync.java b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSync.java index 188e1cb..9f98da4 100644 --- a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSync.java +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSync.java @@ -4,5 +4,6 @@ import java.util.Map; public interface GrievanceDataSync { - public List> dataSyncToGrievance(); + public List> dataSyncToGrievance(String grievanceAuthorization, String registeringUser, + String Authorization); } diff --git a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java index 8b3d384..ba7b273 100644 --- a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java @@ -41,7 +41,7 @@ @Service @PropertySource("classpath:application.properties") -public class GrievanceDataSyncImpl { +public class GrievanceDataSyncImpl implements GrievanceDataSync { Logger logger = LoggerFactory.getLogger(this.getClass().getName()); RestTemplate restTemplateLogin = new RestTemplate(); @@ -76,9 +76,10 @@ public class GrievanceDataSyncImpl { @Value("${grievanceDataSyncDuration}") private String grievanceDataSyncDuration; - private static String GRIEVANCE_AUTH_TOKEN; - private static Long GRIEVANCE_TOKEN_EXP; + private String GRIEVANCE_AUTH_TOKEN; + private Long GRIEVANCE_TOKEN_EXP; + public List> dataSyncToGrievance(String grievanceAuthorization, String registeringUser, String Authorization) { @@ -124,7 +125,7 @@ public List> dataSyncToGrievance(String grievanceAuthorizati if (response != null && response.hasBody()) { JSONObject obj = new JSONObject(response.getBody()); if (obj != null && obj.has("data") && obj.has("statusCode") && obj.getInt("statusCode") == 200) { - logger.info("Grievance data details response: " + response.getBody()); + logger.info("Grievance data details response received successfully "); String responseStr = response.getBody(); JsonObject jsnOBJ = new JsonObject(); @@ -193,7 +194,7 @@ public List> dataSyncToGrievance(String grievanceAuthorizati grievance.setComplaintId(formattedComplaintId); // Fetch related grievance transaction details - List transactionDetailsList = fetchGrievanceTransactions(formattedComplaintId); + List transactionDetailsList = fetchGrievanceTransactions(grievance.getGrievanceId()); if (transactionDetailsList != null && !transactionDetailsList.isEmpty()) { // Loop through each transaction and set individual properties @@ -315,7 +316,7 @@ public List> dataSyncToGrievance(String grievanceAuthorizati return responseData; } - private List fetchGrievanceTransactions(String complaintId) { + private List fetchGrievanceTransactions(Long grievanceId) { List transactionDetailsList = new ArrayList<>(); try { HttpHeaders headers = new HttpHeaders(); @@ -326,8 +327,12 @@ private List fetchGrievanceTransactions(String complaintId HttpEntity request = new HttpEntity(headers); RestTemplate restTemplate = new RestTemplate(); - ResponseEntity response = restTemplate.exchange(updateGrievanceTransactionDetails, HttpMethod.POST, request, String.class); + // ResponseEntity response = restTemplate.exchange(updateGrievanceTransactionDetails, HttpMethod.POST, request, String.class); + + ResponseEntity response = restTemplate.exchange(updateGrievanceTransactionDetails + grievanceId, HttpMethod.POST, request, String.class); + + if (response != null && response.hasBody()) { JSONObject obj = new JSONObject(response.getBody()); if (obj != null && obj.has("data") && obj.has("statusCode") && obj.getInt("statusCode") == 200) { @@ -340,7 +345,7 @@ private List fetchGrievanceTransactions(String complaintId } } } catch (Exception e) { - logger.error("Error fetching grievance transaction details for complaintId " + complaintId, e); + logger.error("Error fetching grievance transaction details for grievanceId " + grievanceId, e); } return transactionDetailsList; } From ea9ff9e1cd4b1ca5268b8ae09691372f3dad3501 Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Thu, 16 Jan 2025 04:46:03 -0800 Subject: [PATCH 10/23] adding code rabbit suggestions --- .../com/iemr/common/data/grievance/GrievanceTransaction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/iemr/common/data/grievance/GrievanceTransaction.java b/src/main/java/com/iemr/common/data/grievance/GrievanceTransaction.java index c6ebcd8..37269a2 100644 --- a/src/main/java/com/iemr/common/data/grievance/GrievanceTransaction.java +++ b/src/main/java/com/iemr/common/data/grievance/GrievanceTransaction.java @@ -228,7 +228,7 @@ public void setStatus(String status) { this.status = status; } - public String comment( ) { + public String getComment( ) { return comment; } From 8825473c48d5728dfb84c1a476c9e1fb4195a1c5 Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Thu, 16 Jan 2025 04:55:27 -0800 Subject: [PATCH 11/23] code rabbit suggested changes to Model classes --- .../data/grievance/GrievanceDetails.java | 34 ++++++++++--------- .../data/grievance/GrievanceTransaction.java | 6 ++++ 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/iemr/common/data/grievance/GrievanceDetails.java b/src/main/java/com/iemr/common/data/grievance/GrievanceDetails.java index 2e26201..02cdc6a 100644 --- a/src/main/java/com/iemr/common/data/grievance/GrievanceDetails.java +++ b/src/main/java/com/iemr/common/data/grievance/GrievanceDetails.java @@ -15,6 +15,7 @@ import jakarta.persistence.Id; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; +import jakarta.validation.constraints.NotBlank; import lombok.Data; @Entity @@ -62,6 +63,7 @@ public class GrievanceDetails { @Expose @Column(name = "Severety") + @NotBlank(message = "Severety is required") private String severety; @Expose @@ -118,17 +120,17 @@ public class GrievanceDetails { @Expose @Column(name = "VanSerialNo") - private Integer VanSerialNo; + private Integer vanSerialNo; @Expose @Column(name = "VanID") - private Integer VanID; + private Integer vanID; @Expose @Column(name = "VehicalNo") - private String VehicalNo; + private String vehicalNo; @Expose @Column(name = "ParkingPlaceID") - private Integer ParkingPlaceID; + private Integer parkingPlaceID; @Expose @Column(name = "SyncedBy") private String syncedBy; @@ -177,10 +179,10 @@ public GrievanceDetails(Long gwid, Long grievanceId, Long beneficiaryRegID, Long this.createdDate = createdDate; this.modifiedBy = modifiedBy; this.lastModDate = lastModDate; - this.VanSerialNo = vanSerialNo; - this.VanID = vanID; - this.VehicalNo = vehicalNo; - this.ParkingPlaceID = parkingPlaceID; + this.vanSerialNo = vanSerialNo; + this.vanID = vanID; + this.vehicalNo = vehicalNo; + this.parkingPlaceID = parkingPlaceID; this.syncedBy = syncedBy; this.syncedDate = syncedDate; this.isCompleted = isCompleted; @@ -372,35 +374,35 @@ public void setLastModDate(Timestamp lastModDate) { } public Integer getVanSerialNo() { - return VanSerialNo; + return vanSerialNo; } public void setVanSerialNo(Integer vanSerialNo) { - this.VanSerialNo = vanSerialNo; + this.vanSerialNo = vanSerialNo; } public Integer getVanId() { - return VanID; + return vanID; } public void setVanId(Integer vanId) { - this.VanID = vanId; + this.vanID = vanId; } public String getVehicleNo() { - return VehicalNo; + return vehicalNo; } public void setVehicleNo(String vehicleNo) { - this.VehicalNo = vehicleNo; + this.vehicalNo = vehicleNo; } public Integer getParkingPlaceId() { - return ParkingPlaceID; + return parkingPlaceID; } public void setParkingPlaceId(Integer parkingPlaceId) { - this.ParkingPlaceID = parkingPlaceId; + this.parkingPlaceID = parkingPlaceId; } public String getSyncedBy() { diff --git a/src/main/java/com/iemr/common/data/grievance/GrievanceTransaction.java b/src/main/java/com/iemr/common/data/grievance/GrievanceTransaction.java index 37269a2..b559339 100644 --- a/src/main/java/com/iemr/common/data/grievance/GrievanceTransaction.java +++ b/src/main/java/com/iemr/common/data/grievance/GrievanceTransaction.java @@ -5,6 +5,8 @@ import com.google.gson.annotations.Expose; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; import lombok.Data; import java.util.Date; @@ -25,10 +27,14 @@ public class GrievanceTransaction { @Column(name = "FileName", nullable = false, length = 500) @Expose + @NotBlank(message = "File name is required") + @Size(max = 500, message = "File name cannot exceed 500 characters") private String fileName; @Column(name = "FileType", nullable = false, length = 300) @Expose + @NotBlank(message = "File name is required") + @Size(max = 300, message = "File type cannot exceed 300 characters") private String fileType; @Column(name = "Redressed", nullable = false) From 2d639c4fcaa2a9c42c48238b0ce8e0864170074a Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Thu, 16 Jan 2025 06:01:13 -0800 Subject: [PATCH 12/23] adding sonar quality changes --- .../common/config/quartz/QuartzConfig.java | 2 +- .../quartz/ScheduleForGrievanceDataSync.java | 11 ++- .../data/grievance/GrievanceDetails.java | 8 +- .../GrievanceFetchBenDetailsRepo.java | 2 + .../service/grievance/GrievanceDataSync.java | 3 +- .../grievance/GrievanceDataSyncImpl.java | 79 ++++++------------- 6 files changed, 40 insertions(+), 65 deletions(-) diff --git a/src/main/java/com/iemr/common/config/quartz/QuartzConfig.java b/src/main/java/com/iemr/common/config/quartz/QuartzConfig.java index 468e9a4..ac359f4 100644 --- a/src/main/java/com/iemr/common/config/quartz/QuartzConfig.java +++ b/src/main/java/com/iemr/common/config/quartz/QuartzConfig.java @@ -170,7 +170,7 @@ public CronTriggerFactoryBean processMQTriggerForEmail() { Boolean startJob = ConfigProperties.getBoolean("start-email-scheduler"); CronTriggerFactoryBean cronTriggerFactoryBean = new CronTriggerFactoryBean(); String scheduleConfig = quartzJobDefaultSchedule; - if (startJob) { + if (Boolean.TRUE.equals(startJob)) { scheduleConfig = ConfigProperties.getPropertyByName("cron-scheduler-email"); } cronTriggerFactoryBean.setJobDetail(processMQJobForEmail().getObject()); diff --git a/src/main/java/com/iemr/common/config/quartz/ScheduleForGrievanceDataSync.java b/src/main/java/com/iemr/common/config/quartz/ScheduleForGrievanceDataSync.java index f1d5a7d..e4eedf0 100644 --- a/src/main/java/com/iemr/common/config/quartz/ScheduleForGrievanceDataSync.java +++ b/src/main/java/com/iemr/common/config/quartz/ScheduleForGrievanceDataSync.java @@ -17,15 +17,20 @@ public class ScheduleForGrievanceDataSync implements Job { private final Logger logger = LoggerFactory.getLogger(this.getClass().getName()); + + private final GrievanceDataSync grievanceDataSync; + @Autowired - GrievanceDataSync grievanceDataSync; + 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()); + logger.info("Started job for grievance data sync " , arg0.getClass().getName()); grievanceDataSync.dataSyncToGrievance(); - logger.info("Completed job for grievance data sync " + arg0.getClass().getName()); + logger.info("Completed job for grievance data sync " , arg0.getClass().getName()); } diff --git a/src/main/java/com/iemr/common/data/grievance/GrievanceDetails.java b/src/main/java/com/iemr/common/data/grievance/GrievanceDetails.java index 02cdc6a..160d0d8 100644 --- a/src/main/java/com/iemr/common/data/grievance/GrievanceDetails.java +++ b/src/main/java/com/iemr/common/data/grievance/GrievanceDetails.java @@ -102,7 +102,7 @@ public class GrievanceDetails { @Expose @Column(name = "Processed") - private Character Processed = 'N'; + private Character processed = 'N'; @Column(name = "CreatedBy") @Expose @@ -174,7 +174,7 @@ public GrievanceDetails(Long gwid, Long grievanceId, Long beneficiaryRegID, Long this.isRegistered = isRegistered; this.callCounter = callCounter; this.deleted = deleted; - this.Processed = processed; + this.processed = processed; this.createdBy = createdBy; this.createdDate = createdDate; this.modifiedBy = modifiedBy; @@ -334,11 +334,11 @@ public void setDeleted(Boolean deleted) { } public Character getProcessed() { - return Processed; + return processed; } public void setProcessed(Character processed) { - this.Processed = processed; + this.processed = processed; } public String getCreatedBy() { diff --git a/src/main/java/com/iemr/common/repository/grievance/GrievanceFetchBenDetailsRepo.java b/src/main/java/com/iemr/common/repository/grievance/GrievanceFetchBenDetailsRepo.java index 19b470f..1a2a91d 100644 --- a/src/main/java/com/iemr/common/repository/grievance/GrievanceFetchBenDetailsRepo.java +++ b/src/main/java/com/iemr/common/repository/grievance/GrievanceFetchBenDetailsRepo.java @@ -1,6 +1,8 @@ package com.iemr.common.repository.grievance; + import java.util.ArrayList; +import java.util.List; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; diff --git a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSync.java b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSync.java index 9f98da4..188e1cb 100644 --- a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSync.java +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSync.java @@ -4,6 +4,5 @@ import java.util.Map; public interface GrievanceDataSync { - public List> dataSyncToGrievance(String grievanceAuthorization, String registeringUser, - String Authorization); + public List> dataSyncToGrievance(); } diff --git a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java index ba7b273..f12ddda 100644 --- a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java @@ -46,17 +46,22 @@ public class GrievanceDataSyncImpl implements GrievanceDataSync { RestTemplate restTemplateLogin = new RestTemplate(); - @Autowired - private GrievanceDataRepo grievanceDataRepo; - - @Autowired - private GrievanceTransactionRepo grievanceTransactionRepo; - - @Autowired - private GrievanceFetchBenDetailsRepo grievanceFetchBenDetailsRepo; + private final GrievanceDataRepo grievanceDataRepo; + private final GrievanceTransactionRepo grievanceTransactionRepo; + private final GrievanceFetchBenDetailsRepo grievanceFetchBenDetailsRepo; + private final LocationStateRepository locationStateRepository; + // Constructor-based injection @Autowired - private LocationStateRepository locationStateRepository; + public GrievanceDataSyncImpl(GrievanceDataRepo grievanceDataRepo, + GrievanceTransactionRepo grievanceTransactionRepo, + GrievanceFetchBenDetailsRepo grievanceFetchBenDetailsRepo, + LocationStateRepository locationStateRepository) { + this.grievanceDataRepo = grievanceDataRepo; + this.grievanceTransactionRepo = grievanceTransactionRepo; + this.grievanceFetchBenDetailsRepo = grievanceFetchBenDetailsRepo; + this.locationStateRepository = locationStateRepository; + } @Value("${greivanceUserAuthenticate}") private String grievanceUserAuthenticate; @@ -80,10 +85,13 @@ public class GrievanceDataSyncImpl implements GrievanceDataSync { private Long GRIEVANCE_TOKEN_EXP; - public List> dataSyncToGrievance(String grievanceAuthorization, String registeringUser, - String Authorization) { +// public List> dataSyncToGrievance(String grievanceAuthorization, String registeringUser, +// String Authorization) { + public List> dataSyncToGrievance() { + int count = 0; + String registeringUser = ""; List> responseData = new ArrayList<>(); List grievanceDetailsListAS = null; try { @@ -134,49 +142,12 @@ public List> dataSyncToGrievance(String grievanceAuthorizati jsnOBJ = jsnElmnt.getAsJsonObject(); JsonObject grievanceJsonData = jsnOBJ.getAsJsonObject("data"); + registeringUser = grievanceJsonData.get("userName").getAsString(); + if (Integer.parseInt(jsnOBJ.get("TotalRecords").toString()) > 0) { GrievanceDetails[] grievanceDetailsArray = InputMapper.gson().fromJson(jsnOBJ.get("Data").toString(), GrievanceDetails[].class); List grievanceDetailsList = Arrays.asList(grievanceDetailsArray); - // Fetch transaction details and integrate them with the grievance details -// for (GrievanceDetails grievance : grievanceDetailsList) { -// String complaintId = grievance.getGrievanceId(); -// String formattedComplaintId = complaintId.replace("\\/", "/"); -// grievance.setGrievanceId(formattedComplaintId); -// -// // Fetch related grievance transaction details -// List transactionDetailsList = fetchGrievanceTransactions(formattedComplaintId); -// -// if (transactionDetailsList != null && !transactionDetailsList.isEmpty()) { -// // Save transactions to the t_grievance_transaction table -// grievanceTransactionRepo.saveAll(transactionDetailsList); -// // Add the transaction list to the grievance object -// grievance.setGrievanceTransactionDetails(transactionDetailsList); -// } -// -// // Adding other grievance-related fields -// grievance.setSubjectOfComplaint(grievanceJsonData.get("subject").getAsString()); -// ArrayList lists = grievanceFetchBenDetailsRepo.findByComplaintId(formattedComplaintId); -// -// for (Object[] objects : lists) { -// if (objects != null && objects.length <= 4) { -// grievance.setComplaintId((String) objects[0]); -// grievance.setBeneficiaryRegId((Long) objects[1]); -// grievance.setBencallId((Long) objects[2]); -// grievance.setProviderServiceMapId((Integer) objects[3]); -// String state = locationStateRepository.findByStateIDForGrievance((Integer) objects[4]); -// grievance.setState(state); -// } -// } -// -// grievance.setAgentId(grievance.getAgentId()); -// grievance.setDeleted(grievance.getDeleted()); -// grievance.setCreatedBy(registeringUser); -// grievance.setProcessed('N'); -// grievance.setIsAllocated(false); -// grievance.setCallCounter(0); -// grievance.setRetryNeeded(true); -// } ////////////////////// // Loop through the fetched grievance list and integrate transaction details @@ -327,7 +298,6 @@ private List fetchGrievanceTransactions(Long grievanceId) HttpEntity request = new HttpEntity(headers); RestTemplate restTemplate = new RestTemplate(); - // ResponseEntity response = restTemplate.exchange(updateGrievanceTransactionDetails, HttpMethod.POST, request, String.class); ResponseEntity response = restTemplate.exchange(updateGrievanceTransactionDetails + grievanceId, HttpMethod.POST, request, String.class); @@ -351,7 +321,7 @@ private List fetchGrievanceTransactions(Long grievanceId) } private void generateGrievanceAuthToken() { - String Authorization = ""; + String authorization = ""; String registeringUser = ""; MultiValueMap requestData = new LinkedMultiValueMap(); requestData.add("username", grievanceUserName); @@ -377,7 +347,7 @@ private void generateGrievanceAuthToken() { + jsnOBJ.get("access_token").getAsString(); JsonObject grievanceLoginJsonData = jsnOBJ.getAsJsonObject("data"); - Authorization = grievanceLoginJsonData.get("key").getAsString(); + authorization = grievanceLoginJsonData.get("key").getAsString(); registeringUser = grievanceLoginJsonData.get("userName").getAsString(); logger.info("Auth key generated at : " + System.currentTimeMillis() + ", Key : " + GRIEVANCE_AUTH_TOKEN); @@ -393,8 +363,7 @@ private void generateGrievanceAuthToken() { int count = 3; while (count > 0) { - List> savedGrievanceData = dataSyncToGrievance(GRIEVANCE_AUTH_TOKEN, registeringUser, - Authorization); + List> savedGrievanceData = dataSyncToGrievance(); if (savedGrievanceData != null) break; else From b0e039b57467606e030d18e0e3cf88de8b42e3da Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Thu, 16 Jan 2025 06:47:00 -0800 Subject: [PATCH 13/23] adding sonar quality code suggestions --- .../quartz/ScheduleForGrievanceDataSync.java | 4 ++-- .../GrievanceFetchBenDetailsRepo.java | 1 - .../grievance/GrievanceDataSyncImpl.java | 24 +++++++------------ 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/iemr/common/config/quartz/ScheduleForGrievanceDataSync.java b/src/main/java/com/iemr/common/config/quartz/ScheduleForGrievanceDataSync.java index e4eedf0..8843738 100644 --- a/src/main/java/com/iemr/common/config/quartz/ScheduleForGrievanceDataSync.java +++ b/src/main/java/com/iemr/common/config/quartz/ScheduleForGrievanceDataSync.java @@ -28,9 +28,9 @@ public ScheduleForGrievanceDataSync(GrievanceDataSync grievanceDataSync) { @Override public void execute(JobExecutionContext arg0) throws JobExecutionException { - logger.info("Started job for grievance data sync " , arg0.getClass().getName()); + logger.info("Started job for grievance data sync {}", arg0.getClass().getName()); grievanceDataSync.dataSyncToGrievance(); - logger.info("Completed job for grievance data sync " , arg0.getClass().getName()); + logger.info("Completed job for grievance data sync {}" , arg0.getClass().getName()); } diff --git a/src/main/java/com/iemr/common/repository/grievance/GrievanceFetchBenDetailsRepo.java b/src/main/java/com/iemr/common/repository/grievance/GrievanceFetchBenDetailsRepo.java index 1a2a91d..2d8c6c4 100644 --- a/src/main/java/com/iemr/common/repository/grievance/GrievanceFetchBenDetailsRepo.java +++ b/src/main/java/com/iemr/common/repository/grievance/GrievanceFetchBenDetailsRepo.java @@ -2,7 +2,6 @@ import java.util.ArrayList; -import java.util.List; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; diff --git a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java index f12ddda..0053917 100644 --- a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java @@ -46,6 +46,10 @@ public class GrievanceDataSyncImpl implements GrievanceDataSync { RestTemplate restTemplateLogin = new RestTemplate(); + private static final String USER_AGENT_HEADER = "user-agent"; + private static final String USER_AGENT_VALUE = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"; + private static final String STATUS_CODE = "statusCode"; + private final GrievanceDataRepo grievanceDataRepo; private final GrievanceTransactionRepo grievanceTransactionRepo; private final GrievanceFetchBenDetailsRepo grievanceFetchBenDetailsRepo; @@ -85,9 +89,6 @@ public GrievanceDataSyncImpl(GrievanceDataRepo grievanceDataRepo, private Long GRIEVANCE_TOKEN_EXP; -// public List> dataSyncToGrievance(String grievanceAuthorization, String registeringUser, -// String Authorization) { - public List> dataSyncToGrievance() { int count = 0; @@ -109,19 +110,14 @@ public List> dataSyncToGrievance() { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); - headers.add("user-agent", - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"); + headers.add(USER_AGENT_HEADER, USER_AGENT_VALUE); headers.add("AUTHORIZATION", GRIEVANCE_AUTH_TOKEN); Date date = new Date(); java.sql.Date sqlDate = new java.sql.Date(date.getTime()); - String text = sqlDate.toString(); - Timestamp currentDate = new Timestamp(sqlDate.getTime()); Calendar calendar = Calendar.getInstance(); calendar.setTime(sqlDate); calendar.add(Calendar.DATE, -Integer.parseInt(grievanceDataSyncDuration)); - Date beforeDate = calendar.getTime(); - Timestamp lastDate = new Timestamp(beforeDate.getTime()); // Request object HttpEntity request = new HttpEntity(headers); @@ -132,7 +128,7 @@ public List> dataSyncToGrievance() { if (response != null && response.hasBody()) { JSONObject obj = new JSONObject(response.getBody()); - if (obj != null && obj.has("data") && obj.has("statusCode") && obj.getInt("statusCode") == 200) { + if (obj != null && obj.has("data") && obj.has(STATUS_CODE) && obj.getInt(STATUS_CODE) == 200) { logger.info("Grievance data details response received successfully "); String responseStr = response.getBody(); @@ -292,8 +288,7 @@ private List fetchGrievanceTransactions(Long grievanceId) try { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); - headers.add("user-agent", - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"); + headers.add(USER_AGENT_HEADER, USER_AGENT_VALUE); headers.add("AUTHORIZATION", GRIEVANCE_AUTH_TOKEN); HttpEntity request = new HttpEntity(headers); @@ -305,7 +300,7 @@ private List fetchGrievanceTransactions(Long grievanceId) if (response != null && response.hasBody()) { JSONObject obj = new JSONObject(response.getBody()); - if (obj != null && obj.has("data") && obj.has("statusCode") && obj.getInt("statusCode") == 200) { + if (obj != null && obj.has("data") && obj.has(STATUS_CODE) && obj.getInt(STATUS_CODE) == 200) { JsonObject jsnOBJ = new JsonObject(); JsonParser jsnParser = new JsonParser(); JsonElement jsnElmnt = jsnParser.parse(response.getBody()); @@ -329,8 +324,7 @@ private void generateGrievanceAuthToken() { requestData.add("grant_type", "password"); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED); - httpHeaders.add("user-agent", - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"); + httpHeaders.add(USER_AGENT_HEADER, USER_AGENT_VALUE); HttpEntity> httpRequestEntity = new HttpEntity>( requestData, httpHeaders); From 9831500c2df43daf24ed10fb1735be92993392e8 Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Thu, 16 Jan 2025 18:53:58 -0800 Subject: [PATCH 14/23] adding sonar quality check suggestions --- .../grievance/GrievanceDataSyncImpl.java | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java index 0053917..4685640 100644 --- a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java @@ -171,7 +171,6 @@ public List> dataSyncToGrievance() { JsonObject transactionDetailsJson = grievanceJsonData.getAsJsonObject("transactionDetails"); // or another relevant path // Adding properties for each transaction detail - // transactionDetails.setComplaintId(formattedComplaintId); // Assuming these fields are coming from your API response transactionDetails.setActionTakenBy(transactionDetailsJson.get("actionTakenBy").getAsString()); transactionDetails.setStatus(transactionDetailsJson.get("status").getAsString()); @@ -227,8 +226,7 @@ public List> dataSyncToGrievance() { combinedData.put("complaint", grievance.getComplaint()); combinedData.put("beneficiaryRegID", grievance.getBeneficiaryRegId()); combinedData.put("providerServiceMapId", grievance.getProviderServiceMapId()); - // combinedData.put("firstName", grievance.getFirstName()); - // combinedData.put("lastName", grievance.getLastName()); + combinedData.put("primaryNumber", grievance.getPrimaryNumber()); // Add transaction data @@ -255,23 +253,18 @@ public List> dataSyncToGrievance() { combinedData.put("createdDate", grievance.getCreatedDate()); combinedData.put("lastModDate", grievance.getLastModDate()); combinedData.put("isCompleted", grievance.getIsCompleted()); - // combinedData.put("gender", grievance.getGender()); - // combinedData.put("district", grievance.getDistrict()); - // combinedData.put("beneficiaryID", grievance.getBeneficiaryId()); - // combinedData.put("age", grievance.getAge()); + combinedData.put("retryNeeded", grievance.getRetryNeeded()); combinedData.put("callCounter", grievance.getCallCounter()); - // combinedData.put("lastCall", grievance.getLastCall()); responseData.add(combinedData); } // Return the combined response as required - // return responseData; } else { - logger.info("No records found for page = " + count); + logger.info("No records found for page = {}" , count); count = -1; } } @@ -316,8 +309,7 @@ private List fetchGrievanceTransactions(Long grievanceId) } private void generateGrievanceAuthToken() { - String authorization = ""; - String registeringUser = ""; + MultiValueMap requestData = new LinkedMultiValueMap(); requestData.add("username", grievanceUserName); requestData.add("password", grievancePassword); @@ -341,10 +333,9 @@ private void generateGrievanceAuthToken() { + jsnOBJ.get("access_token").getAsString(); JsonObject grievanceLoginJsonData = jsnOBJ.getAsJsonObject("data"); - authorization = grievanceLoginJsonData.get("key").getAsString(); - registeringUser = grievanceLoginJsonData.get("userName").getAsString(); + - logger.info("Auth key generated at : " + System.currentTimeMillis() + ", Key : " + GRIEVANCE_AUTH_TOKEN); + logger.info("Auth key generated at : {}" , System.currentTimeMillis() + ", Key : {}" , GRIEVANCE_AUTH_TOKEN); Date date = new Date(); java.sql.Date sqlDate = new java.sql.Date(date.getTime()); From 5cb688601200446c63fd293a0b46c6f03e5b5e9f Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Thu, 16 Jan 2025 19:08:58 -0800 Subject: [PATCH 15/23] adding code rabbit suggestions --- .../service/grievance/GrievanceDataSyncImpl.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java index 4685640..49a6dd3 100644 --- a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java @@ -348,14 +348,24 @@ private void generateGrievanceAuthToken() { int count = 3; while (count > 0) { + try { List> savedGrievanceData = dataSyncToGrievance(); if (savedGrievanceData != null) break; - else + else { count--; + + if (count > 0) { + Thread.sleep(5000); + } + } + + } catch(InterruptedException e) { + Thread.currentThread().interrupt(); + break; } } } } - +} From 9e8e1f271d65af13a8d4757cd079efdde3865410 Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Thu, 16 Jan 2025 19:19:06 -0800 Subject: [PATCH 16/23] adding constant instead of duplicate literals --- .../service/grievance/GrievanceDataSyncImpl.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java index 49a6dd3..c13a92a 100644 --- a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java @@ -50,6 +50,10 @@ public class GrievanceDataSyncImpl implements GrievanceDataSync { private static final String USER_AGENT_VALUE = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"; private static final String STATUS_CODE = "statusCode"; + private static final String FILE_NAME = "fileName"; + private static final String FILE_TYPE = "fileType"; + + private final GrievanceDataRepo grievanceDataRepo; private final GrievanceTransactionRepo grievanceTransactionRepo; private final GrievanceFetchBenDetailsRepo grievanceFetchBenDetailsRepo; @@ -174,8 +178,8 @@ public List> dataSyncToGrievance() { // Assuming these fields are coming from your API response transactionDetails.setActionTakenBy(transactionDetailsJson.get("actionTakenBy").getAsString()); transactionDetails.setStatus(transactionDetailsJson.get("status").getAsString()); - transactionDetails.setFileName(transactionDetailsJson.has("fileName") ? transactionDetailsJson.get("fileName").getAsString() : null); - transactionDetails.setFileType(transactionDetailsJson.has("fileType") ? transactionDetailsJson.get("fileType").getAsString() : null); + transactionDetails.setFileName(transactionDetailsJson.has(FILE_NAME) ? transactionDetailsJson.get(FILE_NAME).getAsString() : null); + transactionDetails.setFileType(transactionDetailsJson.has(FILE_TYPE) ? transactionDetailsJson.get(FILE_TYPE).getAsString() : null); transactionDetails.setRedressed(transactionDetailsJson.get("redressed").getAsString()); transactionDetails.setCreatedAt(Timestamp.valueOf(transactionDetailsJson.get("createdAt").getAsString())); transactionDetails.setUpdatedAt(Timestamp.valueOf(transactionDetailsJson.get("updatedAt").getAsString())); @@ -235,8 +239,8 @@ public List> dataSyncToGrievance() { Map transactionData = new HashMap<>(); transactionData.put("actionTakenBy", transaction.getActionTakenBy()); transactionData.put("status", transaction.getStatus()); - transactionData.put("fileName", transaction.getFileName()); - transactionData.put("fileType", transaction.getFileType()); + transactionData.put(FILE_NAME, transaction.getFileName()); + transactionData.put(FILE_TYPE, transaction.getFileType()); transactionData.put("redressed", transaction.getRedressed()); transactionData.put("createdAt", transaction.getCreatedAt().toString()); transactionData.put("updatedAt", transaction.getUpdatedAt().toString()); From 7b3b9907d10c2e311a28b0cdf59938f6df9a0202 Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Sun, 19 Jan 2025 07:27:14 -0800 Subject: [PATCH 17/23] adding cod changs to fetch unallocated grievance count --- .../grievance/GrievanceController.java | 42 +++++++++++++++++++ .../grievance/GrievanceDataRepo.java | 7 ++-- .../service/grievance/GrievanceDataSync.java | 7 ++++ .../grievance/GrievanceDataSyncImpl.java | 19 ++++++++- 4 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/iemr/common/controller/grievance/GrievanceController.java diff --git a/src/main/java/com/iemr/common/controller/grievance/GrievanceController.java b/src/main/java/com/iemr/common/controller/grievance/GrievanceController.java new file mode 100644 index 0000000..43d38d0 --- /dev/null +++ b/src/main/java/com/iemr/common/controller/grievance/GrievanceController.java @@ -0,0 +1,42 @@ +package com.iemr.common.controller.grievance; + + +import com.iemr.common.service.grievance.GrievanceDataSync; +import com.iemr.common.utils.response.OutputResponse; + +import io.swagger.v3.oas.annotations.Operation; + + +import javax.ws.rs.core.MediaType; + +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.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class GrievanceController { + final Logger logger = LoggerFactory.getLogger(this.getClass().getName()); + + @Autowired + private GrievanceDataSync grievanceDataSync; + + + @CrossOrigin() + @Operation(summary = "/unallocatedGrievanceCount") + @RequestMapping(value = "/unallocatedGrievanceCount", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, headers = "Authorization") + public String fetchUnallocatedGrievanceCount() { + OutputResponse responseData = new OutputResponse(); + try { + responseData.setResponse(grievanceDataSync.fetchUnallocatedGrievanceCount()); + } catch (Exception e) { + logger.error("UnallocatedGrievanceCount failed with error" + e.getMessage(), e); + responseData.setError(e); + } + return responseData.toString(); + + } +} diff --git a/src/main/java/com/iemr/common/repository/grievance/GrievanceDataRepo.java b/src/main/java/com/iemr/common/repository/grievance/GrievanceDataRepo.java index a428c74..13457a9 100644 --- a/src/main/java/com/iemr/common/repository/grievance/GrievanceDataRepo.java +++ b/src/main/java/com/iemr/common/repository/grievance/GrievanceDataRepo.java @@ -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 @@ -18,6 +15,8 @@ public interface GrievanceDataRepo extends CrudRepository 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(); } diff --git a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSync.java b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSync.java index 188e1cb..ec0992f 100644 --- a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSync.java +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSync.java @@ -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> dataSyncToGrievance(); + + public String fetchUnallocatedGrievanceCount() throws IEMRException, JSONException; + } diff --git a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java index c13a92a..1b687ce 100644 --- a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java @@ -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; @@ -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") @@ -371,5 +373,18 @@ private void generateGrievanceAuthToken() { } } } + + public String fetchUnallocatedGrievanceCount() throws IEMRException, JSONException { + logger.debug("Request received for fetchUnallocatedGrievanceCount"); + + Long unallocatedCount = grievanceDataRepo.fetchUnallocatedGrievanceCount(); + + // Create a response JSON object + JSONObject result = new JSONObject(); + result.put("count", unallocatedCount); // Store the count of unallocated grievances + + // Return the result as a string + return result.toString(); + } } From d834aa9b3dacccd29fc507c5eb785c5b38185d9e Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Mon, 20 Jan 2025 05:13:49 -0800 Subject: [PATCH 18/23] adding changes suggested by sonar quality check --- .../common/controller/grievance/GrievanceController.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/iemr/common/controller/grievance/GrievanceController.java b/src/main/java/com/iemr/common/controller/grievance/GrievanceController.java index 43d38d0..599e9ca 100644 --- a/src/main/java/com/iemr/common/controller/grievance/GrievanceController.java +++ b/src/main/java/com/iemr/common/controller/grievance/GrievanceController.java @@ -13,6 +13,7 @@ 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.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; @@ -21,13 +22,17 @@ public class GrievanceController { final Logger logger = LoggerFactory.getLogger(this.getClass().getName()); - @Autowired + private GrievanceDataSync grievanceDataSync; + @Autowired + public GrievanceController(GrievanceDataSync grievanceDataSync) { + this.grievanceDataSync = grievanceDataSync; + } @CrossOrigin() @Operation(summary = "/unallocatedGrievanceCount") - @RequestMapping(value = "/unallocatedGrievanceCount", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, headers = "Authorization") + @PostMapping(value = "/unallocatedGrievanceCount", consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, headers = "Authorization") public String fetchUnallocatedGrievanceCount() { OutputResponse responseData = new OutputResponse(); try { From 734551aa2ef836169b209ca5c93d95370a0b33c2 Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Mon, 20 Jan 2025 05:38:46 -0800 Subject: [PATCH 19/23] adding code rabbit suggested changes --- .../controller/grievance/GrievanceController.java | 15 ++++++++++++--- .../service/grievance/GrievanceDataSyncImpl.java | 11 ++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/iemr/common/controller/grievance/GrievanceController.java b/src/main/java/com/iemr/common/controller/grievance/GrievanceController.java index 599e9ca..563334e 100644 --- a/src/main/java/com/iemr/common/controller/grievance/GrievanceController.java +++ b/src/main/java/com/iemr/common/controller/grievance/GrievanceController.java @@ -2,6 +2,7 @@ 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; @@ -9,13 +10,12 @@ 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.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; @RestController @@ -37,7 +37,16 @@ public String fetchUnallocatedGrievanceCount() { OutputResponse responseData = new OutputResponse(); try { responseData.setResponse(grievanceDataSync.fetchUnallocatedGrievanceCount()); - } catch (Exception e) { + } + 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); } diff --git a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java index 1b687ce..c9e421e 100644 --- a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java @@ -378,12 +378,13 @@ public String fetchUnallocatedGrievanceCount() throws IEMRException, JSONExcepti logger.debug("Request received for fetchUnallocatedGrievanceCount"); Long unallocatedCount = grievanceDataRepo.fetchUnallocatedGrievanceCount(); - - // Create a response JSON object - JSONObject result = new JSONObject(); - result.put("count", unallocatedCount); // Store the count of unallocated grievances - // Return the result as a string + if (unallocatedCount == null) { + throw new IEMRException("Failed to fetch unallocated grievance count"); + } + + JSONObject result = new JSONObject(); + result.put("count", unallocatedCount); return result.toString(); } From 47ceb56ac2ecc5df42afc002392318e7685162e3 Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Tue, 21 Jan 2025 02:13:06 -0800 Subject: [PATCH 20/23] fixing config file --- src/main/java/com/iemr/common/config/PrimaryDBConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/iemr/common/config/PrimaryDBConfig.java b/src/main/java/com/iemr/common/config/PrimaryDBConfig.java index da5268b..fc1eeb8 100644 --- a/src/main/java/com/iemr/common/config/PrimaryDBConfig.java +++ b/src/main/java/com/iemr/common/config/PrimaryDBConfig.java @@ -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()); From f26b8ff9b5a1c6762ceb7772c4a04499694a2556 Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Tue, 21 Jan 2025 02:24:18 -0800 Subject: [PATCH 21/23] fixing space --- src/main/java/com/iemr/common/config/PrimaryDBConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/iemr/common/config/PrimaryDBConfig.java b/src/main/java/com/iemr/common/config/PrimaryDBConfig.java index fc1eeb8..1523fb9 100644 --- a/src/main/java/com/iemr/common/config/PrimaryDBConfig.java +++ b/src/main/java/com/iemr/common/config/PrimaryDBConfig.java @@ -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.data.grievance"," 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()); From d3534d9f19d5266f241022ff8dfd891129d2c686 Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Tue, 21 Jan 2025 02:25:31 -0800 Subject: [PATCH 22/23] fixing space issue --- src/main/java/com/iemr/common/config/PrimaryDBConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/iemr/common/config/PrimaryDBConfig.java b/src/main/java/com/iemr/common/config/PrimaryDBConfig.java index 1523fb9..63042b1 100644 --- a/src/main/java/com/iemr/common/config/PrimaryDBConfig.java +++ b/src/main/java/com/iemr/common/config/PrimaryDBConfig.java @@ -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.data.grievance", " 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()); From 6b58965d1b6f1abcb7131aacb1ab62c99c1dfa84 Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Tue, 21 Jan 2025 21:18:10 -0800 Subject: [PATCH 23/23] adding package for PrimaryDBConfig --- src/main/java/com/iemr/common/config/PrimaryDBConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/iemr/common/config/PrimaryDBConfig.java b/src/main/java/com/iemr/common/config/PrimaryDBConfig.java index 63042b1..36463ab 100644 --- a/src/main/java/com/iemr/common/config/PrimaryDBConfig.java +++ b/src/main/java/com/iemr/common/config/PrimaryDBConfig.java @@ -83,7 +83,7 @@ public DataSource dataSource() { public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder, @Qualifier("dataSource") DataSource dataSource) { return builder.dataSource(dataSource).packages("com.iemr.common.data", "com.iemr.common.notification", - "com.iemr.common.model", "com.iemr.common.covidVaccination", "com.iemr.common.data.everwell", "com.iemr.common.data.users").persistenceUnit("db_iemr").build(); + "com.iemr.common.model", "com.iemr.common.covidVaccination", "com.iemr.common.data.everwell", "com.iemr.common.data.grievance", "com.iemr.common.data.users").persistenceUnit("db_iemr").build(); } @Primary