Updated response of application api
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user