@@ -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<T> 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<T> status(String property) {
|
||||
return new StatusCondition<>(property, factory);
|
||||
}
|
||||
|
||||
static abstract sealed class Condition<T extends Filter> {
|
||||
|
||||
private final String property;
|
||||
@@ -393,6 +415,39 @@ public abstract sealed class Filter {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter condition for a {@code files} property.
|
||||
*
|
||||
* @param <T> the type of the target filter
|
||||
*/
|
||||
public static final class FilesCondition<T extends Filter> extends Condition<T> {
|
||||
|
||||
private FilesCondition(String property, NotionPropertyFilterFactory<T> 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 <T> the type of the target filter
|
||||
*/
|
||||
public static final class StatusCondition<T extends Filter> extends Condition<T> {
|
||||
|
||||
private StatusCondition(String property, NotionPropertyFilterFactory<T> 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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Arguments> 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<Arguments> MULTI_SELECT_FILTERS = List.of( //
|
||||
arguments( //
|
||||
where().multiSelect("property").contains("value"), //
|
||||
@@ -220,11 +242,51 @@ class FilterTests {
|
||||
return propertyFilter;
|
||||
})));
|
||||
|
||||
static final List<Arguments> 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<Arguments> PROPERTY_FILTERS = Stream.of( //
|
||||
CHECKBOX_FILTERS, //
|
||||
FILES_FILTERS, //
|
||||
MULTI_SELECT_FILTERS, //
|
||||
NUMBER_FILTERS, //
|
||||
SELECT_FILTERS) //
|
||||
SELECT_FILTERS, //
|
||||
STATUS_FILTERS) //
|
||||
.flatMap(List::stream)
|
||||
.toList();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user