Added get api which is responsable for get next or pevious form
This commit is contained in:
@@ -121,5 +121,10 @@ public class GepafinConstant {
|
||||
public static final String VALIDATION_FIELD_PATTERN = "validation.field.pattern";
|
||||
public static final String VALIDATION_FIELD_NOT_NULL = "validation.field.not_null";
|
||||
public static final String VALIDATION_FIELD_NOT_EMPTY = "validation.field.not_empty";
|
||||
// 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";
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import net.gepafin.tendermanagement.repositories.ApplicationFormRepository;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
||||
import net.gepafin.tendermanagement.service.CallService;
|
||||
import net.gepafin.tendermanagement.service.FormService;
|
||||
import net.gepafin.tendermanagement.service.UserService;
|
||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||
import net.gepafin.tendermanagement.util.Utils;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
|
||||
@@ -23,6 +23,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -31,13 +32,9 @@ public class ApplicationDao {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(ApplicationDao.class);
|
||||
|
||||
|
||||
@Autowired
|
||||
private CallService callService;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private ApplicationRepository applicationRepository;
|
||||
|
||||
@@ -178,7 +175,7 @@ public class ApplicationDao {
|
||||
}
|
||||
|
||||
public ApplicationEntity getApplicationOrCreate(UserEntity userEntity, CallEntity callEntity, FormEntity formEntity) {
|
||||
ApplicationEntity applicationEntity = applicationRepository.findByUserIdAndCallIdAndIsDeletedFalse(userEntity.getId(), callEntity.getId());
|
||||
ApplicationEntity applicationEntity = applicationRepository.findByUserIdAndCallIdAndIsDeletedFalse(userEntity.getId(), callEntity.getId()).orElse(null);
|
||||
if (applicationEntity == null) {
|
||||
validateFormId(formEntity, callEntity);
|
||||
applicationEntity = createApplicationEntity(userEntity, callEntity);
|
||||
@@ -217,7 +214,7 @@ public class ApplicationDao {
|
||||
public ApplicationFormFieldEntity validateApplicationFormField(Long applicationFormFieldId) {
|
||||
Optional<ApplicationFormFieldEntity> applicationFormFieldEntity = applicationFormFieldRepository.findById(applicationFormFieldId);
|
||||
if (applicationFormFieldEntity.isEmpty()) {
|
||||
throw new CustomValidationException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.APPLICATION_FORM_FIELD_NOT_FOUND));
|
||||
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.APPLICATION_FORM_FIELD_NOT_FOUND));
|
||||
}
|
||||
return applicationFormFieldEntity.get();
|
||||
}
|
||||
@@ -247,4 +244,21 @@ public class ApplicationDao {
|
||||
ApplicationEntity applicationEntity=applicationRepository.save(application);
|
||||
return applicationEntity;
|
||||
}
|
||||
|
||||
|
||||
public ApplicationEntity getApplicationByCallAndUser(CallEntity call, UserEntity userEntity) {
|
||||
return applicationRepository.findByUserIdAndCallIdAndIsDeletedFalse(userEntity.getId(), call.getId())
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.APPLICATION_NOT_FOUND_MSG)));
|
||||
|
||||
}
|
||||
|
||||
public void updateApplicationStatus(Long applicationId, ApplicationStatusTypeEnum status) {
|
||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||
applicationEntity.setStatus(status.getValue());
|
||||
if(status.equals(ApplicationStatusTypeEnum.SUBMIT)) {
|
||||
applicationEntity.setSubmissionDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||
}
|
||||
saveApplicationEntity(applicationEntity);
|
||||
}
|
||||
}
|
||||
|
||||
237
src/main/java/net/gepafin/tendermanagement/dao/FlowFormDao.java
Normal file
237
src/main/java/net/gepafin/tendermanagement/dao/FlowFormDao.java
Normal file
@@ -0,0 +1,237 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
||||
import net.gepafin.tendermanagement.entities.ApplicationFormEntity;
|
||||
import net.gepafin.tendermanagement.entities.ApplicationFormFieldEntity;
|
||||
import net.gepafin.tendermanagement.entities.FlowDataEntity;
|
||||
import net.gepafin.tendermanagement.entities.FlowEdgesEntity;
|
||||
import net.gepafin.tendermanagement.entities.FormEntity;
|
||||
import net.gepafin.tendermanagement.enums.FormActionEnum;
|
||||
import net.gepafin.tendermanagement.model.response.NextOrPreviousFormResponse;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationFormFieldRepository;
|
||||
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.Status;
|
||||
|
||||
@Component
|
||||
public class FlowFormDao {
|
||||
|
||||
@Autowired
|
||||
private FlowEdgesRepository flowEdgesRepository;
|
||||
|
||||
@Autowired
|
||||
private FlowDataRepository flowDataRepository;
|
||||
|
||||
@Autowired
|
||||
private ApplicationFormFieldRepository applicationFormFieldRepository;
|
||||
|
||||
@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());
|
||||
// ApplicationFormEntity applicationFormEntity = applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(), currentFormEntity.getId());
|
||||
// if(applicationFormEntity == null) {
|
||||
// throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
// Translator.toLocale("current form is not fill"));
|
||||
// }
|
||||
// if(flowEdgesList.isEmpty()) {
|
||||
// throw new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
// Translator.toLocale(GepafinConstant.NEXT_FORM_NOT_FOUND));
|
||||
// } else if(flowEdgesList.size() == 1) {
|
||||
// return flowEdgesList.get(0).getTargetId();
|
||||
// } else {
|
||||
// List<Long> nextFormIds = flowEdgesList.stream().map(FlowEdgesEntity::getTargetId).toList();
|
||||
// FlowDataEntity flowDataEntity = flowDataRepository.findByFormIdAndCallId(currentFormEntity.getId(), applicationEntity.getCall().getId());
|
||||
//
|
||||
// ApplicationFormFieldEntity applicationFormFieldEntity = applicationFormFieldRepository
|
||||
// .findByFieldIdAndApplicationFormFormIdAndApplicationFormApplicationId(flowDataEntity.getChoosenField(),
|
||||
// currentFormEntity.getId(), applicationEntity.getId()).orElseThrow(()-> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
// Translator.toLocale(GepafinConstant.NEXT_FORM_NOT_FOUND)));
|
||||
//
|
||||
// flowDataEntity = flowDataRepository.findByChoosenValueAndFormIdIn(applicationFormFieldEntity.getFieldValue(), nextFormIds).orElseThrow(()-> new NullPointerException());
|
||||
// return flowDataEntity.getFormId();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// Long getPreviousForm(FormEntity currentFormEntity, ApplicationEntity applicationEntity) {
|
||||
//
|
||||
// // Step 1: Find all edges where the current form is the target (i.e., reverse flow)
|
||||
// List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByTargetIdAndCallId(
|
||||
// currentFormEntity.getId(), applicationEntity.getCall().getId());
|
||||
//
|
||||
// if (flowEdgesList.isEmpty()) {
|
||||
// // If no previous edges are found, return null or handle this case based on your needs
|
||||
// throw new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
// Translator.toLocale(GepafinConstant.PREVIOUS_FORM_NOT_FOUND));
|
||||
// }
|
||||
//
|
||||
// // Step 2: If only one edge exists, return the source (previous) form ID directly have to look into it
|
||||
// if (flowEdgesList.size() == 1) {
|
||||
// return flowEdgesList.get(0).getSourceId();
|
||||
// }
|
||||
// List<Long> previousFormIds = flowEdgesList.stream().map(FlowEdgesEntity::getSourceId).toList();
|
||||
//
|
||||
//
|
||||
// // Step 3: Try to find flow data for the current form. If not found, we know it's the last step (or no field filtering is needed).
|
||||
// List<FlowDataEntity> flowDataList = flowDataRepository.findByFormIdInAndCallId(
|
||||
// previousFormIds, applicationEntity.getCall().getId());
|
||||
//
|
||||
// List<String> fieldValue = flowDataList.stream().map(FlowDataEntity::getChoosenValue).toList();
|
||||
//
|
||||
//// if (flowDataEntity == null || flowDataEntity.getChoosenField() == null) {
|
||||
//// // If flow data is not found, simply return the first matching previous form
|
||||
//// return flowEdgesList.get(0).getSourceId(); // You can modify this logic if needed
|
||||
//// }
|
||||
//
|
||||
// // Step 4: Fetch the field value from the application form fields
|
||||
// Set<FormEntity> formList = applicationFormFieldRepository
|
||||
// .findByFieldValueInAndAndApplicationFormApplicationId(
|
||||
// fieldValue, applicationEntity.getId()).stream().map(applicationFormFieldEntity->applicationFormFieldEntity.getApplicationForm().getForm()).collect(Collectors.toSet());
|
||||
//
|
||||
// List<Long> fieldIds = formList.stream().map(formEntity->getNextForm(formEntity, applicationEntity)).toList();
|
||||
// for(Long formId:previousFormIds) {
|
||||
// fieldIds.contains(formId);
|
||||
// return formId;
|
||||
// }
|
||||
// return null;
|
||||
//// .orElseThrow(() -> new NullPointerException("Field value not found for the current form and application."));
|
||||
//
|
||||
//
|
||||
//// // Step 5: Check if there's a matching previous form based on the chosen value
|
||||
//// FlowDataEntity previousFlowDataEntity = flowDataRepository.findByChoosenValueAndFormIdIn(
|
||||
//// applicationFormFieldEntity.getFieldValue(), flowEdgesList.stream().map(FlowEdgesEntity::getSourceId).toList())
|
||||
//// .orElse(null); // If no matching form is found, return null or the first source form
|
||||
////
|
||||
//// // Step 6: Return the formId of the matching previous form, or the first one if no specific match is found
|
||||
//// return previousFlowDataEntity != null ? previousFlowDataEntity.getFormId() : flowEdgesList.get(0).getSourceId();
|
||||
// }
|
||||
|
||||
|
||||
public Long getNextForm(FormEntity currentFormEntity, ApplicationEntity applicationEntity) {
|
||||
// Validate if the current form has been filled
|
||||
ApplicationFormEntity applicationFormEntity = applicationFormRepository.findByApplicationIdAndFormId(
|
||||
applicationEntity.getId(), currentFormEntity.getId());
|
||||
|
||||
// Retrieve the flow edges for the next forms
|
||||
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findBySourceIdAndCallId(
|
||||
currentFormEntity.getId(), applicationEntity.getCall().getId());
|
||||
|
||||
if (flowEdgesList.isEmpty()) {
|
||||
return null;
|
||||
// throw new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
// Translator.toLocale(GepafinConstant.NEXT_FORM_NOT_FOUND));
|
||||
}
|
||||
|
||||
// If only one edge exists, return the target form ID
|
||||
if (flowEdgesList.size() == 1) {
|
||||
return flowEdgesList.get(0).getTargetId();
|
||||
}
|
||||
|
||||
if (applicationFormEntity == null) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.CURRENT_FORM_INCOMPLETE));
|
||||
}
|
||||
|
||||
// For multiple edges, find the next form based on the chosen value
|
||||
List<Long> nextFormIds = flowEdgesList.stream()
|
||||
.map(FlowEdgesEntity::getTargetId)
|
||||
.toList();
|
||||
|
||||
// Retrieve the flow data for the current form
|
||||
FlowDataEntity flowDataEntity = flowDataRepository.findByFormIdAndCallId(
|
||||
currentFormEntity.getId(), applicationEntity.getCall().getId());
|
||||
|
||||
// Fetch the application form field related to the chosen field
|
||||
ApplicationFormFieldEntity applicationFormFieldEntity = applicationFormFieldRepository
|
||||
.findByFieldIdAndApplicationFormFormIdAndApplicationFormApplicationId(
|
||||
flowDataEntity.getChoosenField(), currentFormEntity.getId(), applicationEntity.getId()).orElse(null);
|
||||
|
||||
// Find the next form based on the chosen value and return its ID
|
||||
return flowDataRepository.findByChoosenValueAndFormIdIn(
|
||||
applicationFormFieldEntity.getFieldValue(), nextFormIds)
|
||||
.map(FlowDataEntity::getFormId)
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public Long getPreviousForm(FormEntity currentFormEntity, ApplicationEntity applicationEntity) {
|
||||
// Retrieve the flow edges for the previous forms
|
||||
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByTargetIdAndCallId(
|
||||
currentFormEntity.getId(), applicationEntity.getCall().getId());
|
||||
|
||||
if (flowEdgesList.isEmpty()) {
|
||||
return null;
|
||||
// throw new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
// Translator.toLocale(GepafinConstant.PREVIOUS_FORM_NOT_FOUND));
|
||||
}
|
||||
|
||||
// If only one edge exists, return the source form ID
|
||||
if (flowEdgesList.size() == 1) {
|
||||
return flowEdgesList.get(0).getSourceId();
|
||||
}
|
||||
|
||||
// For multiple edges, find the previous form based on the chosen value
|
||||
List<Long> previousFormIds = flowEdgesList.stream()
|
||||
.map(FlowEdgesEntity::getSourceId)
|
||||
.toList();
|
||||
|
||||
// Fetch the flow data based on previous form IDs
|
||||
List<FlowDataEntity> flowDataList = flowDataRepository.findByFormIdInAndCallId(
|
||||
previousFormIds, applicationEntity.getCall().getId());
|
||||
|
||||
List<String> chosenValues = flowDataList.stream()
|
||||
.map(FlowDataEntity::getChoosenValue)
|
||||
.toList();
|
||||
|
||||
// Fetch the previous forms based on the chosen field values
|
||||
Set<FormEntity> formList = applicationFormFieldRepository
|
||||
.findByFieldValueInAndApplicationFormApplicationId(chosenValues, applicationEntity.getId()).stream()
|
||||
.map(fieldEntity -> fieldEntity.getApplicationForm().getForm())
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// Find next form IDs recursively for all forms in the formList
|
||||
List<Long> fieldIds = formList.stream()
|
||||
.map(formEntity -> getNextForm(formEntity, applicationEntity))
|
||||
.toList();
|
||||
|
||||
// Return the first matching previous form ID that corresponds to a next form
|
||||
return previousFormIds.stream()
|
||||
.filter(fieldIds::contains)
|
||||
.findFirst().orElse(null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public NextOrPreviousFormResponse getnextOrPreviousForm(ApplicationEntity applicationEntity, FormEntity formEntity,
|
||||
FormActionEnum action) {
|
||||
|
||||
NextOrPreviousFormResponse nextOrPreviousFormResponse = new NextOrPreviousFormResponse();
|
||||
if (action.equals(FormActionEnum.NEXT)) {
|
||||
nextOrPreviousFormResponse.setNextFormId(getNextForm(formEntity, applicationEntity));
|
||||
} else {
|
||||
nextOrPreviousFormResponse.setPreviousFormId(getPreviousForm(formEntity, applicationEntity));
|
||||
}
|
||||
return nextOrPreviousFormResponse;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -10,7 +10,6 @@ import net.gepafin.tendermanagement.model.request.FormRequest;
|
||||
import net.gepafin.tendermanagement.model.response.ContentResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.FormResponseBean;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationFormRepository;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
||||
import net.gepafin.tendermanagement.repositories.FormRepository;
|
||||
import net.gepafin.tendermanagement.service.CallService;
|
||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||
@@ -36,9 +35,6 @@ public class FormDao {
|
||||
@Autowired
|
||||
private CallService callService;
|
||||
|
||||
@Autowired
|
||||
private ApplicationRepository applicationRepository;
|
||||
|
||||
@Autowired
|
||||
private ApplicationFormRepository applicationFormRepository;
|
||||
|
||||
|
||||
@@ -3,14 +3,10 @@ package net.gepafin.tendermanagement.entities;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
@Table(name = "APPLICATION_FORM")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class ApplicationFormEntity extends BaseEntity {
|
||||
|
||||
@ManyToOne
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package net.gepafin.tendermanagement.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
public enum FormActionEnum {
|
||||
|
||||
NEXT("NEXT"),
|
||||
PREVIOUS("PREVIOUS");
|
||||
|
||||
private String value;
|
||||
|
||||
FormActionEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@JsonValue
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.gepafin.tendermanagement.model.response;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import lombok.Data;
|
||||
import net.gepafin.tendermanagement.model.BaseBean;
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package net.gepafin.tendermanagement.model.response;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class NextOrPreviousFormResponse {
|
||||
|
||||
Long nextFormId;
|
||||
|
||||
Long previousFormId;
|
||||
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
package net.gepafin.tendermanagement.repositories;
|
||||
|
||||
import net.gepafin.tendermanagement.entities.ApplicationFormFieldEntity;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface ApplicationFormFieldRepository extends JpaRepository<ApplicationFormFieldEntity,Long> {
|
||||
@@ -12,4 +14,14 @@ public interface ApplicationFormFieldRepository extends JpaRepository<Applicatio
|
||||
public List<ApplicationFormFieldEntity> findByApplicationFormIdIn(List<Long> applicationFormIds);
|
||||
|
||||
public List<ApplicationFormFieldEntity> findByApplicationFormId(Long applicationFormId);
|
||||
|
||||
public Optional<ApplicationFormFieldEntity> findByFieldIdAndApplicationFormFormIdAndApplicationFormApplicationId(
|
||||
String fieldId, Long formId, Long applicationId);
|
||||
|
||||
public Optional<ApplicationFormFieldEntity> findByFieldValueInAndApplicationFormFormIdInAndApplicationFormApplicationId(
|
||||
List<String> fieldValues, List<Long> previousFormIds, Long applicationId);
|
||||
|
||||
public List<ApplicationFormFieldEntity> findByFieldValueInAndApplicationFormApplicationId(
|
||||
List<String> fieldValue, Long applicationId);
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.Optional;
|
||||
@Repository
|
||||
public interface ApplicationRepository extends JpaRepository<ApplicationEntity,Long> {
|
||||
|
||||
public ApplicationEntity findByUserIdAndCallIdAndIsDeletedFalse(Long userId,Long callId);
|
||||
public Optional<ApplicationEntity> findByUserIdAndCallIdAndIsDeletedFalse(Long userId,Long callId);
|
||||
|
||||
public List<ApplicationEntity> findByUserIdAndIsDeletedFalse(Long userId);
|
||||
|
||||
|
||||
@@ -5,9 +5,16 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface FlowDataRepository extends JpaRepository<FlowDataEntity,Long> {
|
||||
|
||||
public List<FlowDataEntity> findByCallId(Long callId);
|
||||
|
||||
public FlowDataEntity findByFormIdAndCallId(Long formId, Long callId);
|
||||
|
||||
public Optional<FlowDataEntity> findByChoosenValueAndFormIdIn(String fieldValue, List<Long> nextFormIds);
|
||||
|
||||
public List<FlowDataEntity> findByFormIdInAndCallId(List<Long> previousFormIds, Long callId);
|
||||
}
|
||||
|
||||
@@ -10,4 +10,8 @@ import java.util.List;
|
||||
public interface FlowEdgesRepository extends JpaRepository<net.gepafin.tendermanagement.entities.FlowEdgesEntity,Long> {
|
||||
|
||||
public List<FlowEdgesEntity> findByCallId(Long callId);
|
||||
|
||||
public List<FlowEdgesEntity> findBySourceIdAndCallId(Long sourceId, Long callId);
|
||||
|
||||
public List<FlowEdgesEntity> findByTargetIdAndCallId(Long targetId, Long callId);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,11 @@ package net.gepafin.tendermanagement.service;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
||||
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.FormActionEnum;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationRequestBean;
|
||||
import net.gepafin.tendermanagement.model.response.ApplicationResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.NextOrPreviousFormResponse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -18,4 +21,8 @@ public interface ApplicationService {
|
||||
void deleteApplication(HttpServletRequest request, Long applicationId);
|
||||
|
||||
public ApplicationEntity validateApplication(Long userId);
|
||||
|
||||
public NextOrPreviousFormResponse getnextOrPreviousForm(HttpServletRequest request, Long formId, FormActionEnum action);
|
||||
|
||||
public void updateApplicationStatus(HttpServletRequest request, Long applicationId, ApplicationStatusTypeEnum status);
|
||||
}
|
||||
|
||||
@@ -2,11 +2,17 @@ package net.gepafin.tendermanagement.service.impl;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.dao.ApplicationDao;
|
||||
import net.gepafin.tendermanagement.dao.FlowFormDao;
|
||||
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
||||
import net.gepafin.tendermanagement.entities.FormEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.FormActionEnum;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationRequestBean;
|
||||
import net.gepafin.tendermanagement.model.response.ApplicationResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.NextOrPreviousFormResponse;
|
||||
import net.gepafin.tendermanagement.service.ApplicationService;
|
||||
import net.gepafin.tendermanagement.service.FormService;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -22,6 +28,12 @@ public class ApplicationServiceImpl implements ApplicationService {
|
||||
@Autowired
|
||||
private ApplicationDao applicationDao;
|
||||
|
||||
@Autowired
|
||||
private FlowFormDao flowFormDao;
|
||||
|
||||
@Autowired
|
||||
private FormService formService;
|
||||
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
|
||||
@@ -56,4 +68,19 @@ public class ApplicationServiceImpl implements ApplicationService {
|
||||
return applicationDao.getAllApplications(userInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NextOrPreviousFormResponse getnextOrPreviousForm(HttpServletRequest request, 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateApplicationStatus(HttpServletRequest request, Long applicationId, ApplicationStatusTypeEnum status) {
|
||||
applicationDao.updateApplicationStatus(applicationId, status);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
package net.gepafin.tendermanagement.web.rest.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
@@ -7,16 +19,13 @@ import io.swagger.v3.oas.annotations.media.ExampleObject;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.validation.Valid;
|
||||
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.FormActionEnum;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationRequestBean;
|
||||
import net.gepafin.tendermanagement.model.response.ApplicationResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.NextOrPreviousFormResponse;
|
||||
import net.gepafin.tendermanagement.model.util.Response;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Validated
|
||||
public interface ApplicationApi {
|
||||
@@ -73,5 +82,37 @@ public interface ApplicationApi {
|
||||
@DeleteMapping(value = "/{applicationId}")
|
||||
ResponseEntity<Response<Void>> deleteApplication(HttpServletRequest request,
|
||||
@Parameter(description = "The application id", required = true) @PathVariable("applicationId") Long applicationId);
|
||||
|
||||
|
||||
@Operation(summary = "Api to get an next or previous form by current form id",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
|
||||
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@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")
|
||||
ResponseEntity<Response<NextOrPreviousFormResponse>> getnextOrPreviousForm(HttpServletRequest request,
|
||||
@Parameter(description = "The form id", required = true) @PathVariable("formId") Long formId,
|
||||
@RequestParam("action") FormActionEnum action);
|
||||
|
||||
|
||||
@Operation(summary = "Api to update application status",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
|
||||
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@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) })) })
|
||||
@PutMapping(value = "/{applicationId}/status", produces = { "application/json" })
|
||||
ResponseEntity<Response<Void>> updateApplicationStatus(HttpServletRequest request,
|
||||
@Parameter(description = "The application id", required = true) @PathVariable("applicationId") Long applicationId,
|
||||
@Parameter(description = "status", required = true)@RequestParam(value = "status", required = true) ApplicationStatusTypeEnum status);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,11 @@ package net.gepafin.tendermanagement.web.rest.api.impl;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.FormActionEnum;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationRequestBean;
|
||||
import net.gepafin.tendermanagement.model.response.ApplicationResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.FlowResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.NextOrPreviousFormResponse;
|
||||
import net.gepafin.tendermanagement.model.util.Response;
|
||||
import net.gepafin.tendermanagement.service.ApplicationService;
|
||||
import net.gepafin.tendermanagement.web.rest.api.ApplicationApi;
|
||||
@@ -61,4 +63,21 @@ public class ApplicationApiController implements ApplicationApi {
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(applications, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_APPLICATION_SUCCESS_MSG)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<NextOrPreviousFormResponse>> getnextOrPreviousForm(HttpServletRequest request,
|
||||
Long formId, FormActionEnum action) {
|
||||
NextOrPreviousFormResponse data = applicationService.getnextOrPreviousForm(request, 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)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<Void>> updateApplicationStatus(HttpServletRequest request, Long applicationId,
|
||||
ApplicationStatusTypeEnum status) {
|
||||
applicationService.updateApplicationStatus(request, applicationId, status);
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_APPLICATION_SUCCESS_MSG)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,3 +156,4 @@ validation.field.max_length=Field {0} must be no more than {1} characters long.
|
||||
validation.field.pattern=Field {0} does not match the required pattern.
|
||||
validation.field.not_null=Field {0} must not be null.
|
||||
validation.field.not_empty=Field {0} must not be empty.
|
||||
current.form.incomplete=Current form is not filled.
|
||||
@@ -152,3 +152,4 @@ validation.field.max_length=Il campo {0} deve essere lungo al massimo {1} caratt
|
||||
validation.field.pattern=Il campo {0} non corrisponde al modello richiesto.
|
||||
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 è compilato
|
||||
Reference in New Issue
Block a user