diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/processes/implementations/scripts/TestScriptProcessStep.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/processes/implementations/scripts/TestScriptProcessStep.java index cf9df9df..2cd3544b 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/processes/implementations/scripts/TestScriptProcessStep.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/processes/implementations/scripts/TestScriptProcessStep.java @@ -74,11 +74,12 @@ public class TestScriptProcessStep implements BackendStep // get inputs // //////////////// Integer scriptId = input.getValueInteger("scriptId"); - String code = input.getValueString("code"); ScriptRevision scriptRevision = new ScriptRevision(); scriptRevision.setScriptId(scriptId); - scriptRevision.setContents(code); + scriptRevision.setContents(input.getValueString("code")); + scriptRevision.setApiName(input.getValueString("apiName")); + scriptRevision.setApiVersion(input.getValueString("apiVersion")); BuildScriptLogAndScriptLogLineExecutionLogger executionLogger = new BuildScriptLogAndScriptLogLineExecutionLogger(null, null); diff --git a/qqq-backend-module-api/src/test/java/com/kingsrook/qqq/backend/module/api/actions/BaseAPIActionUtilTest.java b/qqq-backend-module-api/src/test/java/com/kingsrook/qqq/backend/module/api/actions/BaseAPIActionUtilTest.java index 04275a80..3930d5b6 100644 --- a/qqq-backend-module-api/src/test/java/com/kingsrook/qqq/backend/module/api/actions/BaseAPIActionUtilTest.java +++ b/qqq-backend-module-api/src/test/java/com/kingsrook/qqq/backend/module/api/actions/BaseAPIActionUtilTest.java @@ -26,6 +26,7 @@ import java.nio.charset.StandardCharsets; import java.util.Base64; import java.util.List; import java.util.Map; +import java.util.concurrent.TimeUnit; import com.kingsrook.qqq.backend.core.actions.tables.CountAction; import com.kingsrook.qqq.backend.core.actions.tables.GetAction; import com.kingsrook.qqq.backend.core.actions.tables.InsertAction; @@ -47,6 +48,7 @@ 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.UniqueKey; import com.kingsrook.qqq.backend.core.utils.CollectionUtils; +import com.kingsrook.qqq.backend.core.utils.SleepUtils; import com.kingsrook.qqq.backend.module.api.BaseTest; import com.kingsrook.qqq.backend.module.api.TestUtils; import com.kingsrook.qqq.backend.module.api.exceptions.RateLimitException; @@ -524,9 +526,20 @@ class BaseAPIActionUtilTest extends BaseTest InsertOutput insertOutput = new InsertAction().execute(insertInput); assertEquals(6, insertOutput.getRecords().get(0).getValueInteger("id")); - QueryInput queryInput = new QueryInput(); - queryInput.setTableName(OutboundAPILog.TABLE_NAME); - QueryOutput apiLogRecords = new QueryAction().execute(queryInput); + ////////////////////////////////////////////////////////////////////////////////////////// + // the outbound api log is inserted async, so... do or do not, and sleep some if needed // + ////////////////////////////////////////////////////////////////////////////////////////// + QueryOutput apiLogRecords = null; + int tries = 0; + do + { + SleepUtils.sleep(10, TimeUnit.MILLISECONDS); + QueryInput queryInput = new QueryInput(); + queryInput.setTableName(OutboundAPILog.TABLE_NAME); + apiLogRecords = new QueryAction().execute(queryInput); + } + while(apiLogRecords.getRecords().isEmpty() && tries++ < 10); + assertEquals(1, apiLogRecords.getRecords().size()); assertEquals("POST", apiLogRecords.getRecords().get(0).getValueString("method")); } diff --git a/qqq-language-support-javascript/pom.xml b/qqq-language-support-javascript/pom.xml index ba2af5a4..0210a4a8 100644 --- a/qqq-language-support-javascript/pom.xml +++ b/qqq-language-support-javascript/pom.xml @@ -33,10 +33,8 @@ + - - 0.10 - 0.10 diff --git a/qqq-middleware-api/src/main/java/com/kingsrook/qqq/api/actions/ApiImplementation.java b/qqq-middleware-api/src/main/java/com/kingsrook/qqq/api/actions/ApiImplementation.java index e58533cd..ea25ac48 100644 --- a/qqq-middleware-api/src/main/java/com/kingsrook/qqq/api/actions/ApiImplementation.java +++ b/qqq-middleware-api/src/main/java/com/kingsrook/qqq/api/actions/ApiImplementation.java @@ -102,7 +102,7 @@ public class ApiImplementation { List badRequestMessages = new ArrayList<>(); - QTableMetaData table = validateTableAndVersion(tableApiName, apiInstanceMetaData, version, tableApiName, ApiOperation.QUERY_BY_QUERY_STRING); + QTableMetaData table = validateTableAndVersion(apiInstanceMetaData, version, tableApiName, ApiOperation.QUERY_BY_QUERY_STRING); String tableName = table.getName(); QueryInput queryInput = new QueryInput(); @@ -326,7 +326,7 @@ public class ApiImplementation *******************************************************************************/ public static Map insert(ApiInstanceMetaData apiInstanceMetaData, String version, String tableApiName, String body) throws QException { - QTableMetaData table = validateTableAndVersion(tableApiName, apiInstanceMetaData, version, tableApiName, ApiOperation.INSERT); + QTableMetaData table = validateTableAndVersion(apiInstanceMetaData, version, tableApiName, ApiOperation.INSERT); String tableName = table.getName(); InsertInput insertInput = new InsertInput(); @@ -392,7 +392,7 @@ public class ApiImplementation *******************************************************************************/ public static List> bulkInsert(ApiInstanceMetaData apiInstanceMetaData, String version, String tableApiName, String body) throws QException { - QTableMetaData table = validateTableAndVersion(tableApiName, apiInstanceMetaData, version, tableApiName, ApiOperation.BULK_INSERT); + QTableMetaData table = validateTableAndVersion(apiInstanceMetaData, version, tableApiName, ApiOperation.BULK_INSERT); String tableName = table.getName(); InsertInput insertInput = new InsertInput(); @@ -481,7 +481,7 @@ public class ApiImplementation *******************************************************************************/ public static Map get(ApiInstanceMetaData apiInstanceMetaData, String version, String tableApiName, String primaryKey) throws QException { - QTableMetaData table = validateTableAndVersion(tableApiName, apiInstanceMetaData, version, tableApiName, ApiOperation.GET); + QTableMetaData table = validateTableAndVersion(apiInstanceMetaData, version, tableApiName, ApiOperation.GET); String tableName = table.getName(); GetInput getInput = new GetInput(); @@ -516,7 +516,7 @@ public class ApiImplementation *******************************************************************************/ public static void update(ApiInstanceMetaData apiInstanceMetaData, String version, String tableApiName, String primaryKey, String body) throws QException { - QTableMetaData table = validateTableAndVersion(tableApiName, apiInstanceMetaData, version, tableApiName, ApiOperation.UPDATE); + QTableMetaData table = validateTableAndVersion(apiInstanceMetaData, version, tableApiName, ApiOperation.UPDATE); String tableName = table.getName(); UpdateInput updateInput = new UpdateInput(); @@ -586,7 +586,7 @@ public class ApiImplementation *******************************************************************************/ public static List> bulkUpdate(ApiInstanceMetaData apiInstanceMetaData, String version, String tableApiName, String body) throws QException { - QTableMetaData table = validateTableAndVersion(tableApiName, apiInstanceMetaData, version, tableApiName, ApiOperation.BULK_UPDATE); + QTableMetaData table = validateTableAndVersion(apiInstanceMetaData, version, tableApiName, ApiOperation.BULK_UPDATE); String tableName = table.getName(); UpdateInput updateInput = new UpdateInput(); @@ -698,7 +698,7 @@ public class ApiImplementation *******************************************************************************/ public static void delete(ApiInstanceMetaData apiInstanceMetaData, String version, String tableApiName, String primaryKey) throws QException { - QTableMetaData table = validateTableAndVersion(tableApiName, apiInstanceMetaData, version, tableApiName, ApiOperation.DELETE); + QTableMetaData table = validateTableAndVersion(apiInstanceMetaData, version, tableApiName, ApiOperation.DELETE); String tableName = table.getName(); DeleteInput deleteInput = new DeleteInput(); @@ -732,7 +732,7 @@ public class ApiImplementation *******************************************************************************/ public static List> bulkDelete(ApiInstanceMetaData apiInstanceMetaData, String version, String tableApiName, String body) throws QException { - QTableMetaData table = validateTableAndVersion(tableApiName, apiInstanceMetaData, version, tableApiName, ApiOperation.BULK_DELETE); + QTableMetaData table = validateTableAndVersion(apiInstanceMetaData, version, tableApiName, ApiOperation.BULK_DELETE); String tableName = table.getName(); DeleteInput deleteInput = new DeleteInput(); @@ -982,55 +982,53 @@ public class ApiImplementation /******************************************************************************* ** *******************************************************************************/ - public static QTableMetaData validateTableAndVersion(String path, ApiInstanceMetaData apiInstanceMetaData, String version, String tableApiName, ApiOperation operation) throws QNotFoundException + public static QTableMetaData validateTableAndVersion(ApiInstanceMetaData apiInstanceMetaData, String version, String tableApiName, ApiOperation operation) throws QNotFoundException { - QNotFoundException qNotFoundException = new QNotFoundException("Could not find any resources at path " + path); - QTableMetaData table = getTableByApiName(apiInstanceMetaData.getName(), version, tableApiName); LogPair[] logPairs = new LogPair[] { logPair("apiName", apiInstanceMetaData.getName()), logPair("version", version), logPair("tableApiName", tableApiName), logPair("operation", operation) }; if(table == null) { LOG.info("404 because table is null (tableApiName=" + tableApiName + ")", logPairs); - throw (qNotFoundException); + throw (new QNotFoundException("Could not find a table named " + tableApiName + " in this api.")); } if(BooleanUtils.isTrue(table.getIsHidden())) { LOG.info("404 because table isHidden", logPairs); - throw (qNotFoundException); + throw (new QNotFoundException("Could not find a table named " + tableApiName + " in this api.")); } ApiTableMetaDataContainer apiTableMetaDataContainer = ApiTableMetaDataContainer.of(table); if(apiTableMetaDataContainer == null) { LOG.info("404 because table apiMetaDataContainer is null", logPairs); - throw (qNotFoundException); + throw (new QNotFoundException("Could not find a table named " + tableApiName + " in this api.")); } ApiTableMetaData apiTableMetaData = apiTableMetaDataContainer.getApiTableMetaData(apiInstanceMetaData.getName()); if(apiTableMetaData == null) { LOG.info("404 because table apiMetaData is null", logPairs); - throw (qNotFoundException); + throw (new QNotFoundException("Could not find a table named " + tableApiName + " in this api.")); } if(BooleanUtils.isTrue(apiTableMetaData.getIsExcluded())) { LOG.info("404 because table is excluded", logPairs); - throw (qNotFoundException); + throw (new QNotFoundException("Could not find a table named " + tableApiName + " in this api.")); } if(!operation.isOperationEnabled(List.of(apiInstanceMetaData, apiTableMetaData))) { LOG.info("404 because api operation is not enabled", logPairs); - throw (qNotFoundException); + throw (new QNotFoundException("Cannot perform operation [" + operation + "] on table named " + tableApiName + " in this api.")); } if(!table.isCapabilityEnabled(QContext.getQInstance().getBackendForTable(table.getName()), operation.getCapability())) { LOG.info("404 because table capability is not enabled", logPairs); - throw (qNotFoundException); + throw (new QNotFoundException("Cannot perform operation [" + operation + "] on table named " + tableApiName + " in this api.")); } APIVersion requestApiVersion = new APIVersion(version); @@ -1038,13 +1036,13 @@ public class ApiImplementation if(CollectionUtils.nullSafeIsEmpty(supportedVersions) || !supportedVersions.contains(requestApiVersion)) { LOG.info("404 because requested version is not supported", logPairs); - throw (qNotFoundException); + throw (new QNotFoundException(version + " is not a supported version in this api.")); } if(!apiTableMetaData.getApiVersionRange().includes(requestApiVersion)) { LOG.info("404 because table version range does not include requested version", logPairs); - throw (qNotFoundException); + throw (new QNotFoundException(version + " is not a supported version for table " + tableApiName + " in this api.")); } return (table); diff --git a/qqq-middleware-api/src/test/java/com/kingsrook/qqq/api/javalin/QJavalinApiHandlerTest.java b/qqq-middleware-api/src/test/java/com/kingsrook/qqq/api/javalin/QJavalinApiHandlerTest.java index 58908fa6..a98d1a80 100644 --- a/qqq-middleware-api/src/test/java/com/kingsrook/qqq/api/javalin/QJavalinApiHandlerTest.java +++ b/qqq-middleware-api/src/test/java/com/kingsrook/qqq/api/javalin/QJavalinApiHandlerTest.java @@ -147,25 +147,29 @@ class QJavalinApiHandlerTest extends BaseTest @Test void testRandom404s() { - for(String method : new String[] { "get", "post", "patch", "delete" }) - { - assertErrorResponse(HttpStatus.NOT_FOUND_404, "Could not find any resources at path", Unirest.request(method, BASE_URL + "/api/" + VERSION + "/notATable/").asString()); - assertErrorResponse(HttpStatus.NOT_FOUND_404, "Could not find any resources at path", Unirest.request(method, BASE_URL + "/api/" + VERSION + "/notATable/notAnId").asString()); - assertErrorResponse(HttpStatus.NOT_FOUND_404, "Could not find any resources at path", Unirest.request(method, BASE_URL + "/api/" + VERSION + "/person/1/2").asString()); - assertErrorResponse(HttpStatus.NOT_FOUND_404, "Could not find any resources at path", Unirest.request(method, BASE_URL + "/api/foo").asString()); + assertErrorResponse(HttpStatus.NOT_FOUND_404, "Could not find any resources at path", Unirest.request("get", BASE_URL + "/api/" + VERSION + "/notATable/").asString()); + assertErrorResponse(HttpStatus.NOT_FOUND_404, "Could not find a table named notATable in this api", Unirest.request("get", BASE_URL + "/api/" + VERSION + "/notATable/notAnId").asString()); + assertErrorResponse(HttpStatus.NOT_FOUND_404, "Could not find any resources at path", Unirest.request("get", BASE_URL + "/api/" + VERSION + "/person/1/2").asString()); + assertErrorResponse(HttpStatus.NOT_FOUND_404, "Could not find any resources at path", Unirest.request("get", BASE_URL + "/api/foo").asString()); + assertErrorResponse(HttpStatus.OK_200, null, Unirest.request("get", BASE_URL + "/api/").asString()); // this path returns the doc site for a GET - if(method.equals("get")) - { - ////////////////////////////////////////////// - // this path returns the doc site for a GET // - ////////////////////////////////////////////// - assertErrorResponse(HttpStatus.OK_200, null, Unirest.request(method, BASE_URL + "/api/").asString()); - } - else - { - assertErrorResponse(HttpStatus.NOT_FOUND_404, "Could not find any resources at path", Unirest.request(method, BASE_URL + "/api/").asString()); - } - } + assertErrorResponse(HttpStatus.NOT_FOUND_404, "Could not find a table named notATable in this api", Unirest.request("post", BASE_URL + "/api/" + VERSION + "/notATable/").asString()); + assertErrorResponse(HttpStatus.NOT_FOUND_404, "Could not find any resources at path", Unirest.request("post", BASE_URL + "/api/" + VERSION + "/notATable/notAnId").asString()); + assertErrorResponse(HttpStatus.NOT_FOUND_404, "Could not find any resources at path", Unirest.request("post", BASE_URL + "/api/" + VERSION + "/person/1/2").asString()); + assertErrorResponse(HttpStatus.NOT_FOUND_404, "Could not find any resources at path", Unirest.request("post", BASE_URL + "/api/foo").asString()); + assertErrorResponse(HttpStatus.NOT_FOUND_404, "Could not find any resources at path", Unirest.request("post", BASE_URL + "/api/").asString()); + + assertErrorResponse(HttpStatus.NOT_FOUND_404, "Could not find any resources at path", Unirest.request("patch", BASE_URL + "/api/" + VERSION + "/notATable/").asString()); + assertErrorResponse(HttpStatus.NOT_FOUND_404, "Could not find a table named notATable in this api", Unirest.request("patch", BASE_URL + "/api/" + VERSION + "/notATable/notAnId").asString()); + assertErrorResponse(HttpStatus.NOT_FOUND_404, "Could not find any resources at path", Unirest.request("patch", BASE_URL + "/api/" + VERSION + "/person/1/2").asString()); + assertErrorResponse(HttpStatus.NOT_FOUND_404, "Could not find any resources at path", Unirest.request("patch", BASE_URL + "/api/foo").asString()); + assertErrorResponse(HttpStatus.NOT_FOUND_404, "Could not find any resources at path", Unirest.request("patch", BASE_URL + "/api/").asString()); + + assertErrorResponse(HttpStatus.NOT_FOUND_404, "Could not find any resources at path", Unirest.request("delete", BASE_URL + "/api/" + VERSION + "/notATable/").asString()); + assertErrorResponse(HttpStatus.NOT_FOUND_404, "Could not find a table named notATable in this api", Unirest.request("delete", BASE_URL + "/api/" + VERSION + "/notATable/notAnId").asString()); + assertErrorResponse(HttpStatus.NOT_FOUND_404, "Could not find any resources at path", Unirest.request("delete", BASE_URL + "/api/" + VERSION + "/person/1/2").asString()); + assertErrorResponse(HttpStatus.NOT_FOUND_404, "Could not find any resources at path", Unirest.request("delete", BASE_URL + "/api/foo").asString()); + assertErrorResponse(HttpStatus.NOT_FOUND_404, "Could not find any resources at path", Unirest.request("delete", BASE_URL + "/api/").asString()); }