use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class ContractGuaranteeSaveProcessor method checkControlledBySlices.
/**
* Test if contract of the given contract guarantee has some slices.
*
* @param guarantee
* @return
*/
private void checkControlledBySlices(EntityEvent<IdmContractGuaranteeDto> event) {
IdmContractGuaranteeDto guarantee = event.getContent();
if (getBooleanProperty(ContractSliceManager.SKIP_CHECK_FOR_SLICES, event.getProperties())) {
return;
}
UUID contract = guarantee.getIdentityContract();
IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
sliceFilter.setParentContract(contract);
if (contract != null && sliceService.count(sliceFilter) > 0) {
throw new ResultCodeException(CoreResultCode.CONTRACT_IS_CONTROLLED_GUARANTEE_CANNOT_BE_MODIFIED, ImmutableMap.of("contractId", contract));
}
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class TreeNodeDeleteProcessor method process.
@Override
public EventResult<IdmTreeNodeDto> process(EntityEvent<IdmTreeNodeDto> event) {
IdmTreeNodeDto treeNode = event.getContent();
Assert.notNull(treeNode, "Tree node is required.");
UUID treeNodeId = treeNode.getId();
Assert.notNull(treeNodeId, "Tree node identifier is required.");
boolean forceDelete = getBooleanProperty(PROPERTY_FORCE_DELETE, event.getProperties());
// check role can be removed without force
if (!forceDelete) {
checkWithoutForceDelete(treeNode);
}
//
// check automatic role request
IdmAutomaticRoleRequestFilter roleRequestFilter = new IdmAutomaticRoleRequestFilter();
roleRequestFilter.setTreeNodeId(treeNodeId);
List<IdmAutomaticRoleRequestDto> roleRequestDtos = roleRequestService.find(roleRequestFilter, null).getContent();
for (IdmAutomaticRoleRequestDto request : roleRequestDtos) {
if (!request.getState().isTerminatedState()) {
roleRequestService.cancel(request);
}
request.setTreeNode(null);
roleRequestService.save(request);
}
if (forceDelete) {
// delete all tree node children
service.findChildrenByParent(treeNodeId, null).forEach(child -> {
TreeNodeEvent treeNodeEvent = new TreeNodeEvent(TreeNodeEventType.DELETE, child);
//
service.publish(treeNodeEvent, event);
clearSession();
});
//
// update contract slices
IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
sliceFilter.setTreeNode(treeNodeId);
sliceFilter.setRecursionType(RecursionType.NO);
contractSliceService.find(sliceFilter, null).forEach(slice -> {
slice.setWorkPosition(null);
contractSliceService.save(slice);
clearSession();
});
//
// update related contracts
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setWorkPosition(treeNodeId);
contractFilter.setRecursionType(RecursionType.NO);
identityContractService.find(contractFilter, null).forEach(identityContract -> {
// prepare event
identityContract.setWorkPosition(null);
IdentityContractEvent contractEvent = new IdentityContractEvent(IdentityContractEventType.UPDATE, identityContract);
//
identityContractService.publish(contractEvent, event);
clearSession();
});
//
// update related contract positions
IdmContractPositionFilter positionFilter = new IdmContractPositionFilter();
positionFilter.setWorkPosition(treeNodeId);
contractPositionService.find(positionFilter, null).forEach(contractPosition -> {
// prepare event
contractPosition.setWorkPosition(null);
ContractPositionEvent contractPositionEvent = new ContractPositionEvent(ContractPositionEventType.UPDATE, contractPosition);
//
contractPositionService.publish(contractPositionEvent, event);
clearSession();
});
//
// related automatic roles by tree structure
IdmRoleTreeNodeFilter roleTreeNodefilter = new IdmRoleTreeNodeFilter();
roleTreeNodefilter.setTreeNodeId(treeNodeId);
roleTreeNodeService.findIds(roleTreeNodefilter, null).stream().forEach(roleTreeNodeId -> {
// sync => all asynchronous requests have to be prepared in event queue
RemoveAutomaticRoleTaskExecutor automaticRoleTask = AutowireHelper.createBean(RemoveAutomaticRoleTaskExecutor.class);
automaticRoleTask.setAutomaticRoleId(roleTreeNodeId);
longRunningTaskManager.executeSync(automaticRoleTask);
clearSession();
});
}
//
if (forceDelete) {
LOG.debug("Tree node [{}] should be deleted by caller after all asynchronus processes are completed.", treeNode.getCode());
//
// dirty flag only - will be processed after asynchronous events ends
IdmEntityStateDto stateDeleted = new IdmEntityStateDto();
stateDeleted.setEvent(event.getId());
stateDeleted.setResult(new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(CoreResultCode.DELETED)).build());
entityStateManager.saveState(treeNode, stateDeleted);
//
// set disabled
treeNode.setDisabled(true);
service.saveInternal(treeNode);
} else {
service.deleteInternal(treeNode);
}
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class IdentityDeleteProcessor method process.
@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
IdmIdentityDto identity = event.getContent();
UUID identityId = identity.getId();
Assert.notNull(identityId, "Identity ID is required!");
boolean forceDelete = getBooleanProperty(PROPERTY_FORCE_DELETE, event.getProperties());
//
// delete contract slices
IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
sliceFilter.setIdentity(identityId);
contractSliceService.find(sliceFilter, null).forEach(guarantee -> {
contractSliceService.delete(guarantee);
});
// delete contract slice guarantees
IdmContractSliceGuaranteeFilter sliceGuaranteeFilter = new IdmContractSliceGuaranteeFilter();
sliceGuaranteeFilter.setGuaranteeId(identityId);
contractSliceGuaranteeService.find(sliceGuaranteeFilter, null).forEach(guarantee -> {
contractSliceGuaranteeService.delete(guarantee);
});
//
// contracts
identityContractService.findAllByIdentity(identityId).forEach(identityContract -> {
// when identity is deleted, then HR processes has to be skipped (prevent to update deleted identity, when contract is removed)
Map<String, Serializable> properties = new HashMap<>();
properties.put(IdmIdentityContractService.SKIP_HR_PROCESSES, Boolean.TRUE);
// propagate force attribute
properties.put(PROPERTY_FORCE_DELETE, forceDelete);
// prepare event
IdentityContractEvent contractEvent = new IdentityContractEvent(IdentityContractEventType.DELETE, identityContract, properties);
contractEvent.setPriority(PriorityType.HIGH);
//
identityContractService.publish(contractEvent);
});
// delete contract guarantees
IdmContractGuaranteeFilter filter = new IdmContractGuaranteeFilter();
filter.setGuaranteeId(identityId);
contractGuaranteeService.find(filter, null).forEach(guarantee -> {
contractGuaranteeService.delete(guarantee);
});
// remove role guarantee
IdmRoleGuaranteeFilter roleGuaranteeFilter = new IdmRoleGuaranteeFilter();
roleGuaranteeFilter.setGuarantee(identityId);
roleGuaranteeService.find(roleGuaranteeFilter, null).forEach(roleGuarantee -> {
roleGuaranteeService.delete(roleGuarantee);
});
// remove password
passwordProcessor.deletePassword(identity);
// delete password history for identity
passwordHistoryService.deleteAllByIdentity(identityId);
// disable related tokens - tokens has to be disabled to prevent their usage (when tokens are deleted, then token is recreated)
tokenManager.disableTokens(identity);
//
// delete all identity's profiles
IdmProfileFilter profileFilter = new IdmProfileFilter();
profileFilter.setIdentityId(identityId);
profileService.find(profileFilter, null).forEach(profile -> {
profileService.delete(profile);
});
// remove all IdentityRoleValidRequest for this identity
List<IdmIdentityRoleValidRequestDto> validRequests = identityRoleValidRequestService.findAllValidRequestForIdentityId(identityId);
identityRoleValidRequestService.deleteAll(validRequests);
//
// delete all identity's delegations - delegate
IdmDelegationDefinitionFilter delegationFilter = new IdmDelegationDefinitionFilter();
delegationFilter.setDelegateId(identityId);
delegationDefinitionService.find(delegationFilter, null).forEach(delegation -> {
delegationDefinitionService.delete(delegation);
});
//
// delete all identity's delegations - delegator
delegationFilter = new IdmDelegationDefinitionFilter();
delegationFilter.setDelegatorId(identityId);
delegationDefinitionService.find(delegationFilter, null).forEach(delegation -> {
delegationDefinitionService.delete(delegation);
});
// deletes identity
if (forceDelete) {
LOG.debug("Identity [{}] should be deleted by caller after all asynchronus processes are completed.", identityId);
//
// dirty flag only - will be processed after asynchronous events ends
IdmEntityStateDto stateDeleted = new IdmEntityStateDto();
stateDeleted.setEvent(event.getId());
stateDeleted.setResult(new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(CoreResultCode.DELETED)).build());
entityStateManager.saveState(identity, stateDeleted);
//
// set disabled (automatically)
identity.setState(IdentityState.DISABLED);
service.saveInternal(identity);
} else {
// delete all role requests where is this identity applicant
IdmRoleRequestFilter roleRequestFilter = new IdmRoleRequestFilter();
roleRequestFilter.setApplicantId(identityId);
roleRequestService.find(roleRequestFilter, null).forEach(request -> {
roleRequestService.delete(request);
});
//
service.deleteInternal(identity);
}
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class ContractSliceSyncTest method sliceWithDefaultLeaderTest.
@Test
public void sliceWithDefaultLeaderTest() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
IdmIdentityDto defaultLeader = helper.createIdentity();
helper.createIdentity(CONTRACT_OWNER_ONE);
((SysSyncContractConfigDto) config).setDefaultLeader(defaultLeader.getId());
config = syncConfigService.save(config);
IdmContractSliceFilter contractSliceFilter = new IdmContractSliceFilter();
contractSliceFilter.setProperty(IdmIdentityContract_.position.getName());
contractSliceFilter.setValue("1");
Assert.assertEquals(0, contractSliceService.find(contractSliceFilter, null).getTotalElements());
contractSliceFilter.setValue("2");
Assert.assertEquals(0, contractSliceService.find(contractSliceFilter, null).getTotalElements());
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 4);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
contractSliceFilter.setValue("2");
// Find slice guarantees (Have to be sets default leader.)
Assert.assertEquals(defaultLeader.getId(), contractSliceManager.findSliceGuarantees(contractSliceService.find(contractSliceFilter, null).getContent().get(0).getId()).get(0).getGuarantee());
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class ContractSliceSyncTest method createContractSlicesTest.
@Test
public void createContractSlicesTest() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
helper.createIdentity(CONTRACT_OWNER_ONE);
helper.createIdentity(CONTRACT_OWNER_TWO);
helper.createIdentity(CONTRACT_LEADER_ONE);
IdmTreeTypeDto treeType = helper.createTreeType();
IdmTreeNodeDto defaultNode = helper.createTreeNode(treeType, null);
((SysSyncContractConfigDto) config).setDefaultTreeType(treeType.getId());
((SysSyncContractConfigDto) config).setDefaultTreeNode(defaultNode.getId());
config = syncConfigService.save(config);
IdmContractSliceFilter contractFilter = new IdmContractSliceFilter();
contractFilter.setProperty(IdmIdentityContract_.position.getName());
contractFilter.setValue("1");
Assert.assertEquals(0, contractSliceService.find(contractFilter, null).getTotalElements());
contractFilter.setValue("2");
Assert.assertEquals(0, contractSliceService.find(contractFilter, null).getTotalElements());
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 4);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
contractFilter.setValue("1");
Assert.assertEquals(1, contractSliceService.find(contractFilter, null).getTotalElements());
// Find slice guarantees
Assert.assertEquals(1, contractSliceManager.findSliceGuarantees(contractSliceService.find(contractFilter, null).getContent().get(0).getId()).size());
contractFilter.setValue("2");
Assert.assertEquals(1, contractSliceService.find(contractFilter, null).getTotalElements());
contractFilter.setValue("3");
List<IdmContractSliceDto> contractsThree = contractSliceService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractsThree.size());
Assert.assertEquals(null, contractsThree.get(0).getState());
// Find slice guarantees
Assert.assertEquals(0, contractSliceManager.findSliceGuarantees(contractsThree.get(0).getId()).size());
contractFilter.setValue("4");
Assert.assertEquals(1, contractSliceService.find(contractFilter, null).getTotalElements());
// Delete log
syncLogService.delete(log);
}
Aggregations