use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.
the class IdentityChangeContractGuaranteeBulkActionTest method ifMultipleSameGuaranteesReplaceAll.
@Test
public void ifMultipleSameGuaranteesReplaceAll() {
List<IdmIdentityDto> oldGuarantees = this.createIdentities(1);
List<IdmIdentityDto> newGuarantees = this.createIdentities(1);
IdmIdentityDto employee = getHelper().createIdentity();
IdmIdentityContractDto contract1 = getHelper().getPrimeContract(employee);
createContractGuarantees(contract1, oldGuarantees);
// repeated assignment
createContractGuarantees(contract1, oldGuarantees);
Assert.assertTrue(isContractGuarantee(contract1, oldGuarantees).isEmpty());
Assert.assertEquals(2, getGuaranteesForContract(contract1.getId()).size());
IdmBulkActionDto bulkAction = this.findBulkAction(IdmIdentity.class, IdentityChangeContractGuaranteeBulkAction.NAME);
Set<UUID> ids = this.getIdFromList(Arrays.asList(employee));
bulkAction.setIdentifiers(ids);
// selected identityDtos
Map<String, Object> properties = new HashMap<>();
properties.put(IdentityAddContractGuaranteeBulkAction.PROPERTY_OLD_GUARANTEE, String.valueOf(oldGuarantees.get(0).getId()));
properties.put(IdentityAddContractGuaranteeBulkAction.PROPERTY_NEW_GUARANTEE, String.valueOf(newGuarantees.get(0).getId()));
bulkAction.setProperties(properties);
bulkActionManager.processAction(bulkAction);
checkResultLrt(bulkAction, 2l, null, null);
// all guarantees updated
List<IdmContractGuaranteeDto> assigned = getGuaranteesForContract(contract1.getId());
Assert.assertEquals(2, assigned.size());
Assert.assertEquals(newGuarantees.get(0).getId(), assigned.get(0).getGuarantee());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.
the class IdentityChangeContractGuaranteeBulkActionTest method withoutPermissionUpdateGuarantee.
@Test
@Transactional
public void withoutPermissionUpdateGuarantee() {
List<IdmIdentityDto> guarantees = this.createIdentities(2);
IdmIdentityDto employee = getHelper().createIdentity();
IdmIdentityContractDto contract1 = getHelper().getPrimeContract(employee);
Assert.assertEquals(0, getGuaranteesForContract(contract1.getId()).size());
// init guarantee to replace
createContractGuarantees(contract1, guarantees.subList(0, 1));
Assert.assertEquals(1, getGuaranteesForContract(contract1.getId()).size());
Assert.assertTrue(isContractGuarantee(contract1, guarantees.subList(0, 1)).isEmpty());
// Log as user without delete permission
IdmIdentityDto identityForLogin = getHelper().createIdentity();
IdmRoleDto permissionRole = getHelper().createRole();
getHelper().createBasePolicy(permissionRole.getId(), CoreGroupPermission.IDENTITY, IdmIdentity.class, IdmBasePermission.READ, IdmBasePermission.COUNT);
getHelper().createBasePolicy(permissionRole.getId(), CoreGroupPermission.CONTRACTGUARANTEE, IdmContractGuarantee.class, IdmBasePermission.READ);
getHelper().createIdentityRole(identityForLogin, permissionRole);
loginAsNoAdmin(identityForLogin.getUsername());
IdmBulkActionDto bulkAction = this.findBulkAction(IdmIdentity.class, IdentityChangeContractGuaranteeBulkAction.NAME);
Set<UUID> ids = this.getIdFromList(Arrays.asList(employee));
bulkAction.setIdentifiers(ids);
Map<String, Object> properties = new HashMap<>();
String oldGuarStr = String.valueOf(guarantees.get(0).getId());
String newGuarStr = String.valueOf(guarantees.get(1).getId());
properties.put(IdentityAddContractGuaranteeBulkAction.PROPERTY_OLD_GUARANTEE, oldGuarStr);
properties.put(IdentityAddContractGuaranteeBulkAction.PROPERTY_NEW_GUARANTEE, newGuarStr);
bulkAction.setProperties(properties);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
// original guarantee was not removed
checkResultLrt(processAction, null, 0l, 1l);
// there stayed original guarantee
List<IdmContractGuaranteeDto> assigned = getGuaranteesForContract(contract1.getId());
Assert.assertEquals(1, assigned.size());
Assert.assertTrue(isContractGuarantee(contract1, guarantees.subList(0, 1)).isEmpty());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.
the class ContractSynchronizationExecutor method isGuaranteesSame.
/**
* Check if current contract's guarantees are same as in account values
*
* @param dto
* @param newGuarantees
* @return
*/
private boolean isGuaranteesSame(IdmIdentityContractDto dto, List<IdmIdentityDto> newGuarantees) {
// Guarantees
IdmContractGuaranteeFilter guaranteeFilter = new IdmContractGuaranteeFilter();
guaranteeFilter.setIdentityContractId(dto.getId());
List<IdmContractGuaranteeDto> currentGuarantees = guaranteeService.find(guaranteeFilter, null).getContent();
List<UUID> currentGuranteeIds = currentGuarantees.stream().map(gurrantee -> {
return gurrantee.getGuarantee();
}).collect(Collectors.toList());
List<UUID> newGuranteeIds = newGuarantees.stream().map(gurrantee -> {
return gurrantee.getId();
}).collect(Collectors.toList());
return CollectionUtils.isEqualCollection(currentGuranteeIds, newGuranteeIds);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto 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.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.
the class DefaultContractSliceManager method cloneGuarante.
private IdmContractGuaranteeDto cloneGuarante(IdmContractSliceGuaranteeDto guarantee) {
IdmContractGuaranteeDto result = new IdmContractGuaranteeDto();
result.setGuarantee(guarantee.getGuarantee());
return result;
}
Aggregations