Merge pull request #99 from Kitzanos/feature/GEPAFINBE-101
GEPAFINBE-101 (Issue With Application Deleted Documents)
This commit is contained in:
@@ -93,6 +93,8 @@ public class ApplicationAmendmentRequestDao {
|
||||
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
@Autowired
|
||||
private ApplicationDao applicationDao;
|
||||
|
||||
@Autowired
|
||||
private EmailLogDao emailLogDao;
|
||||
@@ -560,11 +562,10 @@ public class ApplicationAmendmentRequestDao {
|
||||
|
||||
// Add valid new document IDs from the request
|
||||
existingDocumentIds.addAll(validDocumentIds);
|
||||
|
||||
applicationDao.updateDocumentDeletionStatus(formEntity, updatedFormField, formEntity.getApplicationForm().getForm(), null,validDocumentIds,true);
|
||||
// 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;
|
||||
|
||||
@@ -412,7 +412,7 @@ public class ApplicationDao {
|
||||
|
||||
ApplicationFormFieldEntity applicationFormFieldEntity=null;
|
||||
|
||||
validateFileUploadDocuments(applicationFormFieldRequestBean, formEntity);
|
||||
List<Long> newDocumentIds =validateFileUploadDocuments(applicationFormFieldRequestBean, formEntity);
|
||||
|
||||
if(applicationFormFieldEntities==null || applicationFormFieldEntities.isEmpty()){
|
||||
applicationFormFieldEntity = new ApplicationFormFieldEntity();
|
||||
@@ -434,13 +434,79 @@ public class ApplicationDao {
|
||||
Utils.setIfUpdated(applicationFormFieldEntity::getFieldId, applicationFormFieldEntity::setFieldId, applicationFormFieldRequestBean.getFieldId());
|
||||
|
||||
if(applicationFormFieldRequestBean.getFieldValue() !=null ) {
|
||||
updateDocumentDeletionStatus(applicationFormFieldEntity, applicationFormFieldRequestBean,formEntity,newDocumentIds,null,false);
|
||||
applicationFormFieldEntity.setFieldValue(Utils.convertObjectToJsonString(applicationFormFieldRequestBean.getFieldValue()));
|
||||
}
|
||||
if(applicationFormFieldRequestBean.getFieldValue() ==null ) {
|
||||
updateDocumentDeletionStatus(applicationFormFieldEntity, applicationFormFieldRequestBean,formEntity,newDocumentIds,null,false);
|
||||
applicationFormFieldEntity.setFieldValue(null);
|
||||
}
|
||||
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) {
|
||||
List<Long> documentIds=null;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user