diff --git a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java index 0ef82457..8e56fb33 100644 --- a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java +++ b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java @@ -1,5 +1,8 @@ package net.gepafin.tendermanagement.constants; +import java.util.Arrays; +import java.util.List; + public class GepafinConstant { public static final String USER_CREATED_SUCCESS_MSG = "user.created.success"; @@ -614,6 +617,12 @@ public class GepafinConstant { " \n" + " \n" + ""; + public static final String UPDATE_APPLICATION_TECHNICAL_EVALUATION_REJECTED_MSG = "application.technical.evaluation.rejected.success"; + public static final String SUBJECT = "subject"; + public static final List MANUAL_EMAIL_KEYS = Arrays.asList(SUBJECT, MESSAGE); + public static final String INVALID_EMAIL_JSON = "invalid.email.json"; + public static final String MORE_FIELDS_REQUIRED_FOR_REJECTION="more.fields.required"; + } diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java index c2304d5b..3e6bf38d 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java @@ -34,6 +34,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Component; +import org.springframework.web.multipart.MultipartFile; import java.math.BigDecimal; import java.time.LocalDateTime; @@ -149,6 +150,9 @@ public class ApplicationAmendmentRequestDao { @Autowired private EmailDao emailDao; + @Autowired + private DocumentDao documentDao; + public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(Long applicationEvaluationId) { log.info("Fetching the application data for the Amendment process {}", applicationEvaluationId); ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluation(applicationEvaluationId); @@ -302,10 +306,10 @@ public class ApplicationAmendmentRequestDao { return filteredList; } - public ApplicationAmendmentRequestResponse createApplicationAmendmentRequest(Long applicationEvaluationId, ApplicationAmendmentRequest applicationAmendmentRequest) { + public ApplicationAmendmentRequestResponse createApplicationAmendmentRequest(Long applicationEvaluationId, List files, ApplicationAmendmentRequest applicationAmendmentRequest,Long userId) { log.info("Submiting application data for amendment Process with details: {}", applicationEvaluationId); - ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = createApplicationAmendmentRequestEntity(applicationAmendmentRequest, applicationEvaluationId); + ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = createApplicationAmendmentRequestEntity(applicationAmendmentRequest, applicationEvaluationId,files, userId); ApplicationAmendmentRequestResponse applicationAmendmentRequestResponse = convertEntityToResponse(applicationAmendmentRequestEntity,false); log.info("Application submitted successfully for amendment", applicationAmendmentRequestResponse); if (Boolean.TRUE.equals(applicationAmendmentRequestResponse.getIsSendEmail())) { @@ -323,7 +327,7 @@ public class ApplicationAmendmentRequestDao { return applicationAmendmentRequestResponse; } - public ApplicationAmendmentRequestEntity createApplicationAmendmentRequestEntity(ApplicationAmendmentRequest applicationAmendmentRequest,Long applicationEvaluationId) { + public ApplicationAmendmentRequestEntity createApplicationAmendmentRequestEntity(ApplicationAmendmentRequest applicationAmendmentRequest,Long applicationEvaluationId,List files,Long userId) { ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = new ApplicationAmendmentRequestEntity(); applicationAmendmentRequestEntity.setNote(applicationAmendmentRequest.getNote()); applicationAmendmentRequestEntity.setResponseDays(applicationAmendmentRequest.getResponseDays()); @@ -337,6 +341,7 @@ public class ApplicationAmendmentRequestDao { applicationAmendmentRequestEntity.setIsNotification(applicationAmendmentRequest.getIsSendNotification()); applicationAmendmentRequestEntity.setStartDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); applicationAmendmentRequestEntity.setStatus(ApplicationAmendmentRequestEnum.AWAITING.getValue()); + applicationAmendmentRequestEntity.setType(ApplicationAmendmentRequestTypeEnum.REGULAR.getValue()); ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluation(applicationEvaluationId); //cloned for old data entity ApplicationEvaluationEntity oldApplicationEvaluationEntity = Utils.getClonedEntityForData(applicationEvaluationEntity); @@ -345,7 +350,8 @@ public class ApplicationAmendmentRequestDao { Long applicationId = applicationEvaluationEntity.getApplicationId(); Long assignedApplicationId = applicationEvaluationEntity.getAssignedApplicationsEntity().getId(); applicationAmendmentRequestEntity.setApplicationId(applicationId); - + ApplicationEntity applicationEntity = applicationService.validateApplication(applicationId); + ApplicationEntity oldApplicationEntity = Utils.getClonedEntityForData(applicationEntity); if (applicationAmendmentRequest.getFormFields() != null) { List formFieldRequestBean = applicationAmendmentRequest.getFormFields().stream() .filter(AmendmentFormFieldResponse::isSelected) @@ -362,18 +368,22 @@ public class ApplicationAmendmentRequestDao { } List amendmentRequest = applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(applicationEvaluationEntity.getId()); // Ensure startDate and initialDays are not null to avoid NullPointerException - if (amendmentRequest !=null && amendmentRequest.isEmpty() && applicationEvaluationEntity.getStartDate() != null && applicationEvaluationEntity.getInitialDays() != null ) { - Long initialDays = applicationEvaluationEntity.getInitialDays(); - LocalDateTime startDate = applicationEvaluationEntity.getStartDate(); - LocalDateTime nowInUTC = DateTimeUtil.DateServerToUTC(LocalDateTime.now()); - // Calculate remaining days - Long remainingDays = initialDays - DAYS.between(startDate, nowInUTC); - // Set remaining days in the entity - applicationEvaluationEntity.setRemainingDays(remainingDays); - //Set stop date time in the entity becuase amendment has started - applicationEvaluationEntity.setStopDateTime(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); + if (amendmentRequest !=null && amendmentRequest.isEmpty()) { + if (applicationEvaluationEntity.getStartDate() != null && applicationEvaluationEntity.getInitialDays() != null) { + Long initialDays = applicationEvaluationEntity.getInitialDays(); + LocalDateTime startDate = applicationEvaluationEntity.getStartDate(); + LocalDateTime nowInUTC = DateTimeUtil.DateServerToUTC(LocalDateTime.now()); + // Calculate remaining days + Long remainingDays = initialDays - DAYS.between(startDate, nowInUTC); + // Set remaining days in the entity + applicationEvaluationEntity.setRemainingDays(remainingDays); + //Set stop date time in the entity becuase amendment has started + applicationEvaluationEntity.setStopDateTime(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); + } + applicationEntity.setPreviousStatus(oldApplicationEntity.getStatus()); } + UserEntity userEntity = userService.validateUser(applicationEvaluationEntity.getUserId()); Long protocolNumber = protocolDao.getProtocolNumber(userEntity.getHub()); ProtocolEntity protocolEntity = protocolDao.createProtocolEntity( @@ -383,7 +393,15 @@ public class ApplicationAmendmentRequestDao { applicationAmendmentRequestEntity.setProtocol(protocolEntity); ApplicationAmendmentRequestEntity applicationAmendment = saveApplicationAmendmentRequestEntity(applicationAmendmentRequestEntity, null, VersionActionTypeEnum.INSERT); log.info("Amendment request saved with ID={}", applicationAmendment.getId()); - + List documentResponseBeans= uploadInitialDocument(userId,files,applicationAmendment); + List initialDocumentIds = documentResponseBeans.stream() + .map(DocumentResponseBean::getId) + .collect(Collectors.toList()); + String initialDocumentId = initialDocumentIds.stream() + .map(String::valueOf) + .collect(Collectors.joining(",")); + applicationAmendment.setAmendmentInitialDocument(initialDocumentId); + applicationAmendment = saveApplicationAmendmentRequestEntity(applicationAmendment, null, VersionActionTypeEnum.UPDATE); String evaluationStatusType = applicationEvaluationEntity.getStatus(); if (Boolean.FALSE.equals(evaluationStatusType.equals((ApplicationEvaluationStatusTypeEnum.SOCCORSO.getValue())))){ // applicationEvaluationEntity.setStatus(ApplicationEvaluationStatusTypeEnum.SOCCORSO.getValue()); @@ -396,8 +414,7 @@ public class ApplicationAmendmentRequestDao { loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationEvaluationEntity).newData(applicationEvaluationEntity).build()); } - ApplicationEntity applicationEntity = applicationService.validateApplication(applicationId); - ApplicationEntity oldApplicationEntity = Utils.getClonedEntityForData(applicationEntity); + String applicationStatusType = applicationEntity.getStatus(); if (Boolean.FALSE.equals(applicationStatusType.equals((ApplicationStatusTypeEnum.SOCCORSO.getValue())))) { applicationEntity.setStatus(ApplicationStatusTypeEnum.SOCCORSO.getValue()); @@ -468,45 +485,65 @@ public class ApplicationAmendmentRequestDao { // List amendmentDetailsList = // Utils.convertJsonStringToList(applicationAmendmentRequestEntity.getAmendmentDocument(), // AmendmentDetailsResponseBean.class); - AmendmentDetailsResponseBean amendmentDetails = Utils.convertStringToObject(applicationAmendmentRequestEntity.getAmendmentDocument() ,AmendmentDetailsResponseBean.class); - if(amendmentDetails!=null) { - List documentResponseBeans = new ArrayList<>(); - if (amendmentDetails.getAmendmentDocuments() != null) { - // Extract the comma-separated document IDs as a string - String documentIdsString = amendmentDetails.getAmendmentDocuments(); + AmendmentDetailsResponseBean amendmentDetails = Utils.convertStringToObject(applicationAmendmentRequestEntity.getAmendmentDocument(), AmendmentDetailsResponseBean.class); + if (amendmentDetails != null) { + List documentResponseBeans = new ArrayList<>(); + if (amendmentDetails.getAmendmentDocuments() != null) { + // Extract the comma-separated document IDs as a string + String documentIdsString = amendmentDetails.getAmendmentDocuments(); - if (documentIdsString != null && !documentIdsString.trim().isEmpty()) { - // Split the comma-separated values and process them - List documentIds = Arrays.stream(documentIdsString.split(",")) - .map(String::trim) - .filter(id -> !id.isEmpty()) - .collect(Collectors.toList()); + if (documentIdsString != null && !documentIdsString.trim().isEmpty()) { + // Split the comma-separated values and process them + List documentIds = Arrays.stream(documentIdsString.split(",")) + .map(String::trim) + .filter(id -> !id.isEmpty()) + .collect(Collectors.toList()); - documentResponseBeans.addAll( - documentIds.stream() - .map(id -> { - try { - return createDocumentResponseBean(id); // Convert to Long - } catch (NumberFormatException e) { - // Handle invalid document IDs gracefully - return null; - } - }) - .filter(Objects::nonNull) // Skip null responses - .collect(Collectors.toList()) - ); - response.setAmendmentNotes(amendmentDetails.getAmendmentNotes()); - response.setValid(amendmentDetails.getValid()); - } + documentResponseBeans.addAll( + documentIds.stream() + .map(id -> { + try { + return createDocumentResponseBean(id); // Convert to Long + } catch (NumberFormatException e) { + // Handle invalid document IDs gracefully + return null; + } + }) + .filter(Objects::nonNull) // Skip null responses + .collect(Collectors.toList()) + ); + response.setAmendmentNotes(amendmentDetails.getAmendmentNotes()); + response.setValid(amendmentDetails.getValid()); } - response.setAmendmentDocuments(documentResponseBeans); } - - - + response.setAmendmentDocuments(documentResponseBeans); + } } + List initialDocumentBeans = new ArrayList<>(); + String initialDocuments = applicationAmendmentRequestEntity.getAmendmentInitialDocument(); + if (initialDocuments != null && !initialDocuments.trim().isEmpty()) { + // Split the comma-separated values and process them + List documentIds = Arrays.stream(initialDocuments.split(",")) + .map(String::trim) + .filter(id -> !id.isEmpty()) + .collect(Collectors.toList()); + initialDocumentBeans.addAll( + documentIds.stream() + .map(id -> { + try { + return createDocumentResponseBean(id); // Convert to Long + } catch (NumberFormatException e) { + // Handle invalid document IDs gracefully + return null; + } + }) + .filter(Objects::nonNull) // Skip null responses + .collect(Collectors.toList()) + ); + } + response.setAmendmentInitialDocuments(initialDocumentBeans); processFormFields(amendmentFormFields, fieldIdToLabelMap, formFieldEntityMap, response); return response; @@ -560,13 +597,15 @@ public class ApplicationAmendmentRequestDao { Map bodyPlaceholders = emailNotificationDao.prepareEmailPlaceholders(applicationEntity, entity); EmailContentResponse emailContent =null; if(entity.getType()!=null && entity.getType().equals(ApplicationAmendmentRequestTypeEnum.SPECIAL.getValue())){ - emailContent=emailNotificationDao.prepareEmailContent(applicationEntity, SystemEmailTemplatesEntityTypeEnum.SPECIAL_APPLICATION_AMENDMENT_REQUESTED, hubEntity, bodyPlaceholders); + emailContent=emailNotificationDao.prepareEmailContent(applicationEntity, SystemEmailTemplatesEntityTypeEnum.SPECIAL_APPLICATION_AMENDMENT_REQUESTED, hubEntity, bodyPlaceholders,null); }else { - emailContent = emailNotificationDao.prepareEmailContent(applicationEntity, SystemEmailTemplatesEntityTypeEnum.DOCUMENTATION_INTEGRATION_REQUEST, hubEntity, bodyPlaceholders); + emailContent = emailNotificationDao.prepareEmailContent(applicationEntity, SystemEmailTemplatesEntityTypeEnum.DOCUMENTATION_INTEGRATION_REQUEST, hubEntity, bodyPlaceholders,null); } String body = emailContent.getBody(); response.setEmailTemplate(body); } + response.setAmendmentType(entity.getType()); + response.setAmendmentDocumentType(entity.getAmendmentDocumentType()); return response; } @@ -604,23 +643,7 @@ public class ApplicationAmendmentRequestDao { createFormField(formFields, fieldIdToLabelMap, amendmentFormField); // Create document responses - List documentIds = extractIds(amendmentFormField.getFieldValue()); - List documentResponseBeans = documentIds.stream() - .map(id -> { - DocumentEntity documentEntity = documentService.validateDocument(id); - DocumentResponseBean responseBean = new DocumentResponseBean(); - responseBean.setId(documentEntity.getId()); - responseBean.setName(documentEntity.getFileName()); - responseBean.setType(DocumentTypeEnum.valueOf(documentEntity.getType())); - responseBean.setSource(DocumentSourceTypeEnum.valueOf(documentEntity.getSource())); - responseBean.setSourceId(documentEntity.getSourceId()); - responseBean.setFilePath(documentEntity.getFilePath()); - responseBean.setCreatedDate(documentEntity.getCreatedDate()); - responseBean.setUpdatedDate(documentEntity.getUpdatedDate()); - responseBean.setDocumentAttachmentId(documentEntity.getDocumentAttachmentId()); - return responseBean; - }) - .toList(); + List documentResponseBeans = getDocumentResponseBean(amendmentFormField.getFieldValue()); // Map to application form field response bean ApplicationFormFieldEntity formFieldEntity = formFieldEntityMap.get(amendmentFormField.getFieldId()); @@ -639,6 +662,27 @@ public class ApplicationAmendmentRequestDao { response.setApplicationFormFields(fileDetails); } + private List getDocumentResponseBean(String documentId) { + List documentIds = extractIds(documentId); + List documentResponseBeans = documentIds.stream() + .map(id -> { + DocumentEntity documentEntity = documentService.validateDocument(id); + DocumentResponseBean responseBean = new DocumentResponseBean(); + responseBean.setId(documentEntity.getId()); + responseBean.setName(documentEntity.getFileName()); + responseBean.setType(DocumentTypeEnum.valueOf(documentEntity.getType())); + responseBean.setSource(DocumentSourceTypeEnum.valueOf(documentEntity.getSource())); + responseBean.setSourceId(documentEntity.getSourceId()); + responseBean.setFilePath(documentEntity.getFilePath()); + responseBean.setCreatedDate(documentEntity.getCreatedDate()); + responseBean.setUpdatedDate(documentEntity.getUpdatedDate()); + responseBean.setDocumentAttachmentId(documentEntity.getDocumentAttachmentId()); + return responseBean; + }) + .toList(); + return documentResponseBeans; + } + private String buildBeneficiaryName(UserEntity userEntity) { if (userEntity.getBeneficiary() == null) { return ""; @@ -1120,9 +1164,11 @@ public class ApplicationAmendmentRequestDao { applicationEvaluationRepository.save(existingApplicationAmendment.getApplicationEvaluationEntity()); log.info("Updated ApplicationEvaluation status to OPEN for ID: {}", existingApplicationEvaluationEntity.getId()); - application.setStatus(ApplicationStatusTypeEnum.EVALUATION.getValue()); + if(Boolean.FALSE.equals(existingApplicationAmendment.getType().equals(ApplicationAmendmentRequestTypeEnum.SPECIAL.getValue()))){ + application.setStatus(application.getPreviousStatus()); + } applicationRepository.save(application); - log.info("Updated Application status to EVALUATION for Application ID: {}", application.getId()); + log.info("Updated Application status to previous state for Application ID: {}", application.getId()); existingApplicationAmendment.getApplicationEvaluationEntity().getAssignedApplicationsEntity().setStatus(AssignedApplicationEnum.OPEN.getValue()); @@ -1871,5 +1917,10 @@ public class ApplicationAmendmentRequestDao { log.info("Application submitted successfully for amendment", applicationAmendmentRequestResponse); return applicationAmendmentRequestResponse; } - + public List uploadInitialDocument(Long userId,List files,ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity){ + if(files!=null) { + return documentDao.uploadFiles(userId, files, applicationAmendmentRequestEntity.getId(), DocumentSourceTypeEnum.AMENDMENT, DocumentTypeEnum.DOCUMENT); + } + return new ArrayList<>(); + } } diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java index d71aa1a8..dd978ee9 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java @@ -1,5 +1,6 @@ package net.gepafin.tendermanagement.dao; +import com.amazonaws.services.dynamodbv2.xspec.L; import com.amazonaws.services.dynamodbv2.xspec.S; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonNode; @@ -131,6 +132,9 @@ public class ApplicationDao { @Autowired private AssignedApplicationsRepository assignedApplicationsRepository; + @Autowired + private CommunicationRepository communicationRepository; + // @Value("${default_System_Receiver_Email}") // private String defaultSystemReceiverEmail; @@ -1372,7 +1376,7 @@ public class ApplicationDao { ApplicationSignedDocumentEntity oldApplicationSignedDocument = Utils.getClonedEntityForData(applicationSignedDocumentEntity); String oldS3Path = applicationSignedDocumentEntity.getFilePath(); log.debug("Old S3 path: {} ", oldS3Path); - String newS3Path = s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.DELETED_USER_SIGNED_DOCUMENT,applicationSignedDocumentEntity.getApplication().getCall().getId(),applicationSignedDocumentEntity.getApplication().getId(),0L); + String newS3Path = s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.DELETED_USER_SIGNED_DOCUMENT,applicationSignedDocumentEntity.getApplication().getCall().getId(),applicationSignedDocumentEntity.getApplication().getId(),0L,0L); log.debug("Generated new S3 path for deleted document: {}", newS3Path); UploadFileOnAmazonS3Response response = amazonS3Service.moveFile(applicationSignedDocumentEntity.getFileName(), oldS3Path, newS3Path); @@ -1407,7 +1411,7 @@ public class ApplicationDao { } private String generateS3PathForDelegation(Long callId, Long applicationId) { try { - return s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_SIGNED_DOCUMENT, callId, applicationId,0L); + return s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_SIGNED_DOCUMENT, callId, applicationId,0L,0L); } catch (IllegalArgumentException e) { log.error("Failed to generate S3 path for delegation | callId: {}, applicationId: {}, error: {}", callId, applicationId, e.getMessage(), e); throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.S3_PATH_GENERATION_ERROR_MSG)); @@ -1529,11 +1533,12 @@ public class ApplicationDao { ApplicationSignedDocumentStatusEnum.ACTIVE.getValue()); List amendmentDocuments = fetchAmendmentDocuments(applicationId); List evaluationDocuments = fetchEvaluationDocuments(applicationId); + List communicationnDocuments = fetchCommunicationDocuments(applicationId); if (documents.isEmpty() && signedDocument == null && amendmentDocuments.isEmpty() && evaluationDocuments.isEmpty()) { log.warn("No documents found for applicationId: {}", applicationId); throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND)); } - return createZipWithDocuments(applicationEntity, documents, signedDocument, amendmentDocuments, evaluationDocuments, applicationId); + return createZipWithDocuments(applicationEntity, documents, signedDocument, amendmentDocuments, evaluationDocuments, applicationId,communicationnDocuments); } private void validateAssignedUser(HttpServletRequest request, Long applicationId) { @@ -1582,6 +1587,28 @@ public class ApplicationDao { } return Collections.emptyList(); } + private List fetchCommunicationDocuments(Long applicationId) { + log.info("Fetching communication documents for applicationId: {}", applicationId); + List amendmentRequests = applicationAmendmentRequestRepository.findByApplicationIdAndIsDeletedFalse(applicationId); + List amendmentRequestIds = amendmentRequests.stream() + .map(ApplicationAmendmentRequestEntity::getId) + .collect(Collectors.toList()); + List communicationEntities=communicationRepository.findByApplicationAmendmentRequestIdInAndIsDeletedFalse(amendmentRequestIds); + List documentEntities=new ArrayList<>(); + if (Boolean.FALSE.equals(communicationEntities.isEmpty())) { + for (CommunicationEntity communicationEntity : communicationEntities) { + { + Long communicationId = communicationEntity.getId(); + log.debug("Found communication entity with id: {}", communicationId); + + List communicationDocuments= documentRepository.findBySourceIdInAndSourceAndIsDeletedFalse(Collections.singleton(communicationId), DocumentSourceTypeEnum.COMMUNICATION.getValue()); + documentEntities.addAll(communicationDocuments); + } + } + return documentEntities; + } + return Collections.emptyList(); + } private String fetchProtocolNumberForAmendment(Long amendmentRequestId) { ApplicationAmendmentRequestEntity amendmentRequest = applicationAmendmentRequestRepository.findByIdAndIsDeletedFalse(amendmentRequestId).orElse(null); @@ -1603,12 +1630,12 @@ public class ApplicationDao { } } private byte[] createZipWithDocuments(ApplicationEntity applicationEntity, List documents, ApplicationSignedDocumentEntity signedDocument, - List amendmentDocuments, List evaluationDocuments, Long applicationId) { + List amendmentDocuments, List evaluationDocuments, Long applicationId,List communicationDocuments) { try (ByteArrayOutputStream zipOutputStream = new ByteArrayOutputStream(); ZipOutputStream zos = new ZipOutputStream(zipOutputStream)) { Long callId = applicationEntity.getCall().getId(); // Add Application Documents - String appS3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.APPLICATION, callId, applicationId, 0L); + String appS3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.APPLICATION, callId, applicationId, 0L,0L); for (DocumentEntity document : documents) { String fileName = Utils.extractFileName(document.getFilePath()); addDocumentToZip(zos, appS3Folder, document.getFilePath(), fileName); @@ -1616,7 +1643,7 @@ public class ApplicationDao { // Add Signed Document if (signedDocument != null) { String signedFolder = "SIGNED_DOCUMENT/"; - String signedDocS3Folder = s3PathConfig.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_SIGNED_DOCUMENT, callId, applicationId, 0L); + String signedDocS3Folder = s3PathConfig.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_SIGNED_DOCUMENT, callId, applicationId, 0L,0L); String fileName = signedDocument.getFileName(); addDocumentToZip(zos, signedDocS3Folder, signedDocument.getFilePath(), signedFolder + fileName); } @@ -1624,17 +1651,24 @@ public class ApplicationDao { for (DocumentEntity amendmentDocument : amendmentDocuments) { String protocolNumber = fetchProtocolNumberForAmendment(amendmentDocument.getSourceId()); String amendmentFolder = "SOCCORSO_" + protocolNumber + "/"; - String amendmentS3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.AMENDMENT, callId, applicationId, amendmentDocument.getSourceId()); + String amendmentS3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.AMENDMENT, callId, applicationId, amendmentDocument.getSourceId(),0L); String fileName = Utils.extractFileName(amendmentDocument.getFilePath()); addDocumentToZip(zos, amendmentS3Folder, amendmentDocument.getFilePath(), amendmentFolder + fileName); } // Add Evaluation Documents for (DocumentEntity evaluationDocument : evaluationDocuments) { String evaluationFolder = "EVALUATION/"; - String evaluationS3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.EVALUATION, callId, applicationId, evaluationDocument.getSourceId()); + String evaluationS3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.EVALUATION, callId, applicationId, evaluationDocument.getSourceId(),0L); String fileName = Utils.extractFileName(evaluationDocument.getFilePath()); addDocumentToZip(zos, evaluationS3Folder, evaluationDocument.getFilePath(), evaluationFolder + fileName); } + for (DocumentEntity communicationDocument : communicationDocuments) { + Optional communicationEntity=communicationRepository.findByIdAndIsDeletedFalse(communicationDocument.getSourceId()); + String evaluationFolder = "COMMUNICATION/"; + String evaluationS3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.COMMUNICATION, callId, applicationId, communicationEntity.get().getApplicationAmendmentRequest().getId(),communicationDocument.getSourceId()); + String fileName = Utils.extractFileName(communicationDocument.getFilePath()); + addDocumentToZip(zos, evaluationS3Folder, communicationDocument.getFilePath(), evaluationFolder + fileName); + } zos.finish(); return zipOutputStream.toByteArray(); } catch (IOException e) { diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java index 57158cad..00f37bc1 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java @@ -19,8 +19,10 @@ import net.gepafin.tendermanagement.web.rest.api.errors.Status; import org.apache.commons.lang3.StringUtils; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; +import org.springframework.web.multipart.MultipartFile; import java.math.BigDecimal; import java.text.MessageFormat; @@ -146,6 +148,11 @@ public class ApplicationEvaluationDao { @Autowired private EmailDao emailDao; + @Autowired + private DocumentDao documentDao; + + @Value("${default.hub.uuid}") + private String defaultHubUuid; private ApplicationEvaluationEntity convertToEntity(UserEntity user, ApplicationEvaluationRequest req, Long assignedApplciationId) { @@ -182,7 +189,7 @@ public class ApplicationEvaluationDao { ApplicationEvaluationResponse response = new ApplicationEvaluationResponse(); populateBasicDetails(entity, response); - + ApplicationEntity applicationEntity=entity.getAssignedApplicationsEntity().getApplication(); CallEntity call = callRepository.findCallEntityByApplicationId(entity.getApplicationId()); List evaluationCriterias = evaluationCriteriaRepository .findByCallIdAndLookupDataTypeAndIsDeletedFalse(call.getId(), LookUpDataEntity.LookUpDataTypeEnum.EVALUATION_CRITERIA.getValue()); @@ -201,10 +208,39 @@ public class ApplicationEvaluationDao { List allDocs = prepareEvaluationDocumentBeanList(entity); setEvaluationDocResponse(response, allDocs); setApplicationDetails(response, entity); + setRejectedDocuments(applicationEntity, response); return response; } + private void setRejectedDocuments(ApplicationEntity applicationEntity, ApplicationEvaluationResponse response) { + List initialDocumentBeans = new ArrayList<>(); + String initialDocuments = applicationEntity.getRejectedDocument(); + + if (initialDocuments != null && !initialDocuments.trim().isEmpty()) { + // Split the comma-separated values and process them + List documentIds = Arrays.stream(initialDocuments.split(",")) + .map(String::trim) + .filter(id -> !id.isEmpty()) + .collect(Collectors.toList()); + + initialDocumentBeans.addAll( + documentIds.stream() + .map(id -> { + try { + return applicationAmendmentRequestDao.createDocumentResponseBean(id); // Convert to Long + } catch (NumberFormatException e) { + // Handle invalid document IDs gracefully + return null; + } + }) + .filter(Objects::nonNull) // Skip null responses + .collect(Collectors.toList()) + ); + } + response.setRejectedDocument(initialDocumentBeans); + } + private void setAmendmentDetails(ApplicationEvaluationEntity entity, ApplicationEvaluationResponse response) { List amendmentRequests=applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(entity.getId()); List amendmentDocumentResponseBeans=new ArrayList<>(); @@ -653,7 +689,7 @@ public class ApplicationEvaluationDao { public ApplicationEvaluationResponse createOrUpdateApplicationEvaluation( UserEntity user, ApplicationEvaluationRequest req, - Long assignedApplicationId) { + Long assignedApplicationId, List rejectedDocuments) { log.info("Start createOrUpdateApplicationEvaluation: assignedApplicationId={}, userId={}", assignedApplicationId, user.getId()); Optional existingEntityOptional = @@ -741,7 +777,7 @@ public class ApplicationEvaluationDao { if (status != null) { AssignedApplicationsEntity assignedApplicationsEntity = assignedApplications.get(); - return updateApplicationEvaluationStatus(application, assignedApplicationsEntity, status); + return updateApplicationEvaluationStatus(application, assignedApplicationsEntity, status,rejectedDocuments,req); } else { return convertToResponse(entity); } @@ -1903,7 +1939,7 @@ public class ApplicationEvaluationDao { } public ApplicationEvaluationResponse updateApplicationEvaluationStatus(ApplicationEntity application, AssignedApplicationsEntity assignedApplicationsEntity, - ApplicationStatusForEvaluation newStatus) { + ApplicationStatusForEvaluation newStatus, List files,ApplicationEvaluationRequest applicationEvaluationRequest) { log.info("Starting updateApplicationEvaluationStatus for applicationId: {}, assignedApplicationId: {}, newStatus: {}", application.getId(), assignedApplicationsEntity.getId(), newStatus); @@ -1997,10 +2033,30 @@ public class ApplicationEvaluationDao { notificationDao.sendNotificationToBeneficiary(application, NotificationTypeEnum.EVALUATION_RESULT); } if (Boolean.TRUE.equals(statusType.equals((ApplicationStatusTypeEnum.REJECTED.getValue())))) { + String tipoInammissibilita =null; + String emailType=null; + if(Boolean.TRUE.equals(hub.getUniqueUuid().equals(defaultHubUuid))) { + if (applicationEvaluationRequest.getMotivation() == null || applicationEvaluationRequest.getRejectedReason() == null || applicationEvaluationRequest.getRejectedReasonSubject()==null) { + throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.MORE_FIELDS_REQUIRED_FOR_REJECTION)); + } + if (files != null) { + List documentResponseBeans = uploadRejectedDocument(user.getId(), files, application); + List rejectedDocumentIds = documentResponseBeans.stream() + .map(DocumentResponseBean::getId) + .collect(Collectors.toList()); + String rejectedDocumentId = rejectedDocumentIds.stream() + .map(String::valueOf) + .collect(Collectors.joining(",")); + application.setRejectedDocument(rejectedDocumentId); + } + tipoInammissibilita=applicationEvaluationRequest.getRejectedReason(); + emailType=applicationEvaluationRequest.getRejectedReasonSubject(); + application.setRejectedReason(applicationEvaluationRequest.getRejectedReason()); + } application.setDateRejected(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); application.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); application = applicationRepository.save(application); - emailNotificationDao.sendInadmissibilityEmailForRejectedApplication(application,existingEntity); + emailNotificationDao.sendInadmissibilityEmailForRejectedApplication(application,existingEntity,tipoInammissibilita,emailType); emailSendResponse = emailDao.buildEmailSendResponseFromRequest(request); responses = List.of(emailSendResponse); if (!Boolean.TRUE.equals(emailSendResponse.getIsEmailSend())) { @@ -2083,7 +2139,7 @@ public class ApplicationEvaluationDao { return convertToResponse(savedEntity); } - public ApplicationEvaluationFormResponse createApplicationEvaluation(HttpServletRequest request, ApplicationEvaluationFormRequestBean applicationEvaluationFormRequestBean, Long evaluationFormId, Long assignedApplicationId){ + public ApplicationEvaluationFormResponse createApplicationEvaluation(HttpServletRequest request, List files, ApplicationEvaluationFormRequestBean applicationEvaluationFormRequestBean, Long evaluationFormId, Long assignedApplicationId){ log.info("Start createApplicationEvaluation - assignedApplicationId: {}, evaluationFormId: {}", assignedApplicationId, evaluationFormId); UserEntity user = validator.validateUser(request); @@ -2094,7 +2150,7 @@ public class ApplicationEvaluationDao { ApplicationEvaluationRequest req = convertToApplicationEvaluationRequest(applicationEvaluationFormRequestBean); // Call the existing method to create or update evaluation - ApplicationEvaluationResponse evaluationResponse = createOrUpdateApplicationEvaluation(user, req, assignedApplicationId); + ApplicationEvaluationResponse evaluationResponse = createOrUpdateApplicationEvaluation(user, req, assignedApplicationId,files); ApplicationEvaluationEntity entity = applicationEvaluationService.validateApplicationEvaluation(evaluationResponse.getId()); @@ -2415,7 +2471,8 @@ public class ApplicationEvaluationDao { request.setApplicationStatus(formRequestBean.getApplicationStatus()); request.setMotivation(formRequestBean.getMotivation()); request.setAmountAccepted(formRequestBean.getAmountAccepted()); - + request.setRejectedReason(formRequestBean.getRejectedReason()); + request.setRejectedReasonSubject(formRequestBean.getRejectedReasonSubject()); request.setCriteria(null); request.setChecklist(null); @@ -2605,6 +2662,48 @@ public class ApplicationEvaluationDao { return BigDecimal.ZERO; } } + public ApplicationEvaluationResponse updateApplicationToTechnicalEvaluationRejected(ApplicationTechnicalEvaluationRejectedRequest applicationRequest, Long assignedApplicationsId) { + Optional existingEntityOptional = + applicationEvaluationRepository.findByAssignedApplicationsEntity_IdAndIsDeletedFalse(assignedApplicationsId); + Utils.validateEmailJson(applicationRequest.getEmailJson()); + Optional assignedApplications = + assignedApplicationsRepository.findByIdAndIsDeletedFalse(assignedApplicationsId); + ApplicationEntity application = applicationService.validateApplication(assignedApplications.get().getApplication().getId()); + UserEntity user=userService.validateUser(application.getUserId()); + HubEntity hub=user.getHub(); + EmailSendResponse emailSendResponse = new EmailSendResponse(); + if (existingEntityOptional.isPresent()) { + ApplicationEvaluationEntity existingEntity = existingEntityOptional.get(); + ApplicationEntity oldApplicationEntity = Utils.getClonedEntityForData(application); + List responses = new ArrayList<>(); + + application.setStatus(ApplicationStatusForEvaluation.TECHNICAL_EVALUATION_REJECTED.getValue()); + log.info("Application status updated to {} for applicationId: {}", ApplicationStatusForEvaluation.TECHNICAL_EVALUATION_REJECTED, application.getId()); + emailNotificationDao.sendMailForApplicationTechnicalEvaluationRejected(application, hub, existingEntity); + application.setDateRejected(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); + emailSendResponse = emailDao.buildEmailSendResponseFromRequest(request); + responses = List.of(emailSendResponse); + if (!Boolean.TRUE.equals(emailSendResponse.getIsEmailSend())) { + saveEmailSendResponseToEvaluation(emailSendResponse, existingEntity); + } + application = applicationRepository.save(application); + + loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationEntity).newData(application).build()); + + ApplicationEvaluationResponse response = convertToResponse(existingEntity); + if (!Boolean.TRUE.equals(emailSendResponse.getIsEmailSend())) { + response.setEmailSendResponse(responses); + } + return response; + } + return null; + } + public List uploadRejectedDocument(Long userId,List files,ApplicationEntity application){ + if(files!=null) { + return documentDao.uploadFiles(userId, files, application.getId(), DocumentSourceTypeEnum.APPLICATION, DocumentTypeEnum.DOCUMENT); + } + return new ArrayList<>(); + } } diff --git a/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java b/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java index ef5779fa..6dc65a92 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java @@ -1123,7 +1123,7 @@ public class AppointmentDao { richiestaCliente.setImportoBreveTermine(createAppointmentRequest.getImportoBreveTermine()); richiestaClienteList.add(richiestaCliente); } - + input.setDataAppuntamento(createAppointmentRequest.getDataAppuntamento()); input.setRichiestaCliente(richiestaClienteList); appointmentCreationRequest.setInput(input); return appointmentCreationRequest; diff --git a/src/main/java/net/gepafin/tendermanagement/dao/AssignedApplicationsDao.java b/src/main/java/net/gepafin/tendermanagement/dao/AssignedApplicationsDao.java index 0df566f5..1a3c2e05 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/AssignedApplicationsDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/AssignedApplicationsDao.java @@ -116,7 +116,7 @@ public class AssignedApplicationsDao { UserEntity user = userService.validateUser(userId); AssignedApplicationsEntity assignment = createAssignmentEntity(application, user.getId(), assignedByUser, assignedApplicationsRequest); - applicationEvaluationDao.createOrUpdateApplicationEvaluation(user, new ApplicationEvaluationRequest(), assignment.getId()); + applicationEvaluationDao.createOrUpdateApplicationEvaluation(user, new ApplicationEvaluationRequest(), assignment.getId(),null); AssignedApplicationsResponse assignApplicationToInstructorResponse = convertEntityToResponse(assignment); log.info("Application assigned succesfully {}", assignApplicationToInstructorResponse); return assignApplicationToInstructorResponse; diff --git a/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java b/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java index d0bef93e..0f688aaf 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java @@ -155,7 +155,7 @@ public class CallDao { for (DocumentEntity document : documents) { log.info("Adding document to ZIP: documentId={}, fileName={}", document.getId(), document.getFileName()); - String s3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.CALL, callId, 0L,0L); + String s3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.CALL, callId, 0L,0L,0L); try (InputStream fileInputStream = amazonS3Service.getFile(s3Folder, document.getFilePath())) { String fileName = Utils.extractFileName(document.getFilePath()); ZipEntry zipEntry = new ZipEntry(fileName); diff --git a/src/main/java/net/gepafin/tendermanagement/dao/CommunicationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/CommunicationDao.java index c41aee3f..ef7619b2 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/CommunicationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/CommunicationDao.java @@ -5,13 +5,18 @@ import net.gepafin.tendermanagement.config.Translator; import net.gepafin.tendermanagement.constants.GepafinConstant; import net.gepafin.tendermanagement.entities.ApplicationAmendmentRequestEntity; import net.gepafin.tendermanagement.entities.CommunicationEntity; +import net.gepafin.tendermanagement.entities.DocumentEntity; +import net.gepafin.tendermanagement.enums.CommunicationInitiatorTypeEnum; +import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum; +import net.gepafin.tendermanagement.enums.DocumentTypeEnum; import net.gepafin.tendermanagement.enums.VersionActionTypeEnum; import net.gepafin.tendermanagement.model.request.CommunicationRequestBean; import net.gepafin.tendermanagement.model.request.VersionHistoryRequest; -import net.gepafin.tendermanagement.model.response.ApplicationAmendmentResponse; import net.gepafin.tendermanagement.model.response.CommunicationResponseBean; +import net.gepafin.tendermanagement.model.response.DocumentResponseBean; import net.gepafin.tendermanagement.repositories.CommunicationRepository; import net.gepafin.tendermanagement.service.ApplicationAmendmentRequestService; +import net.gepafin.tendermanagement.service.DocumentService; import net.gepafin.tendermanagement.util.LoggingUtil; import net.gepafin.tendermanagement.util.Utils; import net.gepafin.tendermanagement.util.Validator; @@ -22,9 +27,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.springframework.web.multipart.MultipartFile; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; @Component public class CommunicationDao { @@ -45,17 +53,48 @@ public class CommunicationDao { @Autowired private HttpServletRequest request; - public CommunicationResponseBean addCommentToAmendmentRequest(HttpServletRequest request, CommunicationRequestBean communicationReq, Long amendmentId) { + @Autowired + private DocumentDao documentDao; + + @Autowired + private ApplicationAmendmentRequestDao applicationAmendmentRequestDao; + + @Autowired + private DocumentService documentService; + + public CommunicationResponseBean addCommentToAmendmentRequest(HttpServletRequest request, CommunicationRequestBean communicationReq, Long amendmentId, List files) { log.info("Adding communication request..."); - CommunicationEntity communicationEntity = convertToCommunicationCommentEntity(communicationReq, amendmentId); - communicationEntity = communicationRepository.save(communicationEntity); + List communicationDocumentBeans = new ArrayList<>(); + CommunicationEntity communicationEntity = convertToCommunicationCommentEntity(communicationReq, amendmentId,communicationDocumentBeans,files); /** This code is responsible for adding a version history log for the "adding comment to amendment request" operation. **/ loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(null).newData(communicationEntity).build()); log.info("Added comment: {}", communicationEntity); - return convertToCommunicationResponseBean(communicationEntity); + communicationDocumentBeans=getDocumentResponseBean(communicationEntity); + return convertToCommunicationResponseBean(communicationEntity,communicationDocumentBeans); + } + + private List getDocumentResponseBean(CommunicationEntity communicationEntity) { + List documentIds = applicationAmendmentRequestDao.extractIds(communicationEntity.getDocuments()); + List documentResponseBeans = documentIds.stream() + .map(id -> { + DocumentEntity documentEntity = documentService.validateDocument(id); + DocumentResponseBean responseBean = new DocumentResponseBean(); + responseBean.setId(documentEntity.getId()); + responseBean.setName(documentEntity.getFileName()); + responseBean.setType(DocumentTypeEnum.valueOf(documentEntity.getType())); + responseBean.setSource(DocumentSourceTypeEnum.valueOf(documentEntity.getSource())); + responseBean.setSourceId(documentEntity.getSourceId()); + responseBean.setFilePath(documentEntity.getFilePath()); + responseBean.setCreatedDate(documentEntity.getCreatedDate()); + responseBean.setUpdatedDate(documentEntity.getUpdatedDate()); + responseBean.setDocumentAttachmentId(documentEntity.getDocumentAttachmentId()); + return responseBean; + }) + .toList(); + return documentResponseBeans; } public String deleteComment(Long amendmentId, Long commentId) { @@ -77,19 +116,26 @@ public class CommunicationDao { return "Deleted Comment Successfully."; } - public ApplicationAmendmentResponse getAmendmentComments(Long amendmentId) { + public List getAmendmentComments(Long amendmentId) { ApplicationAmendmentRequestEntity amendmentData = applicationAmendmentRequestService.validateApplicationAmendmentRequest(amendmentId); - List commentsList = communicationRepository.findCommentListDetailsByAmendmentId(amendmentId); + List commentsList = communicationRepository.findByApplicationAmendmentRequestIdAndIsDeletedFalse(amendmentId); if (commentsList == null) { throw new CustomValidationException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.COMMENT_NOT_FOUND)); } - return new ApplicationAmendmentResponse(amendmentData, commentsList); + List communicationResponseBeans=new ArrayList<>(); + for(CommunicationEntity communicationEntity:commentsList){ + List communicationDocumentBeans=getDocumentResponseBean(communicationEntity); + CommunicationResponseBean communicationResponseBean=convertToCommunicationResponseBean(communicationEntity,communicationDocumentBeans); + communicationResponseBeans.add(communicationResponseBean); + } + return communicationResponseBeans; } public CommunicationResponseBean updateAmendmentComment(CommunicationRequestBean communicationRequestBean, Long amendmentId, Long commentId) { log.info("Updating communication comment..."); + CommunicationEntity existingComment = communicationRepository.findById(commentId) .orElseThrow(() -> new CustomValidationException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.COMMENT_NOT_FOUND))); //cloned for old data for communication @@ -106,11 +152,11 @@ public class CommunicationDao { /** This code is responsible for adding a version history log for the "updating comment to amendment request" operation. **/ loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldCommentData).newData(existingComment).build()); - - return convertToCommunicationResponseBean(existingComment); + List communicationDocumentBeans=getDocumentResponseBean(existingComment); + return convertToCommunicationResponseBean(existingComment,communicationDocumentBeans); } - private CommunicationResponseBean convertToCommunicationResponseBean(CommunicationEntity entity) { + private CommunicationResponseBean convertToCommunicationResponseBean(CommunicationEntity entity,List communicationResponseBean) { CommunicationResponseBean response = new CommunicationResponseBean(); response.setComment(entity.getCommunicationComment()); @@ -122,10 +168,11 @@ public class CommunicationDao { response.setSenderUserId(entity.getSenderUserId()); response.setReceiverUserId(entity.getReceiverUserId()); response.setId(entity.getId()); + response.setDocuments(communicationResponseBean); return response; } - private CommunicationEntity convertToCommunicationCommentEntity(CommunicationRequestBean communicationReq, Long amendmentId) { + private CommunicationEntity convertToCommunicationCommentEntity(CommunicationRequestBean communicationReq, Long amendmentId,List communicationDocumentBean,List files) { ApplicationAmendmentRequestEntity amendmentRequest = applicationAmendmentRequestService.validateApplicationAmendmentRequest(amendmentId); @@ -136,12 +183,24 @@ public class CommunicationDao { communicationEntity.setIsDeleted(false); communicationEntity.setCommentedDate(LocalDateTime.now()); if(validator.checkIsPreInstructor()){ + communicationEntity.setIntiatorType(CommunicationInitiatorTypeEnum.INSTRUCTOR.getValue()); communicationEntity.setSenderUserId(amendmentRequest.getApplicationEvaluationEntity().getUserId()); communicationEntity.setReceiverUserId(amendmentRequest.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication().getUserId()); } else if(Boolean.TRUE.equals(validator.checkIsBeneficiary()) || Boolean.TRUE.equals(validator.checkIsConfidi())) { + communicationEntity.setIntiatorType(CommunicationInitiatorTypeEnum.BENEFICIARY.getValue()); communicationEntity.setSenderUserId(amendmentRequest.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication().getUserId()); communicationEntity.setReceiverUserId(amendmentRequest.getApplicationEvaluationEntity().getUserId()); } + communicationEntity = communicationRepository.save(communicationEntity); + communicationDocumentBean=documentDao.uploadFiles(communicationEntity.getSenderUserId(),files,communicationEntity.getId(), DocumentSourceTypeEnum.COMMUNICATION, DocumentTypeEnum.DOCUMENT); + List communicationDocumentIds = communicationDocumentBean.stream() + .map(DocumentResponseBean::getId) + .collect(Collectors.toList()); + String communicationDocumentId = communicationDocumentIds.stream() + .map(String::valueOf) + .collect(Collectors.joining(",")); + communicationEntity.setDocuments(communicationDocumentId); + communicationEntity = communicationRepository.save(communicationEntity); return communicationEntity; } } diff --git a/src/main/java/net/gepafin/tendermanagement/dao/CompanyDocumentDao.java b/src/main/java/net/gepafin/tendermanagement/dao/CompanyDocumentDao.java index acf12515..5c5fa136 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/CompanyDocumentDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/CompanyDocumentDao.java @@ -282,7 +282,7 @@ public class CompanyDocumentDao { validator.validateUserWithCompany(request,companyDocumentEntity.getCompanyId()); String companyDocumentPath = companyDocumentEntity.getFilePath(); - String documentPath = s3ConfigBean.generateDocumentPath(DocumentSourceTypeEnum.APPLICATION,applicationEntity.getCall().getId(),applicationId,0L); + String documentPath = s3ConfigBean.generateDocumentPath(DocumentSourceTypeEnum.APPLICATION,applicationEntity.getCall().getId(),applicationId,0L,0L); log.info("Original Paths - oldPath: {}, newPath: {}", companyDocumentPath, documentPath); diff --git a/src/main/java/net/gepafin/tendermanagement/dao/DelegationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/DelegationDao.java index b39efce7..6af7e820 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/DelegationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/DelegationDao.java @@ -92,7 +92,7 @@ public class DelegationDao { public ByteArrayOutputStream generateDocument(Map placeholders, String templateName) { try { - String s3Folder = s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.TEMPLATE, 0L, 0L,0L); + String s3Folder = s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.TEMPLATE, 0L, 0L,0L,0L); InputStream templateStream = amazonS3Service.getFile(s3Folder ,templateName); XWPFDocument doc = loadTemplate(templateStream); replacePlaceholders(doc, placeholders); diff --git a/src/main/java/net/gepafin/tendermanagement/dao/DocumentDao.java b/src/main/java/net/gepafin/tendermanagement/dao/DocumentDao.java index 013bf9e5..597e3c4f 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/DocumentDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/DocumentDao.java @@ -89,6 +89,9 @@ public class DocumentDao { @Autowired private ApplicationEvaluationDao applicationEvaluationDao; + @Autowired + private CommunicationRepository communicationRepository; + // @Value("${aws.s3.url.folder}") // private String s3Folder; @@ -96,19 +99,22 @@ public class DocumentDao { log.info("Uploading files userId={}, sourceType={}, fileType={}", userId,sourceType,fileType); List documentEntities = new ArrayList<>(); Long source = resolveSourceId(sourceId, sourceType); - for (MultipartFile file : files) { - log.info("Uploading file '{}'", file.getOriginalFilename()); - UploadFileOnAmazonS3Response uploadFileOnAmazonS3Response = uploadFileOnAmazonS3(file, sourceType, sourceId); - if (uploadFileOnAmazonS3Response != null) { - DocumentEntity documentEntity = new DocumentEntity(); - documentEntity.setFileName(uploadFileOnAmazonS3Response.getFileName()); - documentEntity.setSource(sourceType.getValue()); - documentEntity.setSourceId(source); - documentEntity.setType(fileType.getValue()); - documentEntity.setFilePath(uploadFileOnAmazonS3Response.getFilePath()); - documentEntity.setIsDeleted(false); - documentEntity.setUploadedBy(userId); - documentEntities.add(documentEntity); + + if(files!=null) { + for (MultipartFile file : files) { + log.info("Uploading file '{}'", file.getOriginalFilename()); + UploadFileOnAmazonS3Response uploadFileOnAmazonS3Response = uploadFileOnAmazonS3(file, sourceType, sourceId); + if (uploadFileOnAmazonS3Response != null) { + DocumentEntity documentEntity = new DocumentEntity(); + documentEntity.setFileName(uploadFileOnAmazonS3Response.getFileName()); + documentEntity.setSource(sourceType.getValue()); + documentEntity.setSourceId(source); + documentEntity.setType(fileType.getValue()); + documentEntity.setFilePath(uploadFileOnAmazonS3Response.getFilePath()); + documentEntity.setIsDeleted(false); + documentEntity.setUploadedBy(userId); + documentEntities.add(documentEntity); + } } } documentRepository.saveAll(documentEntities); @@ -164,6 +170,7 @@ public class DocumentDao { Long applicationId = 0L; Long amendmentId = 0L; Long evaluationId = 0L; + Long communicationId = 0L; Long callId = sourceId; if (type == DocumentSourceTypeEnum.APPLICATION) { applicationId = sourceId; @@ -181,9 +188,17 @@ public class DocumentDao { applicationId = applicationEntity.getId(); callId = applicationEntity.getCall().getId(); log.info("Processing document of type EVALUATION .Resolved evaluationId={}, applicationId={}, callId={}", evaluationId, applicationId, callId); + }else if (type == DocumentSourceTypeEnum.COMMUNICATION) { + communicationId = sourceId; + Optional communicationEntity=communicationRepository.findByIdAndIsDeletedFalse(communicationId); + Optional applicationAmendmentRequestEntity=applicationAmendmentRequestRepository.findByIdAndIsDeletedFalse(communicationEntity.get().getApplicationAmendmentRequest().getId()); + amendmentId=applicationAmendmentRequestEntity.get().getId(); + applicationId=applicationAmendmentRequestEntity.get().getApplicationId(); + callId = applicationAmendmentRequestEntity.get().getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication().getCall().getId(); + log.info("Processing document of type COMMUNICATION .Resolved evaluationId={}, applicationId={}, callId={}", evaluationId, applicationId, callId); } try { - String s3Path = generateS3Path(type, callId, applicationId, amendmentId); + String s3Path = generateS3Path(type, callId, applicationId, amendmentId,communicationId); log.info("Generated S3 path {}", s3Path); return amazonS3Service.uploadFileOnAmazonS3(s3Path, file); } catch (Exception e) { @@ -194,9 +209,9 @@ public class DocumentDao { } - public String generateS3Path(DocumentSourceTypeEnum typeOfDocument, Long callId, Long applicationId, Long amendmentId) { + public String generateS3Path(DocumentSourceTypeEnum typeOfDocument, Long callId, Long applicationId, Long amendmentId,Long communicationId) { try { - return s3ConfigBean.generateDocumentPath(typeOfDocument, callId, applicationId, amendmentId); + return s3ConfigBean.generateDocumentPath(typeOfDocument, callId, applicationId, amendmentId,communicationId); } catch (IllegalArgumentException e) { throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.S3_PATH_GENERATION_ERROR_MSG)); } @@ -228,6 +243,7 @@ public class DocumentDao { Long applicationId = null; Long amendmentId = null; Long evaluationId = null; + Long communicationId=null; if (DocumentSourceTypeEnum.CALL.getValue().equalsIgnoreCase(documentEntity.getSource())) { callId = documentEntity.getSourceId(); @@ -305,7 +321,7 @@ public class DocumentDao { callId = applicationEntity.getCall().getId(); log.info("Processing document of type EVALUATION. Resolved evaluationId={}, applicationId={}, callId={}", evaluationId, applicationId, callId); } - deleteFileFromS3(documentEntity, callId, applicationId,amendmentId); + deleteFileFromS3(documentEntity, callId, applicationId,amendmentId,communicationId); log.info("Successfully deleted file from S3 for documentId={}", documentId); } @@ -349,6 +365,7 @@ public class DocumentDao { Long applicationId=null; Long amendmentId=null; Long evaluationId=null; + Long communicationId=null; if (type.equals(DocumentSourceTypeEnum.APPLICATION)) { callId = applicationRepository.findCallIdById(id); applicationId = id; @@ -366,6 +383,14 @@ public class DocumentDao { applicationId = applicationEntity.getId(); callId = applicationEntity.getCall().getId(); log.info("Processing document of type EVALUATION . Resolved evaluationId={}, applicationId={}, callId={}", evaluationId, applicationId, callId); + }else if (type == DocumentSourceTypeEnum.COMMUNICATION) { + communicationId = id; + Optional communicationEntity=communicationRepository.findByIdAndIsDeletedFalse(communicationId); + Optional applicationAmendmentRequestEntity=applicationAmendmentRequestRepository.findByIdAndIsDeletedFalse(communicationEntity.get().getApplicationAmendmentRequest().getId()); + amendmentId=applicationAmendmentRequestEntity.get().getId(); + applicationId=applicationAmendmentRequestEntity.get().getApplicationId(); + callId = applicationAmendmentRequestEntity.get().getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication().getCall().getId(); + log.info("Processing document of type EVALUATION .Resolved evaluationId={}, applicationId={}, callId={}", evaluationId, applicationId, callId); } else { @@ -373,7 +398,7 @@ public class DocumentDao { applicationId = 0L; log.info("Processing document of type CALL . Resolved callId={}", callId); } - String s3Path = generateS3Path(type, callId, applicationId,amendmentId); + String s3Path = generateS3Path(type, callId, applicationId,amendmentId,communicationId); log.info("Generated S3 path {}", s3Path); return amazonS3Service.uploadFileOnAmazonS3(s3Path, file); } catch (Exception e) { @@ -386,12 +411,12 @@ public class DocumentDao { return callDao.convertToDocumentResponseBean(documentEntity); } - public void deleteFileFromS3(DocumentEntity documentEntity, Long callId, Long applicationId,Long amendmentId) { + public void deleteFileFromS3(DocumentEntity documentEntity, Long callId, Long applicationId,Long amendmentId,Long communicationId) { try { DocumentEntity oldDocumentEntity = Utils.getClonedEntityForData(documentEntity); String oldS3Path = documentEntity.getFilePath(); - String newS3Path = s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.valueOf("DELETED_" + documentEntity.getSource().toUpperCase()), callId, applicationId,amendmentId); + String newS3Path = s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.valueOf("DELETED_" + documentEntity.getSource().toUpperCase()), callId, applicationId,amendmentId,communicationId); log.info("Moving file to deleted path: oldS3Path={}, newS3Path={}", oldS3Path, newS3Path); UploadFileOnAmazonS3Response response = amazonS3Service.moveFile(documentEntity.getFileName(), oldS3Path, newS3Path); documentEntity.setFileName(response.getFileName()); diff --git a/src/main/java/net/gepafin/tendermanagement/dao/EmailNotificationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/EmailNotificationDao.java index b22ece00..87b23c05 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/EmailNotificationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/EmailNotificationDao.java @@ -94,14 +94,17 @@ public class EmailNotificationDao { @Autowired private ApplicationAmendmentRequestDao applicationAmendmentRequestDao; + @Autowired + private ApplicationDao applicationDao; + public void sendEmail(ApplicationEntity applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum templateType, Map bodyPlaceholders, - List additionalRecipients, Long amendmentId) { + List additionalRecipients, Long amendmentId,String emailType) { HubEntity hubEntity = hubService.valdateHub(applicationEntity.getHubId()); // String service = determineService(applicationEntity.getHubId()); // String legalMail = service.equals("Gepafin S.p.a.") ? "bandi.gepafin@legalmail.it" : "bandi.sviluppumbria@legalmail.it"; - EmailContentResponse emailContent = prepareEmailContent(applicationEntity, templateType, hubEntity, bodyPlaceholders); + EmailContentResponse emailContent = prepareEmailContent(applicationEntity, templateType, hubEntity, bodyPlaceholders,emailType); UserEntity userEntity = userService.validateUser(applicationEntity.getUserId()); sendEmails(applicationEntity, userEntity, additionalRecipients,amendmentId,emailContent.getSystemEmailTemplateResponse(),emailContent.getSubject(),emailContent.getBody()); } @@ -110,7 +113,7 @@ public class EmailNotificationDao { ApplicationEntity applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum templateType, HubEntity hubEntity, - Map bodyPlaceholders + Map bodyPlaceholders,String emailType ) { SystemEmailTemplateResponse systemEmailTemplateResponse = systemEmailTemplatesService.retrieveTemplateByTypeAndCall(templateType, hubEntity, null); if(Boolean.TRUE.equals(templateType.equals(SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.DOCUMENTATION_INTEGRATION_REQUEST)) && Boolean.TRUE.equals(validator.isProductionProfileActivated()) && applicationEntity.getCall().getId().equals(23l)) { @@ -121,6 +124,7 @@ public class EmailNotificationDao { subjectPlaceholders.put("{{call_name}}", applicationEntity.getCall().getName()); subjectPlaceholders.put("{{company_name}}", company.getCompanyName()); // bodyPlaceholders.put("{{legal_mail}}", legalMail); + subjectPlaceholders.put("{{email_type}}",emailType); String subject = Utils.replacePlaceholders(systemEmailTemplateResponse.getSubject(), subjectPlaceholders); String body = Utils.replacePlaceholders(systemEmailTemplateResponse.getHtmlContent(), bodyPlaceholders); @@ -131,21 +135,42 @@ public class EmailNotificationDao { Optional applicationEvaluationEntity = applicationEvaluationRepository.findByApplicationIdAndIsDeletedFalse(applicationEntity.getId()); CompanyEntity company = companyService.validateCompany(applicationEntity.getCompanyId()); - ApplicationAmendmentRequestEntity applicationAmendmentRequest=applicationAmendmentRequestDao.validateApplicationAmendmentRequest(amendmentId); + ApplicationAmendmentRequestEntity applicationAmendmentRequest =null; + if(amendmentId!=null) { + applicationAmendmentRequest = applicationAmendmentRequestDao.validateApplicationAmendmentRequest(amendmentId); + } List attachmentRequests =new ArrayList<>(); + S3DocxProcessor processor = new S3DocxProcessor(s3Client); + List urls=new ArrayList<>(); + Map replacements=new HashMap<>(); + List documentEntities=new ArrayList<>(); if(systemEmailTemplateResponse.getEmailScenario().equals(EmailScenarioTypeEnum.SPECIAL_APPLICATION_AMENDMENT_REQUESTED)) { - S3DocxProcessor processor = new S3DocxProcessor(s3Client); - List urls=new ArrayList<>(); - Map replacements = Map.of( + replacements = Map.of( "{call_name}", applicationEntity.getCall().getName(), "{amount_accepted}", String.valueOf(applicationEntity.getAmountAccepted()), "{pec}", "bandi.gepafin@legalmail.it" ); - List documentEntities=documentRepository.findBySourceInAndIsDeletedFalse(List.of(applicationAmendmentRequest.getAmendmentDocumentType(),"MODELLO_AUTOCERTIFICAZIONE","MODELLO_PRIVACY")); - urls = documentEntities.stream() - .map(DocumentEntity::getFilePath) // or getUrl() - .collect(Collectors.toList()); + documentEntities=documentRepository.findBySourceInAndIsDeletedFalse(List.of(applicationAmendmentRequest.getAmendmentDocumentType(),"MODELLO_AUTOCERTIFICAZIONE","MODELLO_PRIVACY")); + } + if(Boolean.TRUE.equals(userEntity.getHub().getUniqueUuid().equals(defaultHubUuid)) && Boolean.TRUE.equals(systemEmailTemplateResponse.getEmailScenario().equals(EmailScenarioTypeEnum.APPLICATION_AMENDMENT_REQUESTED))) { + List documentIds=applicationDao.validateDocumentIds(applicationAmendmentRequest.getAmendmentInitialDocument()); + Set setOfDocumentIds = (documentIds == null) + ? Collections.emptySet() + : new HashSet<>(documentIds); + documentEntities=documentRepository.findAllByIdInAndIsDeletedFalse(setOfDocumentIds); + } + if(Boolean.TRUE.equals(userEntity.getHub().getUniqueUuid().equals(defaultHubUuid)) && Boolean.TRUE.equals(systemEmailTemplateResponse.getEmailScenario().equals(EmailScenarioTypeEnum.APPLICATION_REJECTED))) { + List documentIds=applicationDao.validateDocumentIds(applicationEntity.getRejectedDocument()); + Set setOfDocumentIds = (documentIds == null) + ? Collections.emptySet() + : new HashSet<>(documentIds); + documentEntities=documentRepository.findAllByIdInAndIsDeletedFalse(setOfDocumentIds); + } + urls = documentEntities.stream() + .map(DocumentEntity::getFilePath) // or getUrl() + .collect(Collectors.toList()); + if(Boolean.FALSE.equals(urls.isEmpty())) { Map processedFiles = null; try { processedFiles = processor.processFiles(urls, replacements); @@ -159,7 +184,6 @@ public class EmailNotificationDao { attachmentRequests.add(attachmentRequest); } } - UserWithCompanyEntity userWithCompany=companyService.getUserWithCompany(userEntity.getId(),company.getId()); String companyEmail = userWithCompany.getEmail(); String contactEmail = userWithCompany.getContactEmail(); @@ -247,7 +271,7 @@ public class EmailNotificationDao { ApplicationEntity applicationEntity = applicationService.validateApplication(applicationAmendmentRequestEntity.getApplicationId()); Map bodyPlaceholders = prepareEmailPlaceholders(applicationEntity, applicationAmendmentRequestEntity); sendEmail(applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.DOCUMENTATION_INTEGRATION_REQUEST, bodyPlaceholders, null, - applicationAmendmentRequestEntity.getId()); + applicationAmendmentRequestEntity.getId(),null); } public Map prepareEmailPlaceholders(ApplicationEntity applicationEntity, ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity){ Map bodyPlaceholders = new HashMap<>(); @@ -339,7 +363,7 @@ public class EmailNotificationDao { } bodyPlaceholders.put("{{date_time_emailSend}}", DateTimeUtil.formatLocalDateTime(lastReminderDateTime, GepafinConstant.DD_MM_YYYY)); - sendEmail(applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.INADMISSIBILITY_NOTIFICATION_DUE_TO_FAILURE, bodyPlaceholders, null,amendmentRequest.getId()); + sendEmail(applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.INADMISSIBILITY_NOTIFICATION_DUE_TO_FAILURE, bodyPlaceholders, null,amendmentRequest.getId(),null); } public void sendAdmissibilityNotificationEmailForAdmissibleApplication(ApplicationEntity applicationEntity) { @@ -357,10 +381,10 @@ public class EmailNotificationDao { bodyPlaceholders.put("{{protocol_date}}", protocolDate); bodyPlaceholders.put("{{protocol_time}}", DateTimeUtil.parseLocalTimeToString(applicationEntity.getProtocol().getTime(), GepafinConstant.HH_MM_SS)); - sendEmail(applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.ADMISSIBILITY_NOTIFICATION, bodyPlaceholders, null,null); + sendEmail(applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.ADMISSIBILITY_NOTIFICATION, bodyPlaceholders, null,null,null); } - public void sendInadmissibilityEmailForRejectedApplication(ApplicationEntity applicationEntity,ApplicationEvaluationEntity applicationEvaluationEntity) { + public void sendInadmissibilityEmailForRejectedApplication(ApplicationEntity applicationEntity,ApplicationEvaluationEntity applicationEvaluationEntity,String tipoInammissibilita,String emailType) { Map bodyPlaceholders = new HashMap<>(); bodyPlaceholders.put("{{call_name}}", applicationEntity.getCall().getName()); String protocolNumber=applicationEntity.getProtocol().getExternalProtocolNumber(); @@ -374,9 +398,10 @@ public class EmailNotificationDao { } bodyPlaceholders.put("{{protocol_date}}", protocolDate); bodyPlaceholders.put("{{protocol_time}}", DateTimeUtil.parseLocalTimeToString(applicationEntity.getProtocol().getTime(), GepafinConstant.HH_MM_SS)); + HubEntity hubEntity = hubService.valdateHub(applicationEntity.getHubId()); + bodyPlaceholders.put("{{tipo_inammissibilita}}", tipoInammissibilita); bodyPlaceholders.put("{{form_text}}", applicationEvaluationEntity.getMotivation()); - - sendEmail(applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.INADMISSIBILITY_TEMPLATE, bodyPlaceholders, null,null); + sendEmail(applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.INADMISSIBILITY_TEMPLATE, bodyPlaceholders, null,null,emailType); } public void sendMail(Long hubId, String subject, String body, List recipientEmails, EmailLogRequest emailLogRequest) { @@ -404,7 +429,7 @@ public class EmailNotificationDao { return emailConfig; } - private EmailConfig parseEmailConfig(String configJson) { + private static EmailConfig parseEmailConfig(String configJson) { ObjectMapper objectMapper = new ObjectMapper(); try { @@ -413,12 +438,36 @@ public class EmailNotificationDao { throw new IllegalArgumentException("Failed to parse email configuration JSON", e); } } + public void sendMailForApplicationTechnicalEvaluationRejected(ApplicationEntity applicationEntity,HubEntity hub,ApplicationEvaluationEntity applicationEvaluationEntity) { Map bodyPlaceholders = prepareEmailPlaceholdersForTechnicalEvaluationRejected(applicationEntity,hub,applicationEvaluationEntity); sendEmail(applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.INADMISSIBILITY_NOTIFICATION_DUE_TO_TECHNICAL_EVALUATION_FAILURE, bodyPlaceholders, null, - null); + null,null); } + +// public void sendMailForApplicationTechnicalEvaluationRejected(ApplicationEntity applicationEntity,HubEntity hub,ApplicationEvaluationEntity applicationEvaluationEntity,Map emailJson) { +// +// HubEntity hubEntity = hubService.valdateHub(applicationEntity.getHubId()); +// SystemEmailTemplateResponse systemEmailTemplateResponse=new SystemEmailTemplateResponse(); +// systemEmailTemplateResponse.setSubject((String) emailJson.get("subject")); +// systemEmailTemplateResponse.setHtmlContent((String) emailJson.get("message")); +// Map subjectPlaceholders = new HashMap<>(); +// CompanyEntity company = companyService.validateCompany(applicationEntity.getCompanyId()); +// subjectPlaceholders.put("{{call_name}}", applicationEntity.getCall().getName()); +// subjectPlaceholders.put("{{company_name}}", company.getCompanyName()); +// Map bodyPlaceholders = prepareEmailPlaceholdersForTechnicalEvaluationRejected(applicationEntity,hub,applicationEvaluationEntity); +// String subject = Utils.replacePlaceholders(systemEmailTemplateResponse.getSubject(), subjectPlaceholders); +// String body = Utils.replacePlaceholders(systemEmailTemplateResponse.getHtmlContent(), bodyPlaceholders); +// SystemEmailTemplateResponse systemEmailTemplateResponse1=new SystemEmailTemplateResponse(); +// systemEmailTemplateResponse1.setSubject(subject); +// systemEmailTemplateResponse1.setHtmlContent(body); +// systemEmailTemplateResponse1.setEmailScenario(EmailScenarioTypeEnum.APPLICATION_TECHNICAL_EVALUATION_REJECTED); +// EmailContentResponse emailContentResponse=new EmailContentResponse(subject,body,systemEmailTemplateResponse1); +// UserEntity userEntity = userService.validateUser(applicationEntity.getUserId()); +// sendEmails(applicationEntity, userEntity, null,null,emailContentResponse.getSystemEmailTemplateResponse(),emailContentResponse.getSubject(),emailContentResponse.getBody()); +// +// } public Map prepareEmailPlaceholdersForTechnicalEvaluationRejected(ApplicationEntity applicationEntity,HubEntity hub,ApplicationEvaluationEntity applicationEvaluationEntity) { Map bodyPlaceholders = new HashMap<>(); bodyPlaceholders.put("{{call_name}}", applicationEntity.getCall().getName()); @@ -443,6 +492,6 @@ public class EmailNotificationDao { Map bodyPlaceholders = prepareEmailPlaceholders(applicationEntity, applicationAmendmentRequestEntity); sendEmail(applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.SPECIAL_APPLICATION_AMENDMENT_REQUESTED, bodyPlaceholders, null, - applicationAmendmentRequestEntity.getId()); + applicationAmendmentRequestEntity.getId(),null); } } \ No newline at end of file diff --git a/src/main/java/net/gepafin/tendermanagement/dao/S3PathConfig.java b/src/main/java/net/gepafin/tendermanagement/dao/S3PathConfig.java index 9b55eda1..9cbc1b26 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/S3PathConfig.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/S3PathConfig.java @@ -15,26 +15,27 @@ public class S3PathConfig { @Autowired S3ConfigRepository s3ConfigRepository; - public String generateDocumentPath(DocumentSourceTypeEnum type, Long callId, Long applicationId,Long amendmentId) { + public String generateDocumentPath(DocumentSourceTypeEnum type, Long callId, Long applicationId,Long amendmentId,Long communicationId) { S3ConfigEntity config = getDocumentPath(type); - return config.getParentFolder() + "/" + buildS3Path(config.getPath(), callId, applicationId,amendmentId); + return config.getParentFolder() + "/" + buildS3Path(config.getPath(), callId, applicationId,amendmentId,communicationId); } - public String generateDocumentPathForOther(DocOtherSourceTypeEnum type, Long callId, Long applicationId,Long amendmentId) { + public String generateDocumentPathForOther(DocOtherSourceTypeEnum type, Long callId, Long applicationId,Long amendmentId,Long communicationId) { S3ConfigEntity config = getDocumentPathForOther(type); - return config.getParentFolder() + "/" + buildS3Path(config.getPath(), callId, applicationId,amendmentId); + return config.getParentFolder() + "/" + buildS3Path(config.getPath(), callId, applicationId,amendmentId,communicationId); } public String generateDocumentPathForDelegationAndSignedDocument(DocOtherSourceTypeEnum type) { S3ConfigEntity config = getDocumentPathForOther(type); return config.getParentFolder() + "/" + config.getPath(); } - private String buildS3Path(String pathTemplate, Long callId, Long applicationId, Long amendmentId) { + private String buildS3Path(String pathTemplate, Long callId, Long applicationId, Long amendmentId,Long communicationId) { return pathTemplate .replace("{call_id}", callId != null && callId != 0L ? "call_" + callId : "") .replace("{application_id}", applicationId != null && applicationId != 0L ? "application_" + applicationId : "") - .replace("{amendment_id}", amendmentId != null && amendmentId != 0L ? "amendment_" + amendmentId : ""); + .replace("{amendment_id}", amendmentId != null && amendmentId != 0L ? "amendment_" + amendmentId : "") + .replace("{communication_id}", communicationId != null && communicationId != 0L ? "communication_" + communicationId : ""); } private S3ConfigEntity getDocumentPath(DocumentSourceTypeEnum type) { diff --git a/src/main/java/net/gepafin/tendermanagement/entities/ApplicationAmendmentRequestEntity.java b/src/main/java/net/gepafin/tendermanagement/entities/ApplicationAmendmentRequestEntity.java index 7195e1cf..1ccd4eed 100644 --- a/src/main/java/net/gepafin/tendermanagement/entities/ApplicationAmendmentRequestEntity.java +++ b/src/main/java/net/gepafin/tendermanagement/entities/ApplicationAmendmentRequestEntity.java @@ -74,4 +74,7 @@ public class ApplicationAmendmentRequestEntity extends BaseEntity { @Column(name = "AMENDMENT_DOCUMENT_TYPE") private String amendmentDocumentType; + @Column(name = "AMENDMENT_INITIAL_DOCUMENT") + private String amendmentInitialDocument; + } diff --git a/src/main/java/net/gepafin/tendermanagement/entities/ApplicationEntity.java b/src/main/java/net/gepafin/tendermanagement/entities/ApplicationEntity.java index dacc3541..8b8c64d7 100644 --- a/src/main/java/net/gepafin/tendermanagement/entities/ApplicationEntity.java +++ b/src/main/java/net/gepafin/tendermanagement/entities/ApplicationEntity.java @@ -79,4 +79,12 @@ public class ApplicationEntity extends BaseEntity { @Column(name="VAT_NUMBER") private String vatNumber; + @Column(name = "PREVIOUS_STATUS") + private String previousStatus; + + @Column(name = "REJECTED_REASON") + private String rejectedReason; + + @Column(name = "REJECTED_DOCUMENT") + private String rejectedDocument; } \ No newline at end of file diff --git a/src/main/java/net/gepafin/tendermanagement/entities/CommunicationEntity.java b/src/main/java/net/gepafin/tendermanagement/entities/CommunicationEntity.java index a1c3ff45..c3d7d61f 100644 --- a/src/main/java/net/gepafin/tendermanagement/entities/CommunicationEntity.java +++ b/src/main/java/net/gepafin/tendermanagement/entities/CommunicationEntity.java @@ -35,4 +35,9 @@ public class CommunicationEntity extends BaseEntity { @JoinColumn(name = "AMENDMENT_ID", referencedColumnName = "id", nullable = false) private ApplicationAmendmentRequestEntity applicationAmendmentRequest; + @Column(name = "INITIATOR_TYPE") + private String intiatorType; + + @Column(name = "DOCUMENTS") + private String documents; } \ No newline at end of file diff --git a/src/main/java/net/gepafin/tendermanagement/enums/CommunicationInitiatorTypeEnum.java b/src/main/java/net/gepafin/tendermanagement/enums/CommunicationInitiatorTypeEnum.java new file mode 100644 index 00000000..8c3e8e9a --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/enums/CommunicationInitiatorTypeEnum.java @@ -0,0 +1,18 @@ +package net.gepafin.tendermanagement.enums; + +public enum CommunicationInitiatorTypeEnum { + + + INSTRUCTOR("INSTRUCTOR"), + BENEFICIARY("BENEFICIARY"); + + private String value; + + CommunicationInitiatorTypeEnum(String value) { + this.value = value; + } + + public String getValue() { + return value; + } +} diff --git a/src/main/java/net/gepafin/tendermanagement/enums/DocumentSourceTypeEnum.java b/src/main/java/net/gepafin/tendermanagement/enums/DocumentSourceTypeEnum.java index e2b121e7..2e10a873 100644 --- a/src/main/java/net/gepafin/tendermanagement/enums/DocumentSourceTypeEnum.java +++ b/src/main/java/net/gepafin/tendermanagement/enums/DocumentSourceTypeEnum.java @@ -5,7 +5,8 @@ public enum DocumentSourceTypeEnum { APPLICATION("APPLICATION"), EVALUATION("EVALUATION"), - AMENDMENT("AMENDMENT"); + AMENDMENT("AMENDMENT"), + COMMUNICATION("COMMUNICATION"); private String value; diff --git a/src/main/java/net/gepafin/tendermanagement/enums/UserActionContextEnum.java b/src/main/java/net/gepafin/tendermanagement/enums/UserActionContextEnum.java index 8d512478..32847535 100644 --- a/src/main/java/net/gepafin/tendermanagement/enums/UserActionContextEnum.java +++ b/src/main/java/net/gepafin/tendermanagement/enums/UserActionContextEnum.java @@ -223,7 +223,8 @@ public enum UserActionContextEnum { UPDATE_EXPIRED_CALL("UPDATE_EXPIRED_CALL"), RESEND_EMAIL("RESEND_EMAIL"), SEND_REMINDER_EMAIL("SEND_REMINDER_EMAIL"), - CREATE_SPECIAL_AMENDMENT("CREATE_SPECIAL_AMENDMENT"); + CREATE_SPECIAL_AMENDMENT("CREATE_SPECIAL_AMENDMENT"), + UPDATE_APPLICATION_TO_TECHNICAL_EVALUATION_REJECTED("UPDATE_APPLICATION_TO_TECHNICAL_EVALUATION_REJECTED"); private final String value; diff --git a/src/main/java/net/gepafin/tendermanagement/model/request/ApplicationEvaluationFormRequestBean.java b/src/main/java/net/gepafin/tendermanagement/model/request/ApplicationEvaluationFormRequestBean.java index d2c0e2dc..6d526122 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/request/ApplicationEvaluationFormRequestBean.java +++ b/src/main/java/net/gepafin/tendermanagement/model/request/ApplicationEvaluationFormRequestBean.java @@ -16,4 +16,7 @@ public class ApplicationEvaluationFormRequestBean { private List formFields; private String motivation; private BigDecimal amountAccepted; + private String rejectedReason; + private String rejectedReasonSubject; + } diff --git a/src/main/java/net/gepafin/tendermanagement/model/request/ApplicationEvaluationRequest.java b/src/main/java/net/gepafin/tendermanagement/model/request/ApplicationEvaluationRequest.java index bd63054c..71405f74 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/request/ApplicationEvaluationRequest.java +++ b/src/main/java/net/gepafin/tendermanagement/model/request/ApplicationEvaluationRequest.java @@ -17,4 +17,6 @@ public class ApplicationEvaluationRequest { private ApplicationStatusForEvaluation applicationStatus; private String motivation; private BigDecimal amountAccepted; + private String rejectedReason; + private String rejectedReasonSubject; } diff --git a/src/main/java/net/gepafin/tendermanagement/model/request/ApplicationTechnicalEvaluationRejectedRequest.java b/src/main/java/net/gepafin/tendermanagement/model/request/ApplicationTechnicalEvaluationRejectedRequest.java new file mode 100644 index 00000000..b4a5d93e --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/model/request/ApplicationTechnicalEvaluationRejectedRequest.java @@ -0,0 +1,13 @@ +package net.gepafin.tendermanagement.model.request; + +import lombok.Data; + +import java.util.Map; + +@Data +public class ApplicationTechnicalEvaluationRejectedRequest { + + private Map emailJson; + + +} diff --git a/src/main/java/net/gepafin/tendermanagement/model/request/AppointmentCreationRequest.java b/src/main/java/net/gepafin/tendermanagement/model/request/AppointmentCreationRequest.java index a1c0bb12..8a16a021 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/request/AppointmentCreationRequest.java +++ b/src/main/java/net/gepafin/tendermanagement/model/request/AppointmentCreationRequest.java @@ -2,6 +2,7 @@ package net.gepafin.tendermanagement.model.request; import lombok.Data; +import java.time.LocalDateTime; import java.util.List; @Data @@ -14,6 +15,7 @@ public class AppointmentCreationRequest { private Long id; private String ndg; private List richiestaCliente; + private LocalDateTime dataAppuntamento; } @Data @@ -32,6 +34,7 @@ public class AppointmentCreationRequest { private String codProdotto; private String codOperazione; private Nota nota; + private LocalDateTime dataAppuntamento; } @Data diff --git a/src/main/java/net/gepafin/tendermanagement/model/request/CreateAppointmentRequest.java b/src/main/java/net/gepafin/tendermanagement/model/request/CreateAppointmentRequest.java index 667ba581..870be4a3 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/request/CreateAppointmentRequest.java +++ b/src/main/java/net/gepafin/tendermanagement/model/request/CreateAppointmentRequest.java @@ -2,11 +2,14 @@ package net.gepafin.tendermanagement.model.request; import lombok.Data; +import java.time.LocalDateTime; + @Data public class CreateAppointmentRequest { private Double importoBreveTermine; private Integer durataMesiFinanziamento; private Nota nota; + private LocalDateTime dataAppuntamento; @Data public static class Nota { 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 c7f1a2eb..b0df6e1c 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationAmendmentRequestResponse.java +++ b/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationAmendmentRequestResponse.java @@ -33,4 +33,7 @@ public class ApplicationAmendmentRequestResponse { private ApplicationAmendmentRequestEnum status; private String emailTemplate; private List emailSendResponse; + private List amendmentInitialDocuments; + private String amendmentType; + private String amendmentDocumentType; } 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 49f07c6f..296d7f6b 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationEvaluationResponse.java +++ b/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationEvaluationResponse.java @@ -50,5 +50,6 @@ public class ApplicationEvaluationResponse { private String companyVatNumber; private String companyCodiceAteco; private List emailSendResponse; + private List rejectedDocument; } diff --git a/src/main/java/net/gepafin/tendermanagement/model/response/CommunicationResponseBean.java b/src/main/java/net/gepafin/tendermanagement/model/response/CommunicationResponseBean.java index 170e1318..49e0c5f8 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/response/CommunicationResponseBean.java +++ b/src/main/java/net/gepafin/tendermanagement/model/response/CommunicationResponseBean.java @@ -3,6 +3,7 @@ package net.gepafin.tendermanagement.model.response; import lombok.Data; import java.time.LocalDateTime; +import java.util.List; @Data public class CommunicationResponseBean { @@ -23,6 +24,8 @@ public class CommunicationResponseBean { private Long receiverUserId; private Long amendmentId; + + private List documents; public CommunicationResponseBean(LocalDateTime commentedDate, String comment, String title, LocalDateTime createdDate, LocalDateTime updatedDate, Long amendmentId, Long id) { diff --git a/src/main/java/net/gepafin/tendermanagement/repositories/CommunicationRepository.java b/src/main/java/net/gepafin/tendermanagement/repositories/CommunicationRepository.java index 2894d57b..751493bf 100644 --- a/src/main/java/net/gepafin/tendermanagement/repositories/CommunicationRepository.java +++ b/src/main/java/net/gepafin/tendermanagement/repositories/CommunicationRepository.java @@ -11,10 +11,12 @@ import java.util.Optional; public interface CommunicationRepository extends JpaRepository { - @Query("SELECT new net.gepafin.tendermanagement.model.response.CommunicationResponseBean( " + "c.commentedDate, c.communicationComment, c.communicationTitle, c.createdDate, c" + - ".updatedDate, " + "c.applicationAmendmentRequest.id, c.senderUserId, c.receiverUserId, c.id " + ") " + "FROM CommunicationEntity c " + "WHERE c" + - ".applicationAmendmentRequest.id = :amendmentId AND c.isDeleted = false") - List findCommentListDetailsByAmendmentId(@Param("amendmentId") Long amendmentId); + // @Query("SELECT new net.gepafin.tendermanagement.model.response.CommunicationResponseBean( " + "c.commentedDate, c.communicationComment, c.communicationTitle, c.createdDate, c" + +// ".updatedDate, " + "c.applicationAmendmentRequest.id, c.senderUserId, c.receiverUserId, c.id " + ") " + "FROM CommunicationEntity c " + "WHERE c" + +// ".applicationAmendmentRequest.id = :amendmentId AND c.isDeleted = false") + List findByApplicationAmendmentRequestIdAndIsDeletedFalse(Long amendmentId); Optional findByIdAndIsDeletedFalse(Long commentId); + + List findByApplicationAmendmentRequestIdInAndIsDeletedFalse(List amendmentId); } diff --git a/src/main/java/net/gepafin/tendermanagement/scheduler/ApplicationAmendmentScheduler.java b/src/main/java/net/gepafin/tendermanagement/scheduler/ApplicationAmendmentScheduler.java index 050b4972..b96eb137 100644 --- a/src/main/java/net/gepafin/tendermanagement/scheduler/ApplicationAmendmentScheduler.java +++ b/src/main/java/net/gepafin/tendermanagement/scheduler/ApplicationAmendmentScheduler.java @@ -161,7 +161,7 @@ public class ApplicationAmendmentScheduler { public void updateApplicationStatus(ApplicationEntity applicationEntity){ ApplicationEntity oldApplicationEntity = Utils.getClonedEntityForData(applicationEntity); - applicationEntity.setStatus(ApplicationStatusTypeEnum.EVALUATION.getValue()); + applicationEntity.setStatus(applicationEntity.getPreviousStatus()); applicationRepository.save(applicationEntity); log.info("Updated status to EVALUATION for Application with ID: {}",applicationEntity.getId()); diff --git a/src/main/java/net/gepafin/tendermanagement/service/ApplicationAmendmentRequestService.java b/src/main/java/net/gepafin/tendermanagement/service/ApplicationAmendmentRequestService.java index 5e698107..d8906aa4 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/ApplicationAmendmentRequestService.java +++ b/src/main/java/net/gepafin/tendermanagement/service/ApplicationAmendmentRequestService.java @@ -6,12 +6,13 @@ import net.gepafin.tendermanagement.enums.ApplicationAmendmentRequestEnum; import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum; import net.gepafin.tendermanagement.model.request.*; import net.gepafin.tendermanagement.model.response.*; +import org.springframework.web.multipart.MultipartFile; import java.util.List; public interface ApplicationAmendmentRequestService { public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(HttpServletRequest request,Long applicationEvaluationId); - public ApplicationAmendmentRequestResponse createApplicationAmendmentRequest(HttpServletRequest request, Long applicationEvaluationId , ApplicationAmendmentRequest applicationAmendmentRequest); + public ApplicationAmendmentRequestResponse createApplicationAmendmentRequest(HttpServletRequest request, Long applicationEvaluationId , List files, ApplicationAmendmentRequest applicationAmendmentRequest); void deleteApplicationAmendmentRequest(HttpServletRequest request, Long id); ApplicationAmendmentRequestResponse getApplicationAmendmentRequestById(HttpServletRequest request,Long id); List getAllApplicationAmendmentRequest(HttpServletRequest request, Long userId); diff --git a/src/main/java/net/gepafin/tendermanagement/service/ApplicationEvaluationService.java b/src/main/java/net/gepafin/tendermanagement/service/ApplicationEvaluationService.java index 86140ac6..e8cfd308 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/ApplicationEvaluationService.java +++ b/src/main/java/net/gepafin/tendermanagement/service/ApplicationEvaluationService.java @@ -3,11 +3,9 @@ package net.gepafin.tendermanagement.service; import jakarta.servlet.http.HttpServletRequest; import net.gepafin.tendermanagement.entities.ApplicationEvaluationEntity; import net.gepafin.tendermanagement.enums.FormActionEnum; -import net.gepafin.tendermanagement.model.request.ApplicationEvaluationFormRequestBean; -import net.gepafin.tendermanagement.model.request.ApplicationEvaluationRequest; -import net.gepafin.tendermanagement.model.request.ApplicationRequestBean; -import net.gepafin.tendermanagement.model.request.EvaluationDocumentRequest; +import net.gepafin.tendermanagement.model.request.*; import net.gepafin.tendermanagement.model.response.*; +import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -15,7 +13,7 @@ public interface ApplicationEvaluationService { ApplicationEvaluationResponse createOrUpdateApplicationEvaluation( HttpServletRequest request, ApplicationEvaluationRequest applicationEvaluationRequest, - Long assignedApplicationsId); + Long assignedApplicationsId, List rejectedDocuments); void deleteApplicationEvaluation(HttpServletRequest request,Long id); @@ -24,10 +22,11 @@ public interface ApplicationEvaluationService { ApplicationEvaluationEntity validateApplicationEvaluationByApplicationId(Long applicationId); - ApplicationEvaluationFormResponse createApplicationEvaluation(HttpServletRequest request, ApplicationEvaluationFormRequestBean applicationEvaluationFormRequestBean, Long evaluationId, Long evaluationFormId); + ApplicationEvaluationFormResponse createApplicationEvaluation(HttpServletRequest request, List rejectedDocuments, ApplicationEvaluationFormRequestBean applicationEvaluationFormRequestBean, Long evaluationId, Long evaluationFormId); ApplicationEvaluationFormResponse getApplicationEvaluationForm(HttpServletRequest request, Long applicationId, Long assignedApplicationId); ApplicationEvaluationVersionResponse getApplicationEvaluationVersion(HttpServletRequest request, Long applicationId); + ApplicationEvaluationResponse updateApplicationToTechnicalEvaluationRejected(HttpServletRequest request, ApplicationTechnicalEvaluationRejectedRequest applicationRequest, Long assignedApplicationsId); } diff --git a/src/main/java/net/gepafin/tendermanagement/service/CommunicationService.java b/src/main/java/net/gepafin/tendermanagement/service/CommunicationService.java index 6c99f4a9..ac25493d 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/CommunicationService.java +++ b/src/main/java/net/gepafin/tendermanagement/service/CommunicationService.java @@ -2,15 +2,17 @@ package net.gepafin.tendermanagement.service; import jakarta.servlet.http.HttpServletRequest; import net.gepafin.tendermanagement.model.request.CommunicationRequestBean; -import net.gepafin.tendermanagement.model.response.ApplicationAmendmentResponse; import net.gepafin.tendermanagement.model.response.CommunicationResponseBean; +import org.springframework.web.multipart.MultipartFile; + +import java.util.List; public interface CommunicationService { - CommunicationResponseBean addCommentToAmendmentRequest(HttpServletRequest request ,CommunicationRequestBean communicationRequestBean, Long amendmentId); + CommunicationResponseBean addCommentToAmendmentRequest(HttpServletRequest request , CommunicationRequestBean communicationRequestBean, Long amendmentId, List files); String deleteComment(HttpServletRequest request,Long amendmentId, Long commentId); CommunicationResponseBean updateAmendmentComment(HttpServletRequest request,CommunicationRequestBean communicationRequestBean, Long amendmentId, Long commentId); - ApplicationAmendmentResponse getAmendmentComments(HttpServletRequest request,Long id); + List getAmendmentComments(HttpServletRequest request,Long id); } 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 8926971f..432f4add 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationAmendmentRequestServiceImpl.java +++ b/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationAmendmentRequestServiceImpl.java @@ -14,6 +14,7 @@ import net.gepafin.tendermanagement.repositories.ApplicationAmendmentRequestRepo import net.gepafin.tendermanagement.repositories.ApplicationEvaluationRepository; import net.gepafin.tendermanagement.service.ApplicationAmendmentRequestService; import net.gepafin.tendermanagement.service.UserService; +import net.gepafin.tendermanagement.util.Utils; import net.gepafin.tendermanagement.util.Validator; import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException; import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException; @@ -21,8 +22,10 @@ import net.gepafin.tendermanagement.web.rest.api.errors.Status; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; import java.util.List; +import java.util.Map; import java.util.Optional; @Service @@ -50,10 +53,15 @@ public class ApplicationAmendmentRequestServiceImpl implements ApplicationAmendm @Override @Transactional(rollbackFor = Exception.class) - public ApplicationAmendmentRequestResponse createApplicationAmendmentRequest(HttpServletRequest request, Long applicationEvaluationId , ApplicationAmendmentRequest applicationAmendmentRequest) { + public ApplicationAmendmentRequestResponse createApplicationAmendmentRequest(HttpServletRequest request, Long applicationEvaluationId , List files, ApplicationAmendmentRequest applicationAmendmentRequest) { Optional entityOptional = applicationEvaluationRepository.findByIdAndIsDeletedFalse(applicationEvaluationId); entityOptional.ifPresent(applicationEvaluationEntity -> validator.validatePreInstructor(request, applicationEvaluationEntity.getUserId())); - return applicationAmendmentRequestDao.createApplicationAmendmentRequest(applicationEvaluationId,applicationAmendmentRequest); + Map userInfo = validator.getUserInfoFromToken(request); + Long userId = validator.getUserId(userInfo); + if(files!=null) { + files.forEach(Utils::validateFileType); + } + return applicationAmendmentRequestDao.createApplicationAmendmentRequest(applicationEvaluationId,files,applicationAmendmentRequest,userId); } @Override 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 650acdc1..5d64f783 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationEvaluationServiceImpl.java +++ b/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationEvaluationServiceImpl.java @@ -9,6 +9,7 @@ import net.gepafin.tendermanagement.entities.AssignedApplicationsEntity; import net.gepafin.tendermanagement.entities.UserEntity; import net.gepafin.tendermanagement.model.request.ApplicationEvaluationFormRequestBean; import net.gepafin.tendermanagement.model.request.ApplicationEvaluationRequest; +import net.gepafin.tendermanagement.model.request.ApplicationTechnicalEvaluationRejectedRequest; import net.gepafin.tendermanagement.model.response.ApplicationEvaluationFormResponse; import net.gepafin.tendermanagement.model.response.ApplicationEvaluationResponse; import net.gepafin.tendermanagement.model.response.ApplicationEvaluationResponseBean; @@ -21,6 +22,7 @@ import net.gepafin.tendermanagement.util.Validator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -46,13 +48,13 @@ public class ApplicationEvaluationServiceImpl implements ApplicationEvaluationSe public ApplicationEvaluationResponse createOrUpdateApplicationEvaluation( HttpServletRequest request, ApplicationEvaluationRequest req, - Long assignedApplicationsId) { + Long assignedApplicationsId, List rejectedDocuments) { AssignedApplicationsEntity assignedApplication =assignedApplicationsService.validateAssignedApplication(assignedApplicationsId); UserEntity user = validator.validatePreInstructor(request, assignedApplication.getUserId()); - return applicationEvaluationDao.createOrUpdateApplicationEvaluation(user, req, assignedApplication.getId()); + return applicationEvaluationDao.createOrUpdateApplicationEvaluation(user, req, assignedApplication.getId(),rejectedDocuments); } @Override @@ -87,10 +89,10 @@ public class ApplicationEvaluationServiceImpl implements ApplicationEvaluationSe @Override @Transactional(rollbackFor = Exception.class) - public ApplicationEvaluationFormResponse createApplicationEvaluation(HttpServletRequest request, ApplicationEvaluationFormRequestBean applicationEvaluationFormRequestBean, Long assignedApplicationId, Long evaluationFormId) { + public ApplicationEvaluationFormResponse createApplicationEvaluation(HttpServletRequest request, List rejectedDocuments, ApplicationEvaluationFormRequestBean applicationEvaluationFormRequestBean, Long assignedApplicationId, Long evaluationFormId) { AssignedApplicationsEntity assignedApplicationsEntity = assignedApplicationsService.validateAssignedApplication(assignedApplicationId); validator.validatePreInstructor(request, assignedApplicationsEntity.getUserId()); - return applicationEvaluationDao.createApplicationEvaluation(request,applicationEvaluationFormRequestBean,evaluationFormId,assignedApplicationId); + return applicationEvaluationDao.createApplicationEvaluation(request,rejectedDocuments,applicationEvaluationFormRequestBean,evaluationFormId,assignedApplicationId); } @Override @@ -106,6 +108,10 @@ public class ApplicationEvaluationServiceImpl implements ApplicationEvaluationSe return applicationEvaluationDao.getApplicationEvaluationVersion(request,applicationId); } + @Override + public ApplicationEvaluationResponse updateApplicationToTechnicalEvaluationRejected(HttpServletRequest request, ApplicationTechnicalEvaluationRejectedRequest applicationRequest, Long assignedApplicationsId) { + return applicationEvaluationDao.updateApplicationToTechnicalEvaluationRejected(applicationRequest,assignedApplicationsId); + } } diff --git a/src/main/java/net/gepafin/tendermanagement/service/impl/CommunicationServiceImpl.java b/src/main/java/net/gepafin/tendermanagement/service/impl/CommunicationServiceImpl.java index ed51cc7a..a1096feb 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/impl/CommunicationServiceImpl.java +++ b/src/main/java/net/gepafin/tendermanagement/service/impl/CommunicationServiceImpl.java @@ -5,14 +5,15 @@ import net.gepafin.tendermanagement.dao.ApplicationAmendmentRequestDao; import net.gepafin.tendermanagement.dao.CommunicationDao; import net.gepafin.tendermanagement.entities.ApplicationAmendmentRequestEntity; import net.gepafin.tendermanagement.model.request.CommunicationRequestBean; -import net.gepafin.tendermanagement.model.response.ApplicationAmendmentResponse; import net.gepafin.tendermanagement.model.response.CommunicationResponseBean; import net.gepafin.tendermanagement.service.CommunicationService; import net.gepafin.tendermanagement.util.Validator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; +import java.util.List; @Service @@ -29,14 +30,14 @@ public class CommunicationServiceImpl implements CommunicationService { @Override @Transactional(rollbackFor = Exception.class) - public CommunicationResponseBean addCommentToAmendmentRequest(HttpServletRequest request ,CommunicationRequestBean communicationRequestBean, Long amendmentId) { + public CommunicationResponseBean addCommentToAmendmentRequest(HttpServletRequest request , CommunicationRequestBean communicationRequestBean, Long amendmentId, List files) { ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = applicationAmendmentRequestDao.validateApplicationAmendmentRequest(amendmentId); if (Boolean.FALSE.equals(validator.checkIsBeneficiary()) && Boolean.FALSE.equals(validator.checkIsConfidi())) { validator.validatePreInstructor(request, applicationAmendmentRequestEntity.getApplicationEvaluationEntity().getUserId()); } else { validator.validateUserId(request, applicationAmendmentRequestEntity.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication().getUserId()); } - return communicationDao.addCommentToAmendmentRequest(request,communicationRequestBean, amendmentId); + return communicationDao.addCommentToAmendmentRequest(request,communicationRequestBean, amendmentId,files); } @Override @@ -64,7 +65,7 @@ public class CommunicationServiceImpl implements CommunicationService { @Override @Transactional(rollbackFor = Exception.class) - public ApplicationAmendmentResponse getAmendmentComments(HttpServletRequest request,Long id) { + public List getAmendmentComments(HttpServletRequest request,Long id) { ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = applicationAmendmentRequestDao.validateApplicationAmendmentRequest(id); if (Boolean.FALSE.equals(validator.checkIsBeneficiary())) { validator.validatePreInstructor(request, applicationAmendmentRequestEntity.getApplicationEvaluationEntity().getUserId()); diff --git a/src/main/java/net/gepafin/tendermanagement/service/impl/S3ReUploadMigrationService.java b/src/main/java/net/gepafin/tendermanagement/service/impl/S3ReUploadMigrationService.java index dac565e7..fdb09116 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/impl/S3ReUploadMigrationService.java +++ b/src/main/java/net/gepafin/tendermanagement/service/impl/S3ReUploadMigrationService.java @@ -10,6 +10,7 @@ import lombok.extern.slf4j.Slf4j; import net.gepafin.tendermanagement.dao.DocumentDao; import net.gepafin.tendermanagement.dao.S3PathConfig; import net.gepafin.tendermanagement.entities.ApplicationEntity; +import net.gepafin.tendermanagement.entities.CommunicationEntity; import net.gepafin.tendermanagement.entities.DocumentEntity; import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum; import net.gepafin.tendermanagement.repositories.*; @@ -25,6 +26,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.List; +import java.util.Optional; @Slf4j @Service @@ -73,6 +75,9 @@ public class S3ReUploadMigrationService { @Autowired private ApplicationEvaluationRepository applicationEvaluationRepository; + @Autowired + private CommunicationRepository communicationRepository; + @Autowired private DocumentDao documentDao; @@ -108,6 +113,7 @@ public class S3ReUploadMigrationService { Long applicationId = null; Long amendmentId = null; Long evaluationId = null; + Long communicationId=null; if (DocumentSourceTypeEnum.CALL.getValue().equalsIgnoreCase(document.getSource())) { callId = document.getSourceId(); } else if (DocumentSourceTypeEnum.APPLICATION.getValue().equalsIgnoreCase(document.getSource())) { @@ -125,10 +131,16 @@ public class S3ReUploadMigrationService { ApplicationEntity applicationEntity = applicationEvaluationRepository.findApplicationByEvaluationId(evaluationId); applicationId = applicationEntity.getId(); callId = applicationEntity.getCall().getId(); + }else if(DocumentSourceTypeEnum.COMMUNICATION.getValue().equalsIgnoreCase(document.getSource())){ + communicationId = document.getSourceId(); + Optional communicationEntity=communicationRepository.findByIdAndIsDeletedFalse(communicationId); + ApplicationEntity applicationEntity =communicationEntity.get().getApplicationAmendmentRequest().getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication(); + applicationId = applicationEntity.getId(); + callId = applicationEntity.getCall().getId(); } - documentDao.deleteFileFromS3(document,callId,applicationId,amendmentId); + documentDao.deleteFileFromS3(document,callId,applicationId,amendmentId,communicationId); processDocuments++; } catch (Exception e) { @@ -219,10 +231,10 @@ public class S3ReUploadMigrationService { Long callId; if (sourceType.equals(DocumentSourceTypeEnum.CALL)) { - return s3ConfigBean.generateDocumentPath(sourceType, document.getSourceId(), 0L,0L); + return s3ConfigBean.generateDocumentPath(sourceType, document.getSourceId(), 0L,0L,0L); } else { callId = applicationRepository.findCallIdById(document.getSourceId()); - return s3ConfigBean.generateDocumentPath(sourceType, callId, document.getSourceId(),0L); + return s3ConfigBean.generateDocumentPath(sourceType, callId, document.getSourceId(),0L,0L); } } diff --git a/src/main/java/net/gepafin/tendermanagement/service/impl/UserSignedAndDelegationServiceImpl.java b/src/main/java/net/gepafin/tendermanagement/service/impl/UserSignedAndDelegationServiceImpl.java index d5bd4c3c..e6ba7821 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/impl/UserSignedAndDelegationServiceImpl.java +++ b/src/main/java/net/gepafin/tendermanagement/service/impl/UserSignedAndDelegationServiceImpl.java @@ -139,7 +139,7 @@ public class UserSignedAndDelegationServiceImpl { private String generateNewS3PathForDelegationDoc() { - return s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_DELEGATION, 0L, 0L,0L); + return s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_DELEGATION, 0L, 0L,0L,0L); } private String generateNewS3PathForUserSignedDoc(ApplicationSignedDocumentEntity document) { diff --git a/src/main/java/net/gepafin/tendermanagement/util/Utils.java b/src/main/java/net/gepafin/tendermanagement/util/Utils.java index 28dca3d7..b9541759 100644 --- a/src/main/java/net/gepafin/tendermanagement/util/Utils.java +++ b/src/main/java/net/gepafin/tendermanagement/util/Utils.java @@ -1095,6 +1095,22 @@ public class Utils { return "Invalid amount format"; } } + public static void validateEmailJson(Map emailJson) { + for (Map.Entry entry : emailJson.entrySet()) { + if (isEmpty(entry.getKey())) { + throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.INVALID_EMAIL_JSON)); + } + } + validateJsonKeys(emailJson, GepafinConstant.MANUAL_EMAIL_KEYS); + } + private static void validateJsonKeys(Map actionJson, List validkeys) { + for (String key : validkeys) { + if (!actionJson.containsKey(key)) { + throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.INVALID_EMAIL_JSON)); + } + } + + } } 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 9fe94bb5..033f9fd6 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 @@ -18,6 +18,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -44,10 +45,16 @@ public interface ApplicationAmendmentRequestApi { @ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })), @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) }) - @PostMapping(value = "", produces = "application/json") - ResponseEntity> createApplicationAmendmentRequest(HttpServletRequest request, - @Parameter(description = "Application Evaluation Id", required = true) @RequestParam Long applicationEvaluationId, - @Valid @RequestBody ApplicationAmendmentRequest applicationAmendmentRequest); + @PostMapping(value = "", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + ResponseEntity> createApplicationAmendmentRequest( + HttpServletRequest request, + @Parameter(description = "Application Evaluation Id", required = true) + @RequestParam Long applicationEvaluationId, + @Parameter(description = "List of files to upload", required = false) + @RequestPart(required = false) List files, + @Parameter(description = "Amendment details as JSON", required = true) + @RequestPart("applicationAmendmentRequest") ApplicationAmendmentRequest applicationAmendmentRequest); + @Operation(summary = "Api to delete application amendment request", 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 4798e078..30e0750d 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 @@ -8,16 +8,14 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.Valid; import net.gepafin.tendermanagement.enums.FormActionEnum; -import net.gepafin.tendermanagement.model.request.ApplicationEvaluationFormRequestBean; -import net.gepafin.tendermanagement.model.request.ApplicationEvaluationRequest; -import net.gepafin.tendermanagement.model.request.ApplicationRequestBean; -import net.gepafin.tendermanagement.model.request.EvaluationDocumentRequest; +import net.gepafin.tendermanagement.model.request.*; import net.gepafin.tendermanagement.model.response.*; import net.gepafin.tendermanagement.model.util.Response; import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -31,11 +29,12 @@ public interface ApplicationEvaluationApi { @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) }) - @PutMapping(value = "/{assignedApplicationsId}", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) + @PutMapping(value = "/{assignedApplicationsId}", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) ResponseEntity> createOrUpdateApplicationEvaluation( HttpServletRequest request, - @Parameter(description = "Assigned Application ID", required = true) @PathVariable("assignedApplicationsId") Long assignedApplicationsId, - @Parameter(description = "Application Evaluation Request Body", required = true) @Valid @RequestBody ApplicationEvaluationRequest evaluationRequest); + @Parameter(description = "Assigned Application ID", required = true) @PathVariable("assignedApplicationsId") Long assignedApplicationsId, @Parameter(description = "List of files to upload", required = false) + @RequestPart(required = false) List rejectedDocuments, + @Parameter(description = "Application Evaluation Request Body", required = true) @RequestPart ApplicationEvaluationRequest evaluationRequest); @Operation(summary = "API to get ApplicationEvaluation data for evaluation process", responses = { @@ -70,9 +69,10 @@ public interface ApplicationEvaluationApi { @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) }) @PutMapping(value = "/v2/assignedApplication/{id}", - produces = { "application/json" }) - ResponseEntity> createApplicationEvaluation(HttpServletRequest request, - @Valid @RequestBody ApplicationEvaluationFormRequestBean applicationEvaluationFormRequestBean, + produces = { "application/json" },consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + ResponseEntity> createApplicationEvaluation(HttpServletRequest request, @Parameter(description = "List of files to upload", required = false) + @RequestPart(required = false) List rejectedDocuments, + @RequestPart ApplicationEvaluationFormRequestBean applicationEvaluationFormRequestBean, @Parameter(description = "Assigned Application ID", required = true) @PathVariable(value = "id", required = true) Long assignedApplicationId, @Parameter(description = "The evaluation form ID", required = true) @RequestParam("evaluationFormId") Long evaluationFormId); @@ -104,5 +104,18 @@ public interface ApplicationEvaluationApi { @Parameter(description = "The application id", required = true) @PathVariable("id") Long id); + @Operation(summary = "API to update Application to TECHNICAL EVALUATION REJECTED", + responses = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { + @ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })), + @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { + @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) + }) + @PutMapping(value = "/{assignedApplicationsId}/technicalEvaluationRejected", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) + ResponseEntity> updateApplicationToTechnicalEvaluationRejected( + HttpServletRequest request, + @Parameter(description = "Assigned Application ID", required = true) @PathVariable("assignedApplicationsId") Long assignedApplicationsId, + @Parameter(description = "Application Request Body", required = true) @Valid @RequestBody ApplicationTechnicalEvaluationRejectedRequest applicationRequest); } diff --git a/src/main/java/net/gepafin/tendermanagement/web/rest/api/CommunicationApi.java b/src/main/java/net/gepafin/tendermanagement/web/rest/api/CommunicationApi.java index 01070a4e..6f9d9ddc 100644 --- a/src/main/java/net/gepafin/tendermanagement/web/rest/api/CommunicationApi.java +++ b/src/main/java/net/gepafin/tendermanagement/web/rest/api/CommunicationApi.java @@ -7,7 +7,6 @@ import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.servlet.http.HttpServletRequest; import net.gepafin.tendermanagement.model.request.CommunicationRequestBean; -import net.gepafin.tendermanagement.model.response.ApplicationAmendmentResponse; import net.gepafin.tendermanagement.model.response.CommunicationResponseBean; import net.gepafin.tendermanagement.model.util.Response; import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants; @@ -16,12 +15,10 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.util.List; @Validated public interface CommunicationApi { @@ -32,10 +29,11 @@ public interface CommunicationApi { @ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })), @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) }) - @PostMapping(value = "/{amendmentId}", produces = { "application/json" }) + @PostMapping(value = "/{amendmentId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @PreAuthorize("hasRole('ROLE_PRE_INSTRUCTOR') || hasRole('ROLE_BENEFICIARY') || hasRole('ROLE_INSTRUCTOR_MANAGER') || hasRole('ROLE_CONFIDI')") - ResponseEntity> addCommentToAmendmentRequest(HttpServletRequest request, - @RequestBody @Parameter CommunicationRequestBean communicationResponseBean, @PathVariable(value = "amendmentId") Long amendmentId); + ResponseEntity> addCommentToAmendmentRequest(HttpServletRequest request, @Parameter(description = "List of files to upload", required = false) + @RequestPart(required = false) List files, + @Parameter(description = "communication request body" ,required=true) @RequestPart CommunicationRequestBean communicationResponseBean, @PathVariable(value = "amendmentId") Long amendmentId); @Operation(summary = "API to Get Amendment Request Comment", responses = { @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = @ExampleObject(value = @@ -45,7 +43,7 @@ public interface CommunicationApi { @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE))) }) @GetMapping(value = "/{amendmentId}", produces = "application/json") - public ResponseEntity> getAmendmentComments(HttpServletRequest request,@PathVariable(value = "amendmentId") Long amendmentId); + public ResponseEntity>> getAmendmentComments(HttpServletRequest request,@PathVariable(value = "amendmentId") Long amendmentId); @Operation(summary = "Api to update communication comments", responses = { @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { 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 797cce3a..12906aef 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 @@ -1,5 +1,7 @@ package net.gepafin.tendermanagement.web.rest.api.impl; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.servlet.http.HttpServletRequest; import lombok.extern.log4j.Log4j2; import net.gepafin.tendermanagement.config.Translator; @@ -19,6 +21,8 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + import java.util.List; @RestController @@ -26,6 +30,9 @@ import java.util.List; @Log4j2 public class ApplicationAmendmentRequestController implements ApplicationAmendmentRequestApi { + @Autowired + private ObjectMapper mapper; + @Autowired ApplicationAmendmentRequestService applicationAmendmentRequestService; @@ -45,13 +52,18 @@ public class ApplicationAmendmentRequestController implements ApplicationAmendme } @Override - public ResponseEntity> createApplicationAmendmentRequest(HttpServletRequest request, Long applicationEvaluationId, ApplicationAmendmentRequest applicationAmendmentRequest) { - + public ResponseEntity> createApplicationAmendmentRequest(HttpServletRequest request, Long applicationEvaluationId, List files, ApplicationAmendmentRequest applicationAmendmentRequest) { +// ApplicationAmendmentRequest data=null; +// try { +// data = mapper.readValue(applicationAmendmentRequest,ApplicationAmendmentRequest.class); +// } catch (JsonProcessingException e) { +// throw new RuntimeException(e); +// } /** This code is responsible for creating user action logs for the "Create Application Amendment" operation. **/ loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.INSERT) .actionContext(UserActionContextEnum.CREATE_AMENDMENT).build()); - ApplicationAmendmentRequestResponse applicationAmendmentRequestResponse = applicationAmendmentRequestService.createApplicationAmendmentRequest(request,applicationEvaluationId,applicationAmendmentRequest); + ApplicationAmendmentRequestResponse applicationAmendmentRequestResponse = applicationAmendmentRequestService.createApplicationAmendmentRequest(request,applicationEvaluationId,files,applicationAmendmentRequest); return ResponseEntity.status(HttpStatus.OK) .body(new Response<>(applicationAmendmentRequestResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.CREATE_APPLICATION_DATA_FOR_AMENDMENT_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 2f6bbcb3..11e1eb1c 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 @@ -18,6 +18,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -34,7 +35,7 @@ public class ApplicationEvaluationApiController implements ApplicationEvaluation @Override public ResponseEntity> createOrUpdateApplicationEvaluation( HttpServletRequest request, - Long assignedApplicationsId, + Long assignedApplicationsId, List rejectedDocuments, ApplicationEvaluationRequest evaluationRequest) { /** This code is responsible for creating user action logs for the "Create or update Application Evaluation" operation. **/ @@ -43,7 +44,7 @@ public class ApplicationEvaluationApiController implements ApplicationEvaluation ApplicationEvaluationResponse response = applicationEvaluationService.createOrUpdateApplicationEvaluation( - request, evaluationRequest, assignedApplicationsId); + request, evaluationRequest, assignedApplicationsId,rejectedDocuments); return ResponseEntity.status(HttpStatus.CREATED) .body(new Response<>(response, Status.SUCCESS, Translator.toLocale(GepafinConstant.USER_REQUEST_COMPLETED))); @@ -82,13 +83,13 @@ public class ApplicationEvaluationApiController implements ApplicationEvaluation } @Override - public ResponseEntity> createApplicationEvaluation(HttpServletRequest request, ApplicationEvaluationFormRequestBean applicationEvaluationFormRequestBean, Long assignedApplicationId, Long evaluationFormId) { + public ResponseEntity> createApplicationEvaluation(HttpServletRequest request, List rejectedDocuments, ApplicationEvaluationFormRequestBean applicationEvaluationFormRequestBean, Long assignedApplicationId, Long evaluationFormId) { /** This code is responsible for creating user action logs for the "Create or update application evaluation form" operation. **/ loggingUtil.logUserAction( UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.UPDATE).actionContext(UserActionContextEnum.CREATE_UPDATE_APPLICATION_EVALUATION_FORM).build()); - ApplicationEvaluationFormResponse applicationEvaluationResponseBean = applicationEvaluationService.createApplicationEvaluation(request, applicationEvaluationFormRequestBean, assignedApplicationId, evaluationFormId); + ApplicationEvaluationFormResponse applicationEvaluationResponseBean = applicationEvaluationService.createApplicationEvaluation(request,rejectedDocuments, applicationEvaluationFormRequestBean, assignedApplicationId, evaluationFormId); return ResponseEntity.status(HttpStatus.CREATED) .body(new Response<>(applicationEvaluationResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.EVALUATION_CREATED_SUCCESSFULLY))); @@ -118,4 +119,15 @@ public class ApplicationEvaluationApiController implements ApplicationEvaluation .body(new Response<>(applicationEvaluationVersionResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_APPLICATION_EVALUATION_VERSION_SUCCESS_MSG))); } + @Override + public ResponseEntity> updateApplicationToTechnicalEvaluationRejected(HttpServletRequest request, Long assignedApplicationsId, ApplicationTechnicalEvaluationRejectedRequest applicationRequest) { + loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW).actionContext(UserActionContextEnum.UPDATE_APPLICATION_TO_TECHNICAL_EVALUATION_REJECTED).build()); + + ApplicationEvaluationResponse applicationEvaluationVersionResponse = applicationEvaluationService.updateApplicationToTechnicalEvaluationRejected(request,applicationRequest,assignedApplicationsId); + + return ResponseEntity.status(HttpStatus.OK) + .body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.UPDATE_APPLICATION_TECHNICAL_EVALUATION_REJECTED_MSG))); + + } + } diff --git a/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/CommunicationController.java b/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/CommunicationController.java index 15552e95..83b83fb3 100644 --- a/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/CommunicationController.java +++ b/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/CommunicationController.java @@ -7,7 +7,6 @@ import net.gepafin.tendermanagement.enums.UserActionContextEnum; import net.gepafin.tendermanagement.enums.UserActionLogsEnum; import net.gepafin.tendermanagement.model.request.CommunicationRequestBean; import net.gepafin.tendermanagement.model.request.UserActionRequest; -import net.gepafin.tendermanagement.model.response.ApplicationAmendmentResponse; import net.gepafin.tendermanagement.model.response.CommunicationResponseBean; import net.gepafin.tendermanagement.model.util.Response; import net.gepafin.tendermanagement.service.CommunicationService; @@ -19,6 +18,9 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import java.util.List; @RestController @RequestMapping("${openapi.gepafin.base-path:/v1/communication}") @@ -31,23 +33,23 @@ public class CommunicationController implements CommunicationApi { private LoggingUtil loggingUtil; @Override - public ResponseEntity> addCommentToAmendmentRequest(HttpServletRequest request, CommunicationRequestBean communicationRequestBean, - Long amendmentId) { + public ResponseEntity> addCommentToAmendmentRequest(HttpServletRequest request, List files, CommunicationRequestBean communicationRequestBean, + Long amendmentId) { /** This code is responsible for creating user action logs for the "Adding comment to amendment request" operation. **/ loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.INSERT).actionContext(UserActionContextEnum.ADD_COMMENT_TO_AMENDMENT_REQUEST).build()); - CommunicationResponseBean communicationResponseBean = communicationService.addCommentToAmendmentRequest(request,communicationRequestBean, amendmentId); + CommunicationResponseBean communicationResponseBean = communicationService.addCommentToAmendmentRequest(request,communicationRequestBean, amendmentId,files); return ResponseEntity.status(HttpStatus.CREATED) .body(new Response<>(communicationResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMMUNICATION_ADDED_TO_AMENDMENT_REQUEST_SUCCESS))); } @Override - public ResponseEntity> getAmendmentComments(HttpServletRequest request,Long amendmentId) { + public ResponseEntity>> getAmendmentComments(HttpServletRequest request,Long amendmentId) { /** This code is responsible for creating user action logs for the "getting comment of amendment" operation. **/ loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW).actionContext(UserActionContextEnum.GET_AMENDMENT_COMMENT).build()); - ApplicationAmendmentResponse response = communicationService.getAmendmentComments(request,amendmentId); + List response = communicationService.getAmendmentComments(request,amendmentId); return ResponseEntity.ok(new Response<>(response, Status.SUCCESS, Translator.toLocale(GepafinConstant.AMENDMENT_FOUND_SUCCESS))); } @Override 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 0011957a..1f58437f 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 @@ -3026,5 +3026,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + UNIQUE_UUID = 'p4lk3bcx1RStqTaIVVbXs' + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/db/dump/update_system_email_template_of_application_rejected_16_10_2025.sql b/src/main/resources/db/dump/update_system_email_template_of_application_rejected_16_10_2025.sql new file mode 100644 index 00000000..fb8bd4a2 --- /dev/null +++ b/src/main/resources/db/dump/update_system_email_template_of_application_rejected_16_10_2025.sql @@ -0,0 +1,18 @@ +UPDATE gepafin_schema.system_email_template +SET html_content = ' + +
+

Buongiorno,

+

Si comunica che, in riferimento alla domanda a valere sul bando “{{call_name}}” di cui al + Protocollo n. {{protocol_number}} del {{protocol_date}} alle {{protocol_time}}, +

+

+ {{tipo_inammissibilita}}.

+

Le motivazioni sono le seguenti: {{form_text}}

+

Vi ricordiamo che i Beneficiari che hanno presentato richieste valutate non ammissibili entro 10 giorni dalla data di ricevimento della presente potranno finoltrare richiesta di chiarimenti e/o osservazioni alla scrivente Società ai sensi e per gli effetti dell’art.10 bis della L.241/1990 e s.m.i.

+

Distinti Saluti,

+

{{email_signature}}

+
+ + ' +WHERE "type" = 'INADMISSIBILITY_NOTIFICATION' and "email_scenario" = 'APPLICATION_REJECTED' and "system" = true; \ No newline at end of file diff --git a/src/main/resources/db/dump/update_system_email_template_of_application_rejected_17_10_2025.sql b/src/main/resources/db/dump/update_system_email_template_of_application_rejected_17_10_2025.sql new file mode 100644 index 00000000..a42ce4a8 --- /dev/null +++ b/src/main/resources/db/dump/update_system_email_template_of_application_rejected_17_10_2025.sql @@ -0,0 +1,3 @@ +UPDATE gepafin_schema.system_email_template +SET subject = 'BANDO {{call_name}} – {{email_type}} {{company_name}}' +WHERE "type" = 'INADMISSIBILITY_NOTIFICATION' and "email_scenario" = 'APPLICATION_REJECTED' and "system" = true; \ No newline at end of file diff --git a/src/main/resources/message_en.properties b/src/main/resources/message_en.properties index 684a6006..c02deff6 100644 --- a/src/main/resources/message_en.properties +++ b/src/main/resources/message_en.properties @@ -413,4 +413,8 @@ email.pec.cannot.null=Email pec is required. user.request.completed=User request completed successfully. end.date.greater.than.now=End date must be greater than the current date and time. pec.email.required=PEC email is required. +application.technical.evaluation.rejected.success=Application changes to status application technical evaluation rejected successfully. +invalid.email.json=Invalid email json. +more.fields.required=Subject, reason, and motivation are required when rejecting the application. + diff --git a/src/main/resources/message_it.properties b/src/main/resources/message_it.properties index 92a96cb0..e18f529a 100644 --- a/src/main/resources/message_it.properties +++ b/src/main/resources/message_it.properties @@ -404,4 +404,6 @@ email.pec.cannot.null=L'indirizzo email pec user.request.completed=Richiesta utente completata con successo. end.date.greater.than.now=La data di fine deve essere successiva alla data e all'ora correnti. pec.email.required=Obbligatorio l'indirizzo e-mail PEC. - +application.technical.evaluation.rejected.success=Lo stato dell'applicazione cambia: valutazione tecnica dell'applicazione rifiutata con successo. +invalid.email.json=Codice email json non valido. +more.fields.required=Per rifiutare la domanda sono richiesti oggetto, motivo e motivazione.