Updated code for evaluation response

This commit is contained in:
nisha
2024-12-13 11:39:46 +05:30
parent 1747d76d7f
commit eb5075488e
9 changed files with 254 additions and 23 deletions

View File

@@ -1,6 +1,5 @@
package net.gepafin.tendermanagement.dao;
import com.amazonaws.services.dynamodbv2.xspec.L;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -99,6 +98,9 @@ public class ApplicationEvaluationDao {
@Autowired
private DocumentService documentService;
@Autowired
private ApplicationAmendmentRequestDao applicationAmendmentRequestDao;
private ApplicationEvaluationEntity convertToEntity(UserEntity user, ApplicationEvaluationRequest req, Long assignedApplciationId) {
ApplicationEvaluationEntity entity = new ApplicationEvaluationEntity();
@@ -134,6 +136,7 @@ public class ApplicationEvaluationDao {
List<CallTargetAudienceChecklistEntity> checklistEntities = callTargetAudienceChecklistRepository
.findByCallIdAndLookupDataTypeAndIsDeletedFalse(call.getId(), LookUpDataEntity.LookUpDataTypeEnum.CHECKLIST.getValue());
List<ApplicationFormEntity> applicationFormEntities = applicationFormRepository.findByApplicationId(entity.getApplicationId());
setAmendmentDetails(entity,response);
setCriteriaResponses(entity, response, evaluationCriterias);
setChecklistResponses(entity, response, checklistEntities);
@@ -144,6 +147,46 @@ public class ApplicationEvaluationDao {
return response;
}
private void setAmendmentDetails(ApplicationEvaluationEntity entity, ApplicationEvaluationResponse response) {
List<ApplicationAmendmentRequestEntity> amendmentRequests=applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(entity.getId());
List<AmendmentDocumentResponseBean> amendmentDocumentResponseBeans=new ArrayList<>();
for(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity:amendmentRequests){
AmendmentDocumentResponseBean amendmentDocumentResponseBean=new AmendmentDocumentResponseBean();
amendmentDocumentResponseBean.setAmendmentId(applicationAmendmentRequestEntity.getId());
String amendmentDocument=applicationAmendmentRequestEntity.getAmendmentDocument();
String formField=applicationAmendmentRequestEntity.getFormFields();
if (amendmentDocument != null) {
List<AmendmentFieldRequest> amendmentFieldRequests=Utils.convertJsonStringToList(amendmentDocument,AmendmentFieldRequest.class);
List<AmendmentDocumentResponse> amendmentDocumentResponses = amendmentFieldRequests.stream()
.map(applicationAmendmentRequestDao::createAmendmentDocumentResponse)
.toList();
amendmentDocumentResponseBean.setAmendmentDocuments(amendmentDocumentResponses);
}
List<AmendmentFormField> amendmentFormFields=Utils.convertJsonStringToList(formField,AmendmentFormField.class);
amendmentDocumentResponseBean.setFormFieldDocuments(setFormFieldDocuments(amendmentFormFields));
amendmentDocumentResponseBeans.add(amendmentDocumentResponseBean);
}
response.setAmendmentDetails(amendmentDocumentResponseBeans);
}
private List<FieldResponse> setFormFieldDocuments(List<AmendmentFormField> amendmentFormFields) {
List<FieldResponse> fieldResponses=new ArrayList<>();
for (AmendmentFormField amendmentFormField: amendmentFormFields){
FieldResponse fieldResponse=new FieldResponse();
fieldResponse.setId(amendmentFormField.getFieldId());
fieldResponse.setLabel(amendmentFormField.getLabel());
fieldResponse.setValid(amendmentFormField.getIsValid());
List<Long> fileIds=applicationAmendmentRequestDao.extractIds(amendmentFormField.getFieldValue());
List<DocumentResponseBean> documentResponseBeans = fileIds.stream()
.map(fileId -> createDocumentResponseBean(documentService.validateDocument(fileId))) // Create DocumentResponseBean for each fileId
.collect(Collectors.toList()); // Collect all into a List
fieldResponse.setFileDetail(documentResponseBeans);
fieldResponses.add(fieldResponse);
}
return fieldResponses;
}
private void setEvaluationDocResponse(ApplicationEvaluationResponse response, List<EvaluationDocumentRequest> docRequest) {
List<EvaluationDocumentResponse> evaluationDocResponses = new ArrayList<>();
@@ -534,6 +577,15 @@ public class ApplicationEvaluationDao {
actionType = VersionActionTypeEnum.INSERT;
}
ApplicationStatusForEvaluation status = req.getApplicationStatus();
// Fetch all amendment request entities associated with the evaluation ID
List<ApplicationAmendmentRequestEntity> applicationAmendmentRequestEntities =
applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(entity.getId());
// Fetch amendment details from the request
List<AmendmentDetailsRequest> amendmentDetailsRequests = req.getAmendmentDetails();
updateAmendmentDocumentsAndFormFields(applicationAmendmentRequestEntities, amendmentDetailsRequests);
ApplicationEvaluationEntity savedEntity = applicationEvaluationRepository.save(entity);
@@ -549,6 +601,132 @@ public class ApplicationEvaluationDao {
}
}
private void updateAmendmentDocumentsAndFormFields(List<ApplicationAmendmentRequestEntity> applicationAmendmentRequestEntities, List<AmendmentDetailsRequest> amendmentFormFields) {
// 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 amendment details for quick lookup by amendment ID
Map<Long, List<AmendmentFormFieldRequest>> amendmentDetailsMap = amendmentFormFields.stream()
.filter(details -> applicationAmendmentRequestEntity.getId().equals(details.getAmendmentId()))
.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::getIsValid, existingField::setIsValid, newField.getIsValid());
Utils.setIfUpdated(existingField::getFieldValue, existingField::setFieldValue, newField.getFieldValue());
updatedFormFields.add(existingField);
break; // Move to the next existing field
}
}
}
// Convert updated form fields back to JSON and save to the database
applicationAmendmentRequestEntity.setFormFields(Utils.convertListToJsonString(updatedFormFields));
applicationAmendmentRequestRepository.save(applicationAmendmentRequestEntity);
}
}
// Process amendment documents if present
if (applicationAmendmentRequestEntity.getAmendmentDocument() != null) {
// Parse existing amendment fields from JSON
List<AmendmentFieldRequest> existingAmendmentFields =
Utils.convertJsonStringToList(applicationAmendmentRequestEntity.getAmendmentDocument(), AmendmentFieldRequest.class);
// Prepare a new list to hold updated amendment fields
List<AmendmentFieldRequest> updatedAmendmentFields = new ArrayList<>();
// Map amendment details for quick lookup by amendment ID
Map<Long, List<AmendmentFieldRequest>> amendmentDetailsMap = amendmentFormFields.stream()
.filter(details -> applicationAmendmentRequestEntity.getId().equals(details.getAmendmentId()))
.collect(Collectors.toMap(AmendmentDetailsRequest::getAmendmentId, AmendmentDetailsRequest::getAmendmentDocuments));
// Get corresponding amendment documents for the current entity
List<AmendmentFieldRequest> amendmentDocuments = amendmentDetailsMap.get(applicationAmendmentRequestEntity.getId());
if (amendmentDocuments != null) {
// Update existing amendment fields with new values
for (AmendmentFieldRequest existingField : existingAmendmentFields) {
for (AmendmentFieldRequest newField : amendmentDocuments) {
if (existingField.getFieldId().equals(newField.getFieldId())) {
// Update fields if there are changes
Utils.setIfUpdated(existingField::getIsValid, existingField::setIsValid, newField.getIsValid());
Utils.setIfUpdated(existingField::getFileValue, existingField::setFileValue, newField.getFileValue());
Utils.setIfUpdated(existingField::getNameValue, existingField::setNameValue, newField.getNameValue());
updatedAmendmentFields.add(existingField);
break; // Move to the next existing field
}
}
}
// Convert updated fields back to JSON and save to the database
applicationAmendmentRequestEntity.setAmendmentDocument(Utils.convertListToJsonString(updatedAmendmentFields));
applicationAmendmentRequestRepository.save(applicationAmendmentRequestEntity);
}
}
}
}
// private void updateAmendmentDocuments(List<ApplicationAmendmentRequestEntity> applicationAmendmentRequestEntities, List<AmendmentDetailsRequest> amendmentFormFields) {
// for (ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity : applicationAmendmentRequestEntities) {
// // Skip if there are no amendment documents
// if (applicationAmendmentRequestEntity.getAmendmentDocument() == null) {
// continue;
// }
//
// // Parse existing amendment fields from JSON
// List<AmendmentFieldRequest> existingAmendmentFields =
// Utils.convertJsonStringToList(applicationAmendmentRequestEntity.getAmendmentDocument(), AmendmentFieldRequest.class);
//
// // Prepare a new list to hold updated amendment fields
// List<AmendmentFieldRequest> updatedAmendmentFields = new ArrayList<>();
//
// // Map amendment details for quick lookup by amendment ID
// Map<Long, List<AmendmentFieldRequest>> amendmentDetailsMap = amendmentFormFields.stream()
// .filter(details -> applicationAmendmentRequestEntity.getId().equals(details.getAmendmentId()))
// .collect(Collectors.toMap(AmendmentDetailsRequest::getAmendmentId, AmendmentDetailsRequest::getAmendmentDocuments));
//
// // Get corresponding amendment documents for the current entity
// List<AmendmentFieldRequest> amendmentDocuments = amendmentDetailsMap.get(applicationAmendmentRequestEntity.getId());
// if (amendmentDocuments == null) {
// continue;
// }
//
// // Update existing amendment fields with new values
// for (AmendmentFieldRequest existingField : existingAmendmentFields) {
// for (AmendmentFieldRequest newField : amendmentDocuments) {
// if (existingField.getFieldId().equals(newField.getFieldId())) {
// // Update fields if there are changes
// Utils.setIfUpdated(existingField::getIsValid, existingField::setIsValid, newField.getIsValid());
// Utils.setIfUpdated(existingField::getFileValue, existingField::setFileValue, newField.getFileValue());
// Utils.setIfUpdated(existingField::getNameValue, existingField::setNameValue, newField.getNameValue());
//
// updatedAmendmentFields.add(existingField);
// break; // Move to the next existing field
// }
// }
// }
//
// // Convert updated fields back to JSON and save to the database
// applicationAmendmentRequestEntity.setAmendmentDocument(Utils.convertListToJsonString(updatedAmendmentFields));
// applicationAmendmentRequestRepository.save(applicationAmendmentRequestEntity);
// }
// }
private List<CriteriaRequest> processCriteria(ApplicationEvaluationEntity entity, ApplicationEvaluationRequest req) {
List<CriteriaRequest> incomingCriteriaList = Optional.ofNullable(req.getCriteria()).orElse(new ArrayList<>());
@@ -1483,6 +1661,10 @@ public class ApplicationEvaluationDao {
ApplicationEvaluationEntity oldApplicationEvaluation = Utils.getClonedEntityForData(existingEntity);
AssignedApplicationsEntity oldAssignedApplication = Utils.getClonedEntityForData(assignedApplicationsEntity);
List<ApplicationAmendmentRequestEntity> amendmentRequest = applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndStatusAndIsDeletedFalse(existingEntity.getId(),ApplicationAmendmentRequestEnum.AWAITING.getValue());
if(amendmentRequest !=null && Boolean.FALSE.equals(amendmentRequest.isEmpty())){
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_CANNOT_APPROVED_OR_REJECTED));
}
String statusType = application.getStatus();
if (application.getStatus().equals(ApplicationStatusTypeEnum.APPROVED.getValue()) || application.getStatus().equals(ApplicationStatusTypeEnum.REJECTED.getValue())) {
existingEntity.setStatus(ApplicationEvaluationStatusTypeEnum.CLOSE.getValue());
@@ -1501,11 +1683,6 @@ public class ApplicationEvaluationDao {
}
List<ApplicationAmendmentRequestEntity> amendmentRequest = applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndStatusAndIsDeletedFalse(existingEntity.getId(),ApplicationAmendmentRequestEnum.AWAITING.getValue());
if(amendmentRequest !=null && Boolean.FALSE.equals(amendmentRequest.isEmpty())){
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_CANNOT_APPROVED_OR_REJECTED));
}
if (Boolean.TRUE.equals(statusType.equals((ApplicationStatusTypeEnum.APPROVED.getValue())))) {
emailNotificationDao.sendAdmissibilityNotificationEmailForApprovedApplication(application);
}