-
Notifications
You must be signed in to change notification settings - Fork 262
Add spring-batch-notion
#147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
fmbenhassine
merged 1 commit into
spring-projects:main
from
scordio:spring-batch-notion
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Spring Batch Notion | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- 'spring-batch-notion/**' | ||
push: | ||
paths: | ||
- 'spring-batch-notion/**' | ||
|
||
defaults: | ||
run: | ||
working-directory: spring-batch-notion | ||
|
||
env: | ||
MAVEN_ARGS: -B -V -ntp -e -Djansi.passthrough=true -Dstyle.color=always | ||
|
||
jobs: | ||
|
||
build: | ||
|
||
name: Build | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Java | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '21' | ||
distribution: 'temurin' | ||
cache: maven | ||
- name: Build with Maven | ||
run: ./mvnw $MAVEN_ARGS verify javadoc:javadoc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
root = true | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
|
||
# Maven POM code convention | ||
[pom.xml] | ||
indent_size = 2 | ||
indent_style = space | ||
max_line_length = 205 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
### Maven ### | ||
target/ | ||
.mvn/wrapper/maven-wrapper.jar | ||
.flattened-pom.xml | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you 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 | ||
# | ||
# http://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. | ||
wrapperVersion=3.3.2 | ||
distributionType=only-script | ||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# Spring Batch Notion [](https://mvnrepository.com/artifact/org.springframework.batch.extensions/spring-batch-notion) [](https://javadoc.io/doc/org.springframework.batch.extensions/spring-batch-notion) | ||
|
||
[](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-notion.yml?query=branch%3Amain) | ||
|
||
This project provides a [Spring Batch][] extension module that adds support for [Notion][]. | ||
|
||
## Compatibility | ||
|
||
Spring Batch Notion is based on Spring Batch 5 and tested on Spring Boot 3, thus requiring at least Java 17. | ||
|
||
Compatibility is guaranteed only with the Spring Boot versions under [OSS support](https://spring.io/projects/spring-boot/#support). | ||
scordio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Getting Started | ||
|
||
### Maven | ||
|
||
```xml | ||
<dependency> | ||
<groupId>org.springframework.batch.extensions</groupId> | ||
<artifactId>spring-batch-notion</artifactId> | ||
<version>${spring-batch-notion.version}</version> | ||
</dependency> | ||
``` | ||
|
||
### Gradle | ||
|
||
```kotlin | ||
implementation("org.springframework.batch.extensions:spring-batch-notion:${springBatchNotionVersion}") | ||
``` | ||
|
||
## NotionDatabaseItemReader | ||
|
||
The `NotionDatabaseItemReader` is a restartable `ItemReader` that reads entries from a [Notion Database] via a paging technique. | ||
|
||
A minimal configuration of the item reader is as follows: | ||
|
||
```java | ||
NotionDatabaseItemReader<Item> itemReader() { | ||
NotionDatabaseItemReader<Item> reader = new NotionDatabaseItemReader<>(); | ||
reader.setToken(System.getenv("NOTION_TOKEN")); | ||
reader.setDatabaseId("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"); // UUID | ||
reader.setPropertiesMapper(new CustomPropertyMapper()); | ||
return reader; | ||
} | ||
``` | ||
|
||
The following configuration options are available: | ||
|
||
| Property | Required | Default | Description | | ||
|------------------|----------|-----------------------------|---------------------------------------------------------------------------------------------------------------------------| | ||
| `baseUrl` | no | `https://api.notion.com/v1` | Base URL of the Notion API. A custom value can be provided for testing purposes (e.g., the URL of a [WireMock][] server). | | ||
| `databaseId` | yes | - | UUID of the database to read from. | | ||
| `filter` | no | `null` | `Filter` condition to limit the returned items. | | ||
| `pageSize` | no | `100` | Number of items to be read with each page. Must be greater than zero and less than or equal to 100. | | ||
| `propertyMapper` | yes | - | The `PropertyMapper` responsible for mapping properties of a Notion item into a Java object. | | ||
| `sorts` | no | `null` | `Sort` conditions to order the returned items. Each condition is applied following the declaration order. | | ||
| `token` | yes | - | The Notion integration token. | | ||
|
||
In addition to the Notion-specific configuration, all the configuration options of the Spring Batch | ||
[`AbstractPaginatedDataItemReader`](https://docs.spring.io/spring-batch/docs/current/api/org/springframework/batch/item/data/AbstractPaginatedDataItemReader.html) | ||
are supported. | ||
|
||
### PropertyMapper | ||
|
||
The `NotionDatabaseItemReader` requires a `PropertyMapper` to map the properties of a Notion item into an object. | ||
|
||
Currently, only properties of type [Title](https://developers.notion.com/reference/property-object#title) | ||
and [Rich Text](https://developers.notion.com/reference/property-object#rich-text) are supported, | ||
and both are converted to strings. | ||
|
||
The following `PropertyMapper` implementations are provided out of the box. | ||
|
||
| Name | Description | | ||
|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| `BeanWrapperPropertyMapper` | Supports JavaBeans. Requires a default constructor and expects the setter names to match the Notion item property names (case-insensitive). | | ||
| `ConstructorPropertyMapper` | Supports types with a constructor with arguments. Requires the constructor to be unique and its argument names to match the Notion item property names (case-insensitive). | | ||
| `RecordPropertyMapper` | Supports Java records. It uses the canonical constructor and requires the component names to match the Notion item property names (case-insensitive). | | ||
|
||
All implementations above offer two constructors: | ||
* One accepting the `Class` instance of the type to be mapped | ||
* One without parameters, for cases where the type to be mapped can be inferred by the generic type of the variable or method enclosing the constructor declaration | ||
|
||
In case none of the provided implementations is suitable, a custom one can be provided. | ||
|
||
## NotionDatabaseItemWriter | ||
|
||
Currently not provided but will be added in the future. | ||
|
||
## License | ||
|
||
The Spring Batch Notion is released under version 2.0 of the [Apache License][]. | ||
|
||
[Apache License]: https://www.apache.org/licenses/LICENSE-2.0 | ||
[Notion]: https://notion.so/ | ||
[Notion Database]: https://www.notion.so/help/category/databases | ||
[Spring Batch]: https://github.com/spring-projects/spring-batch | ||
[WireMock]: https://wiremock.org/ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.