@WithMockUser(username = USERNAME) @Test void forEachBatchedUser() { List<Attribute> attributes = newArrayList(); Attribute attribute1 = mock(Attribute.class); Attribute attribute2 = mock(Attribute.class); Attribute attribute3 = mock(Attribute.class); Attribute attribute4 = mock(Attribute.class); EntityType entityType1 = mock(EntityType.class); EntityType entityType2 = mock(EntityType.class); EntityType entityType3 = mock(EntityType.class); EntityType entityType4 = mock(EntityType.class); when(attribute1.getEntity()).thenReturn(entityType1); when(attribute2.getEntity()).thenReturn(entityType2); when(attribute3.getEntity()).thenReturn(entityType3); when(attribute4.getEntity()).thenReturn(entityType4); when(entityType1.getId()).thenReturn("EntityType1"); when(entityType2.getId()).thenReturn("EntityType2"); when(entityType3.getId()).thenReturn("EntityType3"); when(entityType4.getId()).thenReturn("EntityType4"); repo.forEachBatched(attributes::addAll, 2); when(permissionService.hasPermission( new EntityTypeIdentity("EntityType1"), EntityTypePermission.READ_METADATA)) .thenReturn(true); when(permissionService.hasPermission( new EntityTypeIdentity("EntityType2"), EntityTypePermission.READ_METADATA)) .thenReturn(false); when(permissionService.hasPermission( new EntityTypeIdentity("EntityType3"), EntityTypePermission.READ_METADATA)) .thenReturn(false); when(permissionService.hasPermission( new EntityTypeIdentity("EntityType4"), EntityTypePermission.READ_METADATA)) .thenReturn(true); verify(delegateRepository).forEachBatched(eq(null), consumerCaptor.capture(), eq(2)); consumerCaptor.getValue().accept(Lists.newArrayList(attribute1, attribute2)); consumerCaptor.getValue().accept(Lists.newArrayList(attribute3, attribute4)); assertEquals(newArrayList(attribute1, attribute4), attributes); }
@Override public void forEachBatched(Fetch fetch, Consumer<List<Attribute>> consumer, int batchSize) { if (currentUserIsSuOrSystem()) { delegate().forEachBatched(fetch, consumer, batchSize); } else { FilteredConsumer filteredConsumer = new FilteredConsumer(consumer); delegate().forEachBatched(fetch, filteredConsumer::filter, batchSize); } }
AttributeRepositorySecurityDecorator extends AbstractRepositoryDecorator<Attribute> { @Override public void forEachBatched(Fetch fetch, Consumer<List<Attribute>> consumer, int batchSize) { if (currentUserIsSuOrSystem()) { delegate().forEachBatched(fetch, consumer, batchSize); } else { FilteredConsumer filteredConsumer = new FilteredConsumer(consumer); delegate().forEachBatched(fetch, filteredConsumer::filter, batchSize); } } }
AttributeRepositorySecurityDecorator extends AbstractRepositoryDecorator<Attribute> { @Override public void forEachBatched(Fetch fetch, Consumer<List<Attribute>> consumer, int batchSize) { if (currentUserIsSuOrSystem()) { delegate().forEachBatched(fetch, consumer, batchSize); } else { FilteredConsumer filteredConsumer = new FilteredConsumer(consumer); delegate().forEachBatched(fetch, filteredConsumer::filter, batchSize); } } AttributeRepositorySecurityDecorator(
      Repository<Attribute> delegateRepository,
      SystemEntityTypeRegistry systemEntityTypeRegistry,
      UserPermissionEvaluator permissionService); }
AttributeRepositorySecurityDecorator extends AbstractRepositoryDecorator<Attribute> { @Override public void forEachBatched(Fetch fetch, Consumer<List<Attribute>> consumer, int batchSize) { if (currentUserIsSuOrSystem()) { delegate().forEachBatched(fetch, consumer, batchSize); } else { FilteredConsumer filteredConsumer = new FilteredConsumer(consumer); delegate().forEachBatched(fetch, filteredConsumer::filter, batchSize); } } AttributeRepositorySecurityDecorator(
      Repository<Attribute> delegateRepository,
      SystemEntityTypeRegistry systemEntityTypeRegistry,
      UserPermissionEvaluator permissionService); @Override long count(); @Override long count(Query<Attribute> q); @Override Stream<Attribute> findAll(Query<Attribute> q); @Override Iterator<Attribute> iterator(); @Override void forEachBatched(Fetch fetch, Consumer<List<Attribute>> consumer, int batchSize); @Override Attribute findOne(Query<Attribute> q); @Override Attribute findOneById(Object id); @Override Attribute findOneById(Object id, Fetch fetch); @Override Stream<Attribute> findAll(Stream<Object> ids); @Override Stream<Attribute> findAll(Stream<Object> ids, Fetch fetch); @Override AggregateResult aggregate(AggregateQuery aggregateQuery); @Override void update(Attribute attr); @Override void update(Stream<Attribute> attrs); @Override void delete(Attribute attr); @Override void delete(Stream<Attribute> attrs); @Override void deleteById(Object id); @Override void deleteAll(Stream<Object> ids); @Override void deleteAll(); @Override void add(Attribute attr); @Override Integer add(Stream<Attribute> attrs); }
AttributeRepositorySecurityDecorator extends AbstractRepositoryDecorator<Attribute> { @Override public void forEachBatched(Fetch fetch, Consumer<List<Attribute>> consumer, int batchSize) { if (currentUserIsSuOrSystem()) { delegate().forEachBatched(fetch, consumer, batchSize); } else { FilteredConsumer filteredConsumer = new FilteredConsumer(consumer); delegate().forEachBatched(fetch, filteredConsumer::filter, batchSize); } } AttributeRepositorySecurityDecorator(
      Repository<Attribute> delegateRepository,
      SystemEntityTypeRegistry systemEntityTypeRegistry,
      UserPermissionEvaluator permissionService); @Override long count(); @Override long count(Query<Attribute> q); @Override Stream<Attribute> findAll(Query<Attribute> q); @Override Iterator<Attribute> iterator(); @Override void forEachBatched(Fetch fetch, Consumer<List<Attribute>> consumer, int batchSize); @Override Attribute findOne(Query<Attribute> q); @Override Attribute findOneById(Object id); @Override Attribute findOneById(Object id, Fetch fetch); @Override Stream<Attribute> findAll(Stream<Object> ids); @Override Stream<Attribute> findAll(Stream<Object> ids, Fetch fetch); @Override AggregateResult aggregate(AggregateQuery aggregateQuery); @Override void update(Attribute attr); @Override void update(Stream<Attribute> attrs); @Override void delete(Attribute attr); @Override void delete(Stream<Attribute> attrs); @Override void deleteById(Object id); @Override void deleteAll(Stream<Object> ids); @Override void deleteAll(); @Override void add(Attribute attr); @Override Integer add(Stream<Attribute> attrs);  }