Update possibleValuesStandalone to accept filter as formParam.

This commit is contained in:
2025-07-14 16:32:00 -05:00
parent 79bc7dfecd
commit 384195a2c3
2 changed files with 47 additions and 4 deletions

View File

@ -1856,7 +1856,23 @@ public class QJavalinImplementation
throw (new QNotFoundException("Could not find possible value source " + possibleValueSourceName + " in this instance."));
}
finishPossibleValuesRequest(context, possibleValueSourceName, null, otherValues);
//////////////////////////////////////////////////
// allow a filter to be passed in from frontend //
//////////////////////////////////////////////////
QQueryFilter defaultQueryFilter = null;
List<String> filterParam = context.formParamMap().get("filter");
if(CollectionUtils.nullSafeHasContents(filterParam))
{
String possibleValueSourceFilterJSON = filterParam.get(0);
defaultQueryFilter = JsonUtils.toObject(possibleValueSourceFilterJSON, QQueryFilter.class);
String useCaseParam = QJavalinUtils.getQueryParamOrFormParam(context, "useCase");
PossibleValueSearchFilterUseCase useCase = ObjectUtils.tryElse(() -> PossibleValueSearchFilterUseCase.valueOf(useCaseParam.toUpperCase()), PossibleValueSearchFilterUseCase.FORM);
defaultQueryFilter.interpretValues(otherValues, useCase);
}
finishPossibleValuesRequest(context, possibleValueSourceName, defaultQueryFilter, otherValues);
}
catch(Exception e)
{

View File

@ -39,6 +39,9 @@ import com.kingsrook.qqq.backend.core.exceptions.QInstanceValidationException;
import com.kingsrook.qqq.backend.core.logging.QCollectingLogger;
import com.kingsrook.qqq.backend.core.logging.QLogger;
import com.kingsrook.qqq.backend.core.model.actions.reporting.ReportFormat;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QCriteriaOperator;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QFilterCriteria;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
import com.kingsrook.qqq.backend.core.model.dashboard.widgets.WidgetType;
import com.kingsrook.qqq.backend.core.model.metadata.QAuthenticationType;
import com.kingsrook.qqq.backend.core.model.metadata.QBackendMetaData;
@ -1075,7 +1078,7 @@ class QJavalinImplementationTest extends QJavalinTestBase
**
*******************************************************************************/
@Test
void testPossibleValueWithoutTableOrProcess()
void testStandalonePossibleValueSource()
{
HttpResponse<String> response = Unirest.get(BASE_URL + "/possibleValues/person").asString();
assertEquals(200, response.getStatus());
@ -1089,6 +1092,28 @@ class QJavalinImplementationTest extends QJavalinTestBase
/*******************************************************************************
**
*******************************************************************************/
@Test
void testStandalonePossibleValueSourceWithFilter()
{
HttpResponse<String> response = Unirest.post(BASE_URL + "/possibleValues/person")
.field("values", JsonUtils.toJson(Map.of("firstInitial", "D")))
.field("filter", JsonUtils.toJson(new QQueryFilter(new QFilterCriteria("firstName", QCriteriaOperator.STARTS_WITH, "${input.firstInitial}"))))
.asString();
assertEquals(200, response.getStatus());
JSONObject jsonObject = JsonUtils.toJSONObject(response.getBody());
assertNotNull(jsonObject);
assertNotNull(jsonObject.getJSONArray("options"));
assertEquals(1, jsonObject.getJSONArray("options").length());
assertEquals(1, jsonObject.getJSONArray("options").getJSONObject(0).getInt("id"));
assertEquals("Darin Kelkhoff (1)", jsonObject.getJSONArray("options").getJSONObject(0).getString("label"));
}
/*******************************************************************************
**
*******************************************************************************/
@ -1481,6 +1506,8 @@ class QJavalinImplementationTest extends QJavalinTestBase
{
static int callCount = 0;
@Override
public void run(DownloadFileSupplementalActionInput input, DownloadFileSupplementalActionOutput output) throws QException
{