Done ticket BE-24,25
This commit is contained in:
@@ -125,8 +125,7 @@ public class GepafinConstant {
|
||||
// public static final String NEXT_FORM_NOT_FOUND = "next.form.not.found";
|
||||
// public static final String PREVIOUS_FORM_NOT_FOUND = "previous.form.not.found";
|
||||
public static final String CURRENT_FORM_INCOMPLETE = "current.form.incomplete";
|
||||
|
||||
|
||||
|
||||
public static final String FLOW_NOT_FOUND = "flow.not.found";
|
||||
public static final String VALIDATION_MESSAGE = "validation.message";
|
||||
public static final String ACTION_REQUIRED = "action.required";
|
||||
}
|
||||
|
||||
@@ -102,7 +102,6 @@ public class ApplicationDao {
|
||||
}
|
||||
ApplicationResponseBean applicationResponseBean= convertApplicationEntityToApplicationResponseBean(applicationEntity);
|
||||
applicationResponseBean.setFormFields(applicationFormFieldResponseBeans);
|
||||
applicationResponseBean.setCurrentFormId(formId);
|
||||
return applicationResponseBean;
|
||||
}
|
||||
|
||||
@@ -311,6 +310,8 @@ public class ApplicationDao {
|
||||
applicationGetResponseBean.setStatus(applicationEntity.getStatus());
|
||||
applicationGetResponseBean.setComments(applicationEntity.getComments());
|
||||
applicationGetResponseBean.setSubmissionDate(applicationEntity.getSubmissionDate());
|
||||
applicationGetResponseBean.setCallId(applicationEntity.getCall().getId());
|
||||
applicationGetResponseBean.setCallTitle(applicationEntity.getCall().getDescriptionShort());
|
||||
return applicationGetResponseBean;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,20 +3,13 @@ package net.gepafin.tendermanagement.dao;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||
import net.gepafin.tendermanagement.model.response.*;
|
||||
import net.gepafin.tendermanagement.service.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.context.SecurityContext;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -53,7 +46,6 @@ import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
|
||||
import static net.gepafin.tendermanagement.enums.RoleStatusEnum.ROLE_SUPER_ADMIN;
|
||||
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
||||
import static org.springframework.security.authorization.AuthorityReactiveAuthorizationManager.hasRole;
|
||||
|
||||
@Component
|
||||
public class CallDao {
|
||||
|
||||
@@ -226,31 +226,53 @@ public class FlowFormDao {
|
||||
public NextOrPreviousFormResponse getnextOrPreviousForm(ApplicationEntity applicationEntity, Long formId,
|
||||
FormActionEnum action) {
|
||||
Long calculatedFormId = null;
|
||||
FormEntity fromEntity = null;
|
||||
FormEntity formEntity = null;
|
||||
if (formId == null) {
|
||||
calculatedFormId = getDefaultForm(applicationEntity);
|
||||
} else {
|
||||
fromEntity = Optional
|
||||
if(action==null) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.ACTION_REQUIRED));
|
||||
}
|
||||
formEntity = Optional
|
||||
.of(applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(), formId))
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.FORM_NOT_FOUND)))
|
||||
.getForm();
|
||||
|
||||
if (action.equals(FormActionEnum.NEXT)) {
|
||||
calculatedFormId = getNextForm(fromEntity, applicationEntity);
|
||||
calculatedFormId = getNextForm(formEntity, applicationEntity);
|
||||
} else {
|
||||
calculatedFormId = getPreviousForm(fromEntity, applicationEntity);
|
||||
calculatedFormId = getPreviousForm(formEntity, applicationEntity);
|
||||
}
|
||||
}
|
||||
NextOrPreviousFormResponse nextOrPreviousFormResponse = new NextOrPreviousFormResponse();
|
||||
NextOrPreviousFormResponse nextOrPreviousFormResponse = null;
|
||||
if (calculatedFormId != null) {
|
||||
nextOrPreviousFormResponse.setFormId(calculatedFormId);
|
||||
nextOrPreviousFormResponse.setApplicationFormResponse(
|
||||
applicationDao.processForm(formService.validateForm(calculatedFormId), applicationEntity));
|
||||
nextOrPreviousFormResponse = setNextOrPreviousResponse(calculatedFormId, applicationEntity);
|
||||
}
|
||||
return nextOrPreviousFormResponse;
|
||||
}
|
||||
|
||||
private NextOrPreviousFormResponse setNextOrPreviousResponse(Long calculatedFormId, ApplicationEntity applicationEntity) {
|
||||
NextOrPreviousFormResponse nextOrPreviousFormResponse = new NextOrPreviousFormResponse();
|
||||
FormEntity formEntity = formService.validateForm(calculatedFormId);
|
||||
nextOrPreviousFormResponse.setFormId(calculatedFormId);
|
||||
nextOrPreviousFormResponse.setApplicationFormResponse(
|
||||
applicationDao.processForm(formEntity, applicationEntity));
|
||||
nextOrPreviousFormResponse.setCallId(applicationEntity.getCall().getId());
|
||||
nextOrPreviousFormResponse.setCallTitle(applicationEntity.getCall().getDescriptionShort());
|
||||
|
||||
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
|
||||
Long totalFormSteps = 3l;
|
||||
if (flowEdgesList.size() == 1) {
|
||||
totalFormSteps = 2l;
|
||||
}
|
||||
List<ApplicationFormEntity> applicationFormList = applicationFormRepository.findByApplicationId(applicationEntity.getId());
|
||||
nextOrPreviousFormResponse.setTotalFormSteps(totalFormSteps);
|
||||
nextOrPreviousFormResponse.setCompletedSteps(Long.valueOf(applicationFormList.size()));
|
||||
return nextOrPreviousFormResponse;
|
||||
}
|
||||
|
||||
private Long getDefaultForm(ApplicationEntity applicationEntity) {
|
||||
List<ApplicationFormEntity> applicationFormList = applicationFormRepository.findByApplicationIdOrderByCreatedDateAsc(applicationEntity.getId());
|
||||
if(applicationFormList.isEmpty()) {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package net.gepafin.tendermanagement.model.response;
|
||||
|
||||
import lombok.Data;
|
||||
import net.gepafin.tendermanagement.model.response.ApplicationResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.FormResponseBean;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
@@ -17,6 +15,10 @@ public class ApplicationGetResponseBean {
|
||||
private String status;
|
||||
|
||||
private String comments;
|
||||
|
||||
private Long callId;
|
||||
|
||||
private String callTitle;
|
||||
|
||||
private List<FormApplicationResponse> form;
|
||||
|
||||
|
||||
@@ -19,7 +19,4 @@ public class ApplicationResponseBean extends BaseBean {
|
||||
|
||||
private List<ApplicationFormFieldResponseBean> formFields;
|
||||
|
||||
private Long currentFormId;
|
||||
|
||||
private Long nextFormId;
|
||||
}
|
||||
|
||||
@@ -5,8 +5,16 @@ import lombok.Data;
|
||||
@Data
|
||||
public class NextOrPreviousFormResponse {
|
||||
|
||||
Long formId;
|
||||
private Long formId;
|
||||
|
||||
FormApplicationResponse applicationFormResponse;
|
||||
private Long callId;
|
||||
|
||||
private String callTitle;
|
||||
|
||||
private Long totalFormSteps;
|
||||
|
||||
private Long completedSteps;
|
||||
|
||||
private FormApplicationResponse applicationFormResponse;
|
||||
|
||||
}
|
||||
@@ -31,9 +31,7 @@ public class CallValidatorServiceImpl {
|
||||
.notNull(response.getDocumentationRequested(), "documentationRequested")
|
||||
.notEmpty(response.getAimedTo(), "aimedTo")
|
||||
.notEmpty(response.getCriteria(), "criteria")
|
||||
.notEmpty(response.getDocs(), "docs")
|
||||
.notEmpty(response.getFaq(), "faq")
|
||||
.notEmpty(response.getImages(), "images")
|
||||
.notEmpty(response.getDocs(), "docs")
|
||||
.notEmpty(response.getCheckList(), "checkList");
|
||||
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public class FieldValidator {
|
||||
|
||||
public void validate() {
|
||||
if (!errors.isEmpty()) {
|
||||
throw new ValidationException(Status.VALIDATION_ERROR, errors);
|
||||
throw new ValidationException(Status.VALIDATION_ERROR, errors, Translator.toLocale(GepafinConstant.VALIDATION_MESSAGE));
|
||||
}
|
||||
}
|
||||
public FieldValidator minLength(String value, Long minLength, String fieldName) {
|
||||
|
||||
@@ -34,6 +34,15 @@ public class GlobalExceptionHandler {
|
||||
log.error(ex.getLocalizedMessage(), ex);
|
||||
return new Response<>(null, ex.getStatus(), ex.getMessage());
|
||||
}
|
||||
|
||||
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
|
||||
@ExceptionHandler(ValidationException.class)
|
||||
@ResponseBody
|
||||
public Response<Object> handleValidationException(final ValidationException ex) {
|
||||
log.error(ex.getMessage());
|
||||
log.error(ex.getLocalizedMessage(), ex);
|
||||
return new Response<>(ex.getErrors(), ex.getStatus(), ex.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(ResourceNotFoundException.class)
|
||||
public ResponseEntity<Response<Void>> handleResourceNotFoundException(ResourceNotFoundException ex) {
|
||||
|
||||
@@ -2,14 +2,14 @@ package net.gepafin.tendermanagement.web.rest.api.errors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ValidationException extends CustomValidationException {
|
||||
public class ValidationException extends CustomValidationException {
|
||||
|
||||
private final Status status;
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final List<String> errors;
|
||||
|
||||
public ValidationException(Status status, List<String> errors) {
|
||||
super(status, errors.toString());
|
||||
public ValidationException(Status status, List<String> errors, String message) {
|
||||
super(status, message);
|
||||
this.errors = errors;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@@ -160,3 +160,5 @@ validation.field.not_empty=Field {0} must not be empty.
|
||||
|
||||
current.form.incomplete=Current form is not filled.
|
||||
flow.not.found=Flow not found.
|
||||
validation.message=Validation messages.
|
||||
action.required=Action field required.
|
||||
|
||||
@@ -155,3 +155,5 @@ validation.field.not_null=Il campo {0} non deve essere nullo.
|
||||
validation.field.not_empty=Il campo {0} non deve essere vuoto.
|
||||
current.form.incomplete=il modulo corrente non <20> compilato
|
||||
flow.not.found=Flow not found.
|
||||
validation.message=Messaggi di convalida.
|
||||
action.required=Campo azione obbligatorio.
|
||||
|
||||
Reference in New Issue
Block a user