Add doCheckTableApiVersion, so apps can avoid new error if table version isn't in api

This commit is contained in:
2025-06-02 12:02:07 -05:00
parent c364b2c0be
commit 369d501071
3 changed files with 50 additions and 3 deletions

View File

@ -46,6 +46,7 @@ import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
import com.kingsrook.qqq.backend.core.utils.ObjectUtils;
import org.apache.commons.lang3.BooleanUtils;
import static com.kingsrook.qqq.backend.core.logging.LogUtils.logPair;
@ -153,7 +154,7 @@ public class GetTableApiFieldsAction extends AbstractQActionFunction<GetTableApi
APIVersion version = new APIVersion(input.getVersion());
APIVersionRange tableApiVersionRange = getApiVersionRange(input.getApiName(), table);
if(!tableApiVersionRange.includes(version))
if(BooleanUtils.isTrue(input.getDoCheckTableApiVersion()) && !tableApiVersionRange.includes(version))
{
throw (new QNotFoundException("Table [" + input.getTableName() + "] was not found in this version of this api."));
}

View File

@ -34,6 +34,12 @@ public class GetTableApiFieldsInput extends AbstractActionInput
private String tableName;
private String version;
/////////////////////////////////////////////////////////////////////////////////////
// by default, this action will throw if the input table isn't in the api version. //
// but, to preserve legacy behavior where that didn't happen, allow this input. //
/////////////////////////////////////////////////////////////////////////////////////
private Boolean doCheckTableApiVersion = true;
/*******************************************************************************
@ -127,4 +133,35 @@ public class GetTableApiFieldsInput extends AbstractActionInput
return (this);
}
/*******************************************************************************
** Getter for doCheckTableApiVersion
*******************************************************************************/
public Boolean getDoCheckTableApiVersion()
{
return (this.doCheckTableApiVersion);
}
/*******************************************************************************
** Setter for doCheckTableApiVersion
*******************************************************************************/
public void setDoCheckTableApiVersion(Boolean doCheckTableApiVersion)
{
this.doCheckTableApiVersion = doCheckTableApiVersion;
}
/*******************************************************************************
** Fluent setter for doCheckTableApiVersion
*******************************************************************************/
public GetTableApiFieldsInput withDoCheckTableApiVersion(Boolean doCheckTableApiVersion)
{
this.doCheckTableApiVersion = doCheckTableApiVersion;
return (this);
}
}

View File

@ -66,6 +66,7 @@ class GetTableApiFieldsActionTest extends BaseTest
}
/*******************************************************************************
**
*******************************************************************************/
@ -132,8 +133,8 @@ class GetTableApiFieldsActionTest extends BaseTest
@Test
void testTablesNotFound() throws QException
{
String tableNameVersion2plus = "tableNameVersion2plus";
QInstance qInstance = QContext.getQInstance();
String tableNameVersion2plus = "tableNameVersion2plus";
QInstance qInstance = QContext.getQInstance();
qInstance.addTable(new QTableMetaData()
.withName(tableNameVersion2plus)
.withSupplementalMetaData(new ApiTableMetaDataContainer().withApiTableMetaData(TestUtils.API_NAME, new ApiTableMetaData().withInitialVersion("2")))
@ -165,6 +166,14 @@ class GetTableApiFieldsActionTest extends BaseTest
assertThatThrownBy(() -> getFields(tableNameVersion2through4, "5")).isInstanceOf(QNotFoundException.class);
assertThatThrownBy(() -> getFields(tableNameNoApis, "1")).isInstanceOf(QNotFoundException.class);
///////////////////////////////////////////////////////////////////////////////////////////////////////
// test the withDoCheckTableApiVersion input flag. //
// set up an input that'll fail (verify it fails) - then set the flag to false and make sure no fail //
///////////////////////////////////////////////////////////////////////////////////////////////////////
GetTableApiFieldsInput input = new GetTableApiFieldsInput().withApiName(TestUtils.API_NAME).withTableName(tableNameVersion2through4).withVersion("1");
assertThatThrownBy(() -> new GetTableApiFieldsAction().execute(input));
new GetTableApiFieldsAction().execute(input.withDoCheckTableApiVersion(false));
}
}