Amendment document changes

This commit is contained in:
rajesh
2024-12-18 15:58:17 +05:30
parent 94086428e8
commit 47f67975c1
8 changed files with 167 additions and 80 deletions

View File

@@ -108,6 +108,9 @@ public class ApplicationAmendmentRequestDao {
@Autowired @Autowired
private ApplicationEvaluationDao applicationEvaluationDao; private ApplicationEvaluationDao applicationEvaluationDao;
@Autowired
private DocumentRepository documentRepository;
public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(Long applicationEvaluationId) { public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(Long applicationEvaluationId) {
log.info("Fetching the application data for the Amendment process {}", applicationEvaluationId); log.info("Fetching the application data for the Amendment process {}", applicationEvaluationId);
ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluation(applicationEvaluationId); ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluation(applicationEvaluationId);
@@ -330,15 +333,24 @@ public class ApplicationAmendmentRequestDao {
return applicationAmendment; return applicationAmendment;
} }
private void setAmendmentDocuments(String amendmentNotes, String amendmentFieldRequest,
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity) {
AmendmentDetailsResponseBean amendmentDetails = new AmendmentDetailsResponseBean();
if (amendmentFieldRequest != null && !amendmentFieldRequest.trim().isEmpty()) {
String[] documentIds = amendmentFieldRequest.split(",");
String validDocumentIds = Arrays.stream(documentIds)
.map(String::trim)
.filter(id -> !id.isEmpty())
.collect(Collectors.joining(","));
private void setAmendmentDocuments(List<AmendmentFieldRequest> amendmentFieldRequest, ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity) { amendmentDetails.setAmendmentDocuments(validDocumentIds);
amendmentFieldRequest.stream().forEach(amendmentData->{
String fieldValue=amendmentData.getFileValue();
if(fieldValue!=null){
documentService.validateDocument(Long.valueOf(fieldValue));
} }
}); if (amendmentNotes != null && !amendmentNotes.trim().isEmpty()) {
applicationAmendmentRequestEntity.setAmendmentDocument(Utils.convertListToJsonString(amendmentFieldRequest)); amendmentDetails.setAmendmentNotes(amendmentNotes.trim());
}
amendmentDetails.setValid(null);
String amendmentDetailsJson = Utils.convertListToJsonString(Collections.singletonList(amendmentDetails));
applicationAmendmentRequestEntity.setAmendmentDocument(amendmentDetailsJson);
} }
public ApplicationAmendmentRequestEntity saveApplicationAmendmentRequestEntity(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity,ApplicationAmendmentRequestEntity oldApplicationAmendmentEntity,VersionActionTypeEnum actionTypeEnum) { public ApplicationAmendmentRequestEntity saveApplicationAmendmentRequestEntity(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity,ApplicationAmendmentRequestEntity oldApplicationAmendmentEntity,VersionActionTypeEnum actionTypeEnum) {
@@ -355,38 +367,69 @@ public class ApplicationAmendmentRequestDao {
List<ApplicationFormEntity> forms = applicationFormRepository.findByApplicationId(applicationAmendmentRequestEntity.getApplicationId()); List<ApplicationFormEntity> forms = applicationFormRepository.findByApplicationId(applicationAmendmentRequestEntity.getApplicationId());
Map<String, String> fieldIdToLabelMap = extractFieldIdToLabelMap(forms); Map<String, String> fieldIdToLabelMap = extractFieldIdToLabelMap(forms);
List<AmendmentFieldRequest> amendmentFieldRequests= new ArrayList<>(); // List<AmendmentFieldRequest> amendmentFieldRequests= new ArrayList<>();
List<AmendmentFormField> amendmentFormFields = Utils.convertJsonStringToList( List<AmendmentFormField> amendmentFormFields = Utils.convertJsonStringToList(
applicationAmendmentRequestEntity.getFormFields(), AmendmentFormField.class); applicationAmendmentRequestEntity.getFormFields(), AmendmentFormField.class);
Map<String, ApplicationFormFieldEntity> formFieldEntityMap = getApplicationFormFieldEntityMap(applicationAmendmentRequestEntity, amendmentFormFields); Map<String, ApplicationFormFieldEntity> formFieldEntityMap = getApplicationFormFieldEntityMap(applicationAmendmentRequestEntity, amendmentFormFields);
if (applicationAmendmentRequestEntity.getAmendmentDocument() != null) { if (applicationAmendmentRequestEntity.getAmendmentDocument() != null) {
amendmentFieldRequests = Utils.convertJsonStringToList(applicationAmendmentRequestEntity.getAmendmentDocument(),AmendmentFieldRequest.class);
List<AmendmentDetailsResponseBean> amendmentDetailsList =
Utils.convertJsonStringToList(applicationAmendmentRequestEntity.getAmendmentDocument(),
AmendmentDetailsResponseBean.class);
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
for (AmendmentDetailsResponseBean amendmentDetails:amendmentDetailsList) {
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<String> 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;
} }
if (amendmentFieldRequests != null) { })
List<AmendmentDocumentResponse> amendmentDocumentResponses = amendmentFieldRequests.stream() .filter(Objects::nonNull) // Skip null responses
.map(this::createAmendmentDocumentResponse) .collect(Collectors.toList())
.toList(); );
response.setAmendmentDocuments(amendmentDocumentResponses); response.setAmendmentNotes(amendmentDetails.getAmendmentNotes());
response.setValid(amendmentDetails.getValid()!=null?amendmentDetails.getValid():null);
} }
}
}
response.setAmendmentDocuments(documentResponseBeans);
}
processFormFields(amendmentFormFields, fieldIdToLabelMap, formFieldEntityMap, response); processFormFields(amendmentFormFields, fieldIdToLabelMap, formFieldEntityMap, response);
return response; return response;
} }
public AmendmentDocumentResponse createAmendmentDocumentResponse(AmendmentFieldRequest amendmentFieldRequest) { public DocumentResponseBean createDocumentResponseBean(String documentId) {
AmendmentDocumentResponse amendmentDocumentResponse = new AmendmentDocumentResponse();
amendmentDocumentResponse.setFieldId(amendmentFieldRequest.getFieldId()); if (!StringUtils.isEmpty(documentId)) {
amendmentDocumentResponse.setNameValue(amendmentFieldRequest.getNameValue()); Optional<DocumentEntity> documentEntity = documentRepository.findByIdAndNotDeleted(Long.valueOf(documentId));
amendmentDocumentResponse.setValid(amendmentFieldRequest.getValid()); if(documentEntity.isPresent()){
amendmentDocumentResponse.setFileValue(null); return applicationEvaluationDao.createDocumentResponseBean(documentEntity.get());
if(amendmentFieldRequest.getFileValue()!=null) { }}
DocumentEntity documentEntity = documentService.validateDocument(Long.valueOf(amendmentFieldRequest.getFileValue())); return null;
DocumentResponseBean responseBean = applicationEvaluationDao.createDocumentResponseBean(documentEntity);
amendmentDocumentResponse.setFileValue(List.of(responseBean));
} }
return amendmentDocumentResponse;
}
private ApplicationAmendmentRequestResponse initializeBasicResponse(ApplicationAmendmentRequestEntity entity) { private ApplicationAmendmentRequestResponse initializeBasicResponse(ApplicationAmendmentRequestEntity entity) {
ApplicationAmendmentRequestResponse response = new ApplicationAmendmentRequestResponse(); ApplicationAmendmentRequestResponse response = new ApplicationAmendmentRequestResponse();
@@ -581,7 +624,7 @@ public class ApplicationAmendmentRequestDao {
} }
existingApplicationAmendment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); existingApplicationAmendment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
if(updateRequest.getAmendmentDocuments()!=null && Boolean.FALSE.equals(updateRequest.getAmendmentDocuments().isEmpty())) { if(updateRequest.getAmendmentDocuments()!=null && Boolean.FALSE.equals(updateRequest.getAmendmentDocuments().isEmpty())) {
setAmendmentDocuments(updateRequest.getAmendmentDocuments(), existingApplicationAmendment); setAmendmentDocuments(updateRequest.getAmendmentNotes(),updateRequest.getAmendmentDocuments(), existingApplicationAmendment);
} }
ApplicationAmendmentRequestEntity updatedApplicationAmendment = saveApplicationAmendmentRequestEntity(existingApplicationAmendment,oldApplicationAmendmentEntity,VersionActionTypeEnum.UPDATE); ApplicationAmendmentRequestEntity updatedApplicationAmendment = saveApplicationAmendmentRequestEntity(existingApplicationAmendment,oldApplicationAmendmentEntity,VersionActionTypeEnum.UPDATE);
ApplicationAmendmentRequestResponse response = convertEntityToResponse(updatedApplicationAmendment); ApplicationAmendmentRequestResponse response = convertEntityToResponse(updatedApplicationAmendment);

View File

@@ -157,12 +157,21 @@ public class ApplicationEvaluationDao {
amendmentDocumentResponseBean.setAmendmentId(applicationAmendmentRequestEntity.getId()); amendmentDocumentResponseBean.setAmendmentId(applicationAmendmentRequestEntity.getId());
String amendmentDocument=applicationAmendmentRequestEntity.getAmendmentDocument(); String amendmentDocument=applicationAmendmentRequestEntity.getAmendmentDocument();
String formField=applicationAmendmentRequestEntity.getFormFields(); String formField=applicationAmendmentRequestEntity.getFormFields();
if (Boolean.FALSE.equals(StringUtils.isEmpty(amendmentDocument))) { List<AmendmentDetailsResponseBean> amendmentDetailsList = Utils.convertJsonStringToList(amendmentDocument, AmendmentDetailsResponseBean.class);
List<AmendmentFieldRequest> amendmentFieldRequests=Utils.convertJsonStringToList(amendmentDocument,AmendmentFieldRequest.class); if (amendmentDetailsList != null && !amendmentDetailsList.isEmpty()) {
List<AmendmentDocumentResponse> amendmentDocumentResponses = amendmentFieldRequests.stream() AmendmentDetailsResponseBean amendmentDetails = amendmentDetailsList.get(0);
.map(applicationAmendmentRequestDao::createAmendmentDocumentResponse) if (amendmentDetails.getAmendmentDocuments() != null) {
.toList(); List<DocumentResponseBean> documentResponseBeans = Arrays.stream(amendmentDetails.getAmendmentDocuments().split(","))
amendmentDocumentResponseBean.setAmendmentDocuments(amendmentDocumentResponses); .map(String::trim)
.filter(id -> !id.isEmpty())
.map(documentId -> applicationAmendmentRequestDao.createDocumentResponseBean(documentId))
.filter(Objects::nonNull)
.collect(Collectors.toList());
amendmentDocumentResponseBean.setAmendmentDocuments(documentResponseBeans);
}
amendmentDocumentResponseBean.setAmendmentNotes(amendmentDetails.getAmendmentNotes());
amendmentDocumentResponseBean.setValid(amendmentDetails.getValid());
} }
List<AmendmentFormField> amendmentFormFields=Utils.convertJsonStringToList(formField,AmendmentFormField.class); List<AmendmentFormField> amendmentFormFields=Utils.convertJsonStringToList(formField,AmendmentFormField.class);
amendmentDocumentResponseBean.setFormFieldDocuments(setFormFieldDocuments(amendmentFormFields)); amendmentDocumentResponseBean.setFormFieldDocuments(setFormFieldDocuments(amendmentFormFields));
@@ -657,38 +666,68 @@ public class ApplicationEvaluationDao {
// Process amendment documents if present // Process amendment documents if present
if (applicationAmendmentRequestEntity.getAmendmentDocument() != null) { if (applicationAmendmentRequestEntity.getAmendmentDocument() != null) {
// Parse existing amendment fields from JSON String existingDocumentIds = applicationAmendmentRequestEntity.getAmendmentDocument();
List<AmendmentFieldRequest> existingAmendmentFields =
Utils.convertJsonStringToList(applicationAmendmentRequestEntity.getAmendmentDocument(), AmendmentFieldRequest.class);
// Prepare a new list to hold updated amendment fields // Split comma-separated document IDs into a list
List<AmendmentFieldRequest> updatedAmendmentFields = new ArrayList<>(); List<String> existingDocumentIdList = Arrays.stream(existingDocumentIds.split(","))
.map(String::trim)
.filter(id -> !id.isEmpty())
.collect(Collectors.toList());
// Map amendment details for quick lookup by amendment ID List<String> updatedDocumentIdList = new ArrayList<>();
Map<Long, List<AmendmentFieldRequest>> amendmentDetailsMap = amendmentFormFields.stream() Map<Long, String> amendmentDetailsMap = amendmentFormFields.stream()
.filter(details -> applicationAmendmentRequestEntity.getId().equals(details.getAmendmentId())) .filter(details -> applicationAmendmentRequestEntity.getId().equals(details.getAmendmentId()))
.collect(Collectors.toMap(AmendmentDetailsRequest::getAmendmentId, AmendmentDetailsRequest::getAmendmentDocuments)); .collect(Collectors.toMap(
AmendmentDetailsRequest::getAmendmentId,
AmendmentDetailsRequest::getAmendmentDocuments
));
// Get corresponding amendment documents for the current entity String amendmentDocumentIds = amendmentDetailsMap.get(applicationAmendmentRequestEntity.getId());
List<AmendmentFieldRequest> amendmentDocuments = amendmentDetailsMap.get(applicationAmendmentRequestEntity.getId()); if (amendmentDocumentIds != null) {
if (amendmentDocuments != null) { // Split and validate new document IDs
// Update existing amendment fields with new values List<String> newDocumentIdList = Arrays.stream(amendmentDocumentIds.split(","))
for (AmendmentFieldRequest existingField : existingAmendmentFields) { .map(String::trim)
for (AmendmentFieldRequest newField : amendmentDocuments) { .filter(id -> !id.isEmpty())
if (existingField.getFieldId().equals(newField.getFieldId())) { .collect(Collectors.toList());
// Update fields if there are changes
Utils.setIfUpdated(existingField::getValid, existingField::setValid, newField.getValid());
Utils.setIfUpdated(existingField::getFileValue, existingField::setFileValue, newField.getFileValue());
Utils.setIfUpdated(existingField::getNameValue, existingField::setNameValue, newField.getNameValue());
updatedAmendmentFields.add(existingField); for (String existingId : existingDocumentIdList) {
break; // Move to the next existing field for (String newId : newDocumentIdList) {
if (existingId.equals(newId)) {
Optional<DocumentEntity> documentEntity = documentRepository.findByIdAndNotDeleted(Long.valueOf(newId));
if(documentEntity.isPresent()) {
updatedDocumentIdList.add(newId);
break;
}
} }
} }
} }
// Convert updated fields back to JSON and save to the database // Add any new IDs not in the existing list
applicationAmendmentRequestEntity.setAmendmentDocument(Utils.convertListToJsonString(updatedAmendmentFields)); for (String newId : newDocumentIdList) {
if (!existingDocumentIdList.contains(newId)) {
Optional<DocumentEntity> documentEntity = documentRepository.findByIdAndNotDeleted(Long.valueOf(newId));
if(documentEntity.isPresent()) {
updatedDocumentIdList.add(newId);
}
}
}
String updatedDocumentIds = String.join(",", updatedDocumentIdList);
// Create the AmendmentDetailsResponseBean for structured data
AmendmentDetailsResponseBean amendmentDetails = new AmendmentDetailsResponseBean();
amendmentDetails.setAmendmentDocuments(updatedDocumentIds);
AmendmentDetailsRequest amendmentDetailsRequest = amendmentFormFields.stream()
.filter(details -> applicationAmendmentRequestEntity.getId().equals(details.getAmendmentId()))
.findFirst()
.orElse(null);
if (amendmentDetailsRequest != null) {
amendmentDetails.setValid(amendmentDetailsRequest.getValid());
} else {
amendmentDetails.setValid(false);
}
String amendmentDetailsJson = Utils.convertListToJsonString(Collections.singletonList(amendmentDetails));
applicationAmendmentRequestEntity.setAmendmentDocument(amendmentDetailsJson);
applicationAmendmentRequestRepository.save(applicationAmendmentRequestEntity); applicationAmendmentRequestRepository.save(applicationAmendmentRequestEntity);
} }
} }

View File

@@ -1,8 +1,6 @@
package net.gepafin.tendermanagement.model.request; package net.gepafin.tendermanagement.model.request;
import lombok.Data; import lombok.Data;
import net.gepafin.tendermanagement.model.response.AmendmentDocumentResponse;
import net.gepafin.tendermanagement.model.response.FieldResponse;
import java.util.List; import java.util.List;
@@ -11,7 +9,9 @@ public class AmendmentDetailsRequest {
Long amendmentId; Long amendmentId;
List<AmendmentFieldRequest> amendmentDocuments; String amendmentDocuments;
Boolean valid;
List<AmendmentFormFieldRequest> formFieldDocuments; List<AmendmentFormFieldRequest> formFieldDocuments;
} }

View File

@@ -8,5 +8,6 @@ import lombok.Data;
public class ApplicationAmendmentRequestBean { public class ApplicationAmendmentRequestBean {
private String note; private String note;
private List<AmendmentFormFieldRequest> applicationFormFields; private List<AmendmentFormFieldRequest> applicationFormFields;
private List<AmendmentFieldRequest> amendmentDocuments; private String amendmentDocuments;
private String amendmentNotes;
} }

View File

@@ -0,0 +1,12 @@
package net.gepafin.tendermanagement.model.response;
import lombok.Data;
import java.util.List;
@Data
public class AmendmentDetailsResponseBean {
private String amendmentDocuments;
private String amendmentNotes;
private Boolean valid;
}

View File

@@ -1,14 +0,0 @@
package net.gepafin.tendermanagement.model.response;
import lombok.Data;
import java.util.List;
@Data
public class AmendmentDocumentResponse {
private String fieldId;
private String nameValue;
private List<DocumentResponseBean> fileValue;
private Boolean valid = false;
}

View File

@@ -9,7 +9,11 @@ public class AmendmentDocumentResponseBean {
Long amendmentId; Long amendmentId;
List<AmendmentDocumentResponse> amendmentDocuments; List<DocumentResponseBean> amendmentDocuments;
Boolean valid;
String amendmentNotes;
List<FieldResponse> formFieldDocuments; List<FieldResponse> formFieldDocuments;
} }

View File

@@ -21,7 +21,9 @@ public class ApplicationAmendmentRequestResponse {
private String beneficiaryName; private String beneficiaryName;
private List<AmendmentFormFieldResponse> formFields; private List<AmendmentFormFieldResponse> formFields;
private List<ApplicationFormFieldResponseBean> applicationFormFields; private List<ApplicationFormFieldResponseBean> applicationFormFields;
private List<AmendmentDocumentResponse> amendmentDocuments; private List<DocumentResponseBean> amendmentDocuments;
private String amendmentNotes;
private Boolean valid;
private Long applicationId; private Long applicationId;
private Long applicationEvaluationId; private Long applicationEvaluationId;
private LocalDateTime evaluationEndDate; private LocalDateTime evaluationEndDate;