diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java index 04e6f17b..b8e29a6e 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java @@ -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 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 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 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 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 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 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 amendments) { + List> 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 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 mergedResponses = Utils.mergeEmailSendResponses(amendment.getEmailSendResponse(), newResponses); amendment.setEmailSendResponse(mergedResponses); applicationAmendmentRequestRepository.save(amendment); } + public ApplicationAmendmentRequestEntity validatApplicationAmendmentRequestByListStatus(Long id,List 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; + } } diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java index 296d42d1..1ff7dbcb 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java @@ -211,6 +211,7 @@ public class ApplicationDao { @Autowired private ApplicationEvaluationDao applicationEvaluationDao; + public final Random random = new Random(); public ApplicationResponseBean createApplication(HttpServletRequest request, ApplicationRequestBean applicationRequestBean, Long formId, Long applicationId) { FormEntity formEntity = formService.validateForm(formId); @@ -937,12 +938,16 @@ public class ApplicationDao { } } + public String generateRandomFiveDigitNumber() { + int number = 10000 + random.nextInt(90000); // Generates a number from 10000 to 99999 + return String.valueOf(number); + } public ApplicationResponse updateApplicationStatus(HttpServletRequest request, Long applicationId, ApplicationStatusTypeEnum status) { log.info("Updating status for Application id : " + applicationId); ApplicationEntity applicationEntity = validateApplication(applicationId); - checkCallEndDate(applicationEntity.getCall()); + log.info("Call end date verified successfully | callId: {}", applicationEntity.getCall().getId()); //cloned entity for old application data ApplicationEntity oldApplicationEntity = Utils.getClonedEntityForData(applicationEntity); @@ -956,9 +961,18 @@ public class ApplicationDao { if (Boolean.TRUE.equals(applicationEntity.getStatus().equals(status.getValue()))) { throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_IN_PREVIOUS_STATUS)); } + + if (status.equals(ApplicationStatusTypeEnum.APPOINTMENT) && Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.NDG.getValue()))){ + String appointmentId = generateRandomFiveDigitNumber(); + applicationEntity.setAppointmentId(appointmentId); + applicationEntity.setStatus(ApplicationStatusTypeEnum.APPOINTMENT.getValue()); + } + if (status.equals(ApplicationStatusTypeEnum.SUBMIT) && Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.READY.getValue()))) { CompanyEntity company=companyService.validateCompany(applicationEntity.getCompanyId()); +// callService.validatePublishedCall(applicationEntity.getCall().getId(), userEntity.getHub().getId()); + checkCallEndDate(applicationEntity.getCall()); Long protocolNumber = protocolDao.getProtocolNumber(userEntity.getHub()); ProtocolEntity protocolEntity = protocolDao.createProtocolEntity(applicationEntity, protocolNumber, userEntity.getHub().getId(),true); protocolDao.saveProtocolEntity(protocolEntity); @@ -982,10 +996,12 @@ public class ApplicationDao { log.info("Status updated to SUBMIT for applicationId: " + applicationId); } if (status.equals(ApplicationStatusTypeEnum.DRAFT) && Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.AWAITING.getValue()))) { + checkCallEndDate(applicationEntity.getCall()); applicationEntity.setStatus(status.getValue()); log.info("Status updated to DRAFT for applicationId: " + applicationId); } if (status.equals(ApplicationStatusTypeEnum.AWAITING) && Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.READY.getValue()))) { + checkCallEndDate(applicationEntity.getCall()); ApplicationSignedDocumentEntity applicationSignedDocument = applicationSignedDocumentRepository.findByApplicationIdAndStatus(applicationId, ApplicationSignedDocumentStatusEnum.ACTIVE.getValue()); deleteSignedDocumentFromS3(applicationSignedDocument); @@ -2147,45 +2163,7 @@ public class ApplicationDao { tableDataByApp.put(appId, flattenedAll); } } - - - public void sendApplicationSubmissionFailureEmail(EmailLogRequest emailLogRequest){ - - Long callId = emailLogRequest.getCallId(); - CallEntity call = callService.validateCall(callId); - HubEntity hub = call.getHub(); - Long userId = emailLogRequest.getUserId(); - UserEntity user = userService.validateUser(userId); - Long applicationId = emailLogRequest.getApplicatioId(); - ApplicationEntity applicationEntity = validateApplication(applicationId); - CompanyEntity company = companyService.validateCompany(applicationEntity.getCompanyId()); - - - SystemEmailTemplateResponse systemEmailTemplateResponse = systemEmailTemplatesService - .retrieveTemplateByTypeAndCall(SystemEmailTemplatesEntityTypeEnum.APPLICATION_SUBMISSION_FAILURE_NOTIFICATION, - hub, null); - - Map subjectPlaceholders = new HashMap<>(); - subjectPlaceholders.put("{{call_name}}", call.getName()); - - Map bodyPlaceholders = new HashMap<>(); - bodyPlaceholders.put("{{scenario}}",emailLogRequest.getEmailType().getValue()); - bodyPlaceholders.put("{{call_name}}", call.getName()); - bodyPlaceholders.put("{{application_id}}", applicationEntity.getId().toString()); - bodyPlaceholders.put("{{company_name}}", company.getCompanyName()); - bodyPlaceholders.put("{{protocol_number}}", applicationEntity.getProtocol().getProtocolNumber().toString()); - bodyPlaceholders.put("{{user_action_id}}",emailLogRequest.getUserActionId().toString()); - - String subject = Utils.replacePlaceholders(systemEmailTemplateResponse.getSubject(), subjectPlaceholders); - String body = Utils.replacePlaceholders(systemEmailTemplateResponse.getHtmlContent(), bodyPlaceholders); - - emailLogRequest=emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(),RecipientTypeEnum.PROPERTIES,null,user.getEmail(),user.getId(),applicationEntity.getId(),null,callId); - - emailLogRequest.setRecipientEmails(GepafinConstant.RINALDO_EMAIL); - emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(GepafinConstant.RINALDO_EMAIL),emailLogRequest); - } - - public ApplicationResponse readmitApplication(HttpServletRequest request, Long applicationId) { + public ApplicationResponse readmitApplication(HttpServletRequest request, Long applicationId) { log.info("Re-admiting the Application with id : {}", applicationId); ApplicationEntity applicationEntity = fetchRejectedApplication(applicationId); @@ -2195,7 +2173,7 @@ public class ApplicationDao { } validator.validateUserWithCompany(request, applicationEntity.getCompanyId()); - assignedApplicationsRepository.findByApplicationIdAndStatusAndIsDeletedFalse(applicationEntity.getId(), AssignedApplicationEnum.CLOSE.getValue()) + assignedApplicationsRepository.findByApplicationIdAndIsDeletedFalse(applicationEntity.getId()) .ifPresent(assignedApp -> processAssignedAppAndEvaluation(request, applicationEntity, assignedApp)); return getApplicationResponse(applicationEntity); @@ -2205,7 +2183,7 @@ public class ApplicationDao { } private void processAssignedAppAndEvaluation(HttpServletRequest request, ApplicationEntity applicationEntity, AssignedApplicationsEntity assignedApp) { - applicationEvaluationRepository.findByAssignedApplicationsEntity_IdAndStatusAndIsDeletedFalse(assignedApp.getId(), ApplicationEvaluationStatusTypeEnum.CLOSE.getValue()) + applicationEvaluationRepository.findByAssignedApplicationsEntity_IdAndIsDeletedFalse(assignedApp.getId()) .ifPresent(eval -> reopenApplication(request, applicationEntity, assignedApp, eval)); } @@ -2264,4 +2242,40 @@ public class ApplicationDao { } + public void sendApplicationSubmissionFailureEmail(EmailLogRequest emailLogRequest){ + + Long callId = emailLogRequest.getCallId(); + CallEntity call = callService.validateCall(callId); + HubEntity hub = call.getHub(); + Long userId = emailLogRequest.getUserId(); + UserEntity user = userService.validateUser(userId); + Long applicationId = emailLogRequest.getApplicatioId(); + ApplicationEntity applicationEntity = validateApplication(applicationId); + CompanyEntity company = companyService.validateCompany(applicationEntity.getCompanyId()); + + + SystemEmailTemplateResponse systemEmailTemplateResponse = systemEmailTemplatesService + .retrieveTemplateByTypeAndCall(SystemEmailTemplatesEntityTypeEnum.APPLICATION_SUBMISSION_FAILURE_NOTIFICATION, + hub, null); + + Map subjectPlaceholders = new HashMap<>(); + subjectPlaceholders.put("{{call_name}}", call.getName()); + + Map bodyPlaceholders = new HashMap<>(); + bodyPlaceholders.put("{{scenario}}",emailLogRequest.getEmailType().getValue()); + bodyPlaceholders.put("{{call_name}}", call.getName()); + bodyPlaceholders.put("{{application_id}}", applicationEntity.getId().toString()); + bodyPlaceholders.put("{{company_name}}", company.getCompanyName()); + bodyPlaceholders.put("{{protocol_number}}", applicationEntity.getProtocol().getProtocolNumber().toString()); + bodyPlaceholders.put("{{user_action_id}}",emailLogRequest.getUserActionId().toString()); + + String subject = Utils.replacePlaceholders(systemEmailTemplateResponse.getSubject(), subjectPlaceholders); + String body = Utils.replacePlaceholders(systemEmailTemplateResponse.getHtmlContent(), bodyPlaceholders); + + emailLogRequest=emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(),RecipientTypeEnum.PROPERTIES,null,user.getEmail(),user.getId(),applicationEntity.getId(),null,callId); + + emailLogRequest.setRecipientEmails(GepafinConstant.RINALDO_EMAIL); + emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(GepafinConstant.RINALDO_EMAIL),emailLogRequest); + } + } diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java index 069bbd40..8d4ce08e 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java @@ -703,7 +703,11 @@ public class ApplicationEvaluationDao { /** This code is responsible for adding a version history log for the "Update Application" operation. **/ loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(actionType).oldData(oldApplication).newData(application).build()); - Map placeHolders = notificationDao.sendNotificationToBeneficiary(application, NotificationTypeEnum.EVALUATION_CREATION); +// Map placeHolders = notificationDao.sendNotificationToBeneficiary(application, NotificationTypeEnum.EVALUATION_CREATION); + + Map placeHolders = new HashMap<>(); + placeHolders.put("{{call_name}}", application.getCall().getName()); + placeHolders.put("{{protocol_number}}", String.valueOf(application.getProtocol().getProtocolNumber())); notificationDao.sendNotificationToSuperUser(application,placeHolders,NotificationTypeEnum.EVALUATION_CREATION); notificationDao.sendNotificationToInstructor(placeHolders,entity,NotificationTypeEnum.EVALUATION_CREATION); @@ -1092,7 +1096,7 @@ public class ApplicationEvaluationDao { } validator.validatePreInstructor(request, assignedApplications.getUserId()); } - public ApplicationEvaluationResponseBean getApplicationEvaluationByApplicationId(HttpServletRequest request, UserEntity user, Long applicationID, Long assignedApplicationID) { + public ApplicationEvaluationResponse getApplicationEvaluationByApplicationId(HttpServletRequest request, UserEntity user, Long applicationID, Long assignedApplicationID) { Long applicationId; Long assignedApplicationId; validatePreinstructor(request, applicationID, assignedApplicationID); @@ -1131,12 +1135,9 @@ public class ApplicationEvaluationDao { return null; } ApplicationEvaluationEntity entity = entityOptional.get(); - ApplicationEvaluationResponse response = convertToResponse(entity); - ApplicationEvaluationResponseBean targetResponse = Utils.convertSourceObjectToDestinationObject(response, ApplicationEvaluationResponseBean.class); - if (targetResponse != null && entity.getEmailSendResponse() != null) { - targetResponse.setEmailSendResponse(entity.getEmailSendResponse()); - } - return targetResponse; + ApplicationEvaluationResponse applicationEvaluationResponse = convertToResponse(entity); + applicationEvaluationResponse.setEmailSendResponse(entity.getEmailSendResponse()); + return applicationEvaluationResponse; } private List prepareEvaluationDocumentBeanList(ApplicationEvaluationEntity entity) { List docRequest = new ArrayList<>(); @@ -1893,12 +1894,16 @@ public class ApplicationEvaluationDao { ApplicationEntity oldApplicationEntity = Utils.getClonedEntityForData(application); + List responses = new ArrayList<>(); if(newStatus.equals(ApplicationStatusForEvaluation.ADMISSIBLE) && Boolean.TRUE.equals(application.getStatus().equals(ApplicationStatusTypeEnum.APPOINTMENT.getValue()))){ application.setStatus(newStatus.getValue()); log.info("Status updated to ADMISSIBLE for applicationId: " + application.getId()); emailNotificationDao.sendAdmissibilityNotificationEmailForAdmissibleApplication(application); emailSendResponse = emailDao.buildEmailSendResponseFromRequest(request); - saveEmailSendResponseToEvaluation(emailSendResponse,existingEntity); + responses = List.of(emailSendResponse); + if (!Boolean.TRUE.equals(emailSendResponse.getIsEmailSend())) { + saveEmailSendResponseToEvaluation(emailSendResponse, existingEntity); + } } if(newStatus.equals(ApplicationStatusForEvaluation.TECHNICAL_EVALUATION) && Boolean.TRUE.equals(application.getStatus().equals(ApplicationStatusTypeEnum.ADMISSIBLE.getValue()))){ @@ -1945,10 +1950,11 @@ public class ApplicationEvaluationDao { if (Boolean.TRUE.equals(statusType.equals((ApplicationStatusTypeEnum.APPROVED.getValue())))) { - application.setDateAccepted(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); - application.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); + application.setDateAccepted(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); + application.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); application = applicationRepository.save(application); // emailNotificationDao.sendAdmissibilityNotificationEmailForApprovedApplication(application); + notificationDao.sendNotificationToBeneficiary(application, NotificationTypeEnum.EVALUATION_RESULT); } if (Boolean.TRUE.equals(statusType.equals((ApplicationStatusTypeEnum.REJECTED.getValue())))) { application.setDateRejected(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); @@ -1956,15 +1962,23 @@ public class ApplicationEvaluationDao { application = applicationRepository.save(application); emailNotificationDao.sendInadmissibilityEmailForRejectedApplication(application,existingEntity); emailSendResponse = emailDao.buildEmailSendResponseFromRequest(request); - saveEmailSendResponseToEvaluation(emailSendResponse,existingEntity); + responses = List.of(emailSendResponse); + if (!Boolean.TRUE.equals(emailSendResponse.getIsEmailSend())) { + saveEmailSendResponseToEvaluation(emailSendResponse, existingEntity); + } + notificationDao.sendNotificationToBeneficiary(application, NotificationTypeEnum.EVALUATION_RESULT); } - Map placeHolders = notificationDao.sendNotificationToBeneficiary(application, NotificationTypeEnum.EVALUATION_RESULT); + Map placeHolders = new HashMap<>(); + placeHolders.put("{{call_name}}", application.getCall().getName()); + placeHolders.put("{{protocol_number}}", String.valueOf(application.getProtocol().getProtocolNumber())); notificationDao.sendNotificationToSuperUser(application,placeHolders,NotificationTypeEnum.EVALUATION_RESULT); notificationDao.sendNotificationToInstructor(placeHolders,existingEntity,NotificationTypeEnum.EVALUATION_RESULT); ApplicationEvaluationResponse response = convertToResponse(entity); - response.setEmailSendResponse(emailSendResponse); + if (!Boolean.TRUE.equals(emailSendResponse.getIsEmailSend())) { + response.setEmailSendResponse(responses); + } return response; } return null; @@ -2029,6 +2043,7 @@ public class ApplicationEvaluationDao { ApplicationEvaluationEntity entity = applicationEvaluationService.validateApplicationEvaluation(evaluationResponse.getId()); + //Handling Application Evaluation form EvaluationFormEntity evaluationFormEntity = evaluationFormService.validateEvaluationForm(evaluationFormId); validateFormFields(applicationEvaluationFormRequestBean,evaluationFormEntity); @@ -2037,7 +2052,9 @@ public class ApplicationEvaluationDao { validateFormFieldCustom(applicationEvaluationFormRequestBean.getFormFields(),entity,evaluationFormEntity); ApplicationEvaluationFormEntity applicationEvaluationFormEntity = getApplicationEvaluationFormOrCreate(evaluationFormEntity,entity); createOrUpdateMultipleFormFields(applicationEvaluationFormRequestBean.getFormFields(), applicationEvaluationFormEntity, evaluationFormEntity); - return processEvaluationForm(entity); + ApplicationEvaluationFormResponse response = processEvaluationForm(entity); + response.setEmailSendResponse(evaluationResponse.getEmailSendResponse()); + return response; } private ApplicationEvaluationFormEntity getApplicationEvaluationFormOrCreate(EvaluationFormEntity evaluationFormEntity, ApplicationEvaluationEntity applicationEvaluationEntity) { @@ -2282,6 +2299,7 @@ public class ApplicationEvaluationDao { } response.setCompanyVatNumber(company.getVatNumber()); response.setCompanyCodiceAteco(company.getCodiceAteco()); + response.setEmailSendResponse(evaluationEntity.getEmailSendResponse()); return response; } diff --git a/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java b/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java index 617c9dff..b1166689 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java @@ -62,11 +62,7 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -522,9 +518,12 @@ public class AppointmentDao { application.setStatus(ApplicationStatusTypeEnum.NDG.getValue()); applicationRepository.save(application); companyRepository.save(company); - ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluation( - application.getApplicationEvaluationId()); - Map placeHolders = notificationDao.sendNotificationToBeneficiary(application, NotificationTypeEnum.NDG_GENERATION); + ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluation(application.getApplicationEvaluationId()); +// Map placeHolders = notificationDao.sendNotificationToBeneficiary(application, NotificationTypeEnum.NDG_GENERATION); + + Map placeHolders = new HashMap<>(); + placeHolders.put("{{call_name}}", application.getCall().getName()); + placeHolders.put("{{protocol_number}}", String.valueOf(application.getProtocol().getProtocolNumber())); notificationDao.sendNotificationToInstructor(placeHolders, applicationEvaluationEntity, NotificationTypeEnum.NDG_GENERATION); notificationDao.sendNotificationToSuperUser(application, placeHolders, NotificationTypeEnum.NDG_GENERATION); log.info("NDG saved successfully for applicationId: {}", application.getId()); @@ -574,7 +573,10 @@ public class AppointmentDao { companyRepository.save(company); applicationRepository.save(application); ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluation(application.getApplicationEvaluationId()); - Map placeHolders = notificationDao.sendNotificationToBeneficiary(application, NotificationTypeEnum.NDG_GENERATION); +// Map placeHolders = notificationDao.sendNotificationToBeneficiary(application, NotificationTypeEnum.NDG_GENERATION); + Map placeHolders = new HashMap<>(); + placeHolders.put("{{call_name}}", application.getCall().getName()); + placeHolders.put("{{protocol_number}}", String.valueOf(application.getProtocol().getProtocolNumber())); notificationDao.sendNotificationToInstructor(placeHolders, applicationEvaluationEntity, NotificationTypeEnum.NDG_GENERATION); notificationDao.sendNotificationToSuperUser(application, placeHolders, NotificationTypeEnum.NDG_GENERATION); log.info("NDG saved for applicationId: {}, {}", application.getId(), application.getNdg()); diff --git a/src/main/java/net/gepafin/tendermanagement/dao/EmailDao.java b/src/main/java/net/gepafin/tendermanagement/dao/EmailDao.java index 9b99facb..244df6a4 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/EmailDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/EmailDao.java @@ -161,9 +161,10 @@ public class EmailDao { private boolean updateEmailSendResponse(List responses, String scenario) { if (responses == null || responses.isEmpty()) return false; - for (EmailSendResponse response : responses) { + for (Iterator iterator = responses.iterator(); iterator.hasNext(); ) { + EmailSendResponse response = iterator.next(); if (scenario.equals(response.getEmailScenario().getValue())) { - response.setIsEmailSend(true); + iterator.remove(); // remove only the first match return true; } } @@ -172,6 +173,7 @@ public class EmailDao { + public EmailSendResponse buildEmailSendResponseFromRequest(HttpServletRequest request) { Long userActionId = (Long) request.getAttribute(GepafinConstant.USER_ACTION_ID); List emailLogs = emailLogRepository.findByUserActionIdAndEmailServiceType(userActionId,EmailServiceTypeEnum.PEC_SERVICE.getValue()); diff --git a/src/main/java/net/gepafin/tendermanagement/dao/UserDao.java b/src/main/java/net/gepafin/tendermanagement/dao/UserDao.java index 234ffa1d..0403fde3 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/UserDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/UserDao.java @@ -149,17 +149,25 @@ public class UserDao { /** This code is responsible for adding a version history log for the "Create user" operation. **/ loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).newData(userEntity).build()); - EmailSendResponse emailSendResponse = new EmailSendResponse(); + List responses = new ArrayList<>(); if(Boolean.FALSE.equals(roleEntity.getRoleType().equals(RoleStatusEnum.ROLE_BENEFICIARY.getValue()))){ sendEmailToOnboardingUser(userEntity, userReq ); boolean isEmailSendSuccess = isEmailSentSuccessfully(userEntity.getId()); - emailSendResponse.setIsEmailSend(isEmailSendSuccess); - Long userActionId =(Long)request.getAttribute(GepafinConstant.USER_ACTION_ID); - emailSendResponse.setUserActionId(userActionId); - emailSendResponse.setEmailScenario(EmailScenarioTypeEnum.USER_CREATION); - saveEmailSendResponseToUser(emailSendResponse,userEntity); + EmailSendResponse emailSendResponse = new EmailSendResponse(); + if (Boolean.FALSE.equals(isEmailSendSuccess)){ + emailSendResponse.setIsEmailSend(false); + Long userActionId =(Long)request.getAttribute(GepafinConstant.USER_ACTION_ID); + emailSendResponse.setUserActionId(userActionId); + emailSendResponse.setEmailScenario(EmailScenarioTypeEnum.USER_CREATION); + + saveEmailSendResponseToUser(emailSendResponse,userEntity); + responses = List.of(emailSendResponse); + } + else{ + responses = Collections.emptyList(); + } } - JWTToken token = authService.getJWTTokenBean(userEntity, Boolean.TRUE, loginAttemptEntity.getId(),emailSendResponse); + JWTToken token = authService.getJWTTokenBean(userEntity, Boolean.TRUE, loginAttemptEntity.getId(),responses); return token; } @@ -509,8 +517,14 @@ public class UserDao { sendResetPasswordTokenEmail(user, token); InitiatePasswordResetResponse initiatePasswordResetResponse = new InitiatePasswordResetResponse(); EmailSendResponse emailSendResponse = emailDao.buildEmailSendResponseFromRequest(request); - initiatePasswordResetResponse.setEmailSendResponse(emailSendResponse); - saveEmailSendResponseToUser(emailSendResponse,user); + List responses = List.of(emailSendResponse); + if (!Boolean.TRUE.equals(emailSendResponse.getIsEmailSend())){ + initiatePasswordResetResponse.setEmailSendResponse(responses); + saveEmailSendResponseToUser(emailSendResponse,user); + } + else{ + initiatePasswordResetResponse.setEmailSendResponse(Collections.emptyList()); + } return initiatePasswordResetResponse; } diff --git a/src/main/java/net/gepafin/tendermanagement/entities/EmailSendResponseConverter.java b/src/main/java/net/gepafin/tendermanagement/entities/EmailSendResponseConverter.java index d02a842d..43409886 100644 --- a/src/main/java/net/gepafin/tendermanagement/entities/EmailSendResponseConverter.java +++ b/src/main/java/net/gepafin/tendermanagement/entities/EmailSendResponseConverter.java @@ -18,6 +18,9 @@ public class EmailSendResponseConverter implements AttributeConverter attribute) { try { + if (attribute == null) { + attribute = List.of(); + } return objectMapper.writeValueAsString(attribute); } catch (JsonProcessingException e) { throw new IllegalArgumentException("Error converting list to JSON", e); diff --git a/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationAmendmentRequestResponse.java b/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationAmendmentRequestResponse.java index ace60672..c7f1a2eb 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationAmendmentRequestResponse.java +++ b/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationAmendmentRequestResponse.java @@ -32,5 +32,5 @@ public class ApplicationAmendmentRequestResponse { private String internalNote; private ApplicationAmendmentRequestEnum status; private String emailTemplate; - private EmailSendResponse emailSendResponse; + private List emailSendResponse; } diff --git a/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationEvaluationFormResponse.java b/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationEvaluationFormResponse.java index 38530c8a..92f7933a 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationEvaluationFormResponse.java +++ b/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationEvaluationFormResponse.java @@ -48,5 +48,6 @@ public class ApplicationEvaluationFormResponse { private Long appointmentTemplateId; private String companyVatNumber; private String companyCodiceAteco; + private List emailSendResponse; } diff --git a/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationEvaluationResponse.java b/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationEvaluationResponse.java index 187aa1dd..49f07c6f 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationEvaluationResponse.java +++ b/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationEvaluationResponse.java @@ -49,6 +49,6 @@ public class ApplicationEvaluationResponse { private EvaluationVersionEnum evaluationVersion; private String companyVatNumber; private String companyCodiceAteco; - private EmailSendResponse emailSendResponse; + private List emailSendResponse; } diff --git a/src/main/java/net/gepafin/tendermanagement/model/response/EmailReminderResponse.java b/src/main/java/net/gepafin/tendermanagement/model/response/EmailReminderResponse.java index d76b4fcd..25b8a3b3 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/response/EmailReminderResponse.java +++ b/src/main/java/net/gepafin/tendermanagement/model/response/EmailReminderResponse.java @@ -5,12 +5,14 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import java.util.List; + @Data @AllArgsConstructor @NoArgsConstructor public class EmailReminderResponse { @JsonProperty("emailSendResponse") - private EmailSendResponse emailSendResponse; + private List emailSendResponse; } diff --git a/src/main/java/net/gepafin/tendermanagement/model/response/InitiatePasswordResetResponse.java b/src/main/java/net/gepafin/tendermanagement/model/response/InitiatePasswordResetResponse.java index c14ef643..129a1744 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/response/InitiatePasswordResetResponse.java +++ b/src/main/java/net/gepafin/tendermanagement/model/response/InitiatePasswordResetResponse.java @@ -5,9 +5,11 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import java.util.List; + @Data @AllArgsConstructor @NoArgsConstructor public class InitiatePasswordResetResponse { - private EmailSendResponse emailSendResponse; + private List emailSendResponse; } diff --git a/src/main/java/net/gepafin/tendermanagement/model/util/JWTToken.java b/src/main/java/net/gepafin/tendermanagement/model/util/JWTToken.java index a65f7d6e..fdfb3e3a 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/util/JWTToken.java +++ b/src/main/java/net/gepafin/tendermanagement/model/util/JWTToken.java @@ -6,6 +6,8 @@ import lombok.Data; import net.gepafin.tendermanagement.model.response.EmailSendResponse; import net.gepafin.tendermanagement.model.response.LoginResponse; +import java.util.List; + /** * JWTToken */ @@ -18,14 +20,14 @@ public class JWTToken { private LoginResponse loginResponse; @JsonProperty("emailSendResponse") - private EmailSendResponse emailSendResponse; + private List emailSendResponse; public JWTToken(String token, LoginResponse loginResponse) { this.token = token; this.loginResponse = loginResponse; } - public JWTToken(String token, LoginResponse loginResponse, EmailSendResponse emailSendResponse) { + public JWTToken(String token, LoginResponse loginResponse, List emailSendResponse) { this.token = token; this.loginResponse = loginResponse; this.emailSendResponse = emailSendResponse; diff --git a/src/main/java/net/gepafin/tendermanagement/repositories/ApplicationAmendmentRequestRepository.java b/src/main/java/net/gepafin/tendermanagement/repositories/ApplicationAmendmentRequestRepository.java index fc492019..d063eb37 100644 --- a/src/main/java/net/gepafin/tendermanagement/repositories/ApplicationAmendmentRequestRepository.java +++ b/src/main/java/net/gepafin/tendermanagement/repositories/ApplicationAmendmentRequestRepository.java @@ -150,4 +150,8 @@ public interface ApplicationAmendmentRequestRepository extends JpaRepository applicationIds, @Param("statuses") List statuses); + + ApplicationAmendmentRequestEntity findByIdAndIsDeletedFalseAndStatus(Long id,String status); + + ApplicationAmendmentRequestEntity findByIdAndIsDeletedFalseAndStatusIn(Long id, List statusList); } diff --git a/src/main/java/net/gepafin/tendermanagement/scheduler/ApplicationAmendmentScheduler.java b/src/main/java/net/gepafin/tendermanagement/scheduler/ApplicationAmendmentScheduler.java index 6a4c7b81..050b4972 100644 --- a/src/main/java/net/gepafin/tendermanagement/scheduler/ApplicationAmendmentScheduler.java +++ b/src/main/java/net/gepafin/tendermanagement/scheduler/ApplicationAmendmentScheduler.java @@ -122,7 +122,7 @@ public class ApplicationAmendmentScheduler { .findEvaluationsWithoutActiveAmendmentsByIds(applicationEvaluationIds); evaluationsWithoutActiveAmendmentList.forEach(evaluation -> { try { - applicationAmendmentRequestDao.calculateEndDateAndSuspensionDays(evaluation); + applicationAmendmentRequestDao.calculateEndDateAndSuspensionDaysOnExpirationOrClosing(evaluation); updateEvaluationStatus(evaluation); diff --git a/src/main/java/net/gepafin/tendermanagement/scheduler/ApplicationEvaluationScheduler.java b/src/main/java/net/gepafin/tendermanagement/scheduler/ApplicationEvaluationScheduler.java index c43aca10..af4cb6be 100644 --- a/src/main/java/net/gepafin/tendermanagement/scheduler/ApplicationEvaluationScheduler.java +++ b/src/main/java/net/gepafin/tendermanagement/scheduler/ApplicationEvaluationScheduler.java @@ -24,6 +24,7 @@ import org.springframework.stereotype.Component; import java.time.LocalDateTime; import java.time.LocalTime; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -87,7 +88,10 @@ public class ApplicationEvaluationScheduler { evaluation.setStatus(ApplicationEvaluationStatusTypeEnum.EXPIRED.getValue()); evaluation = applicationEvaluationRepository.save(evaluation); - Map placeHolders = notificationDao.sendNotificationToBeneficiary(application, NotificationTypeEnum.EVALUATION_EXPIRED); +// Map placeHolders = notificationDao.sendNotificationToBeneficiary(application, NotificationTypeEnum.EVALUATION_EXPIRED); + Map placeHolders = new HashMap<>(); + placeHolders.put("{{call_name}}", application.getCall().getName()); + placeHolders.put("{{protocol_number}}", String.valueOf(application.getProtocol().getProtocolNumber())); notificationDao.sendNotificationToSuperUser(application,placeHolders,NotificationTypeEnum.EVALUATION_EXPIRED); notificationDao.sendNotificationToInstructor(placeHolders,evaluation,NotificationTypeEnum.EVALUATION_EXPIRED); notificationDao.sendNotificationToInstructorManager(placeHolders,evaluation,NotificationTypeEnum.EVALUATION_EXPIRED); diff --git a/src/main/java/net/gepafin/tendermanagement/service/ApplicationAmendmentRequestService.java b/src/main/java/net/gepafin/tendermanagement/service/ApplicationAmendmentRequestService.java index 9b4b63ed..b19f77c4 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/ApplicationAmendmentRequestService.java +++ b/src/main/java/net/gepafin/tendermanagement/service/ApplicationAmendmentRequestService.java @@ -16,7 +16,7 @@ public interface ApplicationAmendmentRequestService { public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(HttpServletRequest request,Long applicationEvaluationId); public ApplicationAmendmentRequestResponse createApplicationAmendmentRequest(HttpServletRequest request, Long applicationEvaluationId , ApplicationAmendmentRequest applicationAmendmentRequest); void deleteApplicationAmendmentRequest(HttpServletRequest request, Long id); - ApplicationAmendmentRequestResponseBean getApplicationAmendmentRequestById(HttpServletRequest request,Long id); + ApplicationAmendmentRequestResponse getApplicationAmendmentRequestById(HttpServletRequest request,Long id); List getAllApplicationAmendmentRequest(HttpServletRequest request, Long userId); ApplicationAmendmentRequestResponse updateApplicationAmendment(HttpServletRequest request, Long id, ApplicationAmendmentRequestBean applicationAmendmentRequestBean); ApplicationAmendmentRequestEntity validateApplicationAmendmentRequest(Long applicationAmendmentId); diff --git a/src/main/java/net/gepafin/tendermanagement/service/ApplicationEvaluationService.java b/src/main/java/net/gepafin/tendermanagement/service/ApplicationEvaluationService.java index 67258e9c..86140ac6 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/ApplicationEvaluationService.java +++ b/src/main/java/net/gepafin/tendermanagement/service/ApplicationEvaluationService.java @@ -19,7 +19,7 @@ public interface ApplicationEvaluationService { void deleteApplicationEvaluation(HttpServletRequest request,Long id); - ApplicationEvaluationResponseBean getApplicationEvaluationByApplicationId(HttpServletRequest request,Long applicationId,Long assignedApplicationId); + ApplicationEvaluationResponse getApplicationEvaluationByApplicationId(HttpServletRequest request,Long applicationId,Long assignedApplicationId); ApplicationEvaluationEntity validateApplicationEvaluation(Long applicationEvaluationId); ApplicationEvaluationEntity validateApplicationEvaluationByApplicationId(Long applicationId); diff --git a/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationAmendmentRequestServiceImpl.java b/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationAmendmentRequestServiceImpl.java index 20a1e455..a680ec1b 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationAmendmentRequestServiceImpl.java +++ b/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationAmendmentRequestServiceImpl.java @@ -75,7 +75,7 @@ public class ApplicationAmendmentRequestServiceImpl implements ApplicationAmendm } @Override - public ApplicationAmendmentRequestResponseBean getApplicationAmendmentRequestById(HttpServletRequest request,Long id) { + public ApplicationAmendmentRequestResponse getApplicationAmendmentRequestById(HttpServletRequest request,Long id) { ApplicationAmendmentRequestEntity amendment = applicationAmendmentRequestRepository.findByIdAndIsDeletedFalse(id) .orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.APPLICATION_AMENDMENT_NOT_FOUND_MSG))); diff --git a/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationEvaluationServiceImpl.java b/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationEvaluationServiceImpl.java index 570487a8..650acdc1 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationEvaluationServiceImpl.java +++ b/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationEvaluationServiceImpl.java @@ -57,7 +57,7 @@ public class ApplicationEvaluationServiceImpl implements ApplicationEvaluationSe @Override @Transactional(readOnly = true) - public ApplicationEvaluationResponseBean getApplicationEvaluationByApplicationId( + public ApplicationEvaluationResponse getApplicationEvaluationByApplicationId( HttpServletRequest request, Long applicationId, Long assignedApplicationId) { UserEntity preInstructor = validator.validateUser(request); return applicationEvaluationDao.getApplicationEvaluationByApplicationId( diff --git a/src/main/java/net/gepafin/tendermanagement/service/impl/AuthenticationService.java b/src/main/java/net/gepafin/tendermanagement/service/impl/AuthenticationService.java index e112d40e..01ad155b 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/impl/AuthenticationService.java +++ b/src/main/java/net/gepafin/tendermanagement/service/impl/AuthenticationService.java @@ -142,7 +142,7 @@ public class AuthenticationService { loginAttemptEntity.setErrorMsg(errorMsg); loginAttemptDao.createLoginAttempt(loginAttemptEntity); } - public JWTToken getJWTTokenBean(UserEntity user, Boolean rememberMe, Long loginAttemptId, EmailSendResponse emailSendResponse) { + public JWTToken getJWTTokenBean(UserEntity user, Boolean rememberMe, Long loginAttemptId, List emailSendResponse) { UserEntity oldUserEntity = Utils.getClonedEntityForData(user); user.setLastLogin(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); user = userRepository.save(user); diff --git a/src/main/java/net/gepafin/tendermanagement/service/impl/SystemEmailService.java b/src/main/java/net/gepafin/tendermanagement/service/impl/SystemEmailService.java index 95939082..0cc64b89 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/impl/SystemEmailService.java +++ b/src/main/java/net/gepafin/tendermanagement/service/impl/SystemEmailService.java @@ -73,7 +73,10 @@ public class SystemEmailService implements EmailService { throw new RuntimeException("Failed to send email via Mailgun: " + (response != null ? response.getMessage() : "No response from Mailgun"), e); } - emailLogRequest.setEmailServiceResponse(response.toString()); + if(response != null) { + emailLogRequest.setEmailServiceResponse(response.toString()); + } + emailLogDao.createEmailLog(emailLogRequest); } } diff --git a/src/main/java/net/gepafin/tendermanagement/web/rest/api/ApplicationAmendmentRequestApi.java b/src/main/java/net/gepafin/tendermanagement/web/rest/api/ApplicationAmendmentRequestApi.java index 25b53b3c..5d81ce7e 100644 --- a/src/main/java/net/gepafin/tendermanagement/web/rest/api/ApplicationAmendmentRequestApi.java +++ b/src/main/java/net/gepafin/tendermanagement/web/rest/api/ApplicationAmendmentRequestApi.java @@ -72,7 +72,7 @@ public interface ApplicationAmendmentRequestApi { @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) }) @GetMapping(value = "", produces = "application/json") - ResponseEntity> getApplicationAmendmentRequestById(HttpServletRequest request,@Parameter(description = "The application amendment id", required = true) @RequestParam(value = "id", required = true) Long id); + ResponseEntity> getApplicationAmendmentRequestById(HttpServletRequest request,@Parameter(description = "The application amendment id", required = true) @RequestParam(value = "id", required = true) Long id); @Operation(summary = "Api to get all applications amendment request by preInstructor user Id (deprecated)", responses = { diff --git a/src/main/java/net/gepafin/tendermanagement/web/rest/api/ApplicationEvaluationApi.java b/src/main/java/net/gepafin/tendermanagement/web/rest/api/ApplicationEvaluationApi.java index 1b60e9d7..4798e078 100644 --- a/src/main/java/net/gepafin/tendermanagement/web/rest/api/ApplicationEvaluationApi.java +++ b/src/main/java/net/gepafin/tendermanagement/web/rest/api/ApplicationEvaluationApi.java @@ -44,7 +44,7 @@ public interface ApplicationEvaluationApi { @ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })) }) @GetMapping(value = "/application", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity> getApplicationEvaluationByApplicationId( + ResponseEntity> getApplicationEvaluationByApplicationId( HttpServletRequest request, @Parameter(required = false) @RequestParam(value = "applicationId", required = false) Long applicationId, @Parameter( required = false) @RequestParam(value = "assignedApplicationId", required = false) Long assignedApplicationId); diff --git a/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/ApplicationAmendmentRequestController.java b/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/ApplicationAmendmentRequestController.java index 739c2802..0c8ef489 100644 --- a/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/ApplicationAmendmentRequestController.java +++ b/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/ApplicationAmendmentRequestController.java @@ -69,14 +69,14 @@ public class ApplicationAmendmentRequestController implements ApplicationAmendme } @Override - public ResponseEntity> getApplicationAmendmentRequestById(HttpServletRequest request,Long id) { + public ResponseEntity> getApplicationAmendmentRequestById(HttpServletRequest request,Long id) { log.info("Get Application Amendment Request By Id"); /** This code is responsible for creating user action logs for the "get application amendment by id" operation. **/ loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW) .actionContext(UserActionContextEnum.GET_AMENDMENT).build()); - ApplicationAmendmentRequestResponseBean applicationAmendmentRequestResponse = applicationAmendmentRequestService.getApplicationAmendmentRequestById(request,id); + ApplicationAmendmentRequestResponse applicationAmendmentRequestResponse = applicationAmendmentRequestService.getApplicationAmendmentRequestById(request,id); return ResponseEntity.status(HttpStatus.OK) .body(new Response<>(applicationAmendmentRequestResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_APPLICATION_AMENDMENT_SUCCESS_MSG))); } @@ -185,11 +185,6 @@ public class ApplicationAmendmentRequestController implements ApplicationAmendme EmailReminderResponse emailSendResponse = applicationAmendmentRequestService.sendReminderEmail(request,amendmentId); - if (!emailSendResponse.getEmailSendResponse().getIsEmailSend()) { - return ResponseEntity.status(HttpStatus.OK) - .body(new Response<>(emailSendResponse, Status.EXCEPTION_ERROR, Translator.toLocale(GepafinConstant.REMINDER_EMAIL_FAILED_MSG))); - } - return ResponseEntity.status(HttpStatus.OK) .body(new Response<>(emailSendResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.REMINDER_EMAIL_SENT_SUCCESS_MSG))); } diff --git a/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/ApplicationEvaluationApiController.java b/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/ApplicationEvaluationApiController.java index 85486435..50eadb36 100644 --- a/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/ApplicationEvaluationApiController.java +++ b/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/ApplicationEvaluationApiController.java @@ -51,7 +51,7 @@ public class ApplicationEvaluationApiController implements ApplicationEvaluation @Override - public ResponseEntity> getApplicationEvaluationByApplicationId( + public ResponseEntity> getApplicationEvaluationByApplicationId( HttpServletRequest request, Long applicationId, Long assignedApplicationId) { @@ -59,7 +59,7 @@ public class ApplicationEvaluationApiController implements ApplicationEvaluation loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW).actionContext(UserActionContextEnum.GET_APPLICATION_EVALUATION).build()); - ApplicationEvaluationResponseBean response = null; + ApplicationEvaluationResponse response = null; response = applicationEvaluationService.getApplicationEvaluationByApplicationId(request, applicationId,assignedApplicationId); return ResponseEntity.status(HttpStatus.OK) .body(new Response<>(response, Status.SUCCESS, Translator.toLocale(GepafinConstant.EVALUATION_FETCHED_SUCCESSFULLY))); diff --git a/src/main/resources/db/changelog/db.changelog-1.0.0.xml b/src/main/resources/db/changelog/db.changelog-1.0.0.xml index de206a11..a911a3ac 100644 --- a/src/main/resources/db/changelog/db.changelog-1.0.0.xml +++ b/src/main/resources/db/changelog/db.changelog-1.0.0.xml @@ -2653,6 +2653,8 @@ + + @@ -2666,12 +2668,16 @@ + + + +