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;
}
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()));
}
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()));
}
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());
}
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());
}
Aggregations