mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-21 14:38:43 +00:00
Adding associated records to Get, Query.
This commit is contained in:
@ -70,8 +70,6 @@ public class QRecordApiAdapter
|
||||
{
|
||||
ApiFieldMetaData apiFieldMetaData = ApiFieldMetaData.of(field);
|
||||
|
||||
// todo - what about display values / possible values?
|
||||
|
||||
String apiFieldName = ApiFieldMetaData.getEffectiveApiFieldName(field);
|
||||
if(StringUtils.hasContent(apiFieldMetaData.getReplacedByFieldName()))
|
||||
{
|
||||
@ -82,6 +80,23 @@ public class QRecordApiAdapter
|
||||
outputRecord.put(apiFieldName, record.getValue(field.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// todo - should probably define in meta-data if an association is included in the api or not!! //
|
||||
// and what its name is too... //
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
QTableMetaData table = QContext.getQInstance().getTable(tableName);
|
||||
for(Association association : CollectionUtils.nonNullList(table.getAssociations()))
|
||||
{
|
||||
ArrayList<Map<String, Serializable>> associationList = new ArrayList<>();
|
||||
outputRecord.put(association.getName(), associationList);
|
||||
|
||||
for(QRecord associatedRecord : CollectionUtils.nonNullList(CollectionUtils.nonNullMap(record.getAssociatedRecords()).get(association.getName())))
|
||||
{
|
||||
associationList.add(qRecordToApiMap(associatedRecord, association.getAssociatedTableName(), apiVersion));
|
||||
}
|
||||
}
|
||||
|
||||
return (outputRecord);
|
||||
}
|
||||
|
||||
|
@ -567,6 +567,7 @@ public class QJavalinApiHandler
|
||||
// and throw a 400-series error (tell the user bad-request), rather than, we're doing a 500 (server error)
|
||||
|
||||
getInput.setPrimaryKey(primaryKey);
|
||||
getInput.setIncludeAssociations(true);
|
||||
|
||||
GetAction getAction = new GetAction();
|
||||
GetOutput getOutput = getAction.execute(getInput);
|
||||
@ -616,6 +617,7 @@ public class QJavalinApiHandler
|
||||
QJavalinAccessLogger.logStart("apiQuery", logPair("table", tableName));
|
||||
|
||||
queryInput.setTableName(tableName);
|
||||
queryInput.setIncludeAssociations(true);
|
||||
|
||||
PermissionsHelper.checkTablePermissionThrowing(queryInput, TablePermissionSubType.READ);
|
||||
|
||||
@ -795,6 +797,16 @@ public class QJavalinApiHandler
|
||||
output.put("pageNo", pageNo);
|
||||
output.put("pageSize", pageSize);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// map record fields for api //
|
||||
// note - don't put them in the output until after the count, just because that looks a little nicer, i think //
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
ArrayList<Map<String, Serializable>> records = new ArrayList<>();
|
||||
for(QRecord record : queryOutput.getRecords())
|
||||
{
|
||||
records.add(QRecordApiAdapter.qRecordToApiMap(record, tableName, version));
|
||||
}
|
||||
|
||||
/////////////////////////////
|
||||
// optionally do the count //
|
||||
/////////////////////////////
|
||||
@ -807,14 +819,6 @@ public class QJavalinApiHandler
|
||||
output.put("count", countOutput.getCount());
|
||||
}
|
||||
|
||||
///////////////////////////////
|
||||
// map record fields for api //
|
||||
///////////////////////////////
|
||||
ArrayList<Map<String, Serializable>> records = new ArrayList<>();
|
||||
for(QRecord record : queryOutput.getRecords())
|
||||
{
|
||||
records.add(QRecordApiAdapter.qRecordToApiMap(record, tableName, version));
|
||||
}
|
||||
output.put("records", records);
|
||||
|
||||
QJavalinAccessLogger.logEndSuccess(logPair("recordCount", queryOutput.getRecords().size()), QJavalinAccessLogger.logPairIfSlow("filter", filter, SLOW_LOG_THRESHOLD_MS));
|
||||
|
Reference in New Issue
Block a user