Resolved conflicts

This commit is contained in:
rajesh
2025-05-26 18:53:47 +05:30
27 changed files with 326 additions and 147 deletions

View File

@@ -27,6 +27,7 @@ import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundExceptio
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
@@ -308,8 +309,14 @@ public class ApplicationAmendmentRequestDao {
if (Boolean.TRUE.equals(applicationAmendmentRequestResponse.getIsSendEmail())) {
emailNotificationDao.sendMailToNotifyBeneficiaryRegardingNewAmendment(applicationAmendmentRequestEntity);
EmailSendResponse emailSendResponse = emailDao.buildEmailSendResponseFromRequest(request);
applicationAmendmentRequestResponse.setEmailSendResponse(emailSendResponse);
saveEmailSendResponse(emailSendResponse, applicationAmendmentRequestEntity);
List<EmailSendResponse> responses = List.of(emailSendResponse);
if (!Boolean.TRUE.equals(emailSendResponse.getIsEmailSend())){
saveEmailSendResponse(emailSendResponse, applicationAmendmentRequestEntity);
applicationAmendmentRequestResponse.setEmailSendResponse(responses);
}
else{
applicationAmendmentRequestResponse.setEmailSendResponse(Collections.emptyList());
}
}
return applicationAmendmentRequestResponse;
}
@@ -517,6 +524,7 @@ public class ApplicationAmendmentRequestDao {
Long hubId = applicationEntity.getHubId();
HubEntity hubEntity = hubService.valdateHub(hubId);
response.setEmailSendResponse(entity.getEmailSendResponse());
response.setId(entity.getId());
response.setApplicationId(entity.getApplicationId());
response.setApplicationEvaluationId(entity.getApplicationEvaluationEntity().getId());
@@ -655,19 +663,12 @@ public class ApplicationAmendmentRequestDao {
log.info(" Application amendment deleted with ID: {}", id);
}
public ApplicationAmendmentRequestResponseBean getApplicationAmendmentRequestById(Long id) {
public ApplicationAmendmentRequestResponse getApplicationAmendmentRequestById(Long id) {
log.info("Fetching application amendment with ID: {}", id);
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = validateApplicationAmendmentRequest(id);
ApplicationAmendmentRequestResponse sourceResponse = convertEntityToResponse(applicationAmendmentRequestEntity,true);
ApplicationAmendmentRequestResponseBean targetResponse = Utils.convertSourceObjectToDestinationObject(
sourceResponse, ApplicationAmendmentRequestResponseBean.class
);
if (targetResponse != null) {
targetResponse.setEmailSendResponse(applicationAmendmentRequestEntity.getEmailSendResponse());
}
log.info("Application Amendment fetched successfully by ID: {}", targetResponse);
return targetResponse;
ApplicationAmendmentRequestResponse response = convertEntityToResponse(applicationAmendmentRequestEntity,true);
response.setEmailSendResponse(applicationAmendmentRequestEntity.getEmailSendResponse());
return response;
}
public List<GetAllAmendmentResponseBean> getAllApplicationAmendmentRequest(HttpServletRequest request, Long userId) {
@@ -1050,7 +1051,7 @@ public class ApplicationAmendmentRequestDao {
public ApplicationAmendmentRequestResponse closeAmendmentRequest(Long id, CloseAmendmentRequest closeAmendmentRequest) {
log.info("Closing application amendement with ID: {}", id);
ApplicationAmendmentRequestEntity existingApplicationAmendment = validateApplicationAmendmentRequest(id);
ApplicationAmendmentRequestEntity existingApplicationAmendment = validatApplicationAmendmentRequestByListStatus(id,List.of(ApplicationAmendmentRequestEnum.AWAITING.getValue(),ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED.getValue()));
//cloned entity for old data and versioning
ApplicationAmendmentRequestEntity oldApplicationAmendmentEntity = Utils.getClonedEntityForData(existingApplicationAmendment);
List<ApplicationAmendmentRequestEntity> amendmentRequestList = applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(
@@ -1060,17 +1061,18 @@ public class ApplicationAmendmentRequestDao {
// Check if this is the last amendment being closed
boolean isLastRemaining = amendmentRequestList.stream()
.filter(amendment -> !amendment.getId().equals(id)) // Exclude the current amendment
.allMatch(amendment -> amendment.getStatus().equals(ApplicationAmendmentRequestEnum.CLOSE.getValue()));
.allMatch(amendment -> amendment.getStatus().equals(ApplicationAmendmentRequestEnum.CLOSE.getValue()) || amendment.getStatus().equals(ApplicationAmendmentRequestEnum.EXPIRED.getValue()));
if (isLastRemaining) {
log.info("The current amendment is the last remaining one to be closed.");
applicationAmendmentRequestDao.calculateEndDateAndSuspensionDays(existingApplicationAmendment.getApplicationEvaluationEntity());
}
setIfUpdated(existingApplicationAmendment::getInternalNote, existingApplicationAmendment::setInternalNote, closeAmendmentRequest.getInternalNote());
setIfUpdated(existingApplicationAmendment::getStatus, existingApplicationAmendment::setStatus, ApplicationAmendmentRequestEnum.CLOSE.getValue());
existingApplicationAmendment.setClosingDate(LocalDateTime.now());
ApplicationAmendmentRequestEntity updatedApplicationAmendment = saveApplicationAmendmentRequestEntity(existingApplicationAmendment, oldApplicationAmendmentEntity,
VersionActionTypeEnum.UPDATE);
if (isLastRemaining) {
log.info("The current amendment is the last remaining one to be closed.");
applicationAmendmentRequestDao.calculateEndDateAndSuspensionDaysOnExpirationOrClosing(existingApplicationAmendment.getApplicationEvaluationEntity());
}
ApplicationAmendmentRequestResponse response = convertEntityToResponse(updatedApplicationAmendment,false);
List<ApplicationAmendmentRequestEntity> amendmentRequests = applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(
@@ -1122,15 +1124,17 @@ public class ApplicationAmendmentRequestDao {
return response;
}
public ApplicationAmendmentRequestResponse extendResponseDays(Long id, Long newResponseDays) {
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = validateApplicationAmendmentRequest(id);
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = validatApplicationAmendmentRequestByStatus(id,ApplicationAmendmentRequestEnum.EXPIRED.getValue());
if (newResponseDays != null && newResponseDays > 0) {
ApplicationAmendmentRequestEntity oldApplicationAmendmentEntity = Utils.getClonedEntityForData(applicationAmendmentRequestEntity);
ApplicationAmendmentRequestEntity oldApplicationAmendmentEntity = Utils.getClonedEntityForData(applicationAmendmentRequestEntity);
Long currentResponseDays = applicationAmendmentRequestEntity.getResponseDays() != null ? applicationAmendmentRequestEntity.getResponseDays() : 0L;
applicationAmendmentRequestEntity.setResponseDays(currentResponseDays + newResponseDays);
applicationAmendmentRequestEntity.setEndDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now().plusDays(applicationAmendmentRequestEntity.getResponseDays())));
applicationAmendmentRequestEntity.setEndDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now().plusDays(newResponseDays)));
applicationAmendmentRequestEntity.setStatus(ApplicationAmendmentRequestEnum.AWAITING.getValue());
applicationAmendmentRequestEntity.getApplicationEvaluationEntity().setStatus(ApplicationEvaluationStatusTypeEnum.SOCCORSO.getValue());
applicationAmendmentRequestEntity.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication().setStatus(ApplicationStatusTypeEnum.SOCCORSO.getValue());
applicationAmendmentRequestRepository.save(applicationAmendmentRequestEntity);
/** This code is responsible for adding a version history log for the "Update Application Amendment" operation. **/
@@ -1206,8 +1210,14 @@ public class ApplicationAmendmentRequestDao {
beneficiaryUser.getId(), applicationEntity.getId(), amendment.getId(), applicationEntity.getCall().getId());
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(email), emailLogRequest);
EmailSendResponse emailSendResponse = emailDao.buildEmailSendResponseFromRequest(request);
emailReminderResponse.setEmailSendResponse(emailSendResponse);
saveEmailSendResponse(emailSendResponse, amendment);
List<EmailSendResponse> responses = List.of(emailSendResponse);
if (!Boolean.TRUE.equals(emailSendResponse.getIsEmailSend())){
emailReminderResponse.setEmailSendResponse(responses);
saveEmailSendResponse(emailSendResponse, amendment);
}
else{
emailReminderResponse.setEmailSendResponse(Collections.emptyList());
}
} else {
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.BENEFICIARY_EMAIL_NOT_FOUND_MSG));
}
@@ -1242,26 +1252,26 @@ public class ApplicationAmendmentRequestDao {
return Utils.replacePlaceholders(template.getHtmlContent(), bodyPlaceholders);
}
public ApplicationEvaluationEntity calculateEndDateAndSuspensionDays(ApplicationEvaluationEntity applicationEvaluationEntity){
LocalDateTime currentDate=DateTimeUtil.DateServerToUTC(LocalDateTime.now());
LocalDateTime endDate=currentDate.plusDays(applicationEvaluationEntity.getRemainingDays());
Long suspendedDays = ChronoUnit.DAYS.between(applicationEvaluationEntity.getStopDateTime(), currentDate);
ApplicationEvaluationEntity oldApplicationEvaluationEntity = Utils.getClonedEntityForData(applicationEvaluationEntity);
applicationEvaluationEntity.setEndDate(endDate);
if(applicationEvaluationEntity.getSuspendedDays() == null) {
applicationEvaluationEntity.setSuspendedDays(0L);
}
applicationEvaluationEntity.setSuspendedDays(applicationEvaluationEntity.getSuspendedDays()+suspendedDays);
ApplicationEvaluationEntity applicationEvaluation = applicationEvaluationRepository.save(applicationEvaluationEntity);
/** This code is responsible for adding a version history log for the "Update Application Amendment" operation. **/
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationEvaluationEntity).newData(applicationEvaluation).build());
return applicationEvaluation;
}
// public ApplicationEvaluationEntity calculateEndDateAndSuspensionDays(ApplicationEvaluationEntity applicationEvaluationEntity){
// LocalDateTime currentDate=DateTimeUtil.DateServerToUTC(LocalDateTime.now());
// LocalDateTime endDate=currentDate.plusDays(applicationEvaluationEntity.getRemainingDays());
// Long suspendedDays = ChronoUnit.DAYS.between(applicationEvaluationEntity.getStopDateTime(), currentDate);
//
// ApplicationEvaluationEntity oldApplicationEvaluationEntity = Utils.getClonedEntityForData(applicationEvaluationEntity);
// applicationEvaluationEntity.setEndDate(endDate);
// if(applicationEvaluationEntity.getSuspendedDays() == null) {
// applicationEvaluationEntity.setSuspendedDays(0L);
// }
// applicationEvaluationEntity.setSuspendedDays(applicationEvaluationEntity.getSuspendedDays()+suspendedDays);
// ApplicationEvaluationEntity applicationEvaluation = applicationEvaluationRepository.save(applicationEvaluationEntity);
//
// /** This code is responsible for adding a version history log for the "Update Application Amendment" operation. **/
// loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationEvaluationEntity).newData(applicationEvaluation).build());
//
// return applicationEvaluation;
//
//
// }
private GetAllAmendmentResponseBean initializeGetAllBasicResponse(ApplicationAmendmentRequestEntity entity) {
GetAllAmendmentResponseBean response = new GetAllAmendmentResponseBean();
@@ -1566,10 +1576,107 @@ public class ApplicationAmendmentRequestDao {
return applicationAmendmentRequestViewResponse;
}
public ApplicationEvaluationEntity calculateEndDateAndSuspensionDaysOnExpirationOrClosing
(ApplicationEvaluationEntity applicationEvaluationEntity) {
// Fetch all linked amendments
List<ApplicationAmendmentRequestEntity> amendments =
applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(applicationEvaluationEntity.getId());
// Recalculate suspension
long suspendedDays = calculateSuspendedDays(amendments);
// Update end date and save
ApplicationEvaluationEntity oldEntity = Utils.getClonedEntityForData(applicationEvaluationEntity);
HubEntity hub = hubService.valdateHub(applicationEvaluationEntity.getAssignedApplicationsEntity().getApplication().getHubId());
Long initialDays = (hub != null) ? hub.getEvaluationExpirationDays() : 30L;
LocalDateTime endDate = applicationEvaluationEntity.getStartDate().plusDays(suspendedDays+initialDays);
applicationEvaluationEntity.setEndDate(endDate);
applicationEvaluationEntity.setSuspendedDays(suspendedDays);
ApplicationEvaluationEntity updated = applicationEvaluationRepository.save(applicationEvaluationEntity);
loggingUtil.addVersionHistory(VersionHistoryRequest.builder()
.request(request)
.actionType(VersionActionTypeEnum.UPDATE)
.oldData(oldEntity)
.newData(updated)
.build());
return updated;
}
public long calculateSuspendedDays(List<ApplicationAmendmentRequestEntity> amendments) {
List<Pair<LocalDateTime, LocalDateTime>> periods = amendments.stream()
.filter(amendmentRequest -> amendmentRequest.getStartDate() != null)
.map(amendmentRequest -> {
LocalDateTime start = amendmentRequest.getStartDate();
LocalDateTime end;
String status = amendmentRequest.getStatus();
if (Boolean.TRUE.equals(ApplicationAmendmentRequestEnum.CLOSE.getValue().equals(status)) && amendmentRequest.getClosingDate() != null) {
end = amendmentRequest.getClosingDate();
} else if (Boolean.TRUE.equals(ApplicationAmendmentRequestEnum.EXPIRED.getValue().equals(status)) && amendmentRequest.getEndDate() != null) {
end = amendmentRequest.getStartDate().plusDays(amendmentRequest.getResponseDays());
}else {
end= amendmentRequest.getEndDate();
}
return Pair.of(start, end);
})
.filter(Objects::nonNull)
.sorted(Comparator.comparing(Pair::getLeft))
.collect(Collectors.toList());
long totalDays = 0;
LocalDateTime currentStart = null;
LocalDateTime currentEnd = null;
for (Pair<LocalDateTime, LocalDateTime> period : periods) {
if (currentStart == null) {
currentStart = period.getLeft();
currentEnd = period.getRight();
} else if (!period.getLeft().isAfter(currentEnd)) {
// Merge overlapping/touching periods
currentEnd = currentEnd.isAfter(period.getRight()) ? currentEnd : period.getRight();
} else {
// Non-overlapping: count previous period
totalDays += ChronoUnit.DAYS.between(currentStart.toLocalDate(), currentEnd.toLocalDate());
currentStart = period.getLeft();
currentEnd = period.getRight();
}
}
if (currentStart != null && currentEnd != null) {
totalDays += ChronoUnit.DAYS.between(currentStart.toLocalDate(), currentEnd.toLocalDate());
}
return totalDays;
}
public ApplicationAmendmentRequestEntity validatApplicationAmendmentRequestByStatus(Long id,String status) {
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = applicationAmendmentRequestRepository.findByIdAndIsDeletedFalseAndStatus(id, status);
if (applicationAmendmentRequestEntity == null) {
throw new ResourceNotFoundException(Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.APPLICATION_AMENDMENT_NOT_FOUND_MSG));
}
return applicationAmendmentRequestEntity;
}
private void saveEmailSendResponse(EmailSendResponse newResponses, ApplicationAmendmentRequestEntity amendment) {
List<EmailSendResponse> mergedResponses = Utils.mergeEmailSendResponses(amendment.getEmailSendResponse(), newResponses);
amendment.setEmailSendResponse(mergedResponses);
applicationAmendmentRequestRepository.save(amendment);
}
public ApplicationAmendmentRequestEntity validatApplicationAmendmentRequestByListStatus(Long id,List<String> status) {
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = applicationAmendmentRequestRepository.findByIdAndIsDeletedFalseAndStatusIn(id, status);
if (applicationAmendmentRequestEntity == null) {
throw new ResourceNotFoundException(Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.APPLICATION_AMENDMENT_NOT_FOUND_MSG));
}
return applicationAmendmentRequestEntity;
}
}