Search in sources :

Example 1 with AcceptedException

use of eu.bcvsolutions.idm.core.api.exception.AcceptedException in project CzechIdMng by bcvsolutions.

the class TreeNodeDeleteProcessor method process.

@Override
public EventResult<IdmTreeNodeDto> process(EntityEvent<IdmTreeNodeDto> event) {
    IdmTreeNodeDto treeNode = event.getContent();
    // 
    if (identityContractRepository.countByWorkPosition_Id(treeNode.getId()) > 0) {
        throw new TreeNodeException(CoreResultCode.TREE_NODE_DELETE_FAILED_HAS_CONTRACTS, ImmutableMap.of("treeNode", treeNode.getName()));
    }
    // remove related automatic roles
    IdmRoleTreeNodeFilter filter = new IdmRoleTreeNodeFilter();
    filter.setTreeNodeId(treeNode.getId());
    roleTreeNodeService.find(filter, null).forEach(roleTreeNode -> {
        try {
            roleTreeNodeService.delete(roleTreeNode);
        } catch (AcceptedException ex) {
            throw new TreeNodeException(CoreResultCode.TREE_NODE_DELETE_FAILED_HAS_ROLE, ImmutableMap.of("treeNode", treeNode.getName(), "roleTreeNode", roleTreeNode.getId()));
        }
    });
    // 
    service.deleteInternal(treeNode);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmRoleTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleTreeNodeFilter) TreeNodeException(eu.bcvsolutions.idm.core.exception.TreeNodeException) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException)

Example 2 with AcceptedException

use of eu.bcvsolutions.idm.core.api.exception.AcceptedException in project CzechIdMng by bcvsolutions.

the class DefaultAutomaticRoleManager method createAutomaticRoleByTree.

@Override
public IdmRoleTreeNodeDto createAutomaticRoleByTree(IdmRoleTreeNodeDto automaticRole, boolean executeImmediately) {
    IdmAutomaticRoleRequestDto request = new IdmAutomaticRoleRequestDto();
    request.setOperation(RequestOperationType.ADD);
    request.setRequestType(AutomaticRoleRequestType.TREE);
    request.setExecuteImmediately(executeImmediately);
    request.setName(automaticRole.getName());
    request.setRole(automaticRole.getRole());
    request.setTreeNode(automaticRole.getTreeNode());
    request = roleRequestService.save(request);
    request = roleRequestService.startRequest(request.getId(), true);
    if (RequestState.EXECUTED == request.getState()) {
        UUID createdAutomaticRoleId = request.getAutomaticRole();
        Assert.notNull(createdAutomaticRoleId);
        return roleTreeNodeService.get(request.getAutomaticRole());
    }
    if (RequestState.IN_PROGRESS == request.getState()) {
        throw new AcceptedException(request.getId().toString());
    }
    if (RequestState.EXCEPTION == request.getState()) {
        throw new CoreException(request.getResult().getCause());
    }
    return null;
}
Also used : CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) UUID(java.util.UUID)

Example 3 with AcceptedException

use of eu.bcvsolutions.idm.core.api.exception.AcceptedException in project CzechIdMng by bcvsolutions.

the class DefaultAutomaticRoleManager method createAutomaticRoleByAttribute.

@Override
public IdmAutomaticRoleAttributeDto createAutomaticRoleByAttribute(IdmAutomaticRoleAttributeDto automaticRole, boolean executeImmediately, IdmAutomaticRoleAttributeRuleDto... rules) {
    IdmAutomaticRoleRequestDto request = new IdmAutomaticRoleRequestDto();
    request.setOperation(RequestOperationType.ADD);
    request.setRequestType(AutomaticRoleRequestType.ATTRIBUTE);
    request.setExecuteImmediately(executeImmediately);
    request.setName(automaticRole.getName());
    request.setRole(automaticRole.getRole());
    request = roleRequestService.save(request);
    if (rules != null) {
        for (IdmAutomaticRoleAttributeRuleDto rule : rules) {
            IdmAutomaticRoleAttributeRuleRequestDto ruleRequest = new IdmAutomaticRoleAttributeRuleRequestDto();
            ruleRequest.setRequest(request.getId());
            ruleRequest.setOperation(RequestOperationType.ADD);
            ruleRequest.setAttributeName(rule.getAttributeName());
            ruleRequest.setComparison(rule.getComparison());
            ruleRequest.setType(rule.getType());
            ruleRequest.setFormAttribute(rule.getFormAttribute());
            ruleRequest.setValue(rule.getValue());
            ruleRequest.setRule(rule.getId());
            ruleRequest = ruleRequestService.save(ruleRequest);
        }
    }
    request = roleRequestService.startRequest(request.getId(), true);
    if (RequestState.EXECUTED == request.getState()) {
        UUID createdAutomaticRoleId = request.getAutomaticRole();
        Assert.notNull(createdAutomaticRoleId);
        return automaticRoleAttributeService.get(request.getAutomaticRole());
    }
    if (RequestState.IN_PROGRESS == request.getState()) {
        throw new AcceptedException(request.getId().toString());
    }
    if (RequestState.EXCEPTION == request.getState()) {
        throw new CoreException(request.getResult().getCause());
    }
    return null;
}
Also used : IdmAutomaticRoleAttributeRuleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) UUID(java.util.UUID)

Example 4 with AcceptedException

use of eu.bcvsolutions.idm.core.api.exception.AcceptedException in project CzechIdMng by bcvsolutions.

the class DefaultAutomaticRoleManager method deleteAutomaticRole.

@Override
public void deleteAutomaticRole(AbstractIdmAutomaticRoleDto automaticRole, boolean executeImmediately) {
    Assert.notNull(automaticRole);
    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.startRequest(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 5 with AcceptedException

use of eu.bcvsolutions.idm.core.api.exception.AcceptedException in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleTreeNodeService method save.

/**
 * Publish {@link RoleTreeNodeEvent} only.
 *
 * @see {@link RoleTreeNodeSaveProcessor}
 */
@Override
@Transactional(noRollbackFor = AcceptedException.class)
public IdmRoleTreeNodeDto save(IdmRoleTreeNodeDto roleTreeNode, BasePermission... permission) {
    Assert.notNull(roleTreeNode);
    checkAccess(toEntity(roleTreeNode, null), permission);
    // 
    LOG.debug("Saving automatic role [{}] - [{}] - [{}]", roleTreeNode.getRole(), roleTreeNode.getTreeNode(), roleTreeNode.getRecursionType());
    // 
    if (isNew(roleTreeNode)) {
        // create
        // check if exists same entity for roleId, treeNodeId and recursion type
        IdmRoleTreeNodeFilter filter = new IdmRoleTreeNodeFilter();
        filter.setRoleId(roleTreeNode.getRole());
        filter.setTreeNodeId(roleTreeNode.getTreeNode());
        filter.setRecursionType(roleTreeNode.getRecursionType());
        List<IdmRoleTreeNodeDto> content = this.find(filter, null).getContent();
        if (!content.isEmpty()) {
            throw new ResultCodeException(CoreResultCode.ROLE_TREE_NODE_TYPE_EXISTS, ImmutableMap.of("roleId", roleTreeNode.getRole(), "treeNodeId", roleTreeNode.getTreeNode(), "recursionType", roleTreeNode.getRecursionType()));
        }
        // 
        EventContext<IdmRoleTreeNodeDto> context = entityEventManager.process(new RoleTreeNodeEvent(RoleTreeNodeEventType.CREATE, roleTreeNode));
        if (context.isSuspended()) {
            throw new AcceptedException();
        }
        return context.getContent();
    }
    throw new ResultCodeException(CoreResultCode.METHOD_NOT_ALLOWED, "Automatic role update is not supported");
}
Also used : IdmRoleTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleTreeNodeFilter) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) RoleTreeNodeEvent(eu.bcvsolutions.idm.core.model.event.RoleTreeNodeEvent) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)17 IdmAutomaticRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto)10 UUID (java.util.UUID)10 IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)8 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)7 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)6 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)6 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)5 IdmAutomaticRoleAttributeRuleDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto)5 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)5 IdmRoleGuaranteeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto)5 RoleRequestException (eu.bcvsolutions.idm.core.api.exception.RoleRequestException)5 Test (org.junit.Test)5 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)4 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)3 IdmRoleTreeNodeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleTreeNodeFilter)3 Transactional (org.springframework.transaction.annotation.Transactional)3 IdmAutomaticRoleAttributeRuleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto)2 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)2 RoleTreeNodeEvent (eu.bcvsolutions.idm.core.model.event.RoleTreeNodeEvent)2