microsoftgraph / microsoftgraph/msgraph-sdk-java
Improve paging functionality
Chưa có ai nhận issue này.
- 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.
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- 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 kiểm tra các Java SDK APIs được nêu trong báo cáo: RequestConfiguration, RequestInformation và PageIterator. Tái hiện quy trình phân trang mẫu và so sánh cách các tham số truy vấn được cấu hình cho yêu cầu đầu tiên và các yêu cầu tiếp theo. Công việc được coi là hoàn tất khi các bên gọi có thể cấu hình các tham số truy vấn phân trang mà không cần sao chép chúng hoặc sử dụng các tên đã mã hóa như "%24select" và "%24filter".
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
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100