Resolved Conflicts

This commit is contained in:
harish
2024-10-07 19:26:28 +05:30
16 changed files with 314 additions and 92 deletions

View File

@@ -492,7 +492,7 @@ public class ApplicationDao {
}
}
public void updateApplicationStatus(Long applicationId, ApplicationStatusTypeEnum status) {
public ApplicationResponse updateApplicationStatus(Long applicationId, ApplicationStatusTypeEnum status) {
ApplicationEntity applicationEntity = validateApplication(applicationId);
if (status.equals(ApplicationStatusTypeEnum.SUBMIT)) {
@@ -518,7 +518,9 @@ public class ApplicationDao {
} else {
applicationEntity.setStatus(status.getValue());
}
saveApplicationEntity(applicationEntity);
applicationEntity = saveApplicationEntity(applicationEntity);
return getApplicationResponse(applicationEntity);
}
public Integer calculateProgress(Long totalSteps, Long completedSteps) {

View File

@@ -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,81 +175,83 @@ 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());
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByTargetIdAndCallId(
currentFormEntity.getId(), applicationEntity.getCall().getId());
if (flowEdgesList.isEmpty()) {
return null;
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();
// }
// 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();
List<Long> previousFormIds = flowEdgesList.stream()
.map(FlowEdgesEntity::getSourceId)
.toList();
List<ApplicationFormEntity> applicationFormEntities=applicationFormRepository.findByFormIdInAndApplicationId(previousFormIds,applicationEntity.getId());
// Fetch the flow data based on previous form IDs
List<FlowDataEntity> flowDataList = flowDataRepository.findByFormIdInAndCallId(
previousFormIds, applicationEntity.getCall().getId());
applicationFormEntities.sort(Comparator.comparing(ApplicationFormEntity::getCreatedDate).reversed());
List<String> chosenValues = flowDataList.stream()
.map(FlowDataEntity::getChoosenValue)
.toList();
return applicationFormEntities.isEmpty() ? null : applicationFormEntities.get(0).getForm().getId();
// 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 NextOrPreviousFormResponse getnextOrPreviousForm(ApplicationEntity applicationEntity, Long formId,
FormActionEnum action) {
// 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;
FormEntity formEntity = null;
if (formId == null) {
@@ -299,7 +302,7 @@ public class FlowFormDao {
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
Long totalFormSteps = calculateTotalSteps(flowEdgesList);
Long currentStep = calculateCurrentStep(formEntity);
Long currentStep = calculateCurrentStep(flowEdgesList, formEntity);
nextOrPreviousFormResponse.setTotalFormSteps(totalFormSteps);
completedSteps = getCompletedSteps(applicationEntity);
nextOrPreviousFormResponse.setCompletedSteps(Long.valueOf(completedSteps));
@@ -321,11 +324,11 @@ public class FlowFormDao {
return completedSteps;
}
public Long calculateCurrentStep(FormEntity formEntity) {
public Long calculateCurrentStep(List<FlowEdgesEntity> flowEdgesList, FormEntity formEntity) {
Long currentStep = 2l;
if (formEntity.getId().equals(formEntity.getCall().getInitialForm())) {
currentStep = 1l;
} else if (formEntity.getId().equals(formEntity.getCall().getFinalForm())) {
} else if (flowEdgesList.size()>1 && formEntity.getId().equals(formEntity.getCall().getFinalForm())) {
currentStep = 3l;
}
return currentStep;
@@ -341,13 +344,21 @@ public class FlowFormDao {
private Long getDefaultForm(ApplicationEntity applicationEntity) {
List<ApplicationFormEntity> applicationFormList = applicationFormRepository.findByApplicationIdOrderByCreatedDateAsc(applicationEntity.getId());
if(applicationFormList.isEmpty()) {
if (applicationFormList.isEmpty()) {
return applicationEntity.getCall().getInitialForm();
}
if(applicationFormList.get(applicationFormList.size()-1).getForm().getId().equals(applicationEntity.getCall().getFinalForm())) {
return applicationEntity.getCall().getInitialForm();
if (applicationFormList.get(applicationFormList.size() - 1).getForm().getId().equals(applicationEntity.getCall().getFinalForm())) {
return applicationEntity.getCall().getInitialForm();
}
return getNextForm(applicationFormList.get(applicationFormList.size()-1).getForm(), applicationEntity);
FormEntity currentFormEntity = applicationFormList.get(applicationFormList.size() - 1).getForm();
for (ApplicationFormEntity applicationFormEntity : applicationFormList) {
Boolean isCompleted = formDao.validateCompletedSteps(applicationFormFieldRepository.findByApplicationFormId(applicationFormEntity.getId()), applicationEntity, applicationFormEntity.getForm());
if (Boolean.FALSE.equals(isCompleted)) {
return applicationFormEntity.getForm().getId();
}
}
return getNextForm(currentFormEntity, applicationEntity);
}