Search in sources :

Example 1 with IdmContractPositionFilter

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);
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) TreeNodeEvent(eu.bcvsolutions.idm.core.model.event.TreeNodeEvent) IdmContractPositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter) RemoveAutomaticRoleTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.RemoveAutomaticRoleTaskExecutor) IdmRoleTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleTreeNodeFilter) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) ContractPositionEvent(eu.bcvsolutions.idm.core.model.event.ContractPositionEvent) UUID(java.util.UUID) IdmAutomaticRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleRequestFilter)

Example 2 with IdmContractPositionFilter

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());
}
Also used : IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmContractPositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with IdmContractPositionFilter

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());
}
Also used : IdmContractPositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter)

Example 4 with IdmContractPositionFilter

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;
}
Also used : IdmContractPositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 5 with IdmContractPositionFilter

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;
}
Also used : IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) IdmContractPositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) UnexpectedRollbackException(org.springframework.transaction.UnexpectedRollbackException) UUID(java.util.UUID) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) HashSet(java.util.HashSet)

Aggregations

IdmContractPositionFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter)16 IdmContractPositionDto (eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto)10 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)10 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)7 UUID (java.util.UUID)7 IdmIdentityContractFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter)6 Test (org.junit.Test)6 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)4 SysSyncContractConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto)4 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)4 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)4 IdmContractGuaranteeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter)4 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)4 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)3 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)3 IdmContractGuaranteeDto (eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto)3 EntityEvent (eu.bcvsolutions.idm.core.api.event.EntityEvent)3 EventContext (eu.bcvsolutions.idm.core.api.event.EventContext)3 EventResult (eu.bcvsolutions.idm.core.api.event.EventResult)3 AutomaticRoleManager (eu.bcvsolutions.idm.core.api.service.AutomaticRoleManager)3