Resolved Conflicts.

This commit is contained in:
piyushkag
2024-12-24 18:46:28 +05:30
60 changed files with 1181 additions and 252 deletions

View File

@@ -2,7 +2,6 @@ package net.gepafin.tendermanagement.dao;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.config.Translator;
@@ -16,18 +15,21 @@ import net.gepafin.tendermanagement.service.*;
import net.gepafin.tendermanagement.util.DateTimeUtil;
import net.gepafin.tendermanagement.util.LoggingUtil;
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;
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
import static org.apache.commons.lang3.StringUtils.isNumeric;
@Component
public class ApplicationEvaluationDao {
@@ -99,6 +101,15 @@ public class ApplicationEvaluationDao {
@Autowired
private UserRepository userRepository;
@Autowired
private Validator validator;
@Autowired
private DocumentService documentService;
@Autowired
private ApplicationAmendmentRequestDao applicationAmendmentRequestDao;
private ApplicationEvaluationEntity convertToEntity(UserEntity user, ApplicationEvaluationRequest req, Long assignedApplciationId) {
ApplicationEvaluationEntity entity = new ApplicationEvaluationEntity();
@@ -134,16 +145,103 @@ 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);
setFieldResponses(entity, response, applicationFormEntities);
List<EvaluationDocumentRequest> allDocs = prepareEvaluationDocumentBeanList(entity);
setEvaluationDocResponse(response, allDocs);
setApplicationDetails(response, entity);
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();
AmendmentDetailsResponseBean amendmentDetails = Utils.convertStringToObject(amendmentDocument, AmendmentDetailsResponseBean.class);
if (amendmentDetails != null) {
if (amendmentDetails.getAmendmentDocuments() != null) {
List<DocumentResponseBean> documentResponseBeans = Arrays.stream(amendmentDetails.getAmendmentDocuments().split(","))
.map(String::trim)
.filter(id -> !id.isEmpty())
.map(documentId -> applicationAmendmentRequestDao.createDocumentResponseBean(documentId))
.filter(Objects::nonNull)
.collect(Collectors.toList());
amendmentDocumentResponseBean.setFileDetail(documentResponseBeans);
}
amendmentDocumentResponseBean.setFieldId("amend_" + applicationAmendmentRequestEntity.getId());
amendmentDocumentResponseBean.setLabel(amendmentDetails.getAmendmentNotes());
amendmentDocumentResponseBean.setValid(amendmentDetails.getValid());
amendmentDocumentResponseBeans.add(amendmentDocumentResponseBean);
}
List<AmendmentFormField> amendmentFormFields = Utils.convertJsonStringToList(formField, AmendmentFormField.class);
if (amendmentFormFields != null) {
for (AmendmentFormField amendmentFormField : amendmentFormFields) {
// Skip fields with null or empty fieldValue
if (StringUtils.isEmpty(amendmentFormField.getFieldValue())) {
continue;
}
AmendmentDocumentResponseBean formFieldResponseBean = new AmendmentDocumentResponseBean();
formFieldResponseBean.setAmendmentId(applicationAmendmentRequestEntity.getId());
formFieldResponseBean.setFieldId(amendmentFormField.getFieldId());
formFieldResponseBean.setLabel(amendmentFormField.getLabel());
formFieldResponseBean.setValid(amendmentFormField.getValid());
List<Long> fileIds = applicationAmendmentRequestDao.extractIds(amendmentFormField.getFieldValue());
List<DocumentResponseBean> documentResponseBeans = fileIds.stream()
.map(fileId -> createDocumentResponseBean(documentService.validateDocument(fileId)))
.collect(Collectors.toList());
formFieldResponseBean.setFileDetail(documentResponseBeans);
amendmentDocumentResponseBeans.add(formFieldResponseBean);
}
}
}
response.setAmendmentDetails(amendmentDocumentResponseBeans);
}
private void setEvaluationDocResponse(ApplicationEvaluationResponse response, List<EvaluationDocumentRequest> docRequest) {
List<EvaluationDocumentResponse> evaluationDocResponses = new ArrayList<>();
for (EvaluationDocumentRequest doc : docRequest) {
EvaluationDocumentResponse evaluationDocResponse = new EvaluationDocumentResponse();
if (doc.getFileValue() != null) {
Long fileId = Long.valueOf(doc.getFileValue().toString());
documentRepository.findByIdAndNotDeleted(fileId).ifPresent(documentEntity -> {
DocumentResponseBean documentResponseBean = new DocumentResponseBean();
documentResponseBean.setId(documentEntity.getId());
documentResponseBean.setName(documentEntity.getFileName());
documentResponseBean.setType(DocumentTypeEnum.valueOf(documentEntity.getType()));
documentResponseBean.setSource(DocumentSourceTypeEnum.valueOf(documentEntity.getSource()));
documentResponseBean.setSourceId(documentEntity.getSourceId());
documentResponseBean.setFilePath(documentEntity.getFilePath());
documentResponseBean.setCreatedDate(documentEntity.getCreatedDate());
documentResponseBean.setUpdatedDate(documentEntity.getUpdatedDate());
documentResponseBean.setDocumentAttachmentId(documentEntity.getDocumentAttachmentId());
evaluationDocResponse.setFileValue(List.of(documentResponseBean));
evaluationDocResponse.setNameValue(doc.getNameValue());
evaluationDocResponse.setValid(doc.getValid());
evaluationDocResponse.setFieldId(doc.getFieldId());
});
}
if (evaluationDocResponse.getFileValue() == null) {
continue;
}
evaluationDocResponses.add(evaluationDocResponse);
}
response.setEvaluationDocument(evaluationDocResponses);
}
private void populateBasicDetails(ApplicationEvaluationEntity entity, ApplicationEvaluationResponse response) {
response.setId(entity.getId());
@@ -491,9 +589,15 @@ public class ApplicationEvaluationDao {
if (existingEntityOptional.isPresent()) {
entity = existingEntityOptional.get();
oldApplicationEvaluation = Utils.getClonedEntityForData(entity);
entity.setCriteria(Utils.convertObjectToJson(filterNonNullCriteria(processCriteria(entity, req))));
entity.setChecklist(Utils.convertObjectToJson(filterNonNullChecklist(processChecklist(entity, req))));
entity.setFile(Utils.convertObjectToJson(filterNonNullFields(processField(entity, req))));
if(req.getCriteria()!=null) {
entity.setCriteria(Utils.convertObjectToJson(processCriteria(entity, req)));
}
if(req.getChecklist()!=null) {
entity.setChecklist(Utils.convertObjectToJson(processChecklist(entity, req)));
}
if(req.getFiles()!=null) {
entity.setFile(Utils.convertObjectToJson(processField(entity, req)));
}
entity.setIsDeleted(false);
setIfUpdated(entity::getNote, entity::setNote, req.getNote());
setIfUpdated(entity::getMotivation, entity::setMotivation, req.getMotivation());
@@ -509,6 +613,18 @@ public class ApplicationEvaluationDao {
}
ApplicationStatusForEvaluation status = req.getApplicationStatus();
// Fetch all amendment request entities associated with the evaluation ID
List<ApplicationAmendmentRequestEntity> applicationAmendmentRequestEntities =
applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(entity.getId());
if(req.getEvaluationDocument()!=null) {
updateApplicationEvaluation(assignedApplicationId, req.getEvaluationDocument());
}
// Fetch amendment details from the request
if(req.getAmendmentDetails()!=null) {
List<AmendmentDetailsRequest> amendmentDetailsRequests = req.getAmendmentDetails();
updateAmendmentDocumentsAndFormFields(applicationAmendmentRequestEntities, amendmentDetailsRequests);
}
ApplicationEvaluationEntity savedEntity = applicationEvaluationRepository.save(entity);
@@ -524,22 +640,212 @@ public class ApplicationEvaluationDao {
}
}
private void updateAmendmentDocumentsAndFormFields(List<ApplicationAmendmentRequestEntity> applicationAmendmentRequestEntities, List<AmendmentDetailsRequest> amendmentFormFields) {
// Iterate through amendment request entities
private List<ChecklistRequest> filterNonNullChecklist(List<ChecklistRequest> checklistRequests) {
//
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->{
ApplicationAmendmentRequestEntity oldEntity = Utils.getClonedEntityForData(applicationAmendmentRequestEntity);
updateAmendment(applicationAmendmentRequestEntity, amendmentFormFieldsMap.get(applicationAmendmentRequestEntity.getId()));
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().actionType(VersionActionTypeEnum.UPDATE).oldData(oldEntity).newData(applicationAmendmentRequestEntity).build());
});
applicationAmendmentRequestRepository.saveAll(applicationAmendmentRequestEntities);
return checklistRequests.stream().filter(request -> request.getValid() != null).collect(Collectors.toList());
// 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, Object> amendmentDetailsMap = amendmentFormFields.stream()
// .filter(details -> applicationAmendmentRequestEntity.getId().equals(details.getAmendmentId()))
// .filter(details -> details.getFieldValue() != null) // Null check for getFormFieldDocuments
// .collect(Collectors.toMap(
// AmendmentDetailsRequest::getAmendmentId,
// AmendmentDetailsRequest::getFieldValue
// ));
// // Get corresponding amendment documents for the current entity
// List<AmendmentFormFieldRequest> amendmentDocuments = (List<AmendmentFormFieldRequest>) 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);
// 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) {
// String existingDocumentIds = applicationAmendmentRequestEntity.getAmendmentDocument();
//
// // 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());
//
// List<String> updatedDocumentIdList = new ArrayList<>();
// Map<Long, Object> amendmentDetailsMap = amendmentFormFields.stream()
// .filter(details -> applicationAmendmentRequestEntity.getId().equals(details.getAmendmentId()))
// .collect(Collectors.toMap(
// AmendmentDetailsRequest::getAmendmentId,
// AmendmentDetailsRequest::getFieldValue
// ));
//
// String amendmentDocumentIds = (String) amendmentDetailsMap.get(applicationAmendmentRequestEntity.getId());
// if (amendmentDocumentIds != null) {
// // Split and validate new document IDs
// List<String> newDocumentIdList = Arrays.stream(amendmentDocumentIds.split(","))
// .map(String::trim)
// .filter(id -> !id.isEmpty())
// .collect(Collectors.toList());
//
// for (String existingId : existingDocumentIdList) {
// for (String newId : newDocumentIdList) {
// if (existingId.equals(newId)) {
// Optional<DocumentEntity> documentEntity = documentRepository.findByIdAndNotDeleted(Long.valueOf(newId));
// if(documentEntity.isPresent()) {
// updatedDocumentIdList.add(newId);
// break;
// }
// }
// }
// }
//
// // 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 List<CriteriaRequest> filterNonNullCriteria(List<CriteriaRequest> criteriaRequests) {
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);
return criteriaRequests.stream().filter(request -> request.getScore() != null && request.getValid() != null).collect(Collectors.toList());
}
private List<FieldRequest> filterNonNullFields(List<FieldRequest> fieldRequests) {
return fieldRequests.stream().filter(request -> request.getValid() != null).collect(Collectors.toList());
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) {
// 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<>());
@@ -659,11 +965,52 @@ public class ApplicationEvaluationDao {
return entityOptional.get();
}
public void validatePreinstructor(HttpServletRequest request,Long applicationId,Long assignedApplicationId){
if (applicationId == null && assignedApplicationId == null) {
throw new CustomValidationException(
Status.BAD_REQUEST,
Translator.toLocale(GepafinConstant.EITHER_APPLICATION_OR_ASSIGNED_APPLICATION_ID_REQUIRED_MSG)
);
}
Optional<AssignedApplicationsEntity> assignedApplicationsOptional =
assignedApplicationsRepository.findByApplicationIdOrIdAndIsDeletedFalse(applicationId,assignedApplicationId);
public ApplicationEvaluationResponse getApplicationEvaluationByApplicationId(UserEntity user, Long applicationId, Long assignedApplicationId) {
if (assignedApplicationId != null) {
assignedApplicationsOptional = assignedApplicationsOptional.filter(a -> a.getId().equals(assignedApplicationId));
}
AssignedApplicationsEntity assignedApplications = assignedApplicationsOptional
.orElseThrow(() -> new CustomValidationException(
Status.BAD_REQUEST,
Translator.toLocale(GepafinConstant.ASSIGNED_APPLICATION_NOT_FOUND_WITH_ID_MSG)
));
if (applicationId == null) {
applicationId = assignedApplications.getApplication().getId();
}
validator.validatePreInstructor(request, assignedApplications.getUserId());
}
public ApplicationEvaluationResponse getApplicationEvaluationByApplicationId(HttpServletRequest request, UserEntity user, Long applicationID, Long assignedApplicationID) {
Long applicationId;
Long assignedApplicationId;
validatePreinstructor(request, applicationID, assignedApplicationID);
if (applicationID == null && assignedApplicationID != null) {
assignedApplicationId = assignedApplicationID;
Optional<AssignedApplicationsEntity> assignedApplicationsOptional =
assignedApplicationsRepository.findByIdAndIsDeletedFalse(assignedApplicationId);
applicationId = assignedApplicationsOptional.map(a -> a.getApplication().getId()).orElse(null);
} else {
applicationId = applicationID;
if (assignedApplicationID == null && applicationID != null) {
Optional<AssignedApplicationsEntity> assignedApplicationsOptional =
assignedApplicationsRepository.findByApplicationIdAndIsDeletedFalse(applicationId);
assignedApplicationId = assignedApplicationsOptional.map(AssignedApplicationsEntity::getId).orElse(null);
} else {
assignedApplicationId = assignedApplicationID;
}
}
applicationService.validateApplication(applicationId);
Optional<ApplicationEvaluationEntity> entityOptional;
if (applicationId != null && assignedApplicationId != null) {
@@ -675,11 +1022,19 @@ public class ApplicationEvaluationDao {
} else {
entityOptional = applicationEvaluationRepository.findFirstByIsDeletedFalseOrderByCreatedDateDesc();
}
return entityOptional.map(this::convertToResponse)
return entityOptional.map(this::convertToResponse)
.orElseGet(() -> {
return getEvaluationResponseByApplicationid(user, applicationId, assignedApplicationId);
});
}
private List<EvaluationDocumentRequest> prepareEvaluationDocumentBeanList(ApplicationEvaluationEntity entity) {
List<EvaluationDocumentRequest> docRequest = new ArrayList<>();
if (entity != null && entity.getEvaluationDocument() != null) {
docRequest = Utils.convertJsonToList(entity.getEvaluationDocument(), new TypeReference<List<EvaluationDocumentRequest>>() {});
}
return docRequest;
}
public ApplicationEvaluationResponse getEvaluationResponseByApplicationid(UserEntity user, Long applicationId, Long assignedApplicationId) {
@@ -777,7 +1132,7 @@ public class ApplicationEvaluationDao {
if (!mappedFieldMap.containsKey(formFieldId)) {
// CriteriaMappedField mappedField = new CriteriaMappedField();
CriteriaMappedField mappedField = populateMappedField(formFieldId, criteriaFormField, applicationForm, applicationId);
if(mappedField != null) {
if(mappedField != null) {
mappedFieldMap.put(formFieldId, mappedField);
}
}
@@ -906,7 +1261,7 @@ public class ApplicationEvaluationDao {
}
private DocumentResponseBean createDocumentResponseBean(DocumentEntity documentEntity) {
public DocumentResponseBean createDocumentResponseBean(DocumentEntity documentEntity) {
DocumentResponseBean responseBean = new DocumentResponseBean();
responseBean.setId(documentEntity.getId());
responseBean.setName(documentEntity.getFileName());
@@ -1425,9 +1780,14 @@ public class ApplicationEvaluationDao {
ApplicationEvaluationEntity oldApplicationEvaluation = Utils.getClonedEntityForData(existingEntity);
AssignedApplicationsEntity oldAssignedApplication = Utils.getClonedEntityForData(assignedApplicationsEntity);
List<ApplicationAmendmentRequestEntity> amendmentRequest = applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndStatusAndIsDeletedFalse(existingEntity.getId(),List.of(ApplicationAmendmentRequestEnum.AWAITING.getValue(),ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED.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());
existingEntity.setClosingDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
assignedApplicationsEntity.setStatus(AssignedApplicationEnum.CLOSE.getValue());
}
entity = applicationEvaluationRepository.save(existingEntity);
@@ -1443,11 +1803,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);
}
@@ -1470,5 +1825,33 @@ public class ApplicationEvaluationDao {
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.APPLICATION_EVALUATION_NOT_FOUND)));
}
public ApplicationEvaluationResponse updateApplicationEvaluation(
Long assignedApplicationId,
List<EvaluationDocumentRequest> docRequest) {
Optional<ApplicationEvaluationEntity> entityOptional=applicationEvaluationRepository.findByAssignedApplicationsEntity_IdAndIsDeletedFalse(assignedApplicationId);
ApplicationEvaluationEntity applicationEvaluationEntity =null;
ApplicationEvaluationEntity oldApplicationEvaluation = Utils.getClonedEntityForData(entityOptional.get());
applicationEvaluationEntity = entityOptional.get();
if (docRequest != null) {
List<EvaluationDocumentRequest> existingDocs = new ArrayList<>();
for (EvaluationDocumentRequest doc : docRequest) {
if (doc.getFileValue() != null) {
Long fileId = Long.valueOf(doc.getFileValue());
documentService.validateDocument(fileId);
existingDocs.add(doc);
}
}
String updatedEvaluationDocJson = Utils.convertObjectToJson(existingDocs);
applicationEvaluationEntity.setEvaluationDocument(updatedEvaluationDocJson);
}
ApplicationEvaluationEntity savedEntity = applicationEvaluationRepository.save(applicationEvaluationEntity);
/** This code is responsible for adding a version history log for the "Upload Document in Application Evaluation" operation. **/
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationEvaluation).newData(savedEntity).build());
return convertToResponse(savedEntity);
}
}