DashboardApi: Add method to set a dashboard as the default dashboard
Change-Id: If20358d2507faca7b4a57840cef53bfb04c2d34f
This commit is contained in:
@@ -18,6 +18,7 @@ import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.gerrit.extensions.api.projects.DashboardApi;
|
||||
import com.google.gerrit.extensions.api.projects.DashboardInfo;
|
||||
import com.google.gerrit.extensions.common.SetDashboardInput;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
@@ -26,6 +27,7 @@ import com.google.gerrit.server.project.DashboardResource;
|
||||
import com.google.gerrit.server.project.DashboardsCollection;
|
||||
import com.google.gerrit.server.project.GetDashboard;
|
||||
import com.google.gerrit.server.project.ProjectResource;
|
||||
import com.google.gerrit.server.project.SetDashboard;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
@@ -39,6 +41,7 @@ public class DashboardApiImpl implements DashboardApi {
|
||||
|
||||
private final DashboardsCollection dashboards;
|
||||
private final Provider<GetDashboard> get;
|
||||
private final SetDashboard set;
|
||||
private final ProjectResource project;
|
||||
private final String id;
|
||||
|
||||
@@ -46,10 +49,12 @@ public class DashboardApiImpl implements DashboardApi {
|
||||
DashboardApiImpl(
|
||||
DashboardsCollection dashboards,
|
||||
Provider<GetDashboard> get,
|
||||
SetDashboard set,
|
||||
@Assisted ProjectResource project,
|
||||
@Assisted String id) {
|
||||
this.dashboards = dashboards;
|
||||
this.get = get;
|
||||
this.set = set;
|
||||
this.project = project;
|
||||
this.id = id;
|
||||
}
|
||||
@@ -68,6 +73,17 @@ public class DashboardApiImpl implements DashboardApi {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefault() throws RestApiException {
|
||||
SetDashboardInput input = new SetDashboardInput();
|
||||
input.id = id;
|
||||
try {
|
||||
set.apply(DashboardResource.projectDefault(project.getControl()), input);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set default dashboard", e);
|
||||
}
|
||||
}
|
||||
|
||||
private DashboardResource resource()
|
||||
throws ResourceNotFoundException, IOException, ConfigInvalidException,
|
||||
PermissionBackendException {
|
||||
|
@@ -27,7 +27,7 @@ import com.google.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
|
||||
@Singleton
|
||||
class SetDashboard implements RestModifyView<DashboardResource, SetDashboardInput> {
|
||||
public class SetDashboard implements RestModifyView<DashboardResource, SetDashboardInput> {
|
||||
private final Provider<SetDefaultDashboard> defaultSetter;
|
||||
|
||||
@Inject
|
||||
|
Reference in New Issue
Block a user