Issue With Application Deleted Documents

This commit is contained in:
rajesh
2024-11-20 11:40:12 +05:30
parent bab6fcfad6
commit 334f4b3a79
3 changed files with 126 additions and 58 deletions

View File

@@ -96,6 +96,8 @@ public class ApplicationAmendmentRequestDao {
@Autowired
private Validator validator;
@Autowired
private ApplicationDao applicationDao;
public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(Long applicationEvaluationId) {
log.info("Fetching the application data for the Amendment process {}", applicationEvaluationId);
@@ -556,11 +558,10 @@ public class ApplicationAmendmentRequestDao {
// Add valid new document IDs from the request
existingDocumentIds.addAll(validDocumentIds);
applicationDao.updateDocumentDeletionStatus(formEntity, updatedFormField, formEntity.getApplicationForm().getForm(), null,validDocumentIds);
// 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;

View File

@@ -405,7 +405,7 @@ public class ApplicationDao {
ApplicationFormFieldEntity applicationFormFieldEntity=null;
validateFileUploadDocuments(applicationFormFieldRequestBean, formEntity);
List<Long> newDocumentIds =validateFileUploadDocuments(applicationFormFieldRequestBean, formEntity);
if(applicationFormFieldEntities==null || applicationFormFieldEntities.isEmpty()){
applicationFormFieldEntity = new ApplicationFormFieldEntity();
@@ -427,6 +427,7 @@ public class ApplicationDao {
Utils.setIfUpdated(applicationFormFieldEntity::getFieldId, applicationFormFieldEntity::setFieldId, applicationFormFieldRequestBean.getFieldId());
if(applicationFormFieldRequestBean.getFieldValue() !=null ) {
updateDocumentDeletionStatus(applicationFormFieldEntity, applicationFormFieldRequestBean,formEntity,newDocumentIds,null);
applicationFormFieldEntity.setFieldValue(Utils.convertObjectToJsonString(applicationFormFieldRequestBean.getFieldValue()));
}
if(applicationFormFieldRequestBean.getFieldValue() ==null ) {
@@ -434,6 +435,65 @@ public class ApplicationDao {
}
return applicationFormFieldRepository.save(applicationFormFieldEntity);
}
void updateDocumentDeletionStatus(ApplicationFormFieldEntity applicationFormFieldEntity, ApplicationFormFieldRequestBean applicationFormFieldRequestBean, FormEntity formEntity, List<Long> newDocumentIds,
List<String> preInstructorDocumentId) {
if (newDocumentIds == null) {
newDocumentIds = Collections.emptyList();
}
if (preInstructorDocumentId == null) {
preInstructorDocumentId = Collections.emptyList();
}
List<ContentResponseBean> contentResponseBeans = formDao.convertFormEntityToFormResponseBean(formEntity).getContent();
for (ContentResponseBean contentResponseBean : contentResponseBeans) {
if (Boolean.FALSE.equals(contentResponseBean.getName().equals("fileupload"))) {
return;
}
}
List<Long> currentDocumentIds = parseDocumentIds(applicationFormFieldEntity.getFieldValue());
if (Boolean.FALSE.equals(newDocumentIds.isEmpty())) {
List<Long> finalNewDocumentIds = newDocumentIds;
List<Long> documentsToDelete = currentDocumentIds.stream()
.filter(docId -> !finalNewDocumentIds.contains(docId))
.toList();
documentsToDelete.forEach(docId -> documentService.deleteFile(docId));
}
if (Boolean.FALSE.equals(preInstructorDocumentId.isEmpty())){
List<Long> preInstructorDocIds = preInstructorDocumentId.stream()
.map(Long::valueOf)
.collect(Collectors.toList());
List<Long> documentsToDelete = currentDocumentIds.stream()
.filter(docId -> !preInstructorDocIds.contains(docId))
.toList();
documentsToDelete.forEach(docId -> documentService.deleteFile(docId));
}
}
private List<Long> parseDocumentIds(String fieldValue) {
if (fieldValue == null || fieldValue.isEmpty()) {
return Collections.emptyList();
}
if (fieldValue.contains(",")) {
return Arrays.stream(fieldValue.split(","))
.map(String::trim)
.map(Long::parseLong)
.collect(Collectors.toList());
} else {
try {
return Collections.singletonList(Long.parseLong(fieldValue.trim()));
} catch (NumberFormatException e) {
e.printStackTrace();
return Collections.emptyList();
}
}
}
private List<Long> validateFileUploadDocuments(ApplicationFormFieldRequestBean applicationFormFieldRequestBean, FormEntity formEntity) {
List<Long> documentIds=null;

View File

@@ -249,6 +249,7 @@ public class ApplicationEvaluationDao {
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
for (String docId : documentIds) {
if (Boolean.FALSE.equals(docId.isEmpty())){
Long documentId = Long.valueOf(docId.trim());
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
DocumentResponseBean responseBean = new DocumentResponseBean();
@@ -263,6 +264,7 @@ public class ApplicationEvaluationDao {
documentResponseBeans.add(responseBean);
});
}
}
mappedField.setFieldValue(documentResponseBeans);
}
}
@@ -351,6 +353,7 @@ public class ApplicationEvaluationDao {
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
for (String docId : documentIds) {
if (Boolean.FALSE.equals(docId.isEmpty())){
Long documentId = Long.valueOf(docId.trim());
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
DocumentResponseBean responseBean = new DocumentResponseBean();
@@ -365,6 +368,7 @@ public class ApplicationEvaluationDao {
documentResponseBeans.add(responseBean);
});
}
}
fieldResponse.setFileDetail(documentResponseBeans);
}
@@ -888,6 +892,7 @@ public class ApplicationEvaluationDao {
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
for (String docId : documentIds) {
if (Boolean.FALSE.equals(docId.isEmpty())) {
Long documentId = Long.valueOf(docId.trim());
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
DocumentResponseBean responseBean = new DocumentResponseBean();
@@ -902,6 +907,7 @@ public class ApplicationEvaluationDao {
documentResponseBeans.add(responseBean);
});
}
}
fieldResponse.setFileDetail(documentResponseBeans);
}
@@ -1247,6 +1253,7 @@ public class ApplicationEvaluationDao {
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
for (String docId : documentIds) {
if (Boolean.FALSE.equals(docId.isEmpty())){
Long documentId = Long.valueOf(docId.trim());
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
DocumentResponseBean responseBean = new DocumentResponseBean();
@@ -1261,7 +1268,7 @@ public class ApplicationEvaluationDao {
documentResponseBeans.add(responseBean);
});
}
}
fieldResponse.setFileDetail(documentResponseBeans);
fieldResponses.add(fieldResponse);
}