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

@@ -182,4 +182,6 @@ public class GepafinConstant {
public static final String CALL_NOT_STARTED_YET = "call.not.started.yet";
public static final String CALL_ALREADY_ENDED = "call.already.ended";
public static final String APPLICATION_STATUS_UPDATED_SUCCESSFULLY = "application.status.updated.successfully";
}

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);
}

View File

@@ -2,6 +2,8 @@ package net.gepafin.tendermanagement.model.response;
import lombok.Data;
import java.time.LocalDateTime;
@Data
public class UserSamlResponse {
@@ -10,4 +12,6 @@ public class UserSamlResponse {
private String firstName;
private String lastName;
private LocalDateTime dateOfBirth;
}

View File

@@ -29,6 +29,6 @@ public interface ApplicationService {
public NextOrPreviousFormResponse getNextOrPreviousForm(HttpServletRequest request, Long applicationId, Long formId, FormActionEnum action);
public void updateApplicationStatus(HttpServletRequest request, Long applicationId, ApplicationStatusTypeEnum status);
public ApplicationResponse updateApplicationStatus(HttpServletRequest request, Long applicationId, ApplicationStatusTypeEnum status);
}

View File

@@ -72,12 +72,12 @@ public class ApplicationServiceImpl implements ApplicationService {
public NextOrPreviousFormResponse getNextOrPreviousForm(HttpServletRequest request, Long applicationId, Long formId,
FormActionEnum action) {
ApplicationEntity applicationEntity = validateApplication(applicationId);
return flowFormDao.getnextOrPreviousForm(applicationEntity, formId, action);
return flowFormDao.getNextOrPreviousForm(applicationEntity, formId, action);
}
@Override
public void updateApplicationStatus(HttpServletRequest request, Long applicationId, ApplicationStatusTypeEnum status) {
applicationDao.updateApplicationStatus(applicationId, status);
public ApplicationResponse updateApplicationStatus(HttpServletRequest request, Long applicationId, ApplicationStatusTypeEnum status) {
return applicationDao.updateApplicationStatus(applicationId, status);
}

View File

@@ -33,6 +33,7 @@ import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
@@ -182,6 +183,13 @@ public class AuthenticationService {
&& !userAttributes.get("cognome").isEmpty()) {
userSamlResponse.setLastName(userAttributes.get("cognome").get(0).toString());
}
if (userAttributes.containsKey("dataNascita") && userAttributes.get("dataNascita") != null
&& !userAttributes.get("dataNascita").isEmpty()) {
String dateString =userAttributes.get("dataNascita").get(0).toString();
LocalDate dateOfBirth = LocalDate.parse(dateString);
LocalDateTime dateOfBirthWithTime = dateOfBirth.atStartOfDay();
userSamlResponse.setDateOfBirth(dateOfBirthWithTime);
}
userSamlResponse.setCodiceFiscale(cf);
return userSamlResponse;
}

View File

@@ -127,7 +127,7 @@ public interface ApplicationApi {
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
@PutMapping(value = "/{applicationId}/status", produces = { "application/json" })
ResponseEntity<Response<Void>> updateApplicationStatus(HttpServletRequest request,
ResponseEntity<Response<ApplicationResponse>> updateApplicationStatus(HttpServletRequest request,
@Parameter(description = "The application id", required = true) @PathVariable("applicationId") Long applicationId,
@Parameter(description = "status", required = true)@RequestParam(value = "status", required = true) ApplicationStatusTypeEnum status);

View File

@@ -83,10 +83,10 @@ public class ApplicationApiController implements ApplicationApi {
}
@Override
public ResponseEntity<Response<Void>> updateApplicationStatus(HttpServletRequest request, Long applicationId,
public ResponseEntity<Response<ApplicationResponse>> updateApplicationStatus(HttpServletRequest request, Long applicationId,
ApplicationStatusTypeEnum status) {
applicationService.updateApplicationStatus(request, applicationId, status);
ApplicationResponse applicationResponse = applicationService.updateApplicationStatus(request, applicationId, status);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_APPLICATION_SUCCESS_MSG)));
.body(new Response<>(applicationResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.APPLICATION_STATUS_UPDATED_SUCCESSFULLY)));
}
}