Search in sources :

Example 1 with IdmAutomaticRoleRequestDto

use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto 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 2 with IdmAutomaticRoleRequestDto

use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto 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 3 with IdmAutomaticRoleRequestDto

use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto 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 4 with IdmAutomaticRoleRequestDto

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

the class DefaultIdmAutomaticRoleRequestService method startApprovalProcess.

@Override
@Transactional
public boolean startApprovalProcess(IdmAutomaticRoleRequestDto request, boolean checkRight, EntityEvent<IdmAutomaticRoleRequestDto> event, String wfDefinition) {
    // and do realization immediately (without start approval process)
    if (request.isExecuteImmediately()) {
        boolean haveRightExecuteImmediately = securityService.hasAnyAuthority(CoreGroupPermission.AUTOMATIC_ROLE_REQUEST_ADMIN);
        if (checkRight && !haveRightExecuteImmediately) {
            throw new RoleRequestException(CoreResultCode.ROLE_REQUEST_NO_EXECUTE_IMMEDIATELY_RIGHT, ImmutableMap.of("new", request));
        }
        // Execute request immediately
        return true;
    } else {
        Map<String, Object> variables = new HashMap<>();
        // Minimize size of DTO persisting to WF
        IdmAutomaticRoleRequestDto eventRequest = event.getContent();
        eventRequest.setEmbedded(null);
        variables.put(EntityEvent.EVENT_PROPERTY, event);
        variables.put("approvalForAutomaticRole", Boolean.TRUE);
        ProcessInstance processInstance = workflowProcessInstanceService.startProcess(wfDefinition, IdmRoleDto.class.getSimpleName(), request.getCreator(), request.getCreatorId().toString(), variables);
        // We have to refresh request (maybe was changed in wf process)
        request = this.get(request.getId());
        request.setWfProcessId(processInstance.getProcessInstanceId());
        this.save(request);
    }
    return false;
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) HashMap(java.util.HashMap) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with IdmAutomaticRoleRequestDto

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

the class DefaultIdmAutomaticRoleRequestService method deleteAutomaticRole.

@Override
public void deleteAutomaticRole(AbstractIdmAutomaticRoleDto automaticRole, AutomaticRoleRequestType type) {
    Assert.notNull(automaticRole);
    Assert.notNull(type);
    IdmAutomaticRoleRequestDto request = new IdmAutomaticRoleRequestDto();
    request.setAutomaticRole(automaticRole.getId());
    request.setName(automaticRole.getName());
    request.setRequestType(type);
    request.setOperation(RequestOperationType.REMOVE);
    request.setResult(new OperationResultDto.Builder(OperationState.CREATED).build());
    request = this.save(request);
    this.getIdmAutomaticRoleRequestService().startRequest(request.getId(), true);
}
Also used : IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder)

Aggregations

IdmAutomaticRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto)21 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)13 UUID (java.util.UUID)12 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)10 RoleRequestException (eu.bcvsolutions.idm.core.api.exception.RoleRequestException)10 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)9 IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)8 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)7 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)7 IdmAutomaticRoleAttributeRuleDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto)7 IdmAutomaticRoleAttributeRuleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto)7 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)7 IdmRoleGuaranteeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto)7 Test (org.junit.Test)7 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)6 IdmAutomaticRoleRequestService (eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleRequestService)5 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)5 AutomaticRoleRequestType (eu.bcvsolutions.idm.core.api.domain.AutomaticRoleRequestType)3 RequestOperationType (eu.bcvsolutions.idm.core.api.domain.RequestOperationType)3 RequestState (eu.bcvsolutions.idm.core.api.domain.RequestState)3