Skip to content

Commit

Permalink
Add spring-batch-notion
Browse files Browse the repository at this point in the history
  • Loading branch information
scordio committed Oct 15, 2024
1 parent c2ef3dc commit afa52fd
Show file tree
Hide file tree
Showing 34 changed files with 4,026 additions and 20 deletions.
99 changes: 99 additions & 0 deletions .github/workflows/spring-batch-notion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
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:

java-lts:

name: Java ${{ matrix.java }}
strategy:
fail-fast: false
matrix:
java: [ 17, 21 ]
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: 'zulu'
cache: maven
- name: Test
run: ./mvnw $MAVEN_ARGS verify

java-oracle:

name: Java ${{ matrix.java }}
strategy:
fail-fast: false
matrix:
java: [ 23, 24 ]
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Java
uses: oracle-actions/setup-java@v1
with:
website: jdk.java.net
release: ${{ matrix.java }}
version: latest
- name: Test
run: ./mvnw $MAVEN_ARGS verify

spring-boot:

name: Spring Boot ${{ matrix.spring }}
strategy:
fail-fast: false
matrix:
spring: [ 3.2.0, 3.2.10, 3.4.0-M3 ]
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'zulu'
cache: maven
- name: Set Spring Boot ${{ matrix.spring }}
run: >
./mvnw $MAVEN_ARGS versions:update-parent
-DparentVersion=${{ matrix.spring }}
-DskipResolution
- name: Test
run: ./mvnw $MAVEN_ARGS -Pspring-milestone verify

javadoc:

name: Javadoc
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'zulu'
cache: maven
- name: Generate Javadoc
run: ./mvnw $MAVEN_ARGS javadoc:javadoc
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ This project is part of the [Spring organization][] on GitHub.

## Available Modules

| Module | Description | Lead | Version | CI build |
|----------------------------|-------------------------------|------------------------------------------------------| ------- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 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) |
| 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) |
| 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) |
| 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) |
| 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) |
| Module | Description | Lead | Version | CI build |
|--------------------------------------------------------------------|-------------------------------|------------------------------------------------------|----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [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) |
| [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) |
| [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) |
| [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) |
| [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) |

## Getting support

Expand Down Expand Up @@ -100,23 +100,23 @@ noted differently for individual extension Modules, but this should be the rare

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

[Spring Batch Project]: https://projects.spring.io/spring-batch/
[Spring organization]: https://github.com/spring-projects
[Microsoft Excel]: https://www.microsoft.com/en-us/microsoft-365/excel
[Apache Geode]: https://geode.apache.org
[Apache License]: https://www.apache.org/licenses/LICENSE-2.0
[Contributor Guidelines]: CONTRIBUTING.md
[Elasticsearch]: https://www.elastic.co
[Git]: https://help.github.com/set-up-git-redirect
[GitHub Issue Tracker]: https://github.com/spring-projects/spring-batch-extensions/issues
[Google BigQuery]: https://cloud.google.com/bigquery
[Intellij IDEA]: https://www.jetbrains.com/idea/
[Maven]: https://maven.apache.org
[Microsoft Excel]: https://www.microsoft.com/en-us/microsoft-365/excel
[Neo4j]: https://neo4j.com
[Apache Geode]: https://geode.apache.org
[spring-batch tag]: https://stackoverflow.com/questions/tagged/spring-batch
[Pull requests]: https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests
[Spring Batch]: https://github.com/spring-projects/spring-batch
[Spring Batch Project]: https://projects.spring.io/spring-batch/
[spring-batch tag]: https://stackoverflow.com/questions/tagged/spring-batch
[Spring Boot]: https://github.com/spring-projects/spring-boot
[Spring Cloud Task]: https://github.com/spring-cloud/spring-cloud-task
[Spring Cloud Data Flow]: https://github.com/spring-cloud/spring-cloud-dataflow
[GitHub Issue Tracker]: https://github.com/spring-projects/spring-batch-extensions/issues
[Maven]: https://maven.apache.org
[Git]: https://help.github.com/set-up-git-redirect
[Spring Cloud Task]: https://github.com/spring-cloud/spring-cloud-task
[Spring organization]: https://github.com/spring-projects
[Spring Tool Suite]: https://spring.io/tools
[Intellij IDEA]: https://www.jetbrains.com/idea/
[Pull requests]: https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests
[Contributor Guidelines]: CONTRIBUTING.md
[Apache License]: https://www.apache.org/licenses/LICENSE-2.0
2 changes: 2 additions & 0 deletions spring-batch-elasticsearch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<artifactId>spring-batch-elasticsearch</artifactId>
<version>0.1.0-SNAPSHOT</version>

<name>Spring Batch Elasticsearch</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
Expand Down
13 changes: 13 additions & 0 deletions spring-batch-notion/.editorconfig
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
32 changes: 32 additions & 0 deletions spring-batch-notion/.gitignore
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/
19 changes: 19 additions & 0 deletions spring-batch-notion/.mvn/wrapper/maven-wrapper.properties
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
97 changes: 97 additions & 0 deletions spring-batch-notion/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# 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)

[![Spring Batch Notion](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-notion.yml/badge.svg)](https://github.com/spring-projects/spring-batch-extensions/actions/workflows/spring-batch-notion.yml)

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).

## 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/
Loading

0 comments on commit afa52fd

Please sign in to comment.