Updated code
This commit is contained in:
@@ -222,21 +222,23 @@ public class UserDao {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void validateDuplicateEmail(String email, String hubUuid, String roleType) {
|
||||
Boolean existsForNonBeneficiaries = userRepository.existsByEmailIgnoreCaseForNonBeneficiaries(
|
||||
email, hubUuid, RoleStatusEnum.ROLE_BENEFICIARY.getValue());
|
||||
String beneficiaryRoleType = RoleStatusEnum.ROLE_BENEFICIARY.getValue();
|
||||
|
||||
Boolean beneficiaryExistsInHub = userRepository.existsByEmailIgnoreCaseForBeneficiaries(
|
||||
email, hubUuid, RoleStatusEnum.ROLE_BENEFICIARY.getValue());
|
||||
if (beneficiaryRoleType.equals(roleType)) {
|
||||
Boolean beneficiaryExistsInHub = userRepository.existsByEmailIgnoreCaseForBeneficiaries(
|
||||
email, hubUuid, beneficiaryRoleType);
|
||||
|
||||
if (Boolean.TRUE.equals(RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(roleType))) {
|
||||
if (beneficiaryExistsInHub) {
|
||||
if (Boolean.TRUE.equals(beneficiaryExistsInHub)) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.EMAIL_ALREADY_EXISTS));
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (existsForNonBeneficiaries) {
|
||||
} else {
|
||||
Boolean existsForNonBeneficiaries = userRepository.existsByEmailIgnoreCaseForNonBeneficiaries(
|
||||
email, hubUuid, beneficiaryRoleType);
|
||||
|
||||
if (Boolean.TRUE.equals(existsForNonBeneficiaries)) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.EMAIL_ALREADY_EXISTS));
|
||||
}
|
||||
|
||||
@@ -33,24 +33,28 @@ public interface UserRepository extends JpaRepository<UserEntity, Long> {
|
||||
|
||||
Optional<UserEntity> findByBeneficiaryCodiceFiscaleAndHubId(String codiceFiscale, Long hubId);
|
||||
|
||||
Boolean existsByBeneficiaryCodiceFiscaleAndHubId(String codiceFiscale, Long hubId);
|
||||
// Boolean existsByBeneficiaryCodiceFiscaleAndHubId(String codiceFiscale, Long hubId);
|
||||
|
||||
@Query("SELECT COUNT(u) > 0 " +
|
||||
"FROM UserEntity u " +
|
||||
"WHERE u.email = :email " +
|
||||
"AND u.hub.uniqueUuid = :hubUuid " +
|
||||
"AND u.roleEntity.roleType <> :beneficiaryRoleType")
|
||||
Boolean existsByEmailIgnoreCaseForNonBeneficiaries(@Param("email") String email,
|
||||
@Param("hubUuid") String hubUuid,
|
||||
@Param("beneficiaryRoleType") String beneficiaryRoleType);
|
||||
@Query("SELECT COUNT(u) > 0 " +
|
||||
"FROM UserEntity u " +
|
||||
"WHERE LOWER(u.email) = LOWER(:email) " +
|
||||
"AND u.hub.uniqueUuid = :hubUuid " +
|
||||
"AND u.roleEntity.roleType <> :beneficiaryRoleType")
|
||||
Boolean existsByEmailIgnoreCaseForNonBeneficiaries(@Param("email") String email,
|
||||
@Param("hubUuid") String hubUuid,
|
||||
@Param("beneficiaryRoleType") String beneficiaryRoleType);
|
||||
|
||||
@Query("SELECT CASE WHEN COUNT(u) > 0 THEN true ELSE false END " +
|
||||
"FROM UserEntity u " +
|
||||
"WHERE LOWER(u.email) = LOWER(:email) AND u.hub.uniqueUuid = :hubUuid " +
|
||||
"AND u.roleEntity.roleType = :beneficiaryRoleType")
|
||||
Boolean existsByEmailIgnoreCaseForBeneficiaries(String email, String hubUuid, String beneficiaryRoleType);
|
||||
@Query("SELECT COUNT(u) > 0 " +
|
||||
"FROM UserEntity u " +
|
||||
"WHERE LOWER(u.email) = LOWER(:email) " +
|
||||
"AND u.hub.uniqueUuid = :hubUuid " +
|
||||
"AND u.roleEntity.roleType = :beneficiaryRoleType")
|
||||
Boolean existsByEmailIgnoreCaseForBeneficiaries(@Param("email") String email,
|
||||
@Param("hubUuid") String hubUuid,
|
||||
@Param("beneficiaryRoleType") String beneficiaryRoleType);
|
||||
|
||||
// existsByBebooleanneficiaryCodiceFiscaleAndHubId(String codiceFiscale, Long hubId);
|
||||
|
||||
boolean existsByBeneficiaryCodiceFiscaleAndHubId(String codiceFiscale, Long hubId);
|
||||
|
||||
List<UserEntity> findByRoleEntity_RoleTypeAndHubId(String roleType, Long hubId);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user