Resolved conflicts

This commit is contained in:
rajesh
2024-11-26 19:51:14 +05:30
16 changed files with 517 additions and 328 deletions

View File

@@ -1,6 +1,5 @@
package net.gepafin.tendermanagement.dao; package net.gepafin.tendermanagement.dao;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.persistence.criteria.Join; import jakarta.persistence.criteria.Join;
@@ -12,6 +11,7 @@ import net.gepafin.tendermanagement.entities.*;
import net.gepafin.tendermanagement.entities.SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum; import net.gepafin.tendermanagement.entities.SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum;
import net.gepafin.tendermanagement.enums.*; import net.gepafin.tendermanagement.enums.*;
import net.gepafin.tendermanagement.model.request.*; import net.gepafin.tendermanagement.model.request.*;
import net.gepafin.tendermanagement.model.request.AmendmentFormField.AmendmentIsUploadedByEnum;
import net.gepafin.tendermanagement.model.response.*; import net.gepafin.tendermanagement.model.response.*;
import net.gepafin.tendermanagement.repositories.*; import net.gepafin.tendermanagement.repositories.*;
import net.gepafin.tendermanagement.service.*; import net.gepafin.tendermanagement.service.*;
@@ -21,6 +21,8 @@ import net.gepafin.tendermanagement.util.Validator;
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException; 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.ResourceNotFoundException;
import net.gepafin.tendermanagement.web.rest.api.errors.Status; 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.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
@@ -29,6 +31,7 @@ import org.springframework.stereotype.Component;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
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.log; import static net.gepafin.tendermanagement.util.Utils.log;
@@ -80,21 +83,11 @@ public class ApplicationAmendmentRequestDao {
@Autowired @Autowired
private SystemEmailTemplatesService systemEmailTemplatesService; private SystemEmailTemplatesService systemEmailTemplatesService;
@Autowired
private CallDao callDao;
@Autowired
private DocumentRepository documentRepository;
@Autowired @Autowired
private HubService hubService; private HubService hubService;
// @Autowired
// private MailUtil mailUtil;
@Autowired @Autowired
private Validator validator; private Validator validator;
@Autowired
private ApplicationDao applicationDao;
@Autowired @Autowired
private EmailLogDao emailLogDao; private EmailLogDao emailLogDao;
@@ -218,10 +211,10 @@ public class ApplicationAmendmentRequestDao {
applicationAmendmentRequestEntity.setApplicationId(applicationId); applicationAmendmentRequestEntity.setApplicationId(applicationId);
if (applicationAmendmentRequest.getFormFields() != null) { if (applicationAmendmentRequest.getFormFields() != null) {
List<ApplicationFormFieldRequestBean> formFieldRequestBean = applicationAmendmentRequest.getFormFields().stream() List<AmendmentFormField> formFieldRequestBean = applicationAmendmentRequest.getFormFields().stream()
.filter(AmendmentFormFieldResponse::isSelected) .filter(AmendmentFormFieldResponse::isSelected)
.map(amendmentFormFieldRequest -> { .map(amendmentFormFieldRequest -> {
ApplicationFormFieldRequestBean formField = new ApplicationFormFieldRequestBean(); AmendmentFormField formField = new AmendmentFormField();
formField.setFieldId(amendmentFormFieldRequest.getFieldId()); formField.setFieldId(amendmentFormFieldRequest.getFieldId());
formField.setFieldValue(null); formField.setFieldValue(null);
return formField; return formField;
@@ -263,130 +256,132 @@ public class ApplicationAmendmentRequestDao {
} }
public ApplicationAmendmentRequestResponse convertEntityToResponse(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity) { public ApplicationAmendmentRequestResponse convertEntityToResponse(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity) {
ApplicationAmendmentRequestResponse applicationAmendmentRequestResponse = new ApplicationAmendmentRequestResponse(); ApplicationAmendmentRequestResponse response = initializeBasicResponse(applicationAmendmentRequestEntity);
applicationAmendmentRequestResponse.setId(applicationAmendmentRequestEntity.getId());
Long applicationId = applicationAmendmentRequestEntity.getApplicationId();
ApplicationEntity application = applicationService.validateApplication(applicationId); List<ApplicationFormEntity> forms = applicationFormRepository.findByApplicationId(applicationAmendmentRequestEntity.getApplicationId());
applicationAmendmentRequestResponse.setApplicationId(applicationId); Map<String, String> fieldIdToLabelMap = extractFieldIdToLabelMap(forms);
applicationAmendmentRequestResponse.setCallEmail(application.getCall().getEmail());
applicationAmendmentRequestResponse.setApplicationEvaluationId(applicationAmendmentRequestEntity.getApplicationEvaluationEntity().getId());
applicationAmendmentRequestResponse.setNote(applicationAmendmentRequestEntity.getNote());
applicationAmendmentRequestResponse.setStatus(ApplicationAmendmentRequestEnum.valueOf(applicationAmendmentRequestEntity.getStatus()));
applicationAmendmentRequestResponse.setResponseDays(applicationAmendmentRequestEntity.getResponseDays());
applicationAmendmentRequestResponse.setInternalNote(applicationAmendmentRequestEntity.getInternalNote());
LocalDateTime startDate = applicationAmendmentRequestEntity.getStartDate();
applicationAmendmentRequestResponse.setStartDate(startDate);
LocalDateTime expirationDate = startDate.plus(expirationDays, ChronoUnit.DAYS); List<AmendmentFormField> amendmentFormFields = Utils.convertJsonStringToList(
applicationAmendmentRequestResponse.setExpirationDate(expirationDate); applicationAmendmentRequestEntity.getFormFields(), AmendmentFormField.class);
Map<String, ApplicationFormFieldEntity> formFieldEntityMap = getApplicationFormFieldEntityMap(applicationAmendmentRequestEntity, amendmentFormFields);
applicationAmendmentRequestResponse.setIsSendEmail(applicationAmendmentRequestEntity.getIsEmail()); processFormFields(amendmentFormFields, fieldIdToLabelMap, formFieldEntityMap, response);
applicationAmendmentRequestResponse.setIsSendNotification(applicationAmendmentRequestEntity.getIsNotification());
String callName = application.getCall().getName();
Long protocolNumber = (applicationAmendmentRequestEntity.getProtocol() != null && applicationAmendmentRequestEntity.getProtocol().getProtocolNumber() != null)
? applicationAmendmentRequestEntity.getProtocol().getProtocolNumber()
: null;
UserEntity userEntity = userService.validateUser(application.getUserId());
String firstName = userEntity.getBeneficiary() != null ? userEntity.getBeneficiary().getFirstName() : "";
String lastName = userEntity.getBeneficiary() != null ? userEntity.getBeneficiary().getLastName() : "";
String beneficiaryName = (!firstName.isBlank() ? firstName : "") + return response;
(!lastName.isBlank() ? " " + lastName : "");
beneficiaryName = beneficiaryName.isBlank() ? "" : beneficiaryName;
applicationAmendmentRequestResponse.setCallName(callName);
applicationAmendmentRequestResponse.setProtocolNumber(protocolNumber);
applicationAmendmentRequestResponse.setBeneficiaryName(beneficiaryName);
List<ApplicationFormEntity> forms = applicationFormRepository.findByApplicationId(applicationId);
List<AmendmentFormFieldResponse> allFormFields = new ArrayList<>();
for (ApplicationFormEntity form : forms) {
String content = form.getForm().getContent();
List<Map<String, Object>> result = filterByName(content, "fileupload");
allFormFields.addAll(getIdAndLabelFromResult(result));
} }
Map<String, String> fieldIdToLabelMap = allFormFields.stream() private ApplicationAmendmentRequestResponse initializeBasicResponse(ApplicationAmendmentRequestEntity entity) {
ApplicationAmendmentRequestResponse response = new ApplicationAmendmentRequestResponse();
response.setId(entity.getId());
response.setApplicationId(entity.getApplicationId());
response.setApplicationEvaluationId(entity.getApplicationEvaluationEntity().getId());
response.setNote(entity.getNote());
response.setStatus(ApplicationAmendmentRequestEnum.valueOf(entity.getStatus()));
response.setResponseDays(entity.getResponseDays());
response.setInternalNote(entity.getInternalNote());
LocalDateTime startDate = entity.getStartDate();
response.setStartDate(startDate);
response.setExpirationDate(startDate.plus(expirationDays, ChronoUnit.DAYS));
response.setIsSendEmail(entity.getIsEmail());
response.setIsSendNotification(entity.getIsNotification());
ApplicationEntity application = applicationService.validateApplication(entity.getApplicationId());
response.setCallEmail(application.getCall().getEmail());
response.setCallName(application.getCall().getName());
UserEntity userEntity = userService.validateUser(application.getUserId());
response.setBeneficiaryName(buildBeneficiaryName(userEntity));
Long protocolNumber = entity.getProtocol() != null ? entity.getProtocol().getProtocolNumber() : null;
response.setProtocolNumber(protocolNumber);
return response;
}
private Map<String, String> extractFieldIdToLabelMap(List<ApplicationFormEntity> forms) {
return forms.stream()
.flatMap(form -> {
String content = form.getForm().getContent();
return getIdAndLabelFromResult(filterByName(content, "fileupload")).stream();
})
.collect(Collectors.toMap(AmendmentFormFieldResponse::getFieldId, AmendmentFormFieldResponse::getLabel)); .collect(Collectors.toMap(AmendmentFormFieldResponse::getFieldId, AmendmentFormFieldResponse::getLabel));
}
String formFieldsJson = applicationAmendmentRequestEntity.getFormFields(); private Map<String, ApplicationFormFieldEntity> getApplicationFormFieldEntityMap(
List<AmendmentFormFieldResponse> formFields = Utils.convertJsonToList( ApplicationAmendmentRequestEntity entity, List<AmendmentFormField> amendmentFormFields) {
formFieldsJson, new TypeReference<List<AmendmentFormFieldResponse>>() { List<String> fieldIds = amendmentFormFields.stream()
}); .map(AmendmentFormField::getFieldId)
.toList();
return getApplicationFormFieldList(entity, fieldIds).stream()
.collect(Collectors.toMap(ApplicationFormFieldEntity::getFieldId, Function.identity()));
}
for (AmendmentFormFieldResponse formField : formFields) { private void processFormFields(List<AmendmentFormField> amendmentFormFields, Map<String, String> fieldIdToLabelMap,
String label = fieldIdToLabelMap.get(formField.getFieldId()); Map<String, ApplicationFormFieldEntity> formFieldEntityMap, ApplicationAmendmentRequestResponse response) {
List<AmendmentFormFieldResponse> formFields = new ArrayList<>();
List<ApplicationFormFieldResponseBean> fileDetails = new ArrayList<>();
for (AmendmentFormField amendmentFormField : amendmentFormFields) {
// Create form field response
createFormField(formFields, fieldIdToLabelMap, amendmentFormField);
// Create document responses
List<Long> documentIds = extractIds(amendmentFormField.getFieldValue());
List<DocumentResponseBean> documentResponseBeans = documentIds.stream()
.map(id -> {
DocumentEntity documentEntity = documentService.validateDocument(id);
DocumentResponseBean responseBean = new DocumentResponseBean();
responseBean.setId(documentEntity.getId());
responseBean.setName(documentEntity.getFileName());
responseBean.setType(DocumentTypeEnum.valueOf(documentEntity.getType()));
responseBean.setSource(DocumentSourceTypeEnum.valueOf(documentEntity.getSource()));
responseBean.setSourceId(documentEntity.getSourceId());
responseBean.setFilePath(documentEntity.getFilePath());
responseBean.setCreatedDate(documentEntity.getCreatedDate());
responseBean.setUpdatedDate(documentEntity.getUpdatedDate());
return responseBean;
})
.toList();
// Map to application form field response bean
ApplicationFormFieldEntity formFieldEntity = formFieldEntityMap.get(amendmentFormField.getFieldId());
ApplicationFormFieldResponseBean responseBean = new ApplicationFormFieldResponseBean();
responseBean.setApplicationFormId(formFieldEntity.getApplicationForm().getId());
responseBean.setId(formFieldEntity.getId());
responseBean.setFieldId(amendmentFormField.getFieldId());
responseBean.setCreatedDate(formFieldEntity.getCreatedDate());
responseBean.setUpdatedDate(formFieldEntity.getUpdatedDate());
responseBean.setFieldValue(documentResponseBeans);
fileDetails.add(responseBean);
}
response.setFormFields(formFields);
response.setApplicationFormFields(fileDetails);
}
private String buildBeneficiaryName(UserEntity userEntity) {
if (userEntity.getBeneficiary() == null) {
return "";
}
String firstName = userEntity.getBeneficiary().getFirstName();
String lastName = userEntity.getBeneficiary().getLastName();
return (firstName != null ? firstName : "") +
(lastName != null && !lastName.isBlank() ? " " + lastName : "");
}
private void createFormField(List<AmendmentFormFieldResponse> formFields, Map<String, String> fieldIdToLabelMap,
AmendmentFormField amendmentFormField) {
AmendmentFormFieldResponse formField = new AmendmentFormFieldResponse();
String label = fieldIdToLabelMap.get(amendmentFormField.getFieldId());
formField.setFieldId(amendmentFormField.getFieldId());
formField.setLabel(label); formField.setLabel(label);
formField.setSelected(true); formField.setSelected(true);
} formFields.add(formField);
// Set the filtered formFields in the response
applicationAmendmentRequestResponse.setFormFields(formFields);
String applicationFormFieldsJson = applicationAmendmentRequestEntity.getFormFields();
List<ApplicationFormFieldResponseBean> applicationFormFields = Utils.convertJsonToList(
formFieldsJson, new TypeReference<List<ApplicationFormFieldResponseBean>>() {
});
List<ApplicationFormFieldResponseBean> fileDetailResponses = new ArrayList<>();
for (ApplicationFormFieldResponseBean field : applicationFormFields) {
ApplicationFormFieldResponseBean responseBean = new ApplicationFormFieldResponseBean();
responseBean.setFieldId(field.getFieldId());
Optional<ApplicationFormFieldEntity> formFieldEntity = Optional.empty();
for (ApplicationFormEntity form : forms) {
formFieldEntity = applicationFormFieldRepository
.findByApplicationFormIdAndFieldId(form.getId(), field.getFieldId());
if (formFieldEntity.isPresent()) {
// Set the applicationFormId from the matching form
responseBean.setApplicationFormId(form.getId());
responseBean.setId(formFieldEntity.get().getId());
responseBean.setCreatedDate(formFieldEntity.get().getCreatedDate());
responseBean.setUpdatedDate(formFieldEntity.get().getUpdatedDate());
break;
}
} }
// Check if fieldValue is not null and is a String
if (field.getFieldValue() instanceof String && field.getFieldValue() != null && !((String) field.getFieldValue()).isBlank()) {
String fieldValueString = (String) field.getFieldValue();
String[] documentIds = fieldValueString.split(",");
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
// Process each document ID
for (String docId : documentIds) {
try {
Long documentId = Long.valueOf(docId.trim());
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
DocumentResponseBean docBean = new DocumentResponseBean();
docBean.setId(documentEntity.getId());
docBean.setName(documentEntity.getFileName());
docBean.setType(DocumentTypeEnum.valueOf(documentEntity.getType()));
docBean.setSource(DocumentSourceTypeEnum.valueOf(documentEntity.getSource()));
docBean.setSourceId(documentEntity.getSourceId());
docBean.setFilePath(documentEntity.getFilePath());
docBean.setCreatedDate(documentEntity.getCreatedDate());
docBean.setUpdatedDate(documentEntity.getUpdatedDate());
documentResponseBeans.add(docBean);
});
} catch (NumberFormatException e) {
// Handle the case where documentId is not a valid number
// Log the error if necessary
}
}
responseBean.setFieldValue(documentResponseBeans);
} else {
responseBean.setFieldValue(null);
}
fileDetailResponses.add(responseBean);
}
applicationAmendmentRequestResponse.setApplicationFormFields(fileDetailResponses);
return applicationAmendmentRequestResponse;
}
public ApplicationAmendmentRequestEntity validateApplicationAmendmentRequest(Long id) { public ApplicationAmendmentRequestEntity validateApplicationAmendmentRequest(Long id) {
return applicationAmendmentRequestRepository.findByIdAndIsDeletedFalse(id) return applicationAmendmentRequestRepository.findByIdAndIsDeletedFalse(id)
@@ -447,11 +442,21 @@ public class ApplicationAmendmentRequestDao {
ApplicationAmendmentRequestEntity existingApplicationAmendment = validateApplicationAmendmentRequest(id); ApplicationAmendmentRequestEntity existingApplicationAmendment = validateApplicationAmendmentRequest(id);
setIfUpdated(existingApplicationAmendment::getNote, existingApplicationAmendment::setNote, updateRequest.getNote()); setIfUpdated(existingApplicationAmendment::getNote, existingApplicationAmendment::setNote, updateRequest.getNote());
if (updateRequest.getApplicationFormFields() != null) {
updateApplicationFormFields(existingApplicationAmendment, updateRequest.getApplicationFormFields()); Map<String, AmendmentFormField> amendmentFormFieldMap = Utils
updateFormFieldsJson(existingApplicationAmendment, updateRequest.getApplicationFormFields()); .convertJsonStringToList(existingApplicationAmendment.getFormFields(), AmendmentFormField.class)
.stream().collect(Collectors.toMap(AmendmentFormField::getFieldId, Function.identity()));
Map<String, ApplicationFormFieldEntity> applicationFormFieldMap = getApplicationFormFieldList(existingApplicationAmendment, amendmentFormFieldMap.keySet().stream().toList()).stream().collect(Collectors.toMap(ApplicationFormFieldEntity::getFieldId, Function.identity()));
if(updateRequest.getApplicationFormFields() != null) {
updateRequest.getApplicationFormFields().stream().forEach(applicationFormFieldRequest->{
AmendmentFormField amendmentFormField = getAmendmentFormField(amendmentFormFieldMap,applicationFormFieldRequest.getFieldId());
ApplicationFormFieldEntity applicationFormFieldEntity = getApplicationFormField(applicationFormFieldMap, applicationFormFieldRequest.getFieldId());
updateApplicationFormField(applicationFormFieldEntity,applicationFormFieldRequest, amendmentFormField);
updateFormField(applicationFormFieldRequest, amendmentFormField);
});
existingApplicationAmendment.setFormFields(Utils.convertListToJsonString(amendmentFormFieldMap.values().stream().toList()));
} }
existingApplicationAmendment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
ApplicationAmendmentRequestEntity updatedApplicationAmendment = saveApplicationAmendmentRequestEntity(existingApplicationAmendment); ApplicationAmendmentRequestEntity updatedApplicationAmendment = saveApplicationAmendmentRequestEntity(existingApplicationAmendment);
ApplicationAmendmentRequestResponse response = convertEntityToResponse(updatedApplicationAmendment); ApplicationAmendmentRequestResponse response = convertEntityToResponse(updatedApplicationAmendment);
@@ -459,184 +464,298 @@ public class ApplicationAmendmentRequestDao {
return response; return response;
} }
private void updateApplicationFormFields(ApplicationAmendmentRequestEntity applicationAmendment, ApplicationFormFieldRequestBean updatedFormField) { private List<Long> updateApplicationFormField(ApplicationFormFieldEntity applicationFormFieldEntity,
if (updatedFormField.getFieldValue() == null || "".equals(updatedFormField.getFieldValue().toString().trim())) { ApplicationFormFieldRequestBean applicationFormFieldRequest, AmendmentFormField amendmentFormField) {
List<ApplicationFormEntity> applicationForms = applicationFormRepository.findByApplicationId(applicationAmendment.getApplicationId()); // Step 1: Extract IDs
List<Long> applicationFormFieldIds = extractIds(applicationFormFieldEntity.getFieldValue());
List<Long> amendmentFormFieldIds = extractIds(amendmentFormField.getFieldValue());
List<Long> requestedIds = extractIds(applicationFormFieldRequest.getFieldValue());
boolean fieldUpdated = false; // Step 2: Optimize operations by finding differences
// Remove only those IDs from currentIds that exist in presentIds but not in requestedIds
List<Long> idsToRemove = amendmentFormFieldIds.stream()
.filter(id -> !requestedIds.contains(id))
.toList();
applicationFormFieldIds.removeAll(idsToRemove);
for (ApplicationFormEntity applicationForm : applicationForms) { // Add only those IDs to currentIds that exist in requestedIds but not in presentIds
Optional<ApplicationFormFieldEntity> formFieldEntityOptional = applicationFormFieldRepository List<Long> idsToAdd = requestedIds.stream()
.findByApplicationFormIdAndFieldId(applicationForm.getId(), updatedFormField.getFieldId()); .filter(id -> !amendmentFormFieldIds.contains(id))
.toList();
applicationFormFieldIds.addAll(idsToAdd);
if (formFieldEntityOptional.isPresent()) { // Step 3: Update the applicationFormFieldEntity fieldValue with requestedIds if it has changed
ApplicationFormFieldEntity formEntity = formFieldEntityOptional.get(); if (!amendmentFormFieldIds.equals(requestedIds)) {
formEntity.setFieldValue(null); // Set field value to null String updatedFieldValue = applicationFormFieldIds.stream()
applicationFormFieldRepository.save(formEntity); .map(String::valueOf)
log.info("Set field value to null for application ID {} and field ID {}", applicationAmendment.getApplicationId(), updatedFormField.getFieldId()); .collect(Collectors.joining(","));
fieldUpdated = true; applicationFormFieldEntity.setFieldValue(updatedFieldValue);
break; applicationFormFieldRepository.save(applicationFormFieldEntity);
}
} }
if (!fieldUpdated) { // Step 4: Return the updated currentIds
throw new CustomValidationException(Status.NOT_FOUND, "No ApplicationFormField found for application ID " + applicationAmendment.getApplicationId() + " and field ID " + updatedFormField.getFieldId()); return applicationFormFieldIds;
}
private ApplicationFormFieldEntity getApplicationFormField(
Map<String, ApplicationFormFieldEntity> applicationFormFieldMap, String fieldId) {
ApplicationFormFieldEntity applicationFormFieldEntity = applicationFormFieldMap.get(fieldId);
if (applicationFormFieldEntity == null) {
throw new CustomValidationException(Status.BAD_REQUEST, GepafinConstant.APPLICATION_FORM_FIELD_NOT_FOUND);
}
return applicationFormFieldEntity;
}
private List<ApplicationFormFieldEntity> getApplicationFormFieldList(
ApplicationAmendmentRequestEntity applicationAmendment,
List<String> fieldIds) {
List<ApplicationFormEntity> applicationFormList = applicationFormRepository
.findByApplicationId(applicationAmendment.getApplicationId());
return applicationFormList.stream().flatMap(applicationForm -> applicationFormFieldRepository
.findByApplicationFormIdAndFieldIdIn(applicationForm.getId(), fieldIds).stream()).toList();
}
private AmendmentFormField getAmendmentFormField(Map<String, AmendmentFormField> amendmentFormFieldMap,
String fieldId) {
AmendmentFormField amendmentFormField = amendmentFormFieldMap.get(fieldId);
if (amendmentFormField == null) {
throw new CustomValidationException(Status.BAD_REQUEST, GepafinConstant.APPLICATION_FORM_FIELD_NOT_FOUND);
}
return amendmentFormField;
}
private void updateFormField(ApplicationFormFieldRequestBean applicationFormFieldRequest,
AmendmentFormField amendmentFormField) {
List<Long> requestedDocumentIds = extractIds(applicationFormFieldRequest.getFieldValue());
List<Long> existingDocumentIds = extractIds(amendmentFormField.getFieldValue());
if (requestedDocumentIds.isEmpty()) {
if (!existingDocumentIds.isEmpty()) {
existingDocumentIds.forEach(this::softDeleteDocument);
amendmentFormField.setFieldValue(null);
setIsUploadedBy(amendmentFormField);
} }
return; return;
} }
List<String> documentIds; requestedDocumentIds.forEach(documentId -> documentService.validateDocument(documentId).getId());
existingDocumentIds.stream().filter(documentId -> !requestedDocumentIds.contains(documentId))
.forEach(this::softDeleteDocument);
if (updatedFormField.getFieldValue() instanceof String && updatedFormField.getFieldValue() != null) { String newFieldValue = String.join(",",
documentIds = Arrays.asList(((String) updatedFormField.getFieldValue()).split(",")); requestedDocumentIds.stream().map(String::valueOf).collect(Collectors.toList()));
} else {
log.warn("Expected fieldValue as a comma-separated String but got: {}", updatedFormField.getFieldValue());
return;
}
List<String> validDocumentIds = new ArrayList<>(); if (!newFieldValue.equals(amendmentFormField.getFieldValue())) {
for (String documentId : documentIds) { amendmentFormField.setFieldValue(newFieldValue);
try { setIsUploadedBy(amendmentFormField);
DocumentEntity documentEntity = documentService.validateDocument(Long.parseLong(documentId.trim()));
if (documentEntity != null) {
validDocumentIds.add(documentId.trim());
} else {
log.warn("Document with ID {} does not exist. Skipping this ID.", documentId);
}
} catch (NumberFormatException e) {
log.error("Invalid document ID format: {}. Error: {}", documentId, e.getMessage());
} }
} }
if (!validDocumentIds.isEmpty()) { private List<Long> extractIds(Object fieldValue) {
List<ApplicationFormEntity> applicationForms = applicationFormRepository.findByApplicationId(applicationAmendment.getApplicationId()); if (fieldValue instanceof String && !StringUtils.isEmpty((String) fieldValue)) {
return Arrays.stream(((String) fieldValue).split(","))
boolean fieldUpdated = false; .map(Long::valueOf)
.collect(Collectors.toList());
// Parse the formFields JSON string to get amendment field values
String amendmentFieldValue = null;
try {
ObjectMapper mapper = new ObjectMapper();
List<ApplicationFormFieldRequestBean> amendmentFields = mapper.readValue(
applicationAmendment.getFormFields(),
mapper.getTypeFactory().constructCollectionType(List.class, ApplicationFormFieldRequestBean.class)
);
// Find the matching field value and convert to string if found
Optional<Object> amendmentFieldObj = amendmentFields.stream()
.filter(field -> updatedFormField.getFieldId().equals(field.getFieldId()))
.map(ApplicationFormFieldRequestBean::getFieldValue)
.findFirst();
if (amendmentFieldObj.isPresent() && amendmentFieldObj.get() instanceof String) {
amendmentFieldValue = (String) amendmentFieldObj.get();
}
} catch (JsonProcessingException e) {
log.error("Error parsing formFields JSON: {}", e.getMessage());
return;
}
if (amendmentFieldValue == null) {
log.warn("No matching field found in amendment for field ID {}", updatedFormField.getFieldId());
return;
}
List<String> amendmentDocumentIds = Arrays.asList(amendmentFieldValue.split(","));
for (ApplicationFormEntity applicationForm : applicationForms) {
Optional<ApplicationFormFieldEntity> formFieldEntityOptional = applicationFormFieldRepository
.findByApplicationFormIdAndFieldId(applicationForm.getId(), updatedFormField.getFieldId());
if (formFieldEntityOptional.isPresent()) {
ApplicationFormFieldEntity formEntity = formFieldEntityOptional.get();
// Retrieve existing document IDs in ApplicationFormFieldTable
String existingFieldValue = formEntity.getFieldValue();
Set<String> existingDocumentIds = existingFieldValue != null
? new HashSet<>(Arrays.asList(existingFieldValue.split(",")))
: new HashSet<>();
// Remove amendment documents from existing document IDs
existingDocumentIds.removeAll(amendmentDocumentIds);
// Add valid new document IDs from the request
existingDocumentIds.addAll(validDocumentIds);
applicationDao.updateDocumentDeletionStatus(formEntity, updatedFormField, formEntity.getApplicationForm().getForm(), null,validDocumentIds,true);
// Set the combined document IDs back as the field value
formEntity.setFieldValue(String.join(",", existingDocumentIds));
applicationFormFieldRepository.save(formEntity);
log.info("Updated field value for application ID {} and field ID {} with document IDs {}",
applicationAmendment.getApplicationId(), updatedFormField.getFieldId(), String.join(",", existingDocumentIds));
fieldUpdated = true;
break;
}
}
if (!fieldUpdated) {
throw new CustomValidationException(Status.NOT_FOUND,
String.format("No ApplicationFormField found for application ID %s and field ID %s. Skipping update.",
applicationAmendment.getApplicationId(), updatedFormField.getFieldId()));
}
} else {
log.warn("No valid document IDs found for update. Skipping field ID {}", updatedFormField.getFieldId());
} }
return Collections.emptyList();
} }
private void updateFormFieldsJson(ApplicationAmendmentRequestEntity applicationAmendment, ApplicationFormFieldRequestBean updatedFormField) {
if (updatedFormField != null) {
try {
// Step 1: Fetch the existing form fields JSON
String existingFormFieldsJson = applicationAmendment.getFormFields();
List<ApplicationFormFieldRequestBean> formFieldsList;
if (existingFormFieldsJson == null || existingFormFieldsJson.isEmpty()) { private void setIsUploadedBy(AmendmentFormField amendmentFormField) {
formFieldsList = new ArrayList<>(); // If no existing data, start with an empty list if(validator.checkIsBeneficiary()) {
} else { amendmentFormField.setIsUploadedBy(AmendmentIsUploadedByEnum.BENEFICIARY.getValue());
// Step 2: Deserialize the existing JSON into a list of objects }else {
formFieldsList = new ObjectMapper().readValue(existingFormFieldsJson, new TypeReference<List<ApplicationFormFieldRequestBean>>() { amendmentFormField.setIsUploadedBy(AmendmentIsUploadedByEnum.PRE_INSTRUCTOR.getValue());
});
} }
// Step 3: Check if the field ID already exists in the list and update it
boolean fieldUpdated = false;
for (ApplicationFormFieldRequestBean field : formFieldsList) {
if (field.getFieldId().equals(updatedFormField.getFieldId())) {
field.setFieldValue(updatedFormField.getFieldValue()); // Update field value
fieldUpdated = true;
break;
}
}
// If field wasn't updated, log a warning message instead of adding a new field
if (!fieldUpdated) {
log.warn("Field ID {} does not exist in the form fields for application amendment ID {}", updatedFormField.getFieldId(), applicationAmendment.getId());
throw new CustomValidationException(Status.NOT_FOUND, "Field ID {} does not exist in the form fields for application amendment ID {}");
} }
// Step 4: Serialize the updated list back to JSON if the update was successful
String updatedFormFieldsJson = new ObjectMapper().writeValueAsString(formFieldsList);
applicationAmendment.setFormFields(updatedFormFieldsJson); // Update the form fields with the modified list
log.info("Updated form fields JSON for application amendment ID {}: {}", applicationAmendment.getId(), updatedFormFieldsJson); // private void updateApplicationFormFields(ApplicationAmendmentRequestEntity applicationAmendment, ApplicationFormFieldRequestBean updatedFormField) {
// if (updatedFormField.getFieldValue() == null || "".equals(updatedFormField.getFieldValue().toString().trim())) {
} catch (JsonProcessingException e) { // List<ApplicationFormEntity> applicationForms = applicationFormRepository.findByApplicationId(applicationAmendment.getApplicationId());
log.error("Error processing JSON for form fields for application amendment ID {}: {}", applicationAmendment.getId(), e.getMessage()); //
throw new CustomValidationException(Status.BAD_REQUEST, "Error processing JSON for form fields"); // boolean fieldUpdated = false;
} //
} else { // for (ApplicationFormEntity applicationForm : applicationForms) {
log.warn("No form field data to update for application amendment ID {}", applicationAmendment.getId()); // Optional<ApplicationFormFieldEntity> formFieldEntityOptional = applicationFormFieldRepository
throw new CustomValidationException(Status.NOT_FOUND, "No form field data to update for application amendment ID {}"); // .findByApplicationFormIdAndFieldId(applicationForm.getId(), updatedFormField.getFieldId());
} //
} // if (formFieldEntityOptional.isPresent()) {
// ApplicationFormFieldEntity formEntity = formFieldEntityOptional.get();
// formEntity.setFieldValue(null); // Set field value to null
// applicationFormFieldRepository.save(formEntity);
// log.info("Set field value to null for application ID {} and field ID {}", applicationAmendment.getApplicationId(), updatedFormField.getFieldId());
// fieldUpdated = true;
// break;
// }
// }
//
// if (!fieldUpdated) {
// throw new CustomValidationException(Status.NOT_FOUND, "No ApplicationFormField found for application ID " + applicationAmendment.getApplicationId() + " and field ID " + updatedFormField.getFieldId());
// }
// return;
// }
//
// List<String> documentIds;
//
// if (updatedFormField.getFieldValue() instanceof String && updatedFormField.getFieldValue() != null) {
// documentIds = Arrays.asList(((String) updatedFormField.getFieldValue()).split(","));
// } else {
// log.warn("Expected fieldValue as a comma-separated String but got: {}", updatedFormField.getFieldValue());
// return;
// }
//
// List<String> validDocumentIds = new ArrayList<>();
// for (String documentId : documentIds) {
// try {
// DocumentEntity documentEntity = documentService.validateDocument(Long.parseLong(documentId.trim()));
// if (documentEntity != null) {
// validDocumentIds.add(documentId.trim());
// } else {
// log.warn("Document with ID {} does not exist. Skipping this ID.", documentId);
// }
// } catch (NumberFormatException e) {
// log.error("Invalid document ID format: {}. Error: {}", documentId, e.getMessage());
// }
// }
//
// if (!validDocumentIds.isEmpty()) {
// List<ApplicationFormEntity> applicationForms = applicationFormRepository.findByApplicationId(applicationAmendment.getApplicationId());
//
// boolean fieldUpdated = false;
//
// // Parse the formFields JSON string to get amendment field values
// String amendmentFieldValue = null;
// try {
// ObjectMapper mapper = new ObjectMapper();
// List<ApplicationFormFieldRequestBean> amendmentFields = mapper.readValue(
// applicationAmendment.getFormFields(),
// mapper.getTypeFactory().constructCollectionType(List.class, ApplicationFormFieldRequestBean.class)
// );
//
// // Find the matching field value and convert to string if found
// Optional<Object> amendmentFieldObj = amendmentFields.stream()
// .filter(field -> updatedFormField.getFieldId().equals(field.getFieldId()))
// .map(ApplicationFormFieldRequestBean::getFieldValue)
// .findFirst();
//
// if (amendmentFieldObj.isPresent() && amendmentFieldObj.get() instanceof String) {
// amendmentFieldValue = (String) amendmentFieldObj.get();
// }
//
// } catch (JsonProcessingException e) {
// log.error("Error parsing formFields JSON: {}", e.getMessage());
// return;
// }
//
// if (amendmentFieldValue == null) {
// log.warn("No matching field found in amendment for field ID {}", updatedFormField.getFieldId());
// return;
// }
//
// List<String> amendmentDocumentIds = Arrays.asList(amendmentFieldValue.split(","));
//
// for (ApplicationFormEntity applicationForm : applicationForms) {
// Optional<ApplicationFormFieldEntity> formFieldEntityOptional = applicationFormFieldRepository
// .findByApplicationFormIdAndFieldId(applicationForm.getId(), updatedFormField.getFieldId());
//
// if (formFieldEntityOptional.isPresent()) {
// ApplicationFormFieldEntity formEntity = formFieldEntityOptional.get();
//
// // Retrieve existing document IDs in ApplicationFormFieldTable
// String existingFieldValue = formEntity.getFieldValue();
// Set<String> existingDocumentIds = existingFieldValue != null
// ? new HashSet<>(Arrays.asList(existingFieldValue.split(",")))
// : new HashSet<>();
//
// // Remove amendment documents from existing document IDs
// existingDocumentIds.removeAll(amendmentDocumentIds);
//
// // Add valid new document IDs from the request
// existingDocumentIds.addAll(validDocumentIds);
// applicationDao.updateDocumentDeletionStatus(formEntity, updatedFormField, formEntity.getApplicationForm().getForm(), null,validDocumentIds,true);
// // Set the combined document IDs back as the field value
// formEntity.setFieldValue(String.join(",", existingDocumentIds));
// applicationFormFieldRepository.save(formEntity);
// log.info("Updated field value for application ID {} and field ID {} with document IDs {}",
// applicationAmendment.getApplicationId(), updatedFormField.getFieldId(), String.join(",", existingDocumentIds));
// fieldUpdated = true;
// break;
// }
// }
//
// if (!fieldUpdated) {
// throw new CustomValidationException(Status.NOT_FOUND,
// String.format("No ApplicationFormField found for application ID %s and field ID %s. Skipping update.",
// applicationAmendment.getApplicationId(), updatedFormField.getFieldId()));
// }
// } else {
// log.warn("No valid document IDs found for update. Skipping field ID {}", updatedFormField.getFieldId());
// }
// }
//
//
// private void updateFormFieldsJson(ApplicationAmendmentRequestEntity applicationAmendment, ApplicationFormFieldRequestBean updatedFormField) {
// if (updatedFormField != null) {
// try {
// // Step 1: Fetch the existing form fields JSON
// String existingFormFieldsJson = applicationAmendment.getFormFields();
// List<ApplicationFormFieldRequestBean> formFieldsList;
//
// if (existingFormFieldsJson == null || existingFormFieldsJson.isEmpty()) {
// formFieldsList = new ArrayList<>(); // If no existing data, start with an empty list
// } else {
// // Step 2: Deserialize the existing JSON into a list of objects
// formFieldsList = new ObjectMapper().readValue(existingFormFieldsJson, new TypeReference<List<ApplicationFormFieldRequestBean>>() {
// });
// }
//
// // Step 3: Check if the field ID already exists in the list and update it
// boolean fieldUpdated = false;
// for (ApplicationFormFieldRequestBean field : formFieldsList) {
// if (field.getFieldId().equals(updatedFormField.getFieldId())) {
// field.setFieldValue(updatedFormField.getFieldValue()); // Update field value
// fieldUpdated = true;
// break;
// }
// }
//
// // If field wasn't updated, log a warning message instead of adding a new field
// if (!fieldUpdated) {
// log.warn("Field ID {} does not exist in the form fields for application amendment ID {}", updatedFormField.getFieldId(), applicationAmendment.getId());
// throw new CustomValidationException(Status.NOT_FOUND, "Field ID {} does not exist in the form fields for application amendment ID {}");
//
// }
//
// // Step 4: Serialize the updated list back to JSON if the update was successful
// String updatedFormFieldsJson = new ObjectMapper().writeValueAsString(formFieldsList);
// applicationAmendment.setFormFields(updatedFormFieldsJson); // Update the form fields with the modified list
//
// log.info("Updated form fields JSON for application amendment ID {}: {}", applicationAmendment.getId(), updatedFormFieldsJson);
//
// } catch (JsonProcessingException e) {
// log.error("Error processing JSON for form fields for application amendment ID {}: {}", applicationAmendment.getId(), e.getMessage());
// throw new CustomValidationException(Status.BAD_REQUEST, "Error processing JSON for form fields");
// }
// } else {
// log.warn("No form field data to update for application amendment ID {}", applicationAmendment.getId());
// throw new CustomValidationException(Status.NOT_FOUND, "No form field data to update for application amendment ID {}");
// }
// }
public List<ApplicationAmendmentRequestResponse> getAllAmendmentRequestByBeneficiaryId(Long beneficiaryId) { public List<ApplicationAmendmentRequestResponse> getAllAmendmentRequestByBeneficiaryId(Long beneficiaryUserId) {
UserEntity userEntity = userService.validateUser(beneficiaryId); UserEntity userEntity = userService.validateUser(beneficiaryUserId);
List<ApplicationAmendmentRequestEntity> entities = List<ApplicationAmendmentRequestEntity> entities =
applicationAmendmentRequestRepository.findByUserId(beneficiaryId); applicationAmendmentRequestRepository.findByUserId(beneficiaryUserId);
return entities.stream() return entities.stream()
.map(this::convertEntityToResponse) .map(this::convertEntityToResponse)
@@ -714,9 +833,9 @@ public class ApplicationAmendmentRequestDao {
public ApplicationAmendmentRequestResponse updateApplicationAmendmentStatus( public ApplicationAmendmentRequestResponse updateApplicationAmendmentStatus(
Long id, ApplicationAmendmentRequestEnum statusTypeEnum) { Long id, ApplicationAmendmentRequestEnum statusTypeEnum) {
log.info("Updating application amendement with status: {}", id); log.info("Updating application amendment with status: {}", id);
ApplicationAmendmentRequestEntity existingApplicationAmendment = validateApplicationAmendmentRequest(id); ApplicationAmendmentRequestEntity existingApplicationAmendment = validateApplicationAmendmentRequest(id);
if (Boolean.TRUE.equals(existingApplicationAmendment.getStatus().equals(ApplicationAmendmentRequestEnum.AWAITING.getValue())) && Boolean.TRUE.equals(statusTypeEnum.equals(ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED))) { if (Boolean.TRUE.equals(existingApplicationAmendment.getStatus().equals(ApplicationAmendmentRequestEnum.AWAITING.getValue())) || Boolean.TRUE.equals(statusTypeEnum.equals(ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED))) {
existingApplicationAmendment.setStatus(ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED.getValue()); existingApplicationAmendment.setStatus(ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED.getValue());
existingApplicationAmendment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); existingApplicationAmendment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
applicationAmendmentRequestRepository.save(existingApplicationAmendment); applicationAmendmentRequestRepository.save(existingApplicationAmendment);
@@ -779,4 +898,9 @@ public class ApplicationAmendmentRequestDao {
} }
private void softDeleteDocument(Long documentId) {
documentService.deleteFile(documentId);
}
} }

View File

@@ -99,6 +99,7 @@ public class ApplicationEvaluationDao {
entity.setChecklist(Utils.convertObjectToJson(req.getChecklist())); entity.setChecklist(Utils.convertObjectToJson(req.getChecklist()));
entity.setFile(Utils.convertObjectToJson(req.getFiles())); entity.setFile(Utils.convertObjectToJson(req.getFiles()));
entity.setNote(req.getNote()); entity.setNote(req.getNote());
entity.setMotivation(req.getMotivation());
entity.setIsDeleted(false); entity.setIsDeleted(false);
entity.setStatus(ApplicationEvaluationStatusTypeEnum.OPEN.getValue()); entity.setStatus(ApplicationEvaluationStatusTypeEnum.OPEN.getValue());
return entity; return entity;
@@ -130,6 +131,7 @@ public class ApplicationEvaluationDao {
AssignedApplicationsEntity assignedApplications = assignedApplicationsRepository.findByIdAndIsDeletedFalse(entity.getAssignedApplicationsEntity().getId()).orElse(null); AssignedApplicationsEntity assignedApplications = assignedApplicationsRepository.findByIdAndIsDeletedFalse(entity.getAssignedApplicationsEntity().getId()).orElse(null);
response.setAssignedApplicationId(assignedApplications.getId()); response.setAssignedApplicationId(assignedApplications.getId());
response.setNote(entity.getNote()); response.setNote(entity.getNote());
response.setMotivation(entity.getMotivation());
response.setStatus(ApplicationEvaluationStatusTypeEnum.valueOf(entity.getStatus())); response.setStatus(ApplicationEvaluationStatusTypeEnum.valueOf(entity.getStatus()));
response.setCreatedDate(entity.getCreatedDate()); response.setCreatedDate(entity.getCreatedDate());
response.setUpdatedDate(entity.getUpdatedDate()); response.setUpdatedDate(entity.getUpdatedDate());
@@ -437,6 +439,7 @@ public class ApplicationEvaluationDao {
entity.setFile(Utils.convertObjectToJson(filterNonNullFields(processField(entity, req)))); entity.setFile(Utils.convertObjectToJson(filterNonNullFields(processField(entity, req))));
entity.setIsDeleted(false); entity.setIsDeleted(false);
setIfUpdated(entity::getNote, entity::setNote, req.getNote()); setIfUpdated(entity::getNote, entity::setNote, req.getNote());
setIfUpdated(entity::getMotivation, entity::setMotivation, req.getMotivation());
} else { } else {
entity = convertToEntity(user, req, assignedApplicationId); entity = convertToEntity(user, req, assignedApplicationId);
} }
@@ -636,6 +639,7 @@ public class ApplicationEvaluationDao {
response.setApplicationId(application.getId()); response.setApplicationId(application.getId());
response.setAssignedApplicationId(assignedApplications.getId()); response.setAssignedApplicationId(assignedApplications.getId());
response.setNote(null); response.setNote(null);
response.setMotivation(null);
response.setApplicationStatus(ApplicationStatusTypeEnum.valueOf(application.getStatus())); response.setApplicationStatus(ApplicationStatusTypeEnum.valueOf(application.getStatus()));
response.setStatus(ApplicationEvaluationStatusTypeEnum.valueOf(ApplicationEvaluationStatusTypeEnum.OPEN.getValue())); response.setStatus(ApplicationEvaluationStatusTypeEnum.valueOf(ApplicationEvaluationStatusTypeEnum.OPEN.getValue()));
response.setMinScore(call.getThreshold()!=null?call.getThreshold():null); response.setMinScore(call.getThreshold()!=null?call.getThreshold():null);

View File

@@ -58,7 +58,7 @@ public class CommunicationDao {
public ApplicationAmendmentResponse getAmendmentComments(Long amendmentId) { public ApplicationAmendmentResponse getAmendmentComments(Long amendmentId) {
ApplicationAmendmentRequestEntity amendmentData = applicationAmendmentRequestService.validateApplicationAmendmentRequest(amendmentId); ApplicationAmendmentRequestEntity amendmentData = applicationAmendmentRequestService.validateApplicationAmendmentRequest(amendmentId);
List<CommunicationResponseBean> commentsList = communicationRepository.findCommentDetailsByAmendmentId(amendmentId); List<CommunicationResponseBean> commentsList = communicationRepository.findCommentListDetailsByAmendmentId(amendmentId);
if (commentsList == null) { if (commentsList == null) {
throw new CustomValidationException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.COMMENT_NOT_FOUND)); throw new CustomValidationException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.COMMENT_NOT_FOUND));
} }

View File

@@ -109,7 +109,8 @@ public class DocumentDao {
} }
public void deleteFile(Long documentId) { public void deleteFile(Long documentId) {
DocumentEntity documentEntity = validateDocument(documentId); DocumentEntity documentEntity = documentRepository.findById(documentId).orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND)));
// String fileName= Utils.extractFileName(documentEntity.getFilePath()); // String fileName= Utils.extractFileName(documentEntity.getFilePath());
// deleteFileOnAmazonS3(fileName); // deleteFileOnAmazonS3(fileName);
documentEntity.setIsDeleted(true); documentEntity.setIsDeleted(true);
@@ -118,7 +119,7 @@ public class DocumentDao {
public DocumentEntity validateDocument(Long id) { public DocumentEntity validateDocument(Long id) {
return documentRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, return documentRepository.findByIdAndNotDeleted(id).orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND))); Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND)));
} }

View File

@@ -29,6 +29,9 @@ public class ApplicationEvaluationEntity extends BaseEntity{
@Column(name = "status") @Column(name = "status")
private String status; private String status;
@Column(name = "MOTIVATION")
private String motivation;
@Column(name="IS_DELETED") @Column(name="IS_DELETED")
private Boolean isDeleted; private Boolean isDeleted;

View File

@@ -0,0 +1,33 @@
package net.gepafin.tendermanagement.model.request;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Data;
@Data
public class AmendmentFormField {
private String fieldId;
private String fieldValue;
private String isUploadedBy;
public enum AmendmentIsUploadedByEnum {
PRE_INSTRUCTOR("PRE_INSTRUCTOR"),
BENEFICIARY("BENEFICIARY");
private String value;
AmendmentIsUploadedByEnum(String value) {
this.value = value;
}
@JsonValue
public String getValue() {
return value;
}
}
}

View File

@@ -1,9 +1,11 @@
package net.gepafin.tendermanagement.model.request; package net.gepafin.tendermanagement.model.request;
import java.util.List;
import lombok.Data; import lombok.Data;
@Data @Data
public class ApplicationAmendmentRequestBean { public class ApplicationAmendmentRequestBean {
private String note; private String note;
private ApplicationFormFieldRequestBean applicationFormFields; private List<ApplicationFormFieldRequestBean> applicationFormFields;
} }

View File

@@ -12,4 +12,5 @@ public class ApplicationEvaluationRequest {
private List<FieldRequest> files; private List<FieldRequest> files;
private String note; private String note;
private ApplicationStatusForEvaluation applicationStatus; private ApplicationStatusForEvaluation applicationStatus;
private String motivation;
} }

View File

@@ -26,6 +26,7 @@ public class ApplicationEvaluationResponse {
private String beneficiary; private String beneficiary;
private Long protocolNumber; private Long protocolNumber;
private String callName; private String callName;
private String motivation;
private LocalDateTime submissionDate; private LocalDateTime submissionDate;
private LocalDateTime evaluationDate; private LocalDateTime evaluationDate;
private LocalDateTime callEndDate; private LocalDateTime callEndDate;

View File

@@ -31,6 +31,18 @@ public class CommunicationResponseBean {
this.amendmentId = amendmentId; this.amendmentId = amendmentId;
} }
public CommunicationResponseBean(LocalDateTime commentedDate, String comment, String title, LocalDateTime createdDate, LocalDateTime updatedDate, Long amendmentId,Long senderUserId,Long receiverUserId) {
this.commentedDate = commentedDate;
this.comment = comment;
this.title = title;
this.createdDate = createdDate;
this.updatedDate = updatedDate;
this.amendmentId = amendmentId;
this.senderUserId = senderUserId;
this.receiverUserId = receiverUserId;
}
public CommunicationResponseBean() { public CommunicationResponseBean() {
} }

View File

@@ -38,4 +38,6 @@ public interface ApplicationFormFieldRepository extends JpaRepository<Applicatio
public ApplicationFormFieldEntity findByFieldId(String FieldId); public ApplicationFormFieldEntity findByFieldId(String FieldId);
Optional<ApplicationFormFieldEntity> findByApplicationFormIdAndFieldId(Long id, String fieldId); Optional<ApplicationFormFieldEntity> findByApplicationFormIdAndFieldId(Long id, String fieldId);
public List<ApplicationFormFieldEntity> findByApplicationFormIdAndFieldIdIn(Long id, List<String> fieldIds);
} }

View File

@@ -15,7 +15,8 @@ public interface CommunicationRepository extends JpaRepository<CommunicationEnti
List<CommunicationResponseBean> findCommentsByApplicationAmendmentRequestId(@Param("applicationAmendmentRequestId") Long amendmentRequestId); List<CommunicationResponseBean> findCommentsByApplicationAmendmentRequestId(@Param("applicationAmendmentRequestId") Long amendmentRequestId);
@Query("SELECT new net.gepafin.tendermanagement.model.response.CommunicationResponseBean( " + "c.commentedDate, c.communicationComment, c.communicationTitle, c.createdDate, c" + @Query("SELECT new net.gepafin.tendermanagement.model.response.CommunicationResponseBean( " + "c.commentedDate, c.communicationComment, c.communicationTitle, c.createdDate, c" +
".updatedDate, c.applicationAmendmentRequest.id) " + "FROM CommunicationEntity c " + "WHERE c.applicationAmendmentRequest.id = :amendmentId AND c.isDeleted = false") ".updatedDate, c.applicationAmendmentRequest.id,c.senderUserId, c.receiverUserId) " + "FROM CommunicationEntity c " + "WHERE c.applicationAmendmentRequest.id = :amendmentId AND c.isDeleted = false")
List<CommunicationResponseBean> findCommentDetailsByAmendmentId(@Param("amendmentId") Long amendmentId); List<CommunicationResponseBean> findCommentListDetailsByAmendmentId(@Param("amendmentId") Long amendmentId);
} }

View File

@@ -87,13 +87,12 @@ public class ApplicationAmendmentRequestServiceImpl implements ApplicationAmendm
@Override @Override
public ApplicationAmendmentRequestResponse updateApplicationAmendment(HttpServletRequest request, Long id, ApplicationAmendmentRequestBean applicationAmendmentRequestBean) { public ApplicationAmendmentRequestResponse updateApplicationAmendment(HttpServletRequest request, Long id, ApplicationAmendmentRequestBean applicationAmendmentRequestBean) {
ApplicationAmendmentRequestEntity amendment = applicationAmendmentRequestRepository.findByIdAndIsDeletedFalse(id) ApplicationAmendmentRequestEntity amendment = applicationAmendmentRequestDao.validateApplicationAmendmentRequest(id);
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.APPLICATION_AMENDMENT_NOT_FOUND_MSG)));
Optional<ApplicationEvaluationEntity> entityOptional = applicationEvaluationRepository.findByIdAndIsDeletedFalse(amendment.getApplicationEvaluationEntity().getId()); if (Boolean.FALSE.equals(validator.checkIsBeneficiary())) {
if (entityOptional.isPresent()) { validator.validatePreInstructor(request, amendment.getApplicationEvaluationEntity().getUserId());
UserEntity user = validator.validatePreInstructor(request, entityOptional.get().getUserId()); } else {
validator.validateUserId(request, amendment.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication().getUserId());
} }
return applicationAmendmentRequestDao.updateApplicationAmendment(id,applicationAmendmentRequestBean); return applicationAmendmentRequestDao.updateApplicationAmendment(id,applicationAmendmentRequestBean);
} }
@@ -105,9 +104,9 @@ public class ApplicationAmendmentRequestServiceImpl implements ApplicationAmendm
} }
@Override @Override
public List<ApplicationAmendmentRequestResponse> getAllAmendmentRequestByBeneficiaryId(HttpServletRequest request, Long beneficiaryId) { public List<ApplicationAmendmentRequestResponse> getAllAmendmentRequestByBeneficiaryId(HttpServletRequest request, Long beneficiaryUserId) {
UserEntity user= validator.validateUser(request); UserEntity user= validator.validateUser(request);
return applicationAmendmentRequestDao.getAllAmendmentRequestByBeneficiaryId(beneficiaryId); return applicationAmendmentRequestDao.getAllAmendmentRequestByBeneficiaryId(beneficiaryUserId);
} }
@Override @Override

View File

@@ -115,7 +115,7 @@ public interface ApplicationAmendmentRequestApi {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) }) @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
@GetMapping(value = "/beneficiary/user/{id}", produces = "application/json") @GetMapping(value = "/beneficiary/user/{id}", produces = "application/json")
ResponseEntity<Response<List<ApplicationAmendmentRequestResponse>>> getAllAmendmentRequestByBeneficiaryId(HttpServletRequest request, ResponseEntity<Response<List<ApplicationAmendmentRequestResponse>>> getAllAmendmentRequestByBeneficiaryId(HttpServletRequest request,
@Parameter(description = "Id", required = false) @PathVariable(value = "id",required = false) Long beneficiaryId); @Parameter(description = "Id", required = false) @PathVariable(value = "id",required = false) Long beneficiaryUserId);
@Operation(summary = "Api to extend response days for an amendment request", @Operation(summary = "Api to extend response days for an amendment request",
responses = { responses = {
@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "200", description = "OK"),

View File

@@ -76,9 +76,9 @@ public class ApplicationAmendmentRequestController implements ApplicationAmendme
} }
@Override @Override
public ResponseEntity<Response<List<ApplicationAmendmentRequestResponse>>> getAllAmendmentRequestByBeneficiaryId(HttpServletRequest request, Long beneficiaryId) { public ResponseEntity<Response<List<ApplicationAmendmentRequestResponse>>> getAllAmendmentRequestByBeneficiaryId(HttpServletRequest request, Long beneficiaryUserId) {
log.info("Get All Application Amendment Request By Beneficiary ID"); log.info("Get All Application Amendment Request By Beneficiary ID");
List<ApplicationAmendmentRequestResponse> applicationAmendmentRequestResponseList = applicationAmendmentRequestService.getAllAmendmentRequestByBeneficiaryId(request, beneficiaryId); List<ApplicationAmendmentRequestResponse> applicationAmendmentRequestResponseList = applicationAmendmentRequestService.getAllAmendmentRequestByBeneficiaryId(request, beneficiaryUserId);
return ResponseEntity.status(HttpStatus.CREATED) return ResponseEntity.status(HttpStatus.CREATED)
.body(new Response<>(applicationAmendmentRequestResponseList, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_APPLICATION_AMENDMENT_SUCCESS_MSG))); .body(new Response<>(applicationAmendmentRequestResponseList, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_APPLICATION_AMENDMENT_SUCCESS_MSG)));
} }

View File

@@ -1798,6 +1798,11 @@
<where>role_type = 'ROLE_PRE_INSTRUCTOR'</where> <where>role_type = 'ROLE_PRE_INSTRUCTOR'</where>
</update> </update>
</changeSet> </changeSet>
<changeSet id="22-11-2024_1" author="Rajesh Khore">
<addColumn tableName="application_evaluation">
<column name="MOTIVATION" type="TEXT"></column>
</addColumn>
</changeSet>
<changeSet id="26-11-2024_1" author="Rajesh Khore"> <changeSet id="26-11-2024_1" author="Rajesh Khore">
<addColumn tableName="APPLICATION"> <addColumn tableName="APPLICATION">
<column name="USER_WITH_COMPANY_ID" type="INTEGER"> <column name="USER_WITH_COMPANY_ID" type="INTEGER">
@@ -1821,4 +1826,5 @@
</column> </column>
</addColumn> </addColumn>
</changeSet> </changeSet>
</databaseChangeLog> </databaseChangeLog>