Add overload of getForeignRecordMap that takes additional (base) filter for query

This commit is contained in:
2022-12-09 20:25:59 -06:00
parent 293b3e4207
commit 30003b729c
2 changed files with 49 additions and 1 deletions

View File

@ -67,6 +67,21 @@ public class GeneralProcessUtils
** via getForeignRecordMap(input, orderList, "clientId", "client", "id")
*******************************************************************************/
public static Map<Serializable, QRecord> getForeignRecordMap(AbstractActionInput parentActionInput, List<QRecord> sourceRecords, String sourceTableForeignKeyFieldName, String foreignTableName, String foreignTablePrimaryKeyName) throws QException
{
return getForeignRecordMap(parentActionInput, sourceRecords, sourceTableForeignKeyFieldName, foreignTableName, foreignTablePrimaryKeyName, new QQueryFilter());
}
/*******************************************************************************
** For a list of sourceRecords,
** lookup records in the foreignTableName,
** that have their foreignTablePrimaryKeyName in the sourceTableForeignKeyFieldName on the sourceRecords.
**
** e.g., for a list of orders (with a clientId field), build a map of client.id => client record
** via getForeignRecordMap(input, orderList, "clientId", "client", "id")
*******************************************************************************/
public static Map<Serializable, QRecord> getForeignRecordMap(AbstractActionInput parentActionInput, List<QRecord> sourceRecords, String sourceTableForeignKeyFieldName, String foreignTableName, String foreignTablePrimaryKeyName, QQueryFilter additionalFilter) throws QException
{
Map<Serializable, QRecord> foreignRecordMap = new HashMap<>();
QueryInput queryInput = new QueryInput(parentActionInput.getInstance());
@ -74,7 +89,9 @@ public class GeneralProcessUtils
queryInput.setTableName(foreignTableName);
List<Serializable> foreignIds = new ArrayList<>(sourceRecords.stream().map(r -> r.getValue(sourceTableForeignKeyFieldName)).toList());
queryInput.setFilter(new QQueryFilter().withCriteria(new QFilterCriteria(foreignTablePrimaryKeyName, QCriteriaOperator.IN, foreignIds)));
additionalFilter.addCriteria(new QFilterCriteria(foreignTablePrimaryKeyName, QCriteriaOperator.IN, foreignIds));
queryInput.setFilter(additionalFilter);
QueryOutput queryOutput = new QueryAction().execute(queryInput);
for(QRecord foreignRecord : queryOutput.getRecords())
{