Updated response of application api
This commit is contained in:
@@ -155,6 +155,7 @@ public class GepafinConstant {
|
||||
public static final String IS_CAP="isCAP";
|
||||
public static final String IS_CODICE_FISCALE="isCodiceFiscale";
|
||||
public static final String IS_PIVA="isPIVA";
|
||||
|
||||
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";
|
||||
}
|
||||
|
||||
@@ -13,14 +13,17 @@ import net.gepafin.tendermanagement.model.response.*;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationFormFieldRepository;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationFormRepository;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
||||
import net.gepafin.tendermanagement.repositories.FlowEdgesRepository;
|
||||
import net.gepafin.tendermanagement.service.CallService;
|
||||
import net.gepafin.tendermanagement.service.DocumentService;
|
||||
import net.gepafin.tendermanagement.service.FormService;
|
||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||
import net.gepafin.tendermanagement.util.FieldValidator;
|
||||
import net.gepafin.tendermanagement.util.Utils;
|
||||
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.Status;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -56,6 +59,12 @@ public class ApplicationDao {
|
||||
@Autowired
|
||||
private CallDao callDao;
|
||||
|
||||
@Autowired
|
||||
private FlowFormDao flowFormDao;
|
||||
|
||||
@Autowired
|
||||
private FlowEdgesRepository flowEdgesRepository;
|
||||
|
||||
public ApplicationResponseBean createApplication(ApplicationRequestBean applicationRequestBean, UserEntity userEntity, Long formId,Long applicationId) {
|
||||
FormEntity formEntity = formService.validateForm(formId);
|
||||
CallEntity call = callService.validatePublishedCall(formEntity.getCall().getId());
|
||||
@@ -204,7 +213,16 @@ public class ApplicationDao {
|
||||
|
||||
private ApplicationResponse getApplicationResponse(ApplicationEntity applicationEntity) {
|
||||
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.setProgress(progress);
|
||||
responseBean.setCallTitle(applicationEntity.getCall().getName());
|
||||
responseBean.setCallEndDate(applicationEntity.getCall().getEndDate());
|
||||
responseBean.setModifiedDate(applicationEntity.getCall().getUpdatedDate());
|
||||
responseBean.setCallId(applicationEntity.getCall().getId());
|
||||
responseBean.setSubmissionDate(applicationEntity.getSubmissionDate());
|
||||
responseBean.setStatus(applicationEntity.getStatus());
|
||||
@@ -451,4 +469,18 @@ public class ApplicationDao {
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -290,21 +290,31 @@ public class FlowFormDao {
|
||||
nextOrPreviousFormResponse.setCallTitle(applicationEntity.getCall().getName());
|
||||
|
||||
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
|
||||
Long totalFormSteps = 3l;
|
||||
if (flowEdgesList.size() == 1) {
|
||||
totalFormSteps = 2l;
|
||||
Long totalFormSteps = calculateTotalSteps(flowEdgesList);
|
||||
Long currentStep = calculateCurrentStep(formEntity);
|
||||
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;
|
||||
if (formEntity.getId().equals(formEntity.getCall().getInitialForm())) {
|
||||
currentStep = 1l;
|
||||
} else if (formEntity.getId().equals(formEntity.getCall().getFinalForm())) {
|
||||
currentStep = 3l;
|
||||
}
|
||||
List<ApplicationFormEntity> applicationFormList = applicationFormRepository.findByApplicationId(applicationEntity.getId());
|
||||
nextOrPreviousFormResponse.setTotalFormSteps(totalFormSteps);
|
||||
nextOrPreviousFormResponse.setCompletedSteps(Long.valueOf(applicationFormList.size()));
|
||||
nextOrPreviousFormResponse.setCurrentStep(currentStep);
|
||||
return nextOrPreviousFormResponse;
|
||||
return currentStep;
|
||||
}
|
||||
|
||||
public Long calculateTotalSteps(List<FlowEdgesEntity> flowEdgesList) {
|
||||
Long totalFormSteps = 3l;
|
||||
if (flowEdgesList.size() == 1) {
|
||||
totalFormSteps = 2l;
|
||||
}
|
||||
return totalFormSteps;
|
||||
}
|
||||
|
||||
private Long getDefaultForm(ApplicationEntity applicationEntity) {
|
||||
|
||||
@@ -13,6 +13,14 @@ public class ApplicationResponse{
|
||||
|
||||
private Long callId;
|
||||
|
||||
private String callTitle;
|
||||
|
||||
private LocalDateTime callEndDate;
|
||||
|
||||
private LocalDateTime modifiedDate;
|
||||
|
||||
private Integer progress;
|
||||
|
||||
private LocalDateTime submissionDate;
|
||||
|
||||
private String status;
|
||||
|
||||
@@ -184,3 +184,5 @@ valid.vat.number=The VAT number is not valid for field {0}.
|
||||
failed.retain.field=Failed to retain specific fields.
|
||||
|
||||
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.
|
||||
@@ -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.
|
||||
valid.vat.number=Il numero di partita IVA non � valido per il campo {0}.
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user