Amendment document changes

This commit is contained in:
rajesh
2024-12-18 15:58:17 +05:30
parent 94086428e8
commit 47f67975c1
8 changed files with 167 additions and 80 deletions

View File

@@ -108,6 +108,9 @@ public class ApplicationAmendmentRequestDao {
@Autowired
private ApplicationEvaluationDao applicationEvaluationDao;
@Autowired
private DocumentRepository documentRepository;
public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(Long applicationEvaluationId) {
log.info("Fetching the application data for the Amendment process {}", applicationEvaluationId);
ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluation(applicationEvaluationId);
@@ -330,15 +333,24 @@ public class ApplicationAmendmentRequestDao {
return applicationAmendment;
}
private void setAmendmentDocuments(String amendmentNotes, String amendmentFieldRequest,
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity) {
AmendmentDetailsResponseBean amendmentDetails = new AmendmentDetailsResponseBean();
if (amendmentFieldRequest != null && !amendmentFieldRequest.trim().isEmpty()) {
String[] documentIds = amendmentFieldRequest.split(",");
String validDocumentIds = Arrays.stream(documentIds)
.map(String::trim)
.filter(id -> !id.isEmpty())
.collect(Collectors.joining(","));
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));
amendmentDetails.setAmendmentDocuments(validDocumentIds);
}
if (amendmentNotes != null && !amendmentNotes.trim().isEmpty()) {
amendmentDetails.setAmendmentNotes(amendmentNotes.trim());
}
amendmentDetails.setValid(null);
String amendmentDetailsJson = Utils.convertListToJsonString(Collections.singletonList(amendmentDetails));
applicationAmendmentRequestEntity.setAmendmentDocument(amendmentDetailsJson);
}
public ApplicationAmendmentRequestEntity saveApplicationAmendmentRequestEntity(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity,ApplicationAmendmentRequestEntity oldApplicationAmendmentEntity,VersionActionTypeEnum actionTypeEnum) {
@@ -355,39 +367,70 @@ public class ApplicationAmendmentRequestDao {
List<ApplicationFormEntity> forms = applicationFormRepository.findByApplicationId(applicationAmendmentRequestEntity.getApplicationId());
Map<String, String> fieldIdToLabelMap = extractFieldIdToLabelMap(forms);
List<AmendmentFieldRequest> amendmentFieldRequests= new ArrayList<>();
// List<AmendmentFieldRequest> amendmentFieldRequests= new ArrayList<>();
List<AmendmentFormField> amendmentFormFields = Utils.convertJsonStringToList(
applicationAmendmentRequestEntity.getFormFields(), AmendmentFormField.class);
Map<String, ApplicationFormFieldEntity> formFieldEntityMap = getApplicationFormFieldEntityMap(applicationAmendmentRequestEntity, amendmentFormFields);
if(applicationAmendmentRequestEntity.getAmendmentDocument() !=null ){
amendmentFieldRequests = Utils.convertJsonStringToList(applicationAmendmentRequestEntity.getAmendmentDocument(),AmendmentFieldRequest.class);
}
if (amendmentFieldRequests != null) {
List<AmendmentDocumentResponse> amendmentDocumentResponses = amendmentFieldRequests.stream()
.map(this::createAmendmentDocumentResponse)
.toList();
response.setAmendmentDocuments(amendmentDocumentResponses);
if (applicationAmendmentRequestEntity.getAmendmentDocument() != null) {
List<AmendmentDetailsResponseBean> amendmentDetailsList =
Utils.convertJsonStringToList(applicationAmendmentRequestEntity.getAmendmentDocument(),
AmendmentDetailsResponseBean.class);
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
for (AmendmentDetailsResponseBean amendmentDetails:amendmentDetailsList) {
if (amendmentDetails.getAmendmentDocuments()!=null) {
// Extract the comma-separated document IDs as a string
String documentIdsString = amendmentDetails.getAmendmentDocuments();
if (documentIdsString != null && !documentIdsString.trim().isEmpty()) {
// Split the comma-separated values and process them
List<String> documentIds = Arrays.stream(documentIdsString.split(","))
.map(String::trim)
.filter(id -> !id.isEmpty())
.collect(Collectors.toList());
documentResponseBeans.addAll(
documentIds.stream()
.map(id -> {
try {
return createDocumentResponseBean(id); // Convert to Long
} catch (NumberFormatException e) {
// Handle invalid document IDs gracefully
return null;
}
})
.filter(Objects::nonNull) // Skip null responses
.collect(Collectors.toList())
);
response.setAmendmentNotes(amendmentDetails.getAmendmentNotes());
response.setValid(amendmentDetails.getValid()!=null?amendmentDetails.getValid():null);
}
}
}
response.setAmendmentDocuments(documentResponseBeans);
}
processFormFields(amendmentFormFields, fieldIdToLabelMap, formFieldEntityMap, response);
return response;
}
public AmendmentDocumentResponse createAmendmentDocumentResponse(AmendmentFieldRequest amendmentFieldRequest) {
AmendmentDocumentResponse amendmentDocumentResponse = new AmendmentDocumentResponse();
amendmentDocumentResponse.setFieldId(amendmentFieldRequest.getFieldId());
amendmentDocumentResponse.setNameValue(amendmentFieldRequest.getNameValue());
amendmentDocumentResponse.setValid(amendmentFieldRequest.getValid());
amendmentDocumentResponse.setFileValue(null);
if(amendmentFieldRequest.getFileValue()!=null) {
DocumentEntity documentEntity = documentService.validateDocument(Long.valueOf(amendmentFieldRequest.getFileValue()));
DocumentResponseBean responseBean = applicationEvaluationDao.createDocumentResponseBean(documentEntity);
amendmentDocumentResponse.setFileValue(List.of(responseBean));
}
public DocumentResponseBean createDocumentResponseBean(String documentId) {
return amendmentDocumentResponse;
if (!StringUtils.isEmpty(documentId)) {
Optional<DocumentEntity> documentEntity = documentRepository.findByIdAndNotDeleted(Long.valueOf(documentId));
if(documentEntity.isPresent()){
return applicationEvaluationDao.createDocumentResponseBean(documentEntity.get());
}}
return null;
}
private ApplicationAmendmentRequestResponse initializeBasicResponse(ApplicationAmendmentRequestEntity entity) {
ApplicationAmendmentRequestResponse response = new ApplicationAmendmentRequestResponse();
response.setId(entity.getId());
@@ -581,7 +624,7 @@ public class ApplicationAmendmentRequestDao {
}
existingApplicationAmendment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
if(updateRequest.getAmendmentDocuments()!=null && Boolean.FALSE.equals(updateRequest.getAmendmentDocuments().isEmpty())) {
setAmendmentDocuments(updateRequest.getAmendmentDocuments(), existingApplicationAmendment);
setAmendmentDocuments(updateRequest.getAmendmentNotes(),updateRequest.getAmendmentDocuments(), existingApplicationAmendment);
}
ApplicationAmendmentRequestEntity updatedApplicationAmendment = saveApplicationAmendmentRequestEntity(existingApplicationAmendment,oldApplicationAmendmentEntity,VersionActionTypeEnum.UPDATE);
ApplicationAmendmentRequestResponse response = convertEntityToResponse(updatedApplicationAmendment);