Search in sources :

Example 11 with SysProvisioningAttribute

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

the class DefaultSysProvisioningArchiveService method toPredicates.

@Override
protected List<Predicate> toPredicates(Root<SysProvisioningArchive> 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(SysProvisioningArchive_.system).get(SysSystem_.id), systemId));
    }
    // From
    ZonedDateTime from = filter.getFrom();
    if (from != null) {
        predicates.add(builder.greaterThanOrEqualTo(root.get(SysProvisioningArchive_.created), from));
    }
    // Till
    ZonedDateTime till = filter.getTill();
    if (till != null) {
        predicates.add(builder.lessThanOrEqualTo(root.get(SysProvisioningArchive_.created), till));
    }
    // Operation type
    ProvisioningEventType operationType = filter.getOperationType();
    if (operationType != null) {
        predicates.add(builder.equal(root.get(SysProvisioningArchive_.operationType), operationType));
    }
    // Entity type
    SystemEntityType entityType = filter.getEntityType();
    if (entityType != null) {
        predicates.add(builder.equal(root.get(SysProvisioningArchive_.entityType), entityType));
    }
    // Entity identifier
    UUID entityIdentifier = filter.getEntityIdentifier();
    if (entityIdentifier != null) {
        predicates.add(builder.equal(root.get(SysProvisioningArchive_.entityIdentifier), entityIdentifier));
    }
    // System entity
    if (filter.getSystemEntity() != null) {
        throw new ResultCodeException(CoreResultCode.BAD_FILTER, "Filter by system entity identifier is not supported. Use system entity uid filter.");
    }
    // System entity UID
    String systemEntityUid = filter.getSystemEntityUid();
    if (StringUtils.isNotEmpty(systemEntityUid)) {
        predicates.add(builder.equal(root.get(SysProvisioningArchive_.systemEntityUid), systemEntityUid));
    }
    // Operation result and his state
    OperationState resultState = filter.getResultState();
    if (resultState != null) {
        predicates.add(builder.equal(root.get(SysProvisioningArchive_.result).get(OperationResultDto.PROPERTY_STATE), resultState));
    }
    // Batch id
    if (filter.getBatchId() != null) {
        throw new UnsupportedOperationException("Filter by batch identifier is not supported in archive.");
    }
    // Role-request ID
    UUID roleRequestId = filter.getRoleRequestId();
    if (roleRequestId != null) {
        predicates.add(builder.equal(root.get(SysProvisioningArchive_.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();
    if (emptyProvisioning != null) {
        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);
        if (emptyProvisioning) {
            provisioningPredicate = builder.and(// empty
            builder.not(provisioningPredicate), // delete operations are not considered as empty
            builder.notEqual(root.get(SysProvisioningArchive_.operationType), ProvisioningEventType.DELETE));
        } else {
            // delete operations are not considered as empty or filled => show all time
            provisioningPredicate = builder.or(provisioningPredicate, builder.equal(root.get(SysProvisioningArchive_.operationType), ProvisioningEventType.DELETE));
        }
        predicates.add(provisioningPredicate);
    }
    if (filter.getEmptyProvisioningType() != null) {
        throw new UnsupportedOperationException("Filter by empty provisioning type is not supported in archive. Use 'emptyProvisioning' parameter instead.");
    }
    // 
    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) Predicate(javax.persistence.criteria.Predicate) SysProvisioningAttribute(eu.bcvsolutions.idm.acc.entity.SysProvisioningAttribute) ZonedDateTime(java.time.ZonedDateTime) UUID(java.util.UUID) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState)

Example 12 with SysProvisioningAttribute

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

the class DefaultProvisioningExecutorIntegrationTest method testReferentiralIntegrity.

@Test
public void testReferentiralIntegrity() {
    SysSystemDto system = getHelper().createTestResourceSystem(true);
    SysProvisioningOperationDto operationOne = provisioningOperationService.save(createProvisioningOperation(system, getHelper().createName()));
    SysProvisioningOperationDto operationTwo = provisioningOperationService.save(createProvisioningOperation(system, getHelper().createName()));
    SysProvisioningAttribute attributeOne = new SysProvisioningAttribute(operationOne.getId(), getHelper().createName());
    attributeOne = provisioningAttributeRepository.save(attributeOne);
    SysProvisioningAttribute attributeTwo = new SysProvisioningAttribute(operationTwo.getId(), getHelper().createName());
    attributeTwo = provisioningAttributeRepository.save(attributeTwo);
    // 
    provisioningOperationService.delete(operationOne);
    // 
    Assert.assertFalse(provisioningAttributeRepository.existsById(attributeOne.getId()));
    Assert.assertTrue(provisioningAttributeRepository.existsById(attributeTwo.getId()));
}
Also used : SysProvisioningAttribute(eu.bcvsolutions.idm.acc.entity.SysProvisioningAttribute) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 13 with SysProvisioningAttribute

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

the class DefaultSysProvisioningArchiveServiceIntegrationTest method testReferentiralIntegrity.

@Test
@Transactional
public void testReferentiralIntegrity() {
    SysSystemDto system = createSystem();
    SysProvisioningArchiveDto archiveOne = createProvisioningArchive(SystemEntityType.CONTRACT, system);
    SysProvisioningArchiveDto archiveTwo = createProvisioningArchive(SystemEntityType.IDENTITY, system);
    SysProvisioningAttribute attributeOne = new SysProvisioningAttribute(archiveOne.getId(), getHelper().createName());
    attributeOne = provisioningAttributeRepository.save(attributeOne);
    SysProvisioningAttribute attributeTwo = new SysProvisioningAttribute(archiveTwo.getId(), getHelper().createName());
    attributeTwo = provisioningAttributeRepository.save(attributeTwo);
    // 
    service.delete(archiveOne);
    // 
    Assert.assertFalse(provisioningAttributeRepository.existsById(attributeOne.getId()));
    Assert.assertTrue(provisioningAttributeRepository.existsById(attributeTwo.getId()));
}
Also used : SysProvisioningAttribute(eu.bcvsolutions.idm.acc.entity.SysProvisioningAttribute) SysProvisioningArchiveDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with SysProvisioningAttribute

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

the class DefaultSysProvisioningArchiveServiceIntegrationTest method testOperationArchivateWithSingleRemovedAttributeWithNullValue.

@Test
public void testOperationArchivateWithSingleRemovedAttributeWithNullValue() {
    SysSystemDto system = getHelper().createTestResourceSystem(false);
    // 
    IcAttribute icAttributeOne = new IcAttributeImpl(getHelper().createName(), null);
    IcConnectorObject connectorObject = new IcConnectorObjectImpl(getHelper().createName(), new IcObjectClassImpl("__mock__"), ImmutableList.of(icAttributeOne));
    // 
    SysProvisioningOperationDto operation = prepareProvisioningOperation(system);
    operation.getProvisioningContext().setConnectorObject(connectorObject);
    // 
    SysProvisioningArchiveDto archive = service.archive(operation);
    // 
    List<SysProvisioningAttribute> attributes = provisioningAttributeRepository.findAllByProvisioningId(archive.getId());
    // 
    Assert.assertEquals(1, attributes.size());
    Assert.assertEquals(icAttributeOne.getName(), attributes.get(0).getName());
    Assert.assertTrue(attributes.get(0).isRemoved());
}
Also used : SysProvisioningAttribute(eu.bcvsolutions.idm.acc.entity.SysProvisioningAttribute) IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) IcAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeImpl) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) SysProvisioningArchiveDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 15 with SysProvisioningAttribute

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

the class DefaultSysProvisioningArchiveServiceIntegrationTest method testOperationArchivateWithMultiRemovedAttributeWithEmptyValue.

@Test
public void testOperationArchivateWithMultiRemovedAttributeWithEmptyValue() {
    SysSystemDto system = getHelper().createTestResourceSystem(false);
    // 
    IcAttribute icAttributeOne = new IcAttributeImpl(getHelper().createName(), Lists.newArrayList(""));
    IcConnectorObject connectorObject = new IcConnectorObjectImpl(getHelper().createName(), new IcObjectClassImpl("__mock__"), ImmutableList.of(icAttributeOne));
    // 
    SysProvisioningOperationDto operation = prepareProvisioningOperation(system);
    operation.getProvisioningContext().setConnectorObject(connectorObject);
    // 
    SysProvisioningArchiveDto archive = service.archive(operation);
    // 
    List<SysProvisioningAttribute> attributes = provisioningAttributeRepository.findAllByProvisioningId(archive.getId());
    // 
    Assert.assertEquals(1, attributes.size());
    Assert.assertEquals(icAttributeOne.getName(), attributes.get(0).getName());
    Assert.assertTrue(attributes.get(0).isRemoved());
}
Also used : SysProvisioningAttribute(eu.bcvsolutions.idm.acc.entity.SysProvisioningAttribute) IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) IcAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeImpl) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) SysProvisioningArchiveDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

SysProvisioningAttribute (eu.bcvsolutions.idm.acc.entity.SysProvisioningAttribute)16 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)10 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)10 Test (org.junit.Test)10 SysProvisioningOperationDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)9 SysProvisioningArchiveDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto)7 IcAttribute (eu.bcvsolutions.idm.ic.api.IcAttribute)7 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)6 IcAttributeImpl (eu.bcvsolutions.idm.ic.impl.IcAttributeImpl)6 IcConnectorObjectImpl (eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl)6 IcObjectClassImpl (eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl)6 ProvisioningEventType (eu.bcvsolutions.idm.acc.domain.ProvisioningEventType)2 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)2 SysProvisioningOperationFilter (eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter)2 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)2 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)2 ZonedDateTime (java.time.ZonedDateTime)2 UUID (java.util.UUID)2 Predicate (javax.persistence.criteria.Predicate)2 Transactional (org.springframework.transaction.annotation.Transactional)2