Search in sources :

Example 21 with IdmAutomaticRoleAttributeRuleDto

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

the class AutomaticRoleAttributeRuleSaveProcessor method process.

@Override
public EventResult<IdmAutomaticRoleAttributeRuleDto> process(EntityEvent<IdmAutomaticRoleAttributeRuleDto> event) {
    IdmAutomaticRoleAttributeRuleDto dto = event.getContent();
    // 
    dto = automactiRoleAttributeRuleService.saveInternal(dto);
    event.setContent(dto);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto)

Example 22 with IdmAutomaticRoleAttributeRuleDto

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

the class DefaultAutomaticRoleManager method changeAutomaticRoleRules.

@Override
public IdmAutomaticRoleAttributeDto changeAutomaticRoleRules(IdmAutomaticRoleAttributeDto automaticRole, boolean executeImmediately, IdmAutomaticRoleAttributeRuleDto... newRules) {
    Assert.notNull(automaticRole);
    Assert.notNull(automaticRole.getId(), "Automatic role must exists!");
    IdmAutomaticRoleRequestDto request = new IdmAutomaticRoleRequestDto();
    request.setOperation(RequestOperationType.UPDATE);
    request.setRequestType(AutomaticRoleRequestType.ATTRIBUTE);
    request.setExecuteImmediately(executeImmediately);
    request.setAutomaticRole(automaticRole.getId());
    request.setName(automaticRole.getName());
    request.setRole(automaticRole.getRole());
    final IdmAutomaticRoleRequestDto createdRequest = roleRequestService.save(request);
    ArrayList<IdmAutomaticRoleAttributeRuleDto> rules = Lists.newArrayList(newRules);
    if (rules != null) {
        // Creates request for change or add rule
        rules.forEach(rule -> {
            IdmAutomaticRoleAttributeRuleRequestDto ruleRequest = new IdmAutomaticRoleAttributeRuleRequestDto();
            ruleRequest.setRequest(createdRequest.getId());
            ruleRequest.setOperation(rule.getId() != null ? RequestOperationType.UPDATE : 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);
        });
    }
    IdmAutomaticRoleAttributeRuleFilter ruleFilter = new IdmAutomaticRoleAttributeRuleFilter();
    ruleFilter.setAutomaticRoleAttributeId(automaticRole.getId());
    List<IdmAutomaticRoleAttributeRuleDto> currentRules = ruleService.find(ruleFilter, null).getContent();
    currentRules.stream().filter(currentRule -> {
        return rules == null || !rules.contains(currentRule);
    }).forEach(ruleToDelete -> {
        // Creates request for remove rule
        IdmAutomaticRoleAttributeRuleRequestDto ruleRequest = new IdmAutomaticRoleAttributeRuleRequestDto();
        ruleRequest.setRequest(createdRequest.getId());
        ruleRequest.setOperation(RequestOperationType.REMOVE);
        ruleRequest.setAttributeName(ruleToDelete.getAttributeName());
        ruleRequest.setComparison(ruleToDelete.getComparison());
        ruleRequest.setType(ruleToDelete.getType());
        ruleRequest.setFormAttribute(ruleToDelete.getFormAttribute());
        ruleRequest.setValue(ruleToDelete.getValue());
        ruleRequest.setRule(ruleToDelete.getId());
        ruleRequest = ruleRequestService.save(ruleRequest);
    });
    IdmAutomaticRoleRequestDto executedRequest = roleRequestService.startRequestInternal(createdRequest.getId(), true);
    if (RequestState.EXECUTED == executedRequest.getState()) {
        UUID createdAutomaticRoleId = executedRequest.getAutomaticRole();
        Assert.notNull(createdAutomaticRoleId);
        return automaticRoleAttributeService.get(executedRequest.getAutomaticRole());
    }
    if (RequestState.IN_PROGRESS == executedRequest.getState()) {
        throw new AcceptedException(executedRequest.getId().toString());
    }
    if (RequestState.EXCEPTION == executedRequest.getState()) {
        throw new CoreException(executedRequest.getResult().getCause());
    }
    return null;
}
Also used : RequestOperationType(eu.bcvsolutions.idm.core.api.domain.RequestOperationType) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) RequestState(eu.bcvsolutions.idm.core.api.domain.RequestState) IdmRoleTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmRoleTreeNodeService) Autowired(org.springframework.beans.factory.annotation.Autowired) IdmAutomaticRoleAttributeRuleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter) ArrayList(java.util.ArrayList) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) AutomaticRoleManager(eu.bcvsolutions.idm.core.api.service.AutomaticRoleManager) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) IdmAutomaticRoleAttributeRuleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto) Lists(com.google.common.collect.Lists) IdmAutomaticRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleRequestService) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) Service(org.springframework.stereotype.Service) AutomaticRoleRequestType(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleRequestType) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmAutomaticRoleAttributeRuleRequestService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeRuleRequestService) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) UUID(java.util.UUID) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) List(java.util.List) IdmAutomaticRoleAttributeRuleService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeRuleService) IdmAutomaticRoleAttributeService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeService) Assert(org.springframework.util.Assert) 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) IdmAutomaticRoleAttributeRuleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter) UUID(java.util.UUID)

Example 23 with IdmAutomaticRoleAttributeRuleDto

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

the class DefaultIdmAutomaticRoleRequestService method realizeAttributeRules.

/**
 * Execute change of the request for attribute automatic role
 *
 * @param request
 * @param automaticRoleId
 * @param ruleConcepts
 */
private void realizeAttributeRules(IdmAutomaticRoleRequestDto request, IdmAutomaticRoleAttributeDto automaticRole, List<IdmAutomaticRoleAttributeRuleRequestDto> ruleConcepts) {
    // Create new rule
    ruleConcepts.stream().filter(concept -> {
        return RequestOperationType.ADD == concept.getOperation();
    }).forEach(concept -> {
        IdmAutomaticRoleAttributeRuleDto rule = new IdmAutomaticRoleAttributeRuleDto();
        rule.setAutomaticRoleAttribute(automaticRole.getId());
        rule = automaticRoleRuleService.save(convertConceptRuleToRule(concept, rule));
        // Save created identity role id
        concept.setRule(rule.getId());
        automaticRoleRuleRequestService.save(concept);
    });
    // Update rule
    ruleConcepts.stream().filter(concept -> {
        return RequestOperationType.UPDATE == concept.getOperation();
    }).filter(concept -> {
        return concept.getRule() != null;
    }).forEach(concept -> {
        IdmAutomaticRoleAttributeRuleDto rule = automaticRoleRuleService.get(concept.getRule());
        rule = automaticRoleRuleService.save(convertConceptRuleToRule(concept, rule));
        // Save created identity role id
        concept.setRule(rule.getId());
        automaticRoleRuleRequestService.save(concept);
    });
    // Delete rule
    ruleConcepts.stream().filter(concept -> {
        return RequestOperationType.REMOVE == concept.getOperation();
    }).filter(concept -> {
        return concept.getRule() != null;
    }).forEach(concept -> {
        IdmAutomaticRoleAttributeRuleDto rule = automaticRoleRuleService.get(concept.getRule());
        if (rule != null) {
            concept.setRule(rule.getId());
            automaticRoleRuleRequestService.save(concept);
            // Finally delete of the rule
            automaticRoleRuleService.delete(rule);
        }
    });
}
Also used : RequestState(eu.bcvsolutions.idm.core.api.domain.RequestState) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto) Autowired(org.springframework.beans.factory.annotation.Autowired) AutomaticRoleRequestEventType(eu.bcvsolutions.idm.core.model.event.AutomaticRoleRequestEvent.AutomaticRoleRequestEventType) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) IdmAutomaticRoleAttributeRuleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto) Predicate(javax.persistence.criteria.Predicate) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) IdmAutomaticRole_(eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRole_) IdmAutomaticRoleRequest_(eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRoleRequest_) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) ImmutableMap(com.google.common.collect.ImmutableMap) IdmAutomaticRoleAttributeRuleRequestService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeRuleRequestService) Collection(java.util.Collection) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) UUID(java.util.UUID) Serializable(java.io.Serializable) List(java.util.List) IdmAutomaticRoleAttributeRuleService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeRuleService) RoleRequestApprovalProcessor(eu.bcvsolutions.idm.core.model.event.processor.role.RoleRequestApprovalProcessor) IdmAutomaticRoleAttributeService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeService) RequestOperationType(eu.bcvsolutions.idm.core.api.domain.RequestOperationType) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) IdmRoleTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmRoleTreeNodeService) HashMap(java.util.HashMap) IdmAutomaticRoleRequestRepository(eu.bcvsolutions.idm.core.model.repository.IdmAutomaticRoleRequestRepository) IdmRoleTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmRoleTreeNode) Strings(com.google.common.base.Strings) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmAutomaticRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleRequestService) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) AbstractReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.AbstractReadWriteDtoService) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) AutomaticRoleRequestType(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleRequestType) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Root(javax.persistence.criteria.Root) AutomaticRoleRequestEvent(eu.bcvsolutions.idm.core.model.event.AutomaticRoleRequestEvent) IdmRole_(eu.bcvsolutions.idm.core.model.entity.IdmRole_) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Throwables(com.google.common.base.Throwables) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) IdmAutomaticRoleAttributeRuleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleRequestFilter) IdmAutomaticRoleRequest(eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRoleRequest) ApplicationContext(org.springframework.context.ApplicationContext) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) IdmAutomaticRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleRequestFilter) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) IdmAutomaticRoleAttribute(eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRoleAttribute) AuthorizableType(eu.bcvsolutions.idm.core.security.api.dto.AuthorizableType) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto)

Aggregations

IdmAutomaticRoleAttributeRuleDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto)23 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)20 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)15 Test (org.junit.Test)14 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)11 UUID (java.util.UUID)9 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)7 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)7 IdmAutomaticRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto)6 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)6 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)5 IdmAutomaticRoleAttributeRuleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter)5 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)4 RoleRequestException (eu.bcvsolutions.idm.core.api.exception.RoleRequestException)4 AbstractIdmAutomaticRoleDto (eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto)3 IdmAutomaticRoleAttributeRuleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto)3 IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)3 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)3 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)3 AutomaticRoleRequestType (eu.bcvsolutions.idm.core.api.domain.AutomaticRoleRequestType)2