Rename 'updatedFormFields' to 'applicationFormFields' in request and also fix the bug
This commit is contained in:
@@ -21,6 +21,8 @@ import net.gepafin.tendermanagement.model.response.ApplicationAmendmentRequestRe
|
|||||||
import net.gepafin.tendermanagement.repositories.*;
|
import net.gepafin.tendermanagement.repositories.*;
|
||||||
import net.gepafin.tendermanagement.service.*;
|
import net.gepafin.tendermanagement.service.*;
|
||||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||||
|
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.ResourceNotFoundException;
|
||||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -28,7 +30,6 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
|
||||||
|
|
||||||
@@ -84,6 +85,9 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private AssignedApplicationsRepository assignedApplicationsRepository;
|
private AssignedApplicationsRepository assignedApplicationsRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private Validator validator;
|
||||||
|
|
||||||
public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(HttpServletRequest request, Long applicationEvaluationId) {
|
public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(HttpServletRequest request, Long applicationEvaluationId) {
|
||||||
log.info("Fetching the application data for the Amendment process {}", applicationEvaluationId);
|
log.info("Fetching the application data for the Amendment process {}", applicationEvaluationId);
|
||||||
ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluation(applicationEvaluationId);
|
ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluation(applicationEvaluationId);
|
||||||
@@ -326,7 +330,14 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ApplicationAmendmentRequestResponse> getAllApplicationAmendmentRequest(Long userId) {
|
public List<ApplicationAmendmentRequestResponse> getAllApplicationAmendmentRequest(HttpServletRequest request,Long userId) {
|
||||||
|
UserEntity user = validator.validateUser(request);
|
||||||
|
if(validator.checkIsPreInstructor() && userId == null) {
|
||||||
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.USER_ID_NOT_NULL_MSG));
|
||||||
|
}
|
||||||
|
if(userId != null) {
|
||||||
|
validator.validatePreInstructor(request, userId);
|
||||||
|
}
|
||||||
Specification<ApplicationAmendmentRequestEntity> spec = search(userId);
|
Specification<ApplicationAmendmentRequestEntity> spec = search(userId);
|
||||||
List<ApplicationAmendmentRequestEntity> applicationAmendmentRequestEntities =
|
List<ApplicationAmendmentRequestEntity> applicationAmendmentRequestEntities =
|
||||||
applicationAmendmentRequestRepository.findAll(spec);
|
applicationAmendmentRequestRepository.findAll(spec);
|
||||||
@@ -357,8 +368,8 @@ 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.getUpdatedFormFields() != null) {
|
if (updateRequest.getApplicationFormFields() != null) {
|
||||||
updateApplicationFormFields(existingApplicationAmendment, updateRequest.getUpdatedFormFields());
|
updateApplicationFormFields(existingApplicationAmendment, updateRequest.getApplicationFormFields());
|
||||||
}
|
}
|
||||||
existingApplicationAmendment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
existingApplicationAmendment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||||
|
|
||||||
@@ -368,27 +379,52 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void updateApplicationFormFields(ApplicationAmendmentRequestEntity applicationAmendment, ApplicationFormFieldRequestBean updatedFormField) {
|
private void updateApplicationFormFields(ApplicationAmendmentRequestEntity applicationAmendment, ApplicationFormFieldRequestBean updatedFormField) {
|
||||||
|
if (updatedFormField.getFieldValue() == null || "".equals(updatedFormField.getFieldValue().toString().trim())) {
|
||||||
|
List<ApplicationFormEntity> applicationForms = applicationFormRepository.findByApplicationId(applicationAmendment.getApplicationId());
|
||||||
|
|
||||||
|
boolean fieldUpdated = false;
|
||||||
|
|
||||||
|
for (ApplicationFormEntity applicationForm : applicationForms) {
|
||||||
|
Optional<ApplicationFormFieldEntity> formFieldEntityOptional = applicationFormFieldRepository
|
||||||
|
.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;
|
List<String> documentIds;
|
||||||
|
|
||||||
// Check if fieldValue is an array
|
if (updatedFormField.getFieldValue() instanceof String && updatedFormField.getFieldValue() != null) {
|
||||||
if (updatedFormField.getFieldValue() instanceof List) {
|
documentIds = Arrays.asList(((String) updatedFormField.getFieldValue()).split(","));
|
||||||
documentIds = ((List<?>) updatedFormField.getFieldValue()).stream()
|
|
||||||
.map(Object::toString)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
} else {
|
} else {
|
||||||
log.warn("Expected fieldValue as a list but got: {}", updatedFormField.getFieldValue());
|
log.warn("Expected fieldValue as a comma-separated String but got: {}", updatedFormField.getFieldValue());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> validDocumentIds = new ArrayList<>();
|
List<String> validDocumentIds = new ArrayList<>();
|
||||||
for (String documentId : documentIds) {
|
for (String documentId : documentIds) {
|
||||||
DocumentEntity documentEntity = documentService.validateDocument(Long.parseLong(documentId));
|
try {
|
||||||
if (documentEntity != null) {
|
DocumentEntity documentEntity = documentService.validateDocument(Long.parseLong(documentId.trim()));
|
||||||
validDocumentIds.add(documentId);
|
if (documentEntity != null) {
|
||||||
} else {
|
validDocumentIds.add(documentId.trim());
|
||||||
log.warn("Document with ID {} does not exist. Skipping this ID.", documentId);
|
} 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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -413,8 +449,7 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!fieldUpdated) {
|
if (!fieldUpdated) {
|
||||||
log.warn("No ApplicationFormFieldEntity found for application ID {} and field ID {}. Skipping update.",
|
throw new CustomValidationException(Status.NOT_FOUND,"No ApplicationFormField found for application ID {} and field ID {}. Skipping update.");
|
||||||
applicationAmendment.getApplicationId(), updatedFormField.getFieldId());
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.warn("No valid document IDs found for update. Skipping field ID {}", updatedFormField.getFieldId());
|
log.warn("No valid document IDs found for update. Skipping field ID {}", updatedFormField.getFieldId());
|
||||||
@@ -422,8 +457,9 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<ApplicationAmendmentRequestResponse> getAllAmendmentRequestByBeneficiaryId(Long beneficiaryId) {
|
|
||||||
|
|
||||||
|
public List<ApplicationAmendmentRequestResponse> getAllAmendmentRequestByBeneficiaryId(Long beneficiaryId) {
|
||||||
|
UserEntity userEntity = userService.validateUser(beneficiaryId);
|
||||||
List<ApplicationAmendmentRequestEntity> entities =
|
List<ApplicationAmendmentRequestEntity> entities =
|
||||||
applicationAmendmentRequestRepository.findByUserId(beneficiaryId);
|
applicationAmendmentRequestRepository.findByUserId(beneficiaryId);
|
||||||
|
|
||||||
|
|||||||
@@ -5,5 +5,5 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
public class ApplicationAmendmentRequestBean {
|
public class ApplicationAmendmentRequestBean {
|
||||||
private String note;
|
private String note;
|
||||||
private ApplicationFormFieldRequestBean updatedFormFields;
|
private ApplicationFormFieldRequestBean applicationFormFields;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import net.gepafin.tendermanagement.dao.ApplicationAmendmentRequestDao;
|
|||||||
import net.gepafin.tendermanagement.entities.ApplicationAmendmentRequestEntity;
|
import net.gepafin.tendermanagement.entities.ApplicationAmendmentRequestEntity;
|
||||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||||
import net.gepafin.tendermanagement.enums.ApplicationAmendmentRequestEnum;
|
import net.gepafin.tendermanagement.enums.ApplicationAmendmentRequestEnum;
|
||||||
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
|
||||||
import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequest;
|
import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequest;
|
||||||
import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequestBean;
|
import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequestBean;
|
||||||
import net.gepafin.tendermanagement.model.request.CloseAmendmentRequest;
|
import net.gepafin.tendermanagement.model.request.CloseAmendmentRequest;
|
||||||
@@ -50,7 +49,7 @@ public class ApplicationAmendmentRequestServiceImpl implements ApplicationAmendm
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ApplicationAmendmentRequestResponse> getAllApplicationAmendmentRequest(HttpServletRequest request,Long userId) {
|
public List<ApplicationAmendmentRequestResponse> getAllApplicationAmendmentRequest(HttpServletRequest request,Long userId) {
|
||||||
return applicationAmendmentRequestDao.getAllApplicationAmendmentRequest(userId);
|
return applicationAmendmentRequestDao.getAllApplicationAmendmentRequest(request,userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user