mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +00:00
Refactoring to work with new API middleware routes
This commit is contained in:
@ -58,7 +58,7 @@ public class QJavalinAccessLogger
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
static void logStart(String actionName, LogPair... logPairs)
|
||||
public static void logStart(String actionName, LogPair... logPairs)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -159,7 +159,7 @@ public class QJavalinAccessLogger
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
static void logEndSuccess(LogPair... logPairs)
|
||||
public static void logEndSuccess(LogPair... logPairs)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -182,7 +182,7 @@ public class QJavalinAccessLogger
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
static void logEndFail(Throwable t, LogPair... logPairs)
|
||||
public static void logEndFail(Throwable t, LogPair... logPairs)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -63,7 +63,6 @@ import com.kingsrook.qqq.backend.core.exceptions.QModuleDispatchException;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QNotFoundException;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QPermissionDeniedException;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QUserFacingException;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QValueException;
|
||||
import com.kingsrook.qqq.backend.core.instances.QInstanceValidator;
|
||||
import com.kingsrook.qqq.backend.core.logging.QLogger;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.AbstractActionInput;
|
||||
@ -146,7 +145,7 @@ public class QJavalinImplementation
|
||||
private static long lastQInstanceHotSwapMillis;
|
||||
|
||||
private static final long MILLIS_BETWEEN_HOT_SWAPS = 2500;
|
||||
private static final long SLOW_LOG_THRESHOLD_MS = 1000;
|
||||
public static final long SLOW_LOG_THRESHOLD_MS = 1000;
|
||||
|
||||
private static int DEFAULT_PORT = 8001;
|
||||
|
||||
@ -356,6 +355,14 @@ public class QJavalinImplementation
|
||||
// process routes //
|
||||
////////////////////
|
||||
path("", QJavalinProcessHandler.getRoutes());
|
||||
|
||||
// todo... ? ////////////////
|
||||
// todo... ? // api routes //
|
||||
// todo... ? ////////////////
|
||||
// todo... ? if(qInstance.getApiMetaData() != null)
|
||||
// todo... ? {
|
||||
// todo... ? path("", QJavalinApiHandler.getRoutes());
|
||||
// todo... ? }
|
||||
});
|
||||
}
|
||||
|
||||
@ -758,7 +765,7 @@ public class QJavalinImplementation
|
||||
|
||||
PermissionsHelper.checkTablePermissionThrowing(countInput, TablePermissionSubType.READ);
|
||||
|
||||
filter = stringQueryParam(context, "filter");
|
||||
filter = QJavalinUtils.stringQueryParam(context, "filter");
|
||||
if(!StringUtils.hasContent(filter))
|
||||
{
|
||||
filter = context.formParam("filter");
|
||||
@ -823,12 +830,12 @@ public class QJavalinImplementation
|
||||
queryInput.setTableName(table);
|
||||
queryInput.setShouldGenerateDisplayValues(true);
|
||||
queryInput.setShouldTranslatePossibleValues(true);
|
||||
queryInput.setSkip(integerQueryParam(context, "skip"));
|
||||
queryInput.setLimit(integerQueryParam(context, "limit"));
|
||||
queryInput.setSkip(QJavalinUtils.integerQueryParam(context, "skip"));
|
||||
queryInput.setLimit(QJavalinUtils.integerQueryParam(context, "limit"));
|
||||
|
||||
PermissionsHelper.checkTablePermissionThrowing(queryInput, TablePermissionSubType.READ);
|
||||
|
||||
filter = stringQueryParam(context, "filter");
|
||||
filter = QJavalinUtils.stringQueryParam(context, "filter");
|
||||
if(!StringUtils.hasContent(filter))
|
||||
{
|
||||
filter = context.formParam("filter");
|
||||
@ -862,7 +869,7 @@ public class QJavalinImplementation
|
||||
{
|
||||
List<QueryJoin> queryJoins = null;
|
||||
|
||||
String queryJoinsParam = stringQueryParam(context, "queryJoins");
|
||||
String queryJoinsParam = QJavalinUtils.stringQueryParam(context, "queryJoins");
|
||||
if(StringUtils.hasContent(queryJoinsParam))
|
||||
{
|
||||
queryJoins = new ArrayList<>();
|
||||
@ -1075,7 +1082,7 @@ public class QJavalinImplementation
|
||||
//////////////////////////////////////////
|
||||
String format = context.queryParam("format");
|
||||
String filter = context.queryParam("filter");
|
||||
Integer limit = integerQueryParam(context, "limit");
|
||||
Integer limit = QJavalinUtils.integerQueryParam(context, "limit");
|
||||
|
||||
ReportFormat reportFormat = getReportFormat(context, optionalFilename, format);
|
||||
if(reportFormat == null)
|
||||
@ -1098,7 +1105,7 @@ public class QJavalinImplementation
|
||||
|
||||
PermissionsHelper.checkTablePermissionThrowing(exportInput, TablePermissionSubType.READ);
|
||||
|
||||
String fields = stringQueryParam(context, "fields");
|
||||
String fields = QJavalinUtils.stringQueryParam(context, "fields");
|
||||
if(StringUtils.hasContent(fields))
|
||||
{
|
||||
exportInput.setFieldNames(List.of(fields.split(",")));
|
||||
@ -1417,59 +1424,6 @@ public class QJavalinImplementation
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Returns Integer if context has a valid int query parameter by the given name,
|
||||
** Returns null if no param (or empty value).
|
||||
** Throws QValueException for malformed numbers.
|
||||
*******************************************************************************/
|
||||
public static Integer integerQueryParam(Context context, String name) throws QValueException
|
||||
{
|
||||
String value = context.queryParam(name);
|
||||
if(StringUtils.hasContent(value))
|
||||
{
|
||||
return (ValueUtils.getValueAsInteger(value));
|
||||
}
|
||||
|
||||
return (null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Returns Integer if context has a valid int form parameter by the given name,
|
||||
** Returns null if no param (or empty value).
|
||||
** Throws QValueException for malformed numbers.
|
||||
*******************************************************************************/
|
||||
public static Integer integerFormParam(Context context, String name) throws QValueException
|
||||
{
|
||||
String value = context.formParam(name);
|
||||
if(StringUtils.hasContent(value))
|
||||
{
|
||||
return (ValueUtils.getValueAsInteger(value));
|
||||
}
|
||||
|
||||
return (null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Returns String if context has a valid query parameter by the given name,
|
||||
* Returns null if no param (or empty value).
|
||||
*******************************************************************************/
|
||||
private static String stringQueryParam(Context context, String name)
|
||||
{
|
||||
String value = context.queryParam(name);
|
||||
if(StringUtils.hasContent(value))
|
||||
{
|
||||
return (value);
|
||||
}
|
||||
|
||||
return (null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for qInstanceHotSwapSupplier
|
||||
*******************************************************************************/
|
||||
|
@ -700,8 +700,8 @@ public class QJavalinProcessHandler
|
||||
// todo - need process values? PermissionsHelper.checkProcessPermissionThrowing(input, context.pathParam("processName"));
|
||||
|
||||
String processUUID = context.pathParam("processUUID");
|
||||
Integer skip = Objects.requireNonNullElse(QJavalinImplementation.integerQueryParam(context, "skip"), 0);
|
||||
Integer limit = Objects.requireNonNullElse(QJavalinImplementation.integerQueryParam(context, "limit"), 20);
|
||||
Integer skip = Objects.requireNonNullElse(QJavalinUtils.integerQueryParam(context, "skip"), 0);
|
||||
Integer limit = Objects.requireNonNullElse(QJavalinUtils.integerQueryParam(context, "limit"), 20);
|
||||
|
||||
// todo - potential optimization - if a future state provider could take advantage of it,
|
||||
// we might pass the skip & limit in to a method that fetch just those 'n' rows from state, rather than the whole thing?
|
||||
@ -786,10 +786,10 @@ public class QJavalinProcessHandler
|
||||
*******************************************************************************/
|
||||
private static Integer getTimeoutMillis(Context context)
|
||||
{
|
||||
Integer timeout = QJavalinImplementation.integerQueryParam(context, "_qStepTimeoutMillis");
|
||||
Integer timeout = QJavalinUtils.integerQueryParam(context, "_qStepTimeoutMillis");
|
||||
if(timeout == null)
|
||||
{
|
||||
timeout = QJavalinImplementation.integerFormParam(context, "_qStepTimeoutMillis");
|
||||
timeout = QJavalinUtils.integerFormParam(context, "_qStepTimeoutMillis");
|
||||
if(timeout == null)
|
||||
{
|
||||
timeout = ASYNC_STEP_TIMEOUT_MILLIS;
|
||||
|
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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.javalin;
|
||||
|
||||
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QValueException;
|
||||
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
||||
import com.kingsrook.qqq.backend.core.utils.ValueUtils;
|
||||
import io.javalin.http.Context;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Utility methods shared by javalin implementations
|
||||
*******************************************************************************/
|
||||
public class QJavalinUtils
|
||||
{
|
||||
|
||||
/*******************************************************************************
|
||||
** Returns Integer if context has a valid int query parameter by the given name,
|
||||
** Returns null if no param (or empty value).
|
||||
** Throws QValueException for malformed numbers.
|
||||
*******************************************************************************/
|
||||
public static Integer integerQueryParam(Context context, String name) throws QValueException
|
||||
{
|
||||
String value = context.queryParam(name);
|
||||
if(StringUtils.hasContent(value))
|
||||
{
|
||||
return (ValueUtils.getValueAsInteger(value));
|
||||
}
|
||||
|
||||
return (null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Returns Integer if context has a valid int form parameter by the given name,
|
||||
** Returns null if no param (or empty value).
|
||||
** Throws QValueException for malformed numbers.
|
||||
*******************************************************************************/
|
||||
public static Integer integerFormParam(Context context, String name) throws QValueException
|
||||
{
|
||||
String value = context.formParam(name);
|
||||
if(StringUtils.hasContent(value))
|
||||
{
|
||||
return (ValueUtils.getValueAsInteger(value));
|
||||
}
|
||||
|
||||
return (null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Returns String if context has a valid query parameter by the given name,
|
||||
* Returns null if no param (or empty value).
|
||||
*******************************************************************************/
|
||||
public static String stringQueryParam(Context context, String name)
|
||||
{
|
||||
String value = context.queryParam(name);
|
||||
if(StringUtils.hasContent(value))
|
||||
{
|
||||
return (value);
|
||||
}
|
||||
|
||||
return (null);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user