Merge branch 'develop' of https://github.com/Kitzanos/GEPAFIN-BE into develop
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
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;
|
||||
import net.gepafin.tendermanagement.entities.*;
|
||||
import net.gepafin.tendermanagement.entities.SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum;
|
||||
@@ -42,19 +40,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;
|
||||
@@ -64,6 +64,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 {
|
||||
@@ -1444,7 +1445,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 +1456,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 +1511,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();
|
||||
@@ -1583,13 +1588,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());
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ public class CompanyDocumentDao {
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
|
||||
public List<CompanyDocumentResponseBean> uploadFileForCompany(HttpServletRequest request, Long userId, List<MultipartFile> files, Long companyId, Long documentCategoryId, CompanyDocumentTypeEnum companyDocumentSourceTypeEnum, LocalDateTime expirationDate){
|
||||
public List<CompanyDocumentResponseBean> uploadFileForCompany(HttpServletRequest request, Long userId, List<MultipartFile> files, Long companyId, Long documentCategoryId, CompanyDocumentTypeEnum companyDocumentSourceTypeEnum, LocalDateTime expirationDate,String name){
|
||||
DocumentCategoryEntity categoryEntity = categoryDao.validateCategory(documentCategoryId);
|
||||
validator.validateUserWithCompany(request,companyId);
|
||||
UserWithCompanyEntity userWithCompanyEntity=companyService.getUserWithCompany(userId,companyId);
|
||||
@@ -106,6 +106,7 @@ public class CompanyDocumentDao {
|
||||
companyDocumentEntity.setFilePath(uploadFileOnAmazonS3Response.getFilePath());
|
||||
companyDocumentEntity.setIsDeleted(false);
|
||||
companyDocumentEntity.setUploadedBy(userId);
|
||||
companyDocumentEntity.setName(name);
|
||||
if (expirationDate.isBefore(currentDate.plusDays(7))) {
|
||||
companyDocumentEntity.setStatus(CompanyDocumentStatusEnum.DUE.getValue());
|
||||
} else {
|
||||
@@ -159,7 +160,7 @@ public class CompanyDocumentDao {
|
||||
DocumentCategoryEntity categoryEntity = entity.getCategoryEntity();
|
||||
DocumentCategoryResponse responseCategory = categoryDao.convertToResponseBean(categoryEntity);
|
||||
responseBean.setId(entity.getId());
|
||||
responseBean.setName(entity.getFileName());
|
||||
responseBean.setFileName(entity.getFileName());
|
||||
responseBean.setType(CompanyDocumentTypeEnum.valueOf(entity.getType()));
|
||||
responseBean.setFilePath(entity.getFilePath());
|
||||
responseBean.setCompanyId(entity.getCompanyId());
|
||||
@@ -167,9 +168,11 @@ public class CompanyDocumentDao {
|
||||
responseBean.setStatus(entity.getStatus());
|
||||
responseBean.setUploadedBy(entity.getUploadedBy());
|
||||
responseBean.setCategory(responseCategory);
|
||||
responseBean.setName(entity.getName());
|
||||
responseBean.setUserWithCompanyId(entity.getUserWithCompany().getId());
|
||||
responseBean.setCreatedDate(entity.getCreatedDate());
|
||||
responseBean.setUpdatedDate(entity.getUpdatedDate());
|
||||
|
||||
return responseBean;
|
||||
}
|
||||
|
||||
@@ -194,6 +197,7 @@ public class CompanyDocumentDao {
|
||||
DocumentCategoryEntity categoryEntity = categoryDao.validateCategory(companyDocumentRequest.getCategoryId());
|
||||
setIfUpdated(companyDocumentEntity::getCategoryEntity, companyDocumentEntity::setCategoryEntity, categoryEntity);
|
||||
}
|
||||
setIfUpdated(companyDocumentEntity::getName, companyDocumentEntity::setName, companyDocumentRequest.getName());
|
||||
companyDocumentRepository.save(companyDocumentEntity);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "updating company document" operation. **/
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jdk.jfr.Category;
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.DocumentCategoryEntity;
|
||||
@@ -20,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
||||
|
||||
@@ -108,4 +110,11 @@ public class DocumentCategoryDao {
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
public List<DocumentCategoryResponse> getAllDocumentCategory(){
|
||||
List<DocumentCategoryEntity> documentCategoryEntityList = categoryRepository.findAll();
|
||||
return documentCategoryEntityList.stream()
|
||||
.map(this::convertToResponseBean)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user