microsoftgraph / msgraph-sdk-java

Microsoft Graph SDK for Java
https://docs.microsoft.com/en-us/graph/sdks/sdks-overview
MIT License
374 stars 126 forks source link

Upgrade from 5.80.0 to 6.13.0 #2070

Closed susanYYT closed 1 month ago

susanYYT commented 3 months ago

Hi,

I'm upgrading microsoft graph from 5.80.0 to 6.13.0. The pom.xml part change:

        <dependency>
            <groupId>com.microsoft.graph</groupId>
            <artifactId>microsoft-graph</artifactId>
            <version>6.13.0</version>
        </dependency>

        <dependency>
            <groupId>com.microsoft.graph</groupId>
            <artifactId>microsoft-graph-core</artifactId>
            <version>3.1.13</version>
        </dependency>

        <dependency>
            <groupId>com.azure</groupId>
            <artifactId>azure-core</artifactId>
            <version>1.49.0</version>
        </dependency>

        <dependency>
            <groupId>com.azure</groupId>
            <artifactId>azure-identity</artifactId>
            <version>1.12.1</version>
        </dependency>

        <dependency>
            <groupId>com.azure</groupId>
            <artifactId>azure-core-http-okhttp</artifactId>
            <version>1.12.0</version>
        </dependency>

And here I have several questions.

  1. When I create GraphServiceClient, I will meet the following errors: The type com.microsoft.kiota.authentication.AuthenticationProvider cannot be resolved. The type com.microsoft.kiota.RequestAdapter cannot be resolved

My code is:

final ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
        .clientId(applicationId).clientSecret(clientSecret).tenantId(tenantId).build();

graphClient = new GraphServiceClient(clientSecretCredential, scope);
  1. When I get site by site url, in v5, I use: Site site = graphClient.sites().byId(sitePath).buildRequest().get(); In v6, I only find http method in the doc. Could I use: Site site = graphClient.sites().bySiteId(sitePath).get();
  2. When I get DriveItem by path, in v5, I use: DriveItem item = graphClient.sites(site.id).drives(d.id).root().itemWithPath(itemPath).buildRequest().get(); In v6. am I correct: DriveItem item = graphClient.drives().byDriveId(d.getId()).root().withUrl(itemPath).get();
  3. CollectionResponse issue For example, I use ListCollectionPage.getNextPage() in v5.

While in v6, I try to use PageIterator:

PageIterator<com.microsoft.graph.models.List, ListCollectionResponse> pageIterator = new PageIterator.Builder<com.microsoft.graph.models.List, ListCollectionResponse>()
.client(graphClient)
.collectionPage(Objects.requireNonNull(firstPage))
.collectionPageFactory(MessageCollectionResponse::createFromDiscriminatorValue)
.processPageItemCallback(list -> {
    listFinalSiteLists.add(list);
    return true;
}).build();
pageIterator.iterate();

But it shows "The type com.microsoft.kiota.serialization.ParsableFactory cannot be resolved. "

Could you please give me some suggestions?

Best regards, Susan

ccea-dev-team commented 3 months ago

There was an upgrade guide from 5 to 6 that explains most of the changes you need but can't seem to find it now

susanYYT commented 3 months ago

There was an upgrade guide from 5 to 6 that explains most of the changes you need but can't seem to find it now

No, I found the upgrade guide: https://github.com/microsoftgraph/msgraph-sdk-java/blob/main/docs/upgrade-to-v6.md. But it can't solve the problems I meet.

ccea-dev-team commented 3 months ago

Try removing

com.microsoft.graph microsoft-graph-core 3.1.14

From your pom as this is included in microsoft-graph 6.13.0.

The cannot be resolved errors you are getting - are these at runtime or compliation errors? Try building the project and doing a maven clean and install to ensure the libraries are picked up.

susanYYT commented 3 months ago

I've removed the microsoft-graph-core 3.1.14, but it doesn't work. When I execute mvn clean install, I still failed with error like: ERROR] Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:1.7.0:compileERROR on project harepointservice: Compilation failure: Compilation failure: [ERROR] **/MicrosoftGraphService.java:[76] [ERROR] graphClient = new GraphServiceClient(clientSecretCredential, scope); [ERROR] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [ERROR] The type com.microsoft.kiota.authentication.AuthenticationProvider cannot be resolved. It is indirectly referenced from required .class files [ERROR] **/MicrosoftGraphService.java:[76] [ERROR] graphClient = new GraphServiceClient(clientSecretCredential, scope); [ERROR] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [ERROR] The type com.microsoft.kiota.RequestAdapter cannot be resolved. It is indirectly referenced from required .class files [ERROR] 2 problems (2 errors) [ERROR] -> [Help 1]

johnthad commented 3 months ago

There was an upgrade guide from 5 to 6 that explains most of the changes you need but can't seem to find it now

What's missing from this upgrade guide is a link to any v6 JavaDocs. The javadoc jar on Maven Central is empty, nothing but a META-INF directory. Ditto for all the other v6 versions I checked. I'm trying to upgrade a v5 app and frustrated by the lack of JavaDocs. In particular, I'm stumbling around trying to find the import and API for classes like PageIterator, RequestConfiguration, etc. If you won't provide JavaDocs, then at least show the imports in your examples.

Ndiritu commented 2 months ago

My apologies for this experience @susanYYT

As I try to reproduce this, you can add microsoft-kiota-abstractions as a direct dependency and let me know if this unblocks you.

Thank you for the feedback @johnthad. Created https://github.com/microsoftgraph/msgraph-sdk-java/issues/2078 to track it.

Ndiritu commented 2 months ago

@susanYYT To get sites by URL: Site site = graphClient.sites().bySiteId(sitePath).get(); should work with the sitePath being "{hostname}:/{server-relative-path}"

Similarly for Drives: use graphClient.drives().byDriveId("driveId").items().byDriveItemId("itemPath").get() with itemPath as root:/{relative path}: (with trailing colon)

susanYYT commented 2 months ago

Thanks very much. It works by adding microsoft-kiota-abstractions