use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testGetProjectionWithoutContractAuthority.
@Test
@Transactional
public void testGetProjectionWithoutContractAuthority() {
String defaultRoleCode = roleConfiguration.getDefaultRoleCode();
// create identity with update identity permission only
// with password
IdmIdentityDto identityLogged = getHelper().createIdentity();
IdmRoleDto role = getHelper().createRole();
// read all
getHelper().createBasePolicy(role.getId(), CoreGroupPermission.IDENTITY, IdmIdentity.class, IdmBasePermission.READ, IdmBasePermission.UPDATE);
getHelper().createIdentityRole(identityLogged, role);
//
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
//
// set contract
IdmIdentityContractDto primeContract = new IdmIdentityContractDto();
primeContract.setMain(true);
primeContract.setWorkPosition(getHelper().createTreeNode().getId());
primeContract.setPosition(getHelper().createName());
primeContract.setValidFrom(LocalDate.now().minus(1l, ChronoUnit.DAYS));
primeContract.setValidFrom(LocalDate.now().plus(1l, ChronoUnit.DAYS));
projection.setContract(primeContract);
//
// set other contract
IdmIdentityContractDto otherContractOne = new IdmIdentityContractDto();
otherContractOne.setWorkPosition(getHelper().createTreeNode().getId());
otherContractOne.setPosition(getHelper().createName());
// preset uuid
IdmIdentityContractDto otherContractTwo = new IdmIdentityContractDto(UUID.randomUUID());
otherContractTwo.setWorkPosition(getHelper().createTreeNode().getId());
otherContractTwo.setPosition(getHelper().createName());
projection.setOtherContracts(Lists.newArrayList(otherContractOne, otherContractTwo));
//
// set other contract position
IdmContractPositionDto positionOne = new IdmContractPositionDto();
positionOne.setWorkPosition(getHelper().createTreeNode().getId());
positionOne.setPosition(getHelper().createName());
IdmContractPositionDto positionTwo = new IdmContractPositionDto();
positionTwo.setWorkPosition(getHelper().createTreeNode().getId());
positionTwo.setPosition(getHelper().createName());
positionTwo.setIdentityContract(otherContractTwo.getId());
projection.setOtherPositions(Lists.newArrayList(positionOne, positionTwo));
//
projection = manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection)).getContent();
// assigned roles
getHelper().createIdentityRole(projection.getIdentity(), role);
try {
// empty property => disable default role
getHelper().setConfigurationValue(RoleConfiguration.PROPERTY_DEFAULT_ROLE, "");
//
getHelper().login(identityLogged);
IdmIdentityProjectionDto createdProjection = manager.get(projection, IdmBasePermission.READ);
//
Assert.assertNotNull(createdProjection);
Assert.assertNull(createdProjection.getContract());
Assert.assertTrue(createdProjection.getOtherContracts().isEmpty());
Assert.assertTrue(createdProjection.getOtherPositions().isEmpty());
Assert.assertTrue(createdProjection.getIdentityRoles().isEmpty());
//
createdProjection = manager.get(projection);
//
Assert.assertNotNull(createdProjection);
Assert.assertNotNull(createdProjection.getContract());
Assert.assertFalse(createdProjection.getOtherContracts().isEmpty());
Assert.assertFalse(createdProjection.getOtherPositions().isEmpty());
Assert.assertFalse(createdProjection.getIdentityRoles().isEmpty());
} finally {
logout();
getHelper().setConfigurationValue(RoleConfiguration.PROPERTY_DEFAULT_ROLE, defaultRoleCode);
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testDeleteOtherContractAndPosition.
@Test
@Transactional
public void testDeleteOtherContractAndPosition() {
//
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
//
// set contract
IdmIdentityContractDto primeContract = new IdmIdentityContractDto();
primeContract.setMain(true);
primeContract.setWorkPosition(getHelper().createTreeNode().getId());
primeContract.setPosition(getHelper().createName());
primeContract.setValidFrom(LocalDate.now().minus(1l, ChronoUnit.DAYS));
primeContract.setValidFrom(LocalDate.now().plus(1l, ChronoUnit.DAYS));
projection.setContract(primeContract);
//
// set other contract
IdmIdentityContractDto otherContractOne = new IdmIdentityContractDto();
otherContractOne.setWorkPosition(getHelper().createTreeNode().getId());
otherContractOne.setPosition(getHelper().createName());
// preset uuid
IdmIdentityContractDto otherContractTwo = new IdmIdentityContractDto(UUID.randomUUID());
otherContractTwo.setWorkPosition(getHelper().createTreeNode().getId());
otherContractTwo.setPosition(getHelper().createName());
projection.setOtherContracts(Lists.newArrayList(otherContractOne, otherContractTwo));
//
// set other contract position
IdmContractPositionDto positionOne = new IdmContractPositionDto();
positionOne.setWorkPosition(getHelper().createTreeNode().getId());
positionOne.setPosition(getHelper().createName());
IdmContractPositionDto positionTwo = new IdmContractPositionDto();
positionTwo.setWorkPosition(getHelper().createTreeNode().getId());
positionTwo.setPosition(getHelper().createName());
positionTwo.setIdentityContract(otherContractTwo.getId());
projection.setOtherPositions(Lists.newArrayList(positionOne, positionTwo));
IdmIdentityProjectionDto createdProjection = manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection)).getContent();
// other contract
Assert.assertEquals(2, createdProjection.getOtherContracts().size());
Assert.assertTrue(createdProjection.getOtherContracts().stream().anyMatch(c -> {
return c.getWorkPosition().equals(otherContractOne.getWorkPosition()) && c.getPosition().equals(otherContractOne.getPosition());
}));
Assert.assertTrue(createdProjection.getOtherContracts().stream().anyMatch(c -> {
return c.getWorkPosition().equals(otherContractTwo.getWorkPosition()) && c.getPosition().equals(otherContractTwo.getPosition()) && // preserve id
c.getId().equals(otherContractTwo.getId());
}));
// other position
Assert.assertEquals(2, createdProjection.getOtherPositions().size());
Assert.assertTrue(createdProjection.getOtherPositions().stream().anyMatch(p -> {
return p.getWorkPosition().equals(positionOne.getWorkPosition()) && p.getPosition().equals(positionOne.getPosition()) && p.getIdentityContract().equals(createdProjection.getContract().getId());
}));
Assert.assertTrue(createdProjection.getOtherPositions().stream().anyMatch(p -> {
return p.getWorkPosition().equals(positionTwo.getWorkPosition()) && p.getPosition().equals(positionTwo.getPosition()) && p.getIdentityContract().equals(positionTwo.getIdentityContract());
}));
//
// remove contract and position
createdProjection.getOtherContracts().removeIf(c -> {
return c.getWorkPosition().equals(otherContractOne.getWorkPosition()) && c.getPosition().equals(otherContractOne.getPosition());
});
createdProjection.getOtherPositions().removeIf(p -> {
return p.getWorkPosition().equals(positionOne.getWorkPosition()) && p.getPosition().equals(positionOne.getPosition()) && p.getIdentityContract().equals(createdProjection.getContract().getId());
});
IdmIdentityProjectionDto updatedProjection = manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.UPDATE, createdProjection)).getContent();
// other contract
Assert.assertEquals(1, updatedProjection.getOtherContracts().size());
Assert.assertTrue(updatedProjection.getOtherContracts().stream().anyMatch(c -> {
return c.getWorkPosition().equals(otherContractTwo.getWorkPosition()) && c.getPosition().equals(otherContractTwo.getPosition()) && // preserve id
c.getId().equals(otherContractTwo.getId());
}));
// other position
Assert.assertEquals(1, updatedProjection.getOtherPositions().size());
Assert.assertTrue(updatedProjection.getOtherPositions().stream().anyMatch(p -> {
return p.getWorkPosition().equals(positionTwo.getWorkPosition()) && p.getPosition().equals(positionTwo.getPosition()) && p.getIdentityContract().equals(positionTwo.getIdentityContract());
}));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class TreeNodeDeleteBulkActionIntegrationTest method testForceDelete.
@Test
public void testForceDelete() {
logout();
loginAsAdmin();
// create sub tree nodes, automatic roles, contract, contract positions
IdmTreeNodeDto treeNode = getHelper().createTreeNode();
IdmTreeNodeDto subTreeNode = getHelper().createTreeNode((String) null, treeNode);
IdmTreeNodeDto subSubTreeNode = getHelper().createTreeNode((String) null, subTreeNode);
IdmTreeNodeDto otherTreeNode = getHelper().createTreeNode();
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = getHelper().createContract(identity, subTreeNode);
IdmContractPositionDto contractPosition = getHelper().createContractPosition(contract, subSubTreeNode);
IdmRoleDto role = getHelper().createRole();
IdmIdentityRoleDto assignedRoleOne = getHelper().createIdentityRole(contract, role);
IdmIdentityRoleDto assignedRoleTwo = getHelper().createIdentityRole(contractPosition, role);
IdmIdentityRoleDto assignedRoleOther = getHelper().createIdentityRole(getHelper().getPrimeContract(identity), role);
IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(role, treeNode, RecursionType.DOWN, false);
//
// 3 manual, 2 automatic
Assert.assertEquals(5, identityRoleService.findAllByIdentity(identity.getId()).size());
//
// remove tree node
Map<String, Object> properties = new HashMap<>();
properties.put(EntityEventProcessor.PROPERTY_FORCE_DELETE, Boolean.TRUE);
// delete by bulk action
IdmBulkActionDto bulkAction = this.findBulkAction(IdmTreeNode.class, TreeNodeDeleteBulkAction.NAME);
bulkAction.setIdentifiers(Sets.newHashSet(treeNode.getId()));
bulkAction.setProperties(properties);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, 0l, 0l);
//
Assert.assertNull(treeNodeService.get(treeNode));
Assert.assertNull(treeNodeService.get(subTreeNode));
Assert.assertNull(treeNodeService.get(subSubTreeNode));
Assert.assertNull(treeNodeService.get(subSubTreeNode));
Assert.assertNotNull(identityRoleService.get(assignedRoleOne));
Assert.assertNotNull(identityRoleService.get(assignedRoleTwo));
Assert.assertNull(identityContractService.get(contract).getWorkPosition());
Assert.assertNull(contractPositionService.get(contractPosition).getWorkPosition());
Assert.assertNull(roleTreeNodeService.get(automaticRole));
//
Assert.assertNotNull(treeNodeService.get(otherTreeNode));
Assert.assertNotNull(getHelper().getPrimeContract(identity));
Assert.assertNotNull(identityRoleService.get(assignedRoleOther));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class ContractSynchronizationExecutor method save.
/**
* Save entity
*
* @param entity
* @param skipProvisioning
* @return
*/
@Override
protected IdmIdentityContractDto save(IdmIdentityContractDto entity, boolean skipProvisioning, SynchronizationContext context) {
if (entity.getIdentity() == null) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_IDM_FIELD_CANNOT_BE_NULL, ImmutableMap.of("property", CONTRACT_IDENTITY_FIELD));
}
EntityEvent<IdmIdentityContractDto> event = new IdentityContractEvent(contractService.isNew(entity) ? IdentityContractEventType.CREATE : IdentityContractEventType.UPDATE, entity, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning));
// We do not want execute HR processes for every contract. We need start
// them for every identity only once.
// For this we skip them now. HR processes must be start after whole
// sync finished (by using dependent scheduled task)!
event.getProperties().put(IdmIdentityContractService.SKIP_HR_PROCESSES, Boolean.TRUE);
//
// We don't want recalculate automatic role by attribute recalculation for every
// contract.
// Recalculation will be started only once.
event.getProperties().put(AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE);
EventContext<IdmIdentityContractDto> publishContext = contractService.publish(event);
IdmIdentityContractDto contract = publishContext.getContent();
// We need to flag recalculation for contract immediately to prevent synchronization ends before flag is created by NOTIFY event asynchronously.
Map<String, Serializable> properties = new HashMap<>();
EventResult<IdmIdentityContractDto> lastResult = publishContext.getLastResult();
if (lastResult != null) {
// original contract as property
properties.put(EntityEvent.EVENT_PROPERTY_ORIGINAL_SOURCE, lastResult.getEvent().getOriginalSource());
}
if (contract.isValidNowOrInFuture()) {
entityStateManager.createState(contract, OperationState.BLOCKED, CoreResultCode.AUTOMATIC_ROLE_SKIPPED, properties);
} else {
entityStateManager.createState(contract, OperationState.BLOCKED, CoreResultCode.AUTOMATIC_ROLE_SKIPPED_INVALID_CONTRACT, properties);
}
//
if (entity.getEmbedded().containsKey(SYNC_CONTRACT_FIELD)) {
SyncIdentityContractDto syncContract = (SyncIdentityContractDto) entity.getEmbedded().get(SYNC_CONTRACT_FIELD);
// Positions
IdmContractPositionFilter positionFilter = new IdmContractPositionFilter();
positionFilter.setIdentityContractId(contract.getId());
List<IdmContractPositionDto> currentPositions = contractPositionService.find(positionFilter, null).getContent();
// Search positions to delete
List<IdmContractPositionDto> positionsToDelete = currentPositions.stream().filter(position -> {
return position.getWorkPosition() != null && !syncContract.getPositions().contains(new IdmTreeNodeDto(position.getWorkPosition()));
}).collect(Collectors.toList());
// Search positions to add
List<IdmTreeNodeDto> positionsToAdd = syncContract.getPositions().stream().filter(position -> {
return !currentPositions.stream().filter(currentPosition -> {
return position.getId().equals(currentPosition.getWorkPosition());
}).findFirst().isPresent();
}).collect(Collectors.toList());
// Create new positions
positionsToAdd.forEach(position -> {
IdmContractPositionDto contractPosition = new IdmContractPositionDto();
contractPosition.setIdentityContract(contract.getId());
contractPosition.setWorkPosition(position.getId());
//
EntityEvent<IdmContractPositionDto> positionEvent = new ContractPositionEvent(ContractPositionEventType.CREATE, contractPosition, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning, AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE));
contractPosition = contractPositionService.publish(positionEvent).getContent();
// We need to flag recalculation for contract immediately to prevent synchronization ends before flag is created by NOTIFY event asynchronously.
if (contract.isValidNowOrInFuture()) {
entityStateManager.createState(contractPosition, OperationState.BLOCKED, CoreResultCode.AUTOMATIC_ROLE_SKIPPED, null);
}
});
// Delete positions - should be after new positions are created (prevent to drop and create => delete is sync).
positionsToDelete.forEach(position -> {
EntityEvent<IdmContractPositionDto> positionEvent = new ContractPositionEvent(ContractPositionEventType.DELETE, position, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning, AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE));
contractPositionService.publish(positionEvent);
});
// Guarantees
IdmContractGuaranteeFilter guaranteeFilter = new IdmContractGuaranteeFilter();
guaranteeFilter.setIdentityContractId(contract.getId());
List<IdmContractGuaranteeDto> currentGuarantees = guaranteeService.find(guaranteeFilter, null).getContent();
// Search guarantees to delete
List<IdmContractGuaranteeDto> guaranteesToDelete = currentGuarantees.stream().filter(sysImplementer -> {
return sysImplementer.getGuarantee() != null && !syncContract.getGuarantees().contains(new IdmIdentityDto(sysImplementer.getGuarantee()));
}).collect(Collectors.toList());
// Search guarantees to add
List<IdmIdentityDto> guaranteesToAdd = syncContract.getGuarantees().stream().filter(identity -> {
return !currentGuarantees.stream().filter(currentGuarrantee -> {
return identity.getId().equals(currentGuarrantee.getGuarantee());
}).findFirst().isPresent();
}).collect(Collectors.toList());
// Delete guarantees
guaranteesToDelete.forEach(guarantee -> {
EntityEvent<IdmContractGuaranteeDto> guaranteeEvent = new ContractGuaranteeEvent(ContractGuaranteeEventType.DELETE, guarantee, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning));
guaranteeService.publish(guaranteeEvent);
});
// Create new guarantees
guaranteesToAdd.forEach(identity -> {
IdmContractGuaranteeDto guarantee = new IdmContractGuaranteeDto();
guarantee.setIdentityContract(contract.getId());
guarantee.setGuarantee(identity.getId());
//
EntityEvent<IdmContractGuaranteeDto> guaranteeEvent = new ContractGuaranteeEvent(ContractGuaranteeEventType.CREATE, guarantee, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning));
guaranteeService.publish(guaranteeEvent);
});
}
return contract;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class ContractSynchronizationExecutor method isPositionsSame.
/**
* Check if current contract's positions are same as in account values
*
* @param dto
* @param newPositions
* @return
*/
private boolean isPositionsSame(IdmIdentityContractDto dto, List<IdmTreeNodeDto> newPositions) {
// Find current positions
IdmContractPositionFilter positionFilter = new IdmContractPositionFilter();
positionFilter.setIdentityContractId(dto.getId());
List<IdmContractPositionDto> currentPositions = contractPositionService.find(positionFilter, null).getContent();
List<UUID> currentPositionsIds = currentPositions.stream().map(position -> {
return position.getWorkPosition();
}).collect(Collectors.toList());
List<UUID> newPositionIds = newPositions.stream().map(position -> {
return position.getId();
}).collect(Collectors.toList());
return CollectionUtils.isEqualCollection(currentPositionsIds, newPositionIds);
}
Aggregations