mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-19 21:50:45 +00:00
Try to add hints about unrecognized field names (if they're in other api versions)
This commit is contained in:
@ -35,6 +35,8 @@ import com.kingsrook.qqq.api.model.APIVersion;
|
||||
import com.kingsrook.qqq.api.model.APIVersionRange;
|
||||
import com.kingsrook.qqq.api.model.actions.ApiFieldCustomValueMapper;
|
||||
import com.kingsrook.qqq.api.model.actions.GetTableApiFieldsInput;
|
||||
import com.kingsrook.qqq.api.model.metadata.ApiInstanceMetaData;
|
||||
import com.kingsrook.qqq.api.model.metadata.ApiInstanceMetaDataContainer;
|
||||
import com.kingsrook.qqq.api.model.metadata.fields.ApiFieldMetaData;
|
||||
import com.kingsrook.qqq.api.model.metadata.fields.ApiFieldMetaDataContainer;
|
||||
import com.kingsrook.qqq.api.model.metadata.tables.ApiAssociationMetaData;
|
||||
@ -289,7 +291,27 @@ public class QRecordApiAdapter
|
||||
|
||||
if(!unrecognizedFieldNames.isEmpty())
|
||||
{
|
||||
throw (new QBadRequestException("Request body contained " + unrecognizedFieldNames.size() + " unrecognized field name" + StringUtils.plural(unrecognizedFieldNames) + ": " + StringUtils.joinWithCommasAndAnd(unrecognizedFieldNames)));
|
||||
List<String> otherVersionHints = new ArrayList<>();
|
||||
try
|
||||
{
|
||||
for(String unrecognizedFieldName : unrecognizedFieldNames)
|
||||
{
|
||||
String hint = lookForFieldInOtherVersions(unrecognizedFieldName, tableName, apiName, apiVersion);
|
||||
if(hint != null)
|
||||
{
|
||||
otherVersionHints.add(hint);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
LOG.warn("Error looking for unrecognized field names in other api versions", e);
|
||||
}
|
||||
|
||||
throw (new QBadRequestException("Request body contained "
|
||||
+ (unrecognizedFieldNames.size() + " unrecognized field name" + StringUtils.plural(unrecognizedFieldNames) + ": " + StringUtils.joinWithCommasAndAnd(unrecognizedFieldNames) + ". ")
|
||||
+ (CollectionUtils.nullSafeIsEmpty(otherVersionHints) ? "" : StringUtils.join(" ", otherVersionHints))
|
||||
));
|
||||
}
|
||||
|
||||
return (qRecord);
|
||||
@ -297,6 +319,37 @@ public class QRecordApiAdapter
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private static String lookForFieldInOtherVersions(String unrecognizedFieldName, String tableName, String apiName, String apiVersion) throws QException
|
||||
{
|
||||
ApiInstanceMetaDataContainer apiInstanceMetaDataContainer = ApiInstanceMetaDataContainer.of(QContext.getQInstance());
|
||||
ApiInstanceMetaData apiInstanceMetaData = apiInstanceMetaDataContainer.getApiInstanceMetaData(apiName);
|
||||
|
||||
List<String> versionsWithThisField = new ArrayList<>();
|
||||
for(APIVersion supportedVersion : apiInstanceMetaData.getSupportedVersions())
|
||||
{
|
||||
if(!supportedVersion.toString().equals(apiVersion))
|
||||
{
|
||||
Map<String, QFieldMetaData> versionFields = getTableApiFieldMap(new ApiNameVersionAndTableName(apiName, supportedVersion.toString(), tableName));
|
||||
if(versionFields.containsKey(unrecognizedFieldName))
|
||||
{
|
||||
versionsWithThisField.add(supportedVersion.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(CollectionUtils.nullSafeHasContents(versionsWithThisField))
|
||||
{
|
||||
return (unrecognizedFieldName + " does not exist in version " + apiVersion + ", but does exist in versions: " + StringUtils.joinWithCommasAndAnd(versionsWithThisField) + ". ");
|
||||
}
|
||||
|
||||
return (null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
Reference in New Issue
Block a user