Merge changes from topic "dashboard-api"

* changes:
  DashboardIT: Factor out getting the project API to a method
  ProjectApi: Add method to remove default dashboard
  ProjectApi: Add method to set the default dashboard
This commit is contained in:
David Pursehouse
2017-10-01 16:16:54 +00:00
committed by Gerrit Code Review
4 changed files with 81 additions and 20 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

@@ -485,6 +485,24 @@ public class ProjectApiImpl implements ProjectApi {
return dashboard(DEFAULT_DASHBOARD_NAME);
}
@Override
public void defaultDashboard(String name) throws RestApiException {
try {
dashboardApi.create(checkExists(), name).setDefault();
} catch (Exception e) {
throw asRestApiException("Cannot set default dashboard", e);
}
}
@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() {