ProjectApi: Add method to set the default dashboard
Change-Id: I8e4b36b456b3c34b8fcd4347d1fe546095c875c2
This commit is contained in:
@@ -74,6 +74,15 @@ public class DashboardIT extends AbstractDaemonTest {
|
||||
assertThat(gApi.projects().name(project.get()).defaultDashboard().get().id).isEqualTo(info.id);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDefaultDashboardByProject() throws Exception {
|
||||
DashboardInfo info = createDashboard(DashboardsCollection.DEFAULT_DASHBOARD_NAME, "test");
|
||||
assertThat(info.isDefault).isNull();
|
||||
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);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void replaceDefaultDashboard() throws Exception {
|
||||
DashboardInfo d1 = createDashboard(DashboardsCollection.DEFAULT_DASHBOARD_NAME, "test1");
|
||||
|
@@ -154,6 +154,13 @@ public interface ProjectApi {
|
||||
*/
|
||||
DashboardApi defaultDashboard() throws RestApiException;
|
||||
|
||||
/**
|
||||
* Set the project's default dashboard.
|
||||
*
|
||||
* @param name the dashboard to set as default.
|
||||
*/
|
||||
void defaultDashboard(String name) throws RestApiException;
|
||||
|
||||
abstract class ListDashboardsRequest {
|
||||
public abstract List<DashboardInfo> get() throws RestApiException;
|
||||
}
|
||||
@@ -284,5 +291,10 @@ public interface ProjectApi {
|
||||
public ListDashboardsRequest dashboards() throws RestApiException {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultDashboard(String name) throws RestApiException {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -485,6 +485,15 @@ 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 ListDashboardsRequest dashboards() throws RestApiException {
|
||||
return new ListDashboardsRequest() {
|
||||
|
Reference in New Issue
Block a user