Search in sources :

Example 6 with IdmAutomaticRoleAttributeRuleFilter

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

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

the class DefaultIdmAutomaticRoleAttributeRuleService method deleteAllByAttribute.

@Override
public void deleteAllByAttribute(UUID attributeId) {
    IdmAutomaticRoleAttributeRuleFilter filter = new IdmAutomaticRoleAttributeRuleFilter();
    filter.setAutomaticRoleAttributeId(attributeId);
    this.find(filter, null).forEach(rule -> this.deleteRuleWithSkipCheckLastRule(rule));
}
Also used : IdmAutomaticRoleAttributeRuleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter)

Example 8 with IdmAutomaticRoleAttributeRuleFilter

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

the class DefaultIdmAutomaticRoleAttributeRuleService method findAllRulesForAutomaticRole.

@Override
public List<IdmAutomaticRoleAttributeRuleDto> findAllRulesForAutomaticRole(UUID automaticRole) {
    IdmAutomaticRoleAttributeRuleFilter filter = new IdmAutomaticRoleAttributeRuleFilter();
    filter.setAutomaticRoleAttributeId(automaticRole);
    return this.find(filter, null).getContent();
}
Also used : IdmAutomaticRoleAttributeRuleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter)

Aggregations

IdmAutomaticRoleAttributeRuleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter)8 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)5 IdmAutomaticRoleAttributeRuleDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto)5 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)4 Test (org.junit.Test)4 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)3 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)3 IdmAutomaticRoleAttributeRuleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto)2 Lists (com.google.common.collect.Lists)1 AutomaticRoleRequestType (eu.bcvsolutions.idm.core.api.domain.AutomaticRoleRequestType)1 RequestOperationType (eu.bcvsolutions.idm.core.api.domain.RequestOperationType)1 RequestState (eu.bcvsolutions.idm.core.api.domain.RequestState)1 AbstractIdmAutomaticRoleDto (eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto)1 IdmAutomaticRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto)1 IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)1 IdmAutomaticRoleAttributeRuleRequestFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleRequestFilter)1 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)1 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 AutomaticRoleManager (eu.bcvsolutions.idm.core.api.service.AutomaticRoleManager)1