mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-17 20:50:44 +00:00
Add concept of criteriaOptions - ways an application & backend can add modified behavior to a criteria
This commit is contained in:
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qqq.backend.core.model.actions.tables.query;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public enum CriteriaOption implements CriteriaOptionInterface
|
||||
{
|
||||
CASE_INSENSITIVE;
|
||||
}
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qqq.backend.core.model.actions.tables.query;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public interface CriteriaOptionInterface
|
||||
{
|
||||
}
|
@ -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<Serializable> values;
|
||||
|
||||
@ -53,6 +55,8 @@ public class QFilterCriteria implements Serializable, Cloneable
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
private String otherFieldName;
|
||||
|
||||
private Set<CriteriaOptionInterface> 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<CriteriaOptionInterface> getOptions()
|
||||
{
|
||||
return (this.options);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for options
|
||||
*******************************************************************************/
|
||||
public void setOptions(Set<CriteriaOptionInterface> options)
|
||||
{
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for options
|
||||
*******************************************************************************/
|
||||
public QFilterCriteria withOptions(Set<CriteriaOptionInterface> 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));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user