From 56f04155e4b51458ede67e0cea44310209b53d1a Mon Sep 17 00:00:00 2001 From: sparkle6979 Date: Tue, 28 Jan 2025 01:48:15 +0800 Subject: [PATCH 1/6] feat: add oneNote document reader --- .../onenote-document-reader/pom.xml | 121 +++++++++ .../reader/onenote/OneNoteDocumentReader.java | 233 ++++++++++++++++++ .../api/reader/onenote/OneNoteResource.java | 118 +++++++++ .../onenote/OneNoteDocumentReaderTest.java | 103 ++++++++ 4 files changed, 575 insertions(+) create mode 100644 community/document-readers/onenote-document-reader/pom.xml create mode 100644 community/document-readers/onenote-document-reader/src/main/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReader.java create mode 100644 community/document-readers/onenote-document-reader/src/main/java/com/alibaba/cloud/api/reader/onenote/OneNoteResource.java create mode 100644 community/document-readers/onenote-document-reader/src/test/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReaderTest.java diff --git a/community/document-readers/onenote-document-reader/pom.xml b/community/document-readers/onenote-document-reader/pom.xml new file mode 100644 index 00000000..19bcfbb3 --- /dev/null +++ b/community/document-readers/onenote-document-reader/pom.xml @@ -0,0 +1,121 @@ + + + + 4.0.0 + + com.alibaba.cloud.ai + spring-ai-alibaba + ${revision} + ../../../pom.xml + + + onenote-document-reader + onenote-document-reader + onenote reader for Spring AI Alibaba + jar + https://github.com/alibaba/spring-ai-alibaba + + https://github.com/alibaba/spring-ai-alibaba + git://github.com/alibaba/spring-ai-alibaba.git + git@github.com:alibaba/spring-ai-alibaba.git + + + + 17 + 17 + UTF-8 + 3.1.1 + 1.18.1 + + + + + + com.alibaba.cloud.ai + spring-ai-alibaba-core + ${project.parent.version} + + + + com.alibaba.cloud.ai + document-parser-markdown + ${project.version} + + + + org.jsoup + jsoup + ${jsoup-version} + + + + + org.springframework.ai + spring-ai-test + test + + + + org.springframework.boot + spring-boot-starter-test + test + + + + io.projectreactor + reactor-test + test + + + + io.micrometer + micrometer-observation-test + test + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-deploy-plugin + ${maven-deploy-plugin.version} + + true + + + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + diff --git a/community/document-readers/onenote-document-reader/src/main/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReader.java b/community/document-readers/onenote-document-reader/src/main/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReader.java new file mode 100644 index 00000000..b9e7b0db --- /dev/null +++ b/community/document-readers/onenote-document-reader/src/main/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReader.java @@ -0,0 +1,233 @@ +package com.alibaba.cloud.api.reader.onenote; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import org.jsoup.Jsoup; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.ai.document.Document; +import org.springframework.ai.document.DocumentReader; +import org.springframework.util.Assert; +import org.springframework.util.StringUtils; + +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.time.Instant; +import java.util.*; + +/** + * @author sparkle6979l + */ +public class OneNoteDocumentReader implements DocumentReader { + + public static final String MICROSOFT_GRAPH_BASE_URL = "https://graph.microsoft.com/v1.0"; + + public static final String NOTEBOOK_ID_FILTER_PREFIX = "/me/onenote/pages/?$expand=parentNotebook&$filter=parentNotebook/id"; + + public static final String SECTION_ID_FILTER_PREFIX = "/me/onenote/pages/?$expand=parentSection&$filter=parentSection/id"; + + private static final Logger log = LoggerFactory.getLogger(OneNoteDocumentReader.class); + + private final OneNoteResource oneNoteResource; + + private final HttpClient client; + + private final String accessToken; + + public OneNoteDocumentReader(String accessToken, OneNoteResource oneNoteResource) { + this.accessToken = accessToken; + this.oneNoteResource = oneNoteResource; + this.client = HttpClient.newBuilder().version(HttpClient.Version.HTTP_2).build(); + } + + /** + * Retrieves the content of a OneNote notebook by querying the Microsoft Graph API. + */ + private List getNoteBookContent(String accessToken, String notebookId) { + // Build the URI for fetching pages from the notebook + String uri = MICROSOFT_GRAPH_BASE_URL + NOTEBOOK_ID_FILTER_PREFIX + + "+eq+" + "'" + notebookId + "'"; + + // Get the page IDs from the notebook by querying the API + List pageIdsFromNotebook = getOneNotePageIdsByURI(uri); + + // Fetch the content for each page by its ID + return pageIdsFromNotebook.stream() + .map(id -> getPageContent(accessToken, id)) + .toList(); + } + + /** + * Retrieves the content of a OneNote section by querying the Microsoft Graph API. + */ + private List getSectionContent(String accessToken, String sectionId) { + // Build the URI for fetching pages from the section + String uri = MICROSOFT_GRAPH_BASE_URL + SECTION_ID_FILTER_PREFIX + + "+eq+" + "'" + sectionId + "'"; + + // Get the page IDs from the notebook by querying the API + List pageIdsBySection = getOneNotePageIdsByURI(uri); + + // Fetch the content for each page by its ID + return pageIdsBySection.stream() + .map(id -> getPageContent(accessToken, id)) + .toList(); + } + + private List getOneNotePageIdsByURI(String uri) { + HttpRequest request = HttpRequest.newBuilder() + .header("Authorization", accessToken) + .header("Content-Type", "application/json") + .uri(URI.create(uri)) + .GET() + .build(); + + try { + HttpResponse response = this.client.send(request, HttpResponse.BodyHandlers.ofString()); + Assert.isTrue(response.statusCode() == 200, "Failed to fetch pages information"); + // Parse JSON response and extract page IDs + return parsePageIdsFromJson(response.body()); + } catch (Exception e) { + throw new RuntimeException("Failed to get pages id", e); + } + } + + /** + * Parses the JSON response and extracts page IDs + */ + private List parsePageIdsFromJson(String jsonResponse) { + JsonObject rootObject = JsonParser.parseString(jsonResponse).getAsJsonObject(); + JsonArray valueArray = rootObject.getAsJsonArray("value"); + + return valueArray.asList().stream() + .map(jsonElement -> jsonElement.getAsJsonObject().get("id").getAsString()) + .toList(); + } + + /** + * Retrieves the content of a specific OneNote page by querying the Microsoft Graph API. + */ + private String getPageContent(String accessToken, String pageId) { + URI uri = URI.create(MICROSOFT_GRAPH_BASE_URL + "/me/onenote/pages/" + pageId + "/content"); + HttpRequest request = HttpRequest.newBuilder() + .header("Authorization", accessToken) + .uri(uri) + .GET() + .build(); + try { + HttpResponse response = this.client.send(request, HttpResponse.BodyHandlers.ofString()); + Assert.isTrue(response.statusCode() == 200, "Failed to fetch page blocks"); + return parseHtmlContent(response.body()); + } catch (Exception e) { + log.warn("Failed to get page content with token: {}, pageId: {}, {}", accessToken, pageId, e.getMessage(), e); + throw new RuntimeException("Failed to get page content", e); + } + } + + @Override + public List get() { + // Get the access token + String accessToken = this.accessToken; + // Get the resource type and resource ID for the OneNote resource + OneNoteResource.ResourceType resourceType = this.oneNoteResource.getResourceType(); + String resourceId = this.oneNoteResource.getResourceId(); + + // Fetch content based on the resource type (Notebook, Section, or Page) + List content = switch (resourceType) { + case NOTEBOOK -> getNoteBookContent(accessToken, resourceId); + case SECTION -> getSectionContent(accessToken, resourceId); + case PAGE -> Collections.singletonList(getPageContent(accessToken, resourceId)); + }; + + // Build metadata for the resource + Map metaData = buildMetadata(accessToken); + + // Construct a list of Document objects + return content.stream() + .map(c -> new Document(c, metaData)) + .toList(); + } + + private String parseHtmlContent(String htmlContent) { + // Parse the HTML content + org.jsoup.nodes.Document parseDoc = Jsoup.parse(htmlContent); + + // Get title and text content, ensuring title is not empty + String title = parseDoc.title(); + String text = parseDoc.text(); + + // Return title and content in a readable format + return title + (title.isEmpty() ? "" : "\n") + text; + } + + /** + * Builds metadata for a given OneNote resource (Notebook, Section, or Page) by querying the Microsoft Graph API. + */ + private Map buildMetadata(String accessToken) { + Map metadata = new HashMap<>(); + + String resourceId = this.oneNoteResource.getResourceId(); + OneNoteResource.ResourceType resourceType = this.oneNoteResource.getResourceType(); + String endpoint = switch (resourceType) { + case NOTEBOOK -> "/notebooks/"; + case SECTION -> "/sections/"; + case PAGE -> "/pages/"; + }; + String uriPath = MICROSOFT_GRAPH_BASE_URL + "/me/onenote" + endpoint + resourceId; + URI uri = URI.create(uriPath); + + // Add basic metadata to the map (resource URI, type, and ID) + metadata.put(OneNoteResource.SOURCE, uriPath); + metadata.put("resourceType", resourceType.name()); + metadata.put("resourceId", resourceId); + + try { + HttpRequest request = HttpRequest.newBuilder() + .header("Authorization", accessToken) + .header("Content-Type", "application/json") + .uri(uri) + .GET() + .build(); + + HttpResponse response = this.client.send(request, HttpResponse.BodyHandlers.ofString()); + Assert.isTrue(response.statusCode() == 200, "Failed to fetch page blocks"); + + // Parse the JSON response to extract relevant metadata fields + JsonObject jsonMetaData = JsonParser.parseString(response.body()).getAsJsonObject(); + + // Extract creation date and add to metadata if available + String createDateTime = Optional.ofNullable(jsonMetaData.get("createdDateTime")) + .map(JsonElement::getAsString) + .orElse(null); + if (StringUtils.hasText(createDateTime)) { + metadata.put("createdTime", Instant.parse(createDateTime).toEpochMilli()); + } + + // Extract last modified date and add to metadata if available + String lastModifiedDateTime = Optional.ofNullable(jsonMetaData.get("lastModifiedDateTime")) + .map(JsonElement::getAsString) + .orElse(null); + if (StringUtils.hasText(lastModifiedDateTime)) { + metadata.put("lastModifiedTime", Instant.parse(lastModifiedDateTime).toEpochMilli()); + } + + // Extract content URL and add to metadata if available + String contentURL = Optional.ofNullable(jsonMetaData.get("contentUrl")) + .map(JsonElement::getAsString) + .orElse(null); + if (StringUtils.hasText(contentURL)) { + metadata.put("contentURL", contentURL); + } + + } catch (Exception e) { + log.warn("Failed to get page content with token: {}, resourceId: {}, resourceType: {}, {}", + accessToken, resourceId, resourceType, e.getMessage(), e); + throw new RuntimeException("Failed to get page content", e); + } + return metadata; + } +} diff --git a/community/document-readers/onenote-document-reader/src/main/java/com/alibaba/cloud/api/reader/onenote/OneNoteResource.java b/community/document-readers/onenote-document-reader/src/main/java/com/alibaba/cloud/api/reader/onenote/OneNoteResource.java new file mode 100644 index 00000000..12020040 --- /dev/null +++ b/community/document-readers/onenote-document-reader/src/main/java/com/alibaba/cloud/api/reader/onenote/OneNoteResource.java @@ -0,0 +1,118 @@ +package com.alibaba.cloud.api.reader.onenote; + +import org.springframework.core.io.Resource; +import org.springframework.util.Assert; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; + +/** + * @author sparkle6979l + */ +public class OneNoteResource implements Resource { + public static final String SOURCE = "source"; + + public enum ResourceType { + NOTEBOOK, SECTION, PAGE + + } + private final ResourceType resourceType; + private final String resourceId; + + public ResourceType getResourceType() { + return resourceType; + } + + public String getResourceId() { + return resourceId; + } + + public OneNoteResource(String resourceId, ResourceType resourceType) { + Assert.hasText(resourceId, "ResourceId must not be empty"); + Assert.notNull(resourceType, "ResourceType must not be null"); + + this.resourceId = resourceId; + this.resourceType = resourceType; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + + private ResourceType resourceType; + + private String resourceId; + + public Builder resourceType(ResourceType resourceType) { + this.resourceType = resourceType; + return this; + } + + public Builder resourceId(String resourceId) { + this.resourceId = resourceId; + return this; + } + + public OneNoteResource build() { + Assert.hasText(resourceId, "ResourceId must not be empty"); + Assert.notNull(resourceType, "ResourceType must not be null"); + return new OneNoteResource(resourceId, resourceType); + } + + } + + @Override + public boolean exists() { + return false; + } + + @Override + public URL getURL() throws IOException { + return null; + } + + @Override + public URI getURI() throws IOException { + return null; + } + + @Override + public File getFile() throws IOException { + return null; + } + + @Override + public long contentLength() throws IOException { + return 0; + } + + @Override + public long lastModified() throws IOException { + return 0; + } + + @Override + public Resource createRelative(String relativePath) throws IOException { + return null; + } + + @Override + public String getFilename() { + return null; + } + + @Override + public String getDescription() { + return null; + } + + @Override + public InputStream getInputStream() throws IOException { + return null; + } +} diff --git a/community/document-readers/onenote-document-reader/src/test/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReaderTest.java b/community/document-readers/onenote-document-reader/src/test/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReaderTest.java new file mode 100644 index 00000000..a1a74fbe --- /dev/null +++ b/community/document-readers/onenote-document-reader/src/test/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReaderTest.java @@ -0,0 +1,103 @@ +package com.alibaba.cloud.api.reader.onenote; + +import org.junit.jupiter.api.Test; +import org.springframework.ai.document.Document; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author sparkle6979l + * @version 1.0 + * @data 2025/1/27 19:59 + */ +public class OneNoteDocumentReaderTest { + + private static final String ONENOTE_ACCESS_TOKEN = System.getenv("ONENOTE_ACCESS_TOKEN"); + + private static final String TEST_ACCESS_TOKEN = "EwB4A8l6BAAUBKgm8k1UswUNwklmy2v7U/S+1fEAAba2iydLSDlzJFhBCED/MW+mm4ImR6QHSsyiFeXYWJmTP69wZWHUBDR4XEWV9QMV6CPiperBohvrg5Yeek2Xd8llq9QylEcZruZG4sYuLAs4v0xupNgSas1htKO6Ii+7o3YvhX7XFVbdXE024NXCGvvUssXsUwK684DAfG2ZOoO1hMzsWJlfULR8Sz94F02kORdP2UqtCTMiSmGQgZrcTh4aro3VO0M84lDXqQf1GywIGTI2NFQ8FjLegQ2sn5zYiEARlAsik7LSCuMwWvWzZdtz0sxoSxHczIQJi7qjvXfSL5T+4kqERhuOJEp2/JNcA9g33aXhk/3TNuHC7ZQVn5EQZgAAEHpM1GKBHyQf0Kvwxy9sEwpAAo4InGesijwB4BV/NmKuhNKlk6Ef0oslNtt/QS22ZF+yZb6VAkQK2JGzIRBmHncGRmikhchhqftrqo0sE+bCkAgRXa8S73cF00dqah0Va3T+aI/ep3gDNfovc8q3KrIZBGhFM0cme5/bMToyzvKTBBnooaKYXwvSU5gH/WnhbOQoQ+5B55wjlxXSG87FdTEQUoer60InA0wE1yQECukhIlWotKB3gCUzMpf3lZby3DX7eYASBdXz1r+3vuWGbD09Kg+e8KjR0xFrl2W9T9y9abzGMFvDRnZa/w6n4aR7anTqj1OX3VYvIx7PX6sZ0PgKW06dJyBDejHKhyUhBvMlRXIVWjkCqnQeIGghzUkvnxSYIpG5I44wUtSYvLCWRmGKe7g7ylMV+BGm6eabvwXpESWfPQiUCh2M1nQNLxwv5chCdi4zHdFIE4mq1l5G5d7HPCDxxQoJlSOBGcshYkqfMm9y4BSbTz50as0LWxOo+tPw5ko4I39DtTrTqarLpxEyq94cem6r1mRUB5DTQ6ITeYXeZnzHkCsTdFEgUxMnPqGrpz+WuuuBdxeabttup2dlVLuv8istKddcoCd71xyV02r7iMWi0wz1+Xr3VBUhMln7E3dRUOoSlaVI1lMxHdaqbIIkdYEfPR/N7tJcawShp6wwZHE5XyoZ6D2NRQ5auih/bnVd/u6ACpWwPyDTSO1VumgQyzCYHJkwF6d+gEoE3y3QF32VDN0srw2q2r6jiwaT+vi/jPklXGxh9aG0OqAQLX4C"; + private OneNoteDocumentReader oneNoteDocumentReader; + + @Test + public void test_load_page(){ + String TEST_PAGE_ID = "0-03ec86ad7070ce4193ecc4dbd76e4e41!1-4F3ACAF53591DCC0!2997"; + + // Create page reader + OneNoteResource oneNoteResource = OneNoteResource.builder() + .resourceId(TEST_PAGE_ID) + .resourceType(OneNoteResource.ResourceType.PAGE) + .build(); + OneNoteDocumentReader oneNoteDocumentReader = new OneNoteDocumentReader(TEST_ACCESS_TOKEN, oneNoteResource); + + List documents = oneNoteDocumentReader.get(); + // then + assertThat(documents).isNotEmpty(); + Document document = documents.get(0); + + // Verify metadata + assertThat(document.getMetadata()).containsKey(OneNoteResource.SOURCE); + assertThat(document.getMetadata().get("resourceType")).isEqualTo(OneNoteResource.ResourceType.PAGE.name()); + assertThat(document.getMetadata().get("resourceId")).isEqualTo(TEST_PAGE_ID); + + // Verify content + String content = document.getContent(); + assertThat(content).isNotEmpty(); + } + + + @Test + public void test_load_section(){ + String testSectionId = "0-4F3ACAF53591DCC0!2862"; + + // Create page reader + OneNoteResource oneNoteResource = OneNoteResource.builder() + .resourceId(testSectionId) + .resourceType(OneNoteResource.ResourceType.SECTION) + .build(); + OneNoteDocumentReader oneNoteDocumentReader = new OneNoteDocumentReader(TEST_ACCESS_TOKEN, oneNoteResource); + + List documents = oneNoteDocumentReader.get(); + // then + assertThat(documents).isNotEmpty(); + Document document = documents.get(0); + + // Verify metadata + assertThat(document.getMetadata()).containsKey(OneNoteResource.SOURCE); + assertThat(document.getMetadata().get("resourceType")).isEqualTo(OneNoteResource.ResourceType.SECTION.name()); + assertThat(document.getMetadata().get("resourceId")).isEqualTo(testSectionId); + + // Verify content + String content = document.getContent(); + assertThat(content).isNotEmpty(); + } + + + @Test + public void test_load_notebook(){ + String testNoteBookId = "0-4F3ACAF53591DCC0!2860"; + + // Create page reader + OneNoteResource oneNoteResource = OneNoteResource.builder() + .resourceId(testNoteBookId) + .resourceType(OneNoteResource.ResourceType.NOTEBOOK) + .build(); + OneNoteDocumentReader oneNoteDocumentReader = new OneNoteDocumentReader(TEST_ACCESS_TOKEN, oneNoteResource); + + List documents = oneNoteDocumentReader.get(); + // then + assertThat(documents).isNotEmpty(); + Document document = documents.get(0); + + // Verify metadata + assertThat(document.getMetadata()).containsKey(OneNoteResource.SOURCE); + assertThat(document.getMetadata().get("resourceType")).isEqualTo(OneNoteResource.ResourceType.NOTEBOOK.name()); + assertThat(document.getMetadata().get("resourceId")).isEqualTo(testNoteBookId); + + // Verify content + String content = document.getContent(); + assertThat(content).isNotEmpty(); + } + + +} From fbad2c90d66438e178828bcc982b10143c7adfe3 Mon Sep 17 00:00:00 2001 From: sparkle6979 Date: Tue, 28 Jan 2025 02:02:14 +0800 Subject: [PATCH 2/6] fix: unit test --- .../api/reader/onenote/OneNoteDocumentReader.java | 2 +- .../api/reader/onenote/OneNoteDocumentReaderTest.java | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/community/document-readers/onenote-document-reader/src/main/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReader.java b/community/document-readers/onenote-document-reader/src/main/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReader.java index b9e7b0db..32775de8 100644 --- a/community/document-readers/onenote-document-reader/src/main/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReader.java +++ b/community/document-readers/onenote-document-reader/src/main/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReader.java @@ -161,7 +161,7 @@ private String parseHtmlContent(String htmlContent) { String text = parseDoc.text(); // Return title and content in a readable format - return title + (title.isEmpty() ? "" : "\n") + text; + return title + (StringUtils.hasText(title) ? "" : "\n") + text; } /** diff --git a/community/document-readers/onenote-document-reader/src/test/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReaderTest.java b/community/document-readers/onenote-document-reader/src/test/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReaderTest.java index a1a74fbe..e02fa77f 100644 --- a/community/document-readers/onenote-document-reader/src/test/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReaderTest.java +++ b/community/document-readers/onenote-document-reader/src/test/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReaderTest.java @@ -14,14 +14,18 @@ */ public class OneNoteDocumentReaderTest { - private static final String ONENOTE_ACCESS_TOKEN = System.getenv("ONENOTE_ACCESS_TOKEN"); + private static final String TEST_ACCESS_TOKEN = System.getenv("ONENOTE_ACCESS_TOKEN"); + + private static final String TEST_NOTEBOOK_ID = "${notebookId}"; + + private static final String TEST_SECTION_ID = "${sectionId}"; + + private static final String TEST_PAGE_ID = "${pageId}"; - private static final String TEST_ACCESS_TOKEN = "EwB4A8l6BAAUBKgm8k1UswUNwklmy2v7U/S+1fEAAba2iydLSDlzJFhBCED/MW+mm4ImR6QHSsyiFeXYWJmTP69wZWHUBDR4XEWV9QMV6CPiperBohvrg5Yeek2Xd8llq9QylEcZruZG4sYuLAs4v0xupNgSas1htKO6Ii+7o3YvhX7XFVbdXE024NXCGvvUssXsUwK684DAfG2ZOoO1hMzsWJlfULR8Sz94F02kORdP2UqtCTMiSmGQgZrcTh4aro3VO0M84lDXqQf1GywIGTI2NFQ8FjLegQ2sn5zYiEARlAsik7LSCuMwWvWzZdtz0sxoSxHczIQJi7qjvXfSL5T+4kqERhuOJEp2/JNcA9g33aXhk/3TNuHC7ZQVn5EQZgAAEHpM1GKBHyQf0Kvwxy9sEwpAAo4InGesijwB4BV/NmKuhNKlk6Ef0oslNtt/QS22ZF+yZb6VAkQK2JGzIRBmHncGRmikhchhqftrqo0sE+bCkAgRXa8S73cF00dqah0Va3T+aI/ep3gDNfovc8q3KrIZBGhFM0cme5/bMToyzvKTBBnooaKYXwvSU5gH/WnhbOQoQ+5B55wjlxXSG87FdTEQUoer60InA0wE1yQECukhIlWotKB3gCUzMpf3lZby3DX7eYASBdXz1r+3vuWGbD09Kg+e8KjR0xFrl2W9T9y9abzGMFvDRnZa/w6n4aR7anTqj1OX3VYvIx7PX6sZ0PgKW06dJyBDejHKhyUhBvMlRXIVWjkCqnQeIGghzUkvnxSYIpG5I44wUtSYvLCWRmGKe7g7ylMV+BGm6eabvwXpESWfPQiUCh2M1nQNLxwv5chCdi4zHdFIE4mq1l5G5d7HPCDxxQoJlSOBGcshYkqfMm9y4BSbTz50as0LWxOo+tPw5ko4I39DtTrTqarLpxEyq94cem6r1mRUB5DTQ6ITeYXeZnzHkCsTdFEgUxMnPqGrpz+WuuuBdxeabttup2dlVLuv8istKddcoCd71xyV02r7iMWi0wz1+Xr3VBUhMln7E3dRUOoSlaVI1lMxHdaqbIIkdYEfPR/N7tJcawShp6wwZHE5XyoZ6D2NRQ5auih/bnVd/u6ACpWwPyDTSO1VumgQyzCYHJkwF6d+gEoE3y3QF32VDN0srw2q2r6jiwaT+vi/jPklXGxh9aG0OqAQLX4C"; private OneNoteDocumentReader oneNoteDocumentReader; @Test public void test_load_page(){ - String TEST_PAGE_ID = "0-03ec86ad7070ce4193ecc4dbd76e4e41!1-4F3ACAF53591DCC0!2997"; // Create page reader OneNoteResource oneNoteResource = OneNoteResource.builder() From 4c677401b6ff20da7fa12b7ced97f8e00f99d49b Mon Sep 17 00:00:00 2001 From: sparkle6979 Date: Tue, 28 Jan 2025 02:03:52 +0800 Subject: [PATCH 3/6] fix: unit test ID --- .../cloud/api/reader/onenote/OneNoteDocumentReaderTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/community/document-readers/onenote-document-reader/src/test/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReaderTest.java b/community/document-readers/onenote-document-reader/src/test/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReaderTest.java index e02fa77f..758e603c 100644 --- a/community/document-readers/onenote-document-reader/src/test/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReaderTest.java +++ b/community/document-readers/onenote-document-reader/src/test/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReaderTest.java @@ -52,11 +52,10 @@ public void test_load_page(){ @Test public void test_load_section(){ - String testSectionId = "0-4F3ACAF53591DCC0!2862"; // Create page reader OneNoteResource oneNoteResource = OneNoteResource.builder() - .resourceId(testSectionId) + .resourceId(TEST_SECTION_ID) .resourceType(OneNoteResource.ResourceType.SECTION) .build(); OneNoteDocumentReader oneNoteDocumentReader = new OneNoteDocumentReader(TEST_ACCESS_TOKEN, oneNoteResource); @@ -79,11 +78,10 @@ public void test_load_section(){ @Test public void test_load_notebook(){ - String testNoteBookId = "0-4F3ACAF53591DCC0!2860"; // Create page reader OneNoteResource oneNoteResource = OneNoteResource.builder() - .resourceId(testNoteBookId) + .resourceId(TEST_NOTEBOOK_ID) .resourceType(OneNoteResource.ResourceType.NOTEBOOK) .build(); OneNoteDocumentReader oneNoteDocumentReader = new OneNoteDocumentReader(TEST_ACCESS_TOKEN, oneNoteResource); From 9fdcf1f84efc54c1cc1f834d83b3acb211f8492a Mon Sep 17 00:00:00 2001 From: sparkle6979 Date: Tue, 28 Jan 2025 02:06:46 +0800 Subject: [PATCH 4/6] fix: pom init --- pom.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pom.xml b/pom.xml index 55c87b81..7386962d 100644 --- a/pom.xml +++ b/pom.xml @@ -25,6 +25,12 @@ pom https://github.com/alibaba/spring-ai-alibaba + + + org.springframework.ai + spring-ai-core + + Spring AI Alibaba Building AI applications with Spring Boot @@ -63,6 +69,7 @@ community/document-readers/feishu-document-reader community/document-readers/yuque-document-reader community/document-readers/obsidian-document-reader + community/document-readers/onenote-document-reader community/document-readers/notion-document-reader community/document-readers/arxiv-document-reader community/document-readers/chatgpt-data-document-reader From 671b88c30ef98028f4f6de5f2660f5fbfdafaba6 Mon Sep 17 00:00:00 2001 From: sparkle6979 Date: Tue, 28 Jan 2025 02:30:17 +0800 Subject: [PATCH 5/6] fix: pom fix --- pom.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pom.xml b/pom.xml index 7386962d..b5d89674 100644 --- a/pom.xml +++ b/pom.xml @@ -25,12 +25,6 @@ pom https://github.com/alibaba/spring-ai-alibaba - - - org.springframework.ai - spring-ai-core - - Spring AI Alibaba Building AI applications with Spring Boot From 1bcf4bda36d213e71619545dcb8f7ca05020dd72 Mon Sep 17 00:00:00 2001 From: sparkle6979 Date: Tue, 28 Jan 2025 02:50:28 +0800 Subject: [PATCH 6/6] fix: add license header --- .../api/reader/onenote/OneNoteDocumentReader.java | 15 +++++++++++++++ .../cloud/api/reader/onenote/OneNoteResource.java | 15 +++++++++++++++ .../reader/onenote/OneNoteDocumentReaderTest.java | 15 +++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/community/document-readers/onenote-document-reader/src/main/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReader.java b/community/document-readers/onenote-document-reader/src/main/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReader.java index 32775de8..7dfc00e9 100644 --- a/community/document-readers/onenote-document-reader/src/main/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReader.java +++ b/community/document-readers/onenote-document-reader/src/main/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReader.java @@ -1,3 +1,18 @@ +/* + * Copyright 2024-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.alibaba.cloud.api.reader.onenote; import com.google.gson.JsonArray; diff --git a/community/document-readers/onenote-document-reader/src/main/java/com/alibaba/cloud/api/reader/onenote/OneNoteResource.java b/community/document-readers/onenote-document-reader/src/main/java/com/alibaba/cloud/api/reader/onenote/OneNoteResource.java index 12020040..c202e7ae 100644 --- a/community/document-readers/onenote-document-reader/src/main/java/com/alibaba/cloud/api/reader/onenote/OneNoteResource.java +++ b/community/document-readers/onenote-document-reader/src/main/java/com/alibaba/cloud/api/reader/onenote/OneNoteResource.java @@ -1,3 +1,18 @@ +/* + * Copyright 2024-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.alibaba.cloud.api.reader.onenote; import org.springframework.core.io.Resource; diff --git a/community/document-readers/onenote-document-reader/src/test/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReaderTest.java b/community/document-readers/onenote-document-reader/src/test/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReaderTest.java index 758e603c..0af78ae2 100644 --- a/community/document-readers/onenote-document-reader/src/test/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReaderTest.java +++ b/community/document-readers/onenote-document-reader/src/test/java/com/alibaba/cloud/api/reader/onenote/OneNoteDocumentReaderTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2024-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.alibaba.cloud.api.reader.onenote; import org.junit.jupiter.api.Test;