Search in sources :

Example 1 with SysSystemAttributeMapping

use of eu.bcvsolutions.idm.acc.entity.SysSystemAttributeMapping in project CzechIdMng by bcvsolutions.

the class DefaultAccAccountService method toPredicates.

@Override
protected List<Predicate> toPredicates(Root<AccAccount> root, CriteriaQuery<?> query, CriteriaBuilder builder, AccAccountFilter filter) {
    List<Predicate> predicates = super.toPredicates(root, query, builder, filter);
    // full search
    if (StringUtils.isNotEmpty(filter.getText())) {
        predicates.add(// 
        builder.or(builder.like(builder.lower(root.get(AccAccount_.uid)), "%" + filter.getText().toLowerCase() + "%"), builder.like(builder.lower(root.get(AccAccount_.systemEntity).get(SysSystemEntity_.uid)), "%" + filter.getText().toLowerCase() + "%")));
    }
    if (filter.getSystemId() != null) {
        predicates.add(builder.equal(root.get(AccAccount_.system).get(SysSystem_.id), filter.getSystemId()));
    }
    if (filter.getSystemEntityId() != null) {
        predicates.add(builder.equal(root.get(AccAccount_.systemEntity).get(SysSystemEntity_.id), filter.getSystemEntityId()));
    }
    if (filter.getUid() != null) {
        predicates.add(builder.equal(root.get(AccAccount_.uid), filter.getUid()));
    }
    if (filter.getIdentityId() != null || filter.getOwnership() != null) {
        Subquery<AccIdentityAccount> identityAccountSubquery = query.subquery(AccIdentityAccount.class);
        Root<AccIdentityAccount> subRootIdentityAccount = identityAccountSubquery.from(AccIdentityAccount.class);
        identityAccountSubquery.select(subRootIdentityAccount);
        Predicate predicate = builder.and(builder.equal(subRootIdentityAccount.get(AccIdentityAccount_.account), root));
        Predicate identityPredicate = builder.equal(subRootIdentityAccount.get(AccIdentityAccount_.identity).get(IdmIdentity_.id), filter.getIdentityId());
        Predicate ownerPredicate = builder.equal(subRootIdentityAccount.get(AccIdentityAccount_.ownership), filter.getOwnership());
        if (filter.getIdentityId() != null && filter.getOwnership() == null) {
            predicate = builder.and(predicate, identityPredicate);
        } else if (filter.getOwnership() != null && filter.getIdentityId() == null) {
            predicate = builder.and(predicate, ownerPredicate);
        } else {
            predicate = builder.and(predicate, identityPredicate, ownerPredicate);
        }
        identityAccountSubquery.where(predicate);
        predicates.add(builder.exists(identityAccountSubquery));
    }
    if (filter.getAccountType() != null) {
        predicates.add(builder.equal(root.get(AccAccount_.accountType), filter.getAccountType()));
    }
    if (filter.getSupportChangePassword() != null && filter.getSupportChangePassword()) {
        Subquery<SysSystemAttributeMapping> systemAttributeMappingSubquery = query.subquery(SysSystemAttributeMapping.class);
        Root<SysSystemAttributeMapping> subRootSystemAttributeMapping = systemAttributeMappingSubquery.from(SysSystemAttributeMapping.class);
        systemAttributeMappingSubquery.select(subRootSystemAttributeMapping);
        Predicate predicate = builder.and(builder.equal(// 
        subRootSystemAttributeMapping.get(// 
        SysSystemAttributeMapping_.schemaAttribute).get(// 
        SysSchemaAttribute_.objectClass).get(// 
        SysSchemaObjectClass_.system), root.get(AccAccount_.system)), builder.equal(// 
        subRootSystemAttributeMapping.get(// 
        SysSystemAttributeMapping_.systemMapping).get(SysSystemMapping_.operationType), SystemOperationType.PROVISIONING), builder.equal(// 
        subRootSystemAttributeMapping.get(// 
        SysSystemAttributeMapping_.schemaAttribute).get(SysSchemaAttribute_.name), ProvisioningService.PASSWORD_SCHEMA_PROPERTY_NAME));
        systemAttributeMappingSubquery.where(predicate);
        predicates.add(builder.exists(systemAttributeMappingSubquery));
    }
    if (filter.getEntityType() != null) {
        predicates.add(builder.equal(root.get(AccAccount_.entityType), filter.getEntityType()));
    }
    // 
    return predicates;
}
Also used : AccIdentityAccount(eu.bcvsolutions.idm.acc.entity.AccIdentityAccount) SysSystemAttributeMapping(eu.bcvsolutions.idm.acc.entity.SysSystemAttributeMapping) Predicate(javax.persistence.criteria.Predicate)

Example 2 with SysSystemAttributeMapping

use of eu.bcvsolutions.idm.acc.entity.SysSystemAttributeMapping in project CzechIdMng by bcvsolutions.

the class DefaultSysSystemAttributeMappingService method delete.

@Override
@Transactional
public void delete(SysSystemAttributeMappingDto dto, BasePermission... permission) {
    Assert.notNull(dto);
    SysSystemAttributeMapping entity = this.getEntity(dto.getId());
    Assert.notNull(entity);
    // 
    if (syncConfigRepository.countByCorrelationAttribute_Id(dto.getId()) > 0) {
        throw new ResultCodeException(AccResultCode.ATTRIBUTE_MAPPING_DELETE_FAILED_USED_IN_SYNC, ImmutableMap.of("attribute", dto.getName()));
    }
    if (syncConfigRepository.countByFilterAttribute(entity) > 0) {
        throw new ResultCodeException(AccResultCode.ATTRIBUTE_MAPPING_DELETE_FAILED_USED_IN_SYNC, ImmutableMap.of("attribute", dto.getName()));
    }
    if (syncConfigRepository.countByTokenAttribute(entity) > 0) {
        throw new ResultCodeException(AccResultCode.ATTRIBUTE_MAPPING_DELETE_FAILED_USED_IN_SYNC, ImmutableMap.of("attribute", dto.getName()));
    }
    // delete attributes
    roleSystemAttributeRepository.deleteBySystemAttributeMapping(entity);
    // 
    super.delete(dto, permission);
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) SysSystemAttributeMapping(eu.bcvsolutions.idm.acc.entity.SysSystemAttributeMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

SysSystemAttributeMapping (eu.bcvsolutions.idm.acc.entity.SysSystemAttributeMapping)2 AccIdentityAccount (eu.bcvsolutions.idm.acc.entity.AccIdentityAccount)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 Predicate (javax.persistence.criteria.Predicate)1 Transactional (org.springframework.transaction.annotation.Transactional)1