Search in sources :

Example 21 with IdmRequestDto

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

the class DefaultRequestManager method findRelatedAddedItems.

/**
 * Find related added DTOs by given parents. !!Searching of added DTOs are very
 * naive!! We use all UUID value in the filter and try to find it in the DTOs.
 * It means only equals is implemented.
 *
 * @param request
 * @param predicates
 * @param items
 * @param dtoClass
 * @return
 */
private <R extends Requestable> List<R> findRelatedAddedItems(IdmRequestDto request, List<RequestPredicate> predicates, List<IdmRequestItemDto> items, Class<? extends R> dtoClass) {
    List<R> requestables = new ArrayList<>();
    // 
    items.stream().filter(// 
    i -> RequestOperationType.ADD == i.getOperation()).forEach(item -> {
        // 
        try {
            R requestedDto = this.convertItemToDto(item, dtoClass);
            AbstractDto requested = (AbstractDto) requestedDto;
            addEmbedded(requested, request.getId());
            addRequestItemToDto((Requestable) requested, item);
            requestables.add((R) requestedDto);
            return;
        } catch (IOException | ReflectiveOperationException | IllegalArgumentException | IntrospectionException e) {
            throw new ResultCodeException(CoreResultCode.JSON_CANNOT_BE_CONVERT_TO_DTO, ImmutableMap.of("json", item.getData()), e);
        }
    });
    return filterDtosByPredicates(requestables, dtoClass, predicates);
}
Also used : DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) Map(java.util.Map) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) PageRequest(org.springframework.data.domain.PageRequest) Page(org.springframework.data.domain.Page) IntrospectionException(java.beans.IntrospectionException) Serializable(java.io.Serializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) PropertyDescriptor(java.beans.PropertyDescriptor) Builder(eu.bcvsolutions.idm.core.api.dto.OperationResultDto.Builder) Lazy(org.springframework.context.annotation.Lazy) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) RequestOperationType(eu.bcvsolutions.idm.core.api.domain.RequestOperationType) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Introspector(java.beans.Introspector) Strings(com.google.common.base.Strings) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) Lists(com.google.common.collect.Lists) BaseEntity(eu.bcvsolutions.idm.core.api.entity.BaseEntity) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) Service(org.springframework.stereotype.Service) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) IOException(java.io.IOException) Field(java.lang.reflect.Field) BaseFilter(eu.bcvsolutions.idm.core.api.dto.filter.BaseFilter) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestItemService(eu.bcvsolutions.idm.core.api.service.IdmRequestItemService) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) FormValueService(eu.bcvsolutions.idm.core.eav.api.service.FormValueService) RequestEventType(eu.bcvsolutions.idm.core.model.event.RequestEvent.RequestEventType) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) Embedded(eu.bcvsolutions.idm.core.api.domain.Embedded) RequestEvent(eu.bcvsolutions.idm.core.model.event.RequestEvent) RequestState(eu.bcvsolutions.idm.core.api.domain.RequestState) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Pageable(org.springframework.data.domain.Pageable) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.ReadWriteDtoService) RequestManager(eu.bcvsolutions.idm.core.api.service.RequestManager) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) ExceptionUtils(eu.bcvsolutions.idm.core.api.utils.ExceptionUtils) Modifier(java.lang.reflect.Modifier) Entry(java.util.Map.Entry) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) RoleRequestApprovalProcessor(eu.bcvsolutions.idm.core.model.event.processor.role.RoleRequestApprovalProcessor) PageImpl(org.springframework.data.domain.PageImpl) IdmRequestService(eu.bcvsolutions.idm.core.api.service.IdmRequestService) FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity) IdmRequestItem(eu.bcvsolutions.idm.core.model.entity.IdmRequestItem) HashMap(java.util.HashMap) MessageFormat(java.text.MessageFormat) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) ReadDtoService(eu.bcvsolutions.idm.core.api.service.ReadDtoService) RequestFilterPredicate(eu.bcvsolutions.idm.core.api.domain.RequestFilterPredicate) ImmutableList(com.google.common.collect.ImmutableList) CollectionUtils(org.apache.commons.collections.CollectionUtils) Propagation(org.springframework.transaction.annotation.Propagation) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) Qualifier(org.springframework.beans.factory.annotation.Qualifier) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) Niceable(eu.bcvsolutions.idm.core.api.domain.Niceable) IdmRequestItemFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestItemFilter) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) IdmRequestAttributeValueDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestAttributeValueDto) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IdmRequestItemChangesDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto) MethodDescriptor(java.beans.MethodDescriptor) ApplicationContext(org.springframework.context.ApplicationContext) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) IdmRequestItemAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemAttributeDto) Comparator(java.util.Comparator) IdmRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) ArrayList(java.util.ArrayList) IntrospectionException(java.beans.IntrospectionException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IOException(java.io.IOException)

Example 22 with IdmRequestDto

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

the class DefaultRequestManager method post.

private <R extends Requestable> R post(Serializable requestId, R dto, boolean isNew) {
    Assert.notNull(dto, "DTO is required!");
    Assert.notNull(requestId, "Request ID is required!");
    IdmRequestDto request = requestService.get(requestId);
    Assert.notNull(request, "Request is required!");
    // update existing item
    if (request != null && !(RequestState.CONCEPT == request.getState() || RequestState.IN_PROGRESS == request.getState() || RequestState.EXCEPTION == request.getState())) {
        throw new ResultCodeException(CoreResultCode.REQUEST_ITEM_CANNOT_BE_CREATED, ImmutableMap.of("dto", dto.toString(), "state", request.getState().name()));
    }
    // Exists item for same original owner?
    IdmRequestItemDto item = this.findRequestItem(request.getId(), dto);
    try {
        if (dto.getId() == null) {
            dto.setId(UUID.randomUUID());
        }
        if (item == null) {
            item = createRequestItem(request.getId(), dto);
            item.setOperation(isNew ? RequestOperationType.ADD : RequestOperationType.UPDATE);
            item.setOwnerId((UUID) dto.getId());
        } else {
            item.setOperation(isNew ? RequestOperationType.ADD : RequestOperationType.UPDATE);
        }
        String dtoString = this.convertDtoToString(dto);
        item.setData(dtoString);
        // Update or create new request item
        item = requestItemService.save(item);
        return this.get(request.getId(), dto);
    } catch (JsonProcessingException e) {
        throw new ResultCodeException(CoreResultCode.DTO_CANNOT_BE_CONVERT_TO_JSON, ImmutableMap.of("dto", dto.toString()), e);
    }
}
Also used : IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 23 with IdmRequestDto

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

the class DefaultRequestManager method createRequest.

@Override
@Transactional
public <R extends Requestable> IdmRequestDto createRequest(R dto, BasePermission... permission) {
    Assert.notNull(dto, "DTO is required!");
    boolean createNew = false;
    if (dto.getId() == null) {
        dto.setId(UUID.randomUUID());
        createNew = true;
    }
    IdmRequestDto request = new IdmRequestDto();
    // I need set creator id here, because is checked in the SelfRequestEvaluator
    request.setCreatorId(securityService.getCurrentId());
    initRequest(request, dto);
    // Create request
    request = requestService.save(request, permission);
    // Create item
    if (createNew) {
        this.post(request.getId(), dto, permission);
    }
    return request;
}
Also used : IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with IdmRequestDto

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

the class DefaultRequestManager method startRequest.

@Override
@Transactional
public IdmRequestDto startRequest(UUID requestId, boolean checkRight) {
    IdmRequestDto request = requestService.get(requestId);
    Assert.notNull(request, "Request is required!");
    try {
        RequestManager service = this.getRequestManager();
        if (!(service instanceof DefaultRequestManager)) {
            throw new CoreException("We expects instace of DefaultRequestManager!");
        }
        return ((DefaultRequestManager) service).startRequestNewTransactional(requestId, checkRight);
    } catch (Exception ex) {
        LOG.error(ex.getLocalizedMessage(), ex);
        request = requestService.get(requestId);
        Throwable exceptionToLog = ExceptionUtils.resolveException(ex);
        if (exceptionToLog instanceof ResultCodeException) {
            // 
            request.setResult(new // 
            OperationResultDto.Builder(// 
            OperationState.EXCEPTION).setException(// 
            (ResultCodeException) exceptionToLog).build());
        } else {
            // 
            request.setResult(new // 
            OperationResultDto.Builder(// 
            OperationState.EXCEPTION).setCause(// 
            exceptionToLog).build());
        }
        request.setState(RequestState.EXCEPTION);
        return requestService.save(request);
    }
}
Also used : RequestManager(eu.bcvsolutions.idm.core.api.service.RequestManager) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) Builder(eu.bcvsolutions.idm.core.api.dto.OperationResultDto.Builder) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IOException(java.io.IOException) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with IdmRequestDto

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

the class DefaultRequestManager method startRequestInternal.

@Override
@Transactional
public IdmRequestDto startRequestInternal(UUID requestId, boolean checkRight) {
    LOG.debug("Start role request [{}]", requestId);
    Assert.notNull(requestId, "Role request ID is required!");
    // Load request ... check right for read
    IdmRequestDto request = requestService.get(requestId);
    Assert.notNull(request, "Role request DTO is required!");
    Assert.isTrue(RequestState.CONCEPT == request.getState() || RequestState.DUPLICATED == request.getState() || RequestState.EXCEPTION == request.getState(), "Only role request with CONCEPT or EXCEPTION or DUPLICATED state can be started!");
    // Request will be set on in progress state
    request.setState(RequestState.IN_PROGRESS);
    request.setResult(new OperationResultDto.Builder(OperationState.RUNNING).build());
    IdmRequestDto savedRequest = requestService.save(request);
    // Throw event
    Map<String, Serializable> variables = new HashMap<>();
    variables.put(RoleRequestApprovalProcessor.CHECK_RIGHT_PROPERTY, checkRight);
    return entityEventManager.process(new RequestEvent(RequestEventType.EXECUTE, savedRequest, variables)).getContent();
}
Also used : Serializable(java.io.Serializable) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Builder(eu.bcvsolutions.idm.core.api.dto.OperationResultDto.Builder) RequestEvent(eu.bcvsolutions.idm.core.model.event.RequestEvent) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestDto)47 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)25 Test (org.junit.Test)24 Requestable (eu.bcvsolutions.idm.core.api.domain.Requestable)23 IdmRequestItemDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto)23 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)18 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)18 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)13 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)11 UUID (java.util.UUID)11 IdmRequestItemChangesDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto)9 Transactional (org.springframework.transaction.annotation.Transactional)9 RequestState (eu.bcvsolutions.idm.core.api.domain.RequestState)8 IdmRequestItemAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemAttributeDto)8 IdmRequestFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter)8 IdmRequestService (eu.bcvsolutions.idm.core.api.service.IdmRequestService)8 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)8 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)8 Lists (com.google.common.collect.Lists)7 IdmRequestItemService (eu.bcvsolutions.idm.core.api.service.IdmRequestItemService)7