Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,9 @@ NOT EXISTS (
if (query.onlyRoot()) {
whereConditions.add("\"PROJECT\".\"PARENT_PROJECT_ID\" IS NULL");
}
if (query.onlyLatestVersions()) {
whereConditions.add("\"PROJECT\".\"IS_LATEST\"");
}
if (query.searchText() != null) {
whereConditions.add(/* language=SQL */ """
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ public record ListProjectsQuery(
@Nullable String searchText,
boolean excludeInactive,
boolean onlyRoot,
boolean onlyLatestVersions,
boolean includeMetrics) {

public ListProjectsQuery() {
this(null, null, null, null, null, null, null, null, false, false, false);
this(null, null, null, null, null, null, null, null, false, false, false, false);
}

public ListProjectsQuery withNameFilter(@Nullable String nameFilter) {
Expand All @@ -52,6 +53,7 @@ public ListProjectsQuery withNameFilter(@Nullable String nameFilter) {
this.searchText,
this.excludeInactive,
this.onlyRoot,
this.onlyLatestVersions,
this.includeMetrics);
}

Expand All @@ -67,6 +69,7 @@ public ListProjectsQuery withClassifierFilter(@Nullable String classifierFilter)
this.searchText,
this.excludeInactive,
this.onlyRoot,
this.onlyLatestVersions,
this.includeMetrics);
}

Expand All @@ -82,6 +85,7 @@ public ListProjectsQuery withTagFilter(@Nullable String tagFilter) {
this.searchText,
this.excludeInactive,
this.onlyRoot,
this.onlyLatestVersions,
this.includeMetrics);
}

Expand All @@ -97,6 +101,7 @@ public ListProjectsQuery withTeamFilter(@Nullable String teamFilter) {
this.searchText,
this.excludeInactive,
this.onlyRoot,
this.onlyLatestVersions,
this.includeMetrics);
}

Expand All @@ -112,6 +117,7 @@ public ListProjectsQuery withNotAssignedToTeamWithUuidFilter(@Nullable String no
this.searchText,
this.excludeInactive,
this.onlyRoot,
this.onlyLatestVersions,
this.includeMetrics);
}

Expand All @@ -127,6 +133,7 @@ public ListProjectsQuery withParentUuidFilter(@Nullable UUID parentUuidFilter) {
this.searchText,
this.excludeInactive,
this.onlyRoot,
this.onlyLatestVersions,
this.includeMetrics);
}

Expand All @@ -142,6 +149,7 @@ public ListProjectsQuery withExcludeDescendantsOfUuid(@Nullable UUID excludeDesc
this.searchText,
this.excludeInactive,
this.onlyRoot,
this.onlyLatestVersions,
this.includeMetrics);
}

Expand All @@ -157,6 +165,7 @@ public ListProjectsQuery withSearchText(@Nullable String searchText) {
searchText,
this.excludeInactive,
this.onlyRoot,
this.onlyLatestVersions,
this.includeMetrics);
}

Expand All @@ -172,6 +181,7 @@ public ListProjectsQuery withExcludeInactive(boolean excludeInactive) {
this.searchText,
excludeInactive,
this.onlyRoot,
this.onlyLatestVersions,
this.includeMetrics);
}

Expand All @@ -187,6 +197,23 @@ public ListProjectsQuery withOnlyRoot(boolean onlyRoot) {
this.searchText,
this.excludeInactive,
onlyRoot,
this.onlyLatestVersions,
this.includeMetrics);
}

public ListProjectsQuery withOnlyLatestVersions(boolean onlyLatestVersions) {
return new ListProjectsQuery(
this.nameFilter,
this.classifierFilter,
this.tagFilter,
this.teamFilter,
this.notAssignedToTeamWithUuidFilter,
this.parentUuidFilter,
this.excludeDescendantsOfUuid,
this.searchText,
this.excludeInactive,
this.onlyRoot,
onlyLatestVersions,
this.includeMetrics);
}

Expand All @@ -202,6 +229,7 @@ public ListProjectsQuery withIncludeMetrics(boolean includeMetrics) {
this.searchText,
this.excludeInactive,
this.onlyRoot,
this.onlyLatestVersions,
includeMetrics);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ public Response getProjects(@Parameter(description = "The optional name of the p
@QueryParam("excludeInactive") boolean excludeInactive,
@Parameter(description = "Optionally excludes children projects from being returned")
@QueryParam("onlyRoot") boolean onlyRoot,
@Parameter(description = "Optionally includes only projects flagged as the latest version of their name")
@QueryParam("onlyLatestVersions") boolean onlyLatestVersions,
@Parameter(description = "The UUID of the team which projects shall be excluded", schema = @Schema(format = "uuid", type = "string"))
@QueryParam("notAssignedToTeamWithUuid") @ValidUuid String notAssignedToTeamWithUuid) {
try (QueryManager qm = new QueryManager(getAlpineRequest())) {
Expand All @@ -159,6 +161,7 @@ public Response getProjects(@Parameter(description = "The optional name of the p
.withSearchText(getAlpineRequest().getFilter())
.withExcludeInactive(excludeInactive)
.withOnlyRoot(onlyRoot)
.withOnlyLatestVersions(onlyLatestVersions)
.withIncludeMetrics(true)));
return Response
.ok(ListProjectsResponseItem.of(projectsPage.items()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,50 @@ void getProjectsOnlyRootTest() {
""");
}

@Test
void getProjectsOnlyLatestVersionsTest() {
initializeWithPermissions(Permissions.VIEW_PORTFOLIO);
final var projectV1 = new Project();
projectV1.setName("acme-app");
projectV1.setVersion("1.0.0");
projectV1.setIsLatest(false);
qm.persist(projectV1);

final var projectV2 = new Project();
projectV2.setName("acme-app");
projectV2.setVersion("2.0.0");
projectV2.setIsLatest(true);
qm.persist(projectV2);

// Should return both when onlyLatestVersions=false.
var response = jersey.target(V1_PROJECT)
.queryParam("onlyLatestVersions", "false")
.request()
.header(X_API_KEY, apiKey)
.get();
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getHeaderString(TOTAL_COUNT_HEADER)).isEqualTo("2");

// Should return only the latest version when onlyLatestVersions=true.
response = jersey.target(V1_PROJECT)
.queryParam("onlyLatestVersions", "true")
.request()
.header(X_API_KEY, apiKey)
.get();
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getHeaderString(TOTAL_COUNT_HEADER)).isEqualTo("1");
assertThatJson(getPlainTextBody(response)).isEqualTo(/* language=JSON */ """
[ {
"name" : "acme-app",
"version" : "2.0.0",
"uuid" : "${json-unit.any-string}",
"isLatest" : true,
"active" : true,
"hasChildren" : false
} ]
""");
}

@Test
void getProjectLookupTest() {
initializeWithPermissions(Permissions.VIEW_PORTFOLIO);
Expand Down
Loading