created api to update the call
This commit is contained in:
@@ -24,12 +24,14 @@ import net.gepafin.tendermanagement.entities.LookUpDataEntity.LookUpDataTypeEnum
|
||||
import net.gepafin.tendermanagement.entities.RegionEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
import net.gepafin.tendermanagement.enums.CallTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.DocumentTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.request.CreateCallRequestStep1;
|
||||
import net.gepafin.tendermanagement.model.request.CreateCallRequestStep2;
|
||||
import net.gepafin.tendermanagement.model.request.DocumentReq;
|
||||
import net.gepafin.tendermanagement.model.request.EvaluationCriteriaReq;
|
||||
import net.gepafin.tendermanagement.model.request.FaqReq;
|
||||
import net.gepafin.tendermanagement.model.request.LookUpDataReq;
|
||||
import net.gepafin.tendermanagement.model.request.UpdateCallRequestStep1;
|
||||
import net.gepafin.tendermanagement.model.response.CreateCallResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.EvaluationCriteriaResponseBean;
|
||||
@@ -48,32 +50,34 @@ import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationExceptio
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
|
||||
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
||||
|
||||
@Component
|
||||
public class CallDao {
|
||||
|
||||
@Autowired
|
||||
private CallRepository callRepository;
|
||||
@Autowired
|
||||
private CallRepository callRepository;
|
||||
|
||||
@Autowired
|
||||
private DocumentRepository documentRepository;
|
||||
@Autowired
|
||||
private DocumentRepository documentRepository;
|
||||
|
||||
@Autowired
|
||||
private EvaluationCriteriaRepository evaluationCriteriaRepository;
|
||||
@Autowired
|
||||
private EvaluationCriteriaRepository evaluationCriteriaRepository;
|
||||
|
||||
@Autowired
|
||||
private FaqRepository faqRepository;
|
||||
@Autowired
|
||||
private FaqRepository faqRepository;
|
||||
|
||||
@Autowired
|
||||
private RegionRepository regionRepository;
|
||||
@Autowired
|
||||
private RegionRepository regionRepository;
|
||||
|
||||
@Autowired
|
||||
private LookUpDataRepository lookUpDataRepository;
|
||||
@Autowired
|
||||
private LookUpDataRepository lookUpDataRepository;
|
||||
|
||||
@Autowired
|
||||
private CallTargetAudienceChecklistRepository callTargetAudienceChecklistRepository;
|
||||
@Autowired
|
||||
private CallTargetAudienceChecklistRepository callTargetAudienceChecklistRepository;
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
public CreateCallResponseBean createCallStep1(CreateCallRequestStep1 createCallRequest, Long userId) {
|
||||
CreateCallResponseBean createCallResponseBean = null;
|
||||
@@ -89,55 +93,74 @@ public class CallDao {
|
||||
|
||||
}
|
||||
|
||||
public CallEntity convertToCallEntity(CreateCallRequestStep1 createCallRequest) {
|
||||
CallEntity callEntity = new CallEntity();
|
||||
validateCallEntity(createCallRequest);
|
||||
RegionEntity region = regionRepository.findById(createCallRequest.getRegionId())
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.REGION_NOT_FOUND)));
|
||||
callEntity.setRegion(region);
|
||||
callEntity.setName(createCallRequest.getName());
|
||||
callEntity.setDescriptionShort(createCallRequest.getDescriptionShort());
|
||||
callEntity.setDescriptionLong(createCallRequest.getDescriptionLong());
|
||||
callEntity.setStartDate(createCallRequest.getStartDate());
|
||||
callEntity.setEndDate(createCallRequest.getEndDate());
|
||||
callEntity.setStatus(CallTypeEnum.DRAFT.getValue());
|
||||
callEntity.setAmountMax(createCallRequest.getAmountMax());
|
||||
callEntity.setAmount(createCallRequest.getAmountMax());
|
||||
callEntity.setConfidi(false);
|
||||
if (createCallRequest.getConfidi() != null) {
|
||||
callEntity.setConfidi(createCallRequest.getConfidi());
|
||||
}
|
||||
callEntity.setDocumentationRequested(createCallRequest.getDocumentationRequested());
|
||||
callEntity = callRepository.save(callEntity);
|
||||
return callEntity;
|
||||
}
|
||||
|
||||
public CallEntity convertToCallEntity(CreateCallRequestStep1 createCallRequest) {
|
||||
CallEntity callEntity = new CallEntity();
|
||||
validateCallEntity(createCallRequest);
|
||||
RegionEntity region = regionRepository.findById(createCallRequest.getRegionId())
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.REGION_NOT_FOUND)));
|
||||
callEntity.setRegion(region);
|
||||
callEntity.setName(createCallRequest.getName());
|
||||
callEntity.setDescriptionShort(createCallRequest.getDescriptionShort());
|
||||
callEntity.setDescriptionLong(createCallRequest.getDescriptionLong());
|
||||
callEntity.setStartDate(createCallRequest.getStartDate());
|
||||
callEntity.setEndDate(createCallRequest.getEndDate());
|
||||
callEntity.setStatus(CallTypeEnum.DRAFT.getValue());
|
||||
callEntity.setAmountMax(createCallRequest.getAmountMax());
|
||||
callEntity.setAmount(createCallRequest.getAmountMax());
|
||||
callEntity.setConfidi(false);
|
||||
if(createCallRequest.getConfidi()!=null){
|
||||
callEntity.setConfidi(createCallRequest.getConfidi());
|
||||
}
|
||||
callEntity.setDocumentationRequested(createCallRequest.getDocumentationRequested());
|
||||
callEntity = callRepository.save(callEntity);
|
||||
return callEntity;
|
||||
}
|
||||
public List<EvaluationCriteriaEntity> convertToEvaluationCriteriaEntities(
|
||||
List<EvaluationCriteriaReq> criteriaReqList, CallEntity callEntity) {
|
||||
List<EvaluationCriteriaEntity> evaluationCriteriaEntities = criteriaReqList.stream()
|
||||
.map(req -> convertToEvaluationCriteriaEntity(req, callEntity)).collect(Collectors.toList());
|
||||
evaluationCriteriaRepository.saveAll(evaluationCriteriaEntities);
|
||||
return evaluationCriteriaEntities;
|
||||
}
|
||||
|
||||
public List<EvaluationCriteriaEntity> convertToEvaluationCriteriaEntities(List<EvaluationCriteriaReq> criteriaReqList, CallEntity callEntity) {
|
||||
List<EvaluationCriteriaEntity> evaluationCriteriaEntities = criteriaReqList.stream().map(req -> convertToEvaluationCriteriaEntity(req, callEntity)).collect(Collectors.toList());
|
||||
evaluationCriteriaRepository.saveAll(evaluationCriteriaEntities);
|
||||
return evaluationCriteriaEntities;
|
||||
}
|
||||
private EvaluationCriteriaEntity convertToEvaluationCriteriaEntity(EvaluationCriteriaReq criteriaReq,
|
||||
CallEntity callEntity) {
|
||||
EvaluationCriteriaEntity criteriaEntity = new EvaluationCriteriaEntity();
|
||||
LookUpDataEntity lookUpDataEntity = getOrCreateLookUpData(criteriaReq, LookUpDataTypeEnum.EVALUATION_CRITERIA);
|
||||
criteriaEntity.setLookupData(lookUpDataEntity);
|
||||
criteriaEntity.setScore(criteriaReq.getScore());
|
||||
criteriaEntity.setCall(callEntity);
|
||||
return criteriaEntity;
|
||||
}
|
||||
|
||||
private EvaluationCriteriaEntity convertToEvaluationCriteriaEntity(EvaluationCriteriaReq criteriaReq, CallEntity callEntity) {
|
||||
EvaluationCriteriaEntity criteriaEntity = new EvaluationCriteriaEntity();
|
||||
validateEvolutionCrieteriaEntity(criteriaReq.getName());
|
||||
criteriaEntity.setName(criteriaReq.getName());
|
||||
criteriaEntity.setDescription(criteriaReq.getValue());
|
||||
criteriaEntity.setScore(criteriaReq.getScore());
|
||||
criteriaEntity.setCall(callEntity);
|
||||
return criteriaEntity;
|
||||
}
|
||||
private LookUpDataEntity getOrCreateLookUpData(EvaluationCriteriaReq criteriaReq, LookUpDataTypeEnum typeEnum) {
|
||||
LookUpDataEntity lookUpDataEntity = null;
|
||||
if (criteriaReq.getLookUpDataId() == null || criteriaReq.getLookUpDataId().equals(0l)) {
|
||||
validateEvolutionCrieteriaEntity(criteriaReq.getValue());
|
||||
lookUpDataEntity = new LookUpDataEntity();
|
||||
lookUpDataEntity.setValue(criteriaReq.getValue());
|
||||
lookUpDataEntity.setType(typeEnum.getValue());
|
||||
lookUpDataRepository.save(lookUpDataEntity);
|
||||
} else {
|
||||
lookUpDataEntity = lookUpDataRepository.findById(null)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.LOOK_UP_DATA_NOT_VALID_MSG)));
|
||||
}
|
||||
|
||||
return lookUpDataEntity;
|
||||
}
|
||||
|
||||
public List<DocumentEntity> convertToDocumentEntities(List<DocumentReq> documentReqList, CallEntity callEntity) {
|
||||
List<DocumentEntity> documentEntities = documentReqList.stream().map(req -> convertToDocumentEntity(req, callEntity)).collect(Collectors.toList());
|
||||
documentRepository.saveAll(documentEntities);
|
||||
return documentEntities;
|
||||
}
|
||||
public List<DocumentEntity> convertToDocumentEntities(List<DocumentReq> documentReqList, CallEntity callEntity) {
|
||||
List<DocumentEntity> documentEntities = documentReqList.stream()
|
||||
.map(req -> convertToDocumentEntity(req, callEntity)).collect(Collectors.toList());
|
||||
documentRepository.saveAll(documentEntities);
|
||||
return documentEntities;
|
||||
}
|
||||
|
||||
private DocumentEntity convertToDocumentEntity(DocumentReq documentReq, CallEntity callEntity) {
|
||||
validateDocumentEntity(documentReq.getId(),documentReq.getFileName());
|
||||
private DocumentEntity convertToDocumentEntity(DocumentReq documentReq, CallEntity callEntity) {
|
||||
validateDocumentEntity(documentReq.getId(), documentReq.getFileName());
|
||||
DocumentEntity documentEntity = documentRepository.findById(documentReq.getId())
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND)));
|
||||
@@ -147,208 +170,227 @@ public class CallDao {
|
||||
// documentEntity.setFileName(documentReq.getFileName());
|
||||
// documentEntity.setFilePath(documentReq.getUrl());
|
||||
// documentEntity.setCall(callEntity);
|
||||
return documentEntity;
|
||||
}
|
||||
return documentEntity;
|
||||
}
|
||||
|
||||
public List<FaqEntity> convertToFaqEntities(List<FaqReq> faqReqList, CallEntity callEntity, Long userId) {
|
||||
List<FaqEntity> faqEntities = faqReqList.stream().map(req -> convertToFaqEntity(req, callEntity, userId))
|
||||
.collect(Collectors.toList());
|
||||
faqRepository.saveAll(faqEntities);
|
||||
return faqEntities;
|
||||
}
|
||||
|
||||
public List<FaqEntity> convertToFaqEntities(List<FaqReq> faqReqList, CallEntity callEntity, Long userId) {
|
||||
List<FaqEntity> faqEntities = faqReqList.stream().map(req -> convertToFaqEntity(req, callEntity, userId)).collect(Collectors.toList());
|
||||
faqRepository.saveAll(faqEntities);
|
||||
return faqEntities;
|
||||
}
|
||||
private FaqEntity convertToFaqEntity(FaqReq faqReq, CallEntity callEntity, Long userId) {
|
||||
FaqEntity faqEntity = new FaqEntity();
|
||||
validateFaqEntity(faqReq.getQuestion());
|
||||
UserEntity userEntity = userRepository.findById(userId)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.LOOK_UP_DATA_NOT_VALID_MSG)));
|
||||
faqEntity.setUser(userEntity);
|
||||
faqEntity.setIsVisible(true);
|
||||
if (faqReq.getIsVisible() != null) {
|
||||
faqEntity.setIsVisible(faqReq.getIsVisible());
|
||||
}
|
||||
faqEntity.setQuestionShort(faqReq.getQuestionShort());
|
||||
faqEntity.setQuestion(faqReq.getQuestion());
|
||||
if (faqReq.getResponse() != null || faqReq.getResponseShort() != null) {
|
||||
faqEntity.setResponseDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||
}
|
||||
faqEntity.setResponseShort(faqReq.getResponseShort());
|
||||
faqEntity.setResponse(faqReq.getResponse());
|
||||
faqEntity.setCall(callEntity);
|
||||
return faqEntity;
|
||||
}
|
||||
|
||||
private FaqEntity convertToFaqEntity(FaqReq faqReq, CallEntity callEntity, Long userId) {
|
||||
FaqEntity faqEntity = new FaqEntity();
|
||||
validateFaqEntity(faqReq.getQuestion());
|
||||
UserEntity userEntity= userRepository.findById(userId)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.LOOK_UP_DATA_NOT_VALID_MSG)));
|
||||
faqEntity.setUser(userEntity);
|
||||
faqEntity.setIsVisible(true);
|
||||
if(faqReq.getIsVisible()!=null){
|
||||
faqEntity.setIsVisible(faqReq.getIsVisible());
|
||||
}
|
||||
faqEntity.setQuestionShort(faqReq.getQuestionShort());
|
||||
faqEntity.setQuestion(faqReq.getQuestion());
|
||||
if(faqReq.getResponse()!=null ||faqReq.getResponseShort()!=null){
|
||||
faqEntity.setResponseDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||
}
|
||||
faqEntity.setResponseShort(faqReq.getResponseShort());
|
||||
faqEntity.setResponse(faqReq.getResponse());
|
||||
faqEntity.setCall(callEntity);
|
||||
return faqEntity;
|
||||
}
|
||||
public void validateFaqEntity(String question) {
|
||||
if (!StringUtils.hasText(question)) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.QUESTION_NOT_EMPTY_MSG));
|
||||
}
|
||||
}
|
||||
|
||||
public void validateFaqEntity( String question) {
|
||||
if (!StringUtils.hasText(question)) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.QUESTION_NOT_EMPTY_MSG));
|
||||
}
|
||||
}
|
||||
|
||||
public void validateDocumentEntity(Long documentId,String name) {
|
||||
if(documentId==null){
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,Translator.toLocale(GepafinConstant.DOCUMENT_ID_NOT_FOUND));
|
||||
}
|
||||
public void validateDocumentEntity(Long documentId, String name) {
|
||||
if (documentId == null) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.DOCUMENT_ID_NOT_FOUND));
|
||||
}
|
||||
|
||||
// if (!StringUtils.hasText(name)) {
|
||||
// throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.NAME_NOT_EMPTY_MSG));
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
public void validateEvolutionCrieteriaEntity(String name) {
|
||||
if (!StringUtils.hasText(name)) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.NAME_NOT_EMPTY_MSG));
|
||||
}
|
||||
}
|
||||
public void validateEvolutionCrieteriaEntity(String name) {
|
||||
if (!StringUtils.hasText(name)) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.NAME_NOT_EMPTY_MSG));
|
||||
}
|
||||
}
|
||||
|
||||
public void validateCallEntity(CreateCallRequestStep1 createCallRequest) {
|
||||
if (createCallRequest.getRegionId() == null) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.REGION_NOT_FOUND_MSG));
|
||||
}
|
||||
public void validateCallEntity(CreateCallRequestStep1 createCallRequest) {
|
||||
if (createCallRequest.getRegionId() == null) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.REGION_NOT_FOUND_MSG));
|
||||
}
|
||||
|
||||
if (createCallRequest.getAmount().compareTo(BigDecimal.ZERO) <= 0||createCallRequest.getAmountMax().compareTo(BigDecimal.ZERO) <= 0) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.AMOUNT_GREATER_THAN_ZERO_MSG));
|
||||
}
|
||||
if (createCallRequest.getStartDate().toLocalDate().isBefore(LocalDate.now()) || createCallRequest.getEndDate().toLocalDate().isBefore(LocalDate.now())) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.INVALID_DATE_MSG));
|
||||
}
|
||||
}
|
||||
public CreateCallResponseBean convertToCallResponseBean(CallEntity callEntity) {
|
||||
CreateCallResponseBean createCallResponseBean = new CreateCallResponseBean();
|
||||
createCallResponseBean.setId(callEntity.getId());
|
||||
createCallResponseBean.setName(callEntity.getName());
|
||||
createCallResponseBean.setDates(List.of(callEntity.getStartDate(), callEntity.getEndDate()));
|
||||
createCallResponseBean.setDescriptionShort(callEntity.getDescriptionShort());
|
||||
createCallResponseBean.setDescriptionLong(callEntity.getDescriptionLong());
|
||||
createCallResponseBean.setStatus(CallTypeEnum.valueOf(callEntity.getStatus()));
|
||||
createCallResponseBean.setRegionId(callEntity.getRegion().getId());
|
||||
createCallResponseBean.setAmount(callEntity.getAmount());
|
||||
createCallResponseBean.setAmountMax(callEntity.getAmountMax());
|
||||
createCallResponseBean.setContactInfo(callEntity.getContactInfo());
|
||||
createCallResponseBean.setSubmissionMethod(callEntity.getSubmissionMethod());
|
||||
createCallResponseBean.setThreshold(callEntity.getThreshold());
|
||||
createCallResponseBean.setDocumentationReqested(callEntity.getDocumentationRequested());
|
||||
createCallResponseBean.setPriorityArea(callEntity.getPriorityArea());
|
||||
createCallResponseBean.setCreatedDate(callEntity.getCreatedDate());
|
||||
createCallResponseBean.setUpdatedDate(callEntity.getUpdatedDate());
|
||||
return createCallResponseBean;
|
||||
}
|
||||
public EvaluationCriteriaResponseBean convertToEvaluationCriteriaResponseBean(EvaluationCriteriaEntity entity) {
|
||||
EvaluationCriteriaResponseBean responseBean = new EvaluationCriteriaResponseBean();
|
||||
responseBean.setId(entity.getId());
|
||||
responseBean.setName(entity.getName());
|
||||
responseBean.setDescription(entity.getDescription());
|
||||
responseBean.setScore(entity.getScore());
|
||||
responseBean.setCreatedDate(entity.getCreatedDate());
|
||||
responseBean.setUpdatedDate(entity.getUpdatedDate());
|
||||
return responseBean;
|
||||
}
|
||||
public DocumentResponseBean convertToDocumentResponseBean(DocumentEntity entity) {
|
||||
DocumentResponseBean responseBean = new DocumentResponseBean();
|
||||
responseBean.setId(entity.getId());
|
||||
responseBean.setName(entity.getFileName());
|
||||
responseBean.setDescription(entity.getDescription());
|
||||
responseBean.setFilePath(entity.getFilePath());
|
||||
responseBean.setCreatedDate(entity.getCreatedDate());
|
||||
responseBean.setUpdatedDate(entity.getUpdatedDate());
|
||||
return responseBean;
|
||||
}
|
||||
public FaqResponseBean convertToFaqResponseBean(FaqEntity entity) {
|
||||
FaqResponseBean responseBean = new FaqResponseBean();
|
||||
responseBean.setId(entity.getId());
|
||||
responseBean.setQuestionShort(entity.getQuestionShort());
|
||||
responseBean.setResponseShort(entity.getResponseShort());
|
||||
responseBean.setResponse(entity.getResponse());
|
||||
responseBean.setQuestion(entity.getQuestion());
|
||||
responseBean.setUserId(entity.getUser().getId());
|
||||
responseBean.setIsVisible(entity.getIsVisible());
|
||||
responseBean.setCreatedDate(entity.getCreatedDate());
|
||||
responseBean.setUpdatedDate(entity.getUpdatedDate());
|
||||
return responseBean;
|
||||
}
|
||||
public CreateCallResponseBean assembleCreateCallResponseBean(
|
||||
CallEntity callEntity,
|
||||
List<EvaluationCriteriaEntity> evaluationCriteriaEntities,
|
||||
List<DocumentEntity> documentEntities,
|
||||
List<FaqEntity> faqEntities,List<DocumentEntity> images) {
|
||||
if (createCallRequest.getAmount().compareTo(BigDecimal.ZERO) <= 0
|
||||
|| createCallRequest.getAmountMax().compareTo(BigDecimal.ZERO) <= 0) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.AMOUNT_GREATER_THAN_ZERO_MSG));
|
||||
}
|
||||
if (createCallRequest.getStartDate().toLocalDate().isBefore(LocalDate.now())
|
||||
|| createCallRequest.getEndDate().toLocalDate().isBefore(LocalDate.now())) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.INVALID_DATE_MSG));
|
||||
}
|
||||
}
|
||||
|
||||
CreateCallResponseBean callResponseBean = convertToCallResponseBean(callEntity);
|
||||
public CreateCallResponseBean convertToCallResponseBean(CallEntity callEntity) {
|
||||
CreateCallResponseBean createCallResponseBean = new CreateCallResponseBean();
|
||||
createCallResponseBean.setId(callEntity.getId());
|
||||
createCallResponseBean.setName(callEntity.getName());
|
||||
createCallResponseBean.setDates(List.of(callEntity.getStartDate(), callEntity.getEndDate()));
|
||||
createCallResponseBean.setDescriptionShort(callEntity.getDescriptionShort());
|
||||
createCallResponseBean.setDescriptionLong(callEntity.getDescriptionLong());
|
||||
createCallResponseBean.setStatus(CallTypeEnum.valueOf(callEntity.getStatus()));
|
||||
createCallResponseBean.setRegionId(callEntity.getRegion().getId());
|
||||
createCallResponseBean.setAmount(callEntity.getAmount());
|
||||
createCallResponseBean.setAmountMax(callEntity.getAmountMax());
|
||||
createCallResponseBean.setContactInfo(callEntity.getContactInfo());
|
||||
createCallResponseBean.setSubmissionMethod(callEntity.getSubmissionMethod());
|
||||
createCallResponseBean.setThreshold(callEntity.getThreshold());
|
||||
createCallResponseBean.setDocumentationReqested(callEntity.getDocumentationRequested());
|
||||
createCallResponseBean.setPriorityArea(callEntity.getPriorityArea());
|
||||
createCallResponseBean.setCreatedDate(callEntity.getCreatedDate());
|
||||
createCallResponseBean.setUpdatedDate(callEntity.getUpdatedDate());
|
||||
return createCallResponseBean;
|
||||
}
|
||||
|
||||
List<EvaluationCriteriaResponseBean> evaluationCriteriaResponseBeans = evaluationCriteriaEntities.stream()
|
||||
.map(this::convertToEvaluationCriteriaResponseBean)
|
||||
.collect(Collectors.toList());
|
||||
public EvaluationCriteriaResponseBean convertToEvaluationCriteriaResponseBean(EvaluationCriteriaEntity entity) {
|
||||
EvaluationCriteriaResponseBean responseBean = new EvaluationCriteriaResponseBean();
|
||||
responseBean.setId(entity.getId());
|
||||
responseBean.setLookUpDataId(entity.getLookupData().getId());
|
||||
responseBean.setTitle(entity.getLookupData().getTitle());
|
||||
responseBean.setValue(entity.getLookupData().getValue());
|
||||
responseBean.setScore(entity.getScore());
|
||||
responseBean.setCreatedDate(entity.getCreatedDate());
|
||||
responseBean.setUpdatedDate(entity.getUpdatedDate());
|
||||
return responseBean;
|
||||
}
|
||||
|
||||
List<DocumentResponseBean> documentResponseBeans = documentEntities.stream()
|
||||
.map(this::convertToDocumentResponseBean)
|
||||
.collect(Collectors.toList());
|
||||
public DocumentResponseBean convertToDocumentResponseBean(DocumentEntity entity) {
|
||||
DocumentResponseBean responseBean = new DocumentResponseBean();
|
||||
responseBean.setId(entity.getId());
|
||||
responseBean.setName(entity.getFileName());
|
||||
responseBean.setDescription(entity.getDescription());
|
||||
responseBean.setFilePath(entity.getFilePath());
|
||||
responseBean.setCreatedDate(entity.getCreatedDate());
|
||||
responseBean.setUpdatedDate(entity.getUpdatedDate());
|
||||
return responseBean;
|
||||
}
|
||||
|
||||
List<FaqResponseBean> faqResponseBeans = faqEntities.stream()
|
||||
.map(this::convertToFaqResponseBean)
|
||||
.collect(Collectors.toList());
|
||||
public FaqResponseBean convertToFaqResponseBean(FaqEntity entity) {
|
||||
FaqResponseBean responseBean = new FaqResponseBean();
|
||||
responseBean.setId(entity.getId());
|
||||
responseBean.setQuestionShort(entity.getQuestionShort());
|
||||
responseBean.setResponseShort(entity.getResponseShort());
|
||||
responseBean.setResponse(entity.getResponse());
|
||||
responseBean.setQuestion(entity.getQuestion());
|
||||
responseBean.setUserId(entity.getUser().getId());
|
||||
responseBean.setIsVisible(entity.getIsVisible());
|
||||
responseBean.setCreatedDate(entity.getCreatedDate());
|
||||
responseBean.setUpdatedDate(entity.getUpdatedDate());
|
||||
return responseBean;
|
||||
}
|
||||
|
||||
List<DocumentResponseBean> imagesResponseBean = images.stream()
|
||||
.map(this::convertToDocumentResponseBean)
|
||||
.collect(Collectors.toList());
|
||||
CreateCallResponseBean createCallResponseBean =callResponseBean;
|
||||
createCallResponseBean.setCriteria(evaluationCriteriaResponseBeans);
|
||||
createCallResponseBean.setDocs(documentResponseBeans);
|
||||
createCallResponseBean.setFaq(faqResponseBeans);
|
||||
createCallResponseBean.setImages(imagesResponseBean);
|
||||
return createCallResponseBean;
|
||||
}
|
||||
public List<LookUpDataResponse> convertLookUpDataEntities(List<LookUpDataReq> lookUpData, CallEntity callEntity, LookUpDataEntity.LookUpDataTypeEnum type) {
|
||||
List<LookUpDataEntity> lookUpDataEntities = lookUpData.stream()
|
||||
.map(req -> convertLookUpDataRequestIntoLookUpDataEntity(req, type))
|
||||
.collect(Collectors.toList());
|
||||
public CreateCallResponseBean assembleCreateCallResponseBean(CallEntity callEntity,
|
||||
List<EvaluationCriteriaEntity> evaluationCriteriaEntities, List<DocumentEntity> documentEntities,
|
||||
List<FaqEntity> faqEntities, List<DocumentEntity> images) {
|
||||
|
||||
lookUpDataRepository.saveAll(lookUpDataEntities);
|
||||
CreateCallResponseBean callResponseBean = convertToCallResponseBean(callEntity);
|
||||
|
||||
return createCallTargetAudienceCheckList(callEntity, lookUpDataEntities);
|
||||
}
|
||||
List<EvaluationCriteriaResponseBean> evaluationCriteriaResponseBeans = evaluationCriteriaEntities.stream()
|
||||
.map(this::convertToEvaluationCriteriaResponseBean).collect(Collectors.toList());
|
||||
|
||||
private List<LookUpDataResponse> createCallTargetAudienceCheckList(CallEntity callEntity, List<LookUpDataEntity> lookUpDataEntities) {
|
||||
List<LookUpDataResponse> lookUpDataResponses=new ArrayList<>();
|
||||
for(LookUpDataEntity lookUpDataEntity:lookUpDataEntities){
|
||||
CallTargetAudienceChecklistEntity callTargetAudienceChecklistEntity=new CallTargetAudienceChecklistEntity();
|
||||
callTargetAudienceChecklistEntity.setIsValidated(false);
|
||||
callTargetAudienceChecklistEntity.setLookupData(lookUpDataEntity);
|
||||
callTargetAudienceChecklistEntity.setCall(callEntity);
|
||||
callTargetAudienceChecklistEntity= callTargetAudienceChecklistRepository.save(callTargetAudienceChecklistEntity);
|
||||
lookUpDataResponses.add(convertToLookUpDataResponseBean(callTargetAudienceChecklistEntity));
|
||||
}
|
||||
return lookUpDataResponses;
|
||||
}
|
||||
List<DocumentResponseBean> documentResponseBeans = documentEntities.stream()
|
||||
.map(this::convertToDocumentResponseBean).collect(Collectors.toList());
|
||||
|
||||
private LookUpDataEntity convertLookUpDataRequestIntoLookUpDataEntity(LookUpDataReq req, LookUpDataEntity.LookUpDataTypeEnum type) {
|
||||
if (req.getLookUpDataId() == null || req.getLookUpDataId().equals(0l)) {
|
||||
LookUpDataEntity newEntity = new LookUpDataEntity();
|
||||
newEntity.setValue(req.getValue());
|
||||
newEntity.setType(type.getValue());
|
||||
return newEntity;
|
||||
}
|
||||
List<FaqResponseBean> faqResponseBeans = faqEntities.stream().map(this::convertToFaqResponseBean)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return lookUpDataRepository.findById(req.getLookUpDataId())
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.LOOK_UP_DATA_NOT_VALID_MSG)));
|
||||
}
|
||||
List<DocumentResponseBean> imagesResponseBean = images.stream().map(this::convertToDocumentResponseBean)
|
||||
.collect(Collectors.toList());
|
||||
CreateCallResponseBean createCallResponseBean = callResponseBean;
|
||||
createCallResponseBean.setCriteria(evaluationCriteriaResponseBeans);
|
||||
createCallResponseBean.setDocs(documentResponseBeans);
|
||||
createCallResponseBean.setFaq(faqResponseBeans);
|
||||
createCallResponseBean.setImages(imagesResponseBean);
|
||||
return createCallResponseBean;
|
||||
}
|
||||
|
||||
public LookUpDataResponse convertToLookUpDataResponseBean(CallTargetAudienceChecklistEntity callTargetAudienceChecklistEntity) {
|
||||
LookUpDataResponse lookUpDataResponse = new LookUpDataResponse();
|
||||
LookUpDataEntity lookUpDataEntity = callTargetAudienceChecklistEntity.getLookupData();
|
||||
lookUpDataResponse.setId(callTargetAudienceChecklistEntity.getId());
|
||||
lookUpDataResponse.setLookUpDataId(lookUpDataEntity.getId());
|
||||
lookUpDataResponse.setValue(lookUpDataEntity.getValue());
|
||||
lookUpDataResponse.setTitle(lookUpDataEntity.getTitle());
|
||||
lookUpDataResponse.setCreatedDate(lookUpDataEntity.getCreatedDate());
|
||||
lookUpDataResponse.setUpdatedDate(lookUpDataEntity.getUpdatedDate());
|
||||
return lookUpDataResponse;
|
||||
}
|
||||
|
||||
|
||||
public CreateCallResponseBean createCallStep2(CreateCallRequestStep2 createCallRequest, Long userId) {
|
||||
public List<LookUpDataResponse> convertLookUpDataEntities(List<LookUpDataReq> lookUpData, CallEntity callEntity,
|
||||
LookUpDataEntity.LookUpDataTypeEnum type) {
|
||||
List<LookUpDataEntity> lookUpDataEntities = lookUpData.stream()
|
||||
.map(req -> convertLookUpDataRequestIntoLookUpDataEntity(req, type)).collect(Collectors.toList());
|
||||
|
||||
lookUpDataRepository.saveAll(lookUpDataEntities);
|
||||
|
||||
return createCallTargetAudienceCheckList(callEntity, lookUpDataEntities);
|
||||
}
|
||||
|
||||
private List<LookUpDataResponse> createCallTargetAudienceCheckList(CallEntity callEntity,
|
||||
List<LookUpDataEntity> lookUpDataEntities) {
|
||||
List<LookUpDataResponse> lookUpDataResponses = new ArrayList<>();
|
||||
for (LookUpDataEntity lookUpDataEntity : lookUpDataEntities) {
|
||||
CallTargetAudienceChecklistEntity callTargetAudienceChecklistEntity = new CallTargetAudienceChecklistEntity();
|
||||
callTargetAudienceChecklistEntity.setIsValidated(false);
|
||||
callTargetAudienceChecklistEntity.setLookupData(lookUpDataEntity);
|
||||
callTargetAudienceChecklistEntity.setCall(callEntity);
|
||||
callTargetAudienceChecklistEntity = callTargetAudienceChecklistRepository
|
||||
.save(callTargetAudienceChecklistEntity);
|
||||
lookUpDataResponses.add(convertToLookUpDataResponseBean(callTargetAudienceChecklistEntity));
|
||||
}
|
||||
return lookUpDataResponses;
|
||||
}
|
||||
|
||||
private LookUpDataEntity convertLookUpDataRequestIntoLookUpDataEntity(LookUpDataReq req,
|
||||
LookUpDataEntity.LookUpDataTypeEnum type) {
|
||||
if (req.getLookUpDataId() == null || req.getLookUpDataId().equals(0l)) {
|
||||
LookUpDataEntity newEntity = new LookUpDataEntity();
|
||||
newEntity.setValue(req.getValue());
|
||||
newEntity.setType(type.getValue());
|
||||
return newEntity;
|
||||
}
|
||||
|
||||
return lookUpDataRepository.findById(req.getLookUpDataId())
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.LOOK_UP_DATA_NOT_VALID_MSG)));
|
||||
}
|
||||
|
||||
public LookUpDataResponse convertToLookUpDataResponseBean(
|
||||
CallTargetAudienceChecklistEntity callTargetAudienceChecklistEntity) {
|
||||
LookUpDataResponse lookUpDataResponse = new LookUpDataResponse();
|
||||
LookUpDataEntity lookUpDataEntity = callTargetAudienceChecklistEntity.getLookupData();
|
||||
lookUpDataResponse.setId(callTargetAudienceChecklistEntity.getId());
|
||||
lookUpDataResponse.setLookUpDataId(lookUpDataEntity.getId());
|
||||
lookUpDataResponse.setValue(lookUpDataEntity.getValue());
|
||||
lookUpDataResponse.setTitle(lookUpDataEntity.getTitle());
|
||||
lookUpDataResponse.setCreatedDate(callTargetAudienceChecklistEntity.getCreatedDate());
|
||||
lookUpDataResponse.setUpdatedDate(callTargetAudienceChecklistEntity.getUpdatedDate());
|
||||
return lookUpDataResponse;
|
||||
}
|
||||
|
||||
private CallEntity getCallById(Long callId) {
|
||||
return callRepository.findById(callId).orElseThrow(() -> new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.NAME_NOT_EMPTY_MSG)));
|
||||
}
|
||||
|
||||
public CreateCallResponseBean createCallStep2(CreateCallRequestStep2 createCallRequest, Long userId) {
|
||||
CreateCallResponseBean createCallResponseBean = null;
|
||||
CallEntity callEntity = callRepository.findById(createCallRequest.getCallId())
|
||||
.orElseThrow(() -> new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.NAME_NOT_EMPTY_MSG)));
|
||||
|
||||
Translator.toLocale(GepafinConstant.CALL_NOT_FOUND)));
|
||||
|
||||
callEntity.setThreshold(createCallRequest.getThreshold());
|
||||
callEntity.setStatus(createCallRequest.getStatus().getValue());
|
||||
callRepository.save(callEntity);
|
||||
@@ -369,7 +411,47 @@ public class CallDao {
|
||||
createCallResponseBean.setCurrentStep(GepafinConstant.STEP_2);
|
||||
return createCallResponseBean;
|
||||
}
|
||||
|
||||
public CreateCallResponseBean updateCallStep1(Long callId, UpdateCallRequestStep1 updateCallRequest, Long userId) {
|
||||
CallEntity callEntity = getCallById(callId);
|
||||
setIfUpdated(callEntity::getName, callEntity::setName, updateCallRequest.getName());
|
||||
setIfUpdated(callEntity::getDescriptionShort, callEntity::setDescriptionShort,
|
||||
updateCallRequest.getDescriptionShort());
|
||||
setIfUpdated(callEntity::getDescriptionLong, callEntity::setDescriptionLong,
|
||||
updateCallRequest.getDescriptionLong());
|
||||
setIfUpdated(callEntity::getStartDate, callEntity::setStartDate, updateCallRequest.getStartDate());
|
||||
setIfUpdated(callEntity::getEndDate, callEntity::setEndDate, updateCallRequest.getEndDate());
|
||||
setIfUpdated(callEntity::getAmount, callEntity::setAmount, updateCallRequest.getAmount());
|
||||
setIfUpdated(callEntity::getAmountMax, callEntity::setAmountMax, updateCallRequest.getAmountMax());
|
||||
setIfUpdated(callEntity::getDocumentationRequested, callEntity::setDocumentationRequested,
|
||||
updateCallRequest.getDocumentationRequested());
|
||||
setIfUpdated(callEntity::getConfidi, callEntity::setConfidi, updateCallRequest.getConfidi());
|
||||
|
||||
CreateCallResponseBean createCallResponseBean = getCallResponseBean(callEntity);
|
||||
createCallResponseBean.setCurrentStep(GepafinConstant.STEP_1);
|
||||
return createCallResponseBean;
|
||||
}
|
||||
|
||||
private CreateCallResponseBean getCallResponseBean(CallEntity callEntity) {
|
||||
List<DocumentEntity> documentEntities = documentRepository.findByCallIdAndType(callEntity.getId(),
|
||||
DocumentTypeEnum.DOCUMENT.getValue());
|
||||
List<DocumentEntity> imageEntities = documentRepository.findByCallIdAndType(callEntity.getId(),
|
||||
DocumentTypeEnum.DOCUMENT.getValue());
|
||||
List<FaqEntity> faqEntities = faqRepository.findByCallId(callEntity.getId());
|
||||
List<LookUpDataResponse> amiedTo = callTargetAudienceChecklistRepository
|
||||
.findByCallIdAndLookupDataType(callEntity.getId(), LookUpDataTypeEnum.AIMED_TO.getValue()).stream()
|
||||
.map(this::convertToLookUpDataResponseBean).toList();
|
||||
|
||||
List<LookUpDataResponse> checkList = callTargetAudienceChecklistRepository
|
||||
.findByCallIdAndLookupDataType(callEntity.getId(), LookUpDataTypeEnum.CHECKLIST.getValue()).stream()
|
||||
.map(this::convertToLookUpDataResponseBean).toList();
|
||||
List<EvaluationCriteriaEntity> evaluationCriteriaEntities = evaluationCriteriaRepository
|
||||
.findByCallIdAndLookupDataType(callEntity.getId(), LookUpDataTypeEnum.EVALUATION_CRITERIA.getValue());
|
||||
|
||||
CreateCallResponseBean createCallResponseBean = assembleCreateCallResponseBean(callEntity, evaluationCriteriaEntities,
|
||||
documentEntities, faqEntities, imageEntities);
|
||||
createCallResponseBean.setAimedTo(amiedTo);
|
||||
createCallResponseBean.setCheckList(checkList);
|
||||
return createCallResponseBean;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user