CE-1887 Updates for javalin 6.3.0; add method addJavalinRoutes(EndpointGroup); add getter & setter for QInstance;

This commit is contained in:
2024-10-17 11:55:20 -05:00
parent 7beea514d2
commit 8436f2ab0a

View File

@ -106,7 +106,6 @@ import com.kingsrook.qqq.backend.core.model.actions.values.SearchPossibleValueSo
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetInput; import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetInput;
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetOutput; import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetOutput;
import com.kingsrook.qqq.backend.core.model.data.QRecord; import com.kingsrook.qqq.backend.core.model.data.QRecord;
import com.kingsrook.qqq.backend.core.model.metadata.MetaDataProducerHelper;
import com.kingsrook.qqq.backend.core.model.metadata.QBackendMetaData; import com.kingsrook.qqq.backend.core.model.metadata.QBackendMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance; import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.fields.AdornmentType; import com.kingsrook.qqq.backend.core.model.metadata.fields.AdornmentType;
@ -123,6 +122,7 @@ import com.kingsrook.qqq.backend.core.model.statusmessages.QStatusMessage;
import com.kingsrook.qqq.backend.core.modules.authentication.QAuthenticationModuleDispatcher; import com.kingsrook.qqq.backend.core.modules.authentication.QAuthenticationModuleDispatcher;
import com.kingsrook.qqq.backend.core.modules.authentication.QAuthenticationModuleInterface; import com.kingsrook.qqq.backend.core.modules.authentication.QAuthenticationModuleInterface;
import com.kingsrook.qqq.backend.core.modules.authentication.implementations.Auth0AuthenticationModule; import com.kingsrook.qqq.backend.core.modules.authentication.implementations.Auth0AuthenticationModule;
import com.kingsrook.qqq.backend.core.utils.ClassPathUtils;
import com.kingsrook.qqq.backend.core.utils.CollectionUtils; import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
import com.kingsrook.qqq.backend.core.utils.ExceptionUtils; import com.kingsrook.qqq.backend.core.utils.ExceptionUtils;
import com.kingsrook.qqq.backend.core.utils.JsonUtils; import com.kingsrook.qqq.backend.core.utils.JsonUtils;
@ -178,7 +178,8 @@ public class QJavalinImplementation
private static int DEFAULT_PORT = 8001; private static int DEFAULT_PORT = 8001;
private static Javalin service; private static Javalin service;
private static List<EndpointGroup> endpointGroups;
private static long startTime = 0; private static long startTime = 0;
@ -241,8 +242,18 @@ public class QJavalinImplementation
{ {
// todo port from arg // todo port from arg
// todo base path from arg? - and then potentially multiple instances too (chosen based on the root path??) // 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()); service = Javalin.create(config ->
{
config.router.apiBuilder(getRoutes());
for(EndpointGroup endpointGroup : CollectionUtils.nonNullList(endpointGroups))
{
config.router.apiBuilder(endpointGroup);
}
}
).start(port);
service.before(QJavalinImplementation::hotSwapQInstance); service.before(QJavalinImplementation::hotSwapQInstance);
service.before((Context context) -> context.header("Content-Type", "application/json")); service.before((Context context) -> context.header("Content-Type", "application/json"));
service.after(QJavalinImplementation::clearQContext); service.after(QJavalinImplementation::clearQContext);
@ -292,7 +303,7 @@ public class QJavalinImplementation
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// clear the cache of classes in this class, so that new classes can be found // // clear the cache of classes in this class, so that new classes can be found //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
MetaDataProducerHelper.clearTopLevelClassCache(); ClassPathUtils.clearTopLevelClassCache();
///////////////////////////////////////////////// /////////////////////////////////////////////////
// try to get a new instance from the supplier // // try to get a new instance from the supplier //
@ -1014,8 +1025,7 @@ public class QJavalinImplementation
QRecord record = getOutput.getRecord(); QRecord record = getOutput.getRecord();
if(record == null) if(record == null)
{ {
throw (new QNotFoundException("Could not find " + table.getLabel() + " with " throw (new QNotFoundException("Could not find " + table.getLabel() + " with " + table.getFields().get(table.getPrimaryKeyField()).getLabel() + " of " + primaryKey));
+ table.getFields().get(table.getPrimaryKeyField()).getLabel() + " of " + primaryKey));
} }
QValueFormatter.setBlobValuesToDownloadUrls(table, List.of(record)); QValueFormatter.setBlobValuesToDownloadUrls(table, List.of(record));
@ -1078,8 +1088,7 @@ public class QJavalinImplementation
/////////////////////////////////////////////////////// ///////////////////////////////////////////////////////
if(getOutput.getRecord() == null) if(getOutput.getRecord() == null)
{ {
throw (new QNotFoundException("Could not find " + table.getLabel() + " with " throw (new QNotFoundException("Could not find " + table.getLabel() + " with " + table.getFields().get(table.getPrimaryKeyField()).getLabel() + " of " + primaryKey));
+ table.getFields().get(table.getPrimaryKeyField()).getLabel() + " of " + primaryKey));
} }
String mimeType = null; String mimeType = null;
@ -1789,7 +1798,7 @@ public class QJavalinImplementation
if(CollectionUtils.nullSafeHasContents(valuesParamList)) if(CollectionUtils.nullSafeHasContents(valuesParamList))
{ {
String valuesParam = valuesParamList.get(0); String valuesParam = valuesParamList.get(0);
values = JsonUtils.toObject(valuesParam, new TypeReference<>(){}); values = JsonUtils.toObject(valuesParam, new TypeReference<>() {});
} }
} }
@ -1919,7 +1928,7 @@ public class QJavalinImplementation
** Getter for javalinMetaData ** Getter for javalinMetaData
** **
*******************************************************************************/ *******************************************************************************/
public QJavalinMetaData getJavalinMetaData() public static QJavalinMetaData getJavalinMetaData()
{ {
return javalinMetaData; return javalinMetaData;
} }
@ -1948,7 +1957,7 @@ public class QJavalinImplementation
/******************************************************************************* /*******************************************************************************
** Getter for qInstanceHotSwapSupplier ** Getter for qInstance
*******************************************************************************/ *******************************************************************************/
public static QInstance getQInstance() public static QInstance getQInstance()
{ {
@ -1957,6 +1966,16 @@ public class QJavalinImplementation
/*******************************************************************************
** Setter for qInstance
*******************************************************************************/
public static void setQInstance(QInstance qInstance)
{
QJavalinImplementation.qInstance = qInstance;
}
/******************************************************************************* /*******************************************************************************
** **
*******************************************************************************/ *******************************************************************************/
@ -1984,4 +2003,18 @@ public class QJavalinImplementation
{ {
return (startTime); return (startTime);
} }
/***************************************************************************
**
***************************************************************************/
public void addJavalinRoutes(EndpointGroup routes)
{
if(endpointGroups == null)
{
endpointGroups = new ArrayList<>();
}
endpointGroups.add(routes);
}
} }