@Override public void delete(String id) { if (id == null) return; Resource resource = findById(id, null); if (resource == null) return; cache.invalidateObject(id); invalidationEvents.add(ResourceRemovedEvent.create(id, resource.getName(), resource.getType(), resource.getUris(), resource.getOwner(), resource.getScopes().stream().map(scope -> scope.getId()).collect(Collectors.toSet()), resource.getResourceServer().getId())); cache.resourceRemoval(id, resource.getName(), resource.getType(), resource.getUris(), resource.getOwner(), resource.getScopes().stream().map(scope -> scope.getId()).collect(Collectors.toSet()), resource.getResourceServer().getId(), invalidations); getResourceStoreDelegate().delete(id); }
public CachedResource(Long revision, Resource resource) { super(revision, resource.getId()); this.name = resource.getName(); this.displayName = resource.getDisplayName(); this.type = resource.getType(); this.owner = resource.getOwner(); this.iconUri = resource.getIconUri(); this.resourceServerId = resource.getResourceServer().getId(); ownerManagedAccess = resource.isOwnerManagedAccess(); if (resource.isFetched("uris")) { Set<String> data = new HashSet<>(resource.getUris()); this.uris = source -> data; } else { this.uris = new DefaultLazyLoader<>(source -> new HashSet<>(source.getUris()), Collections::emptySet); } if (resource.isFetched("scopes")) { Set<String> data = resource.getScopes().stream().map(Scope::getId).collect(Collectors.toSet()); this.scopesIds = source -> data; } else { this.scopesIds = new DefaultLazyLoader<>(source -> source.getScopes().stream().map(Scope::getId).collect(Collectors.toSet()), Collections::emptySet); } if (resource.isFetched("attributes")) { MultivaluedHashMap<String, String> data = new MultivaluedHashMap<>(resource.getAttributes()); this.attributes = source -> data; } else { this.attributes = new DefaultLazyLoader<>(source -> new MultivaluedHashMap<>(source.getAttributes()), MultivaluedHashMap::new); } }