microsoftgraph / microsoftgraph/msgraph-sdk-java

Improve v6 for better Generics usage

Đang mở
#2,320 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

status:waiting-for-triage type:feature
Ngôn ngữ chính
Java
Star
444
Fork
154
Merge trung bình
18 giờ 28 phút
Pull request đã merge (30 ngày)
4

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách đọc các triển khai của GetRequestConfiguration trong các lớp Builder, sau đó kiểm tra BaseCollectionPaginationCountResponse, UserCollectionResponse và cách sử dụng PageIterator. Kết quả được đề xuất trong issue là hỗ trợ configurator generic, các response collection có kiểu và giảm việc xử lý discriminator thủ công; không có file hoặc test cụ thể nào được nêu tên.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
java
Lĩnh vực
api
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.