Updated application validation related to company delegation
This commit is contained in:
@@ -198,5 +198,6 @@ public class GepafinConstant {
|
||||
public static final String DELEGATION_NOT_FOUND = "delegation.not.found";
|
||||
public static final String USER_COMPANY_RELATION_NOT_FOUND = "user.company.relation.not.found";
|
||||
public static final String DELEGATION_DELETE_SUCCESS = "delegation.delete.success";
|
||||
public static final String USER_NOT_AUTHORIZED_TO_CREATE_APPLICATION = "user.not.authorized.create.application";
|
||||
|
||||
}
|
||||
|
||||
@@ -6,12 +6,14 @@ import net.gepafin.tendermanagement.entities.*;
|
||||
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||
import net.gepafin.tendermanagement.enums.UserCompanyDelegationStatusEnum;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationFormFieldRequestBean;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationRequest;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationRequestBean;
|
||||
import net.gepafin.tendermanagement.model.response.*;
|
||||
import net.gepafin.tendermanagement.repositories.*;
|
||||
import net.gepafin.tendermanagement.service.CallService;
|
||||
import net.gepafin.tendermanagement.service.CompanyService;
|
||||
import net.gepafin.tendermanagement.service.DocumentService;
|
||||
import net.gepafin.tendermanagement.service.FormService;
|
||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||
@@ -68,10 +70,14 @@ public class ApplicationDao {
|
||||
|
||||
@Autowired
|
||||
private FlowDataRepository flowDataRepository;
|
||||
|
||||
@Autowired
|
||||
private UserWithCompanyRepository userWithCompanyRepository;
|
||||
@Autowired
|
||||
private UserCompanyDelegationRepository userCompanyDelegationRepository;
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
|
||||
@Autowired
|
||||
private CompanyService companyService;
|
||||
|
||||
public ApplicationResponseBean createApplication(ApplicationRequestBean applicationRequestBean, UserEntity userEntity, Long formId, Long applicationId) {
|
||||
FormEntity formEntity = formService.validateForm(formId);
|
||||
@@ -86,6 +92,19 @@ public class ApplicationDao {
|
||||
createOrUpdateMultipleFormFields(applicationRequestBean.getFormFields(), applicationFormEntity,formEntity);
|
||||
return getApplicationById(applicationEntity.getId(),formEntity.getId());
|
||||
}
|
||||
public void validateDelegation(UserEntity user, CompanyEntity company) {
|
||||
UserWithCompanyEntity userWithCompany = companyService.getUserWithCompanyEntity(user.getId(), company.getId());
|
||||
|
||||
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
|
||||
.findByUserIdAndCompanyIdAndStatus(user.getId(), company.getId(),
|
||||
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
|
||||
|
||||
if (!userWithCompany.getIsLegalRepresentant() && userCompanyDelegationEntity == null) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST,
|
||||
Translator.toLocale(GepafinConstant.USER_NOT_AUTHORIZED_TO_CREATE_APPLICATION));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ApplicationFormEntity saveApplicationFormEntity(ApplicationFormEntity applicationFormEntity) {
|
||||
ApplicationFormEntity applicationFormEntity1 = applicationFormRepository.save(applicationFormEntity);
|
||||
@@ -101,6 +120,7 @@ public class ApplicationDao {
|
||||
}
|
||||
|
||||
public ApplicationEntity createApplicationEntity(UserEntity user, CallEntity call, CompanyEntity companyEntity) {
|
||||
validateDelegation(user,companyEntity);
|
||||
ApplicationEntity entity = new ApplicationEntity();
|
||||
entity.setUserId(user.getId());
|
||||
entity.setCompany(companyEntity);
|
||||
@@ -505,7 +525,9 @@ public class ApplicationDao {
|
||||
|
||||
public ApplicationResponse updateApplicationStatus(Long applicationId, ApplicationStatusTypeEnum status) {
|
||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||
|
||||
if (ApplicationStatusTypeEnum.SUBMIT.getValue().equals(applicationEntity.getStatus())) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_SUBMITTED));
|
||||
}
|
||||
if (status.equals(ApplicationStatusTypeEnum.SUBMIT)) {
|
||||
callService.validatePublishedCall(applicationEntity.getCall().getId());
|
||||
// CallEntity callEntity = applicationEntity.getCall();
|
||||
|
||||
@@ -39,5 +39,7 @@ public interface CompanyService {
|
||||
CompanyDelegationResponse getCompanyDelegation(HttpServletRequest request, Long companyId);
|
||||
|
||||
void deleteCompanyDelegation(HttpServletRequest request, Long companyId);
|
||||
UserWithCompanyEntity getUserWithCompanyEntity(Long userId,Long companyId);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -114,4 +114,7 @@ public class CompanyServiceImpl implements CompanyService {
|
||||
UserEntity userEntity =validator.validateUser(request);
|
||||
delegationDao.deleteCompanyDelegation(userEntity, companyId);
|
||||
}
|
||||
public UserWithCompanyEntity getUserWithCompanyEntity(Long userId,Long companyId){
|
||||
return companyDao.getUserWithCompany(userId,companyId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,5 +223,5 @@ application.status.updated.successfully = Application status updated successfull
|
||||
delegation.not.found=Delegation not found.
|
||||
user.company.relation.not.found=User with the specified company relation not found.
|
||||
delegation.delete.success=Delegation deleted successfully.
|
||||
|
||||
user.not.authorized.create.application=User must be a legal representative or have delegation.
|
||||
|
||||
|
||||
@@ -218,5 +218,7 @@ application.status.updated.successfully = Stato dell'applicazione aggiornato con
|
||||
delegation.not.found=Delega non trovata.
|
||||
user.company.relation.not.found=Relazione utente con l'azienda specificata non trovata.
|
||||
delegation.delete.success=Delega eliminata con successo.
|
||||
user.not.authorized.create.application=L'utente deve essere un rappresentante legale o avere una delega.
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user