Skip to content

Commit 322aecc

Browse files
committed
Add files and status filters
See #152.
1 parent 990979b commit 322aecc

File tree

2 files changed

+174
-1
lines changed
  • spring-batch-notion/src

2 files changed

+174
-1
lines changed

spring-batch-notion/src/main/java/org/springframework/batch/extensions/notion/Filter.java

+111
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
import notion.api.v1.model.databases.query.filter.CompoundFilterElement;
1919
import notion.api.v1.model.databases.query.filter.QueryTopLevelFilter;
2020
import notion.api.v1.model.databases.query.filter.condition.CheckboxFilter;
21+
import notion.api.v1.model.databases.query.filter.condition.FilesFilter;
2122
import notion.api.v1.model.databases.query.filter.condition.MultiSelectFilter;
2223
import notion.api.v1.model.databases.query.filter.condition.NumberFilter;
2324
import notion.api.v1.model.databases.query.filter.condition.SelectFilter;
25+
import notion.api.v1.model.databases.query.filter.condition.StatusFilter;
2426

2527
import java.util.ArrayList;
2628
import java.util.List;
@@ -310,6 +312,16 @@ public CheckboxCondition<T> checkbox(String property) {
310312
return new CheckboxCondition<>(property, factory);
311313
}
312314

315+
/**
316+
* Start the definition of the filter condition for a {@code files} property.
317+
* @param property The name of the property as it appears in the database, or the
318+
* property ID
319+
* @return a new {@link CheckboxCondition} instance
320+
*/
321+
public FilesCondition<T> files(String property) {
322+
return new FilesCondition<>(property, factory);
323+
}
324+
313325
/**
314326
* Start the definition of the filter condition for a {@code multi-select}
315327
* property.
@@ -341,6 +353,16 @@ public SelectCondition<T> select(String property) {
341353
return new SelectCondition<>(property, factory);
342354
}
343355

356+
/**
357+
* Start the definition of the filter condition for a {@code status} property.
358+
* @param property The name of the property as it appears in the database, or the
359+
* property ID
360+
* @return a new {@link StatusCondition} instance
361+
*/
362+
public StatusCondition<T> status(String property) {
363+
return new StatusCondition<>(property, factory);
364+
}
365+
344366
static abstract sealed class Condition<T extends Filter> {
345367

346368
private final String property;
@@ -393,6 +415,39 @@ public T isNotEqualTo(boolean value) {
393415

394416
}
395417

418+
/**
419+
* Filter condition for a {@code files} property.
420+
*
421+
* @param <T> the type of the target filter
422+
*/
423+
public static final class FilesCondition<T extends Filter> extends Condition<T> {
424+
425+
private FilesCondition(String property, NotionPropertyFilterFactory<T> factory) {
426+
super(property, factory);
427+
}
428+
429+
/**
430+
* Return database entries where the property value does not contain any data.
431+
* @return a filter with the newly defined condition
432+
*/
433+
public T isEmpty() {
434+
FilesFilter filesFilter = new FilesFilter();
435+
filesFilter.setEmpty(true);
436+
return toFilter(notionPropertyFilter -> notionPropertyFilter.setFile(filesFilter));
437+
}
438+
439+
/**
440+
* Return database entries where the property value contains data.
441+
* @return a filter with the newly defined condition
442+
*/
443+
public T isNotEmpty() {
444+
FilesFilter filesFilter = new FilesFilter();
445+
filesFilter.setNotEmpty(true);
446+
return toFilter(notionPropertyFilter -> notionPropertyFilter.setFile(filesFilter));
447+
}
448+
449+
}
450+
396451
/**
397452
* Filter condition for a {@code multi-select} property.
398453
*
@@ -610,6 +665,62 @@ public T isNotEmpty() {
610665

611666
}
612667

668+
/**
669+
* Filter condition for a {@code status} property.
670+
*
671+
* @param <T> the type of the target filter
672+
*/
673+
public static final class StatusCondition<T extends Filter> extends Condition<T> {
674+
675+
private StatusCondition(String property, NotionPropertyFilterFactory<T> factory) {
676+
super(property, factory);
677+
}
678+
679+
/**
680+
* Return database entries where the property value matches the provided one.
681+
* @param value the value to compare the property value against
682+
* @return a filter with the newly defined condition
683+
*/
684+
public T isEqualTo(String value) {
685+
StatusFilter statusFilter = new StatusFilter();
686+
statusFilter.setEquals(value);
687+
return toFilter(notionPropertyFilter -> notionPropertyFilter.setStatus(statusFilter));
688+
}
689+
690+
/**
691+
* Return database entries where the property value does not match the
692+
* provided one.
693+
* @param value the value to compare the property value against
694+
* @return a filter with the newly defined condition
695+
*/
696+
public T isNotEqualTo(String value) {
697+
StatusFilter statusFilter = new StatusFilter();
698+
statusFilter.setDoesNotEqual(value);
699+
return toFilter(notionPropertyFilter -> notionPropertyFilter.setStatus(statusFilter));
700+
}
701+
702+
/**
703+
* Return database entries where the property value does not contain any data.
704+
* @return a filter with the newly defined condition
705+
*/
706+
public T isEmpty() {
707+
StatusFilter statusFilter = new StatusFilter();
708+
statusFilter.setEmpty(true);
709+
return toFilter(notionPropertyFilter -> notionPropertyFilter.setStatus(statusFilter));
710+
}
711+
712+
/**
713+
* Return database entries where the property value contains data.
714+
* @return a filter with the newly defined condition
715+
*/
716+
public T isNotEmpty() {
717+
StatusFilter statusFilter = new StatusFilter();
718+
statusFilter.setNotEmpty(true);
719+
return toFilter(notionPropertyFilter -> notionPropertyFilter.setStatus(statusFilter));
720+
}
721+
722+
}
723+
613724
}
614725

615726
}

spring-batch-notion/src/test/java/org/springframework/batch/extensions/notion/FilterTests.java

+63-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
import notion.api.v1.model.databases.query.filter.PropertyFilter;
2020
import notion.api.v1.model.databases.query.filter.QueryTopLevelFilter;
2121
import notion.api.v1.model.databases.query.filter.condition.CheckboxFilter;
22+
import notion.api.v1.model.databases.query.filter.condition.FilesFilter;
2223
import notion.api.v1.model.databases.query.filter.condition.MultiSelectFilter;
2324
import notion.api.v1.model.databases.query.filter.condition.NumberFilter;
2425
import notion.api.v1.model.databases.query.filter.condition.SelectFilter;
26+
import notion.api.v1.model.databases.query.filter.condition.StatusFilter;
2527
import org.junit.jupiter.params.ParameterizedTest;
2628
import org.junit.jupiter.params.provider.Arguments;
2729
import org.junit.jupiter.params.provider.FieldSource;
@@ -70,6 +72,26 @@ void toQueryTopLevelFilter(Filter underTest, QueryTopLevelFilter expected) {
7072
}))))
7173
.toList();
7274

75+
static final List<Arguments> FILES_FILTERS = List.of( //
76+
arguments( //
77+
where().files("property").isEmpty(), //
78+
supply(() -> {
79+
FilesFilter filesFilter = new FilesFilter();
80+
filesFilter.setEmpty(true);
81+
PropertyFilter propertyFilter = new PropertyFilter("property");
82+
propertyFilter.setFile(filesFilter);
83+
return propertyFilter;
84+
})),
85+
arguments( //
86+
where().files("property").isNotEmpty(), //
87+
supply(() -> {
88+
FilesFilter filesFilter = new FilesFilter();
89+
filesFilter.setNotEmpty(true);
90+
PropertyFilter propertyFilter = new PropertyFilter("property");
91+
propertyFilter.setFile(filesFilter);
92+
return propertyFilter;
93+
})));
94+
7395
static final List<Arguments> MULTI_SELECT_FILTERS = List.of( //
7496
arguments( //
7597
where().multiSelect("property").contains("value"), //
@@ -220,11 +242,51 @@ void toQueryTopLevelFilter(Filter underTest, QueryTopLevelFilter expected) {
220242
return propertyFilter;
221243
})));
222244

245+
static final List<Arguments> STATUS_FILTERS = List.of( //
246+
arguments( //
247+
where().status("property").isEqualTo("value"), //
248+
supply(() -> {
249+
StatusFilter statusFilter = new StatusFilter();
250+
statusFilter.setEquals("value");
251+
PropertyFilter propertyFilter = new PropertyFilter("property");
252+
propertyFilter.setStatus(statusFilter);
253+
return propertyFilter;
254+
})),
255+
arguments( //
256+
where().status("property").isNotEqualTo("value"), //
257+
supply(() -> {
258+
StatusFilter statusFilter = new StatusFilter();
259+
statusFilter.setDoesNotEqual("value");
260+
PropertyFilter propertyFilter = new PropertyFilter("property");
261+
propertyFilter.setStatus(statusFilter);
262+
return propertyFilter;
263+
})),
264+
arguments( //
265+
where().status("property").isEmpty(), //
266+
supply(() -> {
267+
StatusFilter statusFilter = new StatusFilter();
268+
statusFilter.setEmpty(true);
269+
PropertyFilter propertyFilter = new PropertyFilter("property");
270+
propertyFilter.setStatus(statusFilter);
271+
return propertyFilter;
272+
})),
273+
arguments( //
274+
where().status("property").isNotEmpty(), //
275+
supply(() -> {
276+
StatusFilter statusFilter = new StatusFilter();
277+
statusFilter.setNotEmpty(true);
278+
PropertyFilter propertyFilter = new PropertyFilter("property");
279+
propertyFilter.setStatus(statusFilter);
280+
return propertyFilter;
281+
})));
282+
223283
static final List<Arguments> PROPERTY_FILTERS = Stream.of( //
224284
CHECKBOX_FILTERS, //
285+
FILES_FILTERS, //
225286
MULTI_SELECT_FILTERS, //
226287
NUMBER_FILTERS, //
227-
SELECT_FILTERS) //
288+
SELECT_FILTERS, //
289+
STATUS_FILTERS) //
228290
.flatMap(List::stream)
229291
.toList();
230292

0 commit comments

Comments
 (0)