microsoftgraph / microsoftgraph/msgraph-sdk-java
Boiler plate when iterating through collections
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ả
Hello, i have a small question.
https://github.com/microsoftgraph/msgraph-sdk-java/blob/dev/docs/upgrade-to-v6.md#pageiterator
- With the new page iterator there is a boilerplate associated with each request and iterating through it. Since a new page iterator would need to be created for each request.
- I was wondering if there is a generic way to create an iterator to run on collection requests and delta collection requests.
So I created this code, from looking at the generated code in the msft graph sdk:
public static <T extends Parsable> void genericIterator(
GraphServiceClient graphClient,
BaseDeltaFunctionResponse res,
Consumer<T> processEntity,
Consumer<String> processDeltaLink) {
PageIterator<T, BaseDeltaFunctionResponse> pageIterator;
try {
pageIterator = new PageIterator.Builder<T, BaseDeltaFunctionResponse>()
.client(graphClient)
.collectionPage(res)
.collectionPageFactory(BaseDeltaFunctionResponse::createFromDiscriminatorValue)
.processPageItemCallback(entity -> {
processEntity.accept(entity);
return true;
}).build();
pageIterator.iterate();
processDeltaLink.accept(pageIterator.getDeltaLink());
} catch (ApiException | ReflectiveOperationException e) {
log.error("Error ", e);
}
}
public static <T extends Parsable> void genericIterator(
GraphServiceClient graphClient,
BaseCollectionPaginationCountResponse res,
Consumer<T> processGroupOwner) {
PageIterator<T, BaseCollectionPaginationCountResponse> pageIterator;
try {
pageIterator = new PageIterator.Builder<T, BaseCollectionPaginationCountResponse>()
.client(graphClient)
.collectionPage(res)
.collectionPageFactory(BaseCollectionPaginationCountResponse::createFromDiscriminatorValue)
.processPageItemCallback(entity -> {
processGroupOwner.accept(entity);
return true;
}).build();
pageIterator.iterate();
} catch (ApiException | ReflectiveOperationException e) {
log.error("Error ", e);
}
}
This second method works with general collectors, but not the first one for delta collections.
I was wondering if this is even recommending considering that the sdk is based on code generations and/or if there is a way to iterate over collections in a more concise manner than the current page iterator.
Error received from the generic delta collection iterator:
DeltaGetResponse res2 = graphServiceClient.groups().delta().get();
genericIterator(graphServiceClient, res2, (Group group) -> {
log.info("Group: {} {}", group.getId(), group.getDisplayName());
}, (String deltaLink) -> {
log.info("DeltaLink: {}", deltaLink);
});
java.lang.IllegalAccessException: NO_COLLECTION_PROPERTY_ERROR
at com.microsoft.graph.core.tasks.PageIterator.extractEntityListFromParsable(PageIterator.java:300)
at com.microsoft.graph.core.tasks.PageIterator.interpageIterate(PageIterator.java:250)
at com.microsoft.graph.core.tasks.PageIterator.iterate(PageIterator.java:272)
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 với phần triển khai PageIterator tại com.microsoft.graph.core.tasks.PageIterator.java, đặc biệt là extractEntityListFromParsable và đường dẫn lặp giữa các trang, sau đó xem lại phần PageIterator trong docs/upgrade-to-v6.md. Tái hiện ví dụ delta tổng quát từ issue và xác định xem các yêu cầu collection và delta collection có thể dùng chung một iterator ngắn gọn hay không; hoàn thành có nghĩa là hành vi được hỗ trợ và thay đổi API cần thiết đã rõ ràng.
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ó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- 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