mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
Initial checkin of BasicCustomPossibleValueProvider, and migrate TablesCustomPossibleValueProvider to use it.
This commit is contained in:
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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<S, ID extends Serializable> implements QCustomPossibleValueProvider<ID>
|
||||||
|
{
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
**
|
||||||
|
***************************************************************************/
|
||||||
|
protected abstract QPossibleValue<ID> makePossibleValue(S sourceObject);
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
**
|
||||||
|
***************************************************************************/
|
||||||
|
protected abstract S getSourceObject(Serializable id);
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
**
|
||||||
|
***************************************************************************/
|
||||||
|
protected abstract List<S> getAllSourceObjects();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
**
|
||||||
|
***************************************************************************/
|
||||||
|
@Override
|
||||||
|
public QPossibleValue<ID> getPossibleValue(Serializable idValue)
|
||||||
|
{
|
||||||
|
S sourceObject = getSourceObject(idValue);
|
||||||
|
if(sourceObject == null)
|
||||||
|
{
|
||||||
|
return (null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return makePossibleValue(sourceObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
**
|
||||||
|
***************************************************************************/
|
||||||
|
@Override
|
||||||
|
public List<QPossibleValue<ID>> search(SearchPossibleValueSourceInput input) throws QException
|
||||||
|
{
|
||||||
|
List<QPossibleValue<ID>> allPossibleValues = new ArrayList<>();
|
||||||
|
List<S> allSourceObjects = getAllSourceObjects();
|
||||||
|
for(S sourceObject : allSourceObjects)
|
||||||
|
{
|
||||||
|
allPossibleValues.add(makePossibleValue(sourceObject));
|
||||||
|
}
|
||||||
|
|
||||||
|
return completeCustomPVSSearch(input, allPossibleValues);
|
||||||
|
}
|
||||||
|
}
|
@ -27,11 +27,9 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.kingsrook.qqq.backend.core.actions.permissions.PermissionCheckResult;
|
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.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.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.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.model.metadata.possiblevalues.QPossibleValue;
|
||||||
import com.kingsrook.qqq.backend.core.utils.ValueUtils;
|
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
|
** possible-value source provider for the `Tables` PVS - a list of all tables
|
||||||
** in an application/qInstance.
|
** in an application/qInstance.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public class TablesCustomPossibleValueProvider implements QCustomPossibleValueProvider<String>
|
public class TablesCustomPossibleValueProvider extends BasicCustomPossibleValueProvider<QTableMetaData, String>
|
||||||
{
|
{
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
**
|
**
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
@Override
|
@Override
|
||||||
public QPossibleValue<String> getPossibleValue(Serializable idValue)
|
protected QPossibleValue<String> makePossibleValue(QTableMetaData sourceObject)
|
||||||
{
|
{
|
||||||
QTableMetaData table = QContext.getQInstance().getTable(ValueUtils.getValueAsString(idValue));
|
return (new QPossibleValue<>(sourceObject.getName(), sourceObject.getLabel()));
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -68,22 +56,54 @@ public class TablesCustomPossibleValueProvider implements QCustomPossibleValuePr
|
|||||||
**
|
**
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
@Override
|
@Override
|
||||||
public List<QPossibleValue<String>> search(SearchPossibleValueSourceInput input) throws QException
|
protected QTableMetaData getSourceObject(Serializable id)
|
||||||
{
|
{
|
||||||
/////////////////////////////////////////////////////////////////////////////////////
|
QTableMetaData table = QContext.getQInstance().getTable(ValueUtils.getValueAsString(id));
|
||||||
// build all of the possible values (note, will be filtered by user's permissions) //
|
return isTableAllowed(table) ? table : null;
|
||||||
/////////////////////////////////////////////////////////////////////////////////////
|
}
|
||||||
List<QPossibleValue<String>> allPossibleValues = new ArrayList<>();
|
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
**
|
||||||
|
***************************************************************************/
|
||||||
|
@Override
|
||||||
|
protected List<QTableMetaData> getAllSourceObjects()
|
||||||
|
{
|
||||||
|
ArrayList<QTableMetaData> rs = new ArrayList<>();
|
||||||
for(QTableMetaData table : QContext.getQInstance().getTables().values())
|
for(QTableMetaData table : QContext.getQInstance().getTables().values())
|
||||||
{
|
{
|
||||||
QPossibleValue<String> possibleValue = getPossibleValue(table.getName());
|
if(isTableAllowed(table))
|
||||||
if(possibleValue != null)
|
|
||||||
{
|
{
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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.QInstance;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
|
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.PVSValueFormatAndFields;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.QPossibleValueSource;
|
import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.QPossibleValueSource;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.QPossibleValueSourceType;
|
import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.QPossibleValueSourceType;
|
||||||
@ -45,6 +46,7 @@ public class TablesPossibleValueSourceMetaDataProvider
|
|||||||
{
|
{
|
||||||
QPossibleValueSource possibleValueSource = new QPossibleValueSource()
|
QPossibleValueSource possibleValueSource = new QPossibleValueSource()
|
||||||
.withName(NAME)
|
.withName(NAME)
|
||||||
|
.withIdType(QFieldType.STRING)
|
||||||
.withType(QPossibleValueSourceType.CUSTOM)
|
.withType(QPossibleValueSourceType.CUSTOM)
|
||||||
.withCustomCodeReference(new QCodeReference(TablesCustomPossibleValueProvider.class))
|
.withCustomCodeReference(new QCodeReference(TablesCustomPossibleValueProvider.class))
|
||||||
.withValueFormatAndFields(PVSValueFormatAndFields.LABEL_ONLY);
|
.withValueFormatAndFields(PVSValueFormatAndFields.LABEL_ONLY);
|
||||||
|
Reference in New Issue
Block a user