mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 21:20:45 +00:00
CE-607 Slight tweaks to exposed join field validation
This commit is contained in:
@ -1109,7 +1109,12 @@ public class QInstanceValidator
|
|||||||
{
|
{
|
||||||
for(String fieldName : section.getFieldNames())
|
for(String fieldName : section.getFieldNames())
|
||||||
{
|
{
|
||||||
if(fieldName.contains("."))
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// note - this was originally written as an assertion: //
|
||||||
|
// if(assertCondition(qInstance.getTable(otherTableName) != null, sectionPrefix + "join-field " + fieldName + ", which is referencing an unrecognized table name [" + otherTableName + "]")) //
|
||||||
|
// but... then a field name with dots gives us a bad time here, so... //
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
if(fieldName.contains(".") && qInstance.getTable(fieldName.split("\\.")[0]) != null)
|
||||||
{
|
{
|
||||||
String[] parts = fieldName.split("\\.");
|
String[] parts = fieldName.split("\\.");
|
||||||
String otherTableName = parts[0];
|
String otherTableName = parts[0];
|
||||||
@ -1120,7 +1125,7 @@ public class QInstanceValidator
|
|||||||
List<ExposedJoin> matchedExposedJoins = CollectionUtils.nonNullList(table.getExposedJoins()).stream().filter(ej -> otherTableName.equals(ej.getJoinTable())).toList();
|
List<ExposedJoin> matchedExposedJoins = CollectionUtils.nonNullList(table.getExposedJoins()).stream().filter(ej -> otherTableName.equals(ej.getJoinTable())).toList();
|
||||||
if(assertCondition(CollectionUtils.nullSafeHasContents(matchedExposedJoins), sectionPrefix + "join-field " + fieldName + ", referencing table [" + otherTableName + "] which is not an exposed join on this table."))
|
if(assertCondition(CollectionUtils.nullSafeHasContents(matchedExposedJoins), sectionPrefix + "join-field " + fieldName + ", referencing table [" + otherTableName + "] which is not an exposed join on this table."))
|
||||||
{
|
{
|
||||||
assertCondition(!matchedExposedJoins.get(0).getIsMany(), sectionPrefix + "join-field " + fieldName + " references an is-many join, which is not supported.");
|
assertCondition(!matchedExposedJoins.get(0).getIsMany(qInstance), sectionPrefix + "join-field " + fieldName + " references an is-many join, which is not supported.");
|
||||||
}
|
}
|
||||||
assertCondition(qInstance.getTable(otherTableName).getFields().containsKey(foreignFieldName), sectionPrefix + "join-field " + fieldName + " specifies a fieldName [" + foreignFieldName + "] which does not exist in that table [" + otherTableName + "].");
|
assertCondition(qInstance.getTable(otherTableName).getFields().containsKey(foreignFieldName), sectionPrefix + "join-field " + fieldName + " specifies a fieldName [" + foreignFieldName + "] which does not exist in that table [" + otherTableName + "].");
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,17 @@ public class ExposedJoin
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public Boolean getIsMany()
|
public boolean getIsMany()
|
||||||
|
{
|
||||||
|
return (getIsMany(QContext.getQInstance()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public Boolean getIsMany(QInstance qInstance)
|
||||||
{
|
{
|
||||||
if(isMany == null)
|
if(isMany == null)
|
||||||
{
|
{
|
||||||
@ -70,8 +80,6 @@ public class ExposedJoin
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
QInstance qInstance = QContext.getQInstance();
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// loop backward through the joinPath, starting at the join table (since we don't know the table that this exposedJoin is attached to!) //
|
// loop backward through the joinPath, starting at the join table (since we don't know the table that this exposedJoin is attached to!) //
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -204,5 +212,4 @@ public class ExposedJoin
|
|||||||
this.joinPath = joinPath;
|
this.joinPath = joinPath;
|
||||||
return (this);
|
return (this);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -854,12 +854,15 @@ class QInstanceValidatorTest extends BaseTest
|
|||||||
table.getSections().get(0).getFieldNames().add(TestUtils.TABLE_NAME_ORDER + ".asdf");
|
table.getSections().get(0).getFieldNames().add(TestUtils.TABLE_NAME_ORDER + ".asdf");
|
||||||
}, "order.asdf specifies a fieldName [asdf] which does not exist in that table [order].");
|
}, "order.asdf specifies a fieldName [asdf] which does not exist in that table [order].");
|
||||||
|
|
||||||
assertValidationFailureReasons(qInstance ->
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
{
|
// this is aactually allowed, well, just not considered as a join-field... //
|
||||||
QTableMetaData table = qInstance.getTable(TestUtils.TABLE_NAME_LINE_ITEM);
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
putAllFieldsInASection.accept(table);
|
// assertValidationFailureReasons(qInstance ->
|
||||||
table.getSections().get(0).getFieldNames().add("foo.bar");
|
// {
|
||||||
}, "unrecognized table name [foo]");
|
// QTableMetaData table = qInstance.getTable(TestUtils.TABLE_NAME_LINE_ITEM);
|
||||||
|
// putAllFieldsInASection.accept(table);
|
||||||
|
// table.getSections().get(0).getFieldNames().add("foo.bar");
|
||||||
|
// }, "unrecognized table name [foo]");
|
||||||
|
|
||||||
assertValidationFailureReasons(qInstance ->
|
assertValidationFailureReasons(qInstance ->
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user