Source:
public Entities findSubresources( String entityTypeId, String entityId, String attributeName, @Nullable @CheckForNull Query query, Selection filter, Selection expand, Sort sort, int size, int number) { Repository<Entity> repository = getRepository(entityTypeId); EntityType entityType = repository.getEntityType(); Object typedEntityId = toTypedEntityId(entityType, entityId); Attribute refAttribute = entityType.getAttribute(attributeName); if (refAttribute == null) { throw new UnknownAttributeException(entityType, attributeName); } if (!EntityTypeUtils.isMultipleReferenceType(refAttribute)) { throw new UnsupportedAttributeTypeException(refAttribute); } EntityType refEntityType = refAttribute.getRefEntity(); Fetch refFetch = new Fetch().field(refEntityType.getIdAttribute().getName()); Fetch fetch = new Fetch().field(refAttribute.getName(), refFetch); Entity entity = repository.findOneById(typedEntityId, fetch); List<Object> refEntityIds = StreamSupport.stream(entity.getEntities(attributeName).spliterator(), false) .map(ref -> ref.getIdValue()) .collect(toList()); Repository<Entity> refRepository = getRepository(refEntityType.getId()); org.molgenis.data.Query<Entity> findQuery = query != null ? queryMapperV3.map(query, refRepository) : new QueryImpl<>(refRepository); if (!findQuery.getRules().isEmpty()) { findQuery.and(); } findQuery.in(refEntityType.getIdAttribute().getName(), refEntityIds); return getEntities(filter, expand, sort, size, number, refRepository, findQuery); }

Target:
public Entities findSubresources( String entityTypeId, String entityId, String attributeName, @Nullable @CheckForNull Query query, Selection filter, Selection expand, Sort sort, int size, int number) { Repository<Entity> repository = getRepository(entityTypeId); EntityType entityType = repository.getEntityType(); Object typedEntityId = toTypedEntityId(entityType, entityId); Attribute refAttribute = entityType.getAttribute(attributeName); if (refAttribute == null) { throw new UnknownAttributeException(entityType, attributeName); } if (!EntityTypeUtils.isMultipleReferenceType(refAttribute)) { throw new UnsupportedAttributeTypeException(refAttribute); } EntityType refEntityType = refAttribute.getRefEntity(); Fetch refFetch = new Fetch().field(refEntityType.getIdAttribute().getName()); Fetch fetch = new Fetch().field(refAttribute.getName(), refFetch); Entity entity = repository.findOneById(typedEntityId, fetch); if (entity == null) { throw new UnknownEntityException(refEntityType, typedEntityId); } List<Object> refEntityIds = StreamSupport.stream(entity.getEntities(attributeName).spliterator(), false) .map(Entity::getIdValue) .collect(toList()); Repository<Entity> refRepository = getRepository(refEntityType.getId()); org.molgenis.data.Query<Entity> findQuery = query != null ? queryMapperV3.map(query, refRepository) : new QueryImpl<>(refRepository); QueryImpl<Entity> q = new QueryImpl<>(); if (!findQuery.getRules().isEmpty()) { q.nest(); for (QueryRule rule : findQuery.getRules()) { q.addRule(rule); } q.unnest(); q.and(); } Entities result; if (!refEntityIds.isEmpty()) { q.in(refEntityType.getIdAttribute().getName(), refEntityIds); result = getEntities(filter, expand, sort, size, number, refRepository, q); } else { result = Entities.builder().setEntities(Collections.emptyList()).setTotal(0).build(); } return result; }