use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter 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.IdmContractPositionFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmContractPositionServiceIntegrationTest method testReferentialIntegrityOnContractDelete.
@Test
@Transactional
public void testReferentialIntegrityOnContractDelete() {
// prepare data
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = getHelper().createContract(identity);
getHelper().createContractPosition(contract);
//
IdmContractPositionFilter positionFilter = new IdmContractPositionFilter();
positionFilter.setIdentityContractId(contract.getId());
List<IdmContractPositionDto> positions = service.find(positionFilter, null).getContent();
Assert.assertEquals(1, positions.size());
//
getHelper().deleteContract(contract.getId());
//
positions = service.find(positionFilter, null).getContent();
Assert.assertTrue(positions.isEmpty());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManager method getOtherPositions.
/**
* Load other positions.
*
* @param dto
* @param permission
* @return
*/
protected List<IdmContractPositionDto> getOtherPositions(IdmIdentityProjectionDto dto, BasePermission... permission) {
IdmContractPositionFilter positionFilter = new IdmContractPositionFilter();
positionFilter.setIdentity(dto.getIdentity().getId());
positionFilter.setAddPermissions(true);
//
return Lists.newArrayList(contractPositionService.find(positionFilter, null, permission).getContent());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter in project CzechIdMng by bcvsolutions.
the class IdmContractPositionController method toFilter.
@Override
protected IdmContractPositionFilter toFilter(MultiValueMap<String, Object> parameters) {
IdmContractPositionFilter filter = new IdmContractPositionFilter(parameters, getParameterConverter());
// codeable decorator
filter.setIdentity(getParameterConverter().toEntityUuid(parameters, IdmContractPositionFilter.PARAMETER_IDENTITY, IdmIdentityDto.class));
//
return filter;
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter in project CzechIdMng by bcvsolutions.
the class ProcessAutomaticRoleByTreeTaskExecutor method processPositions.
private Set<UUID> processPositions(IdmRoleTreeNodeDto automaticRole) {
Set<UUID> processedRoles = new HashSet<>();
//
IdmContractPositionFilter filter = new IdmContractPositionFilter();
filter.setWorkPosition(automaticRole.getTreeNode());
filter.setRecursionType(automaticRole.getRecursionType());
filter.setValidNowOrInFuture(Boolean.TRUE);
Pageable pageable = PageRequest.of(0, getPageSize(), new Sort(Direction.ASC, BaseEntity.PROPERTY_ID));
boolean canContinue = true;
//
do {
Page<IdmContractPositionDto> positions = contractPositionService.find(filter, pageable);
//
for (Iterator<IdmContractPositionDto> i = positions.iterator(); i.hasNext() && canContinue; ) {
IdmContractPositionDto position = i.next();
UUID contractId = position.getId();
//
if (!requireNewTransaction()) {
processedRoles.addAll(processPosition(position, automaticRole));
} else {
TransactionTemplate template = new TransactionTemplate(platformTransactionManager);
template.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
//
try {
template.execute(new TransactionCallbackWithoutResult() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
processedRoles.addAll(processPosition(position, automaticRole));
}
});
} catch (UnexpectedRollbackException ex) {
// Just log for sure ... exception solved in new transaction, but this lower transaction is marked as roll-back.
LOG.debug("Statefull process [{}] processed contract [{}] failed", getClass().getSimpleName(), contractId, ex);
}
}
//
if (!this.updateState()) {
LOG.debug("Task [{}] was canceled.", getLongRunningTaskId());
// return null => not continue with role removal
return null;
}
}
canContinue &= positions.hasNext();
pageable = positions.nextPageable();
//
} while (canContinue);
//
return processedRoles;
}
Aggregations