Search in sources :

Example 1 with EmptyProvisioningType

use of eu.bcvsolutions.idm.acc.domain.EmptyProvisioningType in project CzechIdMng by bcvsolutions.

the class DefaultSysProvisioningOperationService method toPredicates.

@Override
protected List<Predicate> toPredicates(Root<SysProvisioningOperation> root, CriteriaQuery<?> query, CriteriaBuilder builder, SysProvisioningOperationFilter filter) {
    List<Predicate> predicates = super.toPredicates(root, query, builder, filter);
    // quick - "fulltext"
    if (StringUtils.isNotEmpty(filter.getText())) {
        throw new ResultCodeException(CoreResultCode.BAD_FILTER, "Filter by text is not supported.");
    }
    // System Id
    UUID systemId = filter.getSystemId();
    if (systemId != null) {
        predicates.add(builder.equal(root.get(SysProvisioningOperation_.system).get(SysSystem_.id), systemId));
    }
    // From
    ZonedDateTime from = filter.getFrom();
    if (from != null) {
        predicates.add(builder.greaterThanOrEqualTo(root.get(SysProvisioningOperation_.created), from));
    }
    // Till
    ZonedDateTime till = filter.getTill();
    if (till != null) {
        predicates.add(builder.lessThanOrEqualTo(root.get(SysProvisioningOperation_.created), till));
    }
    // Operation type
    ProvisioningEventType operationType = filter.getOperationType();
    if (operationType != null) {
        predicates.add(builder.equal(root.get(SysProvisioningOperation_.operationType), operationType));
    }
    // Entity type
    SystemEntityType entityType = filter.getEntityType();
    if (entityType != null) {
        predicates.add(builder.equal(root.get(SysProvisioningOperation_.entityType), entityType));
    }
    // Entity identifier
    UUID entityIdentifier = filter.getEntityIdentifier();
    if (entityIdentifier != null) {
        predicates.add(builder.equal(root.get(SysProvisioningOperation_.entityIdentifier), entityIdentifier));
    }
    // System entity
    UUID systemEntity = filter.getSystemEntity();
    if (systemEntity != null) {
        predicates.add(builder.equal(root.get(SysProvisioningOperation_.systemEntity).get(SysSystemEntity_.id), systemEntity));
    }
    // System entity UID
    String systemEntityUid = filter.getSystemEntityUid();
    if (StringUtils.isNotEmpty(systemEntityUid)) {
        predicates.add(builder.equal(root.get(SysProvisioningOperation_.systemEntity).get(SysSystemEntity_.uid), systemEntityUid));
    }
    // Operation result and his state
    OperationState resultState = filter.getResultState();
    if (resultState != null) {
        predicates.add(builder.equal(root.get(SysProvisioningOperation_.result).get(OperationResultDto.PROPERTY_STATE), resultState));
    }
    // Is not in this operation state
    OperationState notInState = filter.getNotInState();
    if (notInState != null) {
        predicates.add(builder.notEqual(root.get(SysProvisioningOperation_.result).get(OperationResultDto.PROPERTY_STATE), notInState));
    }
    // Batch ID
    UUID batchId = filter.getBatchId();
    if (batchId != null) {
        predicates.add(builder.equal(root.get(SysProvisioningOperation_.batch).get(SysProvisioningBatch_.id), batchId));
    }
    // Role-request ID
    UUID roleRequestId = filter.getRoleRequestId();
    if (roleRequestId != null) {
        predicates.add(builder.equal(root.get(SysProvisioningOperation_.roleRequestId), roleRequestId));
    }
    // updated attributes
    List<String> attributeUpdated = filter.getAttributeUpdated();
    if (!CollectionUtils.isEmpty(attributeUpdated)) {
        Subquery<SysProvisioningAttribute> subquery = query.subquery(SysProvisioningAttribute.class);
        Root<SysProvisioningAttribute> subRoot = subquery.from(SysProvisioningAttribute.class);
        subquery.select(subRoot);
        subquery.where(builder.and(// correlation attr
        builder.equal(subRoot.get(SysProvisioningAttribute_.provisioningId), root.get(SysProvisioningArchive_.id)), subRoot.get(SysProvisioningAttribute_.name).in(attributeUpdated), builder.isFalse(subRoot.get(SysProvisioningAttribute_.removed))));
        predicates.add(builder.exists(subquery));
    }
    // removed attributes
    List<String> attributeRemoved = filter.getAttributeRemoved();
    if (!CollectionUtils.isEmpty(attributeRemoved)) {
        Subquery<SysProvisioningAttribute> subquery = query.subquery(SysProvisioningAttribute.class);
        Root<SysProvisioningAttribute> subRoot = subquery.from(SysProvisioningAttribute.class);
        subquery.select(subRoot);
        subquery.where(builder.and(// correlation attr
        builder.equal(subRoot.get(SysProvisioningAttribute_.provisioningId), root.get(SysProvisioningArchive_.id)), subRoot.get(SysProvisioningAttribute_.name).in(attributeRemoved), builder.isTrue(subRoot.get(SysProvisioningAttribute_.removed))));
        predicates.add(builder.exists(subquery));
    }
    // empty provisioning
    Boolean emptyProvisioning = filter.getEmptyProvisioning();
    EmptyProvisioningType emptyProvisioningType = filter.getEmptyProvisioningType();
    if (emptyProvisioning != null || emptyProvisioningType != null) {
        if (BooleanUtils.isTrue(emptyProvisioning) && emptyProvisioningType != null && emptyProvisioningType != EmptyProvisioningType.EMPTY) {
            // empty + not empty => nothing
            predicates.add(builder.disjunction());
        } else if (BooleanUtils.isFalse(emptyProvisioning) && emptyProvisioningType != null && emptyProvisioningType != EmptyProvisioningType.NON_EMPTY) {
            // not empty + filled somehow => nothing
            predicates.add(builder.disjunction());
        } else if (emptyProvisioningType == null) {
            // fill by boolean value
            emptyProvisioningType = emptyProvisioning ? EmptyProvisioningType.EMPTY : EmptyProvisioningType.NON_EMPTY;
        }
        Subquery<SysProvisioningAttribute> subquery = query.subquery(SysProvisioningAttribute.class);
        Root<SysProvisioningAttribute> subRoot = subquery.from(SysProvisioningAttribute.class);
        subquery.select(subRoot);
        subquery.where(// correlation attr)
        builder.and(builder.equal(subRoot.get(SysProvisioningAttribute_.provisioningId), root.get(SysProvisioningArchive_.id))));
        // 
        // has attributes
        Predicate provisioningPredicate = builder.exists(subquery);
        Predicate notProcessedPredicate = builder.or(// Not executed operations (already in queue, created) are not wanted - attributes are not computed in this phase.
        builder.equal(root.get(SysProvisioningOperation_.result).get(OperationResultDto.PROPERTY_STATE), OperationState.CREATED), builder.equal(root.get(SysProvisioningOperation_.result).get(OperationResultDto.PROPERTY_STATE), OperationState.RUNNING), builder.equal(root.get(SysProvisioningOperation_.result).get(OperationResultDto.PROPERTY_STATE), OperationState.BLOCKED), builder.and(builder.equal(root.get(SysProvisioningOperation_.result).get(OperationResultDto.PROPERTY_STATE), OperationState.NOT_EXECUTED), // only readOnly has attributes evaluated
        builder.or(builder.isNull(root.get(SysProvisioningOperation_.result).get(OperationResultDto.PROPERTY_CODE)), builder.notEqual(root.get(SysProvisioningOperation_.result).get(OperationResultDto.PROPERTY_CODE), AccResultCode.PROVISIONING_SYSTEM_READONLY.name()))));
        switch(emptyProvisioningType) {
            case EMPTY:
                {
                    provisioningPredicate = builder.and(// empty
                    builder.not(provisioningPredicate), // delete operations are not considered as empty
                    builder.notEqual(root.get(SysProvisioningOperation_.operationType), ProvisioningEventType.DELETE), builder.not(notProcessedPredicate));
                    break;
                }
            case NON_EMPTY:
                {
                    // delete operations are not considered as empty or filled => show all time
                    provisioningPredicate = builder.and(builder.or(provisioningPredicate, builder.equal(root.get(SysProvisioningOperation_.operationType), ProvisioningEventType.DELETE)), builder.not(notProcessedPredicate));
                    break;
                }
            case NOT_PROCESSED:
                {
                    provisioningPredicate = notProcessedPredicate;
                    break;
                }
            default:
                {
                    throw new UnsupportedOperationException(String.format("Empty profisioning type [%s] is not supported by filter predicates.", emptyProvisioningType));
                }
        }
        predicates.add(provisioningPredicate);
    }
    return predicates;
}
Also used : ProvisioningEventType(eu.bcvsolutions.idm.acc.domain.ProvisioningEventType) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) ConfidentialString(eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Predicate(javax.persistence.criteria.Predicate) SysProvisioningAttribute(eu.bcvsolutions.idm.acc.entity.SysProvisioningAttribute) ZonedDateTime(java.time.ZonedDateTime) UUID(java.util.UUID) EmptyProvisioningType(eu.bcvsolutions.idm.acc.domain.EmptyProvisioningType) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState)

Aggregations

EmptyProvisioningType (eu.bcvsolutions.idm.acc.domain.EmptyProvisioningType)1 ProvisioningEventType (eu.bcvsolutions.idm.acc.domain.ProvisioningEventType)1 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)1 SysProvisioningAttribute (eu.bcvsolutions.idm.acc.entity.SysProvisioningAttribute)1 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 ConfidentialString (eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString)1 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)1 ZonedDateTime (java.time.ZonedDateTime)1 UUID (java.util.UUID)1 Predicate (javax.persistence.criteria.Predicate)1