mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 21:20:45 +00:00
QQQ-21 adding processRecords
This commit is contained in:
@ -147,7 +147,7 @@ public class QJavalinImplementation
|
||||
void startJavalinServer(int port)
|
||||
{
|
||||
// todo port from arg
|
||||
// todo base path from arg?
|
||||
// todo base path from arg? - and then potentially multiple instances too (chosen based on the root path??)
|
||||
service = Javalin.create().start(port);
|
||||
service.routes(getRoutes());
|
||||
}
|
||||
@ -198,10 +198,8 @@ public class QJavalinImplementation
|
||||
{
|
||||
get("/", QJavalinImplementation::dataQuery);
|
||||
post("/", QJavalinImplementation::dataInsert); // todo - internal to that method, if input is a list, do a bulk - else, single.
|
||||
path("/count", () ->
|
||||
{
|
||||
get("", QJavalinImplementation::dataCount);
|
||||
});
|
||||
get("/count", QJavalinImplementation::dataCount);
|
||||
|
||||
// todo - add put and/or patch at this level (without a primaryKey) to do a bulk update based on primaryKeys in the records.
|
||||
path("/:primaryKey", () ->
|
||||
{
|
||||
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* 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.javalin;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.kingsrook.qqq.backend.core.callbacks.QProcessCallback;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.query.QQueryFilter;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QFieldMetaData;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public class QJavalinProcessCallback implements QProcessCallback
|
||||
{
|
||||
private static final Logger LOG = LogManager.getLogger(QJavalinProcessCallback.class);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public QQueryFilter getQueryFilter()
|
||||
{
|
||||
LOG.warn("Getting a query filter in javalin is NOT yet implemented");
|
||||
return (new QQueryFilter());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public Map<String, Serializable> getFieldValues(List<QFieldMetaData> fields)
|
||||
{
|
||||
LOG.warn("Getting field values in javalin is NOT yet implemented");
|
||||
return (new HashMap<>());
|
||||
}
|
||||
}
|
@ -29,6 +29,7 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -47,6 +48,7 @@ import com.kingsrook.qqq.backend.core.model.actions.processes.RunProcessResult;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.query.QCriteriaOperator;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.query.QFilterCriteria;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.query.QQueryFilter;
|
||||
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QFieldMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QTableMetaData;
|
||||
@ -68,7 +70,7 @@ import static io.javalin.apibuilder.ApiBuilder.post;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** methods for handling qqq processes in javalin.
|
||||
*******************************************************************************/
|
||||
public class QJavalinProcessHandler
|
||||
{
|
||||
@ -96,6 +98,7 @@ public class QJavalinProcessHandler
|
||||
{
|
||||
post("/step/:step", QJavalinProcessHandler::processStep);
|
||||
get("/status/:jobUUID", QJavalinProcessHandler::processStatus);
|
||||
get("/records", QJavalinProcessHandler::processRecords);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -383,6 +386,43 @@ public class QJavalinProcessHandler
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private static void processRecords(Context context)
|
||||
{
|
||||
try
|
||||
{
|
||||
String processUUID = context.pathParam("processUUID");
|
||||
Integer skip = Objects.requireNonNullElse(QJavalinImplementation.integerQueryParam(context, "skip"), 0);
|
||||
Integer limit = Objects.requireNonNullElse(QJavalinImplementation.integerQueryParam(context, "limit"), 20);
|
||||
|
||||
Optional<ProcessState> optionalProcessState = RunProcessAction.getStateProvider().get(ProcessState.class, new UUIDAndTypeStateKey(UUID.fromString(processUUID), StateType.PROCESS_STATUS));
|
||||
if(optionalProcessState.isEmpty())
|
||||
{
|
||||
throw (new Exception("Could not find process results."));
|
||||
}
|
||||
ProcessState processState = optionalProcessState.get();
|
||||
|
||||
List<QRecord> records = processState.getRecords();
|
||||
if(CollectionUtils.nullSafeIsEmpty(records))
|
||||
{
|
||||
throw (new Exception("No records were found for the process."));
|
||||
}
|
||||
|
||||
Map<String, Object> resultForCaller = new HashMap<>();
|
||||
List<QRecord> recordPage = CollectionUtils.safelyGetPage(records, skip, limit);
|
||||
resultForCaller.put("records", recordPage);
|
||||
context.result(JsonUtils.toJson(resultForCaller));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
QJavalinImplementation.handleException(context, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
@ -32,6 +32,7 @@ import com.kingsrook.qqq.backend.core.model.actions.query.QQueryFilter;
|
||||
import com.kingsrook.qqq.backend.core.utils.JsonUtils;
|
||||
import kong.unirest.HttpResponse;
|
||||
import kong.unirest.Unirest;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@ -46,7 +47,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
*******************************************************************************/
|
||||
class QJavalinProcessHandlerTest extends QJavalinTestBase
|
||||
{
|
||||
private static final int MORE_THAN_TIMEOUT = 500;
|
||||
private static final int MORE_THAN_TIMEOUT = 1000;
|
||||
private static final int LESS_THAN_TIMEOUT = 50;
|
||||
|
||||
|
||||
@ -79,7 +80,7 @@ class QJavalinProcessHandlerTest extends QJavalinTestBase
|
||||
JSONObject jsonObject = JsonUtils.toJSONObject(response.getBody());
|
||||
assertNotNull(jsonObject);
|
||||
assertTrue(jsonObject.has("error"));
|
||||
assertTrue(jsonObject.getString("error").contains("missing input records"));
|
||||
assertTrue(jsonObject.getString("error").contains("Missing input records"));
|
||||
}
|
||||
|
||||
|
||||
@ -395,4 +396,32 @@ class QJavalinProcessHandlerTest extends QJavalinTestBase
|
||||
|
||||
return (jsonObject);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** test getting records back from a process
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
public void test_processRecords()
|
||||
{
|
||||
HttpResponse<String> response = Unirest.get(BASE_URL + "/processes/greet/init?recordsParam=recordIds&recordIds=2,3&greetingPrefix=Hey&greetingSuffix=Jude").asString();
|
||||
assertEquals(200, response.getStatus());
|
||||
JSONObject jsonObject = JsonUtils.toJSONObject(response.getBody());
|
||||
assertNotNull(jsonObject);
|
||||
String processUUID = jsonObject.getString("processUUID");
|
||||
|
||||
response = Unirest.get(BASE_URL + "/processes/greet/" + processUUID + "/records").asString();
|
||||
jsonObject = JsonUtils.toJSONObject(response.getBody());
|
||||
assertNotNull(jsonObject);
|
||||
assertTrue(jsonObject.has("records"));
|
||||
JSONArray records = jsonObject.getJSONArray("records");
|
||||
assertEquals(2, records.length());
|
||||
JSONObject record0 = records.getJSONObject(0);
|
||||
JSONObject values = record0.getJSONObject("values");
|
||||
assertTrue(values.has("id"));
|
||||
assertTrue(values.has("firstName"));
|
||||
}
|
||||
|
||||
}
|
@ -47,7 +47,7 @@ public class QJavalinTestBase
|
||||
public static void beforeAll()
|
||||
{
|
||||
qJavalinImplementation = new QJavalinImplementation(TestUtils.defineInstance());
|
||||
QJavalinProcessHandler.setAsyncStepTimeoutMillis(250);
|
||||
QJavalinProcessHandler.setAsyncStepTimeoutMillis(500);
|
||||
qJavalinImplementation.startJavalinServer(PORT);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user