updated code for hub new changes

This commit is contained in:
harish
2024-10-24 14:51:03 +05:30
parent 8f7eb354ea
commit 3c40470dfc
15 changed files with 130 additions and 47 deletions

View File

@@ -175,6 +175,7 @@ public class ApplicationDao {
entity.setUserId(user.getId()); entity.setUserId(user.getId());
entity.setCompany(companyEntity); entity.setCompany(companyEntity);
entity.setCall(call); entity.setCall(call);
entity.setHubId(call.getHub().getId());
entity.setIsDeleted(false); entity.setIsDeleted(false);
entity.setStatus(ApplicationStatusTypeEnum.DRAFT.getValue()); entity.setStatus(ApplicationStatusTypeEnum.DRAFT.getValue());
return entity; return entity;

View File

@@ -40,7 +40,7 @@ public class CompanyDao {
public CompanyResponse createCompany(UserEntity userEntity, CompanyRequest companyRequest) { public CompanyResponse createCompany(UserEntity userEntity, CompanyRequest companyRequest) {
CompanyEntity existingCompany = companyRepository.findByVatNumber(companyRequest.getVatNumber()); CompanyEntity existingCompany = companyRepository.findByVatNumberAndHubId(companyRequest.getVatNumber(), userEntity.getHub().getId());
UserWithCompanyEntity userWithCompanyEntity = null; UserWithCompanyEntity userWithCompanyEntity = null;
if (existingCompany != null) { if (existingCompany != null) {
UserWithCompanyEntity existingRelation = userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userEntity.getId(), existingCompany.getId()) UserWithCompanyEntity existingRelation = userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userEntity.getId(), existingCompany.getId())
@@ -53,7 +53,7 @@ public class CompanyDao {
} }
return convertCompanyEntityToCompanyResponse(existingCompany, userWithCompanyEntity); return convertCompanyEntityToCompanyResponse(existingCompany, userWithCompanyEntity);
} else { } else {
validateCompany(companyRequest); validateCompany(userEntity, companyRequest);
CompanyEntity companyEntity = convertCompanyRequestToCompanyEntity(companyRequest); CompanyEntity companyEntity = convertCompanyRequestToCompanyEntity(companyRequest);
companyRepository.save(companyEntity); companyRepository.save(companyEntity);
userWithCompanyEntity = createUserWithCompanyRelation(userEntity, companyEntity, companyRequest.getIsLegalRepresentant()); userWithCompanyEntity = createUserWithCompanyRelation(userEntity, companyEntity, companyRequest.getIsLegalRepresentant());
@@ -62,7 +62,7 @@ public class CompanyDao {
} }
private void validateCompany(CompanyRequest companyRequest) { private void validateCompany(UserEntity userEntity, 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()))) {
@@ -73,7 +73,7 @@ public class CompanyDao {
throw new CustomValidationException(Status.VALIDATION_ERROR, throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.VATNUMBER_MANDATORY)); Translator.toLocale(GepafinConstant.VATNUMBER_MANDATORY));
} }
if (companyRepository.existsByVatNumber(companyRequest.getVatNumber())) { if (companyRepository.existsByVatNumberAndHubId(companyRequest.getVatNumber(), userEntity.getHub().getId())) {
throw new CustomValidationException(Status.VALIDATION_ERROR, throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.VATNUMBER_ALREADY_EXISTS)); Translator.toLocale(GepafinConstant.VATNUMBER_ALREADY_EXISTS));
} }
@@ -186,7 +186,7 @@ public class CompanyDao {
public List<CompanyResponse> getCompanyByUserId(Long userId) { public List<CompanyResponse> getCompanyByUserId(Long userId) {
UserEntity userEntity = userService.validateUser(userId); UserEntity userEntity = userService.validateUser(userId);
List<Long> activeCompanyIds = userWithCompanyRepository.findActiveCompanyIdsByUserId(userEntity.getId()); List<Long> activeCompanyIds = userWithCompanyRepository.findActiveCompanyIdsByUserId(userEntity.getId());
List<CompanyEntity> companies = companyRepository.findByIdIn(activeCompanyIds); List<CompanyEntity> companies = companyRepository.findByIdInAndHubId(activeCompanyIds, userEntity.getHub().getId());
return companies.stream().map(companyEntity -> { return companies.stream().map(companyEntity -> {
UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyEntity.getId()); UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyEntity.getId());
return convertCompanyEntityToCompanyResponse(companyEntity, userWithCompanyEntity); return convertCompanyEntityToCompanyResponse(companyEntity, userWithCompanyEntity);

View File

@@ -94,7 +94,7 @@ public class DashboardDao {
} }
private void setNumberOfCompanies(Widget1 widget1, UserEntity requestedUserEntity) { private void setNumberOfCompanies(Widget1 widget1, UserEntity requestedUserEntity) {
Long numberOfCompanies = companyRepository.countTotalCompanies(); Long numberOfCompanies = companyRepository.countTotalCompaniesByHubId(requestedUserEntity.getHub().getId());
if (numberOfCompanies != null) { if (numberOfCompanies != null) {
widget1.setNumberOfCompany(numberOfCompanies); widget1.setNumberOfCompany(numberOfCompanies);
} }

View File

@@ -6,6 +6,7 @@ import net.gepafin.tendermanagement.config.SamlSuccessHandler;
import net.gepafin.tendermanagement.config.Translator; import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant; import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.BeneficiaryEntity; import net.gepafin.tendermanagement.entities.BeneficiaryEntity;
import net.gepafin.tendermanagement.entities.HubEntity;
import net.gepafin.tendermanagement.entities.RoleEntity; import net.gepafin.tendermanagement.entities.RoleEntity;
import net.gepafin.tendermanagement.entities.UserEntity; import net.gepafin.tendermanagement.entities.UserEntity;
import net.gepafin.tendermanagement.enums.RoleStatusEnum; import net.gepafin.tendermanagement.enums.RoleStatusEnum;
@@ -84,17 +85,17 @@ public class UserDao {
if(StringUtils.isEmpty(userReq.getHubUuid())) { if(StringUtils.isEmpty(userReq.getHubUuid())) {
userReq.setHubUuid(defaultHubUuid); userReq.setHubUuid(defaultHubUuid);
} }
validateUserRequest(request, tempToken, userReq); HubEntity hub = hubService.getHubByUuid(userReq.getHubUuid());
validateUserRequest(request, tempToken, userReq, hub);
validatePassword(userReq.getPassword(), userReq.getConfPassword(), tempToken); validatePassword(userReq.getPassword(), userReq.getConfPassword(), tempToken);
RoleEntity roleEntity = getRoleEntity(userReq.getRoleId()); RoleEntity roleEntity = getRoleEntity(userReq.getRoleId());
BeneficiaryEntity beneficiary = createBeneficiary(roleEntity, userReq); BeneficiaryEntity beneficiary = createBeneficiary(roleEntity, userReq, hub);
UserEntity userEntity = convertUserRequestToUserEntity(beneficiary, roleEntity, userReq); UserEntity userEntity = convertUserRequestToUserEntity(beneficiary, roleEntity, userReq, hub);
log.info("User created with ID: {}", userEntity.getId()); log.info("User created with ID: {}", userEntity.getId());
return authService.getJWTTokenBean(userEntity, Boolean.TRUE); return authService.getJWTTokenBean(userEntity, Boolean.TRUE);
} }
private BeneficiaryEntity createBeneficiary(RoleEntity roleEntity, UserReq userReq) { private BeneficiaryEntity createBeneficiary(RoleEntity roleEntity, UserReq userReq, HubEntity hub) {
BeneficiaryEntity beneficiaryEntity = null; BeneficiaryEntity beneficiaryEntity = null;
if (RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(roleEntity.getRoleType())) { if (RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(roleEntity.getRoleType())) {
beneficiaryEntity = new BeneficiaryEntity(); beneficiaryEntity = new BeneficiaryEntity();
@@ -114,12 +115,13 @@ public class UserDao {
beneficiaryEntity.setMarketing(userReq.getMarketing()); beneficiaryEntity.setMarketing(userReq.getMarketing());
beneficiaryEntity.setThirdParty(userReq.getThirdParty()); beneficiaryEntity.setThirdParty(userReq.getThirdParty());
beneficiaryEntity.setEmailPec(userReq.getEmailPec()); beneficiaryEntity.setEmailPec(userReq.getEmailPec());
beneficiaryEntity.setHubId(hub.getId());
beneficiaryEntity =beneficiaryRepository.save(beneficiaryEntity); beneficiaryEntity =beneficiaryRepository.save(beneficiaryEntity);
} }
return beneficiaryEntity; return beneficiaryEntity;
} }
private void validateUserRequest(HttpServletRequest request, String tempToken, UserReq userReq) { private void validateUserRequest(HttpServletRequest request, String tempToken, UserReq userReq, HubEntity hub) {
if (tempToken == null) { if (tempToken == null) {
validator.validateRequest(request,RoleStatusEnum.ROLE_SUPER_ADMIN); validator.validateRequest(request,RoleStatusEnum.ROLE_SUPER_ADMIN);
@@ -139,7 +141,7 @@ public class UserDao {
Translator.toLocale(GepafinConstant.EMAIL_ALREADY_EXISTS)); Translator.toLocale(GepafinConstant.EMAIL_ALREADY_EXISTS));
} }
if (Boolean.FALSE.equals(StringUtils.isEmpty(userReq.getCodiceFiscale())) if (Boolean.FALSE.equals(StringUtils.isEmpty(userReq.getCodiceFiscale()))
&& userRepository.existsByBeneficiaryCodiceFiscale(userReq.getCodiceFiscale())) { && userRepository.existsByBeneficiaryCodiceFiscaleAndHubId(userReq.getCodiceFiscale(), hub.getId())) {
log.error("User creation failed: CodiceFiscale {} already exists", userReq.getCodiceFiscale()); log.error("User creation failed: CodiceFiscale {} already exists", userReq.getCodiceFiscale());
throw new CustomValidationException(Status.VALIDATION_ERROR, throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.CODICE_FISCALE_EXISTS)); Translator.toLocale(GepafinConstant.CODICE_FISCALE_EXISTS));
@@ -206,7 +208,7 @@ public class UserDao {
return convertUserEntityToUserResponse(userEntity); return convertUserEntityToUserResponse(userEntity);
} }
private UserEntity convertUserRequestToUserEntity(BeneficiaryEntity beneficiary, RoleEntity roleEntity, UserReq userReq) { private UserEntity convertUserRequestToUserEntity(BeneficiaryEntity beneficiary, RoleEntity roleEntity, UserReq userReq, HubEntity hub) {
UserEntity userEntity = new UserEntity(); UserEntity userEntity = new UserEntity();
if(Boolean.FALSE.equals(StringUtils.isEmpty(userReq.getPassword()))) { if(Boolean.FALSE.equals(StringUtils.isEmpty(userReq.getPassword()))) {
userEntity.setPassword(passwordEncoder.encode(userReq.getPassword())); userEntity.setPassword(passwordEncoder.encode(userReq.getPassword()));
@@ -215,7 +217,7 @@ public class UserDao {
userEntity.setEmail(userReq.getEmail()); userEntity.setEmail(userReq.getEmail());
userEntity.setStatus(UserStatusEnum.ACTIVE.getValue()); userEntity.setStatus(UserStatusEnum.ACTIVE.getValue());
userEntity.setBeneficiary(beneficiary); userEntity.setBeneficiary(beneficiary);
userEntity.setHub(hubService.getHubByUuid(userReq.getHubUuid())); userEntity.setHub(hub);
if (Boolean.FALSE.equals(RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(roleEntity.getRoleType()))) { if (Boolean.FALSE.equals(RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(roleEntity.getRoleType()))) {
userEntity.setFirstName(userReq.getFirstName()); userEntity.setFirstName(userReq.getFirstName());
userEntity.setLastName(userReq.getLastName()); userEntity.setLastName(userReq.getLastName());

View File

@@ -39,4 +39,7 @@ public class ApplicationEntity extends BaseEntity {
@OneToOne @OneToOne
@JoinColumn(name = "PROTOCOL_NUMBER") @JoinColumn(name = "PROTOCOL_NUMBER")
private ProtocolEntity protocol; private ProtocolEntity protocol;
@Column(name = "HUB_ID")
private Long hubId;
} }

View File

@@ -61,4 +61,7 @@ public class BeneficiaryEntity extends BaseEntity {
@Column(name = "EMAIL_PEC") @Column(name = "EMAIL_PEC")
private String emailPec; private String emailPec;
@Column(name = "HUB_ID")
private Long hubId;
} }

View File

@@ -4,6 +4,8 @@ import java.math.BigDecimal;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import lombok.Data; import lombok.Data;
@@ -56,4 +58,9 @@ public class CompanyEntity extends BaseEntity{
@Column(name = "CONTACT_EMAIL") @Column(name = "CONTACT_EMAIL")
private String contactEmail; private String contactEmail;
@ManyToOne
@JoinColumn(name = "HUB_ID")
private HubEntity hub;
} }

View File

@@ -4,6 +4,7 @@ import java.util.List;
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;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import net.gepafin.tendermanagement.entities.CompanyEntity; import net.gepafin.tendermanagement.entities.CompanyEntity;
@@ -11,13 +12,14 @@ import net.gepafin.tendermanagement.entities.CompanyEntity;
@Repository @Repository
public interface CompanyRepository extends JpaRepository<CompanyEntity, Long> { public interface CompanyRepository extends JpaRepository<CompanyEntity, Long> {
List<CompanyEntity> findByIdIn(List<Long> companyIds); List<CompanyEntity> findByIdInAndHubId(List<Long> companyIds, Long hubId);
Boolean existsByVatNumber(String vatNumber); Boolean existsByVatNumberAndHubId(String vatNumber, Long hubId);
CompanyEntity findByVatNumber(String vatNumber);
@Query("SELECT COUNT(c) FROM CompanyEntity c") @Query("SELECT COUNT(c) FROM CompanyEntity c where c.hub.id = :hubId")
long countTotalCompanies(); long countTotalCompaniesByHubId(@Param("hubId") Long hubId);
CompanyEntity findByVatNumberAndHubId(String vatNumber, Long hubId);
} }

View File

@@ -10,21 +10,9 @@ import java.util.Optional;
@Repository @Repository
public interface UserRepository extends JpaRepository<UserEntity, Long> { public interface UserRepository extends JpaRepository<UserEntity, Long> {
// Optional<UserEntity> findByEmailIgnoreCase(String email);
// boolean existsByEmailIgnoreCase(String email);
// UserEntity findByEmail(String email);
Optional<UserEntity> findByBeneficiaryCodiceFiscale(String codiceFiscale);
boolean existsByBeneficiaryCodiceFiscale(String codiceFiscale);
UserEntity findByBeneficiaryId(Long beneficiaryId); UserEntity findByBeneficiaryId(Long beneficiaryId);
Long countByStatusAndRoleEntityRoleType(String status, String roleName); Optional<UserEntity> findByEmailIgnoreCaseAndHubUniqueUuid(String email, String hubUuid);
Optional<UserEntity> findByEmailIgnoreCaseAndHubUniqueUuid(String email, String hubId);
boolean existsByEmailIgnoreCaseAndHubUniqueUuid(String email, String hubUuid); boolean existsByEmailIgnoreCaseAndHubUniqueUuid(String email, String hubUuid);
@@ -35,4 +23,6 @@ public interface UserRepository extends JpaRepository<UserEntity, Long> {
Long countByStatusAndRoleEntityRoleTypeAndHubId(String status, String roleName, Long hubId); Long countByStatusAndRoleEntityRoleTypeAndHubId(String status, String roleName, Long hubId);
Optional<UserEntity> findByBeneficiaryCodiceFiscaleAndHubId(String codiceFiscale, Long hubId); Optional<UserEntity> findByBeneficiaryCodiceFiscaleAndHubId(String codiceFiscale, Long hubId);
boolean existsByBeneficiaryCodiceFiscaleAndHubId(String codiceFiscale, Long hubId);
} }

View File

@@ -17,8 +17,6 @@ public interface UserWithCompanyRepository extends JpaRepository<UserWithCompany
@Query("SELECT u.companyId FROM UserWithCompanyEntity u WHERE u.userId = :userId AND u.isDeleted = false") @Query("SELECT u.companyId FROM UserWithCompanyEntity u WHERE u.userId = :userId AND u.isDeleted = false")
List<Long> findActiveCompanyIdsByUserId(@Param("userId") Long userId); List<Long> findActiveCompanyIdsByUserId(@Param("userId") Long userId);
Optional<UserWithCompanyEntity> findByUserIdAndCompanyIdAndIsDeletedFalse(Long userId, Long companyId); Optional<UserWithCompanyEntity> findByUserIdAndCompanyIdAndIsDeletedFalse(Long userId, Long companyId);
} }

View File

@@ -211,10 +211,11 @@ public class AuthenticationService {
throw new CustomValidationException(Status.VALIDATION_ERROR, throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.INVALID_TOKEN_MSG)); Translator.toLocale(GepafinConstant.INVALID_TOKEN_MSG));
} }
HubEntity hub = hubService.getHubByUuid(samlResponseLogEntity.getHubUuid());
Map<String, List<Object>> userAttributes = Utils Map<String, List<Object>> userAttributes = Utils
.convertStringIntoMap(samlResponseLogEntity.getAuthenticationObject()); .convertStringIntoMap(samlResponseLogEntity.getAuthenticationObject());
String cf = userAttributes.get("CodiceFiscale").get(0).toString(); String cf = userAttributes.get("CodiceFiscale").get(0).toString();
if (userRepository.existsByBeneficiaryCodiceFiscale(cf)) { if (userRepository.existsByBeneficiaryCodiceFiscaleAndHubId(cf, hub.getId())) {
throw new ResourceNotFoundException(Status.NOT_FOUND, throw new ResourceNotFoundException(Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.USER_ALREADY_EXIST_MSG)); Translator.toLocale(GepafinConstant.USER_ALREADY_EXIST_MSG));
} }

View File

@@ -9,7 +9,6 @@ import net.gepafin.tendermanagement.enums.BeneficiaryCallStatus;
import net.gepafin.tendermanagement.model.request.BeneficiaryPreferredCallReq; import net.gepafin.tendermanagement.model.request.BeneficiaryPreferredCallReq;
import net.gepafin.tendermanagement.model.response.BeneficiaryPreferredCallResponseBean; import net.gepafin.tendermanagement.model.response.BeneficiaryPreferredCallResponseBean;
import net.gepafin.tendermanagement.repositories.UserRepository;
import net.gepafin.tendermanagement.service.BeneficiaryPreferredCallService; import net.gepafin.tendermanagement.service.BeneficiaryPreferredCallService;
import net.gepafin.tendermanagement.service.UserService; import net.gepafin.tendermanagement.service.UserService;
import net.gepafin.tendermanagement.util.Validator; import net.gepafin.tendermanagement.util.Validator;
@@ -17,7 +16,6 @@ import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationExceptio
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;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.util.List; import java.util.List;
@@ -26,10 +24,10 @@ public class BeneficiaryPreferredCallServiceImpl implements BeneficiaryPreferred
@Autowired @Autowired
private BeneficiaryPreferredCallDao beneficiaryPreferredCallDao; private BeneficiaryPreferredCallDao beneficiaryPreferredCallDao;
@Autowired @Autowired
private Validator validator; private Validator validator;
@Autowired
private UserRepository userRepository;
@Autowired @Autowired
private UserService userService; private UserService userService;

View File

@@ -56,6 +56,7 @@ public class CompanyServiceImpl implements CompanyService {
@Transactional(readOnly = true) @Transactional(readOnly = true)
public CompanyResponse getCompany(HttpServletRequest request, Long companyId) { public CompanyResponse getCompany(HttpServletRequest request, Long companyId) {
UserEntity userEntity =validator.validateUser(request); UserEntity userEntity =validator.validateUser(request);
validator.validateUserWithCompany(request, companyId);
return companyDao.getCompany(userEntity, companyId); return companyDao.getCompany(userEntity, companyId);
} }
@@ -63,13 +64,14 @@ public class CompanyServiceImpl implements CompanyService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void deleteCompany(HttpServletRequest request, Long companyId) { public void deleteCompany(HttpServletRequest request, Long companyId) {
UserEntity userEntity =validator.validateUser(request); UserEntity userEntity =validator.validateUser(request);
validator.validateUserWithCompany(request, companyId);
companyDao.deleteCompany(userEntity, companyId); companyDao.deleteCompany(userEntity, companyId);
} }
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public List<CompanyResponse> getCompanyByUserId(HttpServletRequest request, Long userId) { public List<CompanyResponse> getCompanyByUserId(HttpServletRequest request, Long userId) {
validator.validateUser(request); validator.validateUserId(request, userId);
return companyDao.getCompanyByUserId(userId); return companyDao.getCompanyByUserId(userId);
} }

View File

@@ -4,7 +4,6 @@ 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.dao.CallDao;
import net.gepafin.tendermanagement.entities.CallEntity; import net.gepafin.tendermanagement.entities.CallEntity;
import net.gepafin.tendermanagement.entities.CompanyEntity; import net.gepafin.tendermanagement.entities.CompanyEntity;
import net.gepafin.tendermanagement.entities.UserEntity; import net.gepafin.tendermanagement.entities.UserEntity;
@@ -73,8 +72,14 @@ public class Validator {
} }
public CompanyEntity validateUserWithCompany(HttpServletRequest request, Long companyId) { public CompanyEntity validateUserWithCompany(HttpServletRequest request, Long companyId) {
UserEntity user = validateUser(request);
CompanyEntity companyEntity = companyService.validateCompany(companyId);
if (Boolean.FALSE.equals(user.getHub().getId().equals(companyEntity.getHub().getId()))) {
throw new ForbiddenAccessException(Status.FORBIDDEN,
Translator.toLocale(GepafinConstant.PERMISSION_DENIED));
}
if (checkIsSuperAdmin()) { if (checkIsSuperAdmin()) {
return companyService.validateCompany(companyId); return companyEntity;
} }
Map<String, Object> userInfo = tokenProvider.getUserInfoAndUserIdFromToken(request); Map<String, Object> userInfo = tokenProvider.getUserInfoAndUserIdFromToken(request);
companyService.validateUserWithCompny(getUserId(userInfo), companyId); companyService.validateUserWithCompny(getUserId(userInfo), companyId);
@@ -100,10 +105,15 @@ public class Validator {
public UserEntity validateUserId(HttpServletRequest request, Long userId) { public UserEntity validateUserId(HttpServletRequest request, Long userId) {
UserEntity user = validateUser(request); UserEntity user = validateUser(request);
UserEntity requestedUser = userService.validateUser(userId);
if(Boolean.FALSE.equals(requestedUser.getHub().getId().equals(user.getHub().getId()))) {
throw new ForbiddenAccessException(Status.FORBIDDEN, Translator.toLocale(GepafinConstant.PERMISSION_DENIED));
}
if(user.getRoleEntity().getRoleType().equals(RoleStatusEnum.ROLE_BENEFICIARY.getValue()) && Boolean.FALSE.equals(user.getId().equals(userId))) { if(user.getRoleEntity().getRoleType().equals(RoleStatusEnum.ROLE_BENEFICIARY.getValue()) && Boolean.FALSE.equals(user.getId().equals(userId))) {
throw new ForbiddenAccessException(Status.FORBIDDEN, Translator.toLocale(GepafinConstant.PERMISSION_DENIED)); throw new ForbiddenAccessException(Status.FORBIDDEN, Translator.toLocale(GepafinConstant.PERMISSION_DENIED));
} }
return userService.validateUser(userId); return requestedUser;
} }
private Long getUserIdFromToken(HttpServletRequest request) { private Long getUserIdFromToken(HttpServletRequest request) {

View File

@@ -1328,4 +1328,70 @@
referencedColumnNames="id"/> referencedColumnNames="id"/>
</changeSet> </changeSet>
<changeSet id="24-10-2024_1" author="Rajesh Khore">
<dropUniqueConstraint
constraintName="company_vat_number_key"
tableName="company"/>
<addColumn tableName="company">
<column name="hub_id" type="INTEGER" defaultValue="1">
<constraints nullable="false"/>
</column>
</addColumn>
<addUniqueConstraint
columnNames="VAT_NUMBER, hub_id"
tableName="company"
constraintName="uk_vat_hub" />
<addForeignKeyConstraint
baseTableName="company"
baseColumnNames="hub_id"
referencedTableName="hub"
referencedColumnNames="id"
constraintName="fk_company_hub" />
</changeSet>
<changeSet id="24-10-2024_2" author="Rajesh Khore">
<dropUniqueConstraint
constraintName="beneficiary_codice_fiscale_key"
tableName="beneficiary"/>
<addColumn tableName="beneficiary">
<column name="hub_id" type="INTEGER" defaultValue="1">
<constraints nullable="false"/>
</column>
</addColumn>
<addUniqueConstraint
columnNames="CODICE_FISCALE, hub_id"
tableName="beneficiary"
constraintName="uk_codice_hub" />
<addForeignKeyConstraint
baseTableName="beneficiary"
baseColumnNames="hub_id"
referencedTableName="hub"
referencedColumnNames="id"
constraintName="fk_beneficiary_hub" />
</changeSet>
<changeSet id="24-10-2024_3" author="Rajesh Khore">
<addColumn tableName="application">
<column name="hub_id" type="INTEGER" defaultValue="1">
<constraints nullable="false"/>
</column>
</addColumn>
<addForeignKeyConstraint
baseTableName="application"
baseColumnNames="hub_id"
referencedTableName="hub"
referencedColumnNames="id"
constraintName="fk_application_hub" />
</changeSet>
</databaseChangeLog> </databaseChangeLog>