Merge pull request #135 from Kitzanos/update-evaluation-amendment-changes
Changes in application evaluation for amendment details
This commit is contained in:
@@ -349,7 +349,7 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
amendmentDetails.setAmendmentNotes(amendmentNotes.trim());
|
amendmentDetails.setAmendmentNotes(amendmentNotes.trim());
|
||||||
}
|
}
|
||||||
amendmentDetails.setValid(null);
|
amendmentDetails.setValid(null);
|
||||||
String amendmentDetailsJson = Utils.convertListToJsonString(Collections.singletonList(amendmentDetails));
|
String amendmentDetailsJson = Utils.convertObjectToString(amendmentDetails);
|
||||||
applicationAmendmentRequestEntity.setAmendmentDocument(amendmentDetailsJson);
|
applicationAmendmentRequestEntity.setAmendmentDocument(amendmentDetailsJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,12 +373,13 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
Map<String, ApplicationFormFieldEntity> formFieldEntityMap = getApplicationFormFieldEntityMap(applicationAmendmentRequestEntity, amendmentFormFields);
|
Map<String, ApplicationFormFieldEntity> formFieldEntityMap = getApplicationFormFieldEntityMap(applicationAmendmentRequestEntity, amendmentFormFields);
|
||||||
if (applicationAmendmentRequestEntity.getAmendmentDocument() != null) {
|
if (applicationAmendmentRequestEntity.getAmendmentDocument() != null) {
|
||||||
|
|
||||||
List<AmendmentDetailsResponseBean> amendmentDetailsList =
|
// List<AmendmentDetailsResponseBean> amendmentDetailsList =
|
||||||
Utils.convertJsonStringToList(applicationAmendmentRequestEntity.getAmendmentDocument(),
|
// Utils.convertJsonStringToList(applicationAmendmentRequestEntity.getAmendmentDocument(),
|
||||||
AmendmentDetailsResponseBean.class);
|
// AmendmentDetailsResponseBean.class);
|
||||||
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
AmendmentDetailsResponseBean amendmentDetails = Utils.convertStringToObject(applicationAmendmentRequestEntity.getAmendmentDocument() ,AmendmentDetailsResponseBean.class);
|
||||||
for (AmendmentDetailsResponseBean amendmentDetails:amendmentDetailsList) {
|
if(amendmentDetails!=null) {
|
||||||
if (amendmentDetails.getAmendmentDocuments()!=null) {
|
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
||||||
|
if (amendmentDetails.getAmendmentDocuments() != null) {
|
||||||
// Extract the comma-separated document IDs as a string
|
// Extract the comma-separated document IDs as a string
|
||||||
String documentIdsString = amendmentDetails.getAmendmentDocuments();
|
String documentIdsString = amendmentDetails.getAmendmentDocuments();
|
||||||
|
|
||||||
@@ -403,13 +404,12 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
.collect(Collectors.toList())
|
.collect(Collectors.toList())
|
||||||
);
|
);
|
||||||
response.setAmendmentNotes(amendmentDetails.getAmendmentNotes());
|
response.setAmendmentNotes(amendmentDetails.getAmendmentNotes());
|
||||||
response.setValid(amendmentDetails.getValid()!=null?amendmentDetails.getValid():null);
|
response.setValid(amendmentDetails.getValid());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
response.setAmendmentDocuments(documentResponseBeans);
|
||||||
}
|
}
|
||||||
|
|
||||||
response.setAmendmentDocuments(documentResponseBeans);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,9 +22,11 @@ import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
|||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
||||||
@@ -157,9 +159,8 @@ 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();
|
||||||
List<AmendmentDetailsResponseBean> amendmentDetailsList = Utils.convertJsonStringToList(amendmentDocument, AmendmentDetailsResponseBean.class);
|
AmendmentDetailsResponseBean amendmentDetails = Utils.convertStringToObject(amendmentDocument, AmendmentDetailsResponseBean.class);
|
||||||
if (amendmentDetailsList != null && !amendmentDetailsList.isEmpty()) {
|
if (amendmentDetails != null) {
|
||||||
AmendmentDetailsResponseBean amendmentDetails = amendmentDetailsList.get(0);
|
|
||||||
if (amendmentDetails.getAmendmentDocuments() != null) {
|
if (amendmentDetails.getAmendmentDocuments() != null) {
|
||||||
List<DocumentResponseBean> documentResponseBeans = Arrays.stream(amendmentDetails.getAmendmentDocuments().split(","))
|
List<DocumentResponseBean> documentResponseBeans = Arrays.stream(amendmentDetails.getAmendmentDocuments().split(","))
|
||||||
.map(String::trim)
|
.map(String::trim)
|
||||||
@@ -168,33 +169,39 @@ public class ApplicationEvaluationDao {
|
|||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
amendmentDocumentResponseBean.setAmendmentDocuments(documentResponseBeans);
|
amendmentDocumentResponseBean.setFileDetail(documentResponseBeans);
|
||||||
}
|
}
|
||||||
amendmentDocumentResponseBean.setAmendmentNotes(amendmentDetails.getAmendmentNotes());
|
amendmentDocumentResponseBean.setLabel(amendmentDetails.getAmendmentNotes());
|
||||||
amendmentDocumentResponseBean.setValid(amendmentDetails.getValid());
|
amendmentDocumentResponseBean.setValid(amendmentDetails.getValid());
|
||||||
}
|
}
|
||||||
List<AmendmentFormField> amendmentFormFields=Utils.convertJsonStringToList(formField,AmendmentFormField.class);
|
List<AmendmentFormField> amendmentFormFields = Utils.convertJsonStringToList(formField, AmendmentFormField.class);
|
||||||
amendmentDocumentResponseBean.setFormFieldDocuments(setFormFieldDocuments(amendmentFormFields));
|
if (amendmentFormFields != null) {
|
||||||
amendmentDocumentResponseBeans.add(amendmentDocumentResponseBean);
|
for (AmendmentFormField amendmentFormField : amendmentFormFields) {
|
||||||
}
|
// Skip fields with null or empty fieldValue
|
||||||
response.setAmendmentDetails(amendmentDocumentResponseBeans);
|
if (StringUtils.isEmpty(amendmentFormField.getFieldValue())) {
|
||||||
}
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
private List<FieldResponse> setFormFieldDocuments(List<AmendmentFormField> amendmentFormFields) {
|
AmendmentDocumentResponseBean formFieldResponseBean = new AmendmentDocumentResponseBean();
|
||||||
List<FieldResponse> fieldResponses=new ArrayList<>();
|
formFieldResponseBean.setAmendmentId(applicationAmendmentRequestEntity.getId());
|
||||||
for (AmendmentFormField amendmentFormField: amendmentFormFields){
|
formFieldResponseBean.setFieldId(amendmentFormField.getFieldId());
|
||||||
FieldResponse fieldResponse=new FieldResponse();
|
formFieldResponseBean.setLabel(amendmentFormField.getLabel());
|
||||||
fieldResponse.setId(amendmentFormField.getFieldId());
|
formFieldResponseBean.setValid(amendmentFormField.getValid());
|
||||||
fieldResponse.setLabel(amendmentFormField.getLabel());
|
|
||||||
fieldResponse.setValid(amendmentFormField.getValid());
|
List<Long> fileIds = applicationAmendmentRequestDao.extractIds(amendmentFormField.getFieldValue());
|
||||||
List<Long> fileIds=applicationAmendmentRequestDao.extractIds(amendmentFormField.getFieldValue());
|
List<DocumentResponseBean> documentResponseBeans = fileIds.stream()
|
||||||
List<DocumentResponseBean> documentResponseBeans = fileIds.stream()
|
.map(fileId -> createDocumentResponseBean(documentService.validateDocument(fileId)))
|
||||||
.map(fileId -> createDocumentResponseBean(documentService.validateDocument(fileId))) // Create DocumentResponseBean for each fileId
|
.collect(Collectors.toList());
|
||||||
.collect(Collectors.toList()); // Collect all into a List
|
|
||||||
fieldResponse.setFileDetail(documentResponseBeans);
|
formFieldResponseBean.setFileDetail(documentResponseBeans);
|
||||||
fieldResponses.add(fieldResponse);
|
amendmentDocumentResponseBeans.add(formFieldResponseBean);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
amendmentDocumentResponseBeans.add(amendmentDocumentResponseBean);
|
||||||
}
|
}
|
||||||
return fieldResponses;
|
|
||||||
|
response.setAmendmentDetails(amendmentDocumentResponseBeans);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setEvaluationDocResponse(ApplicationEvaluationResponse response, List<EvaluationDocumentRequest> docRequest) {
|
private void setEvaluationDocResponse(ApplicationEvaluationResponse response, List<EvaluationDocumentRequest> docRequest) {
|
||||||
@@ -623,117 +630,162 @@ public class ApplicationEvaluationDao {
|
|||||||
|
|
||||||
private void updateAmendmentDocumentsAndFormFields(List<ApplicationAmendmentRequestEntity> applicationAmendmentRequestEntities, List<AmendmentDetailsRequest> amendmentFormFields) {
|
private void updateAmendmentDocumentsAndFormFields(List<ApplicationAmendmentRequestEntity> applicationAmendmentRequestEntities, List<AmendmentDetailsRequest> amendmentFormFields) {
|
||||||
// Iterate through amendment request entities
|
// Iterate through amendment request entities
|
||||||
for (ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity : applicationAmendmentRequestEntities) {
|
|
||||||
// Process form fields if present
|
|
||||||
if (applicationAmendmentRequestEntity.getFormFields() != null) {
|
|
||||||
// Parse existing form fields from JSON
|
|
||||||
List<AmendmentFormFieldRequest> existingFormFields =
|
|
||||||
Utils.convertJsonStringToList(applicationAmendmentRequestEntity.getFormFields(), AmendmentFormFieldRequest.class);
|
|
||||||
|
|
||||||
// Prepare a new list to hold updated form fields
|
//
|
||||||
List<AmendmentFormFieldRequest> updatedFormFields = new ArrayList<>();
|
Map<Long,List<AmendmentDetailsRequest>> amendmentFormFieldsMap = amendmentFormFields.stream().collect(Collectors.groupingBy(AmendmentDetailsRequest::getAmendmentId,HashMap::new,Collectors.toCollection(ArrayList::new)));
|
||||||
|
// amendmentFormFields.forEach(data->{
|
||||||
|
// ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = applicationAmendmentRequestMap.get(data.getAmendmentId());
|
||||||
|
// if (data.getFieldId().contains("amend_")){
|
||||||
|
// updateAmendmentDocument(applicationAmendmentRequestEntity, data);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
applicationAmendmentRequestEntities.forEach(applicationAmendmentRequestEntity->{
|
||||||
|
updateAmendment(applicationAmendmentRequestEntity, amendmentFormFieldsMap.get(applicationAmendmentRequestEntity.getId()));
|
||||||
|
});
|
||||||
|
applicationAmendmentRequestRepository.saveAll(applicationAmendmentRequestEntities);
|
||||||
|
|
||||||
// Map amendment details for quick lookup by amendment ID
|
|
||||||
Map<Long, List<AmendmentFormFieldRequest>> amendmentDetailsMap = amendmentFormFields.stream()
|
|
||||||
.filter(details -> applicationAmendmentRequestEntity.getId().equals(details.getAmendmentId()))
|
|
||||||
.filter(details -> details.getFormFieldDocuments() != null) // Null check for getFormFieldDocuments
|
|
||||||
.collect(Collectors.toMap(
|
|
||||||
AmendmentDetailsRequest::getAmendmentId,
|
|
||||||
AmendmentDetailsRequest::getFormFieldDocuments
|
|
||||||
));
|
|
||||||
// Get corresponding amendment documents for the current entity
|
|
||||||
List<AmendmentFormFieldRequest> amendmentDocuments = amendmentDetailsMap.get(applicationAmendmentRequestEntity.getId());
|
|
||||||
if (amendmentDocuments != null) {
|
|
||||||
// Update existing form fields with new values
|
|
||||||
for (AmendmentFormFieldRequest existingField : existingFormFields) {
|
|
||||||
for (AmendmentFormFieldRequest newField : amendmentDocuments) {
|
|
||||||
if (existingField.getFieldId().equals(newField.getFieldId())) {
|
|
||||||
// Update fields if there are changes
|
|
||||||
Utils.setIfUpdated(existingField::getValid, existingField::setValid, newField.getValid());
|
|
||||||
Utils.setIfUpdated(existingField::getFieldValue, existingField::setFieldValue, newField.getFieldValue());
|
|
||||||
|
|
||||||
updatedFormFields.add(existingField);
|
// for (ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity : applicationAmendmentRequestEntities) {
|
||||||
break; // Move to the next existing field
|
// // Process form fields if present
|
||||||
}
|
// if (applicationAmendmentRequestEntity.getFormFields() != null) {
|
||||||
}
|
// // Parse existing form fields from JSON
|
||||||
}
|
// List<AmendmentFormFieldRequest> existingFormFields =
|
||||||
|
// Utils.convertJsonStringToList(applicationAmendmentRequestEntity.getFormFields(), AmendmentFormFieldRequest.class);
|
||||||
// Convert updated form fields back to JSON and save to the database
|
//
|
||||||
applicationAmendmentRequestEntity.setFormFields(Utils.convertListToJsonString(updatedFormFields));
|
// // Prepare a new list to hold updated form fields
|
||||||
applicationAmendmentRequestRepository.save(applicationAmendmentRequestEntity);
|
// List<AmendmentFormFieldRequest> updatedFormFields = new ArrayList<>();
|
||||||
}
|
//
|
||||||
}
|
// // Map amendment details for quick lookup by amendment ID
|
||||||
|
// Map<Long, Object> amendmentDetailsMap = amendmentFormFields.stream()
|
||||||
// Process amendment documents if present
|
// .filter(details -> applicationAmendmentRequestEntity.getId().equals(details.getAmendmentId()))
|
||||||
if (applicationAmendmentRequestEntity.getAmendmentDocument() != null) {
|
// .filter(details -> details.getFieldValue() != null) // Null check for getFormFieldDocuments
|
||||||
String existingDocumentIds = applicationAmendmentRequestEntity.getAmendmentDocument();
|
// .collect(Collectors.toMap(
|
||||||
|
// AmendmentDetailsRequest::getAmendmentId,
|
||||||
// Split comma-separated document IDs into a list
|
// AmendmentDetailsRequest::getFieldValue
|
||||||
List<String> existingDocumentIdList = Arrays.stream(existingDocumentIds.split(","))
|
// ));
|
||||||
.map(String::trim)
|
// // Get corresponding amendment documents for the current entity
|
||||||
.filter(id -> !id.isEmpty())
|
// List<AmendmentFormFieldRequest> amendmentDocuments = (List<AmendmentFormFieldRequest>) amendmentDetailsMap.get(applicationAmendmentRequestEntity.getId());
|
||||||
.collect(Collectors.toList());
|
// if (amendmentDocuments != null) {
|
||||||
|
// // Update existing form fields with new values
|
||||||
List<String> updatedDocumentIdList = new ArrayList<>();
|
// for (AmendmentFormFieldRequest existingField : existingFormFields) {
|
||||||
Map<Long, String> amendmentDetailsMap = amendmentFormFields.stream()
|
// for (AmendmentFormFieldRequest newField : amendmentDocuments) {
|
||||||
.filter(details -> applicationAmendmentRequestEntity.getId().equals(details.getAmendmentId()))
|
// if (existingField.getFieldId().equals(newField.getFieldId())) {
|
||||||
.collect(Collectors.toMap(
|
// // Update fields if there are changes
|
||||||
AmendmentDetailsRequest::getAmendmentId,
|
// Utils.setIfUpdated(existingField::getValid, existingField::setValid, newField.getValid());
|
||||||
AmendmentDetailsRequest::getAmendmentDocuments
|
// Utils.setIfUpdated(existingField::getFieldValue, existingField::setFieldValue, newField.getFieldValue());
|
||||||
));
|
//
|
||||||
|
// updatedFormFields.add(existingField);
|
||||||
String amendmentDocumentIds = amendmentDetailsMap.get(applicationAmendmentRequestEntity.getId());
|
// break; // Move to the next existing field
|
||||||
if (amendmentDocumentIds != null) {
|
// }
|
||||||
// Split and validate new document IDs
|
// }
|
||||||
List<String> newDocumentIdList = Arrays.stream(amendmentDocumentIds.split(","))
|
// }
|
||||||
.map(String::trim)
|
//
|
||||||
.filter(id -> !id.isEmpty())
|
// // Convert updated form fields back to JSON and save to the database
|
||||||
.collect(Collectors.toList());
|
// applicationAmendmentRequestEntity.setFormFields(Utils.convertListToJsonString(updatedFormFields));
|
||||||
|
// applicationAmendmentRequestRepository.save(applicationAmendmentRequestEntity);
|
||||||
for (String existingId : existingDocumentIdList) {
|
// }
|
||||||
for (String newId : newDocumentIdList) {
|
// }
|
||||||
if (existingId.equals(newId)) {
|
//
|
||||||
Optional<DocumentEntity> documentEntity = documentRepository.findByIdAndNotDeleted(Long.valueOf(newId));
|
// // Process amendment documents if present
|
||||||
if(documentEntity.isPresent()) {
|
// if (applicationAmendmentRequestEntity.getAmendmentDocument() != null) {
|
||||||
updatedDocumentIdList.add(newId);
|
// String existingDocumentIds = applicationAmendmentRequestEntity.getAmendmentDocument();
|
||||||
break;
|
//
|
||||||
}
|
// // Split comma-separated document IDs into a list
|
||||||
}
|
// List<String> existingDocumentIdList = Arrays.stream(existingDocumentIds.split(","))
|
||||||
}
|
// .map(String::trim)
|
||||||
}
|
// .filter(id -> !id.isEmpty())
|
||||||
|
// .collect(Collectors.toList());
|
||||||
// Add any new IDs not in the existing list
|
//
|
||||||
for (String newId : newDocumentIdList) {
|
// List<String> updatedDocumentIdList = new ArrayList<>();
|
||||||
if (!existingDocumentIdList.contains(newId)) {
|
// Map<Long, Object> amendmentDetailsMap = amendmentFormFields.stream()
|
||||||
Optional<DocumentEntity> documentEntity = documentRepository.findByIdAndNotDeleted(Long.valueOf(newId));
|
// .filter(details -> applicationAmendmentRequestEntity.getId().equals(details.getAmendmentId()))
|
||||||
if(documentEntity.isPresent()) {
|
// .collect(Collectors.toMap(
|
||||||
updatedDocumentIdList.add(newId);
|
// AmendmentDetailsRequest::getAmendmentId,
|
||||||
}
|
// AmendmentDetailsRequest::getFieldValue
|
||||||
}
|
// ));
|
||||||
}
|
//
|
||||||
String updatedDocumentIds = String.join(",", updatedDocumentIdList);
|
// String amendmentDocumentIds = (String) amendmentDetailsMap.get(applicationAmendmentRequestEntity.getId());
|
||||||
|
// if (amendmentDocumentIds != null) {
|
||||||
// Create the AmendmentDetailsResponseBean for structured data
|
// // Split and validate new document IDs
|
||||||
AmendmentDetailsResponseBean amendmentDetails = new AmendmentDetailsResponseBean();
|
// List<String> newDocumentIdList = Arrays.stream(amendmentDocumentIds.split(","))
|
||||||
amendmentDetails.setAmendmentDocuments(updatedDocumentIds);
|
// .map(String::trim)
|
||||||
AmendmentDetailsRequest amendmentDetailsRequest = amendmentFormFields.stream()
|
// .filter(id -> !id.isEmpty())
|
||||||
.filter(details -> applicationAmendmentRequestEntity.getId().equals(details.getAmendmentId()))
|
// .collect(Collectors.toList());
|
||||||
.findFirst()
|
//
|
||||||
.orElse(null);
|
// for (String existingId : existingDocumentIdList) {
|
||||||
|
// for (String newId : newDocumentIdList) {
|
||||||
if (amendmentDetailsRequest != null) {
|
// if (existingId.equals(newId)) {
|
||||||
amendmentDetails.setValid(amendmentDetailsRequest.getValid());
|
// Optional<DocumentEntity> documentEntity = documentRepository.findByIdAndNotDeleted(Long.valueOf(newId));
|
||||||
} else {
|
// if(documentEntity.isPresent()) {
|
||||||
amendmentDetails.setValid(false);
|
// updatedDocumentIdList.add(newId);
|
||||||
}
|
// break;
|
||||||
String amendmentDetailsJson = Utils.convertListToJsonString(Collections.singletonList(amendmentDetails));
|
// }
|
||||||
applicationAmendmentRequestEntity.setAmendmentDocument(amendmentDetailsJson);
|
// }
|
||||||
applicationAmendmentRequestRepository.save(applicationAmendmentRequestEntity);
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//
|
||||||
}
|
// // Add any new IDs not in the existing list
|
||||||
|
// 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);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateAmendment(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity, List<AmendmentDetailsRequest> amendmentDetailsRequestList) {
|
||||||
|
if (CollectionUtils.isEmpty(amendmentDetailsRequestList)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Map<String, AmendmentFormField> formFieldsMap = null;
|
||||||
|
List<AmendmentFormField> formFieldList = Utils.convertJsonStringToList(applicationAmendmentRequestEntity.getFormFields(), AmendmentFormField.class);
|
||||||
|
if(Boolean.FALSE.equals(CollectionUtils.isEmpty(formFieldList))){
|
||||||
|
formFieldsMap = formFieldList.stream().collect(Collectors.toMap(AmendmentFormField::getFieldId, Function.identity()));
|
||||||
|
}
|
||||||
|
updateAmendmentData(applicationAmendmentRequestEntity, amendmentDetailsRequestList, formFieldsMap);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void updateAmendmentData(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity, List<AmendmentDetailsRequest> amendmentDetailsRequestList, Map<String, AmendmentFormField> formFieldsMap) {
|
||||||
|
amendmentDetailsRequestList.forEach(amendmentDetailsRequest -> {
|
||||||
|
if (amendmentDetailsRequest.getFieldId().contains("amend_")) {
|
||||||
|
AmendmentDetailsResponseBean amendmentDetails = Utils.convertStringToObject(applicationAmendmentRequestEntity.getAmendmentDocument(), AmendmentDetailsResponseBean.class);
|
||||||
|
if(amendmentDetails!=null) {
|
||||||
|
amendmentDetails.setValid(amendmentDetailsRequest.getValid());
|
||||||
|
applicationAmendmentRequestEntity.setAmendmentDocument(Utils.convertObjectToString(amendmentDetails));
|
||||||
|
}
|
||||||
|
} else if(Boolean.FALSE.equals(CollectionUtils.isEmpty(formFieldsMap))){
|
||||||
|
AmendmentFormField amendmentFormField = formFieldsMap.get(amendmentDetailsRequest.getFieldId());
|
||||||
|
amendmentFormField.setValid(amendmentDetailsRequest.getValid());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
applicationAmendmentRequestEntity.setFormFields(Utils.convertListToJsonString(formFieldsMap.values().stream().toList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// private void updateAmendmentDocuments(List<ApplicationAmendmentRequestEntity> applicationAmendmentRequestEntities, List<AmendmentDetailsRequest> amendmentFormFields) {
|
// private void updateAmendmentDocuments(List<ApplicationAmendmentRequestEntity> applicationAmendmentRequestEntities, List<AmendmentDetailsRequest> amendmentFormFields) {
|
||||||
// for (ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity : applicationAmendmentRequestEntities) {
|
// for (ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity : applicationAmendmentRequestEntities) {
|
||||||
// // Skip if there are no amendment documents
|
// // Skip if there are no amendment documents
|
||||||
@@ -1066,7 +1118,7 @@ public class ApplicationEvaluationDao {
|
|||||||
if (!mappedFieldMap.containsKey(formFieldId)) {
|
if (!mappedFieldMap.containsKey(formFieldId)) {
|
||||||
// CriteriaMappedField mappedField = new CriteriaMappedField();
|
// CriteriaMappedField mappedField = new CriteriaMappedField();
|
||||||
CriteriaMappedField mappedField = populateMappedField(formFieldId, criteriaFormField, applicationForm, applicationId);
|
CriteriaMappedField mappedField = populateMappedField(formFieldId, criteriaFormField, applicationForm, applicationId);
|
||||||
if(mappedField != null) {
|
if(mappedField != null) {
|
||||||
mappedFieldMap.put(formFieldId, mappedField);
|
mappedFieldMap.put(formFieldId, mappedField);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,9 @@ import java.util.List;
|
|||||||
@Data
|
@Data
|
||||||
public class AmendmentDetailsRequest {
|
public class AmendmentDetailsRequest {
|
||||||
|
|
||||||
Long amendmentId;
|
private String fieldId;
|
||||||
|
|
||||||
String amendmentDocuments;
|
private Long amendmentId;
|
||||||
|
|
||||||
Boolean valid;
|
private Boolean valid;
|
||||||
|
|
||||||
List<AmendmentFormFieldRequest> formFieldDocuments;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
package net.gepafin.tendermanagement.model.request;
|
package net.gepafin.tendermanagement.model.request;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
public class AmendmentFormFieldRequest {
|
public class AmendmentFormFieldRequest {
|
||||||
|
|
||||||
private String fieldId;
|
private String fieldId;
|
||||||
|
|||||||
@@ -7,13 +7,9 @@ import java.util.List;
|
|||||||
@Data
|
@Data
|
||||||
public class AmendmentDocumentResponseBean {
|
public class AmendmentDocumentResponseBean {
|
||||||
|
|
||||||
Long amendmentId;
|
private Long amendmentId;
|
||||||
|
private String fieldId;
|
||||||
List<DocumentResponseBean> amendmentDocuments;
|
private String label;
|
||||||
|
private Boolean valid;
|
||||||
Boolean valid;
|
private List<DocumentResponseBean> fileDetail ;
|
||||||
|
|
||||||
String amendmentNotes;
|
|
||||||
|
|
||||||
List<FieldResponse> formFieldDocuments;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -669,4 +669,26 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Method to convert a JSON string to an object of type T
|
||||||
|
public static <T> T convertStringToObject(String jsonString, Class<T> clazz) {
|
||||||
|
try {
|
||||||
|
return mapper.readValue(jsonString, clazz);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
// Handle the exception appropriately (e.g., throw a custom exception)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method to convert an object of type T to a JSON string
|
||||||
|
public static <T> String convertObjectToString(T object) {
|
||||||
|
try {
|
||||||
|
return mapper.writeValueAsString(object);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
// Handle the exception appropriately (e.g., throw a custom exception)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user