updated code for next form api
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package net.gepafin.tendermanagement.dao;
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -22,6 +23,7 @@ import net.gepafin.tendermanagement.repositories.ApplicationFormRepository;
|
|||||||
import net.gepafin.tendermanagement.repositories.FlowDataRepository;
|
import net.gepafin.tendermanagement.repositories.FlowDataRepository;
|
||||||
import net.gepafin.tendermanagement.repositories.FlowEdgesRepository;
|
import net.gepafin.tendermanagement.repositories.FlowEdgesRepository;
|
||||||
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.Status;
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@@ -39,6 +41,7 @@ public class FlowFormDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ApplicationFormRepository applicationFormRepository;
|
private ApplicationFormRepository applicationFormRepository;
|
||||||
|
|
||||||
|
|
||||||
// Long getNextForm(FormEntity currentFormEntity, ApplicationEntity applicationEntity) {
|
// Long getNextForm(FormEntity currentFormEntity, ApplicationEntity applicationEntity) {
|
||||||
// // vlaidation if next form findout and cuuent from is not fill the give error
|
// // vlaidation if next form findout and cuuent from is not fill the give error
|
||||||
// List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findBySourceIdAndCallId(currentFormEntity.getId(), applicationEntity.getCall().getId());
|
// List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findBySourceIdAndCallId(currentFormEntity.getId(), applicationEntity.getCall().getId());
|
||||||
@@ -167,11 +170,6 @@ public class FlowFormDao {
|
|||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Long getPreviousForm(FormEntity currentFormEntity, ApplicationEntity applicationEntity) {
|
public Long getPreviousForm(FormEntity currentFormEntity, ApplicationEntity applicationEntity) {
|
||||||
// Retrieve the flow edges for the previous forms
|
// Retrieve the flow edges for the previous forms
|
||||||
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByTargetIdAndCallId(
|
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByTargetIdAndCallId(
|
||||||
@@ -218,20 +216,40 @@ public class FlowFormDao {
|
|||||||
.findFirst().orElse(null);
|
.findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NextOrPreviousFormResponse getnextOrPreviousForm(ApplicationEntity applicationEntity, Long formId,
|
||||||
|
|
||||||
|
|
||||||
public NextOrPreviousFormResponse getnextOrPreviousForm(ApplicationEntity applicationEntity, FormEntity formEntity,
|
|
||||||
FormActionEnum action) {
|
FormActionEnum action) {
|
||||||
|
FormEntity fromEntity = null;
|
||||||
|
if(formId == null) {
|
||||||
|
NextOrPreviousFormResponse nextOrPreviousFormResponse = new NextOrPreviousFormResponse();
|
||||||
|
nextOrPreviousFormResponse.setNextFormId(getDefaultForm(applicationEntity));
|
||||||
|
return nextOrPreviousFormResponse;
|
||||||
|
}else {
|
||||||
|
fromEntity = Optional
|
||||||
|
.of(applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(), formId))
|
||||||
|
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||||
|
Translator.toLocale(GepafinConstant.FORM_NOT_FOUND)))
|
||||||
|
.getForm();
|
||||||
|
}
|
||||||
|
|
||||||
NextOrPreviousFormResponse nextOrPreviousFormResponse = new NextOrPreviousFormResponse();
|
NextOrPreviousFormResponse nextOrPreviousFormResponse = new NextOrPreviousFormResponse();
|
||||||
if (action.equals(FormActionEnum.NEXT)) {
|
if (action.equals(FormActionEnum.NEXT)) {
|
||||||
nextOrPreviousFormResponse.setNextFormId(getNextForm(formEntity, applicationEntity));
|
nextOrPreviousFormResponse.setNextFormId(getNextForm(fromEntity, applicationEntity));
|
||||||
} else {
|
} else {
|
||||||
nextOrPreviousFormResponse.setPreviousFormId(getPreviousForm(formEntity, applicationEntity));
|
nextOrPreviousFormResponse.setPreviousFormId(getPreviousForm(fromEntity, applicationEntity));
|
||||||
}
|
}
|
||||||
return nextOrPreviousFormResponse;
|
return nextOrPreviousFormResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Long getDefaultForm(ApplicationEntity applicationEntity) {
|
||||||
|
List<ApplicationFormEntity> applicationFormList = applicationFormRepository.findByApplicationIdOrderByCreatedDateAsc(applicationEntity.getId());
|
||||||
|
if(applicationFormList.isEmpty()) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,4 +15,6 @@ public interface ApplicationFormRepository extends JpaRepository<ApplicationForm
|
|||||||
|
|
||||||
public List<ApplicationFormEntity> findByApplicationId(Long applicationId);
|
public List<ApplicationFormEntity> findByApplicationId(Long applicationId);
|
||||||
|
|
||||||
|
public List<ApplicationFormEntity> findByApplicationIdOrderByCreatedDateAsc(Long applicationId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public interface ApplicationService {
|
|||||||
|
|
||||||
public ApplicationEntity validateApplication(Long userId);
|
public ApplicationEntity validateApplication(Long userId);
|
||||||
|
|
||||||
public NextOrPreviousFormResponse getnextOrPreviousForm(HttpServletRequest request, Long formId, FormActionEnum action);
|
public NextOrPreviousFormResponse getnextOrPreviousForm(HttpServletRequest request, Long applicationId, Long formId, FormActionEnum action);
|
||||||
|
|
||||||
public void updateApplicationStatus(HttpServletRequest request, Long applicationId, ApplicationStatusTypeEnum status);
|
public void updateApplicationStatus(HttpServletRequest request, Long applicationId, ApplicationStatusTypeEnum status);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,12 +69,10 @@ public class ApplicationServiceImpl implements ApplicationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NextOrPreviousFormResponse getnextOrPreviousForm(HttpServletRequest request, Long formId,
|
public NextOrPreviousFormResponse getnextOrPreviousForm(HttpServletRequest request, Long applicationId, Long formId,
|
||||||
FormActionEnum action) {
|
FormActionEnum action) {
|
||||||
UserEntity userEntity = validator.validateUser(request);
|
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||||
FormEntity formEntity = formService.validateForm(formId);
|
return flowFormDao.getnextOrPreviousForm(applicationEntity, formId, action);
|
||||||
ApplicationEntity applicationEntity = applicationDao.getApplicationByCallAndUser(formEntity.getCall(), userEntity);
|
|
||||||
return flowFormDao.getnextOrPreviousForm(applicationEntity, formEntity, action);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -93,9 +93,10 @@ public interface ApplicationApi {
|
|||||||
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||||
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
||||||
@GetMapping(value = "form/{formId}", produces = "application/json")
|
@GetMapping(value = "/{applicationId}/form/next-previous", produces = "application/json")
|
||||||
ResponseEntity<Response<NextOrPreviousFormResponse>> getnextOrPreviousForm(HttpServletRequest request,
|
ResponseEntity<Response<NextOrPreviousFormResponse>> getnextOrPreviousForm(HttpServletRequest request,
|
||||||
@Parameter(description = "The form id", required = true) @PathVariable("formId") Long formId,
|
@Parameter(description = "The applicaltion id", required = true) @PathVariable("applicationId") Long applicationId,
|
||||||
|
@Parameter(description = "The form id", required = false) @RequestParam(value = "formId", required = false) Long formId,
|
||||||
@RequestParam("action") FormActionEnum action);
|
@RequestParam("action") FormActionEnum action);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -65,9 +65,9 @@ public class ApplicationApiController implements ApplicationApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<Response<NextOrPreviousFormResponse>> getnextOrPreviousForm(HttpServletRequest request,
|
public ResponseEntity<Response<NextOrPreviousFormResponse>> getnextOrPreviousForm(HttpServletRequest request,Long applicationId,
|
||||||
Long formId, FormActionEnum action) {
|
Long formId, FormActionEnum action) {
|
||||||
NextOrPreviousFormResponse data = applicationService.getnextOrPreviousForm(request, formId, action);
|
NextOrPreviousFormResponse data = applicationService.getnextOrPreviousForm(request, applicationId, formId, action);
|
||||||
log.info("Get Next Or Previous Form ");
|
log.info("Get Next Or Previous Form ");
|
||||||
return ResponseEntity.status(HttpStatus.OK)
|
return ResponseEntity.status(HttpStatus.OK)
|
||||||
.body(new Response<>(data, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_APPLICATION_SUCCESS_MSG)));
|
.body(new Response<>(data, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_APPLICATION_SUCCESS_MSG)));
|
||||||
|
|||||||
Reference in New Issue
Block a user