Issue With Application Deleted Documents
This commit is contained in:
@@ -96,6 +96,8 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private Validator validator;
|
private Validator validator;
|
||||||
|
@Autowired
|
||||||
|
private ApplicationDao applicationDao;
|
||||||
|
|
||||||
public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(Long applicationEvaluationId) {
|
public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(Long applicationEvaluationId) {
|
||||||
log.info("Fetching the application data for the Amendment process {}", 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
|
// Add valid new document IDs from the request
|
||||||
existingDocumentIds.addAll(validDocumentIds);
|
existingDocumentIds.addAll(validDocumentIds);
|
||||||
|
applicationDao.updateDocumentDeletionStatus(formEntity, updatedFormField, formEntity.getApplicationForm().getForm(), null,validDocumentIds);
|
||||||
// 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;
|
||||||
|
|||||||
@@ -405,7 +405,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();
|
||||||
@@ -427,6 +427,7 @@ 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 ) {
|
||||||
|
updateDocumentDeletionStatus(applicationFormFieldEntity, applicationFormFieldRequestBean,formEntity,newDocumentIds,null);
|
||||||
applicationFormFieldEntity.setFieldValue(Utils.convertObjectToJsonString(applicationFormFieldRequestBean.getFieldValue()));
|
applicationFormFieldEntity.setFieldValue(Utils.convertObjectToJsonString(applicationFormFieldRequestBean.getFieldValue()));
|
||||||
}
|
}
|
||||||
if(applicationFormFieldRequestBean.getFieldValue() ==null ) {
|
if(applicationFormFieldRequestBean.getFieldValue() ==null ) {
|
||||||
@@ -434,6 +435,65 @@ public class ApplicationDao {
|
|||||||
}
|
}
|
||||||
return applicationFormFieldRepository.save(applicationFormFieldEntity);
|
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) {
|
private List<Long> validateFileUploadDocuments(ApplicationFormFieldRequestBean applicationFormFieldRequestBean, FormEntity formEntity) {
|
||||||
List<Long> documentIds=null;
|
List<Long> documentIds=null;
|
||||||
|
|||||||
@@ -249,6 +249,7 @@ public class ApplicationEvaluationDao {
|
|||||||
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
||||||
|
|
||||||
for (String docId : documentIds) {
|
for (String docId : documentIds) {
|
||||||
|
if (Boolean.FALSE.equals(docId.isEmpty())){
|
||||||
Long documentId = Long.valueOf(docId.trim());
|
Long documentId = Long.valueOf(docId.trim());
|
||||||
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
|
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
|
||||||
DocumentResponseBean responseBean = new DocumentResponseBean();
|
DocumentResponseBean responseBean = new DocumentResponseBean();
|
||||||
@@ -263,6 +264,7 @@ public class ApplicationEvaluationDao {
|
|||||||
documentResponseBeans.add(responseBean);
|
documentResponseBeans.add(responseBean);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
mappedField.setFieldValue(documentResponseBeans);
|
mappedField.setFieldValue(documentResponseBeans);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -351,6 +353,7 @@ public class ApplicationEvaluationDao {
|
|||||||
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
||||||
|
|
||||||
for (String docId : documentIds) {
|
for (String docId : documentIds) {
|
||||||
|
if (Boolean.FALSE.equals(docId.isEmpty())){
|
||||||
Long documentId = Long.valueOf(docId.trim());
|
Long documentId = Long.valueOf(docId.trim());
|
||||||
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
|
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
|
||||||
DocumentResponseBean responseBean = new DocumentResponseBean();
|
DocumentResponseBean responseBean = new DocumentResponseBean();
|
||||||
@@ -365,6 +368,7 @@ public class ApplicationEvaluationDao {
|
|||||||
documentResponseBeans.add(responseBean);
|
documentResponseBeans.add(responseBean);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fieldResponse.setFileDetail(documentResponseBeans);
|
fieldResponse.setFileDetail(documentResponseBeans);
|
||||||
}
|
}
|
||||||
@@ -888,6 +892,7 @@ public class ApplicationEvaluationDao {
|
|||||||
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
||||||
|
|
||||||
for (String docId : documentIds) {
|
for (String docId : documentIds) {
|
||||||
|
if (Boolean.FALSE.equals(docId.isEmpty())) {
|
||||||
Long documentId = Long.valueOf(docId.trim());
|
Long documentId = Long.valueOf(docId.trim());
|
||||||
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
|
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
|
||||||
DocumentResponseBean responseBean = new DocumentResponseBean();
|
DocumentResponseBean responseBean = new DocumentResponseBean();
|
||||||
@@ -902,6 +907,7 @@ public class ApplicationEvaluationDao {
|
|||||||
documentResponseBeans.add(responseBean);
|
documentResponseBeans.add(responseBean);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fieldResponse.setFileDetail(documentResponseBeans);
|
fieldResponse.setFileDetail(documentResponseBeans);
|
||||||
}
|
}
|
||||||
@@ -1247,6 +1253,7 @@ public class ApplicationEvaluationDao {
|
|||||||
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
||||||
|
|
||||||
for (String docId : documentIds) {
|
for (String docId : documentIds) {
|
||||||
|
if (Boolean.FALSE.equals(docId.isEmpty())){
|
||||||
Long documentId = Long.valueOf(docId.trim());
|
Long documentId = Long.valueOf(docId.trim());
|
||||||
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
|
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
|
||||||
DocumentResponseBean responseBean = new DocumentResponseBean();
|
DocumentResponseBean responseBean = new DocumentResponseBean();
|
||||||
@@ -1261,7 +1268,7 @@ public class ApplicationEvaluationDao {
|
|||||||
documentResponseBeans.add(responseBean);
|
documentResponseBeans.add(responseBean);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
fieldResponse.setFileDetail(documentResponseBeans);
|
fieldResponse.setFileDetail(documentResponseBeans);
|
||||||
fieldResponses.add(fieldResponse);
|
fieldResponses.add(fieldResponse);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user