updated code for next form api

This commit is contained in:
rajesh
2024-09-14 13:07:51 +05:30
parent 5624c61040
commit 14887a75ac
6 changed files with 41 additions and 22 deletions

View File

@@ -1,6 +1,7 @@
package net.gepafin.tendermanagement.dao;
import java.util.List;
import java.util.Optional;
import java.util.Set;
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.FlowEdgesRepository;
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;
@Component
@@ -39,6 +41,7 @@ public class FlowFormDao {
@Autowired
private ApplicationFormRepository applicationFormRepository;
// Long getNextForm(FormEntity currentFormEntity, ApplicationEntity applicationEntity) {
// // vlaidation if next form findout and cuuent from is not fill the give error
// List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findBySourceIdAndCallId(currentFormEntity.getId(), applicationEntity.getCall().getId());
@@ -167,11 +170,6 @@ public class FlowFormDao {
.orElse(null);
}
public Long getPreviousForm(FormEntity currentFormEntity, ApplicationEntity applicationEntity) {
// Retrieve the flow edges for the previous forms
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByTargetIdAndCallId(
@@ -218,20 +216,40 @@ public class FlowFormDao {
.findFirst().orElse(null);
}
public NextOrPreviousFormResponse getnextOrPreviousForm(ApplicationEntity applicationEntity, FormEntity formEntity,
public NextOrPreviousFormResponse getnextOrPreviousForm(ApplicationEntity applicationEntity, Long formId,
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();
if (action.equals(FormActionEnum.NEXT)) {
nextOrPreviousFormResponse.setNextFormId(getNextForm(formEntity, applicationEntity));
nextOrPreviousFormResponse.setNextFormId(getNextForm(fromEntity, applicationEntity));
} else {
nextOrPreviousFormResponse.setPreviousFormId(getPreviousForm(formEntity, applicationEntity));
nextOrPreviousFormResponse.setPreviousFormId(getPreviousForm(fromEntity, applicationEntity));
}
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);
}
}

View File

@@ -15,4 +15,6 @@ public interface ApplicationFormRepository extends JpaRepository<ApplicationForm
public List<ApplicationFormEntity> findByApplicationId(Long applicationId);
public List<ApplicationFormEntity> findByApplicationIdOrderByCreatedDateAsc(Long applicationId);
}

View File

@@ -22,7 +22,7 @@ public interface ApplicationService {
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);
}

View File

@@ -69,12 +69,10 @@ public class ApplicationServiceImpl implements ApplicationService {
}
@Override
public NextOrPreviousFormResponse getnextOrPreviousForm(HttpServletRequest request, Long formId,
public NextOrPreviousFormResponse getnextOrPreviousForm(HttpServletRequest request, Long applicationId, Long formId,
FormActionEnum action) {
UserEntity userEntity = validator.validateUser(request);
FormEntity formEntity = formService.validateForm(formId);
ApplicationEntity applicationEntity = applicationDao.getApplicationByCallAndUser(formEntity.getCall(), userEntity);
return flowFormDao.getnextOrPreviousForm(applicationEntity, formEntity, action);
ApplicationEntity applicationEntity = validateApplication(applicationId);
return flowFormDao.getnextOrPreviousForm(applicationEntity, formId, action);
}
@Override

View File

@@ -93,9 +93,10 @@ public interface ApplicationApi {
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@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,
@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);

View File

@@ -65,9 +65,9 @@ public class ApplicationApiController implements ApplicationApi {
}
@Override
public ResponseEntity<Response<NextOrPreviousFormResponse>> getnextOrPreviousForm(HttpServletRequest request,
public ResponseEntity<Response<NextOrPreviousFormResponse>> getnextOrPreviousForm(HttpServletRequest request,Long applicationId,
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 ");
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(data, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_APPLICATION_SUCCESS_MSG)));