DashboardApi: Add method to set a dashboard as the default dashboard
Change-Id: If20358d2507faca7b4a57840cef53bfb04c2d34f
This commit is contained in:
parent
85cc680945
commit
9d962b9234
@ -58,6 +58,15 @@ public class DashboardIT extends AbstractDaemonTest {
|
||||
assertThat(dashboards()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDefaultDashboard() throws Exception {
|
||||
DashboardInfo info = createDashboard(DashboardsCollection.DEFAULT_DASHBOARD_NAME, "test");
|
||||
assertThat(info.isDefault).isNull();
|
||||
gApi.projects().name(project.get()).dashboard(info.id).setDefault();
|
||||
assertThat(gApi.projects().name(project.get()).dashboard(info.id).get().isDefault).isTrue();
|
||||
assertThat(gApi.projects().name(project.get()).defaultDashboard().get().id).isEqualTo(info.id);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cannotGetDashboardWithInheritedForNonDefault() throws Exception {
|
||||
DashboardInfo info = createDashboard(DashboardsCollection.DEFAULT_DASHBOARD_NAME, "test");
|
||||
|
@ -23,6 +23,8 @@ public interface DashboardApi {
|
||||
|
||||
DashboardInfo get(boolean inherited) throws RestApiException;
|
||||
|
||||
void setDefault() throws RestApiException;
|
||||
|
||||
/**
|
||||
* A default implementation which allows source compatibility when adding new methods to the
|
||||
* interface.
|
||||
@ -37,5 +39,10 @@ public interface DashboardApi {
|
||||
public DashboardInfo get(boolean inherited) throws RestApiException {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefault() throws RestApiException {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user