Done ticket GEPAFINBE-195

This commit is contained in:
piyushkag
2025-04-03 14:51:16 +05:30
parent a4bd8d9329
commit 5afdf042bc
19 changed files with 429 additions and 253 deletions

View File

@@ -134,6 +134,12 @@ public class ApplicationAmendmentRequestDao {
@Autowired
private ApplicationEvaluationFormRepository applicationEvaluationFormRepository;
@Autowired
private ApplicationAmendmentRequestViewRepository applicationAmendmentRequestViewRepository;
@Autowired
private ApplicationDao applicationDao;
public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(Long applicationEvaluationId) {
log.info("Fetching the application data for the Amendment process {}", applicationEvaluationId);
ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluation(applicationEvaluationId);
@@ -1268,7 +1274,122 @@ public class ApplicationAmendmentRequestDao {
documentService.deleteFile(documentId);
}
public PageableResponseBean<List<ApplicationAmendmentRequestResponse>> getApplicationAmendmentByPaginnation(Long userId, ApplicationAmendmentPaginationRequestBean applicationAmendmentPaginationRequestBean) {
// public PageableResponseBean<List<ApplicationAmendmentRequestResponse>> getApplicationAmendmentByPaginnation(Long userId, ApplicationAmendmentPaginationRequestBean applicationAmendmentPaginationRequestBean) {
// Integer pageNo = null;
// Integer pageLimit = null;
// if (applicationAmendmentPaginationRequestBean.getGlobalFilters() != null) {
// pageNo = applicationAmendmentPaginationRequestBean.getGlobalFilters().getPage();
// pageLimit = applicationAmendmentPaginationRequestBean.getGlobalFilters().getLimit();
// }
// if (pageLimit == null || pageLimit <= 0) {
// pageLimit = GepafinConstant.DEFAULT_PAGE_LIMIT;
// }
// if (pageNo == null || pageNo <= 0) {
// pageNo = GepafinConstant.DEFAULT_PAGE;
// }
// Specification<ApplicationAmendmentRequestEntity> spec = searchPagination(userId,applicationAmendmentPaginationRequestBean);
// Page<ApplicationAmendmentRequestEntity> entityPage = applicationAmendmentRequestRepository.findAll(spec, PageRequest.of(pageNo - 1, pageLimit));
//
//
// List<ApplicationAmendmentRequestResponse> applicationResponses = entityPage.getContent().stream()
// .map(application -> {
// ApplicationAmendmentRequestResponse response = convertEntityToResponse(application,false);
// return response;
// })
// .collect(Collectors.toList());
//
//
// PageableResponseBean<List<ApplicationAmendmentRequestResponse>> pageableResponseBean = new PageableResponseBean<>();
// pageableResponseBean.setBody(applicationResponses);
// pageableResponseBean.setCurrentPage(entityPage.getNumber() + 1); // Page numbers typically start from 0, so add 1 for user-friendly indexing
// pageableResponseBean.setTotalPages(entityPage.getTotalPages());
// pageableResponseBean.setTotalRecords(entityPage.getTotalElements());
// pageableResponseBean.setPageSize(entityPage.getSize());
//
// return pageableResponseBean;
// }
//
// public Specification<ApplicationAmendmentRequestEntity> searchPagination(Long userId,ApplicationAmendmentPaginationRequestBean applicationAmendmentPaginationRequestBean) {
// return (root, query, criteriaBuilder) -> {
//
// List<Predicate> predicates = getPredicates(applicationAmendmentPaginationRequestBean, criteriaBuilder, root,userId);
// SortBy sortBy = new SortBy(GepafinConstant.CREATED_DATE, true);
//
// if (applicationAmendmentPaginationRequestBean .getGlobalFilters() != null
// && applicationAmendmentPaginationRequestBean.getGlobalFilters().getSortBy() != null &&
// applicationAmendmentPaginationRequestBean.getGlobalFilters().getSortBy().getColumnName() != null && Boolean.FALSE.equals(
// isEmpty(applicationAmendmentPaginationRequestBean.getGlobalFilters().getSortBy().getColumnName()))) {
// sortBy.setColumnName(applicationAmendmentPaginationRequestBean.getGlobalFilters().getSortBy().getColumnName());
// sortBy.setSortDesc(true);
// if (applicationAmendmentPaginationRequestBean.getGlobalFilters().getSortBy().getSortDesc() != null) {
// sortBy.setSortDesc(applicationAmendmentPaginationRequestBean.getGlobalFilters().getSortBy().getSortDesc());
// }
// }
//
// query.orderBy(criteriaBuilder.desc(root.get(sortBy.getColumnName())));
// if (Boolean.FALSE.equals(sortBy.getSortDesc())) {
// query.orderBy(criteriaBuilder.asc(root.get(sortBy.getColumnName())));
// }
// return query.where(criteriaBuilder.and(predicates.toArray(new Predicate[0]))).getRestriction();
// };
// }
//
//
// private List<Predicate> getPredicates(ApplicationAmendmentPaginationRequestBean amendmentPaginationRequestBean,
// CriteriaBuilder criteriaBuilder, Root<ApplicationAmendmentRequestEntity> root,Long userId) {
//
// Integer year = null;
// String search = null;
// if (amendmentPaginationRequestBean.getGlobalFilters() != null) {
// year = amendmentPaginationRequestBean.getGlobalFilters().getYear();
// search = amendmentPaginationRequestBean.getGlobalFilters().getSearch();
// }
// List<Predicate> predicates = new ArrayList<>();
//
// if (year != null && year > 0) {
// int filterYear = amendmentPaginationRequestBean.getGlobalFilters().getYear();
//
//// Create LocalDateTime boundaries for the start and end of the year
// LocalDateTime startOfYear = LocalDateTime.of(filterYear, 1, 1, 0, 0);
// LocalDateTime endOfYear = LocalDateTime.of(filterYear, 12, 31, 23, 59, 59);
//
//// Add the range comparison to filter records within the year
// predicates.add(criteriaBuilder.between(root.get(GepafinConstant.CREATED_DATE), startOfYear, endOfYear));
//
// }
// // Search in `title` and `message` (if search term is provided)
// if (search != null && !search.isEmpty()) {
// Predicate notePredicate = criteriaBuilder.like(
// criteriaBuilder.upper(root.get(GepafinConstant.NOTE)),
// "%" + search.toUpperCase() + "%"
// );
// predicates.add(criteriaBuilder.or(notePredicate));
// Predicate internalNotePredicate = criteriaBuilder.like(
// criteriaBuilder.upper(root.get(GepafinConstant.INTERNAL_NOTE)),
// "%" + search.toUpperCase() + "%"
// );
// predicates.add(criteriaBuilder.or(internalNotePredicate));
// }
//
// // Filter by `status` (if status list is provided)
// if (amendmentPaginationRequestBean.getStatus() != null && !amendmentPaginationRequestBean.getStatus().isEmpty()) {
// List<String> statusValues = amendmentPaginationRequestBean.getStatus().stream()
// .map(ApplicationAmendmentRequestEnum::name) // Convert enum to string
// .toList();
// predicates.add(root.get(GepafinConstant.STATUS).in(statusValues));
// }
// if(Boolean.TRUE.equals(validator.checkIsBeneficiary()) || Boolean.TRUE.equals(validator.checkIsConfidi())) {
// predicates.add(root.get("applicationEvaluationEntity").get("assignedApplicationsEntity").get("application").get("userId").in(userId));
// }
// else {
// predicates.add(root.get("applicationEvaluationEntity").get("assignedApplicationsEntity").get("userId").in(userId));
// }
//
// return predicates;
//
// }
public PageableResponseBean<List<ApplicationAmendmentRequestViewResponse>> getApplicationAmendmentByPaginationByView(Long userId, ApplicationAmendmentPaginationRequestBean applicationAmendmentPaginationRequestBean) {
Integer pageNo = null;
Integer pageLimit = null;
if (applicationAmendmentPaginationRequestBean.getGlobalFilters() != null) {
@@ -1281,20 +1402,20 @@ public class ApplicationAmendmentRequestDao {
if (pageNo == null || pageNo <= 0) {
pageNo = GepafinConstant.DEFAULT_PAGE;
}
Specification<ApplicationAmendmentRequestEntity> spec = searchPagination(userId,applicationAmendmentPaginationRequestBean);
Page<ApplicationAmendmentRequestEntity> entityPage = applicationAmendmentRequestRepository.findAll(spec, PageRequest.of(pageNo - 1, pageLimit));
Specification<ApplicationAmendmentRequestView> spec = searchPaginationByView(userId,applicationAmendmentPaginationRequestBean);
Page<ApplicationAmendmentRequestView> entityPage = applicationAmendmentRequestViewRepository.findAll(spec, PageRequest.of(pageNo - 1, pageLimit));
List<ApplicationAmendmentRequestResponse> applicationResponses = entityPage.getContent().stream()
.map(application -> {
ApplicationAmendmentRequestResponse response = convertEntityToResponse(application,false);
List<ApplicationAmendmentRequestViewResponse> applicationAmendmentRequestViewResponses = entityPage.getContent().stream()
.map(amendmentRequestView -> {
ApplicationAmendmentRequestViewResponse response = convertAmendmentEntityToApplicationAmendmentRequestViewResponse(amendmentRequestView);
return response;
})
.collect(Collectors.toList());
PageableResponseBean<List<ApplicationAmendmentRequestResponse>> pageableResponseBean = new PageableResponseBean<>();
pageableResponseBean.setBody(applicationResponses);
PageableResponseBean<List<ApplicationAmendmentRequestViewResponse>> pageableResponseBean = new PageableResponseBean<>();
pageableResponseBean.setBody(applicationAmendmentRequestViewResponses);
pageableResponseBean.setCurrentPage(entityPage.getNumber() + 1); // Page numbers typically start from 0, so add 1 for user-friendly indexing
pageableResponseBean.setTotalPages(entityPage.getTotalPages());
pageableResponseBean.setTotalRecords(entityPage.getTotalElements());
@@ -1302,11 +1423,10 @@ public class ApplicationAmendmentRequestDao {
return pageableResponseBean;
}
public Specification<ApplicationAmendmentRequestEntity> searchPagination(Long userId,ApplicationAmendmentPaginationRequestBean applicationAmendmentPaginationRequestBean) {
public Specification<ApplicationAmendmentRequestView> searchPaginationByView(Long userId,ApplicationAmendmentPaginationRequestBean applicationAmendmentPaginationRequestBean) {
return (root, query, criteriaBuilder) -> {
List<Predicate> predicates = getPredicates(applicationAmendmentPaginationRequestBean, criteriaBuilder, root,userId);
List<Predicate> predicates = getPredicatesByView(applicationAmendmentPaginationRequestBean, criteriaBuilder, root,userId);
SortBy sortBy = new SortBy(GepafinConstant.CREATED_DATE, true);
if (applicationAmendmentPaginationRequestBean .getGlobalFilters() != null
@@ -1329,15 +1449,19 @@ public class ApplicationAmendmentRequestDao {
}
private List<Predicate> getPredicates(ApplicationAmendmentPaginationRequestBean amendmentPaginationRequestBean,
CriteriaBuilder criteriaBuilder, Root<ApplicationAmendmentRequestEntity> root,Long userId) {
private List<Predicate> getPredicatesByView(ApplicationAmendmentPaginationRequestBean amendmentPaginationRequestBean,
CriteriaBuilder criteriaBuilder, Root<ApplicationAmendmentRequestView> root,Long userId) {
Integer year = null;
String search = null;
Map<String, FilterCriteria> filters = new HashMap<>();
if (amendmentPaginationRequestBean.getGlobalFilters() != null) {
year = amendmentPaginationRequestBean.getGlobalFilters().getYear();
search = amendmentPaginationRequestBean.getGlobalFilters().getSearch();
}
if (amendmentPaginationRequestBean.getFilters() != null) {
filters = amendmentPaginationRequestBean.getFilters();
}
List<Predicate> predicates = new ArrayList<>();
if (year != null && year > 0) {
@@ -1351,19 +1475,37 @@ public class ApplicationAmendmentRequestDao {
predicates.add(criteriaBuilder.between(root.get(GepafinConstant.CREATED_DATE), startOfYear, endOfYear));
}
// Search in `title` and `message` (if search term is provided)
if (search != null && !search.isEmpty()) {
Predicate notePredicate = criteriaBuilder.like(
criteriaBuilder.upper(root.get(GepafinConstant.NOTE)),
List<Predicate> searchPredicates = new ArrayList<>();
searchPredicates.add(criteriaBuilder.like(
criteriaBuilder.upper(root.get(GepafinConstant.CALL_NAME)),
"%" + search.toUpperCase() + "%"
);
predicates.add(criteriaBuilder.or(notePredicate));
Predicate internalNotePredicate = criteriaBuilder.like(
criteriaBuilder.upper(root.get(GepafinConstant.INTERNAL_NOTE)),
));
searchPredicates.add(criteriaBuilder.like(
criteriaBuilder.upper(root.get(GepafinConstant.COMPANY_NAME)),
"%" + search.toUpperCase() + "%"
);
predicates.add(criteriaBuilder.or(internalNotePredicate));
));
// Uncomment these if needed
// searchPredicates.add(criteriaBuilder.like(
// criteriaBuilder.upper(root.get(GepafinConstant.NOTE)),
// "%" + search.toUpperCase() + "%"
// ));
//
// searchPredicates.add(criteriaBuilder.like(
// criteriaBuilder.upper(root.get(GepafinConstant.INTERNAL_NOTE)),
// "%" + search.toUpperCase() + "%"
// ));
Predicate finalPredicate = criteriaBuilder.or(searchPredicates.toArray(new Predicate[0]));
predicates.add(finalPredicate);
}
Utils.applyFiltersByPagination(root, criteriaBuilder, predicates, filters);
// Filter by `status` (if status list is provided)
if (amendmentPaginationRequestBean.getStatus() != null && !amendmentPaginationRequestBean.getStatus().isEmpty()) {
@@ -1372,14 +1514,33 @@ public class ApplicationAmendmentRequestDao {
.toList();
predicates.add(root.get(GepafinConstant.STATUS).in(statusValues));
}
if(Boolean.TRUE.equals(validator.checkIsBeneficiary()) || Boolean.TRUE.equals(validator.checkIsConfidi())) {
predicates.add(root.get("applicationEvaluationEntity").get("assignedApplicationsEntity").get("application").get("userId").in(userId));
}
else {
predicates.add(root.get("applicationEvaluationEntity").get("assignedApplicationsEntity").get("userId").in(userId));
boolean isBeneficiaryOrConfidi = validator.checkIsBeneficiary() || validator.checkIsConfidi();
boolean isPreInstructor = validator.checkIsPreInstructor();
boolean isInstructorManagerWithPersonalRecords = validator.checkIsInstructorManager() &&
Boolean.TRUE.equals(amendmentPaginationRequestBean.getPersonalRecords());
if (isBeneficiaryOrConfidi) {
predicates.add(root.get(GepafinConstant.APPLICATION_USER_ID).in(userId));
} else if (isPreInstructor || isInstructorManagerWithPersonalRecords) {
predicates.add(root.get(GepafinConstant.ASSIGNED_USER_ID).in(userId));
}
return predicates;
}
public ApplicationAmendmentRequestViewResponse convertAmendmentEntityToApplicationAmendmentRequestViewResponse(ApplicationAmendmentRequestView applicationAmendmentRequestView){
ApplicationAmendmentRequestViewResponse applicationAmendmentRequestViewResponse=new ApplicationAmendmentRequestViewResponse();
applicationAmendmentRequestViewResponse.setId(applicationAmendmentRequestView.getId());
applicationAmendmentRequestViewResponse.setApplicationId(applicationAmendmentRequestView.getApplicationId());
applicationAmendmentRequestViewResponse.setProtocolNumber(applicationAmendmentRequestView.getProtocolNumber());
applicationAmendmentRequestViewResponse.setCallName(applicationAmendmentRequestView.getCallName());
applicationAmendmentRequestViewResponse.setCompanyName(applicationAmendmentRequestView.getCompanyName());
applicationAmendmentRequestViewResponse.setStartDate(applicationAmendmentRequestView.getStartDate());
applicationAmendmentRequestViewResponse.setExpirationDate(applicationAmendmentRequestView.getExpirationDate());
applicationAmendmentRequestViewResponse.setAssigendUserName(applicationAmendmentRequestView.getAssigendUserName());
applicationAmendmentRequestViewResponse.setStatus(applicationAmendmentRequestView.getStatus());
return applicationAmendmentRequestViewResponse;
}
}