mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +00:00
Implement RecordScriptTestInterface.execute, to fix record-script testing from UI
This commit is contained in:
@ -22,13 +22,34 @@
|
|||||||
package com.kingsrook.qqq.backend.core.actions.scripts;
|
package com.kingsrook.qqq.backend.core.actions.scripts;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import com.kingsrook.qqq.backend.core.actions.scripts.logging.BuildScriptLogAndScriptLogLineExecutionLogger;
|
||||||
|
import com.kingsrook.qqq.backend.core.actions.tables.GetAction;
|
||||||
|
import com.kingsrook.qqq.backend.core.actions.tables.QueryAction;
|
||||||
|
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||||
import com.kingsrook.qqq.backend.core.model.actions.scripts.ExecuteCodeInput;
|
import com.kingsrook.qqq.backend.core.model.actions.scripts.ExecuteCodeInput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.scripts.RunAdHocRecordScriptInput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.scripts.RunAdHocRecordScriptOutput;
|
||||||
import com.kingsrook.qqq.backend.core.model.actions.scripts.TestScriptInput;
|
import com.kingsrook.qqq.backend.core.model.actions.scripts.TestScriptInput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.scripts.TestScriptOutput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.tables.get.GetInput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QCriteriaOperator;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QFilterCriteria;
|
||||||
|
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.code.AdHocScriptCodeReference;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
|
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.fields.QFieldType;
|
||||||
|
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.utils.CollectionUtils;
|
||||||
|
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
||||||
|
import com.kingsrook.qqq.backend.core.utils.ValueUtils;
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -48,6 +69,73 @@ public class RecordScriptTestInterface implements TestScriptActionInterface
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
@Override
|
||||||
|
public void execute(TestScriptInput input, TestScriptOutput output) throws QException
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Serializable scriptId = input.getInputValues().get("scriptId");
|
||||||
|
QRecord script = new GetAction().executeForRecord(new GetInput(Script.TABLE_NAME).withPrimaryKey(scriptId));
|
||||||
|
|
||||||
|
//////////////////////////////////////////////
|
||||||
|
// look up the records being tested against //
|
||||||
|
//////////////////////////////////////////////
|
||||||
|
String tableName = script.getValueString("tableName");
|
||||||
|
QTableMetaData table = QContext.getQInstance().getTable(tableName);
|
||||||
|
if(table == null)
|
||||||
|
{
|
||||||
|
throw (new QException("Could not find table [" + tableName + "] for script"));
|
||||||
|
}
|
||||||
|
|
||||||
|
String recordPrimaryKeyList = ValueUtils.getValueAsString(input.getInputValues().get("recordPrimaryKeyList"));
|
||||||
|
if(!StringUtils.hasContent(recordPrimaryKeyList))
|
||||||
|
{
|
||||||
|
throw (new QException("Record primary key list was not given."));
|
||||||
|
}
|
||||||
|
|
||||||
|
QueryOutput queryOutput = new QueryAction().execute(new QueryInput(tableName)
|
||||||
|
.withFilter(new QQueryFilter(new QFilterCriteria(table.getPrimaryKeyField(), QCriteriaOperator.IN, recordPrimaryKeyList.split(","))))
|
||||||
|
.withIncludeAssociations(true));
|
||||||
|
if(CollectionUtils.nullSafeIsEmpty(queryOutput.getRecords()))
|
||||||
|
{
|
||||||
|
throw (new QException("No records were found by the given primary keys."));
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////
|
||||||
|
// set up & run the action //
|
||||||
|
/////////////////////////////
|
||||||
|
RunAdHocRecordScriptInput runAdHocRecordScriptInput = new RunAdHocRecordScriptInput();
|
||||||
|
runAdHocRecordScriptInput.setRecordList(queryOutput.getRecords());
|
||||||
|
|
||||||
|
BuildScriptLogAndScriptLogLineExecutionLogger executionLogger = new BuildScriptLogAndScriptLogLineExecutionLogger(null, null);
|
||||||
|
runAdHocRecordScriptInput.setLogger(executionLogger);
|
||||||
|
|
||||||
|
runAdHocRecordScriptInput.setTableName(tableName);
|
||||||
|
runAdHocRecordScriptInput.setCodeReference((AdHocScriptCodeReference) input.getCodeReference());
|
||||||
|
RunAdHocRecordScriptOutput runAdHocRecordScriptOutput = new RunAdHocRecordScriptOutput();
|
||||||
|
new RunAdHocRecordScriptAction().run(runAdHocRecordScriptInput, runAdHocRecordScriptOutput);
|
||||||
|
|
||||||
|
/////////////////////////////////
|
||||||
|
// send outputs back to caller //
|
||||||
|
/////////////////////////////////
|
||||||
|
output.setScriptLog(executionLogger.getScriptLog());
|
||||||
|
output.setScriptLogLines(executionLogger.getScriptLogLines());
|
||||||
|
if(runAdHocRecordScriptOutput.getException().isPresent())
|
||||||
|
{
|
||||||
|
output.setException(runAdHocRecordScriptOutput.getException().get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(QException e)
|
||||||
|
{
|
||||||
|
output.setException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
Reference in New Issue
Block a user