Merge pull request #256 from Kitzanos/call-date-time-issue-prod

Cherry-pick(Fixed issue for Call date-time check)
This commit is contained in:
Rinaldo
2025-04-01 15:02:27 +02:00
committed by GitHub
4 changed files with 47 additions and 52 deletions

View File

@@ -941,7 +941,7 @@ public class ApplicationDao {
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_IN_PREVIOUS_STATUS)); throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_IN_PREVIOUS_STATUS));
} }
if (status.equals(ApplicationStatusTypeEnum.SUBMIT) && Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.READY.getValue()))) { if (status.equals(ApplicationStatusTypeEnum.SUBMIT) && Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.READY.getValue()))) {
callService.validatePublishedCall(applicationEntity.getCall().getId(), userEntity.getHub().getId()); // callService.validatePublishedCall(applicationEntity.getCall().getId(), userEntity.getHub().getId());
Long protocolNumber = protocolDao.getProtocolNumber(userEntity.getHub()); Long protocolNumber = protocolDao.getProtocolNumber(userEntity.getHub());
ProtocolEntity protocolEntity = protocolDao.createProtocolEntity(applicationEntity, protocolNumber, userEntity.getHub().getId(),true); ProtocolEntity protocolEntity = protocolDao.createProtocolEntity(applicationEntity, protocolNumber, userEntity.getHub().getId(),true);
applicationEntity.setProtocol(protocolEntity); applicationEntity.setProtocol(protocolEntity);
@@ -1724,19 +1724,21 @@ public class ApplicationDao {
public void checkCallEndDate(CallEntity call) { public void checkCallEndDate(CallEntity call) {
LocalDateTime now = DateTimeUtil.DateServerToUTC(LocalDateTime.now());
callService.validatePublishedCall(call.getId(), call.getHub().getId());
LocalDateTime callEndDateTime = LocalDateTime.of( // LocalDateTime now = DateTimeUtil.DateServerToUTC(LocalDateTime.now());
call.getEndDate().toLocalDate(), //
call.getEndTime() // LocalDateTime callEndDateTime = LocalDateTime.of(
); // call.getEndDate().toLocalDate(),
// call.getEndTime()
if (now.isAfter(callEndDateTime)) { // );
throw new CustomValidationException( //
Status.BAD_REQUEST, // if (now.isAfter(callEndDateTime)) {
Translator.toLocale(GepafinConstant.CALL_EXPIRED) // throw new CustomValidationException(
); // Status.BAD_REQUEST,
} // Translator.toLocale(GepafinConstant.CALL_EXPIRED)
// );
// }
} }
public void calculationProcessForFormula(ApplicationFormEntity applicationFormEntity, List<ContentResponseBean> contentResponseBeans, ApplicationFormFieldRequestBean applicationFormFieldRequestBean,FieldValidator fieldValidator) { public void calculationProcessForFormula(ApplicationFormEntity applicationFormEntity, List<ContentResponseBean> contentResponseBeans, ApplicationFormFieldRequestBean applicationFormFieldRequestBean,FieldValidator fieldValidator) {

View File

@@ -796,6 +796,7 @@ public class CallDao {
throw new CustomValidationException(Status.VALIDATION_ERROR, throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.COMPANY_ID_REQUIRED_FOR_PREFERRED_CALL)); Translator.toLocale(GepafinConstant.COMPANY_ID_REQUIRED_FOR_PREFERRED_CALL));
} }
expirePublishedCalls(request);
Specification<CallEntity> spec = buildCallSpecification(request, user, companyId, onlyPreferredCall, onlyConfidiCall, callStatusList); Specification<CallEntity> spec = buildCallSpecification(request, user, companyId, onlyPreferredCall, onlyConfidiCall, callStatusList);
List<CallEntity> calls = callRepository.findAll(spec); List<CallEntity> calls = callRepository.findAll(spec);
@@ -959,8 +960,8 @@ public class CallDao {
Status.NOT_FOUND, Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.CALL_NOT_PUBLISHED)); Translator.toLocale(GepafinConstant.CALL_NOT_PUBLISHED));
} }
LocalDate currentDate = LocalDate.now(); LocalDate currentDate = DateTimeUtil.DateServerToUTC(LocalDateTime.now()).toLocalDate();
LocalTime currentTime = LocalTime.now(); LocalTime currentTime = DateTimeUtil.LocalTimeServerToEurope(LocalTime.now());
if (currentDate.isBefore(callEntity.getStartDate().toLocalDate()) || if (currentDate.isBefore(callEntity.getStartDate().toLocalDate()) ||
(currentDate.isEqual(callEntity.getStartDate().toLocalDate()) && currentTime.isBefore(callEntity.getStartTime()))) { (currentDate.isEqual(callEntity.getStartDate().toLocalDate()) && currentTime.isBefore(callEntity.getStartTime()))) {
@@ -1000,6 +1001,7 @@ public class CallDao {
Translator.toLocale(GepafinConstant.COMPANY_ID_REQUIRED_FOR_PREFERRED_CALL) Translator.toLocale(GepafinConstant.COMPANY_ID_REQUIRED_FOR_PREFERRED_CALL)
); );
} }
expirePublishedCalls(request);
Specification<CallEntity> spec = search(request,user, callPageableRequestBean); Specification<CallEntity> spec = search(request,user, callPageableRequestBean);
Page<CallEntity> entityPage; Page<CallEntity> entityPage;
if (Boolean.TRUE.equals(onlyPreferredCall)) { if (Boolean.TRUE.equals(onlyPreferredCall)) {
@@ -1078,7 +1080,6 @@ public class CallDao {
private List<Predicate> getPredicates(HttpServletRequest request,CallPageableRequestBean callPageableRequestBean, private List<Predicate> getPredicates(HttpServletRequest request,CallPageableRequestBean callPageableRequestBean,
CriteriaBuilder criteriaBuilder, Root<CallEntity> root, UserEntity userEntity) { CriteriaBuilder criteriaBuilder, Root<CallEntity> root, UserEntity userEntity) {
expirePublishedCalls(request);
Integer year = null; Integer year = null;
String search = null; String search = null;
Map<String, FilterCriteria> filters = new HashMap<>(); Map<String, FilterCriteria> filters = new HashMap<>();
@@ -1162,42 +1163,24 @@ public class CallDao {
} }
public void expirePublishedCalls(HttpServletRequest request) { public void expirePublishedCalls(HttpServletRequest request) {
List<CallEntity> expiredCalls = callRepository.findAll((root, query, criteriaBuilder) -> {
Predicate isPublished = criteriaBuilder.equal(root.get(GepafinConstant.STATUS), CallStatusEnum.PUBLISH.name());
LocalDate currentDate = DateTimeUtil.DateServerToUTC(LocalDateTime.now()).toLocalDate();
// Concatenate date and time as a single string LocalTime currentTime = DateTimeUtil.LocalTimeServerToEurope(LocalTime.now());
Expression<String> dateTimeString = criteriaBuilder.concat(
root.get(GepafinConstant.END_DATE), List<CallEntity> expirdedCallList = callRepository.findExpiredCallsWhichIsPublished(CallStatusEnum.PUBLISH.getValue(), currentDate, currentTime);
criteriaBuilder.literal(" ") // Space between date and time
); if (!expirdedCallList.isEmpty()) {
Expression<String> fullDateTimeString = criteriaBuilder.concat(dateTimeString, root.get(GepafinConstant.END_TIME));
loggingUtil.logUserAction(UserActionRequest.builder()
// Convert the concatenated string into TIMESTAMP .request(request)
Expression<LocalDateTime> endDateTime = criteriaBuilder.function( .actionType(UserActionLogsEnum.UPDATE)
"to_timestamp", .actionContext(UserActionContextEnum.UPDATE_EXPIRED_CALL)
LocalDateTime.class, .build());
fullDateTimeString, for (CallEntity call : expirdedCallList) {
criteriaBuilder.literal("YYYY-MM-DD HH24:MI:SS")
);
Predicate isExpired = criteriaBuilder.lessThan(endDateTime, LocalDateTime.now());
return criteriaBuilder.and(isPublished, isExpired);
});
if (!expiredCalls.isEmpty()) {
for (CallEntity call : expiredCalls) {
CallEntity oldCallEntity = Utils.getClonedEntityForData(call); // Clone before modification CallEntity oldCallEntity = Utils.getClonedEntityForData(call); // Clone before modification
call.setStatus(CallStatusEnum.EXPIRED.getValue()); call.setStatus(CallStatusEnum.EXPIRED.getValue());
if (!oldCallEntity.getStatus().equals(call.getStatus())) {
// Log user action
loggingUtil.logUserAction(UserActionRequest.builder()
.request(request)
.actionType(UserActionLogsEnum.UPDATE)
.actionContext(UserActionContextEnum.UPDATE_EXPIRED_CALL)
.build());
// Add version history log // Add version history log
loggingUtil.addVersionHistory(VersionHistoryRequest.builder() loggingUtil.addVersionHistory(VersionHistoryRequest.builder()
.request(request) .request(request)
@@ -1205,9 +1188,8 @@ public class CallDao {
.oldData(oldCallEntity) .oldData(oldCallEntity)
.newData(call) .newData(call)
.build()); .build());
}
} }
callRepository.saveAll(expiredCalls); // Save all modified calls at once callRepository.saveAll(expirdedCallList); // Save all modified calls at once
} }
} }
private void applyFilters(Root<?> root, CriteriaBuilder criteriaBuilder, List<Predicate> predicates, Map<String, FilterCriteria> filters) { private void applyFilters(Root<?> root, CriteriaBuilder criteriaBuilder, List<Predicate> predicates, Map<String, FilterCriteria> filters) {

View File

@@ -7,6 +7,8 @@ import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.List; import java.util.List;
@Repository @Repository
@@ -58,5 +60,8 @@ public interface CallRepository extends JpaRepository<CallEntity, Long>, JpaSpec
List<CallEntity> findByIdInAndStatusInAndConfidi(@Param("ids") List<Long> ids, @Param("status") List<String> status,Boolean confidi); List<CallEntity> findByIdInAndStatusInAndConfidi(@Param("ids") List<Long> ids, @Param("status") List<String> status,Boolean confidi);
public List<CallEntity> findByStatusInAndHubIdAndConfidi(List<String> callStatus, Long hubId,Boolean onlyConfidiCall); public List<CallEntity> findByStatusInAndHubIdAndConfidi(List<String> callStatus, Long hubId,Boolean onlyConfidiCall);
@Query("SELECT c FROM CallEntity c WHERE c.status = :status AND (FUNCTION('DATE', c.endDate) < :endDate OR (FUNCTION('DATE', c.endDate) = :endDate AND c.endTime <= :endTime))")
List<CallEntity> findExpiredCallsWhichIsPublished(@Param("status") String status, @Param("endDate") LocalDate endDate, @Param("endTime") LocalTime endTime);
} }

View File

@@ -4,6 +4,7 @@ import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationExceptio
import net.gepafin.tendermanagement.web.rest.api.errors.Status; import net.gepafin.tendermanagement.web.rest.api.errors.Status;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.ZoneId; import java.time.ZoneId;
@@ -28,6 +29,11 @@ public class DateTimeUtil {
return localDatetime; return localDatetime;
} }
public static LocalTime LocalTimeServerToEurope(LocalTime systemTime) {
ZonedDateTime zonedDateTime = systemTime.atDate(LocalDate.now()).atZone(ZoneId.systemDefault());
return zonedDateTime.withZoneSameInstant(ZoneId.of("Europe/Rome")).toLocalTime();
}
public static LocalDateTime getPreviousMonthDate(int month) { public static LocalDateTime getPreviousMonthDate(int month) {
Calendar c = Calendar.getInstance(); Calendar c = Calendar.getInstance();
c.add(Calendar.MONTH, -month); c.add(Calendar.MONTH, -month);