Search in sources :

Example 21 with RoleRequestEvent

use of eu.bcvsolutions.idm.core.model.event.RoleRequestEvent in project CzechIdMng by bcvsolutions.

the class IdentityContractCreateByAutomaticRoleProcessor method process.

@Override
public EventResult<IdmIdentityContractDto> process(EntityEvent<IdmIdentityContractDto> event) {
    IdmIdentityContractDto contract = event.getContent();
    // flag can be processed afterwards
    if (getBooleanProperty(AutomaticRoleManager.SKIP_RECALCULATION, event.getProperties())) {
        LOG.debug("Automatic roles are skipped for contract [{}], state [AUTOMATIC_ROLE_SKIPPED] for position will be created only.", contract.getId());
        // 
        entityStateManager.createState(contract, OperationState.BLOCKED, CoreResultCode.AUTOMATIC_ROLE_SKIPPED, null);
        // 
        return new DefaultEventResult<>(event, this);
    }
    // get related automatic roles
    Set<IdmRoleTreeNodeDto> automaticRoles = roleTreeNodeService.getAutomaticRolesByTreeNode(contract.getWorkPosition());
    if (automaticRoles.isEmpty()) {
        return new DefaultEventResult<>(event, this);
    }
    // assign automatic roles by role request
    List<IdmConceptRoleRequestDto> concepts = automaticRoles.stream().map(autoRole -> {
        IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
        conceptRoleRequest.setIdentityContract(contract.getId());
        conceptRoleRequest.setValidFrom(contract.getValidFrom());
        conceptRoleRequest.setValidTill(contract.getValidTill());
        conceptRoleRequest.setRole(autoRole.getRole());
        conceptRoleRequest.setAutomaticRole(autoRole.getId());
        conceptRoleRequest.setOperation(ConceptRoleRequestOperation.ADD);
        // 
        return conceptRoleRequest;
    }).collect(Collectors.toList());
    // 
    IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
    roleRequest.setConceptRoles(concepts);
    roleRequest.setApplicant(contract.getIdentity());
    roleRequest = roleRequestService.startConcepts(new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest), event);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmRoleTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmRoleTreeNodeService) Autowired(org.springframework.beans.factory.annotation.Autowired) CoreEventProcessor(eu.bcvsolutions.idm.core.api.event.CoreEventProcessor) IdentityContractProcessor(eu.bcvsolutions.idm.core.api.event.processor.IdentityContractProcessor) AutomaticRoleManager(eu.bcvsolutions.idm.core.api.service.AutomaticRoleManager) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) EntityStateManager(eu.bcvsolutions.idm.core.api.service.EntityStateManager) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Description(org.springframework.context.annotation.Description) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdentityContractEventType(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent.IdentityContractEventType) Set(java.util.Set) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Collectors(java.util.stream.Collectors) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) List(java.util.List) Component(org.springframework.stereotype.Component) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) RoleRequestEventType(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent.RoleRequestEventType) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)

Example 22 with RoleRequestEvent

use of eu.bcvsolutions.idm.core.model.event.RoleRequestEvent in project CzechIdMng by bcvsolutions.

the class IdentityContractUpdateByAutomaticRoleProcessor method process.

@Override
public EventResult<IdmIdentityContractDto> process(EntityEvent<IdmIdentityContractDto> event) {
    IdmIdentityContractDto contract = event.getContent();
    IdmIdentityContractDto previous = event.getOriginalSource();
    UUID previousPosition = previous == null ? null : previous.getWorkPosition();
    UUID newPosition = contract.getWorkPosition();
    boolean validityChangedToValid = previous == null ? false : contract.isValidNowOrInFuture() && previous.isValidNowOrInFuture() != contract.isValidNowOrInFuture();
    IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
    // flag can be processed afterwards
    if (getBooleanProperty(AutomaticRoleManager.SKIP_RECALCULATION, event.getProperties())) {
        LOG.debug("Automatic roles are skipped for contract [{}], state [{}] " + "for position will be created only.", contract.getId(), CoreResultCode.AUTOMATIC_ROLE_SKIPPED.getCode());
        // 
        Map<String, Serializable> properties = new HashMap<>();
        // original contract as property
        properties.put(EntityEvent.EVENT_PROPERTY_ORIGINAL_SOURCE, event.getOriginalSource());
        entityStateManager.createState(contract, OperationState.BLOCKED, contract.isValidNowOrInFuture() ? CoreResultCode.AUTOMATIC_ROLE_SKIPPED : CoreResultCode.AUTOMATIC_ROLE_SKIPPED_INVALID_CONTRACT, properties);
        // 
        return new DefaultEventResult<>(event, this);
    }
    if (!contract.isValidNowOrInFuture()) {
        // but we need to add skipped flag above, even when invalid contract is updated
        return new DefaultEventResult<>(event, this);
    }
    // 
    if (previous == null || !Objects.equals(newPosition, previousPosition) || validityChangedToValid) {
        // work positions has some difference or validity changes
        List<IdmIdentityRoleDto> assignedRoles = getAssignedAutomaticRoles(contract.getId());
        // remove all automatic roles by attribute and by other contract position
        if (!assignedRoles.isEmpty()) {
            assignedRoles = assignedRoles.stream().filter(autoRole -> {
                // remove automatic roles by attribute - solved by different process
                AbstractIdmAutomaticRoleDto automaticRoleDto = DtoUtils.getEmbedded(autoRole, IdmIdentityRole_.automaticRole, (AbstractIdmAutomaticRoleDto) null);
                if (automaticRoleDto instanceof IdmRoleTreeNodeDto) {
                    return true;
                }
                return false;
            }).filter(identityRole -> {
                // remove automatic roles by attribute - solved by different process
                return identityRole.getContractPosition() == null;
            }).collect(Collectors.toList());
        }
        // 
        Set<UUID> previousAutomaticRoles = assignedRoles.stream().filter(identityRole -> {
            return identityRole.getAutomaticRole() != null;
        }).map(identityRole -> {
            return identityRole.getAutomaticRole();
        }).collect(Collectors.toSet());
        Set<IdmRoleTreeNodeDto> addedAutomaticRoles = new HashSet<>();
        if (newPosition != null && contract.isValidNowOrInFuture()) {
            addedAutomaticRoles = roleTreeNodeService.getAutomaticRolesByTreeNode(newPosition);
        }
        // prevent to remove newly added or still exists roles
        Set<UUID> removedAutomaticRoles = new HashSet<>(previousAutomaticRoles);
        removedAutomaticRoles.removeAll(addedAutomaticRoles.stream().map(IdmRoleTreeNodeDto::getId).collect(Collectors.toList()));
        addedAutomaticRoles.removeIf(a -> {
            return previousAutomaticRoles.contains(a.getId());
        });
        // 
        for (UUID removedAutomaticRole : removedAutomaticRoles) {
            Iterator<IdmIdentityRoleDto> iter = assignedRoles.iterator();
            while (iter.hasNext()) {
                IdmIdentityRoleDto identityRole = iter.next();
                if (Objects.equals(identityRole.getAutomaticRole(), removedAutomaticRole)) {
                    // check, if role will be added by new automatic roles and prevent removing
                    IdmRoleTreeNodeDto addedAutomaticRole = getByRole(identityRole.getRole(), addedAutomaticRoles);
                    if (addedAutomaticRole == null) {
                        // remove assigned role
                        IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
                        conceptRoleRequest.setIdentityRole(identityRole.getId());
                        conceptRoleRequest.setRole(identityRole.getRole());
                        conceptRoleRequest.setOperation(ConceptRoleRequestOperation.REMOVE);
                        // 
                        roleRequest.getConceptRoles().add(conceptRoleRequest);
                        iter.remove();
                    } else {
                        // change relation only
                        IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
                        conceptRoleRequest.setIdentityRole(identityRole.getId());
                        conceptRoleRequest.setAutomaticRole(addedAutomaticRole.getId());
                        conceptRoleRequest.setIdentityContract(contract.getId());
                        conceptRoleRequest.setValidFrom(contract.getValidFrom());
                        conceptRoleRequest.setValidTill(contract.getValidTill());
                        conceptRoleRequest.setRole(identityRole.getRole());
                        conceptRoleRequest.setOperation(ConceptRoleRequestOperation.UPDATE);
                        // 
                        roleRequest.getConceptRoles().add(conceptRoleRequest);
                        // 
                        // new automatic role is not needed
                        addedAutomaticRoles.remove(addedAutomaticRole);
                    }
                }
            }
        }
        // change date - for unchanged assigned roles only
        if (previous != null && EntityUtils.validableChanged(previous, contract)) {
            roleRequest.getConceptRoles().addAll(changeValidable(contract, assignedRoles));
        }
        // add identity roles
        for (AbstractIdmAutomaticRoleDto autoRole : addedAutomaticRoles) {
            IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
            conceptRoleRequest.setIdentityContract(contract.getId());
            conceptRoleRequest.setValidFrom(contract.getValidFrom());
            conceptRoleRequest.setValidTill(contract.getValidTill());
            conceptRoleRequest.setRole(autoRole.getRole());
            conceptRoleRequest.setAutomaticRole(autoRole.getId());
            conceptRoleRequest.setOperation(ConceptRoleRequestOperation.ADD);
            // 
            roleRequest.getConceptRoles().add(conceptRoleRequest);
        }
        // contract is enabled => process all contract positions
        if (validityChangedToValid) {
            IdmContractPositionFilter filter = new IdmContractPositionFilter();
            filter.setIdentityContractId(contract.getId());
            // 
            for (IdmContractPositionDto position : contractPositionService.find(filter, null).getContent()) {
                CoreEvent<IdmContractPositionDto> positionEvent = new CoreEvent<>(CoreEventType.NOTIFY, position);
                // we don't need the second asynchronicity
                positionEvent.setPriority(PriorityType.IMMEDIATE);
                positionEvent.getProperties().put(EVENT_PROPERTY_REQUEST, roleRequest);
                // recount automatic roles for given position
                EventContext<IdmContractPositionDto> context = contractPositionService.publish(positionEvent, event);
                // get modified prepared request
                if (context.getLastResult() != null) {
                    roleRequest = (IdmRoleRequestDto) context.getLastResult().getEvent().getProperties().get(EVENT_PROPERTY_REQUEST);
                }
            }
        }
    } else if (previous != null && EntityUtils.validableChanged(previous, contract)) {
        // process validable change only
        roleRequest.getConceptRoles().addAll(changeValidable(contract, getAssignedAutomaticRoles(contract.getId())));
    }
    // start request at end asynchronously
    roleRequest.setApplicant(contract.getIdentity());
    RoleRequestEvent requestEvent = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest);
    roleRequestService.startConcepts(requestEvent, event);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmContractPositionService(eu.bcvsolutions.idm.core.api.service.IdmContractPositionService) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmIdentityRole_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole_) IdmRoleTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmRoleTreeNodeService) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) CoreEventProcessor(eu.bcvsolutions.idm.core.api.event.CoreEventProcessor) IdentityContractProcessor(eu.bcvsolutions.idm.core.api.event.processor.IdentityContractProcessor) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AutomaticRoleManager(eu.bcvsolutions.idm.core.api.service.AutomaticRoleManager) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) EntityStateManager(eu.bcvsolutions.idm.core.api.service.EntityStateManager) IdmContractPositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) Map(java.util.Map) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Description(org.springframework.context.annotation.Description) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) Iterator(java.util.Iterator) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdentityContractEventType(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent.IdentityContractEventType) Set(java.util.Set) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) EventContext(eu.bcvsolutions.idm.core.api.event.EventContext) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) Serializable(java.io.Serializable) Objects(java.util.Objects) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) List(java.util.List) Component(org.springframework.stereotype.Component) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) RoleRequestEventType(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent.RoleRequestEventType) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) Serializable(java.io.Serializable) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) HashMap(java.util.HashMap) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) UUID(java.util.UUID) HashSet(java.util.HashSet) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) IdmContractPositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)

Example 23 with RoleRequestEvent

use of eu.bcvsolutions.idm.core.model.event.RoleRequestEvent in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleRequestService method startRequest.

@Override
@Transactional
public IdmRoleRequestDto startRequest(UUID requestId, boolean checkRight) {
    Assert.notNull(requestId, "Role request ID is required!");
    // Load request ... check right for read
    IdmRoleRequestDto request = get(requestId, new IdmRoleRequestFilter(true));
    Assert.notNull(request, "Role request DTO is required!");
    // 
    Map<String, Serializable> variables = new HashMap<>();
    variables.put(RoleRequestApprovalProcessor.CHECK_RIGHT_PROPERTY, checkRight);
    RoleRequestEvent event = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, request, variables);
    // 
    return startRequest(event);
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with RoleRequestEvent

use of eu.bcvsolutions.idm.core.model.event.RoleRequestEvent in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleRequestService method refreshSystemState.

@Override
@Transactional
public IdmRoleRequestDto refreshSystemState(IdmRoleRequestDto request) {
    Assert.notNull(request, "Role request cannot be null!");
    RoleRequestEvent requestEvent = new RoleRequestEvent(RoleRequestEventType.REFRESH_SYSTEM_STATE, request);
    this.publish(requestEvent);
    return requestEvent.getContent();
}
Also used : RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with RoleRequestEvent

use of eu.bcvsolutions.idm.core.model.event.RoleRequestEvent in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleRequestService method startRequestInternal.

@Override
@Transactional
public IdmRoleRequestDto startRequestInternal(UUID requestId, boolean checkRight, boolean immediate) {
    LOG.debug("Start role request [{}], checkRight [{}], immediate [{}]", requestId, checkRight, immediate);
    Assert.notNull(requestId, "Role request ID is required!");
    // Load request ... check right for read
    IdmRoleRequestDto request = get(requestId);
    Assert.notNull(request, "Role request DTO is required!");
    // 
    // Throw event.
    Map<String, Serializable> properties = new HashMap<>();
    properties.put(RoleRequestApprovalProcessor.CHECK_RIGHT_PROPERTY, checkRight);
    RoleRequestEvent event = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, request, properties);
    if (immediate) {
        event.setPriority(PriorityType.IMMEDIATE);
    }
    return startRequestInternal(event);
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

RoleRequestEvent (eu.bcvsolutions.idm.core.model.event.RoleRequestEvent)34 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)33 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)26 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)21 UUID (java.util.UUID)21 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)16 ArrayList (java.util.ArrayList)13 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)12 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)10 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)10 IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)10 Serializable (java.io.Serializable)10 HashMap (java.util.HashMap)10 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)7 ConceptRoleRequestOperation (eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation)6 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)6 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)6 AbstractIdmAutomaticRoleDto (eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto)6 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)6 Transactional (org.springframework.transaction.annotation.Transactional)6