Skip to content

Commit

Permalink
Merge pull request #104 from VEuPathDB/platform-excludes
Browse files Browse the repository at this point in the history
Add ability to include/exclude sql queries based on DB platform of the App DB
  • Loading branch information
ryanrdoherty authored Aug 21, 2024
2 parents 92c2e74 + c6eeee2 commit a31c830
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 18 deletions.
11 changes: 11 additions & 0 deletions Model/lib/rng/wdkModel.rng
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@
</optional>
</define>

<!-- define inclusion/exclusion attributes for DB platform -->
<define name="DbPlatformIncludeExclude">
<optional>
<attribute name="includeDbPlatforms" />
</optional>
<optional>
<attribute name="excludeDbPlatforms" />
</optional>
</define>

<!-- define constants -->
<define name="constant">
<element name="constant">
Expand Down Expand Up @@ -1105,6 +1115,7 @@
<define name="sqlQuery">
<element name="sqlQuery">
<ref name="QueryBaseContents" />
<ref name="DbPlatformIncludeExclude" />
<optional>
<attribute name="attributeMetaQueryRef" />
</optional>
Expand Down
4 changes: 2 additions & 2 deletions Model/src/main/java/org/gusdb/wdk/model/WdkModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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
Expand Down
70 changes: 56 additions & 14 deletions Model/src/main/java/org/gusdb/wdk/model/WdkModelBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -40,12 +43,17 @@ public abstract class WdkModelBase {
private Set<String> _includeProjects;
private Set<String> _excludeProjects;

private Set<SupportedPlatform> _includeDbPlatforms;
private Set<SupportedPlatform> _excludeDbPlatforms;

private List<PropertyList> _propertyLists;
private Map<String, String[]> _propertyListMap;

public WdkModelBase() {
_includeProjects = new LinkedHashSet<>();
_excludeProjects = new LinkedHashSet<>();
_includeDbPlatforms = new LinkedHashSet<>();
_excludeDbPlatforms = new LinkedHashSet<>();
_propertyLists = new ArrayList<>();
_propertyListMap = new LinkedHashMap<>();
}
Expand All @@ -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)
Expand All @@ -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));
}

/**
Expand All @@ -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<String> parseCommaDelimitedValues(String unparsedList) {
unparsedList = unparsedList.trim();
if (unparsedList.isEmpty())
return Collections.emptySet();

String[] rawValues = unparsedList.split(",");
Set<String> values = new LinkedHashSet<>();
for (String value : rawValues) {
values.add(value.trim());
}
return values;
}

/**
Expand All @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions Model/src/main/java/org/gusdb/wdk/model/query/QuerySet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit a31c830

Please sign in to comment.