Added few validation in call api
This commit is contained in:
@@ -3,13 +3,20 @@ 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.RoleStatusEnum;
|
||||
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||
import net.gepafin.tendermanagement.model.response.*;
|
||||
import net.gepafin.tendermanagement.service.FaqService;
|
||||
import net.gepafin.tendermanagement.service.LookUpDataService;
|
||||
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;
|
||||
|
||||
@@ -39,13 +46,14 @@ import net.gepafin.tendermanagement.repositories.DocumentRepository;
|
||||
import net.gepafin.tendermanagement.repositories.EvaluationCriteriaRepository;
|
||||
import net.gepafin.tendermanagement.repositories.FaqRepository;
|
||||
import net.gepafin.tendermanagement.repositories.RegionRepository;
|
||||
import net.gepafin.tendermanagement.service.UserService;
|
||||
import net.gepafin.tendermanagement.service.impl.CallValidatorServiceImpl;
|
||||
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 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 {
|
||||
@@ -64,7 +72,7 @@ public class CallDao {
|
||||
|
||||
@Autowired
|
||||
private RegionRepository regionRepository;
|
||||
|
||||
|
||||
@Autowired
|
||||
private LookUpDataService lookUpDataService;
|
||||
|
||||
@@ -73,20 +81,24 @@ public class CallDao {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private FaqService faqService;
|
||||
@Autowired
|
||||
private FlowDao flowDao;
|
||||
@Autowired
|
||||
private FormDao formDao;
|
||||
|
||||
public CallResponse createCallStep1(CreateCallRequestStep1 createCallRequest, Long userId) {
|
||||
UserEntity userEntity = userService.validateUser(userId);
|
||||
createCallRequest.setRegionId(userEntity.getRoleEntity().getRegion().getId());
|
||||
CallEntity callEntity = convertToCallEntity(createCallRequest);
|
||||
|
||||
|
||||
updateFaq(createCallRequest.getFaq(), callEntity, userEntity,LookUpDataTypeEnum.FAQ);
|
||||
|
||||
|
||||
convertLookUpDataEntities(createCallRequest.getAimedTo(), callEntity,
|
||||
LookUpDataTypeEnum.AIMED_TO);
|
||||
|
||||
|
||||
CallResponse createCallResponseBean = getCallResponseBean(callEntity);
|
||||
createCallResponseBean.setCurrentStep(GepafinConstant.STEP_1);
|
||||
return createCallResponseBean;
|
||||
@@ -391,12 +403,12 @@ public class CallDao {
|
||||
public void isValidDateRange(UpdateCallRequestStep1 updateCallRequest, CallEntity callEntity) {
|
||||
List<LocalDateTime> dates = updateCallRequest.getDates();
|
||||
|
||||
LocalDate startDate = (dates != null && dates.size() > 0 && dates.get(0) != null)
|
||||
? dates.get(0).toLocalDate()
|
||||
LocalDate startDate = (dates != null && dates.size() > 0 && dates.get(0) != null)
|
||||
? dates.get(0).toLocalDate()
|
||||
: null;
|
||||
|
||||
LocalDate endDate = (dates != null && dates.size() > 1 && dates.get(1) != null)
|
||||
? dates.get(1).toLocalDate()
|
||||
LocalDate endDate = (dates != null && dates.size() > 1 && dates.get(1) != null)
|
||||
? dates.get(1).toLocalDate()
|
||||
: null;
|
||||
|
||||
Boolean isValid = true;
|
||||
@@ -427,7 +439,7 @@ public class CallDao {
|
||||
setIfUpdated(callEntity::getDescriptionLong, callEntity::setDescriptionLong,
|
||||
updateCallRequest.getDescriptionLong());
|
||||
List<LocalDateTime> dates=updateCallRequest.getDates();
|
||||
|
||||
|
||||
if (dates != null && dates.size()>1) {
|
||||
if (dates.size() > 0) {
|
||||
setIfUpdated(callEntity::getStartDate, callEntity::setStartDate, dates.get(0));
|
||||
@@ -545,9 +557,14 @@ public class CallDao {
|
||||
return createCallResponseBean;
|
||||
}
|
||||
|
||||
public List<CallDetailsResponseBean> getAllCalls() {
|
||||
return callRepository.findAll()
|
||||
.stream()
|
||||
public List<CallDetailsResponseBean> getAllCalls(UserEntity user) {
|
||||
String type=user.getRoleEntity().getRoleType();
|
||||
List<String> callStatusList =CallStatusEnum.getStatusValues();
|
||||
if (Boolean.FALSE.equals(ROLE_SUPER_ADMIN.getValue().equals(type))) {
|
||||
callStatusList = List.of(CallStatusEnum.PUBLISH.getValue());
|
||||
}
|
||||
List<CallEntity> calls = callRepository.findByStatusIn(callStatusList);
|
||||
return calls.stream()
|
||||
.map(this::convertToCallDetailsResponseBean)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
@@ -555,7 +572,9 @@ public class CallDao {
|
||||
public CallResponse validateCallData(CallEntity callEntity) {
|
||||
validateUpdate(callEntity);
|
||||
CallResponse callResponseBean = getCallResponseBean(callEntity);
|
||||
CallValidatorServiceImpl.validateResponse(callResponseBean);
|
||||
FlowResponseBean flowResponseBean = flowDao.getFlowByCallId(callEntity.getId());
|
||||
List<FormResponseBean> formResponseBean = formDao.getFormsByCallId(callEntity.getId());
|
||||
CallValidatorServiceImpl.validateResponse(callResponseBean,flowResponseBean,formResponseBean);
|
||||
callEntity.setStatus(CallStatusEnum.READY_TO_PUBLISH.getValue());
|
||||
callRepository.save(callEntity);
|
||||
callResponseBean.setCurrentStep(GepafinConstant.VALIDATE_REQUEST);
|
||||
|
||||
Reference in New Issue
Block a user