Resolved conflicts
This commit is contained in:
@@ -2,8 +2,10 @@ package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Join;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
@@ -12,6 +14,7 @@ import net.gepafin.tendermanagement.entities.SystemEmailTemplatesEntity.SystemEm
|
||||
import net.gepafin.tendermanagement.enums.*;
|
||||
import net.gepafin.tendermanagement.model.request.*;
|
||||
import net.gepafin.tendermanagement.model.response.*;
|
||||
import net.gepafin.tendermanagement.model.util.SortBy;
|
||||
import net.gepafin.tendermanagement.repositories.*;
|
||||
import net.gepafin.tendermanagement.service.*;
|
||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||
@@ -25,6 +28,8 @@ import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -37,6 +42,7 @@ import java.util.stream.Collectors;
|
||||
import static java.time.temporal.ChronoUnit.DAYS;
|
||||
import static net.gepafin.tendermanagement.util.Utils.log;
|
||||
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
||||
import static org.apache.commons.lang3.StringUtils.isEmpty;
|
||||
|
||||
@Component
|
||||
public class ApplicationAmendmentRequestDao {
|
||||
@@ -119,6 +125,15 @@ public class ApplicationAmendmentRequestDao {
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
private EvaluationFormRepository evaluationFormRepository;
|
||||
|
||||
@Autowired
|
||||
private ApplicationEvaluationFormFieldRepository applicationEvaluationFormFieldRepository;
|
||||
|
||||
@Autowired
|
||||
private ApplicationEvaluationFormRepository applicationEvaluationFormRepository;
|
||||
|
||||
public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(Long applicationEvaluationId) {
|
||||
log.info("Fetching the application data for the Amendment process {}", applicationEvaluationId);
|
||||
ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluation(applicationEvaluationId);
|
||||
@@ -132,16 +147,10 @@ public class ApplicationAmendmentRequestDao {
|
||||
if(file != null){
|
||||
evaluationFileRequests=Utils.convertJsonStringToList(file,FieldRequest.class);
|
||||
}
|
||||
Boolean allValid = evaluationFileRequests.stream()
|
||||
.anyMatch(fieldRequest -> fieldRequest.getValid() == null);
|
||||
if(checkList != null) {
|
||||
checklistRequests=Utils.convertJsonStringToList(checkList,ChecklistRequest.class);
|
||||
}
|
||||
boolean resultCheckList = checklistRequests.stream()
|
||||
.anyMatch(checklistRequest -> Boolean.TRUE.equals(checklistRequest.getValid())) ? false : true;
|
||||
|
||||
if(Boolean.TRUE.equals(allValid) || Boolean.TRUE.equals(resultCheckList)){
|
||||
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.All_DOCUMENT_CHECKED_AND_ONE_CHECKLIST_CHECKED));
|
||||
if(applicationEvaluationEntity.getEvaluationVersion().equals(EvaluationVersionEnum.V1.getValue())) {
|
||||
checklistValidationForEvaluationV1(evaluationFileRequests, checkList, checklistRequests);
|
||||
} else if (applicationEvaluationEntity.getEvaluationVersion().equals(EvaluationVersionEnum.V2.getValue())) {
|
||||
validationCheckEvaluationV2(applicationEvaluationEntity, application);
|
||||
}
|
||||
// Set common application-level details
|
||||
String callName = application.getCall().getName();
|
||||
@@ -186,6 +195,47 @@ public class ApplicationAmendmentRequestDao {
|
||||
return response;
|
||||
}
|
||||
|
||||
private void validationCheckEvaluationV2(ApplicationEvaluationEntity applicationEvaluationEntity, ApplicationEntity application) {
|
||||
Long callId= applicationEvaluationEntity.getAssignedApplicationsEntity().getApplication().getCall().getId();
|
||||
EvaluationFormEntity evaluationFormEntity=evaluationFormRepository.findByCallIdAndIsDeletedFalse(callId);
|
||||
Long numberOfCheck= application.getCall().getNumberOfCheck();
|
||||
ApplicationEvaluationFormEntity applicationEvaluationForm=applicationEvaluationFormRepository.findByApplicationEvaluation_IdAndIsDeletedFalse(applicationEvaluationEntity.getId());
|
||||
List<ContentResponseBean> contentResponseBeans=Utils.convertJsonStringToList(evaluationFormEntity.getContent(),ContentResponseBean.class);
|
||||
int count = 0;
|
||||
for (ContentResponseBean content : contentResponseBeans) {
|
||||
if (GepafinConstant.SWITCH.equals(content.getName()) && content.getSettings().stream()
|
||||
.anyMatch(setting -> GepafinConstant.IS_CHECK_LIST_ITEM.equals(setting.getName()))) {
|
||||
|
||||
ApplicationEvaluationFormFieldEntity field = applicationEvaluationFormFieldRepository
|
||||
.findByFieldIdAndApplicationEvaluationFormId(content.getId(), applicationEvaluationForm.getId());
|
||||
|
||||
if (field != null && Utils.isValidBoolean(field.getFieldValue())) {
|
||||
Boolean fieldValueAsBoolean = Boolean.parseBoolean(field.getFieldValue());
|
||||
|
||||
if (Boolean.FALSE.equals(fieldValueAsBoolean)) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,GepafinConstant.VALIDATION_FAILED_FOR_CHECKLIST);
|
||||
}
|
||||
|
||||
if (++count >= numberOfCheck) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void checklistValidationForEvaluationV1(List<FieldRequest> evaluationFileRequests, String checkList, List<ChecklistRequest> checklistRequests) {
|
||||
Boolean allValid = evaluationFileRequests.stream()
|
||||
.anyMatch(fieldRequest -> fieldRequest.getValid() == null);
|
||||
if(checkList != null) {
|
||||
checklistRequests =Utils.convertJsonStringToList(checkList,ChecklistRequest.class);
|
||||
}
|
||||
boolean resultCheckList = checklistRequests.stream()
|
||||
.anyMatch(checklistRequest -> Boolean.TRUE.equals(checklistRequest.getValid())) ? false : true;
|
||||
|
||||
if(Boolean.TRUE.equals(allValid) || Boolean.TRUE.equals(resultCheckList)){
|
||||
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.All_DOCUMENT_CHECKED_AND_ONE_CHECKLIST_CHECKED));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<AmendmentFormFieldResponse> getIdAndLabelFromResult(List<Map<String, Object>> result) {
|
||||
List<AmendmentFormFieldResponse> formFieldResponses = new ArrayList<>();
|
||||
@@ -1083,7 +1133,7 @@ public class ApplicationAmendmentRequestDao {
|
||||
List<ApplicationAmendmentRequestResponse> response = new ArrayList<>();
|
||||
if (applicationAmendmentRequestEntity != null) {
|
||||
response = applicationAmendmentRequestEntity.stream()
|
||||
.map(entity -> convertEntityToResponse(entity, false))
|
||||
.map(entity -> convertEntityToResponse(entity, true))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return response;
|
||||
@@ -1214,4 +1264,118 @@ public class ApplicationAmendmentRequestDao {
|
||||
documentService.deleteFile(documentId);
|
||||
}
|
||||
|
||||
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())) {
|
||||
predicates.add(root.get("applicationEvaluationEntity").get("assignedApplicationsEntity").get("application").get("userId").in(userId));
|
||||
}
|
||||
if (Boolean.FALSE.equals(validator.checkIsBeneficiary())) {
|
||||
predicates.add(root.get("applicationEvaluationEntity").get("assignedApplicationsEntity").get("userId").in(userId));
|
||||
}
|
||||
|
||||
return predicates;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,8 +117,8 @@ public class ApplicationDao {
|
||||
@Autowired
|
||||
private AssignedApplicationsRepository assignedApplicationsRepository;
|
||||
|
||||
@Value("${default_System_Receiver_Email}")
|
||||
private String defaultSystemReceiverEmail;
|
||||
// @Value("${default_System_Receiver_Email}")
|
||||
// private String defaultSystemReceiverEmail;
|
||||
|
||||
@Value("${rinaldo_email}")
|
||||
private String rinaldoEmail;
|
||||
@@ -1132,22 +1132,28 @@ public class ApplicationDao {
|
||||
// mailUtil.sendByMailGun(subject, body, List.of(defaultSystemReceiverEmail), null);
|
||||
// mailUtil.sendByMailGun(subject, body, List.of(gepafinEmail), null);
|
||||
// mailUtil.sendByMailGun(subject, body, List.of(rinaldoEmail), null);
|
||||
if(Boolean.TRUE.equals(hub.getUniqueUuid().equals(defaultHubUuid))) {
|
||||
if (validator.isProductionProfileActivated()) {
|
||||
emailLogRequest.setRecipientEmails(carloEmail);
|
||||
// mailUtil.sendByMailGun(subject, body, List.of(carloEmail), null);
|
||||
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(carloEmail),emailLogRequest);
|
||||
}
|
||||
List<String> listDefaultSystemReceiverEmail = Arrays.stream(defaultSystemReceiverEmail.split(","))
|
||||
.map(String::trim)
|
||||
.filter(email -> !email.isEmpty())
|
||||
.toList();
|
||||
// if(Boolean.TRUE.equals(hub.getUniqueUuid().equals(defaultHubUuid))) {
|
||||
// if (validator.isProductionProfileActivated()) {
|
||||
// emailLogRequest.setRecipientEmails(carloEmail);
|
||||
//// mailUtil.sendByMailGun(subject, body, List.of(carloEmail), null);
|
||||
// emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(carloEmail),emailLogRequest);
|
||||
// }
|
||||
// List<String> listDefaultSystemReceiverEmail = Arrays.stream(defaultSystemReceiverEmail.split(","))
|
||||
// .map(String::trim)
|
||||
// .filter(email -> !email.isEmpty())
|
||||
// .toList();
|
||||
//
|
||||
// emailLogRequest.setRecipientEmails(defaultSystemReceiverEmail);
|
||||
// emailNotificationDao.sendMail(hub.getId(), subject, body, listDefaultSystemReceiverEmail, emailLogRequest);
|
||||
// }
|
||||
|
||||
List<String> hubEmails = Arrays.stream(hub.getEmail().split(","))
|
||||
.map(String::trim)
|
||||
.filter(email -> !email.isEmpty())
|
||||
.toList();
|
||||
|
||||
emailLogRequest.setRecipientEmails(defaultSystemReceiverEmail);
|
||||
emailNotificationDao.sendMail(hub.getId(), subject, body, listDefaultSystemReceiverEmail, emailLogRequest);
|
||||
}
|
||||
emailLogRequest.setRecipientEmails(hub.getEmail());
|
||||
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(hub.getEmail()),emailLogRequest);
|
||||
emailNotificationDao.sendMail(hub.getId(), subject, body,hubEmails,emailLogRequest);
|
||||
emailLogRequest.setRecipientEmails(rinaldoEmail);
|
||||
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(rinaldoEmail),emailLogRequest);
|
||||
}
|
||||
@@ -1532,6 +1538,22 @@ public class ApplicationDao {
|
||||
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).get(GepafinConstant.NAME)), // Adjust field name
|
||||
"%" + search.toUpperCase() + "%"
|
||||
);
|
||||
|
||||
// predicates.add(criteriaBuilder.or(protocolPredicate));
|
||||
predicates.add(criteriaBuilder.or(callNamePredicate));
|
||||
predicates.add(criteriaBuilder.or(titlePredicate));
|
||||
}
|
||||
|
||||
@@ -1714,5 +1736,11 @@ public class ApplicationDao {
|
||||
// Step 4: Evaluate the mathematical expression
|
||||
return Utils.evaluateExpression(expression);
|
||||
}
|
||||
|
||||
public ApplicationEntity validateApplicationWithCompany(Long id,Long companyId) {
|
||||
ApplicationEntity application=applicationRepository.findByIdAndCompanyIdAndIsDeletedFalse(id,companyId);
|
||||
if (application==null){
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,Translator.toLocale(GepafinConstant.PERMISSION_DENIED));
|
||||
}
|
||||
return application;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.MessageFormat;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
@@ -298,7 +297,7 @@ public class ApplicationEvaluationDao {
|
||||
response.setCreatedDate(entity.getCreatedDate());
|
||||
response.setUpdatedDate(entity.getUpdatedDate());
|
||||
response.setNumberOfCheck(entity.getAssignedApplicationsEntity().getApplication().getCall().getNumberOfCheck());
|
||||
response.setProductId(entity.getAssignedApplicationsEntity().getApplication().getCall().getProductId());
|
||||
response.setAppointmentTemplateId(entity.getAssignedApplicationsEntity().getApplication().getCall().getAppointmentTemplateId());
|
||||
|
||||
}
|
||||
|
||||
@@ -1159,7 +1158,7 @@ public class ApplicationEvaluationDao {
|
||||
LocalDateTime callEndDate = application.getCall().getEndDate();
|
||||
response.setCallEndDate(callEndDate);
|
||||
response.setNumberOfCheck(call.getNumberOfCheck());
|
||||
response.setProductId(call.getProductId());
|
||||
response.setAppointmentTemplateId(call.getAppointmentTemplateId());
|
||||
setCriteriaResponses(entity, application.getId(), response, evaluationCriterias);
|
||||
setChecklistResponses(entity, application.getId(), response, checklistEntities);
|
||||
setFileResponses(entity, application.getId(), response, applicationFormEntities);
|
||||
@@ -2210,7 +2209,8 @@ public class ApplicationEvaluationDao {
|
||||
|
||||
ApplicationEvaluationFormResponse response = objectMapper.convertValue(convertedResponse, ApplicationEvaluationFormResponse.class);
|
||||
EvaluationFormEntity evaluationFormEntity = evaluationFormRepository.findByCallIdAndIsDeletedFalse(evaluationEntity.getAssignedApplicationsEntity().getApplication().getCall().getId());
|
||||
|
||||
response.setNumberOfCheck(evaluationEntity.getAssignedApplicationsEntity().getApplication().getCall().getNumberOfCheck());
|
||||
response.setAppointmentTemplateId(evaluationEntity.getAssignedApplicationsEntity().getApplication().getApplicationEvaluationId());
|
||||
if (evaluationFormEntity != null) {
|
||||
response.setApplicationEvaluationFormResponse(convertEvaluationFormToResponse(evaluationFormEntity, evaluationEntity));
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import com.amazonaws.services.s3.AmazonS3Client;
|
||||
import com.amazonaws.services.s3.model.GetObjectRequest;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import feign.FeignException;
|
||||
@@ -16,18 +17,14 @@ import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
||||
import net.gepafin.tendermanagement.entities.CompanyEntity;
|
||||
import net.gepafin.tendermanagement.entities.DocumentEntity;
|
||||
import net.gepafin.tendermanagement.entities.HubEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.NotificationTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.request.AppointmentCreationRequest;
|
||||
import net.gepafin.tendermanagement.model.request.AppointmentNdgRequest;
|
||||
import net.gepafin.tendermanagement.model.request.AppointmentVisuraListRequest;
|
||||
import net.gepafin.tendermanagement.model.request.AppointmentVisuraRequest;
|
||||
import net.gepafin.tendermanagement.model.request.CreateAppointmentRequest;
|
||||
import net.gepafin.tendermanagement.model.request.NotificationReq;
|
||||
import net.gepafin.tendermanagement.model.request.UploadDocToExternalSystemRequest;
|
||||
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
||||
import net.gepafin.tendermanagement.model.response.AppointmentCreationResponse;
|
||||
@@ -63,7 +60,6 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -406,10 +402,15 @@ public class AppointmentDao {
|
||||
}
|
||||
// Handle non-OK response
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.ERROR_IN_GENERATING_NDG_TRY_AGAIN));
|
||||
} catch (FeignException.Forbidden forbiddenException) {
|
||||
logForbiddenError();
|
||||
// Regenerate the token and retry
|
||||
regenerateTokenAndSave(hub);
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to authenticate user on Odessa : {}", e.getMessage(), e);
|
||||
throw new RuntimeException("Authentication failed on Odessa. try again", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private AppointmentLoginResponse retrieveNdgByVatNumber(String vatNumber, String authorizationToken, HubEntity hub, ApplicationEntity application) {
|
||||
@@ -626,7 +627,11 @@ public class AppointmentDao {
|
||||
|
||||
// Generate authorization token and fetch template data
|
||||
String authorizationToken = getBearerToken(hub);
|
||||
ResponseEntity<Object> response = appointmentApiService.getAppointmentTemplateForTemplateCreation(authorizationToken);
|
||||
Long appointmentTemplateId = application.getCall().getAppointmentTemplateId();
|
||||
if (appointmentTemplateId == null) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPOINTMENT_CANNOT_BE_CREATED));
|
||||
}
|
||||
ResponseEntity<Object> response = appointmentApiService.getAppointmentTemplateForTemplateCreation(authorizationToken, appointmentTemplateId);
|
||||
|
||||
if (response.getStatusCode() != HttpStatus.OK) {
|
||||
log.error("Failed to retrieve appointment template for appointment creation. Status: {}", response.getStatusCode());
|
||||
@@ -638,7 +643,7 @@ public class AppointmentDao {
|
||||
AppointmentCreationRequest templateRichiestaData = parseTemplateResponseData(responseDataForTemplate);
|
||||
|
||||
// Build the appointment request body
|
||||
AppointmentCreationRequest appointmentCreationRequest = buildAppointmentCreationRequest(applicationId, createAppointmentRequest, hub.getAreaCode(),
|
||||
AppointmentCreationRequest appointmentCreationRequest = buildAppointmentCreationRequest(applicationId, createAppointmentRequest, appointmentTemplateId,
|
||||
templateRichiestaData);
|
||||
String appointmentRequestBody = Utils.convertObjectToJson(appointmentCreationRequest);
|
||||
|
||||
@@ -646,16 +651,17 @@ public class AppointmentDao {
|
||||
ResponseEntity<Object> appointmentResponse = appointmentApiService.createAppointment(authorizationToken, context, appointmentRequestBody);
|
||||
String appointmentId = extractAppointmentIdFromResponse(appointmentResponse);
|
||||
|
||||
if (appointmentId != null) {
|
||||
// Update application with the appointment ID
|
||||
application.setAppointmentId(appointmentId);
|
||||
application.setStatus(ApplicationStatusTypeEnum.APPOINTMENT.getValue());
|
||||
applicationRepository.save(application);
|
||||
|
||||
// Log version history
|
||||
loggingUtil.addVersionHistory(
|
||||
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationData).newData(application).build());
|
||||
if (appointmentId == null) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPOINTMENT_NOT_CREATED));
|
||||
}
|
||||
// Update application with the appointment ID
|
||||
application.setAppointmentId(appointmentId);
|
||||
application.setStatus(ApplicationStatusTypeEnum.APPOINTMENT.getValue());
|
||||
applicationRepository.save(application);
|
||||
|
||||
// Log version history
|
||||
loggingUtil.addVersionHistory(
|
||||
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationData).newData(application).build());
|
||||
|
||||
appointmentCreationResponse.setAppointmentId(appointmentId);
|
||||
return appointmentCreationResponse;
|
||||
@@ -684,32 +690,64 @@ public class AppointmentDao {
|
||||
public AppointmentCreationRequest parseTemplateResponseData(String jsonResponse) {
|
||||
|
||||
try {
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
JsonNode rootNode = objectMapper.readTree(jsonResponse);
|
||||
JsonNode richiestaClienteArray = rootNode.path(GepafinConstant.DATA_STRING).path(GepafinConstant.RICHIESTA_CLIENTE_STRING);
|
||||
JsonNode richiesteClienteArray = rootNode.path(GepafinConstant.DATA_STRING).path(GepafinConstant.RICHIESTE_CLIENTE_STRING);
|
||||
|
||||
// Initialize the result object
|
||||
AppointmentCreationRequest appointmentCreationRequest = new AppointmentCreationRequest();
|
||||
AppointmentCreationRequest.Input input = new AppointmentCreationRequest.Input();
|
||||
|
||||
// Map `richiestaCliente` array
|
||||
List<AppointmentCreationRequest.RichiestaCliente> richiestaClienteList = new ArrayList<>();
|
||||
if (richiestaClienteArray.isArray()) {
|
||||
for (JsonNode richiestaNode : richiestaClienteArray) {
|
||||
richiestaClienteList.add(objectMapper.treeToValue(richiestaNode, AppointmentCreationRequest.RichiestaCliente.class));
|
||||
}
|
||||
if (!richiesteClienteArray.isArray()) {
|
||||
log.warn("richiesteCliente array is missing or not an array.");
|
||||
return new AppointmentCreationRequest();
|
||||
}
|
||||
for (JsonNode richiestaNode : richiesteClienteArray) {
|
||||
if (richiestaNode.isNull())
|
||||
continue;
|
||||
|
||||
AppointmentCreationRequest.RichiestaCliente richiestaCliente = new AppointmentCreationRequest.RichiestaCliente();
|
||||
JsonNode prodottoNode = richiestaNode.path(AppointmentApiConstant.PRODOTTO);
|
||||
String prodottoCode = prodottoNode.path(AppointmentApiConstant.PRODOTTO_CODE).asText();
|
||||
|
||||
richiestaCliente.setCodProdotto(prodottoCode);
|
||||
richiestaCliente.setIdMotivazione(getIntValue(richiestaNode));
|
||||
richiestaCliente.setCodAbi(getTextValue(richiestaNode, AppointmentApiConstant.COD_ABI));
|
||||
richiestaCliente.setCodCab(getTextValue(richiestaNode, AppointmentApiConstant.COD_CAB));
|
||||
richiestaCliente.setIdNota(getTextValue(richiestaNode, AppointmentApiConstant.ID_NOTA));
|
||||
richiestaCliente.setImportoAgevolato(getTextValue(richiestaNode, AppointmentApiConstant.IMPORTO_AGEVOLATO));
|
||||
richiestaCliente.setImportoMedioLungoTermine(getTextValue(richiestaNode, AppointmentApiConstant.IMPORTO_MEDIOLUNGO_TERMINE));
|
||||
richiestaCliente.setCodTipoProdotto(getTextValue(richiestaNode, AppointmentApiConstant.COD_TIPO_PRODOTTO));
|
||||
richiestaCliente.setCodCategoriaProdotto(getTextValue(richiestaNode, AppointmentApiConstant.COD_CATEGORIA_PRODOTTO));
|
||||
richiestaCliente.setCodFormaTecnica(getTextValue(richiestaNode, AppointmentApiConstant.COD_FORMATECNICA));
|
||||
richiestaCliente.setCodOperazione(getTextValue(richiestaNode, AppointmentApiConstant.COD_OPERAZIONE));
|
||||
|
||||
richiestaClienteList.add(richiestaCliente);
|
||||
}
|
||||
|
||||
input.setRichiestaCliente(richiestaClienteList);
|
||||
appointmentCreationRequest.setInput(input);
|
||||
|
||||
return appointmentCreationRequest;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Error parsing template response: {}", e.getMessage(), e);
|
||||
throw new IllegalStateException("Failed to parse template response", e);
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("JSON processing error: {}", e.getMessage(), e);
|
||||
throw new IllegalStateException("Invalid JSON structure in template response", e);
|
||||
}
|
||||
}
|
||||
|
||||
public AppointmentCreationRequest buildAppointmentCreationRequest(Long applicationId, CreateAppointmentRequest createAppointmentRequest, String areaCode,
|
||||
private String getTextValue(JsonNode node, String fieldName) {
|
||||
|
||||
return node.path(fieldName).isTextual() ? node.path(fieldName).asText() : null;
|
||||
}
|
||||
|
||||
private int getIntValue(JsonNode node) {
|
||||
|
||||
return node.path(AppointmentApiConstant.MOTIVAZIONE).path(AppointmentApiConstant.MOTIVAZIONE_ID).asInt();
|
||||
}
|
||||
|
||||
public AppointmentCreationRequest buildAppointmentCreationRequest(Long applicationId, CreateAppointmentRequest createAppointmentRequest, Long areaCode,
|
||||
AppointmentCreationRequest templateRichiestaData) {
|
||||
|
||||
ApplicationEntity application = applicationService.validateApplication(applicationId);
|
||||
@@ -733,7 +771,8 @@ public class AppointmentDao {
|
||||
requestNota.setTitolo(nota.getTitolo());
|
||||
requestNota.setTesto(nota.getTesto());
|
||||
richiestaCliente.setNota(requestNota);
|
||||
|
||||
richiestaCliente.setDurataMesiFinanziamento(createAppointmentRequest.getDurataMesiFinanziamento());
|
||||
richiestaCliente.setImportoBreveTermine(createAppointmentRequest.getImportoBreveTermine());
|
||||
richiestaClienteList.add(richiestaCliente);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,24 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.*;
|
||||
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.AssignedApplicationEnum;
|
||||
import net.gepafin.tendermanagement.model.request.*;
|
||||
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.*;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationEvaluationRequest;
|
||||
import net.gepafin.tendermanagement.model.request.AssignedApplicationsRequest;
|
||||
import net.gepafin.tendermanagement.model.request.UpdateAssignedApplicationRequest;
|
||||
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
||||
import net.gepafin.tendermanagement.model.response.ApplicationResponse;
|
||||
import net.gepafin.tendermanagement.model.response.AssignedApplicationsResponse;
|
||||
import net.gepafin.tendermanagement.model.response.PageableResponseBean;
|
||||
import net.gepafin.tendermanagement.model.util.SortBy;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationEvaluationRepository;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
||||
import net.gepafin.tendermanagement.repositories.AssignedApplicationsRepository;
|
||||
@@ -26,17 +33,20 @@ import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationExceptio
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.gepafin.tendermanagement.util.Utils.log;
|
||||
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
||||
import static org.apache.commons.lang3.StringUtils.isEmpty;
|
||||
|
||||
@Component
|
||||
public class AssignedApplicationsDao {
|
||||
@@ -201,7 +211,9 @@ public class AssignedApplicationsDao {
|
||||
assignedApplicationsResponse.setEvaluationEndDate(applicationEvaluationEntity.get().getEndDate());
|
||||
}
|
||||
assignedApplicationsResponse.setNumberOfCheck(application.getCall().getNumberOfCheck());
|
||||
assignedApplicationsResponse.setProductId(application.getCall().getProductId());
|
||||
assignedApplicationsResponse.setAppointmentTemplateId(application.getCall().getAppointmentTemplateId());
|
||||
assignedApplicationsResponse.setNdg(application.getNdg());
|
||||
assignedApplicationsResponse.setAppointmentId(application.getAppointmentId());
|
||||
return assignedApplicationsResponse;
|
||||
}
|
||||
|
||||
@@ -288,6 +300,118 @@ public class AssignedApplicationsDao {
|
||||
log.info("Assigned application fetched successfully: {}", response);
|
||||
return response;
|
||||
}
|
||||
public PageableResponseBean<List<AssignedApplicationsResponse>> getAllAssignedApplicationsByPagination(UserEntity user, AssignedApplicationPageableRequestBean assignedApplicationPageableRequestBean,Long userId) {
|
||||
Integer pageNo = null;
|
||||
Integer pageLimit = null;
|
||||
if (assignedApplicationPageableRequestBean.getGlobalFilters() != null) {
|
||||
pageNo = assignedApplicationPageableRequestBean.getGlobalFilters().getPage();
|
||||
pageLimit = assignedApplicationPageableRequestBean.getGlobalFilters().getLimit();
|
||||
}
|
||||
if (pageLimit == null || pageLimit <= 0) {
|
||||
pageLimit = GepafinConstant.DEFAULT_PAGE_LIMIT;
|
||||
}
|
||||
if (pageNo == null || pageNo <= 0) {
|
||||
pageNo = GepafinConstant.DEFAULT_PAGE;
|
||||
}
|
||||
Specification<AssignedApplicationsEntity> spec = searchByPagination( assignedApplicationPageableRequestBean, user,userId);
|
||||
Page<AssignedApplicationsEntity> entityPage = assignedApplicationsRepository.findAll(spec, PageRequest.of(pageNo - 1, pageLimit));
|
||||
// Prepare the response
|
||||
|
||||
|
||||
List<AssignedApplicationsResponse> assignedApplicationsResponses = entityPage.getContent().stream()
|
||||
.map(application -> {
|
||||
AssignedApplicationsResponse response = convertEntityToResponse(application);
|
||||
return response;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
|
||||
PageableResponseBean<List<AssignedApplicationsResponse>> pageableResponseBean = new PageableResponseBean<>();
|
||||
pageableResponseBean.setBody(assignedApplicationsResponses);
|
||||
pageableResponseBean.setCurrentPage(entityPage.getNumber() + 1);
|
||||
pageableResponseBean.setTotalPages(entityPage.getTotalPages());
|
||||
pageableResponseBean.setTotalRecords(entityPage.getTotalElements());
|
||||
pageableResponseBean.setPageSize(entityPage.getSize());
|
||||
|
||||
return pageableResponseBean;
|
||||
}
|
||||
|
||||
public Specification<AssignedApplicationsEntity> searchByPagination(AssignedApplicationPageableRequestBean assignedApplicationPageableRequestBean, UserEntity userEntity,Long userId) {
|
||||
return (root, query, criteriaBuilder) -> {
|
||||
|
||||
List<Predicate> predicates = getPredicates(assignedApplicationPageableRequestBean, criteriaBuilder, root, userEntity,userId);
|
||||
SortBy sortBy = new SortBy(GepafinConstant.CREATED_DATE, true);
|
||||
|
||||
if (assignedApplicationPageableRequestBean.getGlobalFilters() != null
|
||||
&& assignedApplicationPageableRequestBean.getGlobalFilters().getSortBy() != null &&
|
||||
assignedApplicationPageableRequestBean.getGlobalFilters().getSortBy().getColumnName() != null && Boolean.FALSE.equals(
|
||||
isEmpty(assignedApplicationPageableRequestBean.getGlobalFilters().getSortBy().getColumnName()))) {
|
||||
sortBy.setColumnName(assignedApplicationPageableRequestBean.getGlobalFilters().getSortBy().getColumnName());
|
||||
sortBy.setSortDesc(true);
|
||||
if (assignedApplicationPageableRequestBean.getGlobalFilters().getSortBy().getSortDesc() != null) {
|
||||
sortBy.setSortDesc(assignedApplicationPageableRequestBean.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(AssignedApplicationPageableRequestBean assignedApplicationPageableRequestBean,
|
||||
CriteriaBuilder criteriaBuilder, Root<AssignedApplicationsEntity> root, UserEntity userEntity,Long userId) {
|
||||
|
||||
Integer year = null;
|
||||
String search = null;
|
||||
if (assignedApplicationPageableRequestBean.getGlobalFilters() != null) {
|
||||
year = assignedApplicationPageableRequestBean.getGlobalFilters().getYear();
|
||||
search = assignedApplicationPageableRequestBean.getGlobalFilters().getSearch();
|
||||
}
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
|
||||
Boolean isBeneficiary = validator.checkIsBeneficiary();
|
||||
if (userId!=null) {
|
||||
predicates.add(criteriaBuilder.equal(root.get(GepafinConstant.USER_ID), userId));
|
||||
}
|
||||
if (year != null && year > 0) {
|
||||
int filterYear = assignedApplicationPageableRequestBean.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.NOTE)),
|
||||
"%" + search.toUpperCase() + "%"
|
||||
);
|
||||
predicates.add(criteriaBuilder.or(titlePredicate));
|
||||
}
|
||||
|
||||
// Filter by `status` (if status list is provided)
|
||||
if (assignedApplicationPageableRequestBean.getStatus() != null && !assignedApplicationPageableRequestBean.getStatus().isEmpty()) {
|
||||
List<String> statusValues = assignedApplicationPageableRequestBean.getStatus().stream()
|
||||
.map(AssignedApplicationEnum::name) // Convert enum to string
|
||||
.toList();
|
||||
predicates.add(root.get(GepafinConstant.STATUS).in(statusValues));
|
||||
}
|
||||
predicates.add(criteriaBuilder.isFalse(root.get(GepafinConstant.IS_DELETED)));
|
||||
|
||||
|
||||
|
||||
return predicates;
|
||||
|
||||
}
|
||||
public AssignedApplicationsResponse updateAssignedApplicationStatus(HttpServletRequest request, Long assignedApplicationId, AssignedApplicationEnum status) {
|
||||
|
||||
AssignedApplicationsEntity assignedApplication = validateAssignedApplication(assignedApplicationId);
|
||||
|
||||
@@ -202,7 +202,7 @@ public class CallDao {
|
||||
callEntity.setEndTime(DateTimeUtil.parseTime(createCallRequest.getEndTime()));
|
||||
callEntity.setHub(userEntity.getHub());
|
||||
callEntity.setNumberOfCheck(createCallRequest.getNumberOfCheck());
|
||||
callEntity.setProductId(createCallRequest.getProductId());
|
||||
callEntity.setAppointmentTemplateId(createCallRequest.getAppointmentTemplateId());
|
||||
callEntity = callRepository.save(callEntity);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Create Call" operation. **/
|
||||
@@ -610,7 +610,7 @@ public class CallDao {
|
||||
setIfUpdated(callEntity::getConfidi, callEntity::setConfidi, updateCallRequest.getConfidi());
|
||||
setIfUpdated(callEntity::getEvaluationVersion, callEntity::setEvaluationVersion, updateCallRequest.getEvaluationVersion().getValue());
|
||||
setIfUpdated(callEntity::getNumberOfCheck, callEntity::setNumberOfCheck, updateCallRequest.getNumberOfCheck());
|
||||
setIfUpdated(callEntity::getProductId, callEntity::setProductId, updateCallRequest.getProductId());
|
||||
setIfUpdated(callEntity::getAppointmentTemplateId, callEntity::setAppointmentTemplateId, updateCallRequest.getAppointmentTemplateId());
|
||||
callEntity = callRepository.save(callEntity);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "update call step 1" operation **/
|
||||
@@ -718,7 +718,7 @@ public class CallDao {
|
||||
callDetailsResponseBean.setCreatedDate(callEntity.getCreatedDate());
|
||||
callDetailsResponseBean.setUpdatedDate(callEntity.getUpdatedDate());
|
||||
callDetailsResponseBean.setNumberOfCheck(callEntity.getNumberOfCheck());
|
||||
callDetailsResponseBean.setProductId(callEntity.getProductId());
|
||||
callDetailsResponseBean.setAppointmentTemplateId(callEntity.getAppointmentTemplateId());
|
||||
return callDetailsResponseBean;
|
||||
}
|
||||
|
||||
@@ -743,7 +743,7 @@ public class CallDao {
|
||||
createCallResponseBean.setAimedTo(amiedTo);
|
||||
createCallResponseBean.setCheckList(checkList);
|
||||
createCallResponseBean.setNumberOfCheck(callEntity.getNumberOfCheck());
|
||||
createCallResponseBean.setProductId(callEntity.getProductId());
|
||||
createCallResponseBean.setAppointmentTemplateId(callEntity.getAppointmentTemplateId());
|
||||
return createCallResponseBean;
|
||||
}
|
||||
|
||||
|
||||
@@ -122,10 +122,40 @@ public class CompanyDao {
|
||||
userWithCompanyEntity.setPec(companyRequest.getPec());
|
||||
userWithCompanyEntity.setContactName(companyRequest.getContactName());
|
||||
userWithCompanyEntity.setContactEmail(companyRequest.getContactEmail());
|
||||
userWithCompanyEntity.setJson(Utils.convertMapIntoJsonString(companyRequest.getVatCheckResponse()) );
|
||||
UserWithCompanyEntity userWithCompany = userWithCompanyRepository.save(userWithCompanyEntity);
|
||||
/** This code is responsible for adding a version history log for the "adding user with company" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(null).newData(userWithCompany).build());
|
||||
if (StringUtils.isEmpty(companyEntity.getJson())) {
|
||||
companyEntity.setJson(Utils.convertMapIntoJsonString(companyRequest.getVatCheckResponse()));
|
||||
Map<String, Object> vatCheckResponse = companyRequest.getVatCheckResponse();
|
||||
Map<String, Object> data = (Map<String, Object>) vatCheckResponse.get("data");
|
||||
if (data != null) {
|
||||
if (data.containsKey("dettaglio")) {
|
||||
Map<String, Object> dettaglio = (Map<String, Object>) data.get("dettaglio");
|
||||
if (dettaglio != null) {
|
||||
if (dettaglio.containsKey("codice_ateco")) {
|
||||
Object codiceAtecoObj = dettaglio.get("codice_ateco");
|
||||
String codiceAteco = (codiceAtecoObj != null) ? codiceAtecoObj.toString() : null;
|
||||
|
||||
if (codiceAteco != null) {
|
||||
companyEntity.setCodiceAteco(codiceAteco);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companyEntity = companyRepository.save(companyEntity);
|
||||
|
||||
/** This code is responsible for adding a version history log for "updating company json field" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder()
|
||||
.request(request)
|
||||
.actionType(VersionActionTypeEnum.INSERT)
|
||||
.oldData(null)
|
||||
.newData(companyEntity)
|
||||
.build());
|
||||
}
|
||||
|
||||
return userWithCompany;
|
||||
}
|
||||
|
||||
@@ -143,6 +173,7 @@ public class CompanyDao {
|
||||
entity.setNumberOfEmployees(request.getNumberOfEmployees());
|
||||
entity.setAnnualRevenue(request.getAnnualRevenue());
|
||||
entity.setHub(userEntity.getHub());
|
||||
entity.setJson(Utils.convertMapIntoJsonString(request.getVatCheckResponse()));
|
||||
if (request.getVatCheckResponse() != null) {
|
||||
Map<String, Object> vatCheckResponse = request.getVatCheckResponse();
|
||||
Map<String, Object> data = (Map<String, Object>) vatCheckResponse.get("data");
|
||||
@@ -226,10 +257,10 @@ public class CompanyDao {
|
||||
UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyId);
|
||||
//cloned entity for old data
|
||||
UserWithCompanyEntity oldUserWithCompanyData = Utils.getClonedEntityForData(userWithCompanyEntity);
|
||||
if(StringUtils.isNotBlank(companyRequest.getVatNumber())) {
|
||||
String responseJson = companyRequest.getVatCheckResponse() != null ? Utils.convertMapIntoJsonString(companyRequest.getVatCheckResponse()) : null;
|
||||
setIfUpdated(userWithCompanyEntity::getJson, userWithCompanyEntity::setJson, responseJson);
|
||||
}
|
||||
// if(StringUtils.isNotBlank(companyRequest.getVatNumber())) {
|
||||
// String responseJson = companyRequest.getVatCheckResponse() != null ? Utils.convertMapIntoJsonString(companyRequest.getVatCheckResponse()) : null;
|
||||
// setIfUpdated(companyEntity::getJson, companyEntity::setJson, responseJson);
|
||||
// }
|
||||
setIfUpdated(userWithCompanyEntity::getPec, userWithCompanyEntity::setPec, companyRequest.getPec());
|
||||
setIfUpdated(userWithCompanyEntity::getEmail, userWithCompanyEntity::setEmail, companyRequest.getEmail());
|
||||
setIfUpdated(userWithCompanyEntity::getContactName, userWithCompanyEntity::setContactName, companyRequest.getContactName());
|
||||
|
||||
@@ -248,7 +248,7 @@ public class FlowFormDao {
|
||||
//
|
||||
// return applicationFormEntities.isEmpty() ? null : applicationFormEntities.get(0).getForm().getId();
|
||||
// }
|
||||
public NextOrPreviousFormResponse getNextOrPreviousForm(ApplicationEntity applicationEntity, Long formId,
|
||||
public NextOrPreviousFormResponse getNextOrPreviousForm(ApplicationEntity applicationEntity,Long companyId, Long formId,
|
||||
FormActionEnum action) {
|
||||
Long calculatedFormId = null;
|
||||
FormEntity formEntity = null;
|
||||
|
||||
@@ -4,6 +4,7 @@ import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Expression;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
@@ -414,4 +415,48 @@ public class NotificationDao {
|
||||
predicates.add(criteriaBuilder.equal(root.get(GepafinConstant.USER_ID), userId));
|
||||
return predicates;
|
||||
}
|
||||
|
||||
public PageableResponseBean<List<NotificationResponse>> getNotificationsByUserIdAndCompanyIdByPagination(Long userId, Long companyId, NotificationRequestBean notificationRequestBean) {
|
||||
UserWithCompanyEntity userWithCompany;
|
||||
if (companyId != null) {
|
||||
userWithCompany = companyDao.validateUserWithCompny(userId, companyId);
|
||||
}else {
|
||||
userWithCompany=null;
|
||||
}
|
||||
Integer pageNo = null;
|
||||
Integer pageLimit = null;
|
||||
if (notificationRequestBean.getGlobalFilters() != null) {
|
||||
pageNo = notificationRequestBean.getGlobalFilters().getPage();
|
||||
pageLimit = notificationRequestBean.getGlobalFilters().getLimit();
|
||||
}
|
||||
if (pageLimit == null || pageLimit <= 0) {
|
||||
pageLimit = GepafinConstant.DEFAULT_PAGE_LIMIT;
|
||||
}
|
||||
if (pageNo == null || pageNo <= 0) {
|
||||
pageNo = GepafinConstant.DEFAULT_PAGE;
|
||||
}
|
||||
Specification<NotificationEntity> spec = search(userId, notificationRequestBean);
|
||||
if(userWithCompany!=null){
|
||||
spec = spec.and((root, query, criteriaBuilder) ->
|
||||
criteriaBuilder.equal(root.get("userWithCompany").get("id"), userWithCompany.getId()));
|
||||
}
|
||||
Page<NotificationEntity> entityPage = notificationRepository.findAll(spec, PageRequest.of(pageNo - 1, pageLimit));
|
||||
// Prepare the response
|
||||
List<NotificationResponse> notificationResponses = entityPage.getContent().stream()
|
||||
.map(notification -> {
|
||||
NotificationResponse response = convertNotificationEntityToNotificationResponse(notification);
|
||||
return response;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
PageableResponseBean<List<NotificationResponse>> pageableResponseBean = new PageableResponseBean<>();
|
||||
pageableResponseBean.setBody(notificationResponses);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,12 +285,12 @@ public class PdfDao {
|
||||
|
||||
private Document createPdfTable(List<Map<String, Object>> extractedData, Document document, ContentResponseBean contentResponseBean) throws DocumentException {
|
||||
// Create a PdfPTable with dynamic column count based on stateFieldMap size
|
||||
Map<String, String> stateFieldMap = new HashMap<>();
|
||||
Map<String, Boolean> stateFieldBoolean = new HashMap<>();
|
||||
Map<String, Boolean> formulaEnabledMap = new HashMap<>();
|
||||
Map<String, String> formulaTypeMap = new HashMap<>();
|
||||
Map<String, String> fieldTypeMap = new HashMap<>();
|
||||
Map<String, String> totalMap = new HashMap<>();
|
||||
Map<String, String> stateFieldMap = new LinkedHashMap<>();
|
||||
Map<String, Boolean> stateFieldBoolean = new LinkedHashMap<>();
|
||||
Map<String, Boolean> formulaEnabledMap = new LinkedHashMap<>();
|
||||
Map<String, String> formulaTypeMap = new LinkedHashMap<>();
|
||||
Map<String, String> fieldTypeMap = new LinkedHashMap<>();
|
||||
Map<String, String> totalMap = new LinkedHashMap<>();
|
||||
Font lightGrayFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new BaseColor(110, 110, 110)); // Light gray
|
||||
|
||||
|
||||
|
||||
@@ -2,15 +2,18 @@ package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.entities.RoleActionContextEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserActionEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.*;
|
||||
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.TimePeriodEnum;
|
||||
import net.gepafin.tendermanagement.enums.UserActionContextEnum;
|
||||
import net.gepafin.tendermanagement.model.response.ActionContextLabelResponse;
|
||||
import net.gepafin.tendermanagement.model.response.SummaryPageResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.UserActionResponseBean;
|
||||
import net.gepafin.tendermanagement.enums.UserActionLogsEnum;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationPageableRequestBean;
|
||||
import net.gepafin.tendermanagement.model.request.UserActionPaginationRequest;
|
||||
import net.gepafin.tendermanagement.model.response.*;
|
||||
import net.gepafin.tendermanagement.model.util.SortBy;
|
||||
import net.gepafin.tendermanagement.repositories.AssignedApplicationsRepository;
|
||||
import net.gepafin.tendermanagement.repositories.RoleActionContextRepository;
|
||||
import net.gepafin.tendermanagement.repositories.UserActionsRepository;
|
||||
@@ -23,9 +26,12 @@ import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isEmpty;
|
||||
|
||||
@Component
|
||||
public class UserActionDao {
|
||||
|
||||
@@ -41,16 +47,14 @@ public class UserActionDao {
|
||||
@Autowired
|
||||
private RoleActionContextRepository roleActionContextRepository;
|
||||
|
||||
public SummaryPageResponseBean getUserAction(HttpServletRequest request, UserEntity userEntity, TimePeriodEnum timeFilter, List<UserActionContextEnum> actionContext){
|
||||
public SummaryPageResponseBean getUserAction(HttpServletRequest request, UserEntity userEntity){
|
||||
Long numberOfLoginAttempts = userActionsRepository.countUserLoginAttempts(userEntity.getId());
|
||||
Long applicationsProcessed = assignedApplicationsRepository.countAssignedApplicationsByUserId(userEntity.getId());
|
||||
|
||||
List<UserActionEntity> userActions = getFilterUserActions(userEntity.getId(),timeFilter,actionContext);
|
||||
|
||||
return createSummaryPageResponse(userEntity,numberOfLoginAttempts,applicationsProcessed,userActions);
|
||||
return createSummaryPageResponse(userEntity,numberOfLoginAttempts,applicationsProcessed);
|
||||
}
|
||||
|
||||
public SummaryPageResponseBean createSummaryPageResponse(UserEntity user, Long numberOfLoginAttempts, Long applicationsProcessed, List<UserActionEntity> userActions){
|
||||
public SummaryPageResponseBean createSummaryPageResponse(UserEntity user, Long numberOfLoginAttempts, Long applicationsProcessed){
|
||||
SummaryPageResponseBean response = new SummaryPageResponseBean();
|
||||
response.setRole(user.getRoleEntity().getRoleName());
|
||||
response.setLastLogin(user.getLastLogin());
|
||||
@@ -59,9 +63,6 @@ public class UserActionDao {
|
||||
response.setEmail(user.getEmail());
|
||||
response.setNumberOfLoginAttempts(numberOfLoginAttempts);
|
||||
response.setApplicationsProcessed(applicationsProcessed);
|
||||
|
||||
List<UserActionResponseBean> userAction = convertEntityToResponse(userActions);
|
||||
response.setUserActions(userAction);
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -137,6 +138,7 @@ public class UserActionDao {
|
||||
responseBean.setResponse(action.getResponse());
|
||||
responseBean.setCreatedDate(action.getCreatedDate());
|
||||
responseBean.setUpdatedDate(action.getUpdatedDate());
|
||||
responseBean.setMethodType(action.getMethodType());
|
||||
return responseBean;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
@@ -157,4 +159,138 @@ public class UserActionDao {
|
||||
return responseBean;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
public PageableResponseBean<List<UserActionResponseBean>> getUserActionByPagination(UserEntity user, UserActionPaginationRequest userActionPaginationRequest) {
|
||||
Integer pageNo = null;
|
||||
Integer pageLimit = null;
|
||||
if (userActionPaginationRequest.getGlobalFilters() != null) {
|
||||
pageNo = userActionPaginationRequest.getGlobalFilters().getPage();
|
||||
pageLimit = userActionPaginationRequest.getGlobalFilters().getLimit();
|
||||
}
|
||||
if (pageLimit == null || pageLimit <= 0) {
|
||||
pageLimit = GepafinConstant.DEFAULT_PAGE_LIMIT;
|
||||
}
|
||||
if (pageNo == null || pageNo <= 0) {
|
||||
pageNo = GepafinConstant.DEFAULT_PAGE;
|
||||
}
|
||||
Specification<UserActionEntity> spec = search(userActionPaginationRequest,user);
|
||||
Page<UserActionEntity> entityPage = userActionsRepository.findAll(spec, PageRequest.of(pageNo - 1, pageLimit));
|
||||
// Prepare the response
|
||||
Long numberOfLoginAttempts = userActionsRepository.countUserLoginAttempts(user.getId());
|
||||
Long applicationsProcessed = assignedApplicationsRepository.countAssignedApplicationsByUserId(user.getId());
|
||||
|
||||
|
||||
List<UserActionResponseBean> userActionResponseBeans = convertEntityToResponse(entityPage.stream().toList());
|
||||
|
||||
|
||||
PageableResponseBean<List<UserActionResponseBean>> pageableResponseBean = new PageableResponseBean<>();
|
||||
pageableResponseBean.setBody(userActionResponseBeans);
|
||||
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<UserActionEntity> search(UserActionPaginationRequest userActionPaginationRequest,UserEntity userEntity) {
|
||||
return (root, query, criteriaBuilder) -> {
|
||||
|
||||
List<Predicate> predicates = getPredicates(userActionPaginationRequest, criteriaBuilder, root,userEntity);
|
||||
SortBy sortBy = new SortBy(GepafinConstant.CREATED_DATE, true);
|
||||
|
||||
if (userActionPaginationRequest .getGlobalFilters() != null
|
||||
&& userActionPaginationRequest.getGlobalFilters().getSortBy() != null &&
|
||||
userActionPaginationRequest.getGlobalFilters().getSortBy().getColumnName() != null && Boolean.FALSE.equals(
|
||||
isEmpty(userActionPaginationRequest.getGlobalFilters().getSortBy().getColumnName()))) {
|
||||
sortBy.setColumnName(userActionPaginationRequest.getGlobalFilters().getSortBy().getColumnName());
|
||||
sortBy.setSortDesc(true);
|
||||
if (userActionPaginationRequest.getGlobalFilters().getSortBy().getSortDesc() != null) {
|
||||
sortBy.setSortDesc(userActionPaginationRequest.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(UserActionPaginationRequest userActionPaginationRequest,
|
||||
CriteriaBuilder criteriaBuilder, Root<UserActionEntity> root,UserEntity userEntity) {
|
||||
|
||||
Integer year = null;
|
||||
String search = null;
|
||||
if (userActionPaginationRequest.getGlobalFilters() != null) {
|
||||
year = userActionPaginationRequest.getGlobalFilters().getYear();
|
||||
search = userActionPaginationRequest.getGlobalFilters().getSearch();
|
||||
}
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
|
||||
if (year != null && year > 0) {
|
||||
int filterYear = userActionPaginationRequest.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 actionType = criteriaBuilder.like(
|
||||
criteriaBuilder.upper(root.get(GepafinConstant.ACTION_TYPE)),
|
||||
"%" + search.toUpperCase() + "%"
|
||||
);
|
||||
predicates.add(criteriaBuilder.or(actionType));
|
||||
Predicate actionContext = criteriaBuilder.like(
|
||||
criteriaBuilder.upper(root.get(GepafinConstant.ACTION_CONTEXT)),
|
||||
"%" + search.toUpperCase() + "%"
|
||||
);
|
||||
predicates.add(criteriaBuilder.or(actionContext));
|
||||
Predicate methodType = criteriaBuilder.like(
|
||||
criteriaBuilder.upper(root.get(GepafinConstant.METHOD_TYPE)),
|
||||
"%" + search.toUpperCase() + "%"
|
||||
);
|
||||
predicates.add(criteriaBuilder.or(methodType));
|
||||
}
|
||||
|
||||
// Filter by `status` (if status list is provided)
|
||||
if (userActionPaginationRequest.getActionContext() != null && !userActionPaginationRequest.getActionContext().isEmpty()) {
|
||||
List<String> statusValues = userActionPaginationRequest.getActionContext().stream()
|
||||
.map(UserActionContextEnum::name) // Convert enum to string
|
||||
.toList();
|
||||
predicates.add(root.get("actionContext").in(statusValues));
|
||||
}
|
||||
if (userActionPaginationRequest.getActionType() != null && !userActionPaginationRequest.getActionType().isEmpty()) {
|
||||
List<String> statusValues = userActionPaginationRequest.getActionType().stream()
|
||||
.map(UserActionLogsEnum::name) // Convert enum to string
|
||||
.toList();
|
||||
predicates.add(root.get("actionType").in(statusValues));
|
||||
}
|
||||
|
||||
TimePeriodEnum timeRange= userActionPaginationRequest.getTimeFilter();
|
||||
if (timeRange != null) {
|
||||
LocalDateTime startDate = null;
|
||||
LocalDateTime endDate = LocalDateTime.now();
|
||||
|
||||
switch (timeRange) {
|
||||
case LAST_WEEK -> startDate = endDate.minusWeeks(1);
|
||||
case LAST_QUARTER -> startDate = endDate.minusMonths(3);
|
||||
case LAST_SEMESTER -> startDate = endDate.minusMonths(6);
|
||||
case LAST_YEAR -> startDate = endDate.minusYears(1);
|
||||
}
|
||||
|
||||
if (startDate != null) {
|
||||
predicates.add(criteriaBuilder.between(root.get(GepafinConstant.CREATED_DATE), startDate, endDate));
|
||||
}
|
||||
}
|
||||
predicates.add(criteriaBuilder.equal(root.get(GepafinConstant.USER_ID), userEntity.getId()));
|
||||
|
||||
return predicates;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import net.gepafin.tendermanagement.config.SamlSuccessHandler;
|
||||
@@ -10,6 +13,7 @@ import net.gepafin.tendermanagement.enums.*;
|
||||
import net.gepafin.tendermanagement.model.request.*;
|
||||
import net.gepafin.tendermanagement.model.response.*;
|
||||
import net.gepafin.tendermanagement.model.util.JWTToken;
|
||||
import net.gepafin.tendermanagement.model.util.SortBy;
|
||||
import net.gepafin.tendermanagement.repositories.BeneficiaryRepository;
|
||||
import net.gepafin.tendermanagement.repositories.UserRepository;
|
||||
import net.gepafin.tendermanagement.service.HubService;
|
||||
@@ -29,8 +33,13 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -38,6 +47,7 @@ import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
||||
import static org.apache.commons.lang3.StringUtils.isEmpty;
|
||||
|
||||
@Component
|
||||
public class UserDao {
|
||||
@@ -597,11 +607,157 @@ public class UserDao {
|
||||
log.info("Total users found with role ID {}: {}", roleIds, userResponseBeans.size());
|
||||
return userResponseBeans;
|
||||
}
|
||||
public PageableResponseBean<List<UserResponseBean>> getUserByPagination(UserPaginationRequestBean userPaginationRequestBean,UserEntity userEntity) {
|
||||
Integer pageNo = null;
|
||||
Integer pageLimit = null;
|
||||
if (userPaginationRequestBean.getGlobalFilters() != null) {
|
||||
pageNo = userPaginationRequestBean.getGlobalFilters().getPage();
|
||||
pageLimit = userPaginationRequestBean.getGlobalFilters().getLimit();
|
||||
}
|
||||
if (pageLimit == null || pageLimit <= 0) {
|
||||
pageLimit = GepafinConstant.DEFAULT_PAGE_LIMIT;
|
||||
}
|
||||
if (pageNo == null || pageNo <= 0) {
|
||||
pageNo = GepafinConstant.DEFAULT_PAGE;
|
||||
}
|
||||
Specification<UserEntity> spec = search(userPaginationRequestBean,userEntity);
|
||||
Page<UserEntity> entityPage = userRepository.findAll(spec, PageRequest.of(pageNo - 1, pageLimit));
|
||||
|
||||
List<UserResponseBean> applicationResponses = entityPage.getContent().stream()
|
||||
.map(user -> {
|
||||
UserResponseBean response = convertUserEntityToUserResponse(user);
|
||||
return response;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
PageableResponseBean<List<UserResponseBean>> 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<UserEntity> search(UserPaginationRequestBean userPaginationRequestBean,UserEntity userEntity) {
|
||||
return (root, query, criteriaBuilder) -> {
|
||||
|
||||
List<Predicate> predicates = getPredicates(userPaginationRequestBean, criteriaBuilder, root,userEntity);
|
||||
SortBy sortBy = new SortBy(GepafinConstant.CREATED_DATE, true);
|
||||
|
||||
if (userPaginationRequestBean .getGlobalFilters() != null
|
||||
&& userPaginationRequestBean.getGlobalFilters().getSortBy() != null &&
|
||||
userPaginationRequestBean.getGlobalFilters().getSortBy().getColumnName() != null && Boolean.FALSE.equals(
|
||||
isEmpty(userPaginationRequestBean.getGlobalFilters().getSortBy().getColumnName()))) {
|
||||
sortBy.setColumnName(userPaginationRequestBean.getGlobalFilters().getSortBy().getColumnName());
|
||||
sortBy.setSortDesc(true);
|
||||
if (userPaginationRequestBean.getGlobalFilters().getSortBy().getSortDesc() != null) {
|
||||
sortBy.setSortDesc(userPaginationRequestBean.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(UserPaginationRequestBean userPaginationRequestBean,
|
||||
CriteriaBuilder criteriaBuilder, Root<UserEntity> root,UserEntity user) {
|
||||
|
||||
Integer year = null;
|
||||
String search = null;
|
||||
if (userPaginationRequestBean.getGlobalFilters() != null) {
|
||||
year = userPaginationRequestBean.getGlobalFilters().getYear();
|
||||
search = userPaginationRequestBean.getGlobalFilters().getSearch();
|
||||
}
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
|
||||
if (year != null && year > 0) {
|
||||
int filterYear = userPaginationRequestBean.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 predicate = criteriaBuilder.like(
|
||||
criteriaBuilder.upper(root.get("firstName")),
|
||||
"%" + search.toUpperCase() + "%"
|
||||
);
|
||||
predicates.add(criteriaBuilder.or(predicate));
|
||||
Predicate predicate1 = criteriaBuilder.like(
|
||||
criteriaBuilder.upper(root.get("lastName")),
|
||||
"%" + search.toUpperCase() + "%"
|
||||
);
|
||||
predicates.add(criteriaBuilder.or(predicate1));
|
||||
|
||||
Predicate predicate2 = criteriaBuilder.like(
|
||||
criteriaBuilder.upper(root.get("phoneNumber")),
|
||||
"%" + search.toUpperCase() + "%"
|
||||
);
|
||||
predicates.add(criteriaBuilder.or(predicate2));
|
||||
|
||||
Predicate predicate3 = criteriaBuilder.like(
|
||||
criteriaBuilder.upper(root.get("organization")),
|
||||
"%" + search.toUpperCase() + "%"
|
||||
);
|
||||
predicates.add(criteriaBuilder.or(predicate3));
|
||||
|
||||
Predicate predicate4 = criteriaBuilder.like(
|
||||
criteriaBuilder.upper(root.get("address")),
|
||||
"%" + search.toUpperCase() + "%"
|
||||
);
|
||||
predicates.add(criteriaBuilder.or(predicate4));
|
||||
|
||||
Predicate predicate5 = criteriaBuilder.like(
|
||||
criteriaBuilder.upper(root.get("city")),
|
||||
"%" + search.toUpperCase() + "%"
|
||||
);
|
||||
predicates.add(criteriaBuilder.or(predicate5));
|
||||
|
||||
Predicate predicate6 = criteriaBuilder.like(
|
||||
criteriaBuilder.upper(root.get("country")),
|
||||
"%" + search.toUpperCase() + "%"
|
||||
);
|
||||
predicates.add(criteriaBuilder.or(predicate6));
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Filter by `status` (if status list is provided)
|
||||
if (userPaginationRequestBean.getStatus() != null && !userPaginationRequestBean.getStatus().isEmpty()) {
|
||||
List<String> statusValues = userPaginationRequestBean.getStatus().stream()
|
||||
.map(UserStatusEnum::name) // Convert enum to string
|
||||
.toList();
|
||||
predicates.add(root.get(GepafinConstant.STATUS).in(statusValues));
|
||||
}
|
||||
if (userPaginationRequestBean.getRole() != null && !userPaginationRequestBean.getRole().isEmpty()) {
|
||||
List<String> roleValues = userPaginationRequestBean.getRole().stream()
|
||||
.map(RoleStatusEnum::name) // Convert enum to string
|
||||
.toList();
|
||||
predicates.add(root.get("roleEntity").get("roleType").in(roleValues));
|
||||
}
|
||||
predicates.add(root.get(GepafinConstant.HUB).get("id").in(user.getHub().getId()));
|
||||
|
||||
return predicates;
|
||||
|
||||
}
|
||||
|
||||
public UserResponseBean updateUserDetails(HttpServletRequest request , Long userId, UpdateUserReqForBeneficiary userReq){
|
||||
log.info("Updating user by beneficiary with ID: {}", userId);
|
||||
UserEntity userEntity = validator.validateUserId(request, userId);
|
||||
|
||||
|
||||
UserEntity oldUserEntity = Utils.getClonedEntityForData(userEntity);
|
||||
log.info("Current user details: {}", userEntity);
|
||||
log.info("New user details: {}", userReq);
|
||||
@@ -647,9 +803,4 @@ public class UserDao {
|
||||
return convertUserEntityToUserResponse(userEntity);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user