ProjectApi: Add method to list project dashboards
In the initial implementation, support for the "inherit" flag is not included. Change-Id: I0c615236f395db36e8a35318b221c3127a2bd78d
This commit is contained in:
@@ -25,6 +25,7 @@ import com.google.gerrit.extensions.api.projects.DashboardInfo;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.server.project.DashboardsCollection;
|
||||
import java.util.List;
|
||||
import org.eclipse.jgit.junit.TestRepository;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
@@ -46,6 +47,7 @@ public class DashboardIT extends AbstractDaemonTest {
|
||||
|
||||
@Test
|
||||
public void getDashboard() throws Exception {
|
||||
assertThat(dashboards()).isEmpty();
|
||||
DashboardInfo info = createDashboard(DashboardsCollection.DEFAULT_DASHBOARD_NAME, "test");
|
||||
DashboardInfo result = gApi.projects().name(project.get()).dashboard(info.id).get();
|
||||
assertThat(result.id).isEqualTo(info.id);
|
||||
@@ -53,6 +55,7 @@ public class DashboardIT extends AbstractDaemonTest {
|
||||
assertThat(result.ref).isEqualTo(info.ref);
|
||||
assertThat(result.project).isEqualTo(project.get());
|
||||
assertThat(result.definingProject).isEqualTo(project.get());
|
||||
assertThat(dashboards()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -63,6 +66,10 @@ public class DashboardIT extends AbstractDaemonTest {
|
||||
gApi.projects().name(project.get()).dashboard(info.id).get(true);
|
||||
}
|
||||
|
||||
private List<DashboardInfo> dashboards() throws Exception {
|
||||
return gApi.projects().name(project.get()).dashboards().get();
|
||||
}
|
||||
|
||||
private DashboardInfo createDashboard(String ref, String path) throws Exception {
|
||||
DashboardInfo info = DashboardsCollection.newDashboardInfo(ref, path);
|
||||
String canonicalRef = DashboardsCollection.normalizeDashboardRef(info.ref);
|
||||
|
@@ -154,6 +154,12 @@ public interface ProjectApi {
|
||||
*/
|
||||
DashboardApi defaultDashboard() throws RestApiException;
|
||||
|
||||
abstract class ListDashboardsRequest {
|
||||
public abstract List<DashboardInfo> get() throws RestApiException;
|
||||
}
|
||||
|
||||
ListDashboardsRequest dashboards() throws RestApiException;
|
||||
|
||||
/**
|
||||
* A default implementation which allows source compatibility when adding new methods to the
|
||||
* interface.
|
||||
@@ -273,5 +279,10 @@ public interface ProjectApi {
|
||||
public DashboardApi defaultDashboard() throws RestApiException {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListDashboardsRequest dashboards() throws RestApiException {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@ package com.google.gerrit.server.api.projects;
|
||||
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
import static com.google.gerrit.server.project.DashboardsCollection.DEFAULT_DASHBOARD_NAME;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.gerrit.extensions.api.access.ProjectAccessInfo;
|
||||
import com.google.gerrit.extensions.api.access.ProjectAccessInput;
|
||||
@@ -28,6 +29,7 @@ import com.google.gerrit.extensions.api.projects.CommitApi;
|
||||
import com.google.gerrit.extensions.api.projects.ConfigInfo;
|
||||
import com.google.gerrit.extensions.api.projects.ConfigInput;
|
||||
import com.google.gerrit.extensions.api.projects.DashboardApi;
|
||||
import com.google.gerrit.extensions.api.projects.DashboardInfo;
|
||||
import com.google.gerrit.extensions.api.projects.DeleteBranchesInput;
|
||||
import com.google.gerrit.extensions.api.projects.DeleteTagsInput;
|
||||
import com.google.gerrit.extensions.api.projects.DescriptionInput;
|
||||
@@ -39,6 +41,7 @@ import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.ProjectInfo;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.NotImplementedException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
@@ -58,6 +61,7 @@ import com.google.gerrit.server.project.GetConfig;
|
||||
import com.google.gerrit.server.project.GetDescription;
|
||||
import com.google.gerrit.server.project.ListBranches;
|
||||
import com.google.gerrit.server.project.ListChildProjects;
|
||||
import com.google.gerrit.server.project.ListDashboards;
|
||||
import com.google.gerrit.server.project.ListTags;
|
||||
import com.google.gerrit.server.project.ProjectJson;
|
||||
import com.google.gerrit.server.project.ProjectResource;
|
||||
@@ -68,6 +72,7 @@ import com.google.gerrit.server.project.SetAccess;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.google.inject.assistedinject.AssistedInject;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ProjectApiImpl implements ProjectApi {
|
||||
@@ -104,6 +109,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
private final CommitApiImpl.Factory commitApi;
|
||||
private final DashboardApiImpl.Factory dashboardApi;
|
||||
private final CheckAccess checkAccess;
|
||||
private final Provider<ListDashboards> listDashboards;
|
||||
|
||||
@AssistedInject
|
||||
ProjectApiImpl(
|
||||
@@ -132,6 +138,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
CommitApiImpl.Factory commitApi,
|
||||
DashboardApiImpl.Factory dashboardApi,
|
||||
CheckAccess checkAccess,
|
||||
Provider<ListDashboards> listDashboards,
|
||||
@Assisted ProjectResource project) {
|
||||
this(
|
||||
user,
|
||||
@@ -160,6 +167,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
commitApi,
|
||||
dashboardApi,
|
||||
checkAccess,
|
||||
listDashboards,
|
||||
null);
|
||||
}
|
||||
|
||||
@@ -190,6 +198,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
CommitApiImpl.Factory commitApi,
|
||||
DashboardApiImpl.Factory dashboardApi,
|
||||
CheckAccess checkAccess,
|
||||
Provider<ListDashboards> listDashboards,
|
||||
@Assisted String name) {
|
||||
this(
|
||||
user,
|
||||
@@ -218,6 +227,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
commitApi,
|
||||
dashboardApi,
|
||||
checkAccess,
|
||||
listDashboards,
|
||||
name);
|
||||
}
|
||||
|
||||
@@ -248,6 +258,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
CommitApiImpl.Factory commitApi,
|
||||
DashboardApiImpl.Factory dashboardApi,
|
||||
CheckAccess checkAccess,
|
||||
Provider<ListDashboards> listDashboards,
|
||||
String name) {
|
||||
this.user = user;
|
||||
this.permissionBackend = permissionBackend;
|
||||
@@ -275,6 +286,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
this.createAccessChange = createAccessChange;
|
||||
this.dashboardApi = dashboardApi;
|
||||
this.checkAccess = checkAccess;
|
||||
this.listDashboards = listDashboards;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@@ -473,6 +485,27 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
return dashboard(DEFAULT_DASHBOARD_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListDashboardsRequest dashboards() throws RestApiException {
|
||||
return new ListDashboardsRequest() {
|
||||
@Override
|
||||
public List<DashboardInfo> get() throws RestApiException {
|
||||
try {
|
||||
List<?> r = listDashboards.get().apply(checkExists());
|
||||
if (r.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if (r.get(0) instanceof DashboardInfo) {
|
||||
return r.stream().map(i -> (DashboardInfo) i).collect(toList());
|
||||
}
|
||||
throw new NotImplementedException("list with inheritance");
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list dashboards", e);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private ProjectResource checkExists() throws ResourceNotFoundException {
|
||||
if (project == null) {
|
||||
throw new ResourceNotFoundException(name);
|
||||
|
@@ -46,7 +46,7 @@ import org.kohsuke.args4j.Option;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
class ListDashboards implements RestReadView<ProjectResource> {
|
||||
public class ListDashboards implements RestReadView<ProjectResource> {
|
||||
private static final Logger log = LoggerFactory.getLogger(ListDashboards.class);
|
||||
|
||||
private final GitRepositoryManager gitManager;
|
||||
|
Reference in New Issue
Block a user