From 8c7e523e434a84b96769befadc1266b8f3b1ddb8 Mon Sep 17 00:00:00 2001 From: Darin Kelkhoff Date: Thu, 16 Jan 2025 10:23:22 -0600 Subject: [PATCH] Add concept of criteriaOptions - ways an application & backend can add modified behavior to a criteria --- .../actions/tables/query/CriteriaOption.java | 31 +++++++ .../tables/query/CriteriaOptionInterface.java | 30 +++++++ .../actions/tables/query/QFilterCriteria.java | 87 ++++++++++++++++++- .../actions/tables/query/QQueryFilter.java | 16 ++++ 4 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/query/CriteriaOption.java create mode 100644 qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/query/CriteriaOptionInterface.java diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/query/CriteriaOption.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/query/CriteriaOption.java new file mode 100644 index 00000000..e43cece8 --- /dev/null +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/query/CriteriaOption.java @@ -0,0 +1,31 @@ +/* + * QQQ - Low-code Application Framework for Engineers. + * Copyright (C) 2021-2025. Kingsrook, LLC + * 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States + * contact@kingsrook.com + * https://github.com/Kingsrook/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package com.kingsrook.qqq.backend.core.model.actions.tables.query; + + +/******************************************************************************* + ** + *******************************************************************************/ +public enum CriteriaOption implements CriteriaOptionInterface +{ + CASE_INSENSITIVE; +} diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/query/CriteriaOptionInterface.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/query/CriteriaOptionInterface.java new file mode 100644 index 00000000..44ffeb38 --- /dev/null +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/query/CriteriaOptionInterface.java @@ -0,0 +1,30 @@ +/* + * QQQ - Low-code Application Framework for Engineers. + * Copyright (C) 2021-2025. Kingsrook, LLC + * 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States + * contact@kingsrook.com + * https://github.com/Kingsrook/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package com.kingsrook.qqq.backend.core.model.actions.tables.query; + + +/******************************************************************************* + ** + *******************************************************************************/ +public interface CriteriaOptionInterface +{ +} diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/query/QFilterCriteria.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/query/QFilterCriteria.java index 118aacbf..dd5e7c8f 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/query/QFilterCriteria.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/query/QFilterCriteria.java @@ -26,8 +26,10 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.HashSet; import java.util.List; import java.util.Objects; +import java.util.Set; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.kingsrook.qqq.backend.core.logging.QLogger; import com.kingsrook.qqq.backend.core.model.actions.tables.query.serialization.QFilterCriteriaDeserializer; @@ -44,7 +46,7 @@ public class QFilterCriteria implements Serializable, Cloneable { private static final QLogger LOG = QLogger.getLogger(QFilterCriteria.class); - private String fieldName; + private String fieldName; private QCriteriaOperator operator; private List values; @@ -53,6 +55,8 @@ public class QFilterCriteria implements Serializable, Cloneable //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// private String otherFieldName; + private Set options = null; + /******************************************************************************* @@ -69,6 +73,13 @@ public class QFilterCriteria implements Serializable, Cloneable clone.values = new ArrayList<>(); clone.values.addAll(values); } + + if(options != null) + { + clone.options = new HashSet<>(); + clone.options.addAll(options); + } + return clone; } catch(CloneNotSupportedException e) @@ -385,4 +396,78 @@ public class QFilterCriteria implements Serializable, Cloneable return Objects.hash(fieldName, operator, values, otherFieldName); } + + + /******************************************************************************* + ** Getter for options + *******************************************************************************/ + public Set getOptions() + { + return (this.options); + } + + + + /******************************************************************************* + ** Setter for options + *******************************************************************************/ + public void setOptions(Set options) + { + this.options = options; + } + + + + /******************************************************************************* + ** Fluent setter for options + *******************************************************************************/ + public QFilterCriteria withOptions(Set options) + { + this.options = options; + return (this); + } + + + + /*************************************************************************** + ** + ***************************************************************************/ + public QFilterCriteria withOption(CriteriaOptionInterface option) + { + if(options == null) + { + options = new HashSet<>(); + } + options.add(option); + return (this); + } + + + + /*************************************************************************** + ** + ***************************************************************************/ + public QFilterCriteria withoutOption(CriteriaOptionInterface option) + { + if(options != null) + { + options.remove(option); + } + return (this); + } + + + /*************************************************************************** + ** + ***************************************************************************/ + public boolean hasOption(CriteriaOptionInterface option) + { + if(options == null) + { + return (false); + } + + return (options.contains(option)); + } + } diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/query/QQueryFilter.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/query/QQueryFilter.java index 0d18d56d..471bdcea 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/query/QQueryFilter.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/query/QQueryFilter.java @@ -853,4 +853,20 @@ public class QQueryFilter implements Serializable, Cloneable } + /*************************************************************************** + ** + ***************************************************************************/ + public void applyCriteriaOptionToAllCriteria(CriteriaOptionInterface criteriaOption) + { + for(QFilterCriteria criteria : CollectionUtils.nonNullList(this.criteria)) + { + criteria.withOption(criteriaOption); + } + + for(QQueryFilter subFilter : CollectionUtils.nonNullList(subFilters)) + { + subFilter.applyCriteriaOptionToAllCriteria(criteriaOption); + } + } + }