Search in sources :

Example 1 with IdmRequestItemFilter

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

the class DefaultRequestManager method findRequestItems.

private List<IdmRequestItemDto> findRequestItems(UUID requestId, Class<? extends Requestable> dtoClass, RequestOperationType operation) {
    IdmRequestItemFilter itemFilter = new IdmRequestItemFilter();
    itemFilter.setRequestId(requestId);
    itemFilter.setOwnerType(dtoClass != null ? dtoClass.getName() : null);
    itemFilter.setOperationType(operation);
    return requestItemService.find(itemFilter, null).getContent();
}
Also used : IdmRequestItemFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestItemFilter)

Example 2 with IdmRequestItemFilter

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

the class DefaultIdmRequestItemService method deleteInternal.

@Override
@Transactional
public void deleteInternal(IdmRequestItemDto dto) {
    if (dto.getId() != null) {
        // We try to find value in the confidential storage and delete it
        String storageKey = RequestManager.getConfidentialStorageKey(dto.getId());
        confidentialStorage.delete(dto, storageKey);
    }
    super.deleteInternal(dto);
    // We have to ensure the referential integrity, because some item (his DTOs) could be child of that item (DTO)
    if (dto.getId() != null && dto.getOwnerId() != null && RequestOperationType.ADD == dto.getOperation()) {
        if (dto.getRequest() != null) {
            IdmRequestItemFilter requestItemFilter = new IdmRequestItemFilter();
            requestItemFilter.setRequestId(dto.getRequest());
            // Find all items
            List<IdmRequestItemDto> items = this.find(requestItemFilter, null).getContent();
            // Create predicate - find all DTOs with that UUID value in any fields
            ImmutableList<RequestPredicate> predicates = ImmutableList.of(new RequestPredicate(dto.getOwnerId(), null));
            List<IdmRequestItemDto> itemsToDelete = // Search items to delete
            items.stream().filter(item -> {
                try {
                    @SuppressWarnings("unchecked") Class<? extends Requestable> ownerType = (Class<? extends Requestable>) Class.forName(item.getOwnerType());
                    Requestable requestable = requestManager.convertItemToDto(item, ownerType);
                    if (requestable == null) {
                        return false;
                    }
                    List<Requestable> filteredDtos = requestManager.filterDtosByPredicates(ImmutableList.of(requestable), ownerType, predicates);
                    return filteredDtos.contains(requestable);
                } catch (ClassNotFoundException | IOException e) {
                    throw new CoreException(e);
                }
            }).collect(Collectors.toList());
            itemsToDelete.forEach(item -> {
                this.delete(item);
            });
        }
    }
}
Also used : RequestOperationType(eu.bcvsolutions.idm.core.api.domain.RequestOperationType) RequestState(eu.bcvsolutions.idm.core.api.domain.RequestState) IdmRequestItem(eu.bcvsolutions.idm.core.model.entity.IdmRequestItem) IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestPredicate(eu.bcvsolutions.idm.core.api.service.RequestManager.RequestPredicate) MessageFormat(java.text.MessageFormat) Strings(com.google.common.base.Strings) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) Predicate(javax.persistence.criteria.Predicate) ImmutableList(com.google.common.collect.ImmutableList) IdmRequestItemRepository(eu.bcvsolutions.idm.core.model.repository.IdmRequestItemRepository) Service(org.springframework.stereotype.Service) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmRequestItem_(eu.bcvsolutions.idm.core.model.entity.IdmRequestItem_) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) IdmRequestItemFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestItemFilter) AbstractReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.AbstractReadWriteDtoService) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) JsonParseException(com.fasterxml.jackson.core.JsonParseException) Root(javax.persistence.criteria.Root) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) WorkflowHistoricProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowHistoricProcessInstanceService) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) Collection(java.util.Collection) RequestManager(eu.bcvsolutions.idm.core.api.service.RequestManager) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) WorkflowHistoricProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto) List(java.util.List) IdmRequestItemService(eu.bcvsolutions.idm.core.api.service.IdmRequestItemService) Lazy(org.springframework.context.annotation.Lazy) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) AbstractRequestDto(eu.bcvsolutions.idm.core.api.dto.AbstractRequestDto) AuthorizableType(eu.bcvsolutions.idm.core.security.api.dto.AuthorizableType) Transactional(org.springframework.transaction.annotation.Transactional) IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmRequestItemFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestItemFilter) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) RequestPredicate(eu.bcvsolutions.idm.core.api.service.RequestManager.RequestPredicate) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with IdmRequestItemFilter

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

the class DefaultIdmRequestService method deleteInternal.

@Override
@Transactional
public void deleteInternal(IdmRequestDto dto) {
    // Stop connected WF process
    cancelWF(dto);
    // We have to delete all items for this request
    if (dto.getId() != null) {
        IdmRequestItemFilter ruleFilter = new IdmRequestItemFilter();
        ruleFilter.setRequestId(dto.getId());
        List<IdmRequestItemDto> items = requestItemService.find(ruleFilter, null).getContent();
        items.forEach(item -> {
            requestItemService.delete(item);
        });
    }
    super.deleteInternal(dto);
}
Also used : IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) IdmRequestItemFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestItemFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with IdmRequestItemFilter

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

the class DefaultRequestManager method findRequestItem.

private <R extends Requestable> IdmRequestItemDto findRequestItem(UUID requestId, UUID dtoId, Class<? extends R> dtoClass) {
    Assert.notNull(dtoClass, "DTO class is required!");
    if (dtoId == null) {
        return null;
    }
    IdmRequestItemFilter itemFilter = new IdmRequestItemFilter();
    itemFilter.setRequestId(requestId);
    itemFilter.setOwnerId(dtoId);
    itemFilter.setOwnerType(dtoClass.getName());
    List<IdmRequestItemDto> items = requestItemService.find(itemFilter, null).getContent();
    if (items.size() > 0) {
        return items.get(0);
    }
    return null;
}
Also used : IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) IdmRequestItemFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestItemFilter)

Example 5 with IdmRequestItemFilter

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

the class DefaultRequestManager method onDeleteRequestable.

@Override
@Transactional
public <R extends Requestable> void onDeleteRequestable(R requestable) {
    Assert.notNull(requestable, "Requestable DTO cannot be null!");
    // Search requests with that deleting owner
    IdmRequestFilter requestFilter = new IdmRequestFilter();
    requestFilter.setOwnerType(requestable.getClass().getName());
    requestFilter.setOwnerId((UUID) requestable.getId());
    List<IdmRequestDto> requests = requestService.find(requestFilter, null).getContent();
    // 
    requests.stream().filter(// We need filtered request which
    request -> RequestState.APPROVED != request.getState()).forEach(request -> {
        // 
        request = changeRequestState(// 
        requestable, // 
        request, new // 
        ResultCodeException(// 
        CoreResultCode.REQUEST_OWNER_WAS_DELETED, // 
        ImmutableMap.of("owner", requestable.toString())));
        requestService.save(request);
    });
    // Search request items with that deleting owner
    IdmRequestItemFilter requestItemFilter = new IdmRequestItemFilter();
    requestItemFilter.setOwnerType(requestable.getClass().getName());
    requestItemFilter.setOwnerId((UUID) requestable.getId());
    List<IdmRequestItemDto> requestItems = requestItemService.find(requestItemFilter, null).getContent();
    // 
    requestItems.stream().filter(// We need filtered request which invoked that
    item -> RequestState.APPROVED != item.getState()).forEach(item -> {
        // 
        item = changeItemState(// 
        requestable, // 
        item, new // 
        ResultCodeException(// 
        CoreResultCode.REQUEST_OWNER_WAS_DELETED, // 
        ImmutableMap.of("owner", requestable.toString())));
        requestItemService.save(item);
        IdmRequestItemFilter subItemFilter = new IdmRequestItemFilter();
        subItemFilter.setRequestId(item.getRequest());
        // Search all items for that request
        List<IdmRequestItemDto> subItems = requestItemService.find(subItemFilter, null).getContent();
        // TODO: This can be (maybe) removed ... because that 'cancel' is implemented
        // during realization of item
        // Check if items in same request does not contains same ID of deleting owner in
        // the DATA Json.
        // If yes, then state will be changed to cancel.
        // 
        subItems.stream().filter(// We need filtered request
        subItem -> RequestState.APPROVED != subItem.getState()).filter(// 
        subItem -> !requestable.getId().equals(subItem.getOwnerId())).filter(// 
        subItem -> subItem.getData() != null).filter(subItem -> // 
        subItem.getData().indexOf(requestable.getId().toString()) != // 
        -1).forEach(subItem -> {
            // 
            subItem = changeItemState(// 
            requestable, // 
            subItem, new // 
            ResultCodeException(// 
            CoreResultCode.REQUEST_OWNER_FROM_OTHER_REQUEST_WAS_DELETED, ImmutableMap.of("owner", requestable.toString(), "otherRequest", // 
            subItem.toString())));
            requestItemService.save(subItem);
        });
    });
// 
}
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) IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) IdmRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter) IdmRequestItemFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestItemFilter) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmRequestItemFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestItemFilter)7 IdmRequestItemDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto)5 RequestState (eu.bcvsolutions.idm.core.api.domain.RequestState)3 IdmRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestDto)3 Strings (com.google.common.base.Strings)2 ImmutableList (com.google.common.collect.ImmutableList)2 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)2 RequestOperationType (eu.bcvsolutions.idm.core.api.domain.RequestOperationType)2 Requestable (eu.bcvsolutions.idm.core.api.domain.Requestable)2 IdmRequestItemChangesDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto)2 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)2 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)2 ConfidentialStorage (eu.bcvsolutions.idm.core.api.service.ConfidentialStorage)2 IdmRequestItemService (eu.bcvsolutions.idm.core.api.service.IdmRequestItemService)2 Transactional (org.springframework.transaction.annotation.Transactional)2 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1