use of eu.bcvsolutions.idm.core.model.event.IdentityContractEvent in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManager method saveContract.
/**
* Save the first ~ prime contract.
*
* @param event
* @param permission
* @return
*/
protected IdmIdentityContractDto saveContract(EntityEvent<IdmIdentityProjectionDto> event, BasePermission... permission) {
IdmIdentityProjectionDto dto = event.getContent();
IdmIdentityDto identity = dto.getIdentity();
//
IdmIdentityContractDto contract = dto.getContract();
if (contract == null) {
// prime contract was not sent => not save, but is needed in other processing
List<IdmIdentityContractDto> contracts = getContracts(dto, PermissionUtils.isEmpty(permission) ? null : IdmBasePermission.READ);
if (contracts.isEmpty()) {
return null;
}
// ~ prime contract
return contracts.get(0);
}
// check contract has to be saved
if (identity.getFormProjection() != null) {
IdmFormProjectionDto formProjection = lookupService.lookupEmbeddedDto(dto.getIdentity(), IdmIdentity_.formProjection);
if (!formProjection.getProperties().getBooleanValue(IdentityFormProjectionRoute.PARAMETER_ALL_CONTRACTS) && !formProjection.getProperties().getBooleanValue(IdentityFormProjectionRoute.PARAMETER_PRIME_CONTRACT)) {
LOG.debug("Projection [{}] doesn't save prime contract.", formProjection.getCode());
return contract;
}
}
contract.setIdentity(identity.getId());
IdentityContractEventType contractEventType = IdentityContractEventType.CREATE;
if (!contractService.isNew(contract)) {
contractEventType = IdentityContractEventType.UPDATE;
}
EntityEvent<IdmIdentityContractDto> contractEvent = new IdentityContractEvent(contractEventType, contract);
//
return contractService.publish(contractEvent, event, permission).getContent();
}
use of eu.bcvsolutions.idm.core.model.event.IdentityContractEvent in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManager method deleteContract.
private void deleteContract(EntityEvent<IdmIdentityProjectionDto> event, IdmIdentityContractDto contract, BasePermission... permission) {
IdentityContractEventType contractEventType = IdentityContractEventType.DELETE;
IdentityContractEvent otherContractEvent = new IdentityContractEvent(contractEventType, contract);
if (BooleanUtils.isTrue(contract.getControlledBySlices())) {
LOG.debug("Contract [{}] is controlled by contract slices, will be ignored in projection.", contract.getId());
return;
}
//
contractService.publish(otherContractEvent, event, PermissionUtils.isEmpty(permission) ? null : IdmBasePermission.DELETE);
}
use of eu.bcvsolutions.idm.core.model.event.IdentityContractEvent in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManager method saveOtherContracts.
protected List<IdmIdentityContractDto> saveOtherContracts(EntityEvent<IdmIdentityProjectionDto> event, BasePermission... permission) {
IdmIdentityProjectionDto dto = event.getContent();
IdmIdentityProjectionDto previousProjection = event.getOriginalSource();
List<IdmIdentityContractDto> savedContracts = new ArrayList<>(dto.getOtherContracts().size());
//
// check all contracts has to be saved
IdmIdentityDto identity = dto.getIdentity();
if (identity.getFormProjection() != null) {
IdmFormProjectionDto formProjection = lookupService.lookupEmbeddedDto(dto.getIdentity(), IdmIdentity_.formProjection);
if (!formProjection.getProperties().getBooleanValue(IdentityFormProjectionRoute.PARAMETER_ALL_CONTRACTS)) {
LOG.debug("Projection [{}] doesn't save other contracts.", formProjection.getCode());
return savedContracts;
}
}
//
for (IdmIdentityContractDto contract : dto.getOtherContracts()) {
IdentityContractEventType contractEventType = IdentityContractEventType.CREATE;
if (!contractService.isNew(contract)) {
contractEventType = IdentityContractEventType.UPDATE;
// TODO: validation - identity cannot be changed
} else {
contract.setIdentity(dto.getIdentity().getId());
}
IdentityContractEvent otherContractEvent = new IdentityContractEvent(contractEventType, contract);
//
savedContracts.add(contractService.publish(otherContractEvent, event, permission).getContent());
if (previousProjection != null) {
previousProjection.getOtherContracts().removeIf(c -> {
return Objects.equals(c.getId(), contract.getId());
});
}
}
// remove not sent contracts, if previous exists
if (previousProjection != null) {
boolean primeContractChanged = false;
//
for (IdmIdentityContractDto contract : previousProjection.getOtherContracts()) {
if (Objects.equals(dto.getContract(), contract)) {
// new prime contract is saved all time
primeContractChanged = true;
continue;
}
//
deleteContract(event, contract, permission);
}
// delete previous prime contract, if order of contracts changed
if (primeContractChanged && !savedContracts.contains(previousProjection.getContract())) {
deleteContract(event, previousProjection.getContract(), permission);
}
}
//
return savedContracts;
}
use of eu.bcvsolutions.idm.core.model.event.IdentityContractEvent in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testSkipAndAssignAutomaticRoleOnContractAfterChange.
@Test
public void testSkipAndAssignAutomaticRoleOnContractAfterChange() {
IdmTreeNodeDto otherNode = getHelper().createTreeNode();
IdmTreeNodeDto node = getHelper().createTreeNode();
// define automatic role for parent
IdmRoleDto role = getHelper().createRole();
IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(role, node, RecursionType.NO, true);
// create identity with contract on node
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = getHelper().createContract(identity, otherNode);
// no role should be assigned now
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
contract.setWorkPosition(node.getId());
EntityEvent<IdmIdentityContractDto> event = new IdentityContractEvent(IdentityContractEventType.UPDATE, contract);
event.getProperties().put(AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE);
contract = service.publish(event).getContent();
UUID contractId = contract.getId();
IdmEntityStateFilter filter = new IdmEntityStateFilter();
filter.setStates(Lists.newArrayList(OperationState.BLOCKED));
filter.setResultCode(CoreResultCode.AUTOMATIC_ROLE_SKIPPED.getCode());
filter.setOwnerType(entityStateManager.getOwnerType(IdmIdentityContractDto.class));
List<IdmEntityStateDto> skippedStates = entityStateManager.findStates(filter, null).getContent();
Assert.assertFalse(skippedStates.isEmpty());
Assert.assertTrue(skippedStates.stream().anyMatch(s -> s.getOwnerId().equals(contractId)));
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
// recount skipped automatic roles
longRunningTaskManager.execute(new ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor());
skippedStates = entityStateManager.findStates(filter, null).getContent();
Assert.assertFalse(skippedStates.stream().anyMatch(s -> s.getOwnerId().equals(automaticRole.getId())));
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(1, assignedRoles.size());
Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
}
use of eu.bcvsolutions.idm.core.model.event.IdentityContractEvent in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method checkContractInvalidWithStartHrProcessesTest.
@Test
public /**
* HR process are not executed during sync, but after sync end.
*/
void checkContractInvalidWithStartHrProcessesTest() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
((SysSyncContractConfigDto) config).setStartOfHrProcesses(true);
syncConfigService.save(config);
Task task = findTask(HrEnableContractProcess.class);
IdmScheduledTaskDto scheduledTask = null;
if (scheduledService.findByQuartzTaskName(task.getId()) == null) {
scheduledTask = new IdmScheduledTaskDto();
scheduledTask.setQuartzTaskName(task.getId());
scheduledService.save(scheduledTask);
}
task = findTask(HrEndContractProcess.class);
if (scheduledService.findByQuartzTaskName(task.getId()) == null) {
scheduledTask = new IdmScheduledTaskDto();
scheduledTask.setQuartzTaskName(task.getId());
scheduledService.save(scheduledTask);
}
task = findTask(HrContractExclusionProcess.class);
if (scheduledService.findByQuartzTaskName(task.getId()) == null) {
scheduledTask = new IdmScheduledTaskDto();
scheduledTask.setQuartzTaskName(task.getId());
scheduledService.save(scheduledTask);
}
IdmIdentityDto ownerOne = helper.createIdentity(CONTRACT_OWNER_ONE);
IdmIdentityDto ownerTwo = helper.createIdentity(CONTRACT_OWNER_TWO);
helper.createIdentity(CONTRACT_LEADER_ONE);
contractService.findAllByIdentity(ownerOne.getId()).forEach(contract -> {
IdentityContractEvent event = new IdentityContractEvent(IdentityContractEventType.DELETE, contract);
event.getProperties().put(IdmIdentityContractService.SKIP_HR_PROCESSES, Boolean.TRUE);
contractService.publish(event);
});
contractService.findAllByIdentity(ownerTwo.getId()).forEach(contract -> {
IdentityContractEvent event = new IdentityContractEvent(IdentityContractEventType.DELETE, contract);
event.getProperties().put(IdmIdentityContractService.SKIP_HR_PROCESSES, Boolean.TRUE);
contractService.publish(event);
});
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setProperty(IdmIdentityContract_.position.getName());
contractFilter.setValue("1");
Assert.assertEquals(0, contractService.find(contractFilter, null).getTotalElements());
contractFilter.setValue("2");
Assert.assertEquals(0, contractService.find(contractFilter, null).getTotalElements());
// Change resources (set to invalid) .. must be call in transaction
this.getBean().initContractCheckInvalidTest();
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 2);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
contractFilter.setValue("1");
List<IdmIdentityContractDto> contractsOne = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractsOne.size());
Assert.assertFalse(contractsOne.get(0).isValid());
contractFilter.setValue("3");
List<IdmIdentityContractDto> contractsThree = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractsThree.size());
Assert.assertTrue(contractsThree.get(0).isValid());
// HR processes was started, identity have to be in "correct" state
ownerOne = identityService.getByUsername(CONTRACT_OWNER_ONE);
Assert.assertTrue(ownerOne.isDisabled());
ownerTwo = identityService.getByUsername(CONTRACT_OWNER_TWO);
Assert.assertFalse(ownerTwo.isDisabled());
// Delete log
syncLogService.delete(log);
}
Aggregations