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 8a574d8b1..84229a0ca 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 among the parameters declared in 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 4ea4bbf43..77bae2aa2 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<>()); } } }