Skip to content

Commit 65b2b52

Browse files
committed
Add spring-batch-notion
1 parent c2ef3dc commit 65b2b52

33 files changed

+3951
-20
lines changed
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Spring Batch Notion
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'spring-batch-notion/**'
7+
push:
8+
paths:
9+
- 'spring-batch-notion/**'
10+
11+
defaults:
12+
run:
13+
working-directory: spring-batch-notion
14+
15+
env:
16+
MAVEN_ARGS: -B -V -ntp -e -Djansi.passthrough=true -Dstyle.color=always
17+
18+
jobs:
19+
20+
build:
21+
22+
name: Build
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- uses: actions/checkout@v4
27+
- name: Set up Java
28+
uses: actions/setup-java@v4
29+
with:
30+
java-version: '21'
31+
distribution: 'temurin'
32+
cache: maven
33+
- name: Build with Maven
34+
run: ./mvnw $MAVEN_ARGS verify javadoc:javadoc

README.md

+23-20
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ This project is part of the [Spring organization][] on GitHub.
66

77
## Available Modules
88

9-
| Module | Description | Lead | Version | CI build |
10-
|----------------------------|-------------------------------|------------------------------------------------------| ------- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
11-
| spring-batch-excel | Support for [Microsoft Excel] | [@mdeinum](https://github.com/mdeinum) | 0.1.1 | [![Spring Batch Excel](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-excel.yml/badge.svg)](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-excel.yml) |
12-
| spring-batch-elasticsearch | Support for [Elasticsearch] | [@parikshitdutta](https://github.com/parikshitdutta) | 0.1.0-SNAPSHOT | [![Spring Batch Elasticsearch](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-elasticsearch.yml/badge.svg)](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-elasticsearch.yml) |
13-
| spring-batch-bigquery | Support for [Google BigQuery] | [@dgray16](https://github.com/dgray16) | 0.1.0 | [![Spring Batch BigQuery](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-bigquery.yml/badge.svg)](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-bigquery.yml) |
14-
| spring-batch-neo4j | Support for [Neo4j] | [@michael-simons](https://github.com/michael-simons) | 0.1.0 | [![Spring Batch Neo4j](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-neo4j.yml/badge.svg)](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-neo4j.yml) |
15-
| spring-batch-geode | Support for [Apache Geode] | TBA | 0.1.0-SNAPSHOT | [![Spring Batch Geode](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-geode.yml/badge.svg)](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-geode.yml) |
9+
| Module | Description | Lead | Version | CI build |
10+
|--------------------------------------------------------------------|-------------------------------|------------------------------------------------------|----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
11+
| [spring-batch-bigquery](spring-batch-bigquery/README.adoc) | Support for [Google BigQuery] | [@dgray16](https://github.com/dgray16) | 0.1.0 | [![Spring Batch BigQuery](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-bigquery.yml/badge.svg)](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-bigquery.yml) |
12+
| [spring-batch-elasticsearch](spring-batch-elasticsearch/README.md) | Support for [Elasticsearch] | [@parikshitdutta](https://github.com/parikshitdutta) | 0.1.0-SNAPSHOT | [![Spring Batch Elasticsearch](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-elasticsearch.yml/badge.svg)](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-elasticsearch.yml) |
13+
| [spring-batch-excel](spring-batch-excel/README.adoc) | Support for [Microsoft Excel] | [@mdeinum](https://github.com/mdeinum) | 0.1.1 | [![Spring Batch Excel](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-excel.yml/badge.svg)](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-excel.yml) |
14+
| [spring-batch-geode](spring-batch-geode/README.adoc) | Support for [Apache Geode] | TBA | 0.1.0-SNAPSHOT | [![Spring Batch Geode](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-geode.yml/badge.svg)](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-geode.yml) |
15+
| [spring-batch-neo4j](spring-batch-neo4j/README.md) | Support for [Neo4j] | [@michael-simons](https://github.com/michael-simons) | 0.1.0 | [![Spring Batch Neo4j](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-neo4j.yml/badge.svg)](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-neo4j.yml) |
16+
| [spring-batch-notion](spring-batch-notion/README.md) | Support for [Notion] | [@scordio](https://github.com/scordio) | 0.1.0-SNAPSHOT | [![Spring Batch Notion](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-notion.yml/badge.svg?branch=main)](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-notion.yml?query=branch%3Amain) |
1617

1718
## Getting support
1819

@@ -92,6 +93,7 @@ Follow the Spring Batch team members and contributors on Twitter:
9293
* [@rotnroll666](https://twitter.com/rotnroll666) - Michael Simons
9394
* [@meistermeier](https://twitter.com/meistermeier) - Gerrit Meier
9495
* [@truecoder](https://twitter.com/truecoder) - Parikshit Dutta
96+
* [@stefanocodes](https://twitter.com/stefanocodes) - Stefano Cordio
9597

9698
## License
9799

@@ -100,23 +102,24 @@ noted differently for individual extension Modules, but this should be the rare
100102

101103
**We look forward to your contributions!!**
102104

103-
[Spring Batch Project]: https://projects.spring.io/spring-batch/
104-
[Spring organization]: https://github.com/spring-projects
105-
[Microsoft Excel]: https://www.microsoft.com/en-us/microsoft-365/excel
105+
[Apache Geode]: https://geode.apache.org
106+
[Apache License]: https://www.apache.org/licenses/LICENSE-2.0
107+
[Contributor Guidelines]: CONTRIBUTING.md
106108
[Elasticsearch]: https://www.elastic.co
109+
[Git]: https://help.github.com/set-up-git-redirect
110+
[GitHub Issue Tracker]: https://github.com/spring-projects/spring-batch-extensions/issues
107111
[Google BigQuery]: https://cloud.google.com/bigquery
112+
[Intellij IDEA]: https://www.jetbrains.com/idea/
113+
[Maven]: https://maven.apache.org
114+
[Microsoft Excel]: https://www.microsoft.com/en-us/microsoft-365/excel
108115
[Neo4j]: https://neo4j.com
109-
[Apache Geode]: https://geode.apache.org
110-
[spring-batch tag]: https://stackoverflow.com/questions/tagged/spring-batch
116+
[Notion]: https://notion.so/
117+
[Pull requests]: https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests
111118
[Spring Batch]: https://github.com/spring-projects/spring-batch
119+
[Spring Batch Project]: https://projects.spring.io/spring-batch/
112120
[Spring Boot]: https://github.com/spring-projects/spring-boot
113-
[Spring Cloud Task]: https://github.com/spring-cloud/spring-cloud-task
114121
[Spring Cloud Data Flow]: https://github.com/spring-cloud/spring-cloud-dataflow
115-
[GitHub Issue Tracker]: https://github.com/spring-projects/spring-batch-extensions/issues
116-
[Maven]: https://maven.apache.org
117-
[Git]: https://help.github.com/set-up-git-redirect
122+
[Spring Cloud Task]: https://github.com/spring-cloud/spring-cloud-task
123+
[Spring organization]: https://github.com/spring-projects
118124
[Spring Tool Suite]: https://spring.io/tools
119-
[Intellij IDEA]: https://www.jetbrains.com/idea/
120-
[Pull requests]: https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests
121-
[Contributor Guidelines]: CONTRIBUTING.md
122-
[Apache License]: https://www.apache.org/licenses/LICENSE-2.0
125+
[spring-batch tag]: https://stackoverflow.com/questions/tagged/spring-batch

spring-batch-notion/.editorconfig

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
root = true
2+
3+
# Unix-style newlines with a newline ending every file
4+
[*]
5+
charset = utf-8
6+
end_of_line = lf
7+
insert_final_newline = true
8+
9+
# Maven POM code convention
10+
[pom.xml]
11+
indent_size = 2
12+
indent_style = space
13+
max_line_length = 205

spring-batch-notion/.gitignore

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
### Maven ###
2+
target/
3+
.mvn/wrapper/maven-wrapper.jar
4+
.flattened-pom.xml
5+
6+
### STS ###
7+
.apt_generated
8+
.classpath
9+
.factorypath
10+
.project
11+
.settings
12+
.springBeans
13+
.sts4-cache
14+
15+
### IntelliJ IDEA ###
16+
.idea
17+
*.iws
18+
*.iml
19+
*.ipr
20+
21+
### NetBeans ###
22+
/nbproject/private/
23+
/nbbuild/
24+
/dist/
25+
/nbdist/
26+
/.nb-gradle/
27+
build/
28+
!**/src/main/**/build/
29+
!**/src/test/**/build/
30+
31+
### VS Code ###
32+
.vscode/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
wrapperVersion=3.3.2
18+
distributionType=only-script
19+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip

spring-batch-notion/README.md

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Spring Batch Notion [![Maven Central](https://img.shields.io/maven-central/v/org.springframework.batch.extensions/spring-batch-notion?label=Maven%20Central)](https://mvnrepository.com/artifact/org.springframework.batch.extensions/spring-batch-notion) [![javadoc](https://javadoc.io/badge2/org.springframework.batch.extensions/spring-batch-notion/javadoc.svg)](https://javadoc.io/doc/org.springframework.batch.extensions/spring-batch-notion)
2+
3+
[![Spring Batch Notion](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-notion.yml/badge.svg?branch=main)](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-notion.yml?query=branch%3Amain)
4+
5+
This project provides a [Spring Batch][] extension module that adds support for [Notion][].
6+
7+
## Compatibility
8+
9+
Spring Batch Notion is based on Spring Batch 5 and tested on Spring Boot 3, thus requiring at least Java 17.
10+
11+
Compatibility is guaranteed only with the Spring Boot versions under [OSS support](https://spring.io/projects/spring-boot/#support).
12+
13+
## Getting Started
14+
15+
### Maven
16+
17+
```xml
18+
<dependency>
19+
<groupId>org.springframework.batch.extensions</groupId>
20+
<artifactId>spring-batch-notion</artifactId>
21+
<version>${spring-batch-notion.version}</version>
22+
</dependency>
23+
```
24+
25+
### Gradle
26+
27+
```kotlin
28+
implementation("org.springframework.batch.extensions:spring-batch-notion:${springBatchNotionVersion}")
29+
```
30+
31+
## NotionDatabaseItemReader
32+
33+
The `NotionDatabaseItemReader` is a restartable `ItemReader` that reads entries from a [Notion Database] via a paging technique.
34+
35+
A minimal configuration of the item reader is as follows:
36+
37+
```java
38+
NotionDatabaseItemReader<Item> itemReader() {
39+
NotionDatabaseItemReader<Item> reader = new NotionDatabaseItemReader<>();
40+
reader.setToken(System.getenv("NOTION_TOKEN"));
41+
reader.setDatabaseId("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"); // UUID
42+
reader.setPropertiesMapper(new CustomPropertyMapper());
43+
return reader;
44+
}
45+
```
46+
47+
The following configuration options are available:
48+
49+
| Property | Required | Default | Description |
50+
|------------------|----------|-----------------------------|---------------------------------------------------------------------------------------------------------------------------|
51+
| `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). |
52+
| `databaseId` | yes | - | UUID of the database to read from. |
53+
| `filter` | no | `null` | `Filter` condition to limit the returned items. |
54+
| `pageSize` | no | `100` | Number of items to be read with each page. Must be greater than zero and less than or equal to 100. |
55+
| `propertyMapper` | yes | - | The `PropertyMapper` responsible for mapping properties of a Notion item into a Java object. |
56+
| `sorts` | no | `null` | `Sort` conditions to order the returned items. Each condition is applied following the declaration order. |
57+
| `token` | yes | - | The Notion integration token. |
58+
59+
In addition to the Notion-specific configuration, all the configuration options of the Spring Batch
60+
[`AbstractPaginatedDataItemReader`](https://docs.spring.io/spring-batch/docs/current/api/org/springframework/batch/item/data/AbstractPaginatedDataItemReader.html)
61+
are supported.
62+
63+
### PropertyMapper
64+
65+
The `NotionDatabaseItemReader` requires a `PropertyMapper` to map the properties of a Notion item into an object.
66+
67+
Currently, only properties of type [Title](https://developers.notion.com/reference/property-object#title)
68+
and [Rich Text](https://developers.notion.com/reference/property-object#rich-text) are supported,
69+
and both are converted to strings.
70+
71+
The following `PropertyMapper` implementations are provided out of the box.
72+
73+
| Name | Description |
74+
|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
75+
| `BeanWrapperPropertyMapper` | Supports JavaBeans. Requires a default constructor and expects the setter names to match the Notion item property names (case-insensitive). |
76+
| `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). |
77+
| `RecordPropertyMapper` | Supports Java records. It uses the canonical constructor and requires the component names to match the Notion item property names (case-insensitive). |
78+
79+
All implementations above offer two constructors:
80+
* One accepting the `Class` instance of the type to be mapped
81+
* 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
82+
83+
In case none of the provided implementations is suitable, a custom one can be provided.
84+
85+
## NotionDatabaseItemWriter
86+
87+
Currently not provided but will be added in the future.
88+
89+
## License
90+
91+
The Spring Batch Notion is released under version 2.0 of the [Apache License][].
92+
93+
[Apache License]: https://www.apache.org/licenses/LICENSE-2.0
94+
[Notion]: https://notion.so/
95+
[Notion Database]: https://www.notion.so/help/category/databases
96+
[Spring Batch]: https://github.com/spring-projects/spring-batch
97+
[WireMock]: https://wiremock.org/

0 commit comments

Comments
 (0)