Search in sources :

Example 1 with IdmIdentityRole_

use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole_ in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleRequestService method executeRequestInternal.

private IdmRoleRequestDto executeRequestInternal(UUID requestId) {
    Assert.notNull(requestId, "Role request ID is required!");
    IdmRoleRequestDto request = this.get(requestId);
    Assert.notNull(request, "Role request is required!");
    List<IdmConceptRoleRequestDto> concepts = request.getConceptRoles();
    IdmIdentityDto identity = identityService.get(request.getApplicant());
    boolean identityNotSame = concepts.stream().anyMatch(concept -> {
        // get contract dto from embedded map
        IdmIdentityContractDto contract = (IdmIdentityContractDto) concept.getEmbedded().get(IdmConceptRoleRequestService.IDENTITY_CONTRACT_FIELD);
        return !identity.getId().equals(contract.getIdentity());
    });
    if (identityNotSame) {
        throw new RoleRequestException(CoreResultCode.ROLE_REQUEST_APPLICANTS_NOT_SAME, ImmutableMap.of("request", request, "applicant", identity.getUsername()));
    }
    // Create new identity role
    concepts.stream().filter(concept -> {
        return ConceptRoleRequestOperation.ADD == concept.getOperation();
    }).filter(concept -> {
        // approval event disabled)
        return RoleRequestState.APPROVED == concept.getState() || RoleRequestState.CONCEPT == concept.getState();
    }).forEach(concept -> {
        IdmIdentityRoleDto identityRole = new IdmIdentityRoleDto();
        identityRole = identityRoleService.save(convertConceptRoleToIdentityRole(conceptRoleRequestService.get(concept.getId()), identityRole));
        // Save created identity role id
        concept.setIdentityRole(identityRole.getId());
        concept.setState(RoleRequestState.EXECUTED);
        IdmRoleDto roleDto = DtoUtils.getEmbedded(identityRole, IdmIdentityRole_.role, IdmRoleDto.class);
        String message = MessageFormat.format("Role [{0}] was added to applicant. Requested in concept [{1}].", roleDto.getCode(), concept.getId());
        conceptRoleRequestService.addToLog(concept, message);
        conceptRoleRequestService.addToLog(request, message);
        conceptRoleRequestService.save(concept);
    });
    // Update identity role
    concepts.stream().filter(concept -> {
        return ConceptRoleRequestOperation.UPDATE == concept.getOperation();
    }).filter(concept -> {
        // approval event disabled)
        return RoleRequestState.APPROVED == concept.getState() || RoleRequestState.CONCEPT == concept.getState();
    }).forEach(concept -> {
        IdmIdentityRoleDto identityRole = identityRoleService.get(concept.getIdentityRole());
        identityRole = identityRoleService.save(convertConceptRoleToIdentityRole(conceptRoleRequestService.get(concept.getId()), identityRole));
        // Save created identity role id
        concept.setIdentityRole(identityRole.getId());
        concept.setState(RoleRequestState.EXECUTED);
        IdmRoleDto roleDto = DtoUtils.getEmbedded(identityRole, IdmIdentityRole_.role, IdmRoleDto.class);
        String message = MessageFormat.format("Role [{0}] was changed. Requested in concept [{1}].", roleDto.getCode(), concept.getId());
        conceptRoleRequestService.addToLog(concept, message);
        conceptRoleRequestService.addToLog(request, message);
        conceptRoleRequestService.save(concept);
    });
    // Delete identity role
    concepts.stream().filter(concept -> {
        return ConceptRoleRequestOperation.REMOVE == concept.getOperation();
    }).filter(concept -> {
        // approval event disabled)
        return RoleRequestState.APPROVED == concept.getState() || RoleRequestState.CONCEPT == concept.getState();
    }).filter(concept -> {
        return concept.getIdentityRole() != null;
    }).forEach(concept -> {
        IdmIdentityRoleDto identityRole = identityRoleService.get(concept.getIdentityRole());
        if (identityRole != null) {
            concept.setState(RoleRequestState.EXECUTED);
            // we have to remove relation on
            concept.setIdentityRole(null);
            // deleted identityRole
            String message = MessageFormat.format("IdentityRole [{0}] (reqested in concept [{1}]) was deleted (from this role request).", identityRole.getId(), concept.getId());
            conceptRoleRequestService.addToLog(concept, message);
            conceptRoleRequestService.addToLog(request, message);
            conceptRoleRequestService.save(concept);
            identityRoleService.delete(identityRole);
        }
    });
    request.setState(RoleRequestState.EXECUTED);
    return this.save(request);
}
Also used : IdmConceptRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmConceptRoleRequestService) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) Predicate(javax.persistence.criteria.Predicate) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) Loggable(eu.bcvsolutions.idm.core.api.domain.Loggable) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmRoleRequest(eu.bcvsolutions.idm.core.model.entity.IdmRoleRequest) UUID(java.util.UUID) Serializable(java.io.Serializable) IdmRoleRequestRepository(eu.bcvsolutions.idm.core.model.repository.IdmRoleRequestRepository) List(java.util.List) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) Optional(java.util.Optional) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) RoleRequestEventType(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent.RoleRequestEventType) RoleRequestApprovalProcessor(eu.bcvsolutions.idm.core.model.event.processor.role.RoleRequestApprovalProcessor) IdmIdentityRole_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole_) IdmRoleRequest_(eu.bcvsolutions.idm.core.model.entity.IdmRoleRequest_) RoleRequestedByType(eu.bcvsolutions.idm.core.api.domain.RoleRequestedByType) HashMap(java.util.HashMap) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) 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) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Root(javax.persistence.criteria.Root) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) DateTime(org.joda.time.DateTime) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Throwables(com.google.common.base.Throwables) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) ApplicationContext(org.springframework.context.ApplicationContext) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) IdmIdentity_(eu.bcvsolutions.idm.core.model.entity.IdmIdentity_) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) AuthorizableType(eu.bcvsolutions.idm.core.security.api.dto.AuthorizableType) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Strings (com.google.common.base.Strings)1 Throwables (com.google.common.base.Throwables)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ConceptRoleRequestOperation (eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation)1 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)1 Loggable (eu.bcvsolutions.idm.core.api.domain.Loggable)1 RoleRequestState (eu.bcvsolutions.idm.core.api.domain.RoleRequestState)1 RoleRequestedByType (eu.bcvsolutions.idm.core.api.domain.RoleRequestedByType)1 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)1 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)1 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)1 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)1 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)1 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)1 IdmRoleRequestFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter)1 EntityEvent (eu.bcvsolutions.idm.core.api.event.EntityEvent)1 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1