Merge pull request #327 from Kitzanos/feature/GEPAFINBE-232
GEPAFINBE-232 (Fixed Amendment document issue)
This commit is contained in:
@@ -803,7 +803,7 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private List<ApplicationFormFieldEntity> getApplicationFormFieldList(
|
public List<ApplicationFormFieldEntity> getApplicationFormFieldList(
|
||||||
ApplicationAmendmentRequestEntity applicationAmendment,
|
ApplicationAmendmentRequestEntity applicationAmendment,
|
||||||
List<String> fieldIds) {
|
List<String> fieldIds) {
|
||||||
List<ApplicationFormEntity> applicationFormList = applicationFormRepository
|
List<ApplicationFormEntity> applicationFormList = applicationFormRepository
|
||||||
|
|||||||
@@ -1155,7 +1155,7 @@ public class ApplicationEvaluationDao {
|
|||||||
applicationEvaluationResponse.setEmailSendResponse(entity.getEmailSendResponse());
|
applicationEvaluationResponse.setEmailSendResponse(entity.getEmailSendResponse());
|
||||||
return applicationEvaluationResponse;
|
return applicationEvaluationResponse;
|
||||||
}
|
}
|
||||||
private List<EvaluationDocumentRequest> prepareEvaluationDocumentBeanList(ApplicationEvaluationEntity entity) {
|
public List<EvaluationDocumentRequest> prepareEvaluationDocumentBeanList(ApplicationEvaluationEntity entity) {
|
||||||
List<EvaluationDocumentRequest> docRequest = new ArrayList<>();
|
List<EvaluationDocumentRequest> docRequest = new ArrayList<>();
|
||||||
|
|
||||||
if (entity != null && entity.getEvaluationDocument() != null) {
|
if (entity != null && entity.getEvaluationDocument() != null) {
|
||||||
|
|||||||
@@ -1,13 +1,19 @@
|
|||||||
package net.gepafin.tendermanagement.dao;
|
package net.gepafin.tendermanagement.dao;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import net.gepafin.tendermanagement.entities.*;
|
||||||
import net.gepafin.tendermanagement.enums.*;
|
import net.gepafin.tendermanagement.enums.*;
|
||||||
|
import net.gepafin.tendermanagement.model.request.AmendmentFormField;
|
||||||
|
import net.gepafin.tendermanagement.model.request.EvaluationDocumentRequest;
|
||||||
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
||||||
import net.gepafin.tendermanagement.repositories.ApplicationEvaluationRepository;
|
import net.gepafin.tendermanagement.model.response.ContentResponseBean;
|
||||||
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
import net.gepafin.tendermanagement.model.response.SettingResponseBean;
|
||||||
|
import net.gepafin.tendermanagement.repositories.*;
|
||||||
import net.gepafin.tendermanagement.util.LoggingUtil;
|
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||||
import net.gepafin.tendermanagement.util.Utils;
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
||||||
@@ -17,13 +23,8 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
|
|
||||||
import net.gepafin.tendermanagement.config.Translator;
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
|
||||||
import net.gepafin.tendermanagement.entities.CallEntity;
|
|
||||||
import net.gepafin.tendermanagement.entities.DocumentEntity;
|
|
||||||
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
|
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
|
||||||
import net.gepafin.tendermanagement.model.response.UploadFileOnAmazonS3Response;
|
import net.gepafin.tendermanagement.model.response.UploadFileOnAmazonS3Response;
|
||||||
import net.gepafin.tendermanagement.repositories.ApplicationAmendmentRequestRepository;
|
|
||||||
import net.gepafin.tendermanagement.repositories.DocumentRepository;
|
|
||||||
import net.gepafin.tendermanagement.service.AmazonS3Service;
|
import net.gepafin.tendermanagement.service.AmazonS3Service;
|
||||||
import net.gepafin.tendermanagement.service.ApplicationAmendmentRequestService;
|
import net.gepafin.tendermanagement.service.ApplicationAmendmentRequestService;
|
||||||
import net.gepafin.tendermanagement.service.ApplicationService;
|
import net.gepafin.tendermanagement.service.ApplicationService;
|
||||||
@@ -31,8 +32,6 @@ import net.gepafin.tendermanagement.service.CallService;
|
|||||||
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
|
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
|
||||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -78,6 +77,18 @@ public class DocumentDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private HttpServletRequest request;
|
private HttpServletRequest request;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationFormRepository applicationFormRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationFormFieldRepository applicationFormFieldRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationAmendmentRequestDao applicationAmendmentRequestDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationEvaluationDao applicationEvaluationDao;
|
||||||
|
|
||||||
// @Value("${aws.s3.url.folder}")
|
// @Value("${aws.s3.url.folder}")
|
||||||
// private String s3Folder;
|
// private String s3Folder;
|
||||||
|
|
||||||
@@ -224,18 +235,72 @@ public class DocumentDao {
|
|||||||
} else if (DocumentSourceTypeEnum.APPLICATION.getValue().equalsIgnoreCase(documentEntity.getSource())) {
|
} else if (DocumentSourceTypeEnum.APPLICATION.getValue().equalsIgnoreCase(documentEntity.getSource())) {
|
||||||
applicationId = documentEntity.getSourceId();
|
applicationId = documentEntity.getSourceId();
|
||||||
ApplicationEntity applicationEntity = applicationService.validateApplication(applicationId);
|
ApplicationEntity applicationEntity = applicationService.validateApplication(applicationId);
|
||||||
|
|
||||||
|
List<ApplicationFormEntity> applicationFormEntity=applicationFormRepository.findByApplicationId(applicationId);
|
||||||
|
for (ApplicationFormEntity applicationForm:applicationFormEntity){
|
||||||
|
FormEntity formEntity=applicationForm.getForm();
|
||||||
|
List<ContentResponseBean> contentList = Utils.convertJsonStringToList(formEntity.getContent(), ContentResponseBean.class);
|
||||||
|
List<ApplicationFormFieldEntity> applicationFormFieldEntityList=applicationFormFieldRepository.findByApplicationFormId(applicationForm.getId());
|
||||||
|
for (ApplicationFormFieldEntity applicationFormFieldEntity:applicationFormFieldEntityList) {
|
||||||
|
contentList.forEach(contentResponseBean -> {
|
||||||
|
if (("fileupload".equals(contentResponseBean.getName()) || GepafinConstant.FILE_SELECT.equals(contentResponseBean.getName()))
|
||||||
|
&& contentResponseBean.getId().equals(applicationFormFieldEntity.getFieldId())) {
|
||||||
|
String updatedValue = removeDocumentIdFromFieldValue(applicationFormFieldEntity.getFieldValue(), documentId);
|
||||||
|
applicationFormFieldEntity.setFieldValue(updatedValue);
|
||||||
|
applicationFormFieldRepository.save(applicationFormFieldEntity);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
callId = applicationEntity.getCall().getId();
|
callId = applicationEntity.getCall().getId();
|
||||||
log.info("Processing document of type APPLICATION. Resolved applicationId={}, callId={}", applicationId, callId);
|
log.info("Processing document of type APPLICATION. Resolved applicationId={}, callId={}", applicationId, callId);
|
||||||
}
|
}
|
||||||
else if(DocumentSourceTypeEnum.AMENDMENT.getValue().equalsIgnoreCase(documentEntity.getSource())){
|
else if(DocumentSourceTypeEnum.AMENDMENT.getValue().equalsIgnoreCase(documentEntity.getSource())){
|
||||||
amendmentId = documentEntity.getSourceId();
|
amendmentId = documentEntity.getSourceId();
|
||||||
ApplicationEntity applicationEntity = applicationAmendmentRequestRepository.findApplicationByAmendmentId(amendmentId);
|
ApplicationEntity applicationEntity = applicationAmendmentRequestRepository.findApplicationByAmendmentId(amendmentId);
|
||||||
|
Optional<ApplicationAmendmentRequestEntity> applicationAmendmentRequestEntity=applicationAmendmentRequestRepository.findByIdAndIsDeletedFalse(amendmentId);
|
||||||
|
Map<String, AmendmentFormField> amendmentFormFieldMap = Utils
|
||||||
|
.convertJsonStringToList(applicationAmendmentRequestEntity.get().getFormFields(), AmendmentFormField.class)
|
||||||
|
.stream().collect(Collectors.toMap(AmendmentFormField::getFieldId, Function.identity()));
|
||||||
|
for (Map.Entry<String, AmendmentFormField> entry : amendmentFormFieldMap.entrySet()) {
|
||||||
|
AmendmentFormField amendmentFormField=entry.getValue();
|
||||||
|
String updatedValue = removeDocumentIdFromFieldValue(amendmentFormField.getFieldValue(), documentId);
|
||||||
|
amendmentFormField.setFieldValue(updatedValue);
|
||||||
|
}
|
||||||
|
String amendmentDocs=applicationAmendmentRequestEntity.get().getAmendmentDocument();
|
||||||
|
Map<String,Object> amendmentDocument=Utils.convertIntoJson(amendmentDocs);
|
||||||
|
String amendmentDocuments= (String) amendmentDocument.get("amendmentDocuments");
|
||||||
|
if(amendmentDocuments!=null){
|
||||||
|
String updatedValue = removeDocumentIdFromFieldValue(amendmentDocuments, documentId);
|
||||||
|
amendmentDocument.put("amendmentDocuments", updatedValue);
|
||||||
|
|
||||||
|
// Step 4: Convert map back to JSON string
|
||||||
|
String updatedAmendmentDocs = Utils.convertMapIntoJsonString(amendmentDocument); // implement this if not available
|
||||||
|
|
||||||
|
// Step 5: Set it back to entity
|
||||||
|
applicationAmendmentRequestEntity.get().setAmendmentDocument(updatedAmendmentDocs);
|
||||||
|
}
|
||||||
|
applicationAmendmentRequestEntity.get().setFormFields(Utils.convertListToJsonString(amendmentFormFieldMap.values().stream().toList()));
|
||||||
|
applicationAmendmentRequestRepository.save(applicationAmendmentRequestEntity.get());
|
||||||
|
|
||||||
applicationId = applicationEntity.getId();
|
applicationId = applicationEntity.getId();
|
||||||
callId = applicationEntity.getCall().getId();
|
callId = applicationEntity.getCall().getId();
|
||||||
log.info("Processing document of type AMENDMENT. Resolved amendmentId={}, applicationId={}, callId={}", amendmentId, applicationId, callId);
|
log.info("Processing document of type AMENDMENT. Resolved amendmentId={}, applicationId={}, callId={}", amendmentId, applicationId, callId);
|
||||||
} else if(DocumentSourceTypeEnum.EVALUATION.getValue().equalsIgnoreCase(documentEntity.getSource())){
|
} else if(DocumentSourceTypeEnum.EVALUATION.getValue().equalsIgnoreCase(documentEntity.getSource())){
|
||||||
evaluationId = documentEntity.getSourceId();
|
evaluationId = documentEntity.getSourceId();
|
||||||
ApplicationEntity applicationEntity = applicationEvaluationRepository.findApplicationByEvaluationId(evaluationId);
|
ApplicationEntity applicationEntity = applicationEvaluationRepository.findApplicationByEvaluationId(evaluationId);
|
||||||
|
ApplicationEvaluationEntity entity=applicationEvaluationRepository.findByApplicationId(applicationEntity.getId());
|
||||||
|
List<EvaluationDocumentRequest> allDocs = applicationEvaluationDao.prepareEvaluationDocumentBeanList(entity);
|
||||||
|
List<EvaluationDocumentRequest> updatedDocs=allDocs;
|
||||||
|
allDocs = allDocs.stream()
|
||||||
|
.filter(doc -> doc.getFileValue().equals(removeDocumentIdFromFieldValue(doc.getFileValue(), documentId)))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
|
||||||
|
String updatedEvaluationDocJson = Utils.convertObjectToJson(allDocs);
|
||||||
|
entity.setEvaluationDocument(updatedEvaluationDocJson);
|
||||||
|
applicationEvaluationRepository.save(entity);
|
||||||
applicationId = applicationEntity.getId();
|
applicationId = applicationEntity.getId();
|
||||||
callId = applicationEntity.getCall().getId();
|
callId = applicationEntity.getCall().getId();
|
||||||
log.info("Processing document of type EVALUATION. Resolved evaluationId={}, applicationId={}, callId={}", evaluationId, applicationId, callId);
|
log.info("Processing document of type EVALUATION. Resolved evaluationId={}, applicationId={}, callId={}", evaluationId, applicationId, callId);
|
||||||
@@ -343,4 +408,19 @@ public class DocumentDao {
|
|||||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.ERROR_MOVING_FILE_TO_DELETED_FOLDER));
|
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.ERROR_MOVING_FILE_TO_DELETED_FOLDER));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String removeDocumentIdFromFieldValue(String fieldValue, Long documentId) {
|
||||||
|
if (fieldValue == null || fieldValue.isBlank()) {
|
||||||
|
return fieldValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> documentIdList = new ArrayList<>(Arrays.asList(fieldValue.split(",")));
|
||||||
|
documentIdList.replaceAll(String::trim); // Trim spaces for safety
|
||||||
|
|
||||||
|
boolean removed = documentIdList.removeIf(id -> id.equals(String.valueOf(documentId)));
|
||||||
|
|
||||||
|
// Return updated value only if modified, else return original
|
||||||
|
return removed ? String.join(",", documentIdList) : fieldValue;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user