Done ticket GEPAFINBE-194
This commit is contained in:
@@ -129,8 +129,6 @@ public class ApplicationDao {
|
||||
@Value("${rinaldo_email}")
|
||||
private String rinaldoEmail;
|
||||
|
||||
@Value("${carlo_email}")
|
||||
private String carloEmail;
|
||||
|
||||
@Value("${call.id}")
|
||||
private String callId;
|
||||
@@ -195,6 +193,9 @@ public class ApplicationDao {
|
||||
@Autowired
|
||||
private ApplicationEvaluationRepository applicationEvaluationRepository;
|
||||
|
||||
@Autowired
|
||||
private ApplicationViewRepository applicationViewRepository;
|
||||
|
||||
|
||||
public ApplicationResponseBean createApplication(HttpServletRequest request, ApplicationRequestBean applicationRequestBean, Long formId, Long applicationId) {
|
||||
FormEntity formEntity = formService.validateForm(formId);
|
||||
@@ -1614,7 +1615,7 @@ public class ApplicationDao {
|
||||
MatchModeEnum matchMode = filterCriteria.getMatchMode();
|
||||
|
||||
if (value != null && matchMode != null) {
|
||||
Path<?> fieldPath = getFieldPath(root, fieldName);
|
||||
Path<?> fieldPath = root.get(fieldName);
|
||||
if (fieldPath != null) {
|
||||
Utils.applyStringFilter(fieldPath, criteriaBuilder, predicates, value, matchMode);
|
||||
Utils.applyNumberFilter(fieldPath, criteriaBuilder, predicates, value, matchMode);
|
||||
@@ -1628,21 +1629,21 @@ public class ApplicationDao {
|
||||
|
||||
|
||||
|
||||
private Path<?> getFieldPath(Root<?> root, String fieldName) {
|
||||
try {
|
||||
return switch (fieldName) {
|
||||
case GepafinConstant.CALL_ID -> root.get(GepafinConstant.CALL).get(GepafinConstant.ID);
|
||||
case GepafinConstant.CALL_TITLE -> root.get(GepafinConstant.CALL).get(GepafinConstant.NAME);
|
||||
case GepafinConstant.CALL_END_DATE -> root.get(GepafinConstant.CALL).get(GepafinConstant.END_DATE);
|
||||
case GepafinConstant.CALL_END_TIME -> root.get(GepafinConstant.CALL).get(GepafinConstant.END_TIME);
|
||||
case GepafinConstant.MODIFIED_DATE -> root.get(GepafinConstant.CALL).get(GepafinConstant.UPDATED_DATE);
|
||||
case GepafinConstant.PROTOCOL_NUMBER-> root.get(GepafinConstant.PROTOCOL).get(GepafinConstant.PROTOCOL_NUMBER);
|
||||
default -> root.get(fieldName);
|
||||
};
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// private Path<?> getFieldPath(Root<?> root, String fieldName) {
|
||||
// try {
|
||||
// return switch (fieldName) {
|
||||
//// case GepafinConstant.CALL_ID -> root.get(GepafinConstant.CALL).get(GepafinConstant.ID);
|
||||
//// case GepafinConstant.CALL_TITLE -> root.get(GepafinConstant.CALL).get(GepafinConstant.NAME);
|
||||
//// case GepafinConstant.CALL_END_DATE -> root.get(GepafinConstant.CALL).get(GepafinConstant.END_DATE);
|
||||
//// case GepafinConstant.CALL_END_TIME -> root.get(GepafinConstant.CALL).get(GepafinConstant.END_TIME);
|
||||
//// case GepafinConstant.MODIFIED_DATE -> root.get(GepafinConstant.CALL).get(GepafinConstant.UPDATED_DATE);
|
||||
//// case GepafinConstant.PROTOCOL_NUMBER-> root.get(GepafinConstant.PROTOCOL).get(GepafinConstant.PROTOCOL_NUMBER);
|
||||
// default -> root.get(fieldName);
|
||||
// };
|
||||
// } catch (IllegalArgumentException e) {
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
public void checkCallEndDate(CallEntity call) {
|
||||
@@ -1798,4 +1799,199 @@ public class ApplicationDao {
|
||||
}
|
||||
return application;
|
||||
}
|
||||
public PageableResponseBean<List<ApplicationResponse>> getAllApplicationByPaginationByView(UserEntity userEntity, Long callId, Long companyId, ApplicationPageableRequestBean applicationPageableRequestBean) {
|
||||
Integer pageNo = null;
|
||||
Integer pageLimit = null;
|
||||
|
||||
UserWithCompanyEntity userWithCompany= userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userEntity.getId(), companyId).orElse(null);
|
||||
Long userWithCompanyId = userWithCompany!=null?userWithCompany.getId():null;
|
||||
if (applicationPageableRequestBean.getGlobalFilters() != null) {
|
||||
pageNo = applicationPageableRequestBean.getGlobalFilters().getPage();
|
||||
pageLimit = applicationPageableRequestBean.getGlobalFilters().getLimit();
|
||||
}
|
||||
if (pageLimit == null || pageLimit <= 0) {
|
||||
pageLimit = GepafinConstant.DEFAULT_PAGE_LIMIT;
|
||||
}
|
||||
if (pageNo == null || pageNo <= 0) {
|
||||
pageNo = GepafinConstant.DEFAULT_PAGE;
|
||||
}
|
||||
Specification<ApplicationView> spec = searchByView(callId,companyId, userWithCompanyId, applicationPageableRequestBean, userEntity);
|
||||
Page<ApplicationView> entityPage = applicationViewRepository.findAll(spec, PageRequest.of(pageNo - 1, pageLimit));
|
||||
// Prepare the response
|
||||
|
||||
|
||||
List<ApplicationResponse> applicationResponses = entityPage.getContent().stream()
|
||||
.map(application -> {
|
||||
ApplicationResponse response = getApplicationResponseByView(application);
|
||||
return response;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
PageableResponseBean<List<ApplicationResponse>> 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<ApplicationView> searchByView(Long callId, Long companyId, Long userWithCompanyId, ApplicationPageableRequestBean applicationPageableRequestBean, UserEntity userEntity) {
|
||||
return (root, query, criteriaBuilder) -> {
|
||||
|
||||
List<Predicate> predicates = getPredicatesByView(applicationPageableRequestBean, criteriaBuilder, root, callId,companyId, userWithCompanyId, userEntity);
|
||||
SortBy sortBy = new SortBy(GepafinConstant.CREATED_DATE, true);
|
||||
|
||||
if (applicationPageableRequestBean.getGlobalFilters() != null
|
||||
&& applicationPageableRequestBean.getGlobalFilters().getSortBy() != null &&
|
||||
applicationPageableRequestBean.getGlobalFilters().getSortBy().getColumnName() != null && Boolean.FALSE.equals(
|
||||
isEmpty(applicationPageableRequestBean.getGlobalFilters().getSortBy().getColumnName()))) {
|
||||
sortBy.setColumnName(applicationPageableRequestBean.getGlobalFilters().getSortBy().getColumnName());
|
||||
sortBy.setSortDesc(true);
|
||||
if (applicationPageableRequestBean.getGlobalFilters().getSortBy().getSortDesc() != null) {
|
||||
sortBy.setSortDesc(applicationPageableRequestBean.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> getPredicatesByView(ApplicationPageableRequestBean applicationPageableRequestBean,
|
||||
CriteriaBuilder criteriaBuilder, Root<ApplicationView> root, Long callId,Long companyId, Long userWithCompanyId, UserEntity userEntity) {
|
||||
|
||||
Integer year = null;
|
||||
String search = null;
|
||||
Integer daysRange = null;
|
||||
Map<String, FilterCriteria> filters = new HashMap<>();
|
||||
if (applicationPageableRequestBean.getGlobalFilters() != null) {
|
||||
year = applicationPageableRequestBean.getGlobalFilters().getYear();
|
||||
search = applicationPageableRequestBean.getGlobalFilters().getSearch();
|
||||
daysRange = applicationPageableRequestBean.getDaysRange();
|
||||
}
|
||||
if (applicationPageableRequestBean.getFilters() != null) {
|
||||
filters = applicationPageableRequestBean.getFilters();
|
||||
}
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
|
||||
// Boolean isBeneficiary = validator.checkIsBeneficiary();
|
||||
if (Boolean.TRUE.equals(validator.checkIsBeneficiary()) || Boolean.TRUE.equals(validator.checkIsConfidi())) {
|
||||
predicates.add(criteriaBuilder.equal(root.get(GepafinConstant.USER_ID), userEntity.getId()));
|
||||
}
|
||||
if (year != null && year > 0) {
|
||||
int filterYear = applicationPageableRequestBean.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 titlePredicate = criteriaBuilder.like(
|
||||
criteriaBuilder.upper(root.get(GepafinConstant.COMMENTS)),
|
||||
"%" + search.toUpperCase() + "%"
|
||||
);
|
||||
// Predicate protocolPredicate = criteriaBuilder.like(
|
||||
// criteriaBuilder.function(
|
||||
// "TO_CHAR",
|
||||
// String.class,
|
||||
// criteriaBuilder.function("CAST", String.class, root.get(GepafinConstant.PROTOCOL).get(GepafinConstant.PROTOCOL_NUMBER))
|
||||
// ),
|
||||
// "%" + search + "%"
|
||||
// );
|
||||
|
||||
Predicate callNamePredicate =criteriaBuilder.like(
|
||||
criteriaBuilder.upper(root.get(GepafinConstant.CALL_TITLE)), // Adjust field name
|
||||
"%" + search.toUpperCase() + "%"
|
||||
);
|
||||
|
||||
// predicates.add(criteriaBuilder.or(protocolPredicate));
|
||||
predicates.add(criteriaBuilder.or(callNamePredicate));
|
||||
predicates.add(criteriaBuilder.or(titlePredicate));
|
||||
}
|
||||
|
||||
// Filter by `status` (if status list is provided)
|
||||
if (applicationPageableRequestBean.getStatus() != null && !applicationPageableRequestBean.getStatus().isEmpty()) {
|
||||
List<String> statusValues = applicationPageableRequestBean.getStatus().stream()
|
||||
.map(ApplicationStatusTypeEnum::name) // Convert enum to string
|
||||
.toList();
|
||||
predicates.add(root.get(GepafinConstant.STATUS).in(statusValues));
|
||||
}
|
||||
|
||||
if (callId != null) {
|
||||
CallEntity call = callService.validateCall(callId);
|
||||
predicates.add(criteriaBuilder.equal(root.get(GepafinConstant.CALL_ID), callId));
|
||||
}
|
||||
|
||||
// Optional companyId filter
|
||||
if (userWithCompanyId != null) {
|
||||
predicates.add(criteriaBuilder.equal(root.get(GepafinConstant.USER_WITH_COMPANY_ID), userWithCompanyId));
|
||||
}
|
||||
if (companyId != null) {
|
||||
predicates.add(criteriaBuilder.equal(root.get(GepafinConstant.COMPANY_ID), companyId));
|
||||
}
|
||||
|
||||
if (daysRange != null && daysRange >= 0) {
|
||||
LocalDateTime today = LocalDateTime.now();
|
||||
LocalDateTime pastDate = today.minusDays(daysRange);
|
||||
predicates.add(criteriaBuilder.between(root.get(GepafinConstant.CREATED_DATE), pastDate, today));
|
||||
}
|
||||
applyFilters(root, criteriaBuilder, predicates, filters);
|
||||
|
||||
predicates.add(criteriaBuilder.isFalse(root.get(GepafinConstant.IS_DELETED)));
|
||||
|
||||
predicates.add(criteriaBuilder.equal(root.get(GepafinConstant.HUB_ID), userEntity.getHub().getId()));
|
||||
|
||||
|
||||
return predicates;
|
||||
}
|
||||
|
||||
private ApplicationResponse getApplicationResponseByView(ApplicationView applicationView) {
|
||||
ApplicationResponse responseBean = new ApplicationResponse();
|
||||
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationView.getCallId());
|
||||
Long totalFormSteps = flowFormDao.calculateTotalSteps(flowEdgesList);
|
||||
Long completedSteps= Long.valueOf(flowFormDao.getCompletedStepsByView(applicationView.getId(), false));
|
||||
Integer progress = calculateProgress(totalFormSteps, completedSteps);
|
||||
responseBean.setId(applicationView.getId());
|
||||
responseBean.setProgress(progress);
|
||||
responseBean.setCallTitle(applicationView.getCallTitle());
|
||||
responseBean.setCallEndDate(applicationView.getCallEndDate());
|
||||
responseBean.setCallEndTime(applicationView.getCallEndTime());
|
||||
responseBean.setModifiedDate(applicationView.getModifiedDate());
|
||||
responseBean.setCallId(applicationView.getCallId());
|
||||
responseBean.setSubmissionDate(applicationView.getSubmissionDate());
|
||||
responseBean.setStatus(applicationView.getStatus());
|
||||
responseBean.setEvaluationVersion(EvaluationVersionEnum.valueOf(applicationView.getEvaluationVersion()));
|
||||
responseBean.setComments(applicationView.getComments());
|
||||
responseBean.setCompanyId(applicationView.getCompanyId());
|
||||
Optional<AssignedApplicationsEntity> assignedApplicationsOptional =
|
||||
assignedApplicationsRepository.findByApplicationIdAndIsDeletedFalse(applicationView.getId());
|
||||
if(assignedApplicationsOptional.isPresent()){
|
||||
responseBean.setAssignedUserId(assignedApplicationsOptional.get().getUserId());
|
||||
UserEntity user = userService.validateUser(assignedApplicationsOptional.get().getUserId());
|
||||
String firstName = user.getFirstName() != null ? user.getFirstName() : "";
|
||||
String lastName = user.getLastName() != null ? user.getLastName() : "";
|
||||
String userName = String.join(" ", firstName, lastName).trim();
|
||||
responseBean.setAssignedUserName(userName);
|
||||
}
|
||||
CompanyEntity company=companyService.validateCompany(applicationView.getCompanyId());
|
||||
responseBean.setCompanyName(company.getCompanyName());
|
||||
responseBean.setProtocolNumber(applicationView.getProtocolNumber());
|
||||
responseBean.setAmountAccepted(applicationView.getAmountAccepted());
|
||||
responseBean.setAmountRequested(applicationView.getAmountRequested());
|
||||
responseBean.setDateAccepted(applicationView.getDateAccepted());
|
||||
responseBean.setDateRejected(applicationView.getDateRejected());
|
||||
return responseBean;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user