diff --git a/spring-batch-notion/src/main/java/org/springframework/batch/extensions/notion/Filter.java b/spring-batch-notion/src/main/java/org/springframework/batch/extensions/notion/Filter.java index 0aaf368..bbf5f8e 100644 --- a/spring-batch-notion/src/main/java/org/springframework/batch/extensions/notion/Filter.java +++ b/spring-batch-notion/src/main/java/org/springframework/batch/extensions/notion/Filter.java @@ -18,9 +18,11 @@ package org.springframework.batch.extensions.notion; import notion.api.v1.model.databases.query.filter.CompoundFilterElement; import notion.api.v1.model.databases.query.filter.QueryTopLevelFilter; import notion.api.v1.model.databases.query.filter.condition.CheckboxFilter; +import notion.api.v1.model.databases.query.filter.condition.FilesFilter; import notion.api.v1.model.databases.query.filter.condition.MultiSelectFilter; import notion.api.v1.model.databases.query.filter.condition.NumberFilter; import notion.api.v1.model.databases.query.filter.condition.SelectFilter; +import notion.api.v1.model.databases.query.filter.condition.StatusFilter; import java.util.ArrayList; import java.util.List; @@ -310,6 +312,16 @@ public abstract sealed class Filter { return new CheckboxCondition<>(property, factory); } + /** + * Start the definition of the filter condition for a {@code files} property. + * @param property The name of the property as it appears in the database, or the + * property ID + * @return a new {@link CheckboxCondition} instance + */ + public FilesCondition files(String property) { + return new FilesCondition<>(property, factory); + } + /** * Start the definition of the filter condition for a {@code multi-select} * property. @@ -341,6 +353,16 @@ public abstract sealed class Filter { return new SelectCondition<>(property, factory); } + /** + * Start the definition of the filter condition for a {@code status} property. + * @param property The name of the property as it appears in the database, or the + * property ID + * @return a new {@link StatusCondition} instance + */ + public StatusCondition status(String property) { + return new StatusCondition<>(property, factory); + } + static abstract sealed class Condition { private final String property; @@ -393,6 +415,39 @@ public abstract sealed class Filter { } + /** + * Filter condition for a {@code files} property. + * + * @param the type of the target filter + */ + public static final class FilesCondition extends Condition { + + private FilesCondition(String property, NotionPropertyFilterFactory factory) { + super(property, factory); + } + + /** + * Return database entries where the property value does not contain any data. + * @return a filter with the newly defined condition + */ + public T isEmpty() { + FilesFilter filesFilter = new FilesFilter(); + filesFilter.setEmpty(true); + return toFilter(notionPropertyFilter -> notionPropertyFilter.setFile(filesFilter)); + } + + /** + * Return database entries where the property value contains data. + * @return a filter with the newly defined condition + */ + public T isNotEmpty() { + FilesFilter filesFilter = new FilesFilter(); + filesFilter.setNotEmpty(true); + return toFilter(notionPropertyFilter -> notionPropertyFilter.setFile(filesFilter)); + } + + } + /** * Filter condition for a {@code multi-select} property. * @@ -610,6 +665,62 @@ public abstract sealed class Filter { } + /** + * Filter condition for a {@code status} property. + * + * @param the type of the target filter + */ + public static final class StatusCondition extends Condition { + + private StatusCondition(String property, NotionPropertyFilterFactory factory) { + super(property, factory); + } + + /** + * Return database entries where the property value matches the provided one. + * @param value the value to compare the property value against + * @return a filter with the newly defined condition + */ + public T isEqualTo(String value) { + StatusFilter statusFilter = new StatusFilter(); + statusFilter.setEquals(value); + return toFilter(notionPropertyFilter -> notionPropertyFilter.setStatus(statusFilter)); + } + + /** + * Return database entries where the property value does not match the + * provided one. + * @param value the value to compare the property value against + * @return a filter with the newly defined condition + */ + public T isNotEqualTo(String value) { + StatusFilter statusFilter = new StatusFilter(); + statusFilter.setDoesNotEqual(value); + return toFilter(notionPropertyFilter -> notionPropertyFilter.setStatus(statusFilter)); + } + + /** + * Return database entries where the property value does not contain any data. + * @return a filter with the newly defined condition + */ + public T isEmpty() { + StatusFilter statusFilter = new StatusFilter(); + statusFilter.setEmpty(true); + return toFilter(notionPropertyFilter -> notionPropertyFilter.setStatus(statusFilter)); + } + + /** + * Return database entries where the property value contains data. + * @return a filter with the newly defined condition + */ + public T isNotEmpty() { + StatusFilter statusFilter = new StatusFilter(); + statusFilter.setNotEmpty(true); + return toFilter(notionPropertyFilter -> notionPropertyFilter.setStatus(statusFilter)); + } + + } + } } diff --git a/spring-batch-notion/src/test/java/org/springframework/batch/extensions/notion/FilterTests.java b/spring-batch-notion/src/test/java/org/springframework/batch/extensions/notion/FilterTests.java index bc074df..f022457 100644 --- a/spring-batch-notion/src/test/java/org/springframework/batch/extensions/notion/FilterTests.java +++ b/spring-batch-notion/src/test/java/org/springframework/batch/extensions/notion/FilterTests.java @@ -19,9 +19,11 @@ import notion.api.v1.model.databases.query.filter.CompoundFilter; import notion.api.v1.model.databases.query.filter.PropertyFilter; import notion.api.v1.model.databases.query.filter.QueryTopLevelFilter; import notion.api.v1.model.databases.query.filter.condition.CheckboxFilter; +import notion.api.v1.model.databases.query.filter.condition.FilesFilter; import notion.api.v1.model.databases.query.filter.condition.MultiSelectFilter; import notion.api.v1.model.databases.query.filter.condition.NumberFilter; import notion.api.v1.model.databases.query.filter.condition.SelectFilter; +import notion.api.v1.model.databases.query.filter.condition.StatusFilter; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.FieldSource; @@ -70,6 +72,26 @@ class FilterTests { })))) .toList(); + static final List FILES_FILTERS = List.of( // + arguments( // + where().files("property").isEmpty(), // + supply(() -> { + FilesFilter filesFilter = new FilesFilter(); + filesFilter.setEmpty(true); + PropertyFilter propertyFilter = new PropertyFilter("property"); + propertyFilter.setFile(filesFilter); + return propertyFilter; + })), + arguments( // + where().files("property").isNotEmpty(), // + supply(() -> { + FilesFilter filesFilter = new FilesFilter(); + filesFilter.setNotEmpty(true); + PropertyFilter propertyFilter = new PropertyFilter("property"); + propertyFilter.setFile(filesFilter); + return propertyFilter; + }))); + static final List MULTI_SELECT_FILTERS = List.of( // arguments( // where().multiSelect("property").contains("value"), // @@ -220,11 +242,51 @@ class FilterTests { return propertyFilter; }))); + static final List STATUS_FILTERS = List.of( // + arguments( // + where().status("property").isEqualTo("value"), // + supply(() -> { + StatusFilter statusFilter = new StatusFilter(); + statusFilter.setEquals("value"); + PropertyFilter propertyFilter = new PropertyFilter("property"); + propertyFilter.setStatus(statusFilter); + return propertyFilter; + })), + arguments( // + where().status("property").isNotEqualTo("value"), // + supply(() -> { + StatusFilter statusFilter = new StatusFilter(); + statusFilter.setDoesNotEqual("value"); + PropertyFilter propertyFilter = new PropertyFilter("property"); + propertyFilter.setStatus(statusFilter); + return propertyFilter; + })), + arguments( // + where().status("property").isEmpty(), // + supply(() -> { + StatusFilter statusFilter = new StatusFilter(); + statusFilter.setEmpty(true); + PropertyFilter propertyFilter = new PropertyFilter("property"); + propertyFilter.setStatus(statusFilter); + return propertyFilter; + })), + arguments( // + where().status("property").isNotEmpty(), // + supply(() -> { + StatusFilter statusFilter = new StatusFilter(); + statusFilter.setNotEmpty(true); + PropertyFilter propertyFilter = new PropertyFilter("property"); + propertyFilter.setStatus(statusFilter); + return propertyFilter; + }))); + static final List PROPERTY_FILTERS = Stream.of( // CHECKBOX_FILTERS, // + FILES_FILTERS, // MULTI_SELECT_FILTERS, // NUMBER_FILTERS, // - SELECT_FILTERS) // + SELECT_FILTERS, // + STATUS_FILTERS) // .flatMap(List::stream) .toList();