microsoftgraph / microsoftgraph/msgraph-sdk-java
Improve paging functionality
还没有人认领这个 Issue。
- 主要语言
- Java
- 星标
- 444
- 派生
- 154
- 平均合并
- 18 小时 28 分钟
- 30 天内合并 PR
- 4
描述
Is your feature request related to a problem? Please describe the problem.
In my opinion, the code required for getting all paged results of a collection request is not ideal. In v5 I had a generic method that handled it for all types, but I couldn't achieve the same using v6. Mainly because the classes for the original request use a RequestConfiguration object and the classes for the paginated requests use a RequestInformation object and they seem to be wholly incompatible.
This is the best I could come up with:
public List<User> getAllUsers(List<String> selectAttributes, String filter)
{
UserCollectionResponse userCollectionResponse = graphClient.users().get(
requestConfig ->
{
if (!selectAttributes.isEmpty())
{
requestConfig.queryParameters.select = selectAttributes.toArray(new String[0]);
if (selectAttributes.contains("manager"))
requestConfig.queryParameters.expand = new String[]{"manager"};
}
if (filter != null)
requestConfig.queryParameters.filter = filter;
});
UnaryOperator<RequestInformation> requestInformation =
requestInfo ->
{
if (!selectAttributes.isEmpty())
{
requestInfo.addQueryParameter("%24select", selectAttributes.toArray(new String[0]));
if (selectAttributes.contains("manager"))
requestInfo.addQueryParameter("%24expand", new String[]{"manager"});
}
if (filter != null)
requestInfo.addQueryParameter("%24filter", filter);
return requestInfo;
};
return loadPagedEntities(userCollectionResponse, UserCollectionResponse::createFromDiscriminatorValue, requestInformation);
}
private <T extends Parsable> List<T> loadPagedEntities(
BaseCollectionPaginationCountResponse baseCollectionPaginationCountResponse,
Function<ParseNode, BaseCollectionPaginationCountResponse> collectionPageFactoryFunction,
UnaryOperator<RequestInformation> requestInformation)
{
try
{
List<T> entities = new ArrayList<>();
PageIterator<T, BaseCollectionPaginationCountResponse> pageIterator =
new PageIterator.Builder<T, BaseCollectionPaginationCountResponse>()
.client(graphClient)
.collectionPage(Objects.requireNonNull(baseCollectionPaginationCountResponse))
.collectionPageFactory(collectionPageFactoryFunction::apply)
.requestConfigurator(requestInformation)
.processPageItemCallback(entities::add)
.build();
pageIterator.iterate();
return entities;
}
catch (ReflectiveOperationException e)
{
throw new RuntimeException(e);
}
}
What irks me most about this, is that I have to specify the query parameters twice and using different syntax! Especially the "%24..." is pretty ugly.
Describe the solution you'd like.
The best solution, of course, would be if the SDK handled this transparently:
List<User> allUsers = graphClient.users().getAll(requestConfig -> ...);
The next best solution would be some kind of compatibility between RequestConfiguration and RequestInformation, so the query parameters would only have to specified once.
What do you think?
Additional context?
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先检查报告中提到的 Java SDK APIs:RequestConfiguration、RequestInformation 和 PageIterator。复现示例分页流程,并比较首次请求和后续请求的查询参数配置方式。当调用方能够配置分页查询参数,而无需重复这些参数或使用 "%24select" 和 "%24filter" 这样的编码名称时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- java
- 领域
- api
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100