Done ticket GEPAFINBE-182

This commit is contained in:
rajesh
2025-03-05 19:37:25 +05:30
parent a9166ae3fe
commit 47c816c264
3 changed files with 85 additions and 8 deletions

View File

@@ -13,6 +13,7 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Expression;
import jakarta.persistence.criteria.Predicate; import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Root; import jakarta.persistence.criteria.Root;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
@@ -804,6 +805,30 @@ public class CallDao {
} else { } else {
calls = callRepository.findByStatusInAndHubId(callStatusList, user.getHub().getId()); calls = callRepository.findByStatusInAndHubId(callStatusList, user.getHub().getId());
} }
LocalDateTime now = LocalDateTime.now();
for (CallEntity call : calls) {
CallEntity oldCallEntity = Utils.getClonedEntityForData(call);
if (CallStatusEnum.PUBLISH.getValue().equals(call.getStatus()) &&
call.getEndDate() != null && call.getEndTime() != null) {
LocalDateTime callEndDateTime = LocalDateTime.of(LocalDate.from(call.getEndDate()), call.getEndTime());
if (callEndDateTime.isBefore(now)) {
call.setStatus(CallStatusEnum.EXPIRED.getValue());
callRepository.save(call);
}
if (Boolean.FALSE.equals(oldCallEntity.getStatus().equals(call.getStatus()))) {
loggingUtil.logUserAction(UserActionRequest.builder()
.request(request)
.actionType(UserActionLogsEnum.UPDATE)
.actionContext(UserActionContextEnum.UPDATE_EXPIRED_CALL)
.build());
/** This code is responsible for adding a version history log for the "update call status to EXPIRED" operation **/
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldCallEntity).newData(call).build());
}
}
}
List<Long> callIds = calls.stream().map(CallEntity::getId).collect(Collectors.toList()); List<Long> callIds = calls.stream().map(CallEntity::getId).collect(Collectors.toList());
Map<String, BeneficiaryPreferredCallEntity> preferredCallsMap = Map<String, BeneficiaryPreferredCallEntity> preferredCallsMap =
getBeneficiaryPreferredCallsForUser(request,user, callIds, companyId); getBeneficiaryPreferredCallsForUser(request,user, callIds, companyId);
@@ -980,7 +1005,7 @@ public class CallDao {
Translator.toLocale(GepafinConstant.COMPANY_ID_REQUIRED_FOR_PREFERRED_CALL) Translator.toLocale(GepafinConstant.COMPANY_ID_REQUIRED_FOR_PREFERRED_CALL)
); );
} }
Specification<CallEntity> spec = search(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)) {
validator.validateUserWithCompany(request, companyId); validator.validateUserWithCompany(request, companyId);
@@ -1027,10 +1052,10 @@ public class CallDao {
return pageableResponseBean; return pageableResponseBean;
} }
public Specification<CallEntity> search(UserEntity userEntity, CallPageableRequestBean callPageableRequestBean) { public Specification<CallEntity> search(HttpServletRequest request,UserEntity userEntity, CallPageableRequestBean callPageableRequestBean) {
return (root, query, criteriaBuilder) -> { return (root, query, criteriaBuilder) -> {
List<Predicate> predicates = getPredicates(callPageableRequestBean, criteriaBuilder, root, userEntity); List<Predicate> predicates = getPredicates(request,callPageableRequestBean, criteriaBuilder, root, userEntity);
SortBy sortBy = new SortBy(GepafinConstant.CREATED_DATE, true); SortBy sortBy = new SortBy(GepafinConstant.CREATED_DATE, true);
if (callPageableRequestBean.getGlobalFilters() != null if (callPageableRequestBean.getGlobalFilters() != null
@@ -1053,9 +1078,9 @@ public class CallDao {
} }
private List<Predicate> getPredicates(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;
if (callPageableRequestBean.getGlobalFilters() != null) { if (callPageableRequestBean.getGlobalFilters() != null) {
@@ -1107,11 +1132,61 @@ public class CallDao {
predicates.add(criteriaBuilder.equal(root.get(GepafinConstant.HUB).get(GepafinConstant.ID), userEntity.getHub().getId())); predicates.add(criteriaBuilder.equal(root.get(GepafinConstant.HUB).get(GepafinConstant.ID), userEntity.getHub().getId()));
return predicates; return predicates;
} }
public void expirePublishedCalls(HttpServletRequest request) {
List<CallEntity> expiredCalls = callRepository.findAll((root, query, criteriaBuilder) -> {
Predicate isPublished = criteriaBuilder.equal(root.get(GepafinConstant.STATUS), CallStatusEnum.PUBLISH.name());
// Concatenate date and time as a single string
Expression<String> dateTimeString = criteriaBuilder.concat(
root.get(GepafinConstant.END_DATE),
criteriaBuilder.literal(" ") // Space between date and time
);
Expression<String> fullDateTimeString = criteriaBuilder.concat(dateTimeString, root.get(GepafinConstant.END_TIME));
// Convert the concatenated string into TIMESTAMP
Expression<LocalDateTime> endDateTime = criteriaBuilder.function(
"to_timestamp",
LocalDateTime.class,
fullDateTimeString,
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
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
loggingUtil.addVersionHistory(VersionHistoryRequest.builder()
.request(request)
.actionType(VersionActionTypeEnum.UPDATE)
.oldData(oldCallEntity)
.newData(call)
.build());
}
}
callRepository.saveAll(expiredCalls); // Save all modified calls at once
}
}
public CallResponse createCallStep2EvaluationV2(CallEntity callEntity, CreateCallRequestStep2EvaluationV2 createCallRequest, UserEntity user) { public CallResponse createCallStep2EvaluationV2(CallEntity callEntity, CreateCallRequestStep2EvaluationV2 createCallRequest, UserEntity user) {
convertToDocumentEntities(createCallRequest.getDocs(), callEntity.getId(), DocumentTypeEnum.DOCUMENT); convertToDocumentEntities(createCallRequest.getDocs(), callEntity.getId(), DocumentTypeEnum.DOCUMENT);

View File

@@ -213,7 +213,8 @@ public enum UserActionContextEnum {
GET_ALL_APPLICATION_AMENDMENT_BY_PAGINATION("GET_ALL_APPLICATION_AMENDMENT_BY_PAGINATION"), GET_ALL_APPLICATION_AMENDMENT_BY_PAGINATION("GET_ALL_APPLICATION_AMENDMENT_BY_PAGINATION"),
GET_ALL_USER_ACTION_BY_PAGINATION("GET_ALL_USER_ACTION_BY_PAGINATION"), GET_ALL_USER_ACTION_BY_PAGINATION("GET_ALL_USER_ACTION_BY_PAGINATION"),
GET_ALL_USER_BY_PAGINATION("GET_ALL_USER_BY_PAGINATION"), GET_ALL_USER_BY_PAGINATION("GET_ALL_USER_BY_PAGINATION"),
UPDATE_CALL_END_DATE_AND_TIME("UPDATE_CALL_END_DATE_AND_TIME"); UPDATE_CALL_END_DATE_AND_TIME("UPDATE_CALL_END_DATE_AND_TIME"),
UPDATE_EXPIRED_CALL("UPDATE_EXPIRED_CALL") ;
private final String value; private final String value;

View File

@@ -61,7 +61,7 @@ public class CallServiceImpl implements CallService {
} }
@Override @Override
@Transactional(readOnly = true) @Transactional(rollbackFor = Exception.class)
public List<CallDetailsResponseBean> getAllCalls(HttpServletRequest request,Long companyId,Boolean onlyPreferredCall) { public List<CallDetailsResponseBean> getAllCalls(HttpServletRequest request,Long companyId,Boolean onlyPreferredCall) {
UserEntity user = validator.validateUser(request); UserEntity user = validator.validateUser(request);
return callDao.getAllCalls(request,user,companyId,onlyPreferredCall); return callDao.getAllCalls(request,user,companyId,onlyPreferredCall);
@@ -104,6 +104,7 @@ public class CallServiceImpl implements CallService {
} }
@Override @Override
@Transactional(rollbackFor = Exception.class)
public PageableResponseBean<List<CallDetailsResponseBean>> getAllCallsByPagination(HttpServletRequest request,Long companyId , Boolean onlyPreferredCall, CallPageableRequestBean callPageableRequestBean) { public PageableResponseBean<List<CallDetailsResponseBean>> getAllCallsByPagination(HttpServletRequest request,Long companyId , Boolean onlyPreferredCall, CallPageableRequestBean callPageableRequestBean) {
UserEntity user = validator.validateUser(request); UserEntity user = validator.validateUser(request);
return callDao.getAllCallsByPagination(request,user,companyId,onlyPreferredCall,callPageableRequestBean); return callDao.getAllCallsByPagination(request,user,companyId,onlyPreferredCall,callPageableRequestBean);