|
|
|
|
@@ -1,7 +1,6 @@
|
|
|
|
|
package net.gepafin.tendermanagement.dao;
|
|
|
|
|
|
|
|
|
|
import jakarta.persistence.criteria.CriteriaBuilder;
|
|
|
|
|
import jakarta.persistence.criteria.Root;
|
|
|
|
|
import jakarta.persistence.criteria.*;
|
|
|
|
|
import net.gepafin.tendermanagement.config.Translator;
|
|
|
|
|
import net.gepafin.tendermanagement.config.jwt.TokenProvider;
|
|
|
|
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
|
|
|
|
@@ -42,7 +41,6 @@ import org.springframework.data.jpa.domain.Specification;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import jakarta.persistence.criteria.Predicate;
|
|
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
|
@@ -55,6 +53,7 @@ import java.text.ParseException;
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.time.LocalTime;
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
@@ -1444,7 +1443,7 @@ public class ApplicationDao {
|
|
|
|
|
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();
|
|
|
|
|
@@ -1455,7 +1454,7 @@ public class ApplicationDao {
|
|
|
|
|
if (pageNo == null || pageNo <= 0) {
|
|
|
|
|
pageNo = GepafinConstant.DEFAULT_PAGE;
|
|
|
|
|
}
|
|
|
|
|
Specification<ApplicationEntity> spec = search(callId,companyId, userWithCompany.getId(), applicationPageableRequestBean, userEntity);
|
|
|
|
|
Specification<ApplicationEntity> spec = search(callId,companyId, userWithCompanyId, applicationPageableRequestBean, userEntity);
|
|
|
|
|
Page<ApplicationEntity> entityPage = applicationRepository.findAll(spec, PageRequest.of(pageNo - 1, pageLimit));
|
|
|
|
|
// Prepare the response
|
|
|
|
|
|
|
|
|
|
@@ -1510,11 +1509,15 @@ public class ApplicationDao {
|
|
|
|
|
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();
|
|
|
|
|
@@ -1567,6 +1570,8 @@ public class ApplicationDao {
|
|
|
|
|
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()));
|
|
|
|
|
@@ -1574,6 +1579,89 @@ public class ApplicationDao {
|
|
|
|
|
|
|
|
|
|
return predicates;
|
|
|
|
|
}
|
|
|
|
|
private void applyFilters(Root<?> root, CriteriaBuilder criteriaBuilder, List<Predicate> predicates, Map<String, FilterCriteria> filters) {
|
|
|
|
|
if (Boolean.FALSE.equals(filters.isEmpty())) {
|
|
|
|
|
for (Map.Entry<String, FilterCriteria> entry : filters.entrySet()) {
|
|
|
|
|
String fieldName = entry.getKey();
|
|
|
|
|
FilterCriteria filterCriteria = entry.getValue();
|
|
|
|
|
Object value = filterCriteria.getValue();
|
|
|
|
|
String matchMode = filterCriteria.getMatchMode();
|
|
|
|
|
|
|
|
|
|
if (value != null && matchMode != null) {
|
|
|
|
|
Path<?> fieldPath = getFieldPath(root, fieldName);
|
|
|
|
|
if (fieldPath != null) {
|
|
|
|
|
applyStringFilter(fieldPath, criteriaBuilder, predicates, value, matchMode);
|
|
|
|
|
applyNumberFilter(fieldPath, criteriaBuilder, predicates, value, matchMode);
|
|
|
|
|
// applyDateFilter(fieldPath, criteriaBuilder, predicates, value, matchMode); // Date filter is commented
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void applyStringFilter(Path<?> fieldPath, CriteriaBuilder criteriaBuilder, List<Predicate> predicates, Object value, String matchMode) {
|
|
|
|
|
if (value instanceof String) {
|
|
|
|
|
String valueStr = (String) value;
|
|
|
|
|
if (fieldPath.getJavaType().equals(String.class)) {
|
|
|
|
|
switch (matchMode.toLowerCase()) {
|
|
|
|
|
case GepafinConstant.CONTAINS ->
|
|
|
|
|
predicates.add(criteriaBuilder.like(criteriaBuilder.lower(fieldPath.as(String.class)), "%" + valueStr.toLowerCase() + "%"));
|
|
|
|
|
case GepafinConstant.EQUALS -> predicates.add(criteriaBuilder.equal(fieldPath, valueStr));
|
|
|
|
|
case GepafinConstant.STARTS_WITH ->
|
|
|
|
|
predicates.add(criteriaBuilder.like(criteriaBuilder.lower(fieldPath.as(String.class)), valueStr.toLowerCase() + "%"));
|
|
|
|
|
case GepafinConstant.ENDS_WITH ->
|
|
|
|
|
predicates.add(criteriaBuilder.like(criteriaBuilder.lower(fieldPath.as(String.class)), "%" + valueStr.toLowerCase()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void applyNumberFilter(Path<?> fieldPath, CriteriaBuilder criteriaBuilder, List<Predicate> predicates, Object value, String matchMode) {
|
|
|
|
|
if (Number.class.isAssignableFrom(fieldPath.getJavaType())) {
|
|
|
|
|
Number numberValue = null;
|
|
|
|
|
if (value instanceof Number) {
|
|
|
|
|
numberValue = (Number) value;
|
|
|
|
|
}
|
|
|
|
|
switch (matchMode.toLowerCase()) {
|
|
|
|
|
case GepafinConstant.EQUALS -> predicates.add(criteriaBuilder.equal(fieldPath, numberValue));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
private void applyDateFilter(Path<?> fieldPath, CriteriaBuilder criteriaBuilder, List<Predicate> predicates, Object value, String matchMode) {
|
|
|
|
|
if (fieldPath.getJavaType().equals(LocalDateTime.class)) {
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
|
|
|
|
|
LocalDateTime dateValue = LocalDateTime.parse(value.toString(), formatter);
|
|
|
|
|
|
|
|
|
|
Expression<String> fieldAsString = criteriaBuilder.function("TO_CHAR", String.class, fieldPath, criteriaBuilder.literal("YYYY-MM-DD HH24:MI:SS.MS"));
|
|
|
|
|
|
|
|
|
|
switch (matchMode.toLowerCase()) {
|
|
|
|
|
case GepafinConstant.EQUALS -> predicates.add(criteriaBuilder.equal(fieldAsString, value.toString()));
|
|
|
|
|
case GepafinConstant.BEFORE -> predicates.add(criteriaBuilder.lessThan(fieldPath.as(LocalDateTime.class), dateValue));
|
|
|
|
|
case GepafinConstant.AFTER -> predicates.add(criteriaBuilder.greaterThan(fieldPath.as(LocalDateTime.class), dateValue));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
LocalDateTime now = DateTimeUtil.DateServerToUTC(LocalDateTime.now());
|
|
|
|
|
|
|
|
|
|
|