Search in sources :

Example 1 with RequestPredicate

use of eu.bcvsolutions.idm.core.api.service.RequestManager.RequestPredicate 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)

Aggregations

JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)1 RequestOperationType (eu.bcvsolutions.idm.core.api.domain.RequestOperationType)1 RequestState (eu.bcvsolutions.idm.core.api.domain.RequestState)1 Requestable (eu.bcvsolutions.idm.core.api.domain.Requestable)1 AbstractRequestDto (eu.bcvsolutions.idm.core.api.dto.AbstractRequestDto)1 IdmRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestDto)1 IdmRequestItemDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto)1 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)1 IdmRequestItemFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestItemFilter)1 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)1 AbstractReadWriteDtoService (eu.bcvsolutions.idm.core.api.service.AbstractReadWriteDtoService)1 ConfidentialStorage (eu.bcvsolutions.idm.core.api.service.ConfidentialStorage)1 IdmRequestItemService (eu.bcvsolutions.idm.core.api.service.IdmRequestItemService)1 LookupService (eu.bcvsolutions.idm.core.api.service.LookupService)1 RequestManager (eu.bcvsolutions.idm.core.api.service.RequestManager)1 RequestPredicate (eu.bcvsolutions.idm.core.api.service.RequestManager.RequestPredicate)1