Implemented company in application
This commit is contained in:
@@ -176,5 +176,7 @@ public class GepafinConstant {
|
|||||||
public static final String VATNUMBER_MANDATORY = "vatnumber.mandatory";
|
public static final String VATNUMBER_MANDATORY = "vatnumber.mandatory";
|
||||||
public static final String VATNUMBER_ALREADY_EXISTS = "vatnumber.already.exists";
|
public static final String VATNUMBER_ALREADY_EXISTS = "vatnumber.already.exists";
|
||||||
public static final String INVALID_EMAIL = "invalid.email";
|
public static final String INVALID_EMAIL = "invalid.email";
|
||||||
|
public static final String UNAUTHORIZED = "UNAUTHORIZED";
|
||||||
|
public static final String COMPANY_ID_MANDATORY = "company.id.mandatory";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,15 +17,18 @@ import net.gepafin.tendermanagement.service.FormService;
|
|||||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||||
import net.gepafin.tendermanagement.util.FieldValidator;
|
import net.gepafin.tendermanagement.util.FieldValidator;
|
||||||
import net.gepafin.tendermanagement.util.Utils;
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
|
import net.gepafin.tendermanagement.util.Validator;
|
||||||
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.ResourceNotFoundException;
|
||||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
import org.checkerframework.checker.units.qual.A;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import jakarta.persistence.criteria.Predicate;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -66,10 +69,13 @@ public class ApplicationDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private FlowDataRepository flowDataRepository;
|
private FlowDataRepository flowDataRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private Validator validator;
|
||||||
|
|
||||||
|
|
||||||
public ApplicationResponseBean createApplication(ApplicationRequestBean applicationRequestBean, UserEntity userEntity, Long formId, Long applicationId) {
|
public ApplicationResponseBean createApplication(ApplicationRequestBean applicationRequestBean, UserEntity userEntity, Long formId, Long applicationId) {
|
||||||
FormEntity formEntity = formService.validateForm(formId);
|
FormEntity formEntity = formService.validateForm(formId);
|
||||||
CallEntity call = callService.validatePublishedCall(formEntity.getCall().getId());
|
callService.validatePublishedCall(formEntity.getCall().getId());
|
||||||
validateFormFields(applicationRequestBean,formEntity);
|
validateFormFields(applicationRequestBean,formEntity);
|
||||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||||
if(Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.SUBMIT.getValue()))) {
|
if(Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.SUBMIT.getValue()))) {
|
||||||
@@ -94,9 +100,10 @@ public class ApplicationDao {
|
|||||||
return applicationFormEntity;
|
return applicationFormEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApplicationEntity createApplicationEntity(UserEntity user, CallEntity call) {
|
public ApplicationEntity createApplicationEntity(UserEntity user, CallEntity call, CompanyEntity companyEntity) {
|
||||||
ApplicationEntity entity = new ApplicationEntity();
|
ApplicationEntity entity = new ApplicationEntity();
|
||||||
entity.setUser(user);
|
entity.setUserId(user.getId());
|
||||||
|
entity.setCompany(companyEntity);
|
||||||
entity.setCall(call);
|
entity.setCall(call);
|
||||||
entity.setIsDeleted(false);
|
entity.setIsDeleted(false);
|
||||||
entity.setStatus(ApplicationStatusTypeEnum.DRAFT.getValue());
|
entity.setStatus(ApplicationStatusTypeEnum.DRAFT.getValue());
|
||||||
@@ -109,7 +116,6 @@ public class ApplicationDao {
|
|||||||
ApplicationEntity applicationEntity = validateApplication(id);
|
ApplicationEntity applicationEntity = validateApplication(id);
|
||||||
ApplicationFormEntity applicationFormEntity = applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(),formId);
|
ApplicationFormEntity applicationFormEntity = applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(),formId);
|
||||||
List<ApplicationFormFieldResponseBean> applicationFormFieldResponseBeans=new ArrayList<>();
|
List<ApplicationFormFieldResponseBean> applicationFormFieldResponseBeans=new ArrayList<>();
|
||||||
ApplicationFormFieldResponseBean applicationFormFieldResponseBeans1=null;
|
|
||||||
List<ApplicationFormFieldEntity> applicationFormFieldEntities = applicationFormFieldRepository.findByApplicationFormId(applicationFormEntity.getId());
|
List<ApplicationFormFieldEntity> applicationFormFieldEntities = applicationFormFieldRepository.findByApplicationFormId(applicationFormEntity.getId());
|
||||||
applicationFormFieldResponseBeans=createApplicationFormFieldResponse(applicationFormFieldEntities, applicationFormEntity, applicationFormFieldResponseBeans);
|
applicationFormFieldResponseBeans=createApplicationFormFieldResponse(applicationFormFieldEntities, applicationFormEntity, applicationFormFieldResponseBeans);
|
||||||
ApplicationResponseBean applicationResponseBean= convertApplicationEntityToApplicationResponseBean(applicationEntity);
|
ApplicationResponseBean applicationResponseBean= convertApplicationEntityToApplicationResponseBean(applicationEntity);
|
||||||
@@ -170,42 +176,72 @@ public class ApplicationDao {
|
|||||||
log.info("Application deleted with ID: {}", id);
|
log.info("Application deleted with ID: {}", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ApplicationResponse> getAllApplications(UserEntity userEntity, Long callId) {
|
// public List<ApplicationResponse> getAllApplications(UserEntity userEntity, Long callId, CompanyEntity companyEntity) {
|
||||||
boolean isBeneficiary = isBeneficiary(userEntity);
|
// boolean isBeneficiary = validator.checkIsBeneficiary();
|
||||||
|
//
|
||||||
|
// log.info("Fetching applications for RoleType: {}", userEntity.getRoleEntity().getRoleType());
|
||||||
|
// List<ApplicationResponse> applicationResponses = new ArrayList<>();
|
||||||
|
//
|
||||||
|
// if (callId != null) {
|
||||||
|
// // Fetch based on callId and user if role is BENEFICIARY, otherwise fetch all for the call
|
||||||
|
// log.info("Fetching applications for callId: {}", callId);
|
||||||
|
// CallEntity call = callService.validateCall(callId);
|
||||||
|
//
|
||||||
|
// // Use a single method to handle both conditions for consistency
|
||||||
|
// List<ApplicationEntity> applicationEntities = isBeneficiary
|
||||||
|
// ? applicationRepository.findByUserIdAndCallIdAndIsDeletedFalse(userEntity.getId(), call.getId())
|
||||||
|
// .map(List::of) // Convert Optional<ApplicationEntity> to a List of one element
|
||||||
|
// .orElse(List.of()) // If not present, return an empty list
|
||||||
|
// : applicationRepository.findByCallIdAndIsDeletedFalse(call.getId());
|
||||||
|
//
|
||||||
|
// applicationResponses = applicationEntities.stream()
|
||||||
|
// .map(this::getApplicationResponse)
|
||||||
|
// .collect(Collectors.toList());
|
||||||
|
//
|
||||||
|
// } else {
|
||||||
|
// // Fetch all applications for the user if BENEFICIARY, or fetch all applications in general
|
||||||
|
// List<ApplicationEntity> applicationEntities = isBeneficiary
|
||||||
|
// ? applicationRepository.findByUserIdAndIsDeletedFalse(companyEntity.getId())
|
||||||
|
// : applicationRepository.findByIsDeletedFalse();
|
||||||
|
//
|
||||||
|
// applicationResponses = applicationEntities.stream()
|
||||||
|
// .map(this::getApplicationResponse)
|
||||||
|
// .collect(Collectors.toList());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return applicationResponses;
|
||||||
|
// }
|
||||||
|
|
||||||
|
public List<ApplicationResponse> getAllApplications(UserEntity userEntity, Long callId, Long companyId) {
|
||||||
|
|
||||||
log.info("Fetching applications for RoleType: {}", userEntity.getRoleEntity().getRoleType());
|
log.info("Fetching applications for RoleType: {}", userEntity.getRoleEntity().getRoleType());
|
||||||
List<ApplicationResponse> applicationResponses = new ArrayList<>();
|
|
||||||
|
|
||||||
|
Specification<ApplicationEntity> spec = search(userEntity.getId(), callId, companyId);
|
||||||
|
|
||||||
|
List<ApplicationEntity> applicationEntities = applicationRepository.findAll(spec);
|
||||||
|
|
||||||
|
return applicationEntities.stream()
|
||||||
|
.map(this::getApplicationResponse)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Specification<ApplicationEntity> search(Long userId, Long callId, Long companyId) {
|
||||||
|
return (root, query, builder) -> {
|
||||||
|
Boolean isBeneficiary = validator.checkIsBeneficiary();
|
||||||
|
Predicate predicate = builder.isFalse(root.get("isDeleted"));
|
||||||
|
if (isBeneficiary) {
|
||||||
|
predicate = builder.and(predicate, builder.equal(root.get("userId"), userId));
|
||||||
|
}
|
||||||
if (callId != null) {
|
if (callId != null) {
|
||||||
// Fetch based on callId and user if role is BENEFICIARY, otherwise fetch all for the call
|
predicate = builder.and(predicate, builder.equal(root.get("call").get("id"), callId));
|
||||||
log.info("Fetching applications for callId: {}", callId);
|
|
||||||
CallEntity call = callService.validateCall(callId);
|
|
||||||
|
|
||||||
// Use a single method to handle both conditions for consistency
|
|
||||||
List<ApplicationEntity> applicationEntities = isBeneficiary
|
|
||||||
? applicationRepository.findByUserIdAndCallIdAndIsDeletedFalse(userEntity.getId(), call.getId())
|
|
||||||
.map(List::of) // Convert Optional<ApplicationEntity> to a List of one element
|
|
||||||
.orElse(List.of()) // If not present, return an empty list
|
|
||||||
: applicationRepository.findByCallIdAndIsDeletedFalse(call.getId());
|
|
||||||
|
|
||||||
applicationResponses = applicationEntities.stream()
|
|
||||||
.map(this::getApplicationResponse)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// Fetch all applications for the user if BENEFICIARY, or fetch all applications in general
|
|
||||||
List<ApplicationEntity> applicationEntities = isBeneficiary
|
|
||||||
? applicationRepository.findByUserIdAndIsDeletedFalse(userEntity.getId())
|
|
||||||
: applicationRepository.findByIsDeletedFalse();
|
|
||||||
|
|
||||||
applicationResponses = applicationEntities.stream()
|
|
||||||
.map(this::getApplicationResponse)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
if (companyId != null) {
|
||||||
return applicationResponses;
|
predicate = builder.and(predicate, builder.equal(root.get("company").get("id"), companyId));
|
||||||
|
}
|
||||||
|
return predicate;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private ApplicationResponse getApplicationResponse(ApplicationEntity applicationEntity) {
|
private ApplicationResponse getApplicationResponse(ApplicationEntity applicationEntity) {
|
||||||
ApplicationResponse responseBean = new ApplicationResponse();
|
ApplicationResponse responseBean = new ApplicationResponse();
|
||||||
@@ -223,11 +259,15 @@ public class ApplicationDao {
|
|||||||
responseBean.setSubmissionDate(applicationEntity.getSubmissionDate());
|
responseBean.setSubmissionDate(applicationEntity.getSubmissionDate());
|
||||||
responseBean.setStatus(applicationEntity.getStatus());
|
responseBean.setStatus(applicationEntity.getStatus());
|
||||||
responseBean.setComments(applicationEntity.getComments());
|
responseBean.setComments(applicationEntity.getComments());
|
||||||
|
responseBean.setCompanyId(applicationEntity.getCompany().getId());
|
||||||
|
responseBean.setCompanyName(applicationEntity.getCompany().getCompanyName());
|
||||||
return responseBean;
|
return responseBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApplicationEntity validateApplication(Long id) {
|
public ApplicationEntity validateApplication(Long id) {
|
||||||
ApplicationEntity applicationEntity= applicationRepository.findById(id).orElseThrow(() ->new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.APPLICATION_NOT_FOUND_MSG)));
|
ApplicationEntity applicationEntity = applicationRepository.findById(id)
|
||||||
|
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||||
|
Translator.toLocale(GepafinConstant.APPLICATION_NOT_FOUND_MSG)));
|
||||||
return applicationEntity;
|
return applicationEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,10 +399,9 @@ public class ApplicationDao {
|
|||||||
: applicationRepository.findById(applicationId)
|
: applicationRepository.findById(applicationId)
|
||||||
.stream().findFirst()
|
.stream().findFirst()
|
||||||
.orElseThrow(() -> new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_NOT_FOUND_MSG)));
|
.orElseThrow(() -> new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_NOT_FOUND_MSG)));
|
||||||
|
|
||||||
if (formId != null) {
|
if (formId != null) {
|
||||||
FormEntity formEntity = formService.validateForm(formId);
|
FormEntity formEntity = formService.validateForm(formId);
|
||||||
Optional<ApplicationEntity> application = applicationRepository.findByUserIdAndCallIdAndIsDeletedFalse(userEntity.getId(),
|
Optional<ApplicationEntity> application = applicationRepository.findByIdAndUserIdAndCallIdAndIsDeletedFalse(applicationId, userEntity.getId(),
|
||||||
formEntity.getCall().getId());
|
formEntity.getCall().getId());
|
||||||
applicationEntity=application.get();
|
applicationEntity=application.get();
|
||||||
formEntities.add(formEntity);
|
formEntities.add(formEntity);
|
||||||
@@ -422,6 +461,8 @@ public class ApplicationDao {
|
|||||||
applicationGetResponseBean.setSubmissionDate(applicationEntity.getSubmissionDate());
|
applicationGetResponseBean.setSubmissionDate(applicationEntity.getSubmissionDate());
|
||||||
applicationGetResponseBean.setCallId(applicationEntity.getCall().getId());
|
applicationGetResponseBean.setCallId(applicationEntity.getCall().getId());
|
||||||
applicationGetResponseBean.setCallTitle(applicationEntity.getCall().getName());
|
applicationGetResponseBean.setCallTitle(applicationEntity.getCall().getName());
|
||||||
|
applicationGetResponseBean.setCompanyId(applicationEntity.getCompany().getId());
|
||||||
|
applicationGetResponseBean.setCompanyName(applicationEntity.getCompany().getCompanyName());
|
||||||
return applicationGetResponseBean;
|
return applicationGetResponseBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -434,36 +475,29 @@ public class ApplicationDao {
|
|||||||
return formApplicationResponse;
|
return formApplicationResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApplicationResponse createApplicationByCallId(ApplicationRequest applicationRequest,Long callId,UserEntity userEntity){
|
public ApplicationResponse createApplicationByCallId(CompanyEntity companyEntity,
|
||||||
|
ApplicationRequest applicationRequest, Long callId, UserEntity userEntity) {
|
||||||
CallEntity call = callService.validateCall(callId);
|
CallEntity call = callService.validateCall(callId);
|
||||||
call = callService.validatePublishedCall(call.getId());
|
call = callService.validatePublishedCall(call.getId());
|
||||||
checkIfApplicationExists(call,userEntity);
|
checkIfApplicationExists(call, companyEntity);
|
||||||
ApplicationEntity applicationEntity=createApplicationEntity(userEntity,call);
|
ApplicationEntity applicationEntity = createApplicationEntity(userEntity, call, companyEntity);
|
||||||
applicationEntity.setComments(applicationRequest.getComments());
|
applicationEntity.setComments(applicationRequest.getComments());
|
||||||
applicationEntity = saveApplicationEntity(applicationEntity);
|
applicationEntity = saveApplicationEntity(applicationEntity);
|
||||||
ApplicationResponse applicationResponse = getApplicationResponse(applicationEntity);
|
ApplicationResponse applicationResponse = getApplicationResponse(applicationEntity);
|
||||||
return applicationResponse;
|
return applicationResponse;
|
||||||
}
|
}
|
||||||
public void checkIfApplicationExists(CallEntity call,UserEntity userEntity){
|
public void checkIfApplicationExists(CallEntity call, CompanyEntity companyEntity){
|
||||||
Optional<ApplicationEntity> applicationEntity=applicationRepository.findByUserIdAndCallIdAndIsDeletedFalse(userEntity.getId(),call.getId());
|
Optional<ApplicationEntity> applicationEntity=applicationRepository.findByCompanyIdAndCallIdAndIsDeletedFalse(companyEntity.getId(),call.getId());
|
||||||
if(applicationEntity.isPresent()){
|
if(applicationEntity.isPresent()){
|
||||||
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_EXISTS));
|
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_EXISTS));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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) {
|
public void updateApplicationStatus(Long applicationId, ApplicationStatusTypeEnum status) {
|
||||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||||
|
|
||||||
if (status.equals(ApplicationStatusTypeEnum.SUBMIT)) {
|
if (status.equals(ApplicationStatusTypeEnum.SUBMIT)) {
|
||||||
CallEntity callEntity = applicationEntity.getCall();
|
// CallEntity callEntity = applicationEntity.getCall();
|
||||||
// Long initialFormId = callEntity.getInitialForm();
|
// Long initialFormId = callEntity.getInitialForm();
|
||||||
// Long finalFormId = callEntity.getFinalForm();
|
// Long finalFormId = callEntity.getFinalForm();
|
||||||
//// if (initialFormId == null || finalFormId == null) {
|
//// if (initialFormId == null || finalFormId == null) {
|
||||||
@@ -501,7 +535,7 @@ public class ApplicationDao {
|
|||||||
return (int) Math.round(progress);
|
return (int) Math.round(progress);
|
||||||
}
|
}
|
||||||
public void validateFormFields(ApplicationRequestBean request, FormEntity formEntity) {
|
public void validateFormFields(ApplicationRequestBean request, FormEntity formEntity) {
|
||||||
List<String> errors=new ArrayList<>();
|
|
||||||
List<ContentResponseBean> contentResponseBeans=Utils.convertJsonStringToList(formEntity.getContent(),ContentResponseBean.class);
|
List<ContentResponseBean> contentResponseBeans=Utils.convertJsonStringToList(formEntity.getContent(),ContentResponseBean.class);
|
||||||
|
|
||||||
List<ApplicationFormFieldRequestBean> requestFields = request.getFormFields();
|
List<ApplicationFormFieldRequestBean> requestFields = request.getFormFields();
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ public class CompanyDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void validateCompany(CompanyRequest companyRequest) {
|
private void validateCompany(CompanyRequest companyRequest) {
|
||||||
|
|
||||||
if (Boolean.FALSE.equals(StringUtils.isEmpty(companyRequest.getEmail()))
|
if (Boolean.FALSE.equals(StringUtils.isEmpty(companyRequest.getEmail()))
|
||||||
&& Boolean.FALSE.equals(Utils.isValidEmail(companyRequest.getEmail()))) {
|
&& Boolean.FALSE.equals(Utils.isValidEmail(companyRequest.getEmail()))) {
|
||||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
@@ -55,7 +56,6 @@ public class CompanyDao {
|
|||||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
Translator.toLocale(GepafinConstant.VATNUMBER_ALREADY_EXISTS));
|
Translator.toLocale(GepafinConstant.VATNUMBER_ALREADY_EXISTS));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private UserWithCompanyEntity createUserWithCompanyRelation(UserEntity userEntity, CompanyEntity companyEntity) {
|
private UserWithCompanyEntity createUserWithCompanyRelation(UserEntity userEntity, CompanyEntity companyEntity) {
|
||||||
@@ -153,4 +153,9 @@ public class CompanyDao {
|
|||||||
return list.stream().map(this::convertCompanyEntityToCompanyResponse).toList();
|
return list.stream().map(this::convertCompanyEntityToCompanyResponse).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UserWithCompanyEntity validateUserWithCompny(Long userId, Long companyId) {
|
||||||
|
return userWithCompanyRepository.findByUserIdAndCompanyId(userId, companyId).orElseThrow(() -> new CustomValidationException(Status.UNAUTHORIZED,
|
||||||
|
Translator.toLocale(GepafinConstant.UNAUTHORIZED)));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,11 @@ import net.gepafin.tendermanagement.model.request.FaqReq;
|
|||||||
import net.gepafin.tendermanagement.model.response.FaqResponseBean;
|
import net.gepafin.tendermanagement.model.response.FaqResponseBean;
|
||||||
import net.gepafin.tendermanagement.repositories.FaqRepository;
|
import net.gepafin.tendermanagement.repositories.FaqRepository;
|
||||||
import net.gepafin.tendermanagement.service.CallService;
|
import net.gepafin.tendermanagement.service.CallService;
|
||||||
|
import net.gepafin.tendermanagement.service.CompanyService;
|
||||||
import net.gepafin.tendermanagement.service.LookUpDataService;
|
import net.gepafin.tendermanagement.service.LookUpDataService;
|
||||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||||
|
import net.gepafin.tendermanagement.util.Validator;
|
||||||
|
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.ResourceNotFoundException;
|
||||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -36,11 +39,24 @@ public class FaqDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private LookUpDataService lookUpDataService;
|
private LookUpDataService lookUpDataService;
|
||||||
|
|
||||||
public FaqResponseBean createFaq(FaqReq faqRequest, UserEntity userEntity, Long callId) {
|
@Autowired
|
||||||
FaqEntity entity = new FaqEntity();
|
private Validator validator;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CompanyService companyService;
|
||||||
|
|
||||||
|
public FaqResponseBean createFaq(FaqReq faqRequest, UserEntity userEntity, Long callId, Long companyId) {
|
||||||
CallEntity callEntity = callService.validateCall(callId);
|
CallEntity callEntity = callService.validateCall(callId);
|
||||||
entity = createOrUpdateFaqEntity(faqRequest, callEntity, userEntity,
|
FaqEntity entity = createOrUpdateFaqEntity(faqRequest, callEntity, userEntity,
|
||||||
LookUpDataEntity.LookUpDataTypeEnum.FAQ);
|
LookUpDataEntity.LookUpDataTypeEnum.FAQ);
|
||||||
|
if (validator.checkIsBeneficiary() && companyId == null) {
|
||||||
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
|
Translator.toLocale(GepafinConstant.COMPANY_ID_MANDATORY));
|
||||||
|
}
|
||||||
|
if(companyId!=null) {
|
||||||
|
companyService.validateCompany(companyId);
|
||||||
|
entity.setCompanyId(companyId);
|
||||||
|
}
|
||||||
faqRepository.save(entity);
|
faqRepository.save(entity);
|
||||||
return convertToFaqResponseBean(entity);
|
return convertToFaqResponseBean(entity);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,20 +4,16 @@ import net.gepafin.tendermanagement.config.Translator;
|
|||||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
import net.gepafin.tendermanagement.entities.CallEntity;
|
import net.gepafin.tendermanagement.entities.CallEntity;
|
||||||
import net.gepafin.tendermanagement.entities.FlowDataEntity;
|
import net.gepafin.tendermanagement.entities.FlowDataEntity;
|
||||||
import net.gepafin.tendermanagement.entities.FlowDataEntity;
|
|
||||||
import net.gepafin.tendermanagement.entities.FlowEdgesEntity;
|
import net.gepafin.tendermanagement.entities.FlowEdgesEntity;
|
||||||
import net.gepafin.tendermanagement.enums.CallStatusEnum;
|
import net.gepafin.tendermanagement.enums.CallStatusEnum;
|
||||||
import net.gepafin.tendermanagement.model.request.FlowDataRequestBean;
|
import net.gepafin.tendermanagement.model.request.FlowDataRequestBean;
|
||||||
import net.gepafin.tendermanagement.model.request.FlowEdgesRequestBean;
|
import net.gepafin.tendermanagement.model.request.FlowEdgesRequestBean;
|
||||||
import net.gepafin.tendermanagement.model.request.FlowRequestBean;
|
import net.gepafin.tendermanagement.model.request.FlowRequestBean;
|
||||||
import net.gepafin.tendermanagement.model.response.EvaluationCriteriaResponseBean;
|
|
||||||
import net.gepafin.tendermanagement.model.response.FlowDataResponseBean;
|
import net.gepafin.tendermanagement.model.response.FlowDataResponseBean;
|
||||||
import net.gepafin.tendermanagement.model.response.FlowEdgesResponseBean;
|
import net.gepafin.tendermanagement.model.response.FlowEdgesResponseBean;
|
||||||
import net.gepafin.tendermanagement.model.response.FlowResponseBean;
|
import net.gepafin.tendermanagement.model.response.FlowResponseBean;
|
||||||
import net.gepafin.tendermanagement.repositories.CallRepository;
|
import net.gepafin.tendermanagement.repositories.CallRepository;
|
||||||
import net.gepafin.tendermanagement.repositories.FlowDataRepository;
|
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.repositories.FlowEdgesRepository;
|
||||||
import net.gepafin.tendermanagement.service.CallService;
|
import net.gepafin.tendermanagement.service.CallService;
|
||||||
import net.gepafin.tendermanagement.service.FormService;
|
import net.gepafin.tendermanagement.service.FormService;
|
||||||
@@ -29,7 +25,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package net.gepafin.tendermanagement.dao;
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||||
import net.gepafin.tendermanagement.repositories.*;
|
import net.gepafin.tendermanagement.repositories.*;
|
||||||
@@ -20,7 +19,6 @@ import net.gepafin.tendermanagement.enums.FormActionEnum;
|
|||||||
import net.gepafin.tendermanagement.model.response.NextOrPreviousFormResponse;
|
import net.gepafin.tendermanagement.model.response.NextOrPreviousFormResponse;
|
||||||
import net.gepafin.tendermanagement.service.FormService;
|
import net.gepafin.tendermanagement.service.FormService;
|
||||||
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
|
||||||
@@ -296,6 +294,8 @@ public class FlowFormDao {
|
|||||||
applicationDao.processForm(formEntity, applicationEntity));
|
applicationDao.processForm(formEntity, applicationEntity));
|
||||||
nextOrPreviousFormResponse.setCallId(applicationEntity.getCall().getId());
|
nextOrPreviousFormResponse.setCallId(applicationEntity.getCall().getId());
|
||||||
nextOrPreviousFormResponse.setCallTitle(applicationEntity.getCall().getName());
|
nextOrPreviousFormResponse.setCallTitle(applicationEntity.getCall().getName());
|
||||||
|
nextOrPreviousFormResponse.setCompanyId(applicationEntity.getCompany().getId());
|
||||||
|
nextOrPreviousFormResponse.setCompanyName(applicationEntity.getCompany().getCompanyName());
|
||||||
|
|
||||||
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
|
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
|
||||||
Long totalFormSteps = calculateTotalSteps(flowEdgesList);
|
Long totalFormSteps = calculateTotalSteps(flowEdgesList);
|
||||||
|
|||||||
@@ -13,9 +13,12 @@ import java.time.LocalDateTime;
|
|||||||
@Builder
|
@Builder
|
||||||
public class ApplicationEntity extends BaseEntity {
|
public class ApplicationEntity extends BaseEntity {
|
||||||
|
|
||||||
|
@Column(name = "USER_ID")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "USER_ID", nullable = false)
|
@JoinColumn(name = "COMPANY_ID", nullable = false)
|
||||||
private UserEntity user;
|
private CompanyEntity company;
|
||||||
|
|
||||||
@Column(name = "SUBMISSION_DATE")
|
@Column(name = "SUBMISSION_DATE")
|
||||||
private LocalDateTime submissionDate;
|
private LocalDateTime submissionDate;
|
||||||
|
|||||||
@@ -42,5 +42,8 @@ public class FaqEntity extends BaseEntity {
|
|||||||
@Column(name ="IS_DELETED", nullable = false)
|
@Column(name ="IS_DELETED", nullable = false)
|
||||||
private Boolean isDeleted = false;
|
private Boolean isDeleted = false;
|
||||||
|
|
||||||
|
@Column(name ="COMPANY_ID")
|
||||||
|
private Long companyId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ public class ApplicationGetResponseBean {
|
|||||||
|
|
||||||
private String callTitle;
|
private String callTitle;
|
||||||
|
|
||||||
|
private Long companyId;
|
||||||
|
|
||||||
|
private String companyName;
|
||||||
|
|
||||||
private List<FormApplicationResponse> form;
|
private List<FormApplicationResponse> form;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,4 +27,8 @@ public class ApplicationResponse{
|
|||||||
|
|
||||||
private String comments;
|
private String comments;
|
||||||
|
|
||||||
|
private Long companyId;
|
||||||
|
|
||||||
|
private String companyName;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -18,6 +18,10 @@ public class NextOrPreviousFormResponse {
|
|||||||
|
|
||||||
private Long currentStep;
|
private Long currentStep;
|
||||||
|
|
||||||
|
private Long companyId;
|
||||||
|
|
||||||
|
private String companyName;
|
||||||
|
|
||||||
private ApplicationStatusTypeEnum applicationStatus;
|
private ApplicationStatusTypeEnum applicationStatus;
|
||||||
|
|
||||||
private FormApplicationResponse applicationFormResponse;
|
private FormApplicationResponse applicationFormResponse;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package net.gepafin.tendermanagement.repositories;
|
|||||||
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
||||||
import net.gepafin.tendermanagement.entities.FaqEntity;
|
import net.gepafin.tendermanagement.entities.FaqEntity;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
@@ -11,9 +12,7 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface ApplicationRepository extends JpaRepository<ApplicationEntity,Long> {
|
public interface ApplicationRepository extends JpaRepository<ApplicationEntity, Long>, JpaSpecificationExecutor<ApplicationEntity> {
|
||||||
|
|
||||||
public Optional<ApplicationEntity> findByUserIdAndCallIdAndIsDeletedFalse(Long userId,Long callId);
|
|
||||||
|
|
||||||
public List<ApplicationEntity> findByUserIdAndIsDeletedFalse(Long userId);
|
public List<ApplicationEntity> findByUserIdAndIsDeletedFalse(Long userId);
|
||||||
|
|
||||||
@@ -26,4 +25,9 @@ public interface ApplicationRepository extends JpaRepository<ApplicationEntity,L
|
|||||||
|
|
||||||
public Optional<ApplicationEntity> findByIdAndUserIdAndIsDeletedFalse(Long id,Long userId);
|
public Optional<ApplicationEntity> findByIdAndUserIdAndIsDeletedFalse(Long id,Long userId);
|
||||||
|
|
||||||
|
Optional<ApplicationEntity> findByCompanyIdAndCallIdAndIsDeletedFalse(Long companyId, Long callId);
|
||||||
|
|
||||||
|
public Optional<ApplicationEntity> findByIdAndUserIdAndCallIdAndIsDeletedFalse(Long applicationId, Long userId,
|
||||||
|
Long callId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.gepafin.tendermanagement.repositories;
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
@@ -16,4 +17,6 @@ public interface UserWithCompanyRepository extends JpaRepository<UserWithCompany
|
|||||||
@Query("SELECT uwc.companyId FROM UserWithCompanyEntity uwc WHERE uwc.userId = :userId")
|
@Query("SELECT uwc.companyId FROM UserWithCompanyEntity uwc WHERE uwc.userId = :userId")
|
||||||
List<Long> findCompanyIdByUserId(@Param("userId") Long userId);
|
List<Long> findCompanyIdByUserId(@Param("userId") Long userId);
|
||||||
|
|
||||||
|
Optional<UserWithCompanyEntity> findByUserIdAndCompanyId(Long userId, Long companyId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,15 +19,16 @@ public interface ApplicationService {
|
|||||||
|
|
||||||
ApplicationGetResponseBean getApplicationByFormId(HttpServletRequest request, Long applicationId,Long formId);
|
ApplicationGetResponseBean getApplicationByFormId(HttpServletRequest request, Long applicationId,Long formId);
|
||||||
|
|
||||||
List<ApplicationResponse> getAllApplications(HttpServletRequest request,Long callId);
|
List<ApplicationResponse> getAllApplications(HttpServletRequest request,Long callId, Long companyId);
|
||||||
|
|
||||||
void deleteApplication(HttpServletRequest request, Long applicationId);
|
void deleteApplication(HttpServletRequest request, Long applicationId);
|
||||||
|
|
||||||
public ApplicationEntity validateApplication(Long userId);
|
public ApplicationEntity validateApplication(Long userId);
|
||||||
|
|
||||||
public ApplicationResponse createApplication(HttpServletRequest request, ApplicationRequest applicationRequest, Long callId);
|
public ApplicationResponse createApplication(HttpServletRequest request, Long companyId, ApplicationRequest applicationRequest, Long callId);
|
||||||
|
|
||||||
public NextOrPreviousFormResponse getNextOrPreviousForm(HttpServletRequest request, Long applicationId, 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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import net.gepafin.tendermanagement.entities.CompanyEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.UserWithCompanyEntity;
|
||||||
import net.gepafin.tendermanagement.model.request.CompanyRequest;
|
import net.gepafin.tendermanagement.model.request.CompanyRequest;
|
||||||
import net.gepafin.tendermanagement.model.response.CompanyResponse;
|
import net.gepafin.tendermanagement.model.response.CompanyResponse;
|
||||||
|
|
||||||
@@ -21,4 +23,8 @@ public interface CompanyService {
|
|||||||
|
|
||||||
Map<String, Object> checkVatNumber(HttpServletRequest request, String vatNumber);
|
Map<String, Object> checkVatNumber(HttpServletRequest request, String vatNumber);
|
||||||
|
|
||||||
|
CompanyEntity validateCompany(Long companyId);
|
||||||
|
|
||||||
|
UserWithCompanyEntity validateUserWithCompny(Long userId, Long companyId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import net.gepafin.tendermanagement.model.response.FaqResponseBean;
|
|||||||
|
|
||||||
public interface FaqService {
|
public interface FaqService {
|
||||||
|
|
||||||
FaqResponseBean createFaq(HttpServletRequest request,Long callId, FaqReq faqRequest);
|
FaqResponseBean createFaq(HttpServletRequest request,Long callId, Long companyId, FaqReq faqRequest);
|
||||||
|
|
||||||
FaqResponseBean getFaqById(HttpServletRequest request, Long id);
|
FaqResponseBean getFaqById(HttpServletRequest request, Long id);
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import jakarta.servlet.http.HttpServletRequest;
|
|||||||
import net.gepafin.tendermanagement.dao.ApplicationDao;
|
import net.gepafin.tendermanagement.dao.ApplicationDao;
|
||||||
import net.gepafin.tendermanagement.dao.FlowFormDao;
|
import net.gepafin.tendermanagement.dao.FlowFormDao;
|
||||||
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.CompanyEntity;
|
||||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||||
import net.gepafin.tendermanagement.model.request.ApplicationRequest;
|
import net.gepafin.tendermanagement.model.request.ApplicationRequest;
|
||||||
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||||
@@ -35,7 +36,8 @@ public class ApplicationServiceImpl implements ApplicationService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public ApplicationResponseBean createApplication(HttpServletRequest request, ApplicationRequestBean applicationRequestBean,Long applicationId, Long formId) {
|
public ApplicationResponseBean createApplication(HttpServletRequest request,
|
||||||
|
ApplicationRequestBean applicationRequestBean, Long applicationId, Long formId) {
|
||||||
UserEntity userEntity = validator.validateUser(request);
|
UserEntity userEntity = validator.validateUser(request);
|
||||||
return applicationDao.createApplication(applicationRequestBean, userEntity, formId, applicationId);
|
return applicationDao.createApplication(applicationRequestBean, userEntity, formId, applicationId);
|
||||||
}
|
}
|
||||||
@@ -60,9 +62,10 @@ public class ApplicationServiceImpl implements ApplicationService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public ApplicationResponse createApplication(HttpServletRequest request, ApplicationRequest applicationRequest, Long callId) {
|
public ApplicationResponse createApplication(HttpServletRequest request, Long companyId, ApplicationRequest applicationRequest, Long callId) {
|
||||||
UserEntity userEntity = validator.validateUser(request);
|
UserEntity userEntity = validator.validateUser(request);
|
||||||
return applicationDao.createApplicationByCallId(applicationRequest,callId,userEntity);
|
CompanyEntity companyEntity = validator.validateUSerWithCompany(request, companyId);
|
||||||
|
return applicationDao.createApplicationByCallId(companyEntity, applicationRequest, callId, userEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -80,8 +83,11 @@ public class ApplicationServiceImpl implements ApplicationService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public List<ApplicationResponse> getAllApplications(HttpServletRequest request,Long callId) {
|
public List<ApplicationResponse> getAllApplications(HttpServletRequest request, Long callId, Long companyId) {
|
||||||
UserEntity userEntity = validator.validateUser(request);
|
UserEntity userEntity = validator.validateUser(request);
|
||||||
return applicationDao.getAllApplications(userEntity,callId);
|
if (companyId != null) {
|
||||||
|
validator.validateUSerWithCompany(request, companyId);
|
||||||
|
}
|
||||||
|
return applicationDao.getAllApplications(userEntity, callId, companyId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import net.gepafin.tendermanagement.dao.CompanyDao;
|
import net.gepafin.tendermanagement.dao.CompanyDao;
|
||||||
import net.gepafin.tendermanagement.dao.VatCheckDao;
|
import net.gepafin.tendermanagement.dao.VatCheckDao;
|
||||||
|
import net.gepafin.tendermanagement.entities.CompanyEntity;
|
||||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.UserWithCompanyEntity;
|
||||||
import net.gepafin.tendermanagement.model.request.CompanyRequest;
|
import net.gepafin.tendermanagement.model.request.CompanyRequest;
|
||||||
import net.gepafin.tendermanagement.model.response.CompanyResponse;
|
import net.gepafin.tendermanagement.model.response.CompanyResponse;
|
||||||
import net.gepafin.tendermanagement.service.CompanyService;
|
import net.gepafin.tendermanagement.service.CompanyService;
|
||||||
@@ -68,5 +70,14 @@ public class CompanyServiceImpl implements CompanyService {
|
|||||||
public Map<String, Object> checkVatNumber(HttpServletRequest request, String vatNumber) {
|
public Map<String, Object> checkVatNumber(HttpServletRequest request, String vatNumber) {
|
||||||
return vatCheckDao.checkVatNumber(vatNumber);
|
return vatCheckDao.checkVatNumber(vatNumber);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public CompanyEntity validateCompany(Long companyId) {
|
||||||
|
return companyDao.validateCompany(companyId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserWithCompanyEntity validateUserWithCompny(Long userId, Long companyId) {
|
||||||
|
return companyDao.validateUserWithCompny(userId, companyId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ public class FaqServiceImpl implements FaqService {
|
|||||||
private Validator validator;
|
private Validator validator;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FaqResponseBean createFaq(HttpServletRequest request,Long callId, FaqReq faqRequest) {
|
public FaqResponseBean createFaq(HttpServletRequest request,Long callId, Long companyId, FaqReq faqRequest) {
|
||||||
UserEntity userEntity = validator.validateUser(request);
|
UserEntity userEntity = validator.validateUser(request);
|
||||||
return faqDao.createFaq(faqRequest, userEntity,callId);
|
return faqDao.createFaq(faqRequest, userEntity, callId, companyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ import jakarta.servlet.http.HttpServletRequest;
|
|||||||
import net.gepafin.tendermanagement.config.Translator;
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
import net.gepafin.tendermanagement.config.jwt.TokenProvider;
|
import net.gepafin.tendermanagement.config.jwt.TokenProvider;
|
||||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
|
import net.gepafin.tendermanagement.entities.CompanyEntity;
|
||||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||||
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||||
|
import net.gepafin.tendermanagement.service.CompanyService;
|
||||||
import net.gepafin.tendermanagement.service.UserService;
|
import net.gepafin.tendermanagement.service.UserService;
|
||||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
import net.gepafin.tendermanagement.web.rest.api.errors.UnauthorizedAccessException;
|
import net.gepafin.tendermanagement.web.rest.api.errors.UnauthorizedAccessException;
|
||||||
@@ -27,6 +29,9 @@ public class Validator {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CompanyService companyService;
|
||||||
|
|
||||||
public Map<String, Object> getUserInfoFromToken(HttpServletRequest request) {
|
public Map<String, Object> getUserInfoFromToken(HttpServletRequest request) {
|
||||||
return tokenProvider.getUserInfoAndUserIdFromToken(request);
|
return tokenProvider.getUserInfoAndUserIdFromToken(request);
|
||||||
}
|
}
|
||||||
@@ -36,7 +41,7 @@ public class Validator {
|
|||||||
return userService.validateUser(Long.parseLong(userInfo.get("userId").toString()));
|
return userService.validateUser(Long.parseLong(userInfo.get("userId").toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean checkIsSuperAdmin(HttpServletRequest request) {
|
public Boolean checkIsSuperAdmin() {
|
||||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
|
|
||||||
if (authentication != null && authentication.isAuthenticated()) {
|
if (authentication != null && authentication.isAuthenticated()) {
|
||||||
@@ -51,9 +56,35 @@ public class Validator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void validateRequest(HttpServletRequest request,RoleStatusEnum role) {
|
public void validateRequest(HttpServletRequest request,RoleStatusEnum role) {
|
||||||
if (RoleStatusEnum.ROLE_SUPER_ADMIN.equals(role) && Boolean.FALSE.equals(checkIsSuperAdmin(request))) {
|
if (RoleStatusEnum.ROLE_SUPER_ADMIN.equals(role) && Boolean.FALSE.equals(checkIsSuperAdmin())) {
|
||||||
throw new UnauthorizedAccessException(Status.UNAUTHORIZED, Translator.toLocale(GepafinConstant.INVALID_REQUEST));
|
throw new UnauthorizedAccessException(Status.UNAUTHORIZED, Translator.toLocale(GepafinConstant.INVALID_REQUEST));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CompanyEntity validateUSerWithCompany(HttpServletRequest request, Long companyId) {
|
||||||
|
if (checkIsSuperAdmin()) {
|
||||||
|
return companyService.validateCompany(companyId);
|
||||||
|
}
|
||||||
|
Map<String, Object> userInfo = tokenProvider.getUserInfoAndUserIdFromToken(request);
|
||||||
|
companyService.validateUserWithCompny(getUserId(userInfo), companyId);
|
||||||
|
return companyService.validateCompany(companyId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Long getUserId(Map<String, Object> userInfo) {
|
||||||
|
return Long.parseLong(userInfo.get("userId").toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean checkIsBeneficiary() {
|
||||||
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
|
if (authentication != null && authentication.isAuthenticated()) {
|
||||||
|
// Check if the user has the ROLE_SUPER_ADMIN authority
|
||||||
|
for (GrantedAuthority authority : authentication.getAuthorities()) {
|
||||||
|
if (RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(authority.getAuthority())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,8 @@ public interface ApplicationApi {
|
|||||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
||||||
@GetMapping(value = "", produces = "application/json")
|
@GetMapping(value = "", produces = "application/json")
|
||||||
ResponseEntity<Response<List<ApplicationResponse>>> getAllApplications(HttpServletRequest request,
|
ResponseEntity<Response<List<ApplicationResponse>>> getAllApplications(HttpServletRequest request,
|
||||||
@Parameter(description = "The call id", required = false) @RequestParam(value = "callId", required = false) Long callId);
|
@Parameter(description = "The call id", required = false) @RequestParam(value = "callId", required = false) Long callId,
|
||||||
|
@Parameter(description = "The company id", required = false) @RequestParam(value = "companyId", required = false) Long companyId);
|
||||||
|
|
||||||
@Operation(summary = "Api to delete application",
|
@Operation(summary = "Api to delete application",
|
||||||
responses = {
|
responses = {
|
||||||
@@ -94,6 +95,7 @@ public interface ApplicationApi {
|
|||||||
@PostMapping(value = "/call/{callId}",
|
@PostMapping(value = "/call/{callId}",
|
||||||
produces = { "application/json" })
|
produces = { "application/json" })
|
||||||
ResponseEntity<Response<ApplicationResponse>> createApplicationByCallId(HttpServletRequest request,
|
ResponseEntity<Response<ApplicationResponse>> createApplicationByCallId(HttpServletRequest request,
|
||||||
|
@Parameter(description = "The company ID", required = true) @RequestParam(value = "companyId", required = true) Long companyId,
|
||||||
@Parameter(description = " Flow request object", required = true) @Valid @RequestBody ApplicationRequest applicationRequest,
|
@Parameter(description = " Flow request object", required = true) @Valid @RequestBody ApplicationRequest applicationRequest,
|
||||||
@Parameter(description = "The call ID", required = true) @PathVariable("callId") Long callId);
|
@Parameter(description = "The call ID", required = true) @PathVariable("callId") Long callId);
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,11 @@ public interface DocumentApi {
|
|||||||
@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) }))})
|
||||||
@PostMapping(value = "/uploadFile/source/{sourceId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
@PostMapping(value = "/uploadFile/source/{sourceId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
default ResponseEntity<Response<List<DocumentResponseBean>>> uploadFile(HttpServletRequest httpServletRequest, @Parameter(description = "Source Id", required = true) @PathVariable("sourceId") Long sourceId, @RequestParam DocumentSourceTypeEnum sourceType, @RequestParam("file") List<MultipartFile> files, @RequestParam("documentType") DocumentTypeEnum documentTypeEnum) {
|
default ResponseEntity<Response<List<DocumentResponseBean>>> uploadFile(HttpServletRequest httpServletRequest,
|
||||||
|
@Parameter(description = "Source Id", required = true) @PathVariable("sourceId") Long sourceId,
|
||||||
|
@RequestParam("sourceType") DocumentSourceTypeEnum sourceType,
|
||||||
|
@RequestParam("file") List<MultipartFile> files,
|
||||||
|
@RequestParam("documentType") DocumentTypeEnum documentTypeEnum) {
|
||||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public interface FaqApi {
|
|||||||
})
|
})
|
||||||
@PostMapping(value = "/call/{callId}", consumes = "application/json", produces = "application/json")
|
@PostMapping(value = "/call/{callId}", consumes = "application/json", produces = "application/json")
|
||||||
ResponseEntity<Response<FaqResponseBean>> createFaq(HttpServletRequest request, @Parameter(description = "call id", required = true)
|
ResponseEntity<Response<FaqResponseBean>> createFaq(HttpServletRequest request, @Parameter(description = "call id", required = true)
|
||||||
@PathVariable("callId") Long callId, @Valid @RequestBody FaqReq faqRequest);
|
@PathVariable("callId") Long callId, @RequestParam(value = "companyId", required = false) Long companyId, @Valid @RequestBody FaqReq faqRequest);
|
||||||
|
|
||||||
@Operation(summary = "API to get FAQ by id",
|
@Operation(summary = "API to get FAQ by id",
|
||||||
responses = {
|
responses = {
|
||||||
|
|||||||
@@ -60,14 +60,14 @@ public class ApplicationApiController implements ApplicationApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<Response<ApplicationResponse>> createApplicationByCallId(HttpServletRequest request, ApplicationRequest applicationRequest, Long callId) {
|
public ResponseEntity<Response<ApplicationResponse>> createApplicationByCallId(HttpServletRequest request, Long companyId, ApplicationRequest applicationRequest, Long callId) {
|
||||||
ApplicationResponse applicationResponseBean=applicationService.createApplication(request,applicationRequest,callId);
|
ApplicationResponse applicationResponseBean=applicationService.createApplication(request, companyId, applicationRequest, callId);
|
||||||
return ResponseEntity.status(HttpStatus.CREATED)
|
return ResponseEntity.status(HttpStatus.CREATED)
|
||||||
.body(new Response<>(applicationResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.APPLICATION_CREATED_SUCCESS_MSG)));
|
.body(new Response<>(applicationResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.APPLICATION_CREATED_SUCCESS_MSG)));
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<Response<List<ApplicationResponse>>> getAllApplications(HttpServletRequest request,Long callId) {
|
public ResponseEntity<Response<List<ApplicationResponse>>> getAllApplications(HttpServletRequest request,Long callId,Long companyId) {
|
||||||
List<ApplicationResponse> applications = applicationService.getAllApplications(request,callId);
|
List<ApplicationResponse> applications = applicationService.getAllApplications(request,callId,companyId);
|
||||||
log.info("Get All Applications");
|
log.info("Get All Applications");
|
||||||
return ResponseEntity.status(HttpStatus.OK)
|
return ResponseEntity.status(HttpStatus.OK)
|
||||||
.body(new Response<>(applications, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_APPLICATION_SUCCESS_MSG)));
|
.body(new Response<>(applications, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_APPLICATION_SUCCESS_MSG)));
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ public class FaqApiController implements FaqApi {
|
|||||||
private FaqService faqService;
|
private FaqService faqService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<Response<FaqResponseBean>> createFaq(HttpServletRequest request, Long callId,FaqReq faqRequest) {
|
public ResponseEntity<Response<FaqResponseBean>> createFaq(HttpServletRequest request, Long callId, Long companyId, FaqReq faqRequest) {
|
||||||
FaqResponseBean response = faqService.createFaq(request,callId, faqRequest);
|
FaqResponseBean response = faqService.createFaq(request,callId, companyId, faqRequest);
|
||||||
return ResponseEntity.status(HttpStatus.CREATED)
|
return ResponseEntity.status(HttpStatus.CREATED)
|
||||||
.body(new Response<>(response, Status.SUCCESS, Translator.toLocale(GepafinConstant.FAQ_CREATED_SUCCESSFULLY)));
|
.body(new Response<>(response, Status.SUCCESS, Translator.toLocale(GepafinConstant.FAQ_CREATED_SUCCESSFULLY)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -814,4 +814,15 @@
|
|||||||
</createTable>
|
</createTable>
|
||||||
</changeSet>
|
</changeSet>
|
||||||
|
|
||||||
|
<changeSet id="27-09-2024_4" author="Rajesh Khore">
|
||||||
|
<addColumn tableName="APPLICATION">
|
||||||
|
<column name="COMPANY_ID" type="INTEGER">
|
||||||
|
<constraints nullable="true" foreignKeyName="fk_COMPANY_APPLICATION" references="company(id)"/>
|
||||||
|
</column>
|
||||||
|
</addColumn>
|
||||||
|
<addColumn tableName="FAQ">
|
||||||
|
<column name="COMPANY_ID" type="INTEGER"/>
|
||||||
|
</addColumn>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
||||||
|
|||||||
@@ -204,3 +204,4 @@ invalid.vatnumber=Invalid VAT number.
|
|||||||
vatnumber.mandatory=VatNumber is mandatory.
|
vatnumber.mandatory=VatNumber is mandatory.
|
||||||
vatnumber.already.exists=VatNumber already exists.
|
vatnumber.already.exists=VatNumber already exists.
|
||||||
invalid.email=Invalid email.
|
invalid.email=Invalid email.
|
||||||
|
company.id.mandatory=Company id is mandatory.
|
||||||
|
|||||||
@@ -197,3 +197,4 @@ invalid.vatnumber=Numero di partita IVA non valido.
|
|||||||
vatnumber.mandatory=Il numero di partita IVA è obbligatorio.
|
vatnumber.mandatory=Il numero di partita IVA è obbligatorio.
|
||||||
vatnumber.already.exists=Il numero di partita IVA esiste già.
|
vatnumber.already.exists=Il numero di partita IVA esiste già.
|
||||||
invalid.email=Email non valida.
|
invalid.email=Email non valida.
|
||||||
|
company.id.mandatory=L'ID dell'azienda è obbligatorio.
|
||||||
|
|||||||
Reference in New Issue
Block a user