Updated response of application api

This commit is contained in:
nisha
2024-09-25 12:25:29 +05:30
parent b997fb3a5a
commit 49f5eb0883
6 changed files with 66 additions and 10 deletions

View File

@@ -155,6 +155,7 @@ public class GepafinConstant {
public static final String IS_CAP="isCAP"; public static final String IS_CAP="isCAP";
public static final String IS_CODICE_FISCALE="isCodiceFiscale"; public static final String IS_CODICE_FISCALE="isCodiceFiscale";
public static final String IS_PIVA="isPIVA"; public static final String IS_PIVA="isPIVA";
public static final String FAILED_RETAIN_FIELD="failed.retain.field"; public static final String FAILED_RETAIN_FIELD="failed.retain.field";
public static final String TOTAL_STEPS_NOT_BE_ZERO="total.steps.not.zero";
public static final String COMPLETED_STEPS_NOT_VALID="completed.steps.not.valid";
} }

View File

@@ -13,14 +13,17 @@ import net.gepafin.tendermanagement.model.response.*;
import net.gepafin.tendermanagement.repositories.ApplicationFormFieldRepository; import net.gepafin.tendermanagement.repositories.ApplicationFormFieldRepository;
import net.gepafin.tendermanagement.repositories.ApplicationFormRepository; import net.gepafin.tendermanagement.repositories.ApplicationFormRepository;
import net.gepafin.tendermanagement.repositories.ApplicationRepository; import net.gepafin.tendermanagement.repositories.ApplicationRepository;
import net.gepafin.tendermanagement.repositories.FlowEdgesRepository;
import net.gepafin.tendermanagement.service.CallService; import net.gepafin.tendermanagement.service.CallService;
import net.gepafin.tendermanagement.service.DocumentService; import net.gepafin.tendermanagement.service.DocumentService;
import net.gepafin.tendermanagement.service.FormService; import net.gepafin.tendermanagement.service.FormService;
import net.gepafin.tendermanagement.util.DateTimeUtil; import net.gepafin.tendermanagement.util.DateTimeUtil;
import net.gepafin.tendermanagement.util.FieldValidator;
import net.gepafin.tendermanagement.util.Utils; import net.gepafin.tendermanagement.util.Utils;
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException; import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException; import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
import net.gepafin.tendermanagement.web.rest.api.errors.Status; import net.gepafin.tendermanagement.web.rest.api.errors.Status;
import org.checkerframework.checker.units.qual.A;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -56,6 +59,12 @@ public class ApplicationDao {
@Autowired @Autowired
private CallDao callDao; private CallDao callDao;
@Autowired
private FlowFormDao flowFormDao;
@Autowired
private FlowEdgesRepository flowEdgesRepository;
public ApplicationResponseBean createApplication(ApplicationRequestBean applicationRequestBean, UserEntity userEntity, Long formId,Long applicationId) { public ApplicationResponseBean createApplication(ApplicationRequestBean applicationRequestBean, UserEntity userEntity, Long formId,Long applicationId) {
FormEntity formEntity = formService.validateForm(formId); FormEntity formEntity = formService.validateForm(formId);
CallEntity call = callService.validatePublishedCall(formEntity.getCall().getId()); CallEntity call = callService.validatePublishedCall(formEntity.getCall().getId());
@@ -204,7 +213,16 @@ public class ApplicationDao {
private ApplicationResponse getApplicationResponse(ApplicationEntity applicationEntity) { private ApplicationResponse getApplicationResponse(ApplicationEntity applicationEntity) {
ApplicationResponse responseBean = new ApplicationResponse(); ApplicationResponse responseBean = new ApplicationResponse();
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
Long totalFormSteps = flowFormDao.calculateTotalSteps(flowEdgesList);
List<ApplicationFormEntity> applicationFormList = applicationFormRepository.findByApplicationId(applicationEntity.getId());
Long completedSteps=(Long.valueOf(applicationFormList.size()));
Integer progress=calculateProgress(totalFormSteps,completedSteps);
responseBean.setId(applicationEntity.getId()); responseBean.setId(applicationEntity.getId());
responseBean.setProgress(progress);
responseBean.setCallTitle(applicationEntity.getCall().getName());
responseBean.setCallEndDate(applicationEntity.getCall().getEndDate());
responseBean.setModifiedDate(applicationEntity.getCall().getUpdatedDate());
responseBean.setCallId(applicationEntity.getCall().getId()); responseBean.setCallId(applicationEntity.getCall().getId());
responseBean.setSubmissionDate(applicationEntity.getSubmissionDate()); responseBean.setSubmissionDate(applicationEntity.getSubmissionDate());
responseBean.setStatus(applicationEntity.getStatus()); responseBean.setStatus(applicationEntity.getStatus());
@@ -451,4 +469,18 @@ public class ApplicationDao {
} }
saveApplicationEntity(applicationEntity); saveApplicationEntity(applicationEntity);
} }
public Integer calculateProgress(Long totalSteps, Long completedSteps) {
if (FieldValidator.isNullOrZero(totalSteps)) {
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.TOTAL_STEPS_NOT_BE_ZERO));
}
if (completedSteps < 0 || completedSteps > totalSteps) {
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.COMPLETED_STEPS_NOT_VALID));
}
double progress = ((double) completedSteps / totalSteps) * 100;
return (int) Math.round(progress);
}
} }

View File

@@ -290,21 +290,31 @@ public class FlowFormDao {
nextOrPreviousFormResponse.setCallTitle(applicationEntity.getCall().getName()); nextOrPreviousFormResponse.setCallTitle(applicationEntity.getCall().getName());
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId()); List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
Long totalFormSteps = 3l; Long totalFormSteps = calculateTotalSteps(flowEdgesList);
if (flowEdgesList.size() == 1) { Long currentStep = calculateCurrentStep(formEntity);
totalFormSteps = 2l; List<ApplicationFormEntity> applicationFormList = applicationFormRepository.findByApplicationId(applicationEntity.getId());
nextOrPreviousFormResponse.setTotalFormSteps(totalFormSteps);
nextOrPreviousFormResponse.setCompletedSteps(Long.valueOf(applicationFormList.size()));
nextOrPreviousFormResponse.setCurrentStep(currentStep);
return nextOrPreviousFormResponse;
} }
public Long calculateCurrentStep(FormEntity formEntity) {
Long currentStep = 2l; Long currentStep = 2l;
if (formEntity.getId().equals(formEntity.getCall().getInitialForm())) { if (formEntity.getId().equals(formEntity.getCall().getInitialForm())) {
currentStep = 1l; currentStep = 1l;
} else if (formEntity.getId().equals(formEntity.getCall().getFinalForm())) { } else if (formEntity.getId().equals(formEntity.getCall().getFinalForm())) {
currentStep = 3l; currentStep = 3l;
} }
List<ApplicationFormEntity> applicationFormList = applicationFormRepository.findByApplicationId(applicationEntity.getId()); return currentStep;
nextOrPreviousFormResponse.setTotalFormSteps(totalFormSteps); }
nextOrPreviousFormResponse.setCompletedSteps(Long.valueOf(applicationFormList.size()));
nextOrPreviousFormResponse.setCurrentStep(currentStep); public Long calculateTotalSteps(List<FlowEdgesEntity> flowEdgesList) {
return nextOrPreviousFormResponse; Long totalFormSteps = 3l;
if (flowEdgesList.size() == 1) {
totalFormSteps = 2l;
}
return totalFormSteps;
} }
private Long getDefaultForm(ApplicationEntity applicationEntity) { private Long getDefaultForm(ApplicationEntity applicationEntity) {

View File

@@ -13,6 +13,14 @@ public class ApplicationResponse{
private Long callId; private Long callId;
private String callTitle;
private LocalDateTime callEndDate;
private LocalDateTime modifiedDate;
private Integer progress;
private LocalDateTime submissionDate; private LocalDateTime submissionDate;
private String status; private String status;

View File

@@ -184,3 +184,5 @@ valid.vat.number=The VAT number is not valid for field {0}.
failed.retain.field=Failed to retain specific fields. failed.retain.field=Failed to retain specific fields.
application.is.incomplete = The application is incomplete. application.is.incomplete = The application is incomplete.
total.steps.not.zero=Total steps cannot be zero.
completed.steps.not.valid=Completed steps should be between 0 and total steps.

View File

@@ -176,3 +176,6 @@ validation.marca.da.bollo=Il campo {0} deve essere una Marca Da Bollo valida con
validation.piva=Il numero di partita IVA per {0} deve essere lungo fino a 11 cifre. validation.piva=Il numero di partita IVA per {0} deve essere lungo fino a 11 cifre.
valid.vat.number=Il numero di partita IVA non � valido per il campo {0}. valid.vat.number=Il numero di partita IVA non � valido per il campo {0}.
failed.retain.field=Impossibile conservare campi specifici. failed.retain.field=Impossibile conservare campi specifici.
total.steps.not.zero=Il totale dei passaggi non può essere zero.
completed.steps.not.valid=I passaggi completati devono essere compresi tra 0 e il totale dei passaggi.