You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2024/02/07 02:25:50 UTC
(james-project) 04/05: JAMES-2586 Improve PostgresVacationRepository
This is an automated email from the ASF dual-hosted git repository.
rcordier pushed a commit to branch postgresql
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit dadd591cb2bed75af97b21673294817ed3ac5346
Author: Quan Tran <hq...@linagora.com>
AuthorDate: Tue Feb 6 14:42:30 2024 +0700
JAMES-2586 Improve PostgresVacationRepository
---
.../apache/james/vacation/postgres/PostgresVacationModule.java | 3 ++-
.../james/vacation/postgres/PostgresVacationResponseDAO.java | 9 +++------
2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/server/data/data-postgres/src/main/java/org/apache/james/vacation/postgres/PostgresVacationModule.java b/server/data/data-postgres/src/main/java/org/apache/james/vacation/postgres/PostgresVacationModule.java
index c1deec31fd..8149ed53a7 100644
--- a/server/data/data-postgres/src/main/java/org/apache/james/vacation/postgres/PostgresVacationModule.java
+++ b/server/data/data-postgres/src/main/java/org/apache/james/vacation/postgres/PostgresVacationModule.java
@@ -37,7 +37,8 @@ public interface PostgresVacationModule {
Table<Record> TABLE_NAME = DSL.table("vacation_response");
Field<String> ACCOUNT_ID = DSL.field("account_id", SQLDataType.VARCHAR.notNull());
- Field<Boolean> IS_ENABLED = DSL.field("is_enabled", SQLDataType.BOOLEAN);
+ Field<Boolean> IS_ENABLED = DSL.field("is_enabled", SQLDataType.BOOLEAN.notNull()
+ .defaultValue(DSL.field("false", SQLDataType.BOOLEAN)));
Field<LocalDateTime> FROM_DATE = DSL.field("from_date", PostgresCommons.DataTypes.TIMESTAMP);
Field<LocalDateTime> TO_DATE = DSL.field("to_date", PostgresCommons.DataTypes.TIMESTAMP);
Field<String> TEXT = DSL.field("text", SQLDataType.VARCHAR);
diff --git a/server/data/data-postgres/src/main/java/org/apache/james/vacation/postgres/PostgresVacationResponseDAO.java b/server/data/data-postgres/src/main/java/org/apache/james/vacation/postgres/PostgresVacationResponseDAO.java
index 8131156da2..52e4328ffa 100644
--- a/server/data/data-postgres/src/main/java/org/apache/james/vacation/postgres/PostgresVacationResponseDAO.java
+++ b/server/data/data-postgres/src/main/java/org/apache/james/vacation/postgres/PostgresVacationResponseDAO.java
@@ -145,12 +145,9 @@ public class PostgresVacationResponseDAO {
return postgresExecutor.executeSingleRowOptional(dsl -> dsl.selectFrom(TABLE_NAME)
.where(ACCOUNT_ID.eq(accountId.getIdentifier())))
.map(recordOptional -> recordOptional.map(record -> Vacation.builder()
- .enabled(Optional.ofNullable(record.get(IS_ENABLED))
- .orElse(false))
- .fromDate(Optional.ofNullable(record.get(FROM_DATE, LocalDateTime.class))
- .map(LOCAL_DATE_TIME_ZONED_DATE_TIME_FUNCTION))
- .toDate(Optional.ofNullable(record.get(TO_DATE, LocalDateTime.class))
- .map(LOCAL_DATE_TIME_ZONED_DATE_TIME_FUNCTION))
+ .enabled(record.get(IS_ENABLED))
+ .fromDate(Optional.ofNullable(LOCAL_DATE_TIME_ZONED_DATE_TIME_FUNCTION.apply(record.get(FROM_DATE, LocalDateTime.class))))
+ .toDate(Optional.ofNullable(LOCAL_DATE_TIME_ZONED_DATE_TIME_FUNCTION.apply(record.get(TO_DATE, LocalDateTime.class))))
.subject(Optional.ofNullable(record.get(SUBJECT)))
.textBody(Optional.ofNullable(record.get(TEXT)))
.htmlBody(Optional.ofNullable(record.get(HTML)))
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org