diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/values/BasicCustomPossibleValueProvider.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/values/BasicCustomPossibleValueProvider.java
new file mode 100644
index 00000000..da1421bc
--- /dev/null
+++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/values/BasicCustomPossibleValueProvider.java
@@ -0,0 +1,91 @@
+/*
+ * QQQ - Low-code Application Framework for Engineers.
+ * Copyright (C) 2021-2025. 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 .
+ */
+
+package com.kingsrook.qqq.backend.core.actions.values;
+
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import com.kingsrook.qqq.backend.core.exceptions.QException;
+import com.kingsrook.qqq.backend.core.model.actions.values.SearchPossibleValueSourceInput;
+import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.QPossibleValue;
+
+
+/*******************************************************************************
+ ** Basic implementation of a possible value provider, for where there's a limited
+ ** set of possible source objects - so you just have to define how to make one
+ ** PV from a source object, how to list all of the source objects, and how to
+ ** look up a PV from an id.
+ *******************************************************************************/
+public abstract class BasicCustomPossibleValueProvider implements QCustomPossibleValueProvider
+{
+
+ /***************************************************************************
+ **
+ ***************************************************************************/
+ protected abstract QPossibleValue makePossibleValue(S sourceObject);
+
+ /***************************************************************************
+ **
+ ***************************************************************************/
+ protected abstract S getSourceObject(Serializable id);
+
+ /***************************************************************************
+ **
+ ***************************************************************************/
+ protected abstract List getAllSourceObjects();
+
+
+
+ /***************************************************************************
+ **
+ ***************************************************************************/
+ @Override
+ public QPossibleValue getPossibleValue(Serializable idValue)
+ {
+ S sourceObject = getSourceObject(idValue);
+ if(sourceObject == null)
+ {
+ return (null);
+ }
+
+ return makePossibleValue(sourceObject);
+ }
+
+
+
+ /***************************************************************************
+ **
+ ***************************************************************************/
+ @Override
+ public List> search(SearchPossibleValueSourceInput input) throws QException
+ {
+ List> allPossibleValues = new ArrayList<>();
+ List allSourceObjects = getAllSourceObjects();
+ for(S sourceObject : allSourceObjects)
+ {
+ allPossibleValues.add(makePossibleValue(sourceObject));
+ }
+
+ return completeCustomPVSSearch(input, allPossibleValues);
+ }
+}
diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/tables/TablesCustomPossibleValueProvider.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/tables/TablesCustomPossibleValueProvider.java
index e72d188f..e2d98b4a 100644
--- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/tables/TablesCustomPossibleValueProvider.java
+++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/tables/TablesCustomPossibleValueProvider.java
@@ -27,11 +27,9 @@ import java.util.ArrayList;
import java.util.List;
import com.kingsrook.qqq.backend.core.actions.permissions.PermissionCheckResult;
import com.kingsrook.qqq.backend.core.actions.permissions.PermissionsHelper;
-import com.kingsrook.qqq.backend.core.actions.values.QCustomPossibleValueProvider;
+import com.kingsrook.qqq.backend.core.actions.values.BasicCustomPossibleValueProvider;
import com.kingsrook.qqq.backend.core.context.QContext;
-import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryInput;
-import com.kingsrook.qqq.backend.core.model.actions.values.SearchPossibleValueSourceInput;
import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.QPossibleValue;
import com.kingsrook.qqq.backend.core.utils.ValueUtils;
@@ -40,26 +38,16 @@ import com.kingsrook.qqq.backend.core.utils.ValueUtils;
** possible-value source provider for the `Tables` PVS - a list of all tables
** in an application/qInstance.
*******************************************************************************/
-public class TablesCustomPossibleValueProvider implements QCustomPossibleValueProvider
+public class TablesCustomPossibleValueProvider extends BasicCustomPossibleValueProvider
{
/***************************************************************************
**
***************************************************************************/
@Override
- public QPossibleValue getPossibleValue(Serializable idValue)
+ protected QPossibleValue makePossibleValue(QTableMetaData sourceObject)
{
- QTableMetaData table = QContext.getQInstance().getTable(ValueUtils.getValueAsString(idValue));
- if(table != null && !table.getIsHidden())
- {
- PermissionCheckResult permissionCheckResult = PermissionsHelper.getPermissionCheckResult(new QueryInput(table.getName()), table);
- if(PermissionCheckResult.ALLOW.equals(permissionCheckResult))
- {
- return (new QPossibleValue<>(table.getName(), table.getLabel()));
- }
- }
-
- return null;
+ return (new QPossibleValue<>(sourceObject.getName(), sourceObject.getLabel()));
}
@@ -68,22 +56,54 @@ public class TablesCustomPossibleValueProvider implements QCustomPossibleValuePr
**
***************************************************************************/
@Override
- public List> search(SearchPossibleValueSourceInput input) throws QException
+ protected QTableMetaData getSourceObject(Serializable id)
{
- /////////////////////////////////////////////////////////////////////////////////////
- // build all of the possible values (note, will be filtered by user's permissions) //
- /////////////////////////////////////////////////////////////////////////////////////
- List> allPossibleValues = new ArrayList<>();
+ QTableMetaData table = QContext.getQInstance().getTable(ValueUtils.getValueAsString(id));
+ return isTableAllowed(table) ? table : null;
+ }
+
+
+
+ /***************************************************************************
+ **
+ ***************************************************************************/
+ @Override
+ protected List getAllSourceObjects()
+ {
+ ArrayList rs = new ArrayList<>();
for(QTableMetaData table : QContext.getQInstance().getTables().values())
{
- QPossibleValue possibleValue = getPossibleValue(table.getName());
- if(possibleValue != null)
+ if(isTableAllowed(table))
{
- allPossibleValues.add(possibleValue);
+ rs.add(table);
}
}
+ return rs;
+ }
- return completeCustomPVSSearch(input, allPossibleValues);
+
+ /***************************************************************************
+ **
+ ***************************************************************************/
+ private boolean isTableAllowed(QTableMetaData table)
+ {
+ if(table == null)
+ {
+ return (false);
+ }
+
+ if(table.getIsHidden())
+ {
+ return (false);
+ }
+
+ PermissionCheckResult permissionCheckResult = PermissionsHelper.getPermissionCheckResult(new QueryInput(table.getName()), table);
+ if(!PermissionCheckResult.ALLOW.equals(permissionCheckResult))
+ {
+ return (false);
+ }
+
+ return (true);
}
}
diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/tables/TablesPossibleValueSourceMetaDataProvider.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/tables/TablesPossibleValueSourceMetaDataProvider.java
index 75087ae7..cdc9b6d3 100644
--- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/tables/TablesPossibleValueSourceMetaDataProvider.java
+++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/tables/TablesPossibleValueSourceMetaDataProvider.java
@@ -24,6 +24,7 @@ package com.kingsrook.qqq.backend.core.model.metadata.tables;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
+import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldType;
import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.PVSValueFormatAndFields;
import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.QPossibleValueSource;
import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.QPossibleValueSourceType;
@@ -45,6 +46,7 @@ public class TablesPossibleValueSourceMetaDataProvider
{
QPossibleValueSource possibleValueSource = new QPossibleValueSource()
.withName(NAME)
+ .withIdType(QFieldType.STRING)
.withType(QPossibleValueSourceType.CUSTOM)
.withCustomCodeReference(new QCodeReference(TablesCustomPossibleValueProvider.class))
.withValueFormatAndFields(PVSValueFormatAndFields.LABEL_ONLY);