From 90ac411b89ebbea22e3c3ad708a3aa7ab46b1477 Mon Sep 17 00:00:00 2001 From: Ryan Doherty Date: Tue, 20 Aug 2024 00:22:47 -0400 Subject: [PATCH 1/2] Add ability to include/exclude sql queries based on DB platform of the App DB --- Model/lib/rng/wdkModel.rng | 11 +++ .../java/org/gusdb/wdk/model/WdkModel.java | 4 +- .../org/gusdb/wdk/model/WdkModelBase.java | 70 +++++++++++++++---- .../org/gusdb/wdk/model/query/QuerySet.java | 9 ++- 4 files changed, 76 insertions(+), 18 deletions(-) diff --git a/Model/lib/rng/wdkModel.rng b/Model/lib/rng/wdkModel.rng index f5528beac9..a1524fa489 100644 --- a/Model/lib/rng/wdkModel.rng +++ b/Model/lib/rng/wdkModel.rng @@ -83,6 +83,16 @@ + + + + + + + + + + @@ -1105,6 +1115,7 @@ + diff --git a/Model/src/main/java/org/gusdb/wdk/model/WdkModel.java b/Model/src/main/java/org/gusdb/wdk/model/WdkModel.java index 410a3850d0..c1c260b8cc 100644 --- a/Model/src/main/java/org/gusdb/wdk/model/WdkModel.java +++ b/Model/src/main/java/org/gusdb/wdk/model/WdkModel.java @@ -903,7 +903,7 @@ private void excludeResources() throws WdkModelException { // remove query sets for (QuerySet querySet : querySetList) { if (querySet.include(_projectId)) { - querySet.excludeResources(_projectId); + querySet.excludeResources(_projectId, _modelConfig.getAppDB().getPlatformEnum()); addSet(querySet, querySets); } } @@ -1041,7 +1041,7 @@ private void createInternalSets() throws WdkModelException { internalQuerySet.setName(Utilities.INTERNAL_QUERY_SET); internalQuerySet.setDoNotTest(true); addQuerySet(internalQuerySet); - internalQuerySet.excludeResources(_projectId); + internalQuerySet.excludeResources(_projectId, _modelConfig.getAppDB().getPlatformEnum()); } // create a query set to hold all internal questions, that is, the diff --git a/Model/src/main/java/org/gusdb/wdk/model/WdkModelBase.java b/Model/src/main/java/org/gusdb/wdk/model/WdkModelBase.java index 065b79d308..ec09e7d235 100644 --- a/Model/src/main/java/org/gusdb/wdk/model/WdkModelBase.java +++ b/Model/src/main/java/org/gusdb/wdk/model/WdkModelBase.java @@ -2,13 +2,16 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import org.apache.log4j.Logger; +import org.gusdb.fgputil.db.platform.SupportedPlatform; import org.gusdb.wdk.model.RngAnnotations.RngUndefined; /** @@ -40,12 +43,17 @@ public abstract class WdkModelBase { private Set _includeProjects; private Set _excludeProjects; + private Set _includeDbPlatforms; + private Set _excludeDbPlatforms; + private List _propertyLists; private Map _propertyListMap; public WdkModelBase() { _includeProjects = new LinkedHashSet<>(); _excludeProjects = new LinkedHashSet<>(); + _includeDbPlatforms = new LinkedHashSet<>(); + _excludeDbPlatforms = new LinkedHashSet<>(); _propertyLists = new ArrayList<>(); _propertyListMap = new LinkedHashMap<>(); } @@ -55,6 +63,8 @@ public WdkModelBase(WdkModelBase base) { _resolved = base._resolved; _includeProjects = new LinkedHashSet<>(base._includeProjects); _excludeProjects = new LinkedHashSet<>(base._excludeProjects); + _includeDbPlatforms = new LinkedHashSet<>(base._includeDbPlatforms); + _excludeDbPlatforms = new LinkedHashSet<>(base._excludeDbPlatforms); if (base._propertyLists != null) _propertyLists = new ArrayList<>(base._propertyLists); if (base._propertyListMap != null) @@ -78,14 +88,7 @@ public WdkModelBase clone() { */ @RngUndefined public void setExcludeProjects(String excludeProjects) { - excludeProjects = excludeProjects.trim(); - if (excludeProjects.isEmpty()) - return; - - String[] projects = excludeProjects.split(","); - for (String project : projects) { - _excludeProjects.add(project.trim()); - } + _excludeProjects.addAll(parseCommaDelimitedValues(excludeProjects)); } /** @@ -94,14 +97,42 @@ public void setExcludeProjects(String excludeProjects) { */ @RngUndefined public void setIncludeProjects(String includeProjects) { - includeProjects = includeProjects.trim(); - if (includeProjects.isEmpty()) - return; + _includeProjects.addAll(parseCommaDelimitedValues(includeProjects)); + } - String[] projects = includeProjects.split(","); - for (String project : projects) { - _includeProjects.add(project.trim()); + /** + * @param excludeDbPlatforms + * the excludeDbPlatforms to set + */ + @RngUndefined + public void setExcludeDbPlatforms(String excludeDbPlatforms) { + _excludeDbPlatforms.addAll( + parseCommaDelimitedValues(excludeDbPlatforms) + .stream().map(SupportedPlatform::toPlatform).collect(Collectors.toSet())); + } + + /** + * @param includeDbPlatforms + * the includeDbPlatforms to set + */ + @RngUndefined + public void setIncludeDbPlatforms(String includeDbPlatforms) { + _includeDbPlatforms.addAll( + parseCommaDelimitedValues(includeDbPlatforms) + .stream().map(SupportedPlatform::toPlatform).collect(Collectors.toSet())); + } + + private Set parseCommaDelimitedValues(String unparsedList) { + unparsedList = unparsedList.trim(); + if (unparsedList.isEmpty()) + return Collections.emptySet(); + + String[] rawValues = unparsedList.split(","); + Set values = new LinkedHashSet<>(); + for (String value : rawValues) { + values.add(value.trim()); } + return values; } /** @@ -115,6 +146,17 @@ public boolean include(String projectId) { } } + /** + * @return true if the object is included in the current AppDB platform + */ + public boolean include(SupportedPlatform dbPlatform) { + if (_includeDbPlatforms.isEmpty()) { // no inclusions assigned + return !_excludeDbPlatforms.contains(dbPlatform); + } else { // has inclusions + return _includeDbPlatforms.contains(dbPlatform); + } + } + /** * @return the resolved */ diff --git a/Model/src/main/java/org/gusdb/wdk/model/query/QuerySet.java b/Model/src/main/java/org/gusdb/wdk/model/query/QuerySet.java index aaff34b7c2..84042d5697 100644 --- a/Model/src/main/java/org/gusdb/wdk/model/query/QuerySet.java +++ b/Model/src/main/java/org/gusdb/wdk/model/query/QuerySet.java @@ -8,6 +8,7 @@ import java.util.stream.Collectors; import org.apache.log4j.Logger; +import org.gusdb.fgputil.db.platform.SupportedPlatform; import org.gusdb.wdk.model.ModelSetI; import org.gusdb.wdk.model.Utilities; import org.gusdb.wdk.model.WdkModel; @@ -215,10 +216,14 @@ public String toString() { } @Override - public void excludeResources(String projectId) throws WdkModelException { + public void excludeResources(String projectId) { + throw new UnsupportedOperationException("QuerySet excludes must be handled by excludeResources(projectId,supportedPlatform"); + } + + public void excludeResources(String projectId, SupportedPlatform supportedPlatform) throws WdkModelException { // exclude queries for (Query query : _queryList) { - if (query.include(projectId)) { + if (query.include(projectId) && query.include(supportedPlatform)) { query.excludeResources(projectId); String queryName = query.getName(); if (_queries.containsKey(queryName)) From c6eeee20a7d4356ec3fe42cc52b24ac14e6e55ad Mon Sep 17 00:00:00 2001 From: Ryan Doherty Date: Wed, 21 Aug 2024 09:25:08 -0400 Subject: [PATCH 2/2] Improve exception message in rare cases --- Model/src/main/java/org/gusdb/wdk/model/WdkModelException.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Model/src/main/java/org/gusdb/wdk/model/WdkModelException.java b/Model/src/main/java/org/gusdb/wdk/model/WdkModelException.java index 5ce19e94d3..557379771f 100644 --- a/Model/src/main/java/org/gusdb/wdk/model/WdkModelException.java +++ b/Model/src/main/java/org/gusdb/wdk/model/WdkModelException.java @@ -33,6 +33,8 @@ public static WdkModelException translateFrom(Exception e) { } public static WdkModelException translateFrom(Exception e, String newMessage) { + // if passed message is null, use name of original exception + if (newMessage == null) newMessage = e.getClass().getSimpleName(); // if exception is already a WdkModelException, simply return if (e instanceof WdkModelException) return (WdkModelException)e; // check underlying exception; a WdkModelException may simply have been wrapped