mirror of
https://github.com/DependencyTrack/dependency-track.git
synced 2025-11-01 22:20:56 +00:00
#1185 - Adding support for querying projects by classifier
Signed-off-by: Steve Springett <steve@springett.us>
This commit is contained in:
parent
f7ff2294c4
commit
f3fe456bc0
3 changed files with 65 additions and 1 deletions
|
|
@ -32,6 +32,7 @@ import org.dependencytrack.auth.Permissions;
|
|||
import org.dependencytrack.event.IndexEvent;
|
||||
import org.dependencytrack.model.Analysis;
|
||||
import org.dependencytrack.model.AnalysisComment;
|
||||
import org.dependencytrack.model.Classifier;
|
||||
import org.dependencytrack.model.Component;
|
||||
import org.dependencytrack.model.ConfigPropertyConstants;
|
||||
import org.dependencytrack.model.FindingAttribution;
|
||||
|
|
@ -235,7 +236,7 @@ final class ProjectQueryManager extends QueryManager implements IQueryManager {
|
|||
final Query<Project> query = pm.newQuery(Project.class);
|
||||
final String queryFilter;
|
||||
if (excludeInactive) {
|
||||
queryFilter = "(tags.contains(:tag)) && (active == true || active == null))";
|
||||
queryFilter = "(tags.contains(:tag)) && (active == true || active == null)";
|
||||
} else {
|
||||
queryFilter = "(tags.contains(:tag))";
|
||||
}
|
||||
|
|
@ -256,6 +257,37 @@ final class ProjectQueryManager extends QueryManager implements IQueryManager {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a paginated result of projects by classifier.
|
||||
* @param classifier the classifier of the Project
|
||||
* @return a List of Projects of the specified classifier
|
||||
*/
|
||||
public PaginatedResult getProjects(final Classifier classifier, final boolean includeMetrics, final boolean excludeInactive) {
|
||||
final PaginatedResult result;
|
||||
final Query<Project> query = pm.newQuery(Project.class);
|
||||
final String queryFilter;
|
||||
if (excludeInactive) {
|
||||
queryFilter = "(classifier == :classifier) && (active == true || active == null)";
|
||||
} else {
|
||||
queryFilter = "(classifier == :classifier)";
|
||||
}
|
||||
if (orderBy == null) {
|
||||
query.setOrdering("name asc");
|
||||
}
|
||||
final Map<String, Object> params = new HashMap<>();
|
||||
params.put("classifier", classifier);
|
||||
preprocessACLs(query, queryFilter, params, false);
|
||||
result = execute(query, params);
|
||||
if (includeMetrics) {
|
||||
// Populate each Project object in the paginated result with transitive related
|
||||
// data to minimize the number of round trips a client needs to make, process, and render.
|
||||
for (Project project : result.getList(Project.class)) {
|
||||
project.setMetrics(getMostRecentProjectMetrics(project));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a paginated result of projects by tag.
|
||||
* @param tag the tag associated with the Project
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue