Merge remote-tracking branch 'origin/integration/sprint-28' into feature/CTLE-503-optimization-weather-api-data

# Conflicts:
#	qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/tables/QueryAction.java
#	qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/frontend/QFrontendTableMetaData.java
#	qqq-backend-module-api/src/main/java/com/kingsrook/qqq/backend/module/api/actions/BaseAPIActionUtil.java
#	qqq-middleware-api/src/main/java/com/kingsrook/qqq/api/actions/QRecordApiAdapter.java
This commit is contained in:
2023-07-03 15:38:55 -05:00
104 changed files with 7092 additions and 516 deletions

View File

@ -38,6 +38,8 @@ import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldType;
import com.kingsrook.qqq.backend.core.model.metadata.tables.AssociatedScript;
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
import com.kingsrook.qqq.backend.core.model.scripts.Script;
import com.kingsrook.qqq.backend.core.model.scripts.ScriptRevisionFile;
import com.kingsrook.qqq.backend.core.model.scripts.ScriptsMetaDataProvider;
import com.kingsrook.qqq.backend.core.modules.backend.implementations.memory.MemoryRecordStore;
import com.kingsrook.qqq.backend.core.utils.TestUtils;
@ -100,7 +102,8 @@ class StoreAssociatedScriptActionTest extends BaseTest
StoreAssociatedScriptInput storeAssociatedScriptInput = new StoreAssociatedScriptInput();
storeAssociatedScriptInput.setTableName(TestUtils.TABLE_NAME_PERSON_MEMORY);
storeAssociatedScriptInput.setRecordPrimaryKey(1);
storeAssociatedScriptInput.setCode("var i = 0;");
String code = "var i = 0;";
storeAssociatedScriptInput.setCode(code);
storeAssociatedScriptInput.setCommitMessage("Test commit");
storeAssociatedScriptInput.setFieldName("testScriptId");
StoreAssociatedScriptOutput storeAssociatedScriptOutput = new StoreAssociatedScriptOutput();
@ -110,26 +113,33 @@ class StoreAssociatedScriptActionTest extends BaseTest
///////////////////////////////////////////////
new StoreAssociatedScriptAction().run(storeAssociatedScriptInput, storeAssociatedScriptOutput);
assertValueInField(instance, TestUtils.TABLE_NAME_PERSON_MEMORY, 1, "testScriptId", 1);
assertValueInField(instance, "script", 1, "currentScriptRevisionId", 1);
assertValueInField(instance, Script.TABLE_NAME, 1, "currentScriptRevisionId", 1);
assertValueInField(instance, ScriptRevisionFile.TABLE_NAME, 1, "contents", code);
////////////////////////////////////////////
// add 2nd version of script for record 1 //
////////////////////////////////////////////
storeAssociatedScriptInput.setCode("var i = 1;");
code = "var i = 1;";
storeAssociatedScriptInput.setCode(code);
storeAssociatedScriptInput.setCommitMessage("2nd commit");
new StoreAssociatedScriptAction().run(storeAssociatedScriptInput, storeAssociatedScriptOutput);
assertValueInField(instance, TestUtils.TABLE_NAME_PERSON_MEMORY, 1, "testScriptId", 1);
assertValueInField(instance, "script", 1, "currentScriptRevisionId", 2);
assertValueInField(instance, Script.TABLE_NAME, 1, "currentScriptRevisionId", 2);
assertValueInField(instance, ScriptRevisionFile.TABLE_NAME, 2, "contents", code);
assertValueInField(instance, ScriptRevisionFile.TABLE_NAME, 2, "scriptRevisionId", 2);
///////////////////////////////////////////////
// insert 1st version of script for record 3 //
///////////////////////////////////////////////
code = "var i = 2;";
storeAssociatedScriptInput.setRecordPrimaryKey(3);
storeAssociatedScriptInput.setCode("var i = 2;");
storeAssociatedScriptInput.setCode(code);
storeAssociatedScriptInput.setCommitMessage("First Commit here");
new StoreAssociatedScriptAction().run(storeAssociatedScriptInput, storeAssociatedScriptOutput);
assertValueInField(instance, TestUtils.TABLE_NAME_PERSON_MEMORY, 3, "testScriptId", 2);
assertValueInField(instance, "script", 2, "currentScriptRevisionId", 3);
assertValueInField(instance, Script.TABLE_NAME, 2, "currentScriptRevisionId", 3);
assertValueInField(instance, ScriptRevisionFile.TABLE_NAME, 3, "contents", code);
assertValueInField(instance, ScriptRevisionFile.TABLE_NAME, 3, "scriptRevisionId", 3);
/////////////////////////////////////
// make sure no script on record 2 //
@ -146,7 +156,7 @@ class StoreAssociatedScriptActionTest extends BaseTest
new StoreAssociatedScriptAction().run(storeAssociatedScriptInput, storeAssociatedScriptOutput);
assertValueInField(instance, TestUtils.TABLE_NAME_PERSON_MEMORY, 1, "testScriptId", 1);
assertValueInField(instance, TestUtils.TABLE_NAME_PERSON_MEMORY, 1, "otherScriptId", 3);
assertValueInField(instance, "script", 3, "currentScriptRevisionId", 4);
assertValueInField(instance, Script.TABLE_NAME, 3, "currentScriptRevisionId", 4);
}

View File

@ -28,13 +28,21 @@ import java.util.List;
import com.kingsrook.qqq.backend.core.BaseTest;
import com.kingsrook.qqq.backend.core.actions.async.AsyncRecordPipeLoop;
import com.kingsrook.qqq.backend.core.actions.reporting.RecordPipe;
import com.kingsrook.qqq.backend.core.actions.tables.helpers.QueryStatManager;
import com.kingsrook.qqq.backend.core.context.QContext;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QFilterOrderBy;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryOutput;
import com.kingsrook.qqq.backend.core.model.data.QRecord;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.tables.Capability;
import com.kingsrook.qqq.backend.core.model.querystats.QueryStat;
import com.kingsrook.qqq.backend.core.model.querystats.QueryStatMetaDataProvider;
import com.kingsrook.qqq.backend.core.model.session.QSession;
import com.kingsrook.qqq.backend.core.model.tables.QQQTablesMetaDataProvider;
import com.kingsrook.qqq.backend.core.modules.backend.implementations.mock.MockQueryAction;
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
import com.kingsrook.qqq.backend.core.utils.TestUtils;
@ -390,6 +398,59 @@ class QueryActionTest extends BaseTest
/*******************************************************************************
**
*******************************************************************************/
@Test
void testQueryManager() throws QException
{
//////////////////////////////////////////////////////////////////////////////////////////////////////////
// add tables for QueryStats, and turn them on in the memory backend, then start the query-stat manager //
//////////////////////////////////////////////////////////////////////////////////////////////////////////
QInstance qInstance = QContext.getQInstance();
qInstance.getBackend(TestUtils.MEMORY_BACKEND_NAME).withCapability(Capability.QUERY_STATS);
new QQQTablesMetaDataProvider().defineAll(qInstance, TestUtils.MEMORY_BACKEND_NAME, TestUtils.MEMORY_BACKEND_NAME, null);
new QueryStatMetaDataProvider().defineAll(qInstance, TestUtils.MEMORY_BACKEND_NAME, null);
QueryStatManager.getInstance().start(QContext.getQInstance(), QSession::new);
/////////////////////////////////////////////////////////////////////////////////
// insert some order "trees", then query them, so some stats will get recorded //
/////////////////////////////////////////////////////////////////////////////////
insert2OrdersWith3Lines3LineExtrinsicsAnd4OrderExtrinsicAssociations();
QueryInput queryInput = new QueryInput();
queryInput.setTableName(TestUtils.TABLE_NAME_ORDER);
queryInput.setIncludeAssociations(true);
queryInput.setFilter(new QQueryFilter().withOrderBy(new QFilterOrderBy("id")));
QContext.pushAction(queryInput);
QueryOutput queryOutput = new QueryAction().execute(queryInput);
////////////////////////////////////////////////////////////
// run the stat manager (so we don't have to wait for it) //
////////////////////////////////////////////////////////////
QueryStatManager.getInstance().storeStatsNow();
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// stat manager expects to be ran in a thread, where it needs to clear context, so reset context after it //
////////////////////////////////////////////////////////////////////////////////////////////////////////////
QContext.init(qInstance, new QSession());
////////////////////////////////////////////////
// query to see that some stats were inserted //
////////////////////////////////////////////////
queryInput = new QueryInput();
queryInput.setTableName(QueryStat.TABLE_NAME);
QContext.pushAction(queryInput);
queryOutput = new QueryAction().execute(queryInput);
///////////////////////////////////////////////////////////////////////////////////
// selecting all of those associations should have caused (at least?) 4 queries. //
// this is the most basic test here, but we'll take it. //
///////////////////////////////////////////////////////////////////////////////////
assertThat(queryOutput.getRecords().size()).isGreaterThanOrEqualTo(4);
}
/*******************************************************************************
**
*******************************************************************************/

View File

@ -30,10 +30,10 @@ import java.util.Map;
import com.kingsrook.qqq.backend.core.BaseTest;
import com.kingsrook.qqq.backend.core.context.QContext;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.templates.ConvertHtmlToPdfInput;
import com.kingsrook.qqq.backend.core.model.actions.templates.RenderTemplateInput;
import com.kingsrook.qqq.backend.core.model.actions.templates.RenderTemplateOutput;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.templates.ConvertHtmlToPdfInput;
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.junit.jupiter.api.Test;

View File

@ -25,8 +25,8 @@ package com.kingsrook.qqq.backend.core.actions.templates;
import java.util.Map;
import com.kingsrook.qqq.backend.core.BaseTest;
import com.kingsrook.qqq.backend.core.exceptions.QException;
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.actions.templates.RenderTemplateInput;
import com.kingsrook.qqq.backend.core.model.actions.templates.RenderTemplateOutput;
import com.kingsrook.qqq.backend.core.model.templates.TemplateType;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -30,8 +30,10 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
/*******************************************************************************
@ -224,6 +226,53 @@ class QMetaDataVariableInterpreterTest extends BaseTest
/*******************************************************************************
**
*******************************************************************************/
@Test
void testGetBooleanFromPropertyOrEnvironment()
{
QMetaDataVariableInterpreter interpreter = new QMetaDataVariableInterpreter();
//////////////////////////////////////////////////////////
// if neither prop nor env is set, get back the default //
//////////////////////////////////////////////////////////
assertFalse(interpreter.getBooleanFromPropertyOrEnvironment("notSet", "NOT_SET", false));
assertTrue(interpreter.getBooleanFromPropertyOrEnvironment("notSet", "NOT_SET", true));
/////////////////////////////////////////////
// unrecognized values are same as not set //
/////////////////////////////////////////////
System.setProperty("unrecognized", "asdf");
interpreter.setEnvironmentOverrides(Map.of("UNRECOGNIZED", "1234"));
assertFalse(interpreter.getBooleanFromPropertyOrEnvironment("unrecognized", "UNRECOGNIZED", false));
assertTrue(interpreter.getBooleanFromPropertyOrEnvironment("unrecognized", "UNRECOGNIZED", true));
/////////////////////////////////
// if only prop is set, get it //
/////////////////////////////////
assertFalse(interpreter.getBooleanFromPropertyOrEnvironment("foo.enabled", "FOO_ENABLED", false));
System.setProperty("foo.enabled", "true");
assertTrue(interpreter.getBooleanFromPropertyOrEnvironment("foo.enabled", "FOO_ENABLED", false));
////////////////////////////////
// if only env is set, get it //
////////////////////////////////
assertFalse(interpreter.getBooleanFromPropertyOrEnvironment("bar.enabled", "BAR_ENABLED", false));
interpreter.setEnvironmentOverrides(Map.of("BAR_ENABLED", "true"));
assertTrue(interpreter.getBooleanFromPropertyOrEnvironment("bar.enabled", "BAR_ENABLED", false));
///////////////////////////////////
// if both are set, get the prop //
///////////////////////////////////
System.setProperty("baz.enabled", "true");
interpreter.setEnvironmentOverrides(Map.of("BAZ_ENABLED", "false"));
assertTrue(interpreter.getBooleanFromPropertyOrEnvironment("baz.enabled", "BAZ_ENABLED", true));
assertTrue(interpreter.getBooleanFromPropertyOrEnvironment("baz.enabled", "BAZ_ENABLED", false));
}
/*******************************************************************************
**
*******************************************************************************/

View File

@ -23,10 +23,14 @@ package com.kingsrook.qqq.backend.core.model.data;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import com.kingsrook.qqq.backend.core.BaseTest;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.data.testentities.Item;
import com.kingsrook.qqq.backend.core.model.data.testentities.ItemWithPrimitives;
import com.kingsrook.qqq.backend.core.model.data.testentities.LineItem;
import com.kingsrook.qqq.backend.core.model.data.testentities.Order;
import com.kingsrook.qqq.backend.core.model.metadata.fields.DisplayFormat;
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldType;
@ -34,6 +38,7 @@ import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ -119,6 +124,29 @@ class QRecordEntityTest extends BaseTest
/*******************************************************************************
**
*******************************************************************************/
@Test
void testQRecordFromJoinToItem() throws QException
{
QRecord qRecord = new QRecord()
.withValue("item.sku", "WXYZ-9876")
.withValue("item.description", "Items are cool")
.withValue("item.quantity", 42)
.withValue("item.price", new BigDecimal("3.50"))
.withValue("item.featured", false);
Item item = QRecordEntity.fromQRecord(Item.class, qRecord, "item.");
assertEquals("WXYZ-9876", item.getSku());
assertEquals("Items are cool", item.getDescription());
assertEquals(42, item.getQuantity());
assertEquals(new BigDecimal("3.50"), item.getPrice());
assertFalse(item.getFeatured());
}
/*******************************************************************************
**
*******************************************************************************/
@ -281,7 +309,103 @@ class QRecordEntityTest extends BaseTest
assertEquals(QFieldType.STRING, qTableMetaData.getField("sku").getType());
assertEquals(QFieldType.INTEGER, qTableMetaData.getField("quantity").getType());
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testOrderWithAssociationsToQRecord() throws QException
{
Order order = new Order();
order.setOrderNo("ORD001");
order.setLineItems(List.of(
new LineItem().withSku("ABC").withQuantity(1),
new LineItem().withSku("DEF").withQuantity(2)
));
QRecord qRecord = order.toQRecord();
assertEquals("ORD001", qRecord.getValueString("orderNo"));
List<QRecord> lineItems = qRecord.getAssociatedRecords().get("lineItems");
assertNotNull(lineItems);
assertEquals(2, lineItems.size());
assertEquals("ABC", lineItems.get(0).getValueString("sku"));
assertEquals(1, lineItems.get(0).getValueInteger("quantity"));
assertEquals("DEF", lineItems.get(1).getValueString("sku"));
assertEquals(2, lineItems.get(1).getValueInteger("quantity"));
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testOrderWithoutAssociationsToQRecord() throws QException
{
Order order = new Order();
order.setOrderNo("ORD001");
order.setLineItems(null);
QRecord qRecord = order.toQRecord();
assertEquals("ORD001", qRecord.getValueString("orderNo"));
List<QRecord> lineItems = qRecord.getAssociatedRecords().get("lineItems");
assertNull(lineItems);
order.setLineItems(new ArrayList<>());
qRecord = order.toQRecord();
lineItems = qRecord.getAssociatedRecords().get("lineItems");
assertNotNull(lineItems);
assertEquals(0, lineItems.size());
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testQRecordWithAssociationsToOrder() throws QException
{
QRecord qRecord = new QRecord()
.withValue("orderNo", "ORD002")
.withAssociatedRecords("lineItems", List.of(
new QRecord().withValue("sku", "AB12").withValue("quantity", 42),
new QRecord().withValue("sku", "XY89").withValue("quantity", 47)
));
Order order = qRecord.toEntity(Order.class);
assertEquals("ORD002", order.getOrderNo());
assertEquals(2, order.getLineItems().size());
assertEquals("AB12", order.getLineItems().get(0).getSku());
assertEquals(42, order.getLineItems().get(0).getQuantity());
assertEquals("XY89", order.getLineItems().get(1).getSku());
assertEquals(47, order.getLineItems().get(1).getQuantity());
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testQRecordWithoutAssociationsToOrder() throws QException
{
QRecord qRecord = new QRecord().withValue("orderNo", "ORD002");
Order order = qRecord.toEntity(Order.class);
assertEquals("ORD002", order.getOrderNo());
assertNull(order.getLineItems());
qRecord.withAssociatedRecords("lineItems", null);
order = qRecord.toEntity(Order.class);
assertNull(order.getLineItems());
qRecord.withAssociatedRecords("lineItems", new ArrayList<>());
order = qRecord.toEntity(Order.class);
assertNotNull(order.getLineItems());
assertEquals(0, order.getLineItems().size());
}
}

View File

@ -43,6 +43,7 @@ public class Item extends QRecordEntity
@QField(isEditable = false, displayFormat = DisplayFormat.COMMAS)
private Integer quantity;
@QField()
private BigDecimal price;
@QField(backendName = "is_featured")

View File

@ -23,6 +23,7 @@ package com.kingsrook.qqq.backend.core.model.data.testentities;
import java.math.BigDecimal;
import com.kingsrook.qqq.backend.core.model.data.QField;
import com.kingsrook.qqq.backend.core.model.data.QRecordEntity;
@ -31,11 +32,20 @@ import com.kingsrook.qqq.backend.core.model.data.QRecordEntity;
*******************************************************************************/
public class ItemWithPrimitives extends QRecordEntity
{
private String sku;
private String description;
private int quantity;
@QField()
private String sku;
@QField()
private String description;
@QField()
private int quantity;
@QField()
private BigDecimal price;
private boolean featured;
@QField()
private boolean featured;

View File

@ -0,0 +1,102 @@
/*
* 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.data.testentities;
import com.kingsrook.qqq.backend.core.model.data.QField;
import com.kingsrook.qqq.backend.core.model.data.QRecordEntity;
/*******************************************************************************
** Sample of an entity that can be converted to & from a QRecord
*******************************************************************************/
public class LineItem extends QRecordEntity
{
@QField()
private String sku;
@QField()
private Integer quantity;
/*******************************************************************************
** Getter for sku
*******************************************************************************/
public String getSku()
{
return (this.sku);
}
/*******************************************************************************
** Setter for sku
*******************************************************************************/
public void setSku(String sku)
{
this.sku = sku;
}
/*******************************************************************************
** Fluent setter for sku
*******************************************************************************/
public LineItem withSku(String sku)
{
this.sku = sku;
return (this);
}
/*******************************************************************************
** Getter for quantity
*******************************************************************************/
public Integer getQuantity()
{
return (this.quantity);
}
/*******************************************************************************
** Setter for quantity
*******************************************************************************/
public void setQuantity(Integer quantity)
{
this.quantity = quantity;
}
/*******************************************************************************
** Fluent setter for quantity
*******************************************************************************/
public LineItem withQuantity(Integer quantity)
{
this.quantity = quantity;
return (this);
}
}

View File

@ -0,0 +1,104 @@
/*
* 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.data.testentities;
import java.util.List;
import com.kingsrook.qqq.backend.core.model.data.QAssociation;
import com.kingsrook.qqq.backend.core.model.data.QField;
import com.kingsrook.qqq.backend.core.model.data.QRecordEntity;
/*******************************************************************************
** Sample of an entity that can be converted to & from a QRecord
*******************************************************************************/
public class Order extends QRecordEntity
{
@QField()
private String orderNo;
@QAssociation(name = "lineItems")
private List<LineItem> lineItems;
/*******************************************************************************
** Getter for orderNo
*******************************************************************************/
public String getOrderNo()
{
return (this.orderNo);
}
/*******************************************************************************
** Setter for orderNo
*******************************************************************************/
public void setOrderNo(String orderNo)
{
this.orderNo = orderNo;
}
/*******************************************************************************
** Fluent setter for orderNo
*******************************************************************************/
public Order withOrderNo(String orderNo)
{
this.orderNo = orderNo;
return (this);
}
/*******************************************************************************
** Getter for lineItems
*******************************************************************************/
public List<LineItem> getLineItems()
{
return (this.lineItems);
}
/*******************************************************************************
** Setter for lineItems
*******************************************************************************/
public void setLineItems(List<LineItem> lineItems)
{
this.lineItems = lineItems;
}
/*******************************************************************************
** Fluent setter for lineItems
*******************************************************************************/
public Order withLineItems(List<LineItem> lineItems)
{
this.lineItems = lineItems;
return (this);
}
}

View File

@ -69,6 +69,16 @@ class QTableMetaDataTest extends BaseTest
// table:false & backend:false = false
assertFalse(new QTableMetaData().withoutCapability(capability).isCapabilityEnabled(new QBackendMetaData().withoutCapability(capability), capability));
// backend false, but then true = true
assertTrue(new QTableMetaData().isCapabilityEnabled(new QBackendMetaData().withoutCapability(capability).withCapability(capability), capability));
// backend true, but then false = false
assertFalse(new QTableMetaData().isCapabilityEnabled(new QBackendMetaData().withCapability(capability).withoutCapability(capability), capability));
// table true, but then false = true
assertFalse(new QTableMetaData().withCapability(capability).withoutCapability(capability).isCapabilityEnabled(new QBackendMetaData(), capability));
}
}

View File

@ -0,0 +1,81 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2023. 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.processes.implementations.scripts;
import java.io.Serializable;
import java.util.List;
import com.kingsrook.qqq.backend.core.BaseTest;
import com.kingsrook.qqq.backend.core.actions.scripts.RecordScriptTestInterface;
import com.kingsrook.qqq.backend.core.actions.tables.InsertAction;
import com.kingsrook.qqq.backend.core.context.QContext;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepInput;
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepOutput;
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertOutput;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
import com.kingsrook.qqq.backend.core.model.scripts.ScriptType;
import com.kingsrook.qqq.backend.core.model.scripts.ScriptsMetaDataProvider;
import com.kingsrook.qqq.backend.core.utils.TestUtils;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
/*******************************************************************************
** Unit test for LoadScriptTestDetailsProcessStep
*******************************************************************************/
class LoadScriptTestDetailsProcessStepTest extends BaseTest
{
/*******************************************************************************
**
*******************************************************************************/
@Test
void test() throws QException
{
QInstance qInstance = QContext.getQInstance();
new ScriptsMetaDataProvider().defineAll(qInstance, TestUtils.MEMORY_BACKEND_NAME, null);
InsertInput insertInput = new InsertInput();
insertInput.setTableName(ScriptType.TABLE_NAME);
insertInput.setRecords(List.of(new ScriptType()
.withName("TestScriptType")
.withTestScriptInterfaceName(RecordScriptTestInterface.class.getName())
.toQRecord()));
InsertOutput insertOutput = new InsertAction().execute(insertInput);
RunBackendStepInput input = new RunBackendStepInput();
input.addValue("scriptTypeId", insertOutput.getRecords().get(0).getValueInteger("id"));
RunBackendStepOutput output = new RunBackendStepOutput();
new LoadScriptTestDetailsProcessStep().run(input, output);
Serializable inputFields = output.getValue("testInputFields");
assertThat(inputFields).isInstanceOf(List.class);
List<QFieldMetaData> inputFieldsList = (List<QFieldMetaData>) inputFields;
assertEquals(1, inputFieldsList.size());
assertEquals("recordPrimaryKeyList", inputFieldsList.get(0).getName());
}
}

View File

@ -33,10 +33,12 @@ import com.kingsrook.qqq.backend.core.model.data.QRecord;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.scripts.Script;
import com.kingsrook.qqq.backend.core.model.scripts.ScriptRevision;
import com.kingsrook.qqq.backend.core.model.scripts.ScriptRevisionFile;
import com.kingsrook.qqq.backend.core.model.scripts.ScriptsMetaDataProvider;
import com.kingsrook.qqq.backend.core.utils.TestUtils;
import com.kingsrook.qqq.backend.core.utils.collections.MapBuilder;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
@ -51,7 +53,7 @@ class StoreScriptRevisionProcessStepTest extends BaseTest
**
*******************************************************************************/
@Test
void test() throws QException
void testSingleFileScriptType() throws QException
{
QInstance qInstance = QContext.getQInstance();
new ScriptsMetaDataProvider().defineAll(qInstance, TestUtils.MEMORY_BACKEND_NAME, null);
@ -59,13 +61,14 @@ class StoreScriptRevisionProcessStepTest extends BaseTest
Integer scriptId = 1701;
String scriptContents = "logger.log('Hi');";
TestUtils.insertRecords(qInstance, qInstance.getTable(Script.TABLE_NAME), List.of(new QRecord().withValue("id", 1701)));
TestUtils.insertRecords(qInstance, qInstance.getTable(Script.TABLE_NAME), List.of(new QRecord().withValue("id", scriptId)));
List<QRecord> scripts = TestUtils.queryTable(Script.TABLE_NAME);
assertNull(scripts.get(0).getValueInteger("currentScriptRevisionId"));
new StoreScriptRevisionProcessStep().run(new RunBackendStepInput().withValues(MapBuilder.of(
"scriptId", scriptId,
"contents", scriptContents
"fileNames", "script",
"fileContents:script", scriptContents
)), new RunBackendStepOutput());
scripts = TestUtils.queryTable(Script.TABLE_NAME);
@ -73,14 +76,19 @@ class StoreScriptRevisionProcessStepTest extends BaseTest
List<QRecord> scriptRevisions = TestUtils.queryTable(ScriptRevision.TABLE_NAME);
QRecord scriptRevision = scriptRevisions.get(0);
assertEquals(1701, scriptRevision.getValueInteger("scriptId"));
assertEquals(scriptId, scriptRevision.getValueInteger("scriptId"));
assertEquals(1, scriptRevision.getValueInteger("sequenceNo"));
assertEquals("Initial version", scriptRevision.getValueString("commitMessage"));
assertEquals(scriptContents, scriptRevision.getValueString("contents"));
List<QRecord> scriptRevisionFiles = TestUtils.queryTable(ScriptRevisionFile.TABLE_NAME);
QRecord scriptRevisionFile = scriptRevisionFiles.get(0);
assertEquals(scriptContents, scriptRevisionFile.getValueString("contents"));
String updatedScriptContents = "logger.log('Really, Hi');";
new StoreScriptRevisionProcessStep().run(new RunBackendStepInput().withValues(MapBuilder.of(
"scriptId", scriptId,
"contents", scriptContents
"fileNames", "script",
"fileContents:script", updatedScriptContents
)), new RunBackendStepOutput());
scripts = TestUtils.queryTable(Script.TABLE_NAME);
@ -88,10 +96,94 @@ class StoreScriptRevisionProcessStepTest extends BaseTest
scriptRevisions = TestUtils.queryTable(ScriptRevision.TABLE_NAME).stream().filter(r -> r.getValueInteger("id").equals(2)).collect(Collectors.toList());
scriptRevision = scriptRevisions.get(0);
assertEquals(1701, scriptRevision.getValueInteger("scriptId"));
Integer newScriptRevisionId = scriptRevision.getValueInteger("id");
assertEquals(scriptId, scriptRevision.getValueInteger("scriptId"));
assertEquals(2, scriptRevision.getValueInteger("sequenceNo"));
assertEquals("No commit message given", scriptRevision.getValueString("commitMessage"));
assertEquals(scriptContents, scriptRevision.getValueString("contents"));
scriptRevisionFiles = TestUtils.queryTable(ScriptRevisionFile.TABLE_NAME);
scriptRevisionFile = scriptRevisionFiles.stream().filter(r -> r.getValueInteger("scriptRevisionId").equals(newScriptRevisionId)).findFirst().get();
assertEquals(updatedScriptContents, scriptRevisionFile.getValueString("contents"));
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testMultiFileScriptType() throws QException
{
QInstance qInstance = QContext.getQInstance();
new ScriptsMetaDataProvider().defineAll(qInstance, TestUtils.MEMORY_BACKEND_NAME, null);
Integer scriptId = 1701;
String scriptContents = "logger.log('Hi');";
String templateContents = "<h1>Hey</h1>";
TestUtils.insertRecords(qInstance, qInstance.getTable(Script.TABLE_NAME), List.of(new QRecord().withValue("id", scriptId)));
List<QRecord> scripts = TestUtils.queryTable(Script.TABLE_NAME);
assertNull(scripts.get(0).getValueInteger("currentScriptRevisionId"));
RunBackendStepInput runBackendStepInput = new RunBackendStepInput();
runBackendStepInput.addValue("scriptId", scriptId);
runBackendStepInput.addValue("fileNames", "script,template");
runBackendStepInput.addValue("fileContents:script", scriptContents);
runBackendStepInput.addValue("fileContents:template", templateContents);
new StoreScriptRevisionProcessStep().run(runBackendStepInput, new RunBackendStepOutput());
scripts = TestUtils.queryTable(Script.TABLE_NAME);
assertEquals(1, scripts.get(0).getValueInteger("currentScriptRevisionId"));
List<QRecord> scriptRevisions = TestUtils.queryTable(ScriptRevision.TABLE_NAME);
QRecord scriptRevision = scriptRevisions.get(0);
assertEquals(scriptId, scriptRevision.getValueInteger("scriptId"));
assertEquals(1, scriptRevision.getValueInteger("sequenceNo"));
assertEquals("Initial version", scriptRevision.getValueString("commitMessage"));
assertNull(scriptRevision.getValueString("contents"));
List<QRecord> scriptRevisionFiles = TestUtils.queryTable(ScriptRevisionFile.TABLE_NAME);
assertThat(scriptRevisionFiles.stream().filter(srf -> srf.getValueString("fileName").equals("script")).findFirst())
.isPresent().get()
.matches(r -> r.getValueString("contents").equals(scriptContents));
assertThat(scriptRevisionFiles.stream().filter(srf -> srf.getValueString("fileName").equals("template")).findFirst())
.isPresent().get()
.matches(r -> r.getValueString("contents").equals(templateContents));
////////////////////////////
// now add a new revision //
////////////////////////////
String updatedScriptContents = "logger.log('Really, Hi');";
String updatedTemplateContents = "<h1>Hey, what's up</h1>";
runBackendStepInput = new RunBackendStepInput();
runBackendStepInput.addValue("scriptId", scriptId);
runBackendStepInput.addValue("fileNames", "script,template");
runBackendStepInput.addValue("fileContents:script", updatedScriptContents);
runBackendStepInput.addValue("fileContents:template", updatedTemplateContents);
runBackendStepInput.addValue("commitMessage", "Updated files");
new StoreScriptRevisionProcessStep().run(runBackendStepInput, new RunBackendStepOutput());
scripts = TestUtils.queryTable(Script.TABLE_NAME);
assertEquals(2, scripts.get(0).getValueInteger("currentScriptRevisionId"));
scriptRevisions = TestUtils.queryTable(ScriptRevision.TABLE_NAME).stream().filter(r -> r.getValueInteger("id").equals(2)).collect(Collectors.toList());
scriptRevision = scriptRevisions.get(0);
assertEquals(scriptId, scriptRevision.getValueInteger("scriptId"));
assertEquals(2, scriptRevision.getValueInteger("id"));
assertEquals(2, scriptRevision.getValueInteger("sequenceNo"));
assertEquals("Updated files", scriptRevision.getValueString("commitMessage"));
assertNull(scriptRevision.getValueString("contents"));
scriptRevisionFiles = TestUtils.queryTable(ScriptRevisionFile.TABLE_NAME);
assertThat(scriptRevisionFiles.stream().filter(srf -> srf.getValueString("fileName").equals("script") && srf.getValueInteger("scriptRevisionId").equals(2)).findFirst())
.isPresent().get()
.matches(r -> r.getValueString("contents").equals(updatedScriptContents));
assertThat(scriptRevisionFiles.stream().filter(srf -> srf.getValueString("fileName").equals("template") && srf.getValueInteger("scriptRevisionId").equals(2)).findFirst())
.isPresent().get()
.matches(r -> r.getValueString("contents").equals(updatedTemplateContents));
}
}

View File

@ -0,0 +1,95 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2023. 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.processes.implementations.scripts;
import java.util.ArrayList;
import java.util.List;
import com.kingsrook.qqq.backend.core.BaseTest;
import com.kingsrook.qqq.backend.core.actions.scripts.RecordScriptTestInterface;
import com.kingsrook.qqq.backend.core.actions.tables.InsertAction;
import com.kingsrook.qqq.backend.core.context.QContext;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepInput;
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepOutput;
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertOutput;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.scripts.Script;
import com.kingsrook.qqq.backend.core.model.scripts.ScriptType;
import com.kingsrook.qqq.backend.core.model.scripts.ScriptsMetaDataProvider;
import com.kingsrook.qqq.backend.core.utils.TestUtils;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/*******************************************************************************
** Unit test for TestScriptProcessStep
*******************************************************************************/
class TestScriptProcessStepTest extends BaseTest
{
/*******************************************************************************
**
*******************************************************************************/
@Test
void test() throws QException
{
QInstance qInstance = QContext.getQInstance();
new ScriptsMetaDataProvider().defineAll(qInstance, TestUtils.MEMORY_BACKEND_NAME, null);
InsertInput insertInput = new InsertInput();
insertInput.setTableName(ScriptType.TABLE_NAME);
insertInput.setRecords(List.of(new ScriptType()
.withName("TestScriptType")
.withTestScriptInterfaceName(RecordScriptTestInterface.class.getName())
.toQRecord()));
InsertOutput insertOutput = new InsertAction().execute(insertInput);
insertInput = new InsertInput();
insertInput.setTableName(Script.TABLE_NAME);
insertInput.setRecords(List.of(new Script()
.withName("TestScript")
.withScriptTypeId(insertOutput.getRecords().get(0).getValueInteger("id"))
.withTableName(TestUtils.TABLE_NAME_SHAPE)
.toQRecord()));
insertOutput = new InsertAction().execute(insertInput);
RunBackendStepInput input = new RunBackendStepInput();
input.addValue("scriptId", insertOutput.getRecords().get(0).getValueInteger("id"));
TestUtils.insertDefaultShapes(qInstance);
input.addValue("recordPrimaryKeyList", "1");
input.addValue("fileNames", new ArrayList<>(List.of("script.js")));
input.addValue("fileContents:script.js", "logger.log('oh my.')");
RunBackendStepOutput output = new RunBackendStepOutput();
new TestScriptProcessStep().run(input, output);
//////////////////////////////////////////////////////////////////
// expect an error because the javascript module isn't available //
//////////////////////////////////////////////////////////////////
assertNotNull(output.getValue("exception"));
assertThat((Exception) output.getValue("exception")).hasRootCauseInstanceOf(ClassNotFoundException.class);
}
}

View File

@ -23,17 +23,24 @@ package com.kingsrook.qqq.backend.core.utils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.function.Function;
import com.google.gson.reflect.TypeToken;
import com.kingsrook.qqq.backend.core.BaseTest;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ -544,4 +551,47 @@ class CollectionUtilsTest extends BaseTest
assertEquals(List.of(1, 2, 3), CollectionUtils.mergeLists(null, List.of(1, 2, 3), null));
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testUseOrWrap()
{
assertNull(CollectionUtils.useOrWrap((Collection<?>) null, TypeToken.get(ArrayList.class)));
assertNull(CollectionUtils.useOrWrap((Map<?, ?>) null, TypeToken.get(HashMap.class)));
{
List<String> originalList = new ArrayList<>(List.of("A", "B", "C"));
ArrayList<String> reallyArrayList = CollectionUtils.useOrWrap(originalList, new TypeToken<>() {});
assertSame(originalList, reallyArrayList);
}
{
List<String> originalList = new LinkedList<>(List.of("A", "B", "C"));
ArrayList<String> reallyArrayList = CollectionUtils.useOrWrap(originalList, new TypeToken<>() {});
assertNotSame(originalList, reallyArrayList);
assertEquals(ArrayList.class, reallyArrayList.getClass());
}
assertEquals(ArrayList.class, CollectionUtils.useOrWrap(new LinkedList<>(), TypeToken.get(ArrayList.class)).getClass());
{
Map<String, Integer> originalMap = new HashMap<>(Map.of("A", 1, "B", 2));
HashMap<String, Integer> reallyHashMap = CollectionUtils.useOrWrap(originalMap, new TypeToken<>() {});
assertSame(originalMap, reallyHashMap);
}
{
Map<String, Integer> originalMap = new TreeMap<>(Map.of("A", 1, "B", 2));
HashMap<String, Integer> reallyHashMap = CollectionUtils.useOrWrap(originalMap, new TypeToken<>() {});
assertNotSame(originalMap, reallyHashMap);
assertEquals(HashMap.class, reallyHashMap.getClass());
}
assertEquals(TreeMap.class, CollectionUtils.useOrWrap(new Hashtable<>(), TypeToken.get(TreeMap.class)).getClass());
}
}