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);
});
}
}
}
Aggregations