From 0e5e36cc7fff2477c17d474e0d18e698d475d96d Mon Sep 17 00:00:00 2001 From: Ryan Doherty Date: Sun, 4 Feb 2024 21:57:48 -0500 Subject: [PATCH 1/2] Clarify what code is doing and error message --- .../query/param/AbstractDependentParam.java | 29 ++++++++++++------- .../query/param/ParameterContainerImpl.java | 8 ++--- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/Model/src/main/java/org/gusdb/wdk/model/query/param/AbstractDependentParam.java b/Model/src/main/java/org/gusdb/wdk/model/query/param/AbstractDependentParam.java index 8a574d8b15..1e099289d0 100644 --- a/Model/src/main/java/org/gusdb/wdk/model/query/param/AbstractDependentParam.java +++ b/Model/src/main/java/org/gusdb/wdk/model/query/param/AbstractDependentParam.java @@ -263,20 +263,29 @@ static JSONObject getDependedParamValuesJson( return dependedParamValuesJson; } - public void checkParam(String queryFullName, String parentParamName, Map rootParamMap, List ancestorParamNames) throws WdkModelException { - if(!rootParamMap.keySet().contains(getName())) { - throw new WdkModelException("The param " + getFullName() + " is not found in the param map of the root query " + queryFullName + "."); - } - if(ancestorParamNames.contains(getFullName())) { - throw new WdkModelException("The param " + getFullName() + " is a cyclic dependency in the root query " + queryFullName + "."); + public void checkParam(String queryFullName, Map rootParamMap, List ancestorParamNames) throws WdkModelException { + + // check for cyclic dependencies and add this param to dependency chain + if (ancestorParamNames.contains(getFullName())) { + throw new WdkModelException("The param " + getFullName() + " is a cyclic dependency under ID query " + queryFullName + "."); } ancestorParamNames.add(getFullName()); - List queries = getQueries(); - for(Query query : queries) { + + // check to ensure params in required queries are referenced by the ID query (dependency relationships within a query are checked elsewhere) + for (Query query : getQueries()) { Map paramMap = query.getParamMap(); - for(Param param : paramMap.values()) { + for (Param param : paramMap.values()) { if (param instanceof AbstractDependentParam) { - ((AbstractDependentParam) param).checkParam(queryFullName, parentParamName, rootParamMap, new ArrayList(ancestorParamNames)); + + // check to make sure a dependent param's query's params are also params on the ID query + if (!rootParamMap.keySet().contains(param.getName())) { + throw new WdkModelException("The dependent param " + param.getFullName() + + " of query " + query.getFullName() + " (needed by param " + getFullName() + + ") is not found in the param map of the ID query " + queryFullName + "."); + } + + // recurse through dependent param queries + ((AbstractDependentParam) param).checkParam(queryFullName, rootParamMap, new ArrayList<>(ancestorParamNames)); } } } diff --git a/Model/src/main/java/org/gusdb/wdk/model/query/param/ParameterContainerImpl.java b/Model/src/main/java/org/gusdb/wdk/model/query/param/ParameterContainerImpl.java index 4ea4bbf439..77bae2aa22 100644 --- a/Model/src/main/java/org/gusdb/wdk/model/query/param/ParameterContainerImpl.java +++ b/Model/src/main/java/org/gusdb/wdk/model/query/param/ParameterContainerImpl.java @@ -110,15 +110,13 @@ public static Param getUserParam(WdkModel wdkModel) throws WdkModelException { } public void validateDependentParams() throws WdkModelException { - validateDependentParams(getFullName(), paramMap); - } - - private static void validateDependentParams(String queryName, Map paramMap) throws WdkModelException { // TODO: Need to validate that no params in the rootQuery paramMap have a short name that in fact refers // to different params (i.e., params with different full names but the same short name). + + // for each dependent param, ensure all the params it depends on, and that any of its queries' params depend on, are present in this container for (Param param : paramMap.values()) { if (param instanceof AbstractDependentParam) { - ((AbstractDependentParam) param).checkParam(queryName, null, paramMap, new ArrayList<>()); + ((AbstractDependentParam) param).checkParam(getFullName(), paramMap, new ArrayList<>()); } } } From 4b690c8f09b8110a959a7132390776686a135c24 Mon Sep 17 00:00:00 2001 From: Ryan Doherty Date: Mon, 11 Mar 2024 06:28:48 -0400 Subject: [PATCH 2/2] Slight error message verbiage change --- .../org/gusdb/wdk/model/query/param/AbstractDependentParam.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Model/src/main/java/org/gusdb/wdk/model/query/param/AbstractDependentParam.java b/Model/src/main/java/org/gusdb/wdk/model/query/param/AbstractDependentParam.java index 1e099289d0..84229a0ca5 100644 --- a/Model/src/main/java/org/gusdb/wdk/model/query/param/AbstractDependentParam.java +++ b/Model/src/main/java/org/gusdb/wdk/model/query/param/AbstractDependentParam.java @@ -281,7 +281,7 @@ public void checkParam(String queryFullName, Map rootParamMap, Lis if (!rootParamMap.keySet().contains(param.getName())) { throw new WdkModelException("The dependent param " + param.getFullName() + " of query " + query.getFullName() + " (needed by param " + getFullName() + - ") is not found in the param map of the ID query " + queryFullName + "."); + ") is not found among the parameters declared in the ID query " + queryFullName + "."); } // recurse through dependent param queries