Done Ticket GEPAFINBE-171

This commit is contained in:
Piyush
2025-05-28 11:56:17 +05:30
parent 9699964b09
commit f9b9c5f2e0
10 changed files with 361 additions and 64 deletions

View File

@@ -151,7 +151,8 @@ public class ApplicationAmendmentRequestDao {
String file=applicationEvaluationEntity.getFile();
String checkList=applicationEvaluationEntity.getChecklist();
if(file != null){
evaluationFileRequests=Utils.convertJsonStringToList(file,FieldRequest.class);
log.info("Parsing evaluation file data for evaluationId={}", applicationEvaluationId);
evaluationFileRequests=Utils.convertJsonStringToList(file,FieldRequest.class);
}
if(applicationEvaluationEntity.getEvaluationVersion().equals(EvaluationVersionEnum.V1.getValue())) {
checklistValidationForEvaluationV1(evaluationFileRequests, checkList, checklistRequests);
@@ -309,6 +310,7 @@ public class ApplicationAmendmentRequestDao {
applicationAmendmentRequestEntity.setNote(applicationAmendmentRequest.getNote());
applicationAmendmentRequestEntity.setResponseDays(applicationAmendmentRequest.getResponseDays());
if(applicationAmendmentRequest.getResponseDays()==null || applicationAmendmentRequest.getResponseDays() < 0){
log.warn("Invalid responseDays received: {}", applicationAmendmentRequest.getResponseDays());
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.RESPONSE_DAYS_NOT_NULL));
}
applicationAmendmentRequestEntity.setEndDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()).plusDays(applicationAmendmentRequest.getResponseDays()));
@@ -361,6 +363,8 @@ public class ApplicationAmendmentRequestDao {
userEntity.getHub().getId(),false);
applicationAmendmentRequestEntity.setProtocol(protocolEntity);
ApplicationAmendmentRequestEntity applicationAmendment = saveApplicationAmendmentRequestEntity(applicationAmendmentRequestEntity, null, VersionActionTypeEnum.INSERT);
log.info("Amendment request saved with ID={}", applicationAmendment.getId());
String evaluationStatusType = applicationEvaluationEntity.getStatus();
if (Boolean.FALSE.equals(evaluationStatusType.equals((ApplicationEvaluationStatusTypeEnum.SOCCORSO.getValue())))){
// applicationEvaluationEntity.setStatus(ApplicationEvaluationStatusTypeEnum.SOCCORSO.getValue());
@@ -399,7 +403,7 @@ public class ApplicationAmendmentRequestDao {
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldAssignedApplication).newData(assignedApplicationsEntity).build());
}
log.info("Amendment creation process completed successfully for applicationId={}, evaluationId={}", applicationId, applicationEvaluationId);
return applicationAmendment;
}
private void setAmendmentDocuments(String amendmentNotes, String amendmentFieldRequest,
@@ -490,7 +494,7 @@ public class ApplicationAmendmentRequestDao {
}
public DocumentResponseBean createDocumentResponseBean(String documentId) {
log.info("Initiating document response creation for documentId={}", documentId);
if (!StringUtils.isEmpty(documentId)) {
Optional<DocumentEntity> documentEntity = documentRepository.findByIdAndNotDeleted(Long.valueOf(documentId));
if(documentEntity.isPresent()){
@@ -653,7 +657,9 @@ public class ApplicationAmendmentRequestDao {
}
public List<GetAllAmendmentResponseBean> getAllApplicationAmendmentRequest(HttpServletRequest request, Long userId) {
log.info("Entering getAllApplicationAmendmentRequest with userId={}", userId);
if (validator.checkIsPreInstructor() && userId == null) {
log.warn("Access denied: Pre-instructor must provide userId for amendment request retrieval.");
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.USER_ID_NOT_NULL_MSG));
}
if (userId != null) {
@@ -696,9 +702,11 @@ public class ApplicationAmendmentRequestDao {
isBeneficiary=true;
}
if(Boolean.TRUE.equals(isBeneficiary) && existingApplicationAmendment.getStatus().equals(ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED.getValue())){
throw new CustomValidationException(Status.VALIDATION_ERROR,Translator.toLocale(GepafinConstant.PERMISSION_DENIED));
log.warn("Permission denied: Beneficiary tried to update amendment ID {} with status RESPONSE_RECEIVED", id);
throw new CustomValidationException(Status.VALIDATION_ERROR,Translator.toLocale(GepafinConstant.PERMISSION_DENIED));
}
if(Boolean.FALSE.equals(isBeneficiary) && existingApplicationAmendment.getStatus().equals(ApplicationAmendmentRequestEnum.AWAITING.getValue())){
log.warn("Permission denied: Non-beneficiary tried to update amendment ID {} with status AWAITING", id);
throw new CustomValidationException(Status.VALIDATION_ERROR,Translator.toLocale(GepafinConstant.PERMISSION_DENIED));
}
@@ -721,10 +729,12 @@ public class ApplicationAmendmentRequestDao {
}
existingApplicationAmendment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
if(updateRequest.getAmendmentDocuments()!=null && Boolean.FALSE.equals(updateRequest.getAmendmentDocuments().isEmpty())) {
log.debug("Setting amendment documents for amendment ID: {}", id);
setAmendmentDocuments(updateRequest.getAmendmentNotes(),updateRequest.getAmendmentDocuments(), existingApplicationAmendment);
}
ApplicationAmendmentRequestEntity updatedApplicationAmendment = saveApplicationAmendmentRequestEntity(existingApplicationAmendment,oldApplicationAmendmentEntity,VersionActionTypeEnum.UPDATE);
ApplicationAmendmentRequestResponse response = convertEntityToResponse(updatedApplicationAmendment,false);
log.info("Successfully updated ApplicationAmendmentRequest with ID: {}", id);
log.info("Application Amendment updated successfully: {}", response);
return response;
}
@@ -1020,6 +1030,7 @@ public class ApplicationAmendmentRequestDao {
public List<ApplicationAmendmentRequestResponse> getAllAmendmentRequestByBeneficiaryId(Long beneficiaryUserId) {
log.info("Fetching all amendment requests for beneficiaryUserId={}", beneficiaryUserId);
UserEntity userEntity = userService.validateUser(beneficiaryUserId);
List<ApplicationAmendmentRequestEntity> entities =
applicationAmendmentRequestRepository.findByUserId(beneficiaryUserId);
@@ -1039,6 +1050,8 @@ public class ApplicationAmendmentRequestDao {
existingApplicationAmendment.getApplicationEvaluationEntity().getId()
);
log.debug("Found {} amendment requests for ApplicationEvaluationId={}", amendmentRequestList.size(), existingApplicationAmendment.getApplicationEvaluationEntity().getId());
// Check if this is the last amendment being closed
boolean isLastRemaining = amendmentRequestList.stream()
.filter(amendment -> !amendment.getId().equals(id)) // Exclude the current amendment
@@ -1055,6 +1068,8 @@ public class ApplicationAmendmentRequestDao {
VersionActionTypeEnum.UPDATE);
ApplicationAmendmentRequestResponse response = convertEntityToResponse(updatedApplicationAmendment,false);
log.info("Updated amendment status to CLOSE for amendment ID: {}", id);
List<ApplicationAmendmentRequestEntity> amendmentRequests = applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(
existingApplicationAmendment.getApplicationEvaluationEntity().getId());
Boolean allClosed = amendmentRequests.stream().allMatch(amendment -> (amendment.getStatus().equals(ApplicationAmendmentRequestEnum.CLOSE.getValue()) || amendment.getStatus().equals(ApplicationAmendmentRequestEnum.EXPIRED.getValue())));
@@ -1062,16 +1077,18 @@ public class ApplicationAmendmentRequestDao {
ApplicationEntity oldApplicationEntityData = Utils.getClonedEntityForData(application);
if (Boolean.TRUE.equals(allClosed)) {
existingApplicationAmendment.getApplicationEvaluationEntity().setStatus(ApplicationEvaluationStatusTypeEnum.OPEN.getValue());
if (allClosed) {
ApplicationEvaluationEntity existingApplicationEvaluationEntity = existingApplicationAmendment.getApplicationEvaluationEntity();
ApplicationEvaluationEntity oldApplicationEvaluationEntity = Utils.getClonedEntityForData(existingApplicationEvaluationEntity);
existingApplicationEvaluationEntity.setStatus(ApplicationEvaluationStatusTypeEnum.OPEN.getValue());
applicationEvaluationRepository.save(existingApplicationAmendment.getApplicationEvaluationEntity());
log.info("Updated ApplicationEvaluation status to OPEN for ID: {}", existingApplicationEvaluationEntity.getId());
application.setStatus(ApplicationStatusTypeEnum.EVALUATION.getValue());
applicationRepository.save(application);
log.info("Updated Application status to EVALUATION for Application ID: {}", application.getId());
existingApplicationAmendment.getApplicationEvaluationEntity().getAssignedApplicationsEntity().setStatus(AssignedApplicationEnum.OPEN.getValue());
AssignedApplicationsEntity assignedApplicationsEntity = assignedApplicationsDao.validateAssignedApplication(
@@ -1079,7 +1096,7 @@ public class ApplicationAmendmentRequestDao {
AssignedApplicationsEntity oldAssignedApplicationData = Utils.getClonedEntityForData(assignedApplicationsEntity);
assignedApplicationsEntity = assignedApplicationsRepository.save(existingApplicationAmendment.getApplicationEvaluationEntity().getAssignedApplicationsEntity());
log.info("Updated AssignedApplication status to OPEN for ID: {}", assignedApplicationsEntity.getId());
Map<String, String> placeHolders = notificationDao.sendNotificationToBeneficiary(application, NotificationTypeEnum.AMENDMENT_CLOSED);
@@ -1106,6 +1123,7 @@ public class ApplicationAmendmentRequestDao {
public ApplicationAmendmentRequestResponse extendResponseDays(Long id, Long newResponseDays) {
log.info("Extending response days for Application Amendment ID: {}, Additional Days: {}", id, newResponseDays);
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = validateApplicationAmendmentRequest(id);
if (newResponseDays != null && newResponseDays > 0) {
@@ -1156,6 +1174,7 @@ public class ApplicationAmendmentRequestDao {
ApplicationAmendmentRequestEntity existingApplicationAmendment = validateApplicationAmendmentRequest(id);
ApplicationAmendmentRequestEntity oldApplicationAmendmentEntity = Utils.getClonedEntityForData(existingApplicationAmendment);
if (Boolean.TRUE.equals(existingApplicationAmendment.getStatus().equals(ApplicationAmendmentRequestEnum.AWAITING.getValue())) && Boolean.TRUE.equals(statusTypeEnum.equals(ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED))) {
log.info("Updating amendment ID {} status from {} to {}", id, existingApplicationAmendment.getStatus(), statusTypeEnum);
existingApplicationAmendment.setStatus(ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED.getValue());
existingApplicationAmendment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
applicationAmendmentRequestRepository.save(existingApplicationAmendment);
@@ -1169,9 +1188,11 @@ public class ApplicationAmendmentRequestDao {
}
public void sendReminderEmail(Long amendmentId) {
log.info("Initiating reminder email process for Amendment ID: {}", amendmentId);
ApplicationAmendmentRequestEntity amendment = applicationAmendmentRequestRepository.findByIdAndIsDeletedFalse(amendmentId)
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.APPLICATION_AMENDMENT_NOT_FOUND_MSG)));
.orElseThrow(() -> { log.error("Amendment not found with ID: {}", amendmentId);
return new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.APPLICATION_AMENDMENT_NOT_FOUND_MSG));
});
Optional<ApplicationEvaluationEntity> entityOptional = applicationEvaluationRepository.findByIdAndIsDeletedFalse(amendment.getApplicationEvaluationEntity().getId());
if (entityOptional.isPresent()) {
@@ -1183,10 +1204,13 @@ public class ApplicationAmendmentRequestDao {
String body = prepareBody(emailTemplate, amendment, beneficiaryUser);
String email = beneficiaryUser.getEmail();
if (Boolean.TRUE.equals(amendment.getIsEmail()) && email != null && !email.isEmpty()) {
log.info("Sending reminder email to: {}", email);
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(emailTemplate.getEmailScenario(), RecipientTypeEnum.USER, beneficiaryUser.getId(), email,
beneficiaryUser.getId(), applicationEntity.getId(), amendment.getId(), applicationEntity.getCall().getId());
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(email), emailLogRequest);
log.info("Reminder email sent successfully for Amendment ID: {}", amendmentId);
} else {
log.warn("Beneficiary email not found or isEmail flag is false for Amendment ID: {}", amendmentId);
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.BENEFICIARY_EMAIL_NOT_FOUND_MSG));
}
}
@@ -1220,6 +1244,7 @@ public class ApplicationAmendmentRequestDao {
}
public ApplicationEvaluationEntity calculateEndDateAndSuspensionDays(ApplicationEvaluationEntity applicationEvaluationEntity){
log.info("Calculating end date and suspension days for Application Evaluation ID: {}", applicationEvaluationEntity.getId());
LocalDateTime currentDate=DateTimeUtil.DateServerToUTC(LocalDateTime.now());
LocalDateTime endDate=currentDate.plusDays(applicationEvaluationEntity.getRemainingDays());
Long suspendedDays = ChronoUnit.DAYS.between(applicationEvaluationEntity.getStopDateTime(), currentDate);
@@ -1230,8 +1255,10 @@ public class ApplicationAmendmentRequestDao {
applicationEvaluationEntity.setSuspendedDays(0L);
}
applicationEvaluationEntity.setSuspendedDays(applicationEvaluationEntity.getSuspendedDays()+suspendedDays);
log.debug("Updated suspended days: {}", applicationEvaluationEntity.getSuspendedDays());
ApplicationEvaluationEntity applicationEvaluation = applicationEvaluationRepository.save(applicationEvaluationEntity);
log.info("Application Evaluation updated successfully. ID: {}", applicationEvaluation.getId());
/** This code is responsible for adding a version history log for the "Update Application Amendment" operation. **/
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationEvaluationEntity).newData(applicationEvaluation).build());
@@ -1271,7 +1298,9 @@ public class ApplicationAmendmentRequestDao {
return response;
}
private void softDeleteDocument(Long documentId) {
log.info("Initiating soft delete for Document ID: {}", documentId);
documentService.deleteFile(documentId);
log.info("Document ID: {} soft deleted successfully.", documentId);
}
// public PageableResponseBean<List<ApplicationAmendmentRequestResponse>> getApplicationAmendmentByPaginnation(Long userId, ApplicationAmendmentPaginationRequestBean applicationAmendmentPaginationRequestBean) {
@@ -1390,6 +1419,7 @@ public class ApplicationAmendmentRequestDao {
// }
public PageableResponseBean<List<ApplicationAmendmentRequestViewResponse>> getApplicationAmendmentByPaginationByView(Long userId, ApplicationAmendmentPaginationRequestBean applicationAmendmentPaginationRequestBean) {
log.info("Fetching paginated application amendments for userId: {}", userId);
Integer pageNo = null;
Integer pageLimit = null;
if (applicationAmendmentPaginationRequestBean.getGlobalFilters() != null) {
@@ -1421,6 +1451,7 @@ public class ApplicationAmendmentRequestDao {
pageableResponseBean.setTotalRecords(entityPage.getTotalElements());
pageableResponseBean.setPageSize(entityPage.getSize());
log.info("Paginated response prepared successfully for userId: {}", userId);
return pageableResponseBean;
}
public Specification<ApplicationAmendmentRequestView> searchPaginationByView(Long userId,ApplicationAmendmentPaginationRequestBean applicationAmendmentPaginationRequestBean) {
@@ -1452,6 +1483,7 @@ public class ApplicationAmendmentRequestDao {
private List<Predicate> getPredicatesByView(ApplicationAmendmentPaginationRequestBean amendmentPaginationRequestBean,
CriteriaBuilder criteriaBuilder, Root<ApplicationAmendmentRequestView> root,Long userId) {
log.info("Building predicates for userId: {}", userId);
Integer year = null;
String search = null;
Map<String, FilterCriteria> filters = new HashMap<>();
@@ -1471,6 +1503,7 @@ public class ApplicationAmendmentRequestDao {
LocalDateTime startOfYear = LocalDateTime.of(filterYear, 1, 1, 0, 0);
LocalDateTime endOfYear = LocalDateTime.of(filterYear, 12, 31, 23, 59, 59);
log.debug("Filtering by year between {} and {}", startOfYear, endOfYear);
// Add the range comparison to filter records within the year
predicates.add(criteriaBuilder.between(root.get(GepafinConstant.CREATED_DATE), startOfYear, endOfYear));