Add aggregateAction; Add renderTemplateAction

This commit is contained in:
2022-11-18 16:30:48 -06:00
parent 1d1461deea
commit 105b2c92c9
26 changed files with 2030 additions and 82 deletions

View File

@ -0,0 +1,40 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2022. 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.actions.interfaces;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.tables.aggregate.AggregateInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.aggregate.AggregateOutput;
/*******************************************************************************
** Interface for the Aggregate action.
**
*******************************************************************************/
public interface AggregateInterface
{
/*******************************************************************************
**
*******************************************************************************/
AggregateOutput execute(AggregateInput aggregateInput) throws QException;
}

View File

@ -0,0 +1,53 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2022. 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.actions.tables;
import com.kingsrook.qqq.backend.core.actions.ActionHelper;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.tables.aggregate.AggregateInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.aggregate.AggregateOutput;
import com.kingsrook.qqq.backend.core.modules.backend.QBackendModuleDispatcher;
import com.kingsrook.qqq.backend.core.modules.backend.QBackendModuleInterface;
/*******************************************************************************
** Action to run an aggregate against a table.
**
*******************************************************************************/
public class AggregateAction
{
/*******************************************************************************
**
*******************************************************************************/
public AggregateOutput execute(AggregateInput aggregateInput) throws QException
{
ActionHelper.validateSession(aggregateInput);
QBackendModuleDispatcher qBackendModuleDispatcher = new QBackendModuleDispatcher();
QBackendModuleInterface qModule = qBackendModuleDispatcher.getQBackendModule(aggregateInput.getBackend());
// todo pre-customization - just get to modify the request?
AggregateOutput aggregateOutput = qModule.getAggregateInterface().execute(aggregateInput);
// todo post-customization - can do whatever w/ the result if you want
return aggregateOutput;
}
}

View File

@ -0,0 +1,94 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2022. 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.actions.templates;
import java.io.StringWriter;
import java.util.Map;
import com.kingsrook.qqq.backend.core.actions.AbstractQActionFunction;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.AbstractActionInput;
import com.kingsrook.qqq.backend.core.model.templates.RenderTemplateInput;
import com.kingsrook.qqq.backend.core.model.templates.RenderTemplateOutput;
import com.kingsrook.qqq.backend.core.model.templates.TemplateType;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.context.Context;
/*******************************************************************************
** Basic action to render a template!
*******************************************************************************/
public class RenderTemplateAction extends AbstractQActionFunction<RenderTemplateInput, RenderTemplateOutput>
{
/*******************************************************************************
**
*******************************************************************************/
@Override
public RenderTemplateOutput execute(RenderTemplateInput input) throws QException
{
RenderTemplateOutput output = new RenderTemplateOutput();
if(TemplateType.VELOCITY.equals(input.getTemplateType()))
{
Velocity.init();
Context context = new VelocityContext(input.getContext());
StringWriter stringWriter = new StringWriter();
Velocity.evaluate(context, stringWriter, "logTag", input.getCode());
output.setResult(stringWriter.getBuffer().toString());
}
else
{
throw (new QException("Unsupported Template Type: " + input.getTemplateType()));
}
return (output);
}
/*******************************************************************************
** Most convenient static wrapper to render a Velocity template.
*******************************************************************************/
public static String renderVelocity(AbstractActionInput parentActionInput, Map<String, Object> context, String code) throws QException
{
return (render(parentActionInput, TemplateType.VELOCITY, context, code));
}
/*******************************************************************************
** Convenient static wrapper to render a template of an arbitrary type (language).
*******************************************************************************/
public static String render(AbstractActionInput parentActionInput, TemplateType templateType, Map<String, Object> context, String code) throws QException
{
RenderTemplateInput renderTemplateInput = new RenderTemplateInput(parentActionInput.getInstance());
renderTemplateInput.setSession(parentActionInput.getSession());
renderTemplateInput.setCode(code);
renderTemplateInput.setContext(context);
renderTemplateInput.setTemplateType(templateType);
RenderTemplateOutput output = new RenderTemplateAction().execute(renderTemplateInput);
return (output.getResult());
}
}

View File

@ -462,9 +462,25 @@ public class QInstanceEnricher
.withTableName(table.getName())
.withIsHidden(true);
List<QFieldMetaData> editableFields = table.getFields().values().stream()
.filter(QFieldMetaData::getIsEditable)
.toList();
List<QFieldMetaData> editableFields = new ArrayList<>();
for(QFieldSection section : CollectionUtils.nonNullList(table.getSections()))
{
for(String fieldName : CollectionUtils.nonNullList(section.getFieldNames()))
{
try
{
QFieldMetaData field = table.getField(fieldName);
if(field.getIsEditable())
{
editableFields.add(field);
}
}
catch(Exception e)
{
// shrug?
}
}
}
String fieldsForHelpText = editableFields.stream()
.map(QFieldMetaData::getLabel)

View File

@ -114,6 +114,7 @@ public class QInstanceValidator
}
catch(Exception e)
{
LOG.error("Error enriching instance prior to validation", e);
throw (new QInstanceValidationException("Error enriching qInstance prior to validation.", e));
}

View File

@ -0,0 +1,156 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2022. 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.aggregate;
import java.io.Serializable;
import java.util.Objects;
/*******************************************************************************
**
*******************************************************************************/
public class Aggregate implements Serializable
{
private String fieldName;
private AggregateOperator operator;
/*******************************************************************************
**
*******************************************************************************/
public Aggregate()
{
}
/*******************************************************************************
**
*******************************************************************************/
@Override
public boolean equals(Object o)
{
if(this == o)
{
return true;
}
if(o == null || getClass() != o.getClass())
{
return false;
}
Aggregate aggregate = (Aggregate) o;
return Objects.equals(fieldName, aggregate.fieldName) && operator == aggregate.operator;
}
/*******************************************************************************
**
*******************************************************************************/
@Override
public int hashCode()
{
return Objects.hash(fieldName, operator);
}
/*******************************************************************************
**
*******************************************************************************/
public Aggregate(String fieldName, AggregateOperator operator)
{
this.fieldName = fieldName;
this.operator = operator;
}
/*******************************************************************************
** Getter for fieldName
**
*******************************************************************************/
public String getFieldName()
{
return fieldName;
}
/*******************************************************************************
** Setter for fieldName
**
*******************************************************************************/
public void setFieldName(String fieldName)
{
this.fieldName = fieldName;
}
/*******************************************************************************
** Fluent setter for fieldName
**
*******************************************************************************/
public Aggregate withFieldName(String fieldName)
{
this.fieldName = fieldName;
return (this);
}
/*******************************************************************************
** Getter for operator
**
*******************************************************************************/
public AggregateOperator getOperator()
{
return operator;
}
/*******************************************************************************
** Setter for operator
**
*******************************************************************************/
public void setOperator(AggregateOperator operator)
{
this.operator = operator;
}
/*******************************************************************************
** Fluent setter for operator
**
*******************************************************************************/
public Aggregate withOperator(AggregateOperator operator)
{
this.operator = operator;
return (this);
}
}

View File

@ -0,0 +1,195 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2022. 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.aggregate;
import java.util.ArrayList;
import java.util.List;
import com.kingsrook.qqq.backend.core.model.actions.AbstractTableActionInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
/*******************************************************************************
** Input data for the Count action
**
*******************************************************************************/
public class AggregateInput extends AbstractTableActionInput
{
private QQueryFilter filter;
private List<Aggregate> aggregates;
private List<String> groupByFieldNames;
/*******************************************************************************
**
*******************************************************************************/
public AggregateInput()
{
}
/*******************************************************************************
**
*******************************************************************************/
public AggregateInput(QInstance instance)
{
super(instance);
}
/*******************************************************************************
** Getter for filter
**
*******************************************************************************/
public QQueryFilter getFilter()
{
return filter;
}
/*******************************************************************************
** Setter for filter
**
*******************************************************************************/
public void setFilter(QQueryFilter filter)
{
this.filter = filter;
}
/*******************************************************************************
** Fluent setter for filter
**
*******************************************************************************/
public AggregateInput withFilter(QQueryFilter filter)
{
setFilter(filter);
return (this);
}
/*******************************************************************************
** Getter for aggregates
**
*******************************************************************************/
public List<Aggregate> getAggregates()
{
return aggregates;
}
/*******************************************************************************
** Setter for aggregates
**
*******************************************************************************/
public void setAggregates(List<Aggregate> aggregates)
{
this.aggregates = aggregates;
}
/*******************************************************************************
** Fluent setter for aggregates
**
*******************************************************************************/
public AggregateInput withAggregates(List<Aggregate> aggregates)
{
this.aggregates = aggregates;
return (this);
}
/*******************************************************************************
** Fluent setter for aggregates
**
*******************************************************************************/
public AggregateInput withAggregate(Aggregate aggregate)
{
if(this.aggregates == null)
{
this.aggregates = new ArrayList<>();
}
this.aggregates.add(aggregate);
return (this);
}
/*******************************************************************************
** Getter for groupByFieldNames
**
*******************************************************************************/
public List<String> getGroupByFieldNames()
{
return groupByFieldNames;
}
/*******************************************************************************
** Setter for groupByFieldNames
**
*******************************************************************************/
public void setGroupByFieldNames(List<String> groupByFieldNames)
{
this.groupByFieldNames = groupByFieldNames;
}
/*******************************************************************************
** Fluent setter for groupByFieldNames
**
*******************************************************************************/
public AggregateInput withGroupByFieldNames(List<String> groupByFieldNames)
{
this.groupByFieldNames = groupByFieldNames;
return (this);
}
/*******************************************************************************
** Fluent setter for groupByFieldNames
**
*******************************************************************************/
public AggregateInput withGroupByFieldName(String groupByFieldName)
{
if(this.groupByFieldNames == null)
{
this.groupByFieldNames = new ArrayList<>();
}
this.groupByFieldNames.add(groupByFieldName);
return (this);
}
}

View File

@ -0,0 +1,35 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2022. 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.aggregate;
/*******************************************************************************
**
*******************************************************************************/
public enum AggregateOperator
{
COUNT,
SUM,
MIN,
MAX,
AVG
}

View File

@ -0,0 +1,59 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2022. 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.aggregate;
import java.util.List;
import com.kingsrook.qqq.backend.core.model.actions.AbstractActionOutput;
/*******************************************************************************
** Output for an aggregate action
**
*******************************************************************************/
public class AggregateOutput extends AbstractActionOutput
{
private List<AggregateResult> results;
/*******************************************************************************
** Getter for results
**
*******************************************************************************/
public List<AggregateResult> getResults()
{
return results;
}
/*******************************************************************************
** Setter for results
**
*******************************************************************************/
public void setResults(List<AggregateResult> results)
{
this.results = results;
}
}

View File

@ -0,0 +1,158 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2022. 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.aggregate;
import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Map;
/*******************************************************************************
**
*******************************************************************************/
public class AggregateResult
{
private Map<Aggregate, Serializable> aggregateValues = new LinkedHashMap<>();
private Map<String, Serializable> groupByValues = new LinkedHashMap<>();
/*******************************************************************************
** Getter for aggregateValues
**
*******************************************************************************/
public Map<Aggregate, Serializable> getAggregateValues()
{
return aggregateValues;
}
/*******************************************************************************
** Setter for aggregateValues
**
*******************************************************************************/
public void setAggregateValues(Map<Aggregate, Serializable> aggregateValues)
{
this.aggregateValues = aggregateValues;
}
/*******************************************************************************
** Fluent setter for aggregateValues
**
*******************************************************************************/
public AggregateResult withAggregateValues(Map<Aggregate, Serializable> aggregateValues)
{
this.aggregateValues = aggregateValues;
return (this);
}
/*******************************************************************************
** Fluent setter for groupByValues
**
*******************************************************************************/
public AggregateResult withAggregateValue(Aggregate aggregate, Serializable value)
{
if(this.aggregateValues == null)
{
this.aggregateValues = new LinkedHashMap<>();
}
this.aggregateValues.put(aggregate, value);
return (this);
}
/*******************************************************************************
**
*******************************************************************************/
public Serializable getAggregateValue(Aggregate aggregate)
{
return (this.aggregateValues.get(aggregate));
}
/*******************************************************************************
** Getter for groupByValues
**
*******************************************************************************/
public Map<String, Serializable> getGroupByValues()
{
return groupByValues;
}
/*******************************************************************************
** Setter for groupByValues
**
*******************************************************************************/
public void setGroupByValues(Map<String, Serializable> groupByValues)
{
this.groupByValues = groupByValues;
}
/*******************************************************************************
** Fluent setter for groupByValues
**
*******************************************************************************/
public AggregateResult withGroupByValues(Map<String, Serializable> groupByValues)
{
this.groupByValues = groupByValues;
return (this);
}
/*******************************************************************************
** Fluent setter for groupByValues
**
*******************************************************************************/
public AggregateResult withGroupByValue(String fieldName, Serializable value)
{
if(this.groupByValues == null)
{
this.groupByValues = new LinkedHashMap<>();
}
this.groupByValues.put(fieldName, value);
return (this);
}
/*******************************************************************************
**
*******************************************************************************/
public Serializable getGroupByValue(String fieldName)
{
return (this.groupByValues.get(fieldName));
}
}

View File

@ -0,0 +1,123 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2022. 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.aggregate;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QFilterOrderBy;
/*******************************************************************************
** Bean representing an element of a query order-by clause - ordering by an
** aggregate field.
**
*******************************************************************************/
public class QFilterOrderByAggregate extends QFilterOrderBy implements Cloneable
{
private Aggregate aggregate;
/*******************************************************************************
**
*******************************************************************************/
@Override
public QFilterOrderByAggregate clone()
{
return (QFilterOrderByAggregate) super.clone();
}
/*******************************************************************************
** Default no-arg constructor
*******************************************************************************/
public QFilterOrderByAggregate()
{
}
/*******************************************************************************
** Constructor that sets field name, but leaves default for isAscending (true)
*******************************************************************************/
public QFilterOrderByAggregate(Aggregate aggregate)
{
this.aggregate = aggregate;
}
/*******************************************************************************
** Constructor that takes field name and isAscending.
*******************************************************************************/
public QFilterOrderByAggregate(Aggregate aggregate, boolean isAscending)
{
this.aggregate = aggregate;
setIsAscending(isAscending);
}
/*******************************************************************************
** Getter for aggregate
**
*******************************************************************************/
public Aggregate getAggregate()
{
return aggregate;
}
/*******************************************************************************
** Setter for aggregate
**
*******************************************************************************/
public void setAggregate(Aggregate aggregate)
{
this.aggregate = aggregate;
}
/*******************************************************************************
** Fluent setter for aggregate
**
*******************************************************************************/
public QFilterOrderByAggregate withAggregate(Aggregate aggregate)
{
this.aggregate = aggregate;
return (this);
}
/*******************************************************************************
**
*******************************************************************************/
@Override
public String toString()
{
return (aggregate + " " + (getIsAscending() ? "ASC" : "DESC"));
}
}

View File

@ -24,6 +24,7 @@ package com.kingsrook.qqq.backend.core.model.actions.tables.query;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
import org.apache.logging.log4j.LogManager;
@ -73,6 +74,10 @@ public class QFilterCriteria implements Serializable, Cloneable
*******************************************************************************/
public QFilterCriteria()
{
///////////////////////////////
// don't let values be null. //
///////////////////////////////
values = new ArrayList<>();
}
@ -84,7 +89,31 @@ public class QFilterCriteria implements Serializable, Cloneable
{
this.fieldName = fieldName;
this.operator = operator;
this.values = values;
this.values = values == null ? new ArrayList<>() : values;
}
/*******************************************************************************
**
*******************************************************************************/
public QFilterCriteria(String fieldName, QCriteriaOperator operator, Serializable... values)
{
this.fieldName = fieldName;
this.operator = operator;
if(values == null || (values.length == 1 && values[0] == null))
{
////////////////////////////////////////////////////////////////////
// this ... could be a sign of an issue... debug juuuust in case? //
////////////////////////////////////////////////////////////////////
LOG.debug("null passed as singleton varargs array will be ignored");
this.values = new ArrayList<>();
}
else
{
this.values = Arrays.stream(values).toList();
}
}

View File

@ -24,6 +24,7 @@ package com.kingsrook.qqq.backend.core.model.actions.tables.query;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
import org.apache.logging.log4j.LogManager;
@ -57,6 +58,27 @@ public class QQueryFilter implements Serializable, Cloneable
/*******************************************************************************
** Constructor
**
*******************************************************************************/
public QQueryFilter()
{
}
/*******************************************************************************
** Constructor
**
*******************************************************************************/
public QQueryFilter(QFilterCriteria... criteria)
{
this.criteria = new ArrayList<>(Arrays.stream(criteria).toList());
}
/*******************************************************************************
**
*******************************************************************************/

View File

@ -0,0 +1,152 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2022. 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.templates;
import java.util.Map;
import com.kingsrook.qqq.backend.core.model.actions.AbstractActionInput;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
/*******************************************************************************
**
*******************************************************************************/
public class RenderTemplateInput extends AbstractActionInput
{
private String code; // todo - TemplateReference, like CodeReference??
private TemplateType templateType;
private Map<String, Object> context;
/*******************************************************************************
**
*******************************************************************************/
public RenderTemplateInput(QInstance instance)
{
super(instance);
}
/*******************************************************************************
** Getter for code
**
*******************************************************************************/
public String getCode()
{
return code;
}
/*******************************************************************************
** Setter for code
**
*******************************************************************************/
public void setCode(String code)
{
this.code = code;
}
/*******************************************************************************
** Fluent setter for code
**
*******************************************************************************/
public RenderTemplateInput withCode(String code)
{
this.code = code;
return (this);
}
/*******************************************************************************
** Getter for templateType
**
*******************************************************************************/
public TemplateType getTemplateType()
{
return templateType;
}
/*******************************************************************************
** Setter for templateType
**
*******************************************************************************/
public void setTemplateType(TemplateType templateType)
{
this.templateType = templateType;
}
/*******************************************************************************
** Fluent setter for templateType
**
*******************************************************************************/
public RenderTemplateInput withTemplateType(TemplateType templateType)
{
this.templateType = templateType;
return (this);
}
/*******************************************************************************
** Getter for context
**
*******************************************************************************/
public Map<String, Object> getContext()
{
return context;
}
/*******************************************************************************
** Setter for context
**
*******************************************************************************/
public void setContext(Map<String, Object> context)
{
this.context = context;
}
/*******************************************************************************
** Fluent setter for context
**
*******************************************************************************/
public RenderTemplateInput withContext(Map<String, Object> context)
{
this.context = context;
return (this);
}
}

View File

@ -0,0 +1,69 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2022. 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.templates;
import com.kingsrook.qqq.backend.core.model.actions.AbstractActionOutput;
/*******************************************************************************
**
*******************************************************************************/
public class RenderTemplateOutput extends AbstractActionOutput
{
private String result;
/*******************************************************************************
** Getter for result
**
*******************************************************************************/
public String getResult()
{
return result;
}
/*******************************************************************************
** Setter for result
**
*******************************************************************************/
public void setResult(String result)
{
this.result = result;
}
/*******************************************************************************
** Fluent setter for result
**
*******************************************************************************/
public RenderTemplateOutput withResult(String result)
{
this.result = result;
return (this);
}
}

View File

@ -0,0 +1,31 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2022. 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.templates;
/*******************************************************************************
**
*******************************************************************************/
public enum TemplateType
{
VELOCITY
}

View File

@ -22,6 +22,7 @@
package com.kingsrook.qqq.backend.core.modules.backend;
import com.kingsrook.qqq.backend.core.actions.interfaces.AggregateInterface;
import com.kingsrook.qqq.backend.core.actions.interfaces.CountInterface;
import com.kingsrook.qqq.backend.core.actions.interfaces.DeleteInterface;
import com.kingsrook.qqq.backend.core.actions.interfaces.GetInterface;
@ -116,6 +117,15 @@ public interface QBackendModuleInterface
return null;
}
/*******************************************************************************
**
*******************************************************************************/
default AggregateInterface getAggregateInterface()
{
throwNotImplemented("Aggregate");
return null;
}
/*******************************************************************************
**
*******************************************************************************/

View File

@ -0,0 +1,96 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2022. 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.actions.templates;
import java.util.Map;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.session.QSession;
import com.kingsrook.qqq.backend.core.model.templates.RenderTemplateInput;
import com.kingsrook.qqq.backend.core.model.templates.RenderTemplateOutput;
import com.kingsrook.qqq.backend.core.model.templates.TemplateType;
import com.kingsrook.qqq.backend.core.utils.TestUtils;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
/*******************************************************************************
** Unit test for RenderTemplateAction
*******************************************************************************/
class RenderTemplateActionTest
{
/*******************************************************************************
**
*******************************************************************************/
@Test
void test() throws QException
{
RenderTemplateInput renderTemplateInput = new RenderTemplateInput(TestUtils.defineInstance());
renderTemplateInput.setSession(new QSession());
renderTemplateInput.setCode("""
Hello, $name""");
renderTemplateInput.setContext(Map.of("name", "Darin"));
renderTemplateInput.setTemplateType(TemplateType.VELOCITY);
RenderTemplateOutput output = new RenderTemplateAction().execute(renderTemplateInput);
assertEquals("Hello, Darin", output.getResult());
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testConvenientWrapper() throws QException
{
RenderTemplateInput parentActionInput = new RenderTemplateInput(TestUtils.defineInstance());
parentActionInput.setSession(new QSession());
String template = "Hello, $name";
assertEquals("Hello, Darin", RenderTemplateAction.renderVelocity(parentActionInput, Map.of("name", "Darin"), template));
assertEquals("Hello, Tim", RenderTemplateAction.renderVelocity(parentActionInput, Map.of("name", "Tim"), template));
assertEquals("Hello, $name", RenderTemplateAction.renderVelocity(parentActionInput, Map.of(), template));
template = "Hello, $!name";
assertEquals("Hello, ", RenderTemplateAction.renderVelocity(parentActionInput, Map.of(), template));
assertEquals("Hello, ", RenderTemplateAction.renderVelocity(parentActionInput, null, template));
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testMissingType()
{
RenderTemplateInput parentActionInput = new RenderTemplateInput(TestUtils.defineInstance());
parentActionInput.setSession(new QSession());
assertThatThrownBy(() -> RenderTemplateAction.render(parentActionInput, null, Map.of("name", "Darin"), "Hello, $name"))
.isInstanceOf(QException.class)
.hasMessageContaining("Unsupported Template Type");
}
}

View File

@ -0,0 +1,75 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2022. 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;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
import static com.kingsrook.qqq.backend.core.model.actions.tables.query.QCriteriaOperator.EQUALS;
import static com.kingsrook.qqq.backend.core.model.actions.tables.query.QCriteriaOperator.IS_BLANK;
import static org.junit.jupiter.api.Assertions.assertEquals;
/*******************************************************************************
** Unit test for QFilterCriteria
*******************************************************************************/
class QFilterCriteriaTest
{
/*******************************************************************************
** Make sure that the constructors that takes a List or Serializable... and does
** the right thing - e.g., never making a List-of-List, or List of array, and
** that we never have null values - always an empty list as the degenerate case.
*******************************************************************************/
@Test
void test()
{
assertEquals(1, new QFilterCriteria("foo", EQUALS, "A").getValues().size());
assertEquals(1, new QFilterCriteria("foo", EQUALS, List.of("A")).getValues().size());
assertEquals(2, new QFilterCriteria("foo", EQUALS, List.of("A", "B")).getValues().size());
assertEquals(2, new QFilterCriteria("foo", EQUALS, "A", "B").getValues().size());
List<Serializable> list = List.of("A", "B", "C");
assertEquals(3, new QFilterCriteria("foo", EQUALS, list).getValues().size());
assertEquals(List.of("A", "B", "C"), new QFilterCriteria("foo", EQUALS, list).getValues());
Serializable[] array = new Serializable[] { "A", "B", "C", "D" };
assertEquals(4, new QFilterCriteria("foo", EQUALS, array).getValues().size());
assertEquals(List.of("A", "B", "C", "D"), new QFilterCriteria("foo", EQUALS, array).getValues());
assertEquals(3, new QFilterCriteria("foo", EQUALS, new ArrayList<>(list)).getValues().size());
assertEquals(List.of("A", "B", "C"), new QFilterCriteria("foo", EQUALS, new ArrayList<>(list)).getValues());
assertEquals(0, new QFilterCriteria("foo", IS_BLANK).getValues().size());
Serializable maybeNull = null;
assertEquals(0, new QFilterCriteria("foo", EQUALS, maybeNull).getValues().size());
List<Serializable> nullList = null;
assertEquals(0, new QFilterCriteria("foo", EQUALS, nullList).getValues().size());
assertEquals(0, new QFilterCriteria("foo", EQUALS, (List<Serializable>) null).getValues().size());
}
}