ProjectApi: Add method to remove default dashboard
Change-Id: I10d19dd72276f368dea2288dd94a3259d2f494bc
This commit is contained in:
@@ -81,6 +81,12 @@ public class DashboardIT extends AbstractDaemonTest {
|
|||||||
gApi.projects().name(project.get()).defaultDashboard(info.id);
|
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()).dashboard(info.id).get().isDefault).isTrue();
|
||||||
assertThat(gApi.projects().name(project.get()).defaultDashboard().get().id).isEqualTo(info.id);
|
assertThat(gApi.projects().name(project.get()).defaultDashboard().get().id).isEqualTo(info.id);
|
||||||
|
|
||||||
|
gApi.projects().name(project.get()).removeDefaultDashboard();
|
||||||
|
assertThat(gApi.projects().name(project.get()).dashboard(info.id).get().isDefault).isNull();
|
||||||
|
|
||||||
|
exception.expect(ResourceNotFoundException.class);
|
||||||
|
gApi.projects().name(project.get()).defaultDashboard().get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -161,6 +161,9 @@ public interface ProjectApi {
|
|||||||
*/
|
*/
|
||||||
void defaultDashboard(String name) throws RestApiException;
|
void defaultDashboard(String name) throws RestApiException;
|
||||||
|
|
||||||
|
/** Remove the project's default dashboard. */
|
||||||
|
void removeDefaultDashboard() throws RestApiException;
|
||||||
|
|
||||||
abstract class ListDashboardsRequest {
|
abstract class ListDashboardsRequest {
|
||||||
public abstract List<DashboardInfo> get() throws RestApiException;
|
public abstract List<DashboardInfo> get() throws RestApiException;
|
||||||
}
|
}
|
||||||
@@ -296,5 +299,10 @@ public interface ProjectApi {
|
|||||||
public void defaultDashboard(String name) throws RestApiException {
|
public void defaultDashboard(String name) throws RestApiException {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeDefaultDashboard() throws RestApiException {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,7 @@ package com.google.gerrit.server.api.projects;
|
|||||||
|
|
||||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
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.DashboardApi;
|
||||||
import com.google.gerrit.extensions.api.projects.DashboardInfo;
|
import com.google.gerrit.extensions.api.projects.DashboardInfo;
|
||||||
import com.google.gerrit.extensions.common.SetDashboardInput;
|
import com.google.gerrit.extensions.common.SetDashboardInput;
|
||||||
@@ -51,7 +52,7 @@ public class DashboardApiImpl implements DashboardApi {
|
|||||||
Provider<GetDashboard> get,
|
Provider<GetDashboard> get,
|
||||||
SetDashboard set,
|
SetDashboard set,
|
||||||
@Assisted ProjectResource project,
|
@Assisted ProjectResource project,
|
||||||
@Assisted String id) {
|
@Assisted @Nullable String id) {
|
||||||
this.dashboards = dashboards;
|
this.dashboards = dashboards;
|
||||||
this.get = get;
|
this.get = get;
|
||||||
this.set = set;
|
this.set = set;
|
||||||
@@ -80,7 +81,8 @@ public class DashboardApiImpl implements DashboardApi {
|
|||||||
try {
|
try {
|
||||||
set.apply(DashboardResource.projectDefault(project.getControl()), input);
|
set.apply(DashboardResource.projectDefault(project.getControl()), input);
|
||||||
} catch (Exception e) {
|
} 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -494,6 +494,15 @@ public class ProjectApiImpl implements ProjectApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeDefaultDashboard() throws RestApiException {
|
||||||
|
try {
|
||||||
|
dashboardApi.create(checkExists(), null).setDefault();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw asRestApiException("Cannot remove default dashboard", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ListDashboardsRequest dashboards() throws RestApiException {
|
public ListDashboardsRequest dashboards() throws RestApiException {
|
||||||
return new ListDashboardsRequest() {
|
return new ListDashboardsRequest() {
|
||||||
|
Reference in New Issue
Block a user