Merge branch 'develop' of https://github.com/Kitzanos/GEPAFIN-BE into feature/GEPAFINBE-175

This commit is contained in:
rajesh
2025-02-27 19:20:29 +05:30
30 changed files with 412 additions and 21 deletions

View File

@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Root;
import jakarta.persistence.criteria.*;
import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.*;
@@ -43,19 +44,21 @@ 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;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.MessageFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -65,6 +68,7 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import static org.apache.commons.lang3.StringUtils.isEmpty;
import static org.hibernate.validator.internal.engine.messageinterpolation.el.RootResolver.FORMATTER;
@Component
public class ApplicationDao {
@@ -1492,7 +1496,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();
@@ -1503,7 +1507,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
@@ -1558,11 +1562,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();
@@ -1631,13 +1639,104 @@ public class ApplicationDao {
LocalDateTime pastDate = today.minusDays(daysRange);
predicates.add(criteriaBuilder.between(root.get(GepafinConstant.CREATED_DATE), pastDate, today));
}
predicates.add(criteriaBuilder.isFalse(root.get(GepafinConstant.IS_DELETED)));
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 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();
MatchModeEnum 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,root);
}
}
}
}
}
private void applyStringFilter(Path<?> fieldPath, CriteriaBuilder criteriaBuilder, List<Predicate> predicates, Object value, MatchModeEnum matchMode) {
if (value instanceof String) {
String valueStr = (String) value;
if (fieldPath.getJavaType().equals(String.class)) {
MatchModeEnum mode = MatchModeEnum.fromObject(matchMode.getValue());
switch (mode) {
case CONTAINS ->
predicates.add(criteriaBuilder.like(criteriaBuilder.lower(fieldPath.as(String.class)), "%" + valueStr.toLowerCase() + "%"));
case EQUALS -> predicates.add(criteriaBuilder.equal(fieldPath, valueStr));
case STARTSWITH ->
predicates.add(criteriaBuilder.like(criteriaBuilder.lower(fieldPath.as(String.class)), valueStr.toLowerCase() + "%"));
case ENDSWITH ->
predicates.add(criteriaBuilder.like(criteriaBuilder.lower(fieldPath.as(String.class)), "%" + valueStr.toLowerCase()));
}
}
}
}
private void applyNumberFilter(Path<?> fieldPath, CriteriaBuilder criteriaBuilder, List<Predicate> predicates, Object value, MatchModeEnum matchMode) {
if (Number.class.isAssignableFrom(fieldPath.getJavaType())) {
Number numberValue = null;
if (value instanceof Number) {
numberValue = (Number) value;
}
MatchModeEnum mode = MatchModeEnum.fromObject(matchMode.getValue());
switch (mode) {
case EQUALS -> predicates.add(criteriaBuilder.equal(fieldPath, numberValue));
}
}
}
private void applyDateFilter(Path<?> fieldPath, CriteriaBuilder criteriaBuilder, List<Predicate> predicates, Object value, MatchModeEnum matchMode, Root<?> root) {
if (fieldPath.getJavaType().equals(LocalDateTime.class)) {
LocalDateTime testDateTime = DateTimeUtil.parseStringToLocalDateTime(value.toString());
MatchModeEnum mode = MatchModeEnum.fromObject(matchMode.getValue());
switch (mode) {
// case DATEIS -> predicates.add(criteriaBuilder.equal(fieldPath.as(Timestamp.class), Timestamp.valueOf(testDateTime)));
case DATEISNOT -> predicates.add(criteriaBuilder.notEqual(fieldPath.as(Timestamp.class), Timestamp.valueOf(testDateTime)));
case BEFORE -> predicates.add(criteriaBuilder.lessThan(fieldPath.as(Timestamp.class), Timestamp.valueOf(testDateTime)));
case AFTER -> predicates.add(criteriaBuilder.greaterThan(fieldPath.as(Timestamp.class), Timestamp.valueOf(testDateTime)));
}
}
}
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());