updated code
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package net.gepafin.tendermanagement.dao;
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||||
import net.gepafin.tendermanagement.repositories.*;
|
import net.gepafin.tendermanagement.repositories.*;
|
||||||
@@ -174,54 +175,8 @@ public class FlowFormDao {
|
|||||||
.orElse(null);
|
.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) {
|
public Long getPreviousForm(FormEntity currentFormEntity, ApplicationEntity applicationEntity) {
|
||||||
|
// Retrieve the flow edges for the previous forms
|
||||||
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByTargetIdAndCallId(
|
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByTargetIdAndCallId(
|
||||||
currentFormEntity.getId(), applicationEntity.getCall().getId());
|
currentFormEntity.getId(), applicationEntity.getCall().getId());
|
||||||
|
|
||||||
@@ -231,24 +186,70 @@ public class FlowFormDao {
|
|||||||
// Translator.toLocale(GepafinConstant.PREVIOUS_FORM_NOT_FOUND));
|
// Translator.toLocale(GepafinConstant.PREVIOUS_FORM_NOT_FOUND));
|
||||||
}
|
}
|
||||||
|
|
||||||
// // If only one edge exists, return the source form ID
|
// If only one edge exists, return the source form ID
|
||||||
// if (flowEdgesList.size() == 1) {
|
if (flowEdgesList.size() == 1) {
|
||||||
// return flowEdgesList.get(0).getSourceId();
|
return flowEdgesList.get(0).getSourceId();
|
||||||
// }
|
}
|
||||||
|
|
||||||
// For multiple edges, find the previous form based on the chosen value
|
// For multiple edges, find the previous form based on the chosen value
|
||||||
List<Long> previousFormIds = flowEdgesList.stream()
|
List<Long> previousFormIds = flowEdgesList.stream()
|
||||||
.map(FlowEdgesEntity::getSourceId)
|
.map(FlowEdgesEntity::getSourceId)
|
||||||
.toList();
|
.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());
|
// public Long getPreviousForm(FormEntity currentFormEntity, ApplicationEntity applicationEntity) {
|
||||||
applicationFormEntities.sort(Comparator.comparing(ApplicationFormEntity::getCreatedDate).reversed());
|
//
|
||||||
|
// List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByTargetIdAndCallId(
|
||||||
return applicationFormEntities.isEmpty() ? null : applicationFormEntities.get(0).getForm().getId();
|
// 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,
|
public NextOrPreviousFormResponse getNextOrPreviousForm(ApplicationEntity applicationEntity, Long formId,
|
||||||
FormActionEnum action) {
|
FormActionEnum action) {
|
||||||
Long calculatedFormId = null;
|
Long calculatedFormId = null;
|
||||||
@@ -354,8 +355,7 @@ public class FlowFormDao {
|
|||||||
for (ApplicationFormEntity applicationFormEntity : applicationFormList) {
|
for (ApplicationFormEntity applicationFormEntity : applicationFormList) {
|
||||||
Boolean isCompleted = formDao.validateCompletedSteps(applicationFormFieldRepository.findByApplicationFormId(applicationFormEntity.getId()), applicationEntity, applicationFormEntity.getForm());
|
Boolean isCompleted = formDao.validateCompletedSteps(applicationFormFieldRepository.findByApplicationFormId(applicationFormEntity.getId()), applicationEntity, applicationFormEntity.getForm());
|
||||||
if (Boolean.FALSE.equals(isCompleted)) {
|
if (Boolean.FALSE.equals(isCompleted)) {
|
||||||
currentFormEntity = applicationFormEntity.getForm();
|
return applicationFormEntity.getForm().getId();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return getNextForm(currentFormEntity, applicationEntity);
|
return getNextForm(currentFormEntity, applicationEntity);
|
||||||
|
|||||||
Reference in New Issue
Block a user