Skip to content

Commit

Permalink
Merge pull request #79 from VEuPathDB/dependent-param-checks
Browse files Browse the repository at this point in the history
Clarify what code is doing and improve error message
  • Loading branch information
ryanrdoherty authored Mar 11, 2024
2 parents 3f439d3 + 4b690c8 commit 5b55c5a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
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

0 comments on commit 5b55c5a

Please sign in to comment.