microsoftgraph / microsoftgraph/msgraph-sdk-java

Improve paging functionality

オープン
#2,095 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

type:feature
主要言語
Java
スター
444
フォーク
154
平均マージ
18時間 28分
マージ済み PR(30日)
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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、レポートで名前が挙げられている Java SDK APIs(RequestConfiguration、RequestInformation、PageIterator)を調査します。ページングのサンプルフローを再現し、最初のリクエストと後続のリクエストでクエリパラメーターがどのように設定されるかを比較します。呼び出し元が、クエリパラメーターを重複させたり、"%24select" や "%24filter" のようなエンコードされた名前を使用したりせずに、ページングのクエリパラメーターを設定できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
java
領域
api
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。