Search in sources :

Example 61 with IdmRoleTreeNodeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.

the class TreeNodeDeleteBulkActionIntegrationTest method testForceDelete.

@Test
public void testForceDelete() {
    logout();
    loginAsAdmin();
    // create sub tree nodes, automatic roles, contract, contract positions
    IdmTreeNodeDto treeNode = getHelper().createTreeNode();
    IdmTreeNodeDto subTreeNode = getHelper().createTreeNode((String) null, treeNode);
    IdmTreeNodeDto subSubTreeNode = getHelper().createTreeNode((String) null, subTreeNode);
    IdmTreeNodeDto otherTreeNode = getHelper().createTreeNode();
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmIdentityContractDto contract = getHelper().createContract(identity, subTreeNode);
    IdmContractPositionDto contractPosition = getHelper().createContractPosition(contract, subSubTreeNode);
    IdmRoleDto role = getHelper().createRole();
    IdmIdentityRoleDto assignedRoleOne = getHelper().createIdentityRole(contract, role);
    IdmIdentityRoleDto assignedRoleTwo = getHelper().createIdentityRole(contractPosition, role);
    IdmIdentityRoleDto assignedRoleOther = getHelper().createIdentityRole(getHelper().getPrimeContract(identity), role);
    IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(role, treeNode, RecursionType.DOWN, false);
    // 
    // 3 manual, 2 automatic
    Assert.assertEquals(5, identityRoleService.findAllByIdentity(identity.getId()).size());
    // 
    // remove tree node
    Map<String, Object> properties = new HashMap<>();
    properties.put(EntityEventProcessor.PROPERTY_FORCE_DELETE, Boolean.TRUE);
    // delete by bulk action
    IdmBulkActionDto bulkAction = this.findBulkAction(IdmTreeNode.class, TreeNodeDeleteBulkAction.NAME);
    bulkAction.setIdentifiers(Sets.newHashSet(treeNode.getId()));
    bulkAction.setProperties(properties);
    IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
    // 
    checkResultLrt(processAction, 1l, 0l, 0l);
    // 
    Assert.assertNull(treeNodeService.get(treeNode));
    Assert.assertNull(treeNodeService.get(subTreeNode));
    Assert.assertNull(treeNodeService.get(subSubTreeNode));
    Assert.assertNull(treeNodeService.get(subSubTreeNode));
    Assert.assertNotNull(identityRoleService.get(assignedRoleOne));
    Assert.assertNotNull(identityRoleService.get(assignedRoleTwo));
    Assert.assertNull(identityContractService.get(contract).getWorkPosition());
    Assert.assertNull(contractPositionService.get(contractPosition).getWorkPosition());
    Assert.assertNull(roleTreeNodeService.get(automaticRole));
    // 
    Assert.assertNotNull(treeNodeService.get(otherTreeNode));
    Assert.assertNotNull(getHelper().getPrimeContract(identity));
    Assert.assertNotNull(identityRoleService.get(assignedRoleOther));
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) HashMap(java.util.HashMap) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Example 62 with IdmRoleTreeNodeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.

the class RoleTreeNodeSaveProcessor method process.

@Override
public EventResult<IdmRoleTreeNodeDto> process(EntityEvent<IdmRoleTreeNodeDto> event) {
    IdmRoleTreeNodeDto dto = event.getContent();
    // 
    dto = service.saveInternal(dto);
    event.setContent(dto);
    // assign role by this added automatic role to all existing identity contracts with long running task
    try {
        ProcessAutomaticRoleByTreeTaskExecutor automaticRoleTask = AutowireHelper.createBean(ProcessAutomaticRoleByTreeTaskExecutor.class);
        automaticRoleTask.setAutomaticRoles(Lists.newArrayList(dto.getId()));
        executeTask(event, automaticRoleTask);
    } catch (AcceptedException ex) {
        DefaultEventResult<IdmRoleTreeNodeDto> result = new DefaultEventResult<>(event, this);
        result.setSuspended(true);
        // 
        return result;
    }
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : ProcessAutomaticRoleByTreeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByTreeTaskExecutor) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException)

Example 63 with IdmRoleTreeNodeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.

the class ProcessAutomaticRoleByTreeTaskExecutor method getItemsToProcess.

@Override
public Page<IdmRoleTreeNodeDto> getItemsToProcess(Pageable pageable) {
    IdmRoleTreeNodeFilter filter = new IdmRoleTreeNodeFilter();
    // 
    // we need to process all automatic roles => assigned role removal is on the end
    List<IdmRoleTreeNodeDto> items = new ArrayList<>(automaticRoles.size());
    // 
    // prevent to exceed IN limit sql clause
    int pageSize = 500;
    Page<UUID> idPage = new PageImpl<UUID>(automaticRoles, PageRequest.of(0, pageSize), automaticRoles.size());
    for (int page = 0; page < idPage.getTotalPages(); page++) {
        int end = (page + 1) * pageSize;
        if (end > automaticRoles.size()) {
            end = automaticRoles.size();
        }
        filter.setIds(automaticRoles.subList(page * pageSize, end));
        items.addAll(roleTreeNodeService.find(filter, PageRequest.of(0, Integer.MAX_VALUE, Sort.by(String.format("%s.%s", IdmRoleTreeNode_.role.getName(), IdmRole_.code.getName())))).getContent());
    }
    // 
    return new PageImpl<>(items, PageRequest.of(0, automaticRoles.size()), automaticRoles.size());
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) IdmRoleTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleTreeNodeFilter) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) ArrayList(java.util.ArrayList) UUID(java.util.UUID)

Example 64 with IdmRoleTreeNodeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.

the class RemoveAutomaticRoleTaskExecutor method end.

@Override
protected Boolean end(Boolean result, Exception ex) {
    if (!BooleanUtils.isTrue(result) || ex != null) {
        return super.end(result, ex);
    }
    // 
    IdmRoleDto role = DtoUtils.getEmbedded(getAutomaticRole(), IdmRoleTreeNode_.role);
    long assignedRoles = identityRoleService.findByAutomaticRole(getAutomaticRoleId(), PageRequest.of(0, 1)).getTotalElements();
    if (assignedRoles != 0) {
        // some assigned role was created in the meantime
        UUID automaticRoleId = getAutomaticRoleId();
        LOG.debug("Remove role [{}] by automatic role [{}] is not complete, some roles [{}] remains assigned to identities.", role.getCode(), automaticRoleId, assignedRoles);
        ResultModel resultModel = new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_REMOVE_HAS_ASSIGNED_ROLES, ImmutableMap.of("automaticRoleId", automaticRoleId.toString(), "assignedRoles", String.valueOf(assignedRoles)));
        saveResult(resultModel, OperationState.EXCEPTION, null);
    } else {
        // 
        LOG.debug("Remove role [{}] by automatic role [{}]", role.getCode(), getAutomaticRole().getId());
        try {
            // 
            // Find all concepts and remove relation on automatic role
            IdmConceptRoleRequestFilter conceptRequestFilter = new IdmConceptRoleRequestFilter();
            conceptRequestFilter.setAutomaticRole(getAutomaticRoleId());
            // 
            List<IdmConceptRoleRequestDto> concepts = conceptRequestService.find(conceptRequestFilter, null).getContent();
            for (IdmConceptRoleRequestDto concept : concepts) {
                IdmRoleRequestDto request = roleRequestService.get(concept.getRoleRequest());
                String message = null;
                if (concept.getState().isTerminatedState()) {
                    message = MessageFormat.format("Automatic role [{0}] (reqested in concept [{1}]) was deleted (not from this role request)!", getAutomaticRoleId(), concept.getId());
                } else {
                    message = MessageFormat.format("Request change in concept [{0}], was not executed, because requested automatic role [{1}] was deleted (not from this role request)!", concept.getId(), getAutomaticRoleId());
                    concept.setState(RoleRequestState.CANCELED);
                }
                roleRequestService.addToLog(request, message);
                conceptRequestService.addToLog(concept, message);
                concept.setAutomaticRole(null);
                roleRequestService.save(request);
                conceptRequestService.save(concept);
            }
            // by default is this allowed
            if (this.isDeleteEntity()) {
                // delete entity
                if (getAutomaticRole() instanceof IdmRoleTreeNodeDto) {
                    roleTreeNodeService.deleteInternalById(getAutomaticRole().getId());
                } else {
                    // remove all rules
                    automaticRoleAttributeRuleService.deleteAllByAttribute(getAutomaticRole().getId());
                    automaticRoleAttributeService.deleteInternalById(getAutomaticRole().getId());
                }
            }
            // 
            LOG.debug("End: Remove role [{}] by automatic role [{}].", role.getCode(), getAutomaticRole().getId());
        // 
        } catch (Exception O_o) {
            LOG.debug("Remove role [{}] by automatic role [{}] failed", role.getCode(), getAutomaticRole().getId(), O_o);
            // 
            IdmLongRunningTaskDto task = longRunningTaskService.get(getLongRunningTaskId());
            ResultModel resultModel = new DefaultResultModel(CoreResultCode.LONG_RUNNING_TASK_FAILED, ImmutableMap.of("taskId", getLongRunningTaskId(), "taskType", task.getTaskType(), ConfigurationService.PROPERTY_INSTANCE_ID, task.getInstanceId()));
            saveResult(resultModel, OperationState.EXCEPTION, O_o);
        }
    }
    // 
    return super.end(result, ex);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) IdmConceptRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) UUID(java.util.UUID) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)

Example 65 with IdmRoleTreeNodeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmContractPositionServiceIntegrationTest method testChangePositionWithAutomaticRolesAssigned.

@Test
@Transactional
public void testChangePositionWithAutomaticRolesAssigned() {
    IdmRoleDto role = getHelper().createRole();
    IdmTreeNodeDto treeNode = getHelper().createTreeNode();
    IdmRoleTreeNodeDto automaticRole = getHelper().createAutomaticRole(role, treeNode);
    // 
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
    List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertTrue(assignedRoles.isEmpty());
    // 
    IdmContractPositionDto position = getHelper().createContractPosition(contract);
    // 
    assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertTrue(assignedRoles.isEmpty());
    // 
    position.setWorkPosition(treeNode.getId());
    position = service.save(position);
    // 
    assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertEquals(1, assignedRoles.size());
    Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
    Assert.assertEquals(position.getId(), assignedRoles.get(0).getContractPosition());
    // 
    position.setWorkPosition(null);
    position = service.save(position);
    // 
    assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertTrue(assignedRoles.isEmpty());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) 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)

Aggregations

IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)83 Test (org.junit.Test)56 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)48 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)46 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)42 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)39 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)38 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)38 UUID (java.util.UUID)32 Autowired (org.springframework.beans.factory.annotation.Autowired)20 IdmContractPositionDto (eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto)19 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)19 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)19 List (java.util.List)19 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)18 ProcessAutomaticRoleByTreeTaskExecutor (eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByTreeTaskExecutor)18 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)17 Transactional (org.springframework.transaction.annotation.Transactional)17 IdmIdentityRoleService (eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService)16 Assert (org.junit.Assert)16