Skip to content

Commit 076d92f

Browse files
committed
Make changes to migration and filtering to support default date value
1 parent 67d6a03 commit 076d92f

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

‎src/main/java/org/brapi/test/BrAPITestServer/service/SearchQueryBuilder.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class SearchQueryBuilder<T> {
2626
private List<String> joinedTables = new ArrayList<>();
2727
private List<String> joinedFetchedTables = new ArrayList<>();
2828
private Class<T> clazz;
29+
private final String default_date = "1970-01-01";
2930

3031
public SearchQueryBuilder(Class<T> clazz) {
3132
this.selectClause = "SELECT distinct entity FROM " + clazz.getSimpleName() + " entity ";
@@ -202,7 +203,9 @@ public SearchQueryBuilder<T> appendLikeDate(String like, String columnName) {
202203
String paramName = paramFilterPattern(columnName);
203204

204205
if (like != null) {
205-
this.whereClause += " AND to_char(" + entityPrefix(columnName) + ", 'YYYY-MM-DD') LIKE :" + paramName + " ";
206+
this.whereClause += " AND to_char(" + entityPrefix(columnName) + ", 'YYYY-MM-DD') LIKE :" + paramName + " " +
207+
// Ensure we do not filter against the default date, which is effectively a NULL value for DeltaBreed's system.
208+
" AND to_char(" + entityPrefix(columnName) + ", 'YYYY-MM-DD') <> '" + default_date + "' ";
206209
this.params.put(paramName, "%" + like + "%");
207210
}
208211
return this;

‎src/main/resources/db/migration/V006_004__collate_germplasm_columns.sql‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,20 @@ ALTER TABLE germplasm
3636
ALTER TABLE germplasm
3737
ADD COLUMN created_date TIMESTAMP NOT NULL
3838
GENERATED ALWAYS AS (
39-
make_timestamp(
40-
substring(additional_info #>> '{createdDate}' from 7 for 4)::int, -- year
41-
substring(additional_info #>> '{createdDate}' from 4 for 2)::int, -- month
42-
substring(additional_info #>> '{createdDate}' from 1 for 2)::int, -- day
43-
substring(additional_info #>> '{createdDate}' from 12 for 2)::int, -- hour
44-
substring(additional_info #>> '{createdDate}' from 15 for 2)::int, -- minute
45-
substring(additional_info #>> '{createdDate}' from 18 for 2)::int -- second
46-
)
47-
) STORED;
39+
CASE
40+
WHEN additional_info #>> '{createdDate}' IS NULL
41+
THEN TIMESTAMP '1970-01-01 00:00:00'
42+
ELSE
43+
make_timestamp(
44+
substring(additional_info #>> '{createdDate}' from 7 for 4)::int, -- year
45+
substring(additional_info #>> '{createdDate}' from 4 for 2)::int, -- month
46+
substring(additional_info #>> '{createdDate}' from 1 for 2)::int, -- day
47+
substring(additional_info #>> '{createdDate}' from 12 for 2)::int, -- hour
48+
substring(additional_info #>> '{createdDate}' from 15 for 2)::int, -- minute
49+
substring(additional_info #>> '{createdDate}' from 18 for 2)::int -- second
50+
)
51+
END
52+
) STORED;
4853

4954
ALTER TABLE germplasm
5055
ADD COLUMN

0 commit comments

Comments
 (0)