Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify what code is doing and improve error message #79

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -263,20 +263,29 @@ static JSONObject getDependedParamValuesJson(
return dependedParamValuesJson;
}

public void checkParam(String queryFullName, String parentParamName, Map<String,Param> rootParamMap, List<String> 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<String,Param> rootParamMap, List<String> 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<Query> 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<String,Param> 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<String>(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));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Param> 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<>());
}
}
}
Expand Down
Loading