DashboardApi: Add method to set a dashboard as the default dashboard
Change-Id: If20358d2507faca7b4a57840cef53bfb04c2d34f
This commit is contained in:
@@ -58,6 +58,15 @@ public class DashboardIT extends AbstractDaemonTest {
|
|||||||
assertThat(dashboards()).hasSize(1);
|
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
|
@Test
|
||||||
public void cannotGetDashboardWithInheritedForNonDefault() throws Exception {
|
public void cannotGetDashboardWithInheritedForNonDefault() throws Exception {
|
||||||
DashboardInfo info = createDashboard(DashboardsCollection.DEFAULT_DASHBOARD_NAME, "test");
|
DashboardInfo info = createDashboard(DashboardsCollection.DEFAULT_DASHBOARD_NAME, "test");
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ public interface DashboardApi {
|
|||||||
|
|
||||||
DashboardInfo get(boolean inherited) throws RestApiException;
|
DashboardInfo get(boolean inherited) throws RestApiException;
|
||||||
|
|
||||||
|
void setDefault() throws RestApiException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A default implementation which allows source compatibility when adding new methods to the
|
* A default implementation which allows source compatibility when adding new methods to the
|
||||||
* interface.
|
* interface.
|
||||||
@@ -37,5 +39,10 @@ public interface DashboardApi {
|
|||||||
public DashboardInfo get(boolean inherited) throws RestApiException {
|
public DashboardInfo get(boolean inherited) throws RestApiException {
|
||||||
throw new NotImplementedException();
|
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.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.restapi.IdString;
|
import com.google.gerrit.extensions.restapi.IdString;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
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.DashboardsCollection;
|
||||||
import com.google.gerrit.server.project.GetDashboard;
|
import com.google.gerrit.server.project.GetDashboard;
|
||||||
import com.google.gerrit.server.project.ProjectResource;
|
import com.google.gerrit.server.project.ProjectResource;
|
||||||
|
import com.google.gerrit.server.project.SetDashboard;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
import com.google.inject.assistedinject.Assisted;
|
import com.google.inject.assistedinject.Assisted;
|
||||||
@@ -39,6 +41,7 @@ public class DashboardApiImpl implements DashboardApi {
|
|||||||
|
|
||||||
private final DashboardsCollection dashboards;
|
private final DashboardsCollection dashboards;
|
||||||
private final Provider<GetDashboard> get;
|
private final Provider<GetDashboard> get;
|
||||||
|
private final SetDashboard set;
|
||||||
private final ProjectResource project;
|
private final ProjectResource project;
|
||||||
private final String id;
|
private final String id;
|
||||||
|
|
||||||
@@ -46,10 +49,12 @@ public class DashboardApiImpl implements DashboardApi {
|
|||||||
DashboardApiImpl(
|
DashboardApiImpl(
|
||||||
DashboardsCollection dashboards,
|
DashboardsCollection dashboards,
|
||||||
Provider<GetDashboard> get,
|
Provider<GetDashboard> get,
|
||||||
|
SetDashboard set,
|
||||||
@Assisted ProjectResource project,
|
@Assisted ProjectResource project,
|
||||||
@Assisted String id) {
|
@Assisted String id) {
|
||||||
this.dashboards = dashboards;
|
this.dashboards = dashboards;
|
||||||
this.get = get;
|
this.get = get;
|
||||||
|
this.set = set;
|
||||||
this.project = project;
|
this.project = project;
|
||||||
this.id = id;
|
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()
|
private DashboardResource resource()
|
||||||
throws ResourceNotFoundException, IOException, ConfigInvalidException,
|
throws ResourceNotFoundException, IOException, ConfigInvalidException,
|
||||||
PermissionBackendException {
|
PermissionBackendException {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import com.google.inject.Singleton;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class SetDashboard implements RestModifyView<DashboardResource, SetDashboardInput> {
|
public class SetDashboard implements RestModifyView<DashboardResource, SetDashboardInput> {
|
||||||
private final Provider<SetDefaultDashboard> defaultSetter;
|
private final Provider<SetDefaultDashboard> defaultSetter;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
|||||||
Reference in New Issue
Block a user