mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
Add deploymentMode as a field in QInstance; pass it into scripts (e.g., in executeCodeAction)
This commit is contained in:
@ -33,6 +33,7 @@ import com.kingsrook.qqq.backend.core.actions.scripts.logging.QCodeExecutionLogg
|
|||||||
import com.kingsrook.qqq.backend.core.actions.scripts.logging.ScriptExecutionLoggerInterface;
|
import com.kingsrook.qqq.backend.core.actions.scripts.logging.ScriptExecutionLoggerInterface;
|
||||||
import com.kingsrook.qqq.backend.core.actions.scripts.logging.StoreScriptLogAndScriptLogLineExecutionLogger;
|
import com.kingsrook.qqq.backend.core.actions.scripts.logging.StoreScriptLogAndScriptLogLineExecutionLogger;
|
||||||
import com.kingsrook.qqq.backend.core.actions.tables.QueryAction;
|
import com.kingsrook.qqq.backend.core.actions.tables.QueryAction;
|
||||||
|
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||||
import com.kingsrook.qqq.backend.core.exceptions.QCodeException;
|
import com.kingsrook.qqq.backend.core.exceptions.QCodeException;
|
||||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||||
import com.kingsrook.qqq.backend.core.logging.QLogger;
|
import com.kingsrook.qqq.backend.core.logging.QLogger;
|
||||||
@ -50,6 +51,7 @@ import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeType;
|
|||||||
import com.kingsrook.qqq.backend.core.model.scripts.ScriptRevision;
|
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.ScriptRevisionFile;
|
||||||
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
|
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
|
||||||
|
import com.kingsrook.qqq.backend.core.utils.ObjectUtils;
|
||||||
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
||||||
|
|
||||||
|
|
||||||
@ -112,6 +114,11 @@ public class ExecuteCodeAction
|
|||||||
context.putAll(input.getInput());
|
context.putAll(input.getInput());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////
|
||||||
|
// safely always set the deploymentMode //
|
||||||
|
//////////////////////////////////////////
|
||||||
|
context.put("deploymentMode", ObjectUtils.tryAndRequireNonNullElse(() -> QContext.getQInstance().getDeploymentMode(), null));
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
// set the qCodeExecutor into any context objects which are QCodeExecutorAware //
|
// set the qCodeExecutor into any context objects which are QCodeExecutorAware //
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -93,6 +93,7 @@ public class QInstance
|
|||||||
|
|
||||||
private Map<String, QSupplementalInstanceMetaData> supplementalMetaData = new LinkedHashMap<>();
|
private Map<String, QSupplementalInstanceMetaData> supplementalMetaData = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
private String deploymentMode;
|
||||||
private Map<String, String> environmentValues = new LinkedHashMap<>();
|
private Map<String, String> environmentValues = new LinkedHashMap<>();
|
||||||
private String defaultTimeZoneId = "UTC";
|
private String defaultTimeZoneId = "UTC";
|
||||||
|
|
||||||
@ -1165,4 +1166,36 @@ public class QInstance
|
|||||||
}
|
}
|
||||||
this.joinGraph = joinGraph;
|
this.joinGraph = joinGraph;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Getter for deploymentMode
|
||||||
|
*******************************************************************************/
|
||||||
|
public String getDeploymentMode()
|
||||||
|
{
|
||||||
|
return (this.deploymentMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Setter for deploymentMode
|
||||||
|
*******************************************************************************/
|
||||||
|
public void setDeploymentMode(String deploymentMode)
|
||||||
|
{
|
||||||
|
this.deploymentMode = deploymentMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Fluent setter for deploymentMode
|
||||||
|
*******************************************************************************/
|
||||||
|
public QInstance withDeploymentMode(String deploymentMode)
|
||||||
|
{
|
||||||
|
this.deploymentMode = deploymentMode;
|
||||||
|
return (this);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ import java.util.Map;
|
|||||||
import com.kingsrook.qqq.backend.core.actions.scripts.ExecuteCodeAction;
|
import com.kingsrook.qqq.backend.core.actions.scripts.ExecuteCodeAction;
|
||||||
import com.kingsrook.qqq.backend.core.actions.scripts.QCodeExecutor;
|
import com.kingsrook.qqq.backend.core.actions.scripts.QCodeExecutor;
|
||||||
import com.kingsrook.qqq.backend.core.actions.scripts.QCodeExecutorAware;
|
import com.kingsrook.qqq.backend.core.actions.scripts.QCodeExecutorAware;
|
||||||
|
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||||
import com.kingsrook.qqq.backend.core.exceptions.QCodeException;
|
import com.kingsrook.qqq.backend.core.exceptions.QCodeException;
|
||||||
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;
|
||||||
@ -307,6 +308,32 @@ class ExecuteCodeActionTest extends BaseTest
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
@Test
|
||||||
|
void testDeploymentModeIsInContext() throws QException
|
||||||
|
{
|
||||||
|
String scriptSource = """
|
||||||
|
return (deploymentMode);
|
||||||
|
""";
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// first, with no deployment mode in the qInstance, make sure we can run, but get a null output //
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
OneTestOutput oneTestOutput = testOne(null, scriptSource, new HashMap<>());
|
||||||
|
assertNull(oneTestOutput.executeCodeOutput.getOutput());
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
// next, set a deploymentMode, and assert that we get it back out. //
|
||||||
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
QContext.getQInstance().setDeploymentMode("unit-test");
|
||||||
|
oneTestOutput = testOne(null, scriptSource, new HashMap<>());
|
||||||
|
assertEquals("unit-test", oneTestOutput.executeCodeOutput.getOutput());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
Reference in New Issue
Block a user