ProjectApi: Add method to remove default dashboard
Change-Id: I10d19dd72276f368dea2288dd94a3259d2f494bc
This commit is contained in:
@@ -81,6 +81,12 @@ public class DashboardIT extends AbstractDaemonTest {
|
||||
gApi.projects().name(project.get()).defaultDashboard(info.id);
|
||||
assertThat(gApi.projects().name(project.get()).dashboard(info.id).get().isDefault).isTrue();
|
||||
assertThat(gApi.projects().name(project.get()).defaultDashboard().get().id).isEqualTo(info.id);
|
||||
|
||||
gApi.projects().name(project.get()).removeDefaultDashboard();
|
||||
assertThat(gApi.projects().name(project.get()).dashboard(info.id).get().isDefault).isNull();
|
||||
|
||||
exception.expect(ResourceNotFoundException.class);
|
||||
gApi.projects().name(project.get()).defaultDashboard().get();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -161,6 +161,9 @@ public interface ProjectApi {
|
||||
*/
|
||||
void defaultDashboard(String name) throws RestApiException;
|
||||
|
||||
/** Remove the project's default dashboard. */
|
||||
void removeDefaultDashboard() throws RestApiException;
|
||||
|
||||
abstract class ListDashboardsRequest {
|
||||
public abstract List<DashboardInfo> get() throws RestApiException;
|
||||
}
|
||||
@@ -296,5 +299,10 @@ public interface ProjectApi {
|
||||
public void defaultDashboard(String name) throws RestApiException {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeDefaultDashboard() 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 com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.extensions.api.projects.DashboardApi;
|
||||
import com.google.gerrit.extensions.api.projects.DashboardInfo;
|
||||
import com.google.gerrit.extensions.common.SetDashboardInput;
|
||||
@@ -51,7 +52,7 @@ public class DashboardApiImpl implements DashboardApi {
|
||||
Provider<GetDashboard> get,
|
||||
SetDashboard set,
|
||||
@Assisted ProjectResource project,
|
||||
@Assisted String id) {
|
||||
@Assisted @Nullable String id) {
|
||||
this.dashboards = dashboards;
|
||||
this.get = get;
|
||||
this.set = set;
|
||||
@@ -80,7 +81,8 @@ public class DashboardApiImpl implements DashboardApi {
|
||||
try {
|
||||
set.apply(DashboardResource.projectDefault(project.getControl()), input);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set default dashboard", e);
|
||||
String msg = String.format("Cannot %s default dashboard", id != null ? "set" : "remove");
|
||||
throw asRestApiException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -494,6 +494,15 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeDefaultDashboard() throws RestApiException {
|
||||
try {
|
||||
dashboardApi.create(checkExists(), null).setDefault();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot remove default dashboard", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListDashboardsRequest dashboards() throws RestApiException {
|
||||
return new ListDashboardsRequest() {
|
||||
|
Reference in New Issue
Block a user