microsoftgraph / microsoftgraph/msgraph-sdk-java

Improve v6 for better Generics usage

未關閉
#2,320 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

status:waiting-for-triage type:feature
主要語言
Java
星號
444
分支
154
平均合併
18 小時 28 分鐘
30 天內合併 PR
4

描述

Is your feature request related to a problem? Please describe the problem.

We are trying to use v6 with generic methods to reduce duplicate boiler plate code, but struggle to do this efficiently. We struggled with the following:

  1. GetRequestConfiguration
    This class seems to be part of each Builder class and there is not one abstract parent implementation for all Builder classes. We can't write a generic method handling each entity because there are hundreds of seperate GetRequestConfiguration implementations, e.g. one for UsersRequestBuilder and this method now can only be used for UsersRequestBuilder:
public static Consumer<UsersRequestBuilder.GetRequestConfiguration> addAdvancedQueryCapabilities() {
		return cust -> {
			Objects.requireNonNull(cust.queryParameters).count = true;
			cust.headers.add("ConsistencyLevel", "eventual");
		};
	}

The same applies for PostRequestConfiguration and all other classes.

  1. BaseCollectionPaginationCountResponse
    Here we see some problems:
  • This class is not typed at all. In v5 there is a generic return type of the response class which determines the correct class for the actual item values in the page collection.
  • After the typing you could add getValue to the base class and not implement it in each subclass which should help to determine the actual return type in v6 as well.
  • Also we think as improvement createFromDiscriminatorValue should be overwritten in each subclass with it's correct implementation (I think this is already done), but we don't understand why we have the need to manually pass the correct descriminator to the PageIterator. We believe this can be done automatically without manual interaction.

Our call currently looks like this using a similar PageIterator as seen in here:

UserCollectionResponse page = userCollectionRequest.get(customizer);
List<User> users = RequestUtils.collectListFromAllPages(this.graphClient.getGraphServiceClient(), page,
	UserCollectionResponse::createFromDiscriminatorValue, this.getClass());

We already pass a UserCollectionResponse but we don't understand why the PageIterator does not get it's discriminator automatically and we have to set it manually by passing the explicit discriminator.

Also we can't use var users = ..., because we need to declare the return type as Entity and can't get it from UserCollectionResponse since that class is not typed.

What do you think about this?

Describe the solution you'd like.

For 1)
Use interfaces for the Configurators, such that generic implementations can be done using these interfaces.

For 2:
Already proposed above

Additional context?

No response

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

先閱讀各個 Builder 類別中的 GetRequestConfiguration 實作,接著檢查 BaseCollectionPaginationCountResponse、UserCollectionResponse 以及 PageIterator 的使用方式。Issue 提議的結果是支援泛型設定器、具型別的集合回應,以及減少手動處理 discriminator;未指定特定檔案或測試。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
java
領域
api
Issue 類型
功能
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
需要釐清
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。