Code for amendment module
This commit is contained in:
@@ -105,12 +105,33 @@ public class ApplicationAmendmentRequestDao {
|
||||
@Autowired
|
||||
private AssignedApplicationsDao assignedApplicationsDao;
|
||||
|
||||
@Autowired
|
||||
private ApplicationEvaluationDao applicationEvaluationDao;
|
||||
|
||||
public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(Long applicationEvaluationId) {
|
||||
log.info("Fetching the application data for the Amendment process {}", applicationEvaluationId);
|
||||
ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluation(applicationEvaluationId);
|
||||
Long applicationId = applicationEvaluationEntity.getApplicationId();
|
||||
ApplicationEntity application = applicationService.validateApplication(applicationId);
|
||||
List<FieldRequest> evaluationFileRequests=new ArrayList<>();
|
||||
List<ChecklistRequest> checklistRequests=new ArrayList<>();
|
||||
|
||||
ApplicationEntity application = applicationService.validateApplication(applicationId);
|
||||
String file=applicationEvaluationEntity.getFile();
|
||||
String checkList=applicationEvaluationEntity.getChecklist();
|
||||
if(file != null){
|
||||
evaluationFileRequests=Utils.convertJsonStringToList(file,FieldRequest.class);
|
||||
}
|
||||
Boolean allValid = evaluationFileRequests.stream()
|
||||
.anyMatch(fieldRequest -> fieldRequest.getValid() == null);
|
||||
if(checkList != null) {
|
||||
checklistRequests=Utils.convertJsonStringToList(checkList,ChecklistRequest.class);
|
||||
}
|
||||
boolean resultCheckList = checklistRequests.stream()
|
||||
.anyMatch(checklistRequest -> Boolean.TRUE.equals(checklistRequest.getValid())) ? false : true;
|
||||
|
||||
if(Boolean.TRUE.equals(allValid) || Boolean.TRUE.equals(resultCheckList)){
|
||||
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.All_DOCUMENT_CHECKED_AND_ONE_CHECKLIST_CHECKED));
|
||||
}
|
||||
// Set common application-level details
|
||||
String callName = application.getCall().getName();
|
||||
Long protocolNumber = (application.getProtocol() != null && application.getProtocol().getProtocolNumber() != null)
|
||||
@@ -135,11 +156,18 @@ public class ApplicationAmendmentRequestDao {
|
||||
|
||||
List<ApplicationFormEntity> forms = applicationFormRepository.findByApplicationId(applicationId);
|
||||
List<AmendmentFormFieldResponse> allFormFields = new ArrayList<>();
|
||||
|
||||
Map<String, FieldRequest> fieldRequestMap = evaluationFileRequests.stream()
|
||||
.collect(Collectors.toMap(FieldRequest::getId, fieldRequest -> fieldRequest));
|
||||
for (ApplicationFormEntity form : forms) {
|
||||
String content = form.getForm().getContent();
|
||||
List<Map<String, Object>> result = filterByName(content, "fileupload");
|
||||
allFormFields.addAll(getIdAndLabelFromResult(result));
|
||||
List<AmendmentFormFieldResponse> amendmentFormFieldResponses= getIdAndLabelFromResult(result);
|
||||
amendmentFormFieldResponses.removeIf(amendmentFormFieldResponse -> {
|
||||
FieldRequest matchingRequest = fieldRequestMap.get(amendmentFormFieldResponse.getFieldId());
|
||||
// Remove if no matching FieldRequest exists or if valid is true
|
||||
return matchingRequest == null || Boolean.TRUE.equals(matchingRequest.getValid());
|
||||
});
|
||||
allFormFields.addAll(amendmentFormFieldResponses);
|
||||
}
|
||||
|
||||
response.setFormFields(allFormFields);
|
||||
@@ -243,6 +271,9 @@ public class ApplicationAmendmentRequestDao {
|
||||
String formFieldsJson = Utils.convertObjectToJson(formFieldRequestBean);
|
||||
applicationAmendmentRequestEntity.setFormFields(formFieldsJson);
|
||||
}
|
||||
if(Boolean.FALSE.equals(applicationAmendmentRequest.getAmendmentDocument().isEmpty())) {
|
||||
setAmendmentDocuments(applicationAmendmentRequest.getAmendmentDocument(), applicationAmendmentRequestEntity);
|
||||
}
|
||||
List<ApplicationAmendmentRequestEntity> amendmentRequest = applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(applicationEvaluationEntity.getId());
|
||||
// Ensure startDate and initialDays are not null to avoid NullPointerException
|
||||
if (amendmentRequest !=null && amendmentRequest.isEmpty() && applicationEvaluationEntity.getStartDate() != null && applicationEvaluationEntity.getInitialDays() != null ) {
|
||||
@@ -261,7 +292,7 @@ public class ApplicationAmendmentRequestDao {
|
||||
Long protocolNumber = protocolDao.getProtocolNumber(userEntity.getHub());
|
||||
ProtocolEntity protocolEntity = protocolDao.createProtocolEntity(
|
||||
applicationEvaluationEntity.getAssignedApplicationsEntity().getApplication(), protocolNumber,
|
||||
userEntity.getHub().getId());
|
||||
userEntity.getHub().getId(),false);
|
||||
applicationAmendmentRequestEntity.setProtocol(protocolEntity);
|
||||
ApplicationAmendmentRequestEntity applicationAmendment = saveApplicationAmendmentRequestEntity(applicationAmendmentRequestEntity, null, VersionActionTypeEnum.INSERT);
|
||||
String evaluationStatusType = applicationEvaluationEntity.getStatus();
|
||||
@@ -302,6 +333,16 @@ public class ApplicationAmendmentRequestDao {
|
||||
return applicationAmendment;
|
||||
}
|
||||
|
||||
private void setAmendmentDocuments(List<AmendmentFieldRequest> amendmentFieldRequest, ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity) {
|
||||
amendmentFieldRequest.stream().forEach(amendmentData->{
|
||||
String fieldValue=amendmentData.getFileValue();
|
||||
if(fieldValue!=null){
|
||||
documentService.validateDocument(Long.valueOf(fieldValue));
|
||||
}
|
||||
});
|
||||
applicationAmendmentRequestEntity.setAmendmentDocument(Utils.convertListToJsonString(amendmentFieldRequest));
|
||||
}
|
||||
|
||||
public ApplicationAmendmentRequestEntity saveApplicationAmendmentRequestEntity(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity,ApplicationAmendmentRequestEntity oldApplicationAmendmentEntity,VersionActionTypeEnum actionTypeEnum) {
|
||||
ApplicationAmendmentRequestEntity applicationAmendmentRequest = applicationAmendmentRequestRepository.save(applicationAmendmentRequestEntity);
|
||||
|
||||
@@ -320,12 +361,31 @@ public class ApplicationAmendmentRequestDao {
|
||||
List<AmendmentFormField> amendmentFormFields = Utils.convertJsonStringToList(
|
||||
applicationAmendmentRequestEntity.getFormFields(), AmendmentFormField.class);
|
||||
Map<String, ApplicationFormFieldEntity> formFieldEntityMap = getApplicationFormFieldEntityMap(applicationAmendmentRequestEntity, amendmentFormFields);
|
||||
|
||||
List<AmendmentFieldRequest> amendmentFieldRequests = Utils.convertJsonStringToList(applicationAmendmentRequestEntity.getAmendmentDocument(),AmendmentFieldRequest.class);
|
||||
if (amendmentFieldRequests != null) {
|
||||
List<AmendmentDocumentResponse> amendmentDocumentResponses = amendmentFieldRequests.stream()
|
||||
.map(this::createAmendmentDocumentResponse)
|
||||
.toList();
|
||||
response.setAmendmentDocuments(amendmentDocumentResponses);
|
||||
}
|
||||
processFormFields(amendmentFormFields, fieldIdToLabelMap, formFieldEntityMap, response);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private AmendmentDocumentResponse createAmendmentDocumentResponse(AmendmentFieldRequest amendmentFieldRequest) {
|
||||
AmendmentDocumentResponse amendmentDocumentResponse = new AmendmentDocumentResponse();
|
||||
amendmentDocumentResponse.setFieldId(amendmentFieldRequest.getFieldId());
|
||||
amendmentDocumentResponse.setNameValue(amendmentFieldRequest.getNameValue());
|
||||
amendmentDocumentResponse.setIsValid(amendmentFieldRequest.getIsValid());
|
||||
|
||||
DocumentEntity documentEntity = documentService.validateDocument(Long.valueOf(amendmentFieldRequest.getFileValue()));
|
||||
DocumentResponseBean responseBean = applicationEvaluationDao.createDocumentResponseBean(documentEntity);
|
||||
amendmentDocumentResponse.setFileValue(responseBean);
|
||||
|
||||
return amendmentDocumentResponse;
|
||||
}
|
||||
|
||||
private ApplicationAmendmentRequestResponse initializeBasicResponse(ApplicationAmendmentRequestEntity entity) {
|
||||
ApplicationAmendmentRequestResponse response = new ApplicationAmendmentRequestResponse();
|
||||
response.setId(entity.getId());
|
||||
@@ -519,6 +579,7 @@ public class ApplicationAmendmentRequestDao {
|
||||
}
|
||||
existingApplicationAmendment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||
|
||||
setAmendmentDocuments(updateRequest.getAmendmentDocuments(),existingApplicationAmendment);
|
||||
ApplicationAmendmentRequestEntity updatedApplicationAmendment = saveApplicationAmendmentRequestEntity(existingApplicationAmendment,oldApplicationAmendmentEntity,VersionActionTypeEnum.UPDATE);
|
||||
ApplicationAmendmentRequestResponse response = convertEntityToResponse(updatedApplicationAmendment);
|
||||
log.info("Application Amendment updated successfully: {}", response);
|
||||
@@ -585,7 +646,7 @@ public class ApplicationAmendmentRequestDao {
|
||||
String fieldId) {
|
||||
AmendmentFormField amendmentFormField = amendmentFormFieldMap.get(fieldId);
|
||||
if (amendmentFormField == null) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, GepafinConstant.APPLICATION_FORM_FIELD_NOT_FOUND);
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_FORM_FIELD_NOT_FOUND));
|
||||
}
|
||||
return amendmentFormField;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user