From 5dfa10912edbc8e318052296ce1d4d3f5848a738 Mon Sep 17 00:00:00 2001 From: Darin Kelkhoff Date: Tue, 8 Aug 2023 16:45:30 -0500 Subject: [PATCH] CE-607 Slight tweaks to exposed join field validation --- .../core/instances/QInstanceValidator.java | 9 +++++++-- .../core/model/metadata/tables/ExposedJoin.java | 15 +++++++++++---- .../core/instances/QInstanceValidatorTest.java | 15 +++++++++------ 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/instances/QInstanceValidator.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/instances/QInstanceValidator.java index 7c253031..38aae827 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/instances/QInstanceValidator.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/instances/QInstanceValidator.java @@ -1109,7 +1109,12 @@ public class QInstanceValidator { 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 otherTableName = parts[0]; @@ -1120,7 +1125,7 @@ public class QInstanceValidator List 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.")) { - 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 + "]."); } diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/tables/ExposedJoin.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/tables/ExposedJoin.java index f66b1b23..6c3fa7b0 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/tables/ExposedJoin.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/tables/ExposedJoin.java @@ -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) { @@ -70,8 +80,6 @@ public class ExposedJoin { 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!) // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -204,5 +212,4 @@ public class ExposedJoin this.joinPath = joinPath; return (this); } - } diff --git a/qqq-backend-core/src/test/java/com/kingsrook/qqq/backend/core/instances/QInstanceValidatorTest.java b/qqq-backend-core/src/test/java/com/kingsrook/qqq/backend/core/instances/QInstanceValidatorTest.java index 84e48161..f66dfa16 100644 --- a/qqq-backend-core/src/test/java/com/kingsrook/qqq/backend/core/instances/QInstanceValidatorTest.java +++ b/qqq-backend-core/src/test/java/com/kingsrook/qqq/backend/core/instances/QInstanceValidatorTest.java @@ -854,12 +854,15 @@ class QInstanceValidatorTest extends BaseTest 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]."); - assertValidationFailureReasons(qInstance -> - { - QTableMetaData table = qInstance.getTable(TestUtils.TABLE_NAME_LINE_ITEM); - putAllFieldsInASection.accept(table); - table.getSections().get(0).getFieldNames().add("foo.bar"); - }, "unrecognized table name [foo]"); + ///////////////////////////////////////////////////////////////////////////// + // this is aactually allowed, well, just not considered as a join-field... // + ///////////////////////////////////////////////////////////////////////////// + // assertValidationFailureReasons(qInstance -> + // { + // 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 -> {