updated code
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.repositories.*;
|
||||
@@ -174,54 +175,8 @@ public class FlowFormDao {
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
// public Long getPreviousForm(FormEntity currentFormEntity, ApplicationEntity applicationEntity) {
|
||||
// // Retrieve the flow edges for the previous forms
|
||||
// List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByTargetIdAndCallId(
|
||||
// currentFormEntity.getId(), applicationEntity.getCall().getId());
|
||||
//
|
||||
// if (flowEdgesList.isEmpty()) {
|
||||
// return null;
|
||||
//// throw new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
//// Translator.toLocale(GepafinConstant.PREVIOUS_FORM_NOT_FOUND));
|
||||
// }
|
||||
//
|
||||
// // If only one edge exists, return the source form ID
|
||||
// if (flowEdgesList.size() == 1) {
|
||||
// return flowEdgesList.get(0).getSourceId();
|
||||
// }
|
||||
//
|
||||
// // For multiple edges, find the previous form based on the chosen value
|
||||
// List<Long> previousFormIds = flowEdgesList.stream()
|
||||
// .map(FlowEdgesEntity::getSourceId)
|
||||
// .toList();
|
||||
//
|
||||
// // Fetch the flow data based on previous form IDs
|
||||
// List<FlowDataEntity> flowDataList = flowDataRepository.findByFormIdInAndCallId(
|
||||
// previousFormIds, applicationEntity.getCall().getId());
|
||||
//
|
||||
// List<String> chosenValues = flowDataList.stream()
|
||||
// .map(FlowDataEntity::getChoosenValue)
|
||||
// .toList();
|
||||
//
|
||||
// // Fetch the previous forms based on the chosen field values
|
||||
// Set<FormEntity> formList = applicationFormFieldRepository
|
||||
// .findByFieldValueInAndApplicationFormApplicationId(chosenValues, applicationEntity.getId()).stream()
|
||||
// .map(fieldEntity -> fieldEntity.getApplicationForm().getForm())
|
||||
// .collect(Collectors.toSet());
|
||||
//
|
||||
// // Find next form IDs recursively for all forms in the formList
|
||||
// List<Long> fieldIds = formList.stream()
|
||||
// .map(formEntity -> getNextForm(formEntity, applicationEntity))
|
||||
// .toList();
|
||||
//
|
||||
// // Return the first matching previous form ID that corresponds to a next form
|
||||
// return previousFormIds.stream()
|
||||
// .filter(fieldIds::contains)
|
||||
// .findFirst().orElse(null);
|
||||
// }
|
||||
|
||||
public Long getPreviousForm(FormEntity currentFormEntity, ApplicationEntity applicationEntity) {
|
||||
|
||||
// Retrieve the flow edges for the previous forms
|
||||
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByTargetIdAndCallId(
|
||||
currentFormEntity.getId(), applicationEntity.getCall().getId());
|
||||
|
||||
@@ -231,24 +186,70 @@ public class FlowFormDao {
|
||||
// Translator.toLocale(GepafinConstant.PREVIOUS_FORM_NOT_FOUND));
|
||||
}
|
||||
|
||||
// // If only one edge exists, return the source form ID
|
||||
// if (flowEdgesList.size() == 1) {
|
||||
// return flowEdgesList.get(0).getSourceId();
|
||||
// }
|
||||
// If only one edge exists, return the source form ID
|
||||
if (flowEdgesList.size() == 1) {
|
||||
return flowEdgesList.get(0).getSourceId();
|
||||
}
|
||||
|
||||
// For multiple edges, find the previous form based on the chosen value
|
||||
List<Long> previousFormIds = flowEdgesList.stream()
|
||||
.map(FlowEdgesEntity::getSourceId)
|
||||
.toList();
|
||||
if (previousFormIds.size() == 1) {
|
||||
return previousFormIds.get(0);
|
||||
|
||||
// Fetch the flow data based on previous form IDs
|
||||
List<FlowDataEntity> flowDataList = flowDataRepository.findByFormIdInAndCallId(
|
||||
previousFormIds, applicationEntity.getCall().getId());
|
||||
|
||||
List<String> chosenValues = flowDataList.stream()
|
||||
.map(FlowDataEntity::getChoosenValue)
|
||||
.toList();
|
||||
|
||||
// Fetch the previous forms based on the chosen field values
|
||||
Set<FormEntity> formList = applicationFormFieldRepository
|
||||
.findByFieldValueInAndApplicationFormApplicationId(chosenValues, applicationEntity.getId()).stream()
|
||||
.map(fieldEntity -> fieldEntity.getApplicationForm().getForm())
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// Find next form IDs recursively for all forms in the formList
|
||||
List<Long> fieldIds = formList.stream()
|
||||
.map(formEntity -> getNextForm(formEntity, applicationEntity))
|
||||
.toList();
|
||||
|
||||
// Return the first matching previous form ID that corresponds to a next form
|
||||
return previousFormIds.stream()
|
||||
.filter(fieldIds::contains)
|
||||
.findFirst().orElse(null);
|
||||
}
|
||||
|
||||
List<ApplicationFormEntity> applicationFormEntities=applicationFormRepository.findByFormIdInAndApplicationId(previousFormIds,applicationEntity.getId());
|
||||
applicationFormEntities.sort(Comparator.comparing(ApplicationFormEntity::getCreatedDate).reversed());
|
||||
|
||||
return applicationFormEntities.isEmpty() ? null : applicationFormEntities.get(0).getForm().getId();
|
||||
}
|
||||
// public Long getPreviousForm(FormEntity currentFormEntity, ApplicationEntity applicationEntity) {
|
||||
//
|
||||
// List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByTargetIdAndCallId(
|
||||
// currentFormEntity.getId(), applicationEntity.getCall().getId());
|
||||
//
|
||||
// if (flowEdgesList.isEmpty()) {
|
||||
// return null;
|
||||
//// throw new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
//// Translator.toLocale(GepafinConstant.PREVIOUS_FORM_NOT_FOUND));
|
||||
// }
|
||||
//
|
||||
// // // If only one edge exists, return the source form ID
|
||||
// // if (flowEdgesList.size() == 1) {
|
||||
// // return flowEdgesList.get(0).getSourceId();
|
||||
// // }
|
||||
//
|
||||
// // For multiple edges, find the previous form based on the chosen value
|
||||
// List<Long> previousFormIds = flowEdgesList.stream()
|
||||
// .map(FlowEdgesEntity::getSourceId)
|
||||
// .toList();
|
||||
// if (previousFormIds.size() == 1) {
|
||||
// return previousFormIds.get(0);
|
||||
// }
|
||||
//
|
||||
// List<ApplicationFormEntity> applicationFormEntities=applicationFormRepository.findByFormIdInAndApplicationId(previousFormIds,applicationEntity.getId());
|
||||
// applicationFormEntities.sort(Comparator.comparing(ApplicationFormEntity::getCreatedDate).reversed());
|
||||
//
|
||||
// return applicationFormEntities.isEmpty() ? null : applicationFormEntities.get(0).getForm().getId();
|
||||
// }
|
||||
public NextOrPreviousFormResponse getNextOrPreviousForm(ApplicationEntity applicationEntity, Long formId,
|
||||
FormActionEnum action) {
|
||||
Long calculatedFormId = null;
|
||||
@@ -354,8 +355,7 @@ public class FlowFormDao {
|
||||
for (ApplicationFormEntity applicationFormEntity : applicationFormList) {
|
||||
Boolean isCompleted = formDao.validateCompletedSteps(applicationFormFieldRepository.findByApplicationFormId(applicationFormEntity.getId()), applicationEntity, applicationFormEntity.getForm());
|
||||
if (Boolean.FALSE.equals(isCompleted)) {
|
||||
currentFormEntity = applicationFormEntity.getForm();
|
||||
break;
|
||||
return applicationFormEntity.getForm().getId();
|
||||
}
|
||||
}
|
||||
return getNextForm(currentFormEntity, applicationEntity);
|
||||
|
||||
Reference in New Issue
Block a user