Merge pull request #99 from Kitzanos/feature/GEPAFINBE-101

GEPAFINBE-101 (Issue With Application Deleted Documents)
This commit is contained in:
rajeshkhore
2024-11-21 16:49:01 +05:30
committed by GitHub
3 changed files with 132 additions and 58 deletions

View File

@@ -93,6 +93,8 @@ public class ApplicationAmendmentRequestDao {
@Autowired @Autowired
private Validator validator; private Validator validator;
@Autowired
private ApplicationDao applicationDao;
@Autowired @Autowired
private EmailLogDao emailLogDao; private EmailLogDao emailLogDao;
@@ -560,11 +562,10 @@ public class ApplicationAmendmentRequestDao {
// Add valid new document IDs from the request // Add valid new document IDs from the request
existingDocumentIds.addAll(validDocumentIds); existingDocumentIds.addAll(validDocumentIds);
applicationDao.updateDocumentDeletionStatus(formEntity, updatedFormField, formEntity.getApplicationForm().getForm(), null,validDocumentIds,true);
// Set the combined document IDs back as the field value // Set the combined document IDs back as the field value
formEntity.setFieldValue(String.join(",", existingDocumentIds)); formEntity.setFieldValue(String.join(",", existingDocumentIds));
applicationFormFieldRepository.save(formEntity); applicationFormFieldRepository.save(formEntity);
log.info("Updated field value for application ID {} and field ID {} with document IDs {}", log.info("Updated field value for application ID {} and field ID {} with document IDs {}",
applicationAmendment.getApplicationId(), updatedFormField.getFieldId(), String.join(",", existingDocumentIds)); applicationAmendment.getApplicationId(), updatedFormField.getFieldId(), String.join(",", existingDocumentIds));
fieldUpdated = true; fieldUpdated = true;

View File

@@ -412,7 +412,7 @@ public class ApplicationDao {
ApplicationFormFieldEntity applicationFormFieldEntity=null; ApplicationFormFieldEntity applicationFormFieldEntity=null;
validateFileUploadDocuments(applicationFormFieldRequestBean, formEntity); List<Long> newDocumentIds =validateFileUploadDocuments(applicationFormFieldRequestBean, formEntity);
if(applicationFormFieldEntities==null || applicationFormFieldEntities.isEmpty()){ if(applicationFormFieldEntities==null || applicationFormFieldEntities.isEmpty()){
applicationFormFieldEntity = new ApplicationFormFieldEntity(); applicationFormFieldEntity = new ApplicationFormFieldEntity();
@@ -434,13 +434,79 @@ public class ApplicationDao {
Utils.setIfUpdated(applicationFormFieldEntity::getFieldId, applicationFormFieldEntity::setFieldId, applicationFormFieldRequestBean.getFieldId()); Utils.setIfUpdated(applicationFormFieldEntity::getFieldId, applicationFormFieldEntity::setFieldId, applicationFormFieldRequestBean.getFieldId());
if(applicationFormFieldRequestBean.getFieldValue() !=null ) { if(applicationFormFieldRequestBean.getFieldValue() !=null ) {
applicationFormFieldEntity.setFieldValue(Utils.convertObjectToJsonString(applicationFormFieldRequestBean.getFieldValue())); updateDocumentDeletionStatus(applicationFormFieldEntity, applicationFormFieldRequestBean,formEntity,newDocumentIds,null,false);
} applicationFormFieldEntity.setFieldValue(Utils.convertObjectToJsonString(applicationFormFieldRequestBean.getFieldValue()));
}
if(applicationFormFieldRequestBean.getFieldValue() ==null ) { if(applicationFormFieldRequestBean.getFieldValue() ==null ) {
updateDocumentDeletionStatus(applicationFormFieldEntity, applicationFormFieldRequestBean,formEntity,newDocumentIds,null,false);
applicationFormFieldEntity.setFieldValue(null); applicationFormFieldEntity.setFieldValue(null);
} }
return applicationFormFieldRepository.save(applicationFormFieldEntity); return applicationFormFieldRepository.save(applicationFormFieldEntity);
} }
void updateDocumentDeletionStatus(ApplicationFormFieldEntity applicationFormFieldEntity, ApplicationFormFieldRequestBean applicationFormFieldRequestBean, FormEntity formEntity, List<Long> newDocumentIds,
List<String> preInstructorDocumentId,boolean isPreInstructor) {
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;
}
}
if(!isPreInstructor){
List<Long> currentDocumentIds = parseDocumentIds(applicationFormFieldEntity.getFieldValue());
if (Boolean.TRUE.equals(newDocumentIds.isEmpty())) {
currentDocumentIds.forEach(docId -> documentService.deleteFile(docId));
} else {
List<Long> finalNewDocumentIds = newDocumentIds;
List<Long> documentsToDelete = currentDocumentIds.stream()
.filter(docId -> !finalNewDocumentIds.contains(docId))
.toList();
documentsToDelete.forEach(docId -> documentService.deleteFile(docId));
}}
else{
List<Long> currentDocumentIds = parseDocumentIds(applicationFormFieldEntity.getFieldValue());
if (Boolean.TRUE.equals(preInstructorDocumentId.isEmpty())) {
currentDocumentIds.forEach(docId -> documentService.deleteFile(docId));
} else {
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) { private List<Long> validateFileUploadDocuments(ApplicationFormFieldRequestBean applicationFormFieldRequestBean, FormEntity formEntity) {
List<Long> documentIds=null; List<Long> documentIds=null;

View File

@@ -249,19 +249,21 @@ public class ApplicationEvaluationDao {
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>(); List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
for (String docId : documentIds) { for (String docId : documentIds) {
Long documentId = Long.valueOf(docId.trim()); if (Boolean.FALSE.equals(docId.isEmpty())){
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> { Long documentId = Long.valueOf(docId.trim());
DocumentResponseBean responseBean = new DocumentResponseBean(); documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
responseBean.setId(documentEntity.getId()); DocumentResponseBean responseBean = new DocumentResponseBean();
responseBean.setName(documentEntity.getFileName()); responseBean.setId(documentEntity.getId());
responseBean.setType(DocumentTypeEnum.valueOf(documentEntity.getType())); responseBean.setName(documentEntity.getFileName());
responseBean.setSource(DocumentSourceTypeEnum.valueOf(documentEntity.getSource())); responseBean.setType(DocumentTypeEnum.valueOf(documentEntity.getType()));
responseBean.setSourceId(documentEntity.getSourceId()); responseBean.setSource(DocumentSourceTypeEnum.valueOf(documentEntity.getSource()));
responseBean.setFilePath(documentEntity.getFilePath()); responseBean.setSourceId(documentEntity.getSourceId());
responseBean.setCreatedDate(documentEntity.getCreatedDate()); responseBean.setFilePath(documentEntity.getFilePath());
responseBean.setUpdatedDate(documentEntity.getUpdatedDate()); responseBean.setCreatedDate(documentEntity.getCreatedDate());
documentResponseBeans.add(responseBean); responseBean.setUpdatedDate(documentEntity.getUpdatedDate());
}); documentResponseBeans.add(responseBean);
});
}
} }
mappedField.setFieldValue(documentResponseBeans); mappedField.setFieldValue(documentResponseBeans);
} }
@@ -351,19 +353,21 @@ public class ApplicationEvaluationDao {
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>(); List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
for (String docId : documentIds) { for (String docId : documentIds) {
Long documentId = Long.valueOf(docId.trim()); if (Boolean.FALSE.equals(docId.isEmpty())){
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> { Long documentId = Long.valueOf(docId.trim());
DocumentResponseBean responseBean = new DocumentResponseBean(); documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
responseBean.setId(documentEntity.getId()); DocumentResponseBean responseBean = new DocumentResponseBean();
responseBean.setName(documentEntity.getFileName()); responseBean.setId(documentEntity.getId());
responseBean.setType(DocumentTypeEnum.valueOf(documentEntity.getType())); responseBean.setName(documentEntity.getFileName());
responseBean.setSource(DocumentSourceTypeEnum.valueOf(documentEntity.getSource())); responseBean.setType(DocumentTypeEnum.valueOf(documentEntity.getType()));
responseBean.setSourceId(documentEntity.getSourceId()); responseBean.setSource(DocumentSourceTypeEnum.valueOf(documentEntity.getSource()));
responseBean.setFilePath(documentEntity.getFilePath()); responseBean.setSourceId(documentEntity.getSourceId());
responseBean.setCreatedDate(documentEntity.getCreatedDate()); responseBean.setFilePath(documentEntity.getFilePath());
responseBean.setUpdatedDate(documentEntity.getUpdatedDate()); responseBean.setCreatedDate(documentEntity.getCreatedDate());
documentResponseBeans.add(responseBean); responseBean.setUpdatedDate(documentEntity.getUpdatedDate());
}); documentResponseBeans.add(responseBean);
});
}
} }
fieldResponse.setFileDetail(documentResponseBeans); fieldResponse.setFileDetail(documentResponseBeans);
@@ -888,19 +892,21 @@ public class ApplicationEvaluationDao {
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>(); List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
for (String docId : documentIds) { for (String docId : documentIds) {
Long documentId = Long.valueOf(docId.trim()); if (Boolean.FALSE.equals(docId.isEmpty())) {
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> { Long documentId = Long.valueOf(docId.trim());
DocumentResponseBean responseBean = new DocumentResponseBean(); documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
responseBean.setId(documentEntity.getId()); DocumentResponseBean responseBean = new DocumentResponseBean();
responseBean.setName(documentEntity.getFileName()); responseBean.setId(documentEntity.getId());
responseBean.setType(DocumentTypeEnum.valueOf(documentEntity.getType())); responseBean.setName(documentEntity.getFileName());
responseBean.setSource(DocumentSourceTypeEnum.valueOf(documentEntity.getSource())); responseBean.setType(DocumentTypeEnum.valueOf(documentEntity.getType()));
responseBean.setSourceId(documentEntity.getSourceId()); responseBean.setSource(DocumentSourceTypeEnum.valueOf(documentEntity.getSource()));
responseBean.setFilePath(documentEntity.getFilePath()); responseBean.setSourceId(documentEntity.getSourceId());
responseBean.setCreatedDate(documentEntity.getCreatedDate()); responseBean.setFilePath(documentEntity.getFilePath());
responseBean.setUpdatedDate(documentEntity.getUpdatedDate()); responseBean.setCreatedDate(documentEntity.getCreatedDate());
documentResponseBeans.add(responseBean); responseBean.setUpdatedDate(documentEntity.getUpdatedDate());
}); documentResponseBeans.add(responseBean);
});
}
} }
fieldResponse.setFileDetail(documentResponseBeans); fieldResponse.setFileDetail(documentResponseBeans);
@@ -1247,21 +1253,22 @@ public class ApplicationEvaluationDao {
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>(); List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
for (String docId : documentIds) { for (String docId : documentIds) {
Long documentId = Long.valueOf(docId.trim()); if (Boolean.FALSE.equals(docId.isEmpty())){
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> { Long documentId = Long.valueOf(docId.trim());
DocumentResponseBean responseBean = new DocumentResponseBean(); documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
responseBean.setId(documentEntity.getId()); DocumentResponseBean responseBean = new DocumentResponseBean();
responseBean.setName(documentEntity.getFileName()); responseBean.setId(documentEntity.getId());
responseBean.setType(DocumentTypeEnum.valueOf(documentEntity.getType())); responseBean.setName(documentEntity.getFileName());
responseBean.setSource(DocumentSourceTypeEnum.valueOf(documentEntity.getSource())); responseBean.setType(DocumentTypeEnum.valueOf(documentEntity.getType()));
responseBean.setSourceId(documentEntity.getSourceId()); responseBean.setSource(DocumentSourceTypeEnum.valueOf(documentEntity.getSource()));
responseBean.setFilePath(documentEntity.getFilePath()); responseBean.setSourceId(documentEntity.getSourceId());
responseBean.setCreatedDate(documentEntity.getCreatedDate()); responseBean.setFilePath(documentEntity.getFilePath());
responseBean.setUpdatedDate(documentEntity.getUpdatedDate()); responseBean.setCreatedDate(documentEntity.getCreatedDate());
documentResponseBeans.add(responseBean); responseBean.setUpdatedDate(documentEntity.getUpdatedDate());
}); documentResponseBeans.add(responseBean);
});
}
} }
fieldResponse.setFileDetail(documentResponseBeans); fieldResponse.setFileDetail(documentResponseBeans);
fieldResponses.add(fieldResponse); fieldResponses.add(fieldResponse);
} }