ProjectApi: Add method to remove default dashboard

Change-Id: I10d19dd72276f368dea2288dd94a3259d2f494bc
This commit is contained in:
David Pursehouse
2017-10-01 15:36:26 +01:00
parent 41d2a5adcf
commit 83e4639801
4 changed files with 27 additions and 2 deletions

View File

@@ -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);
}
}

View File

@@ -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() {