mirror of
https://github.com/DependencyTrack/dependency-track.git
synced 2025-10-20 00:13:20 +00:00
refactor: move ProjectQueryFilterBuilder to package
Signed-off-by: Pinto Spindler, Stephan <25225092+s-spindler@users.noreply.github.com>
This commit is contained in:
parent
815971aa69
commit
7c912cf3a4
2 changed files with 82 additions and 71 deletions
|
@ -806,75 +806,4 @@ final class ProjectQueryManager extends QueryManager implements IQueryManager {
|
|||
return hasPermission(apiKey, Permissions.ACCESS_MANAGEMENT.name());
|
||||
}
|
||||
|
||||
static class ProjectQueryFilterBuilder {
|
||||
|
||||
final private Map<String, Object> params;
|
||||
final private List<String> filterCriteria;
|
||||
|
||||
ProjectQueryFilterBuilder() {
|
||||
this.params = new HashMap<>();
|
||||
this.filterCriteria = new ArrayList<>();
|
||||
}
|
||||
|
||||
ProjectQueryFilterBuilder excludeInactive(boolean excludeInactive) {
|
||||
if (excludeInactive) {
|
||||
filterCriteria.add("(active == true || active == null)");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
ProjectQueryFilterBuilder withTeam(Team team) {
|
||||
params.put("team", team);
|
||||
filterCriteria.add("(accessTeams.contains(:team))");
|
||||
return this;
|
||||
}
|
||||
|
||||
ProjectQueryFilterBuilder withName(String name) {
|
||||
params.put("name", name);
|
||||
filterCriteria.add("(name == :name)");
|
||||
return this;
|
||||
}
|
||||
|
||||
ProjectQueryFilterBuilder withVersion(String version) {
|
||||
params.put("version", version);
|
||||
filterCriteria.add("(version == :version)");
|
||||
return this;
|
||||
}
|
||||
|
||||
ProjectQueryFilterBuilder withTag(Tag tag) {
|
||||
params.put("tag", tag);
|
||||
filterCriteria.add("(tags.contains(:tag))");
|
||||
return this;
|
||||
}
|
||||
|
||||
ProjectQueryFilterBuilder withClassifier(Classifier classifier) {
|
||||
params.put("classifier", classifier);
|
||||
filterCriteria.add("(classifier == :classifier)");
|
||||
return this;
|
||||
}
|
||||
|
||||
ProjectQueryFilterBuilder withFuzzyName(String name, Tag tag) {
|
||||
params.put("name", name);
|
||||
|
||||
final String filter;
|
||||
if (tag != null) {
|
||||
params.put("tag", tag);
|
||||
filter = "(name.toLowerCase().matches(:name) || tags.contains(:tag))";
|
||||
|
||||
} else {
|
||||
filter = "(name.toLowerCase().matches(:name))";
|
||||
}
|
||||
|
||||
filterCriteria.add(filter);
|
||||
return this;
|
||||
}
|
||||
|
||||
String buildFilter() {
|
||||
return "(" + String.join(" && ", this.filterCriteria) + ")";
|
||||
}
|
||||
|
||||
Map<String, Object> getParams() {
|
||||
return params;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue