ProjectApi: Add method to set the default dashboard

Change-Id: I8e4b36b456b3c34b8fcd4347d1fe546095c875c2
This commit is contained in:
David Pursehouse
2017-10-01 15:20:03 +01:00
parent eb09dcec56
commit 41d2a5adcf
3 changed files with 30 additions and 0 deletions

View File

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

View File

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

View File

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