@WithMockUser(username = USERNAME) @Test void findAllQueryUserOffsetLimit() { String entityType0Name = "entity0"; EntityType entityType0 = when(mock(EntityType.class).getId()).thenReturn(entityType0Name).getMock(); String entityType1Name = "entity1"; EntityType entityType1 = when(mock(EntityType.class).getId()).thenReturn(entityType1Name).getMock(); String attr0Name = "entity0attr0"; Attribute attr0 = when(mock(Attribute.class).getName()).thenReturn(attr0Name).getMock(); when(attr0.getEntity()).thenReturn(entityType0); String attr1Name = "entity1attr0"; Attribute attr1 = when(mock(Attribute.class).getName()).thenReturn(attr1Name).getMock(); when(attr1.getEntity()).thenReturn(entityType1); @SuppressWarnings("unchecked") Query<Attribute> q = mock(Query.class); when(q.getOffset()).thenReturn(1); when(q.getPageSize()).thenReturn(1); @SuppressWarnings("unchecked") ArgumentCaptor<Query<Attribute>> queryCaptor = forClass(Query.class); when(delegateRepository.findAll(queryCaptor.capture())).thenReturn(Stream.of(attr0, attr1)); when(permissionService.hasPermission( new EntityTypeIdentity(entityType0Name), EntityTypePermission.READ_METADATA)) .thenReturn(false); when(permissionService.hasPermission( new EntityTypeIdentity(entityType1Name), EntityTypePermission.READ_METADATA)) .thenReturn(true); assertEquals(emptyList(), repo.findAll(q).collect(toList())); assertEquals(0, queryCaptor.getValue().getOffset()); assertEquals(MAX_VALUE, queryCaptor.getValue().getPageSize()); }
@Override public Stream<Attribute> findAll(Query<Attribute> q) { if (currentUserIsSuOrSystem()) { return delegate().findAll(q); } else { Query<Attribute> qWithoutLimitOffset = new QueryImpl<>(q); qWithoutLimitOffset.offset(0).pageSize(Integer.MAX_VALUE); Stream<Attribute> attrs = delegate().findAll(qWithoutLimitOffset); Stream<Attribute> filteredAttrs = filterReadMetadataPermission(attrs); if (q.getOffset() > 0) { filteredAttrs = filteredAttrs.skip(q.getOffset()); } if (q.getPageSize() > 0) { filteredAttrs = filteredAttrs.limit(q.getPageSize()); } return filteredAttrs; } }
AttributeRepositorySecurityDecorator extends AbstractRepositoryDecorator<Attribute> { @Override public Stream<Attribute> findAll(Query<Attribute> q) { if (currentUserIsSuOrSystem()) { return delegate().findAll(q); } else { Query<Attribute> qWithoutLimitOffset = new QueryImpl<>(q); qWithoutLimitOffset.offset(0).pageSize(Integer.MAX_VALUE); Stream<Attribute> attrs = delegate().findAll(qWithoutLimitOffset); Stream<Attribute> filteredAttrs = filterReadMetadataPermission(attrs); if (q.getOffset() > 0) { filteredAttrs = filteredAttrs.skip(q.getOffset()); } if (q.getPageSize() > 0) { filteredAttrs = filteredAttrs.limit(q.getPageSize()); } return filteredAttrs; } } }
AttributeRepositorySecurityDecorator extends AbstractRepositoryDecorator<Attribute> { @Override public Stream<Attribute> findAll(Query<Attribute> q) { if (currentUserIsSuOrSystem()) { return delegate().findAll(q); } else { Query<Attribute> qWithoutLimitOffset = new QueryImpl<>(q); qWithoutLimitOffset.offset(0).pageSize(Integer.MAX_VALUE); Stream<Attribute> attrs = delegate().findAll(qWithoutLimitOffset); Stream<Attribute> filteredAttrs = filterReadMetadataPermission(attrs); if (q.getOffset() > 0) { filteredAttrs = filteredAttrs.skip(q.getOffset()); } if (q.getPageSize() > 0) { filteredAttrs = filteredAttrs.limit(q.getPageSize()); } return filteredAttrs; } } AttributeRepositorySecurityDecorator(
      Repository<Attribute> delegateRepository,
      SystemEntityTypeRegistry systemEntityTypeRegistry,
      UserPermissionEvaluator permissionService); }
AttributeRepositorySecurityDecorator extends AbstractRepositoryDecorator<Attribute> { @Override public Stream<Attribute> findAll(Query<Attribute> q) { if (currentUserIsSuOrSystem()) { return delegate().findAll(q); } else { Query<Attribute> qWithoutLimitOffset = new QueryImpl<>(q); qWithoutLimitOffset.offset(0).pageSize(Integer.MAX_VALUE); Stream<Attribute> attrs = delegate().findAll(qWithoutLimitOffset); Stream<Attribute> filteredAttrs = filterReadMetadataPermission(attrs); if (q.getOffset() > 0) { filteredAttrs = filteredAttrs.skip(q.getOffset()); } if (q.getPageSize() > 0) { filteredAttrs = filteredAttrs.limit(q.getPageSize()); } return filteredAttrs; } } 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 Stream<Attribute> findAll(Query<Attribute> q) { if (currentUserIsSuOrSystem()) { return delegate().findAll(q); } else { Query<Attribute> qWithoutLimitOffset = new QueryImpl<>(q); qWithoutLimitOffset.offset(0).pageSize(Integer.MAX_VALUE); Stream<Attribute> attrs = delegate().findAll(qWithoutLimitOffset); Stream<Attribute> filteredAttrs = filterReadMetadataPermission(attrs); if (q.getOffset() > 0) { filteredAttrs = filteredAttrs.skip(q.getOffset()); } if (q.getPageSize() > 0) { filteredAttrs = filteredAttrs.limit(q.getPageSize()); } return filteredAttrs; } } 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);  }