Search in sources :

Example 41 with IdmRoleTreeNodeDto

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

the class DefaultAutomaticRoleManager method deleteAutomaticRole.

@Override
public void deleteAutomaticRole(AbstractIdmAutomaticRoleDto automaticRole, boolean executeImmediately) {
    Assert.notNull(automaticRole, "Automatic role is required.");
    Assert.notNull(automaticRole.getId(), "Automatic role must exists!");
    IdmAutomaticRoleRequestDto request = new IdmAutomaticRoleRequestDto();
    if (automaticRole instanceof IdmRoleTreeNodeDto) {
        request.setRequestType(AutomaticRoleRequestType.TREE);
        request.setTreeNode(((IdmRoleTreeNodeDto) automaticRole).getTreeNode());
    } else {
        request.setRequestType(AutomaticRoleRequestType.ATTRIBUTE);
    }
    request.setOperation(RequestOperationType.REMOVE);
    request.setExecuteImmediately(executeImmediately);
    request.setAutomaticRole(automaticRole.getId());
    request.setName(automaticRole.getName());
    request.setRole(automaticRole.getRole());
    request = roleRequestService.save(request);
    request = roleRequestService.startRequestInternal(request.getId(), true);
    if (RequestState.EXECUTED == request.getState()) {
        return;
    }
    if (RequestState.IN_PROGRESS == request.getState()) {
        throw new AcceptedException(request.getId().toString());
    }
    if (RequestState.EXCEPTION == request.getState()) {
        throw new CoreException(request.getResult().getCause());
    }
}
Also used : IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException)

Example 42 with IdmRoleTreeNodeDto

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

the class ProcessSkippedAutomaticRoleByTreeTaskExecutor method processItem.

@Override
public Optional<OperationResult> processItem(IdmEntityStateDto state) {
    // check state is already processed by ProcessAutomaticRoleByTreeTaskExecutor
    // => automatic role recount can be skipped multiple times for the same automatic role.
    UUID ownerId = state.getOwnerId();
    state = entityStateService.get(state);
    if (state == null) {
        LOG.debug("Automatic roles for owner [{}] was already processed.", ownerId);
        // we need some result - counter / count will match.
        return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
    }
    // 
    if (processedOwnerIds.contains(ownerId)) {
        LOG.debug("Automatic roles for owner [{}] was already processed, delete state only.", ownerId);
        // 
        entityStateManager.deleteState(state);
        // Item will be deleted only - we need some result - counter / count will match.
        return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
    }
    // 
    // process automatic role on state owner
    LOG.debug("Process automatic roles for contract [{}].", ownerId);
    // 
    IdmRoleTreeNodeDto automaticRole = lookupService.lookupDto(IdmRoleTreeNodeDto.class, ownerId);
    if (automaticRole == null) {
        getItemService().createLogItem(state, new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.CONTENT_DELETED, ImmutableMap.of("ownerId", ownerId, "ownerType", entityEventManager.getOwnerType(IdmRoleTreeNodeDto.class)))).build(), this.getLongRunningTaskId());
        // delete state only
        entityStateManager.deleteState(state);
    } else {
        ProcessAutomaticRoleByTreeTaskExecutor automaticRoleTask = AutowireHelper.createBean(ProcessAutomaticRoleByTreeTaskExecutor.class);
        automaticRoleTask.setAutomaticRoles(Lists.newArrayList(automaticRole.getId()));
        // invalid roles will be removed, after LRT end (prevent drop and create target account)
        automaticRoleTask.setRemoveNotProcessedIdentityRoles(false);
        automaticRoleTask.setRequireNewTransaction(true);
        // exception is thrown and logged otherwise
        longRunningTaskManager.executeSync(automaticRoleTask);
        processedRoleRequests.addAll(automaticRoleTask.getProcessedRoleRequests());
        processedAutomaticRoles.add(ownerId);
        // 
        getItemService().createLogItem(automaticRole, new OperationResult.Builder(OperationState.EXECUTED).build(), this.getLongRunningTaskId());
    }
    // 
    processedOwnerIds.add(ownerId);
    // Log added manually above - log processed contract / position instead of deleted entity state.
    return Optional.empty();
}
Also used : IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) UUID(java.util.UUID)

Example 43 with IdmRoleTreeNodeDto

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

the class ProcessAutomaticRoleByTreeTaskExecutor method getFormInstance.

@Override
public IdmFormInstanceDto getFormInstance(ConfigurationMap properties) {
    IdmFormInstanceDto formInstance = new IdmFormInstanceDto(getFormDefinition());
    // 
    List<UUID> automaticRoles = getAutomaticRoles(properties);
    if (CollectionUtils.isEmpty(automaticRoles)) {
        return null;
    }
    automaticRoles.forEach(automaticRoleId -> {
        IdmFormValueDto value = new IdmFormValueDto(formInstance.getMappedAttributeByCode(AbstractAutomaticRoleTaskExecutor.PARAMETER_ROLE_TREE_NODE));
        value.setUuidValue(automaticRoleId);
        IdmRoleTreeNodeDto automaticRole = roleTreeNodeService.get(automaticRoleId);
        if (automaticRole == null) {
            // id only => prevent to load on UI
            // TODO: load from audit => #978 required
            automaticRole = new IdmRoleTreeNodeDto(automaticRoleId);
        }
        value.getEmbedded().put(IdmFormValueDto.PROPERTY_UUID_VALUE, automaticRole);
        formInstance.getValues().add(value);
    });
    // 
    return formInstance;
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) UUID(java.util.UUID)

Example 44 with IdmRoleTreeNodeDto

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

the class ProcessAutomaticRoleByTreeTaskExecutorIntegrationTest method testFormInstance.

@Test
public void testFormInstance() {
    ConfigurationMap properties = new ConfigurationMap();
    // 
    Assert.assertNull(executor.getFormInstance(properties));
    // 
    UUID automaticRoleId = UUID.randomUUID();
    properties.put(AbstractAutomaticRoleTaskExecutor.PARAMETER_ROLE_TREE_NODE, automaticRoleId);
    // 
    IdmFormInstanceDto formInstance = executor.getFormInstance(properties);
    Assert.assertNotNull(formInstance);
    Assert.assertNotNull(formInstance.getValues().stream().anyMatch(v -> v.getUuidValue().equals(automaticRoleId) && v.getEmbedded().get(IdmFormValueDto.PROPERTY_UUID_VALUE) != null));
    // 
    IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(getHelper().createRole(), getHelper().createTreeNode(), true);
    properties.put(AbstractAutomaticRoleTaskExecutor.PARAMETER_ROLE_TREE_NODE, automaticRole.getId());
    // 
    formInstance = executor.getFormInstance(properties);
    Assert.assertNotNull(formInstance);
    Assert.assertNotNull(formInstance.getValues().stream().anyMatch(v -> v.getUuidValue().equals(automaticRole.getId()) && v.getEmbedded().get(IdmFormValueDto.PROPERTY_UUID_VALUE) != null));
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmConceptRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmConceptRoleRequestService) Autowired(org.springframework.beans.factory.annotation.Autowired) RoleRequestedByType(eu.bcvsolutions.idm.core.api.domain.RoleRequestedByType) AutowireHelper(eu.bcvsolutions.idm.core.api.utils.AutowireHelper) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) Qualifier(org.springframework.beans.factory.annotation.Qualifier) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) LongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskManager) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) UUID(java.util.UUID) Sets(com.google.common.collect.Sets) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) ExecutionException(java.util.concurrent.ExecutionException) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) UUID(java.util.UUID) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 45 with IdmRoleTreeNodeDto

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

the class IdmRoleTreeNodeControllerRestTest method prepareDto.

@Override
protected IdmRoleTreeNodeDto prepareDto() {
    IdmRoleTreeNodeDto dto = new IdmRoleTreeNodeDto();
    dto.setName(getHelper().createName());
    dto.setRole(getHelper().createRole().getId());
    dto.setTreeNode(getHelper().createTreeNode().getId());
    dto.setRecursionType(RecursionType.NO);
    // 
    return dto;
}
Also used : IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)

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