use of com.google.gerrit.extensions.api.projects.SetDashboardInput in project gerrit by GerritCodeReview.
the class DashboardApiImpl method setDefault.
@Override
public void setDefault() throws RestApiException {
SetDashboardInput input = new SetDashboardInput();
input.id = id;
try {
set.apply(DashboardResource.projectDefault(project.getProjectState(), project.getUser()), input);
} catch (Exception e) {
String msg = String.format("Cannot %s default dashboard", id != null ? "set" : "remove");
throw asRestApiException(msg, e);
}
}
use of com.google.gerrit.extensions.api.projects.SetDashboardInput in project gerrit by GerritCodeReview.
the class SetDefaultDashboard method apply.
@Override
public Response<DashboardInfo> apply(DashboardResource rsrc, SetDashboardInput input) throws RestApiException, IOException, PermissionBackendException {
if (input == null) {
// Delete would set input to null.
input = new SetDashboardInput();
}
input.id = Strings.emptyToNull(input.id);
permissionBackend.user(rsrc.getUser()).project(rsrc.getProjectState().getNameKey()).check(ProjectPermission.WRITE_CONFIG);
DashboardResource target = null;
if (input.id != null) {
try {
target = dashboards.parse(new ProjectResource(rsrc.getProjectState(), rsrc.getUser()), IdString.fromUrl(input.id));
} catch (ResourceNotFoundException e) {
throw new BadRequestException("dashboard " + input.id + " not found", e);
} catch (ConfigInvalidException e) {
throw new ResourceConflictException(e.getMessage());
}
}
try (MetaDataUpdate md = updateFactory.create(rsrc.getProjectState().getNameKey())) {
ProjectConfig config = projectConfigFactory.read(md);
String id = input.id;
if (inherited) {
config.updateProject(p -> p.setDefaultDashboard(id));
} else {
config.updateProject(p -> p.setLocalDefaultDashboard(id));
}
String msg = MoreObjects.firstNonNull(Strings.emptyToNull(input.commitMessage), input.id == null ? "Removed default dashboard.\n" : String.format("Changed default dashboard to %s.\n", input.id));
if (!msg.endsWith("\n")) {
msg += "\n";
}
md.setAuthor(rsrc.getUser().asIdentifiedUser());
md.setMessage(msg);
config.commit(md);
cache.evictAndReindex(rsrc.getProjectState().getProject());
if (target != null) {
Response<DashboardInfo> response = get.get().apply(target);
response.value().isDefault = true;
return response;
}
return Response.none();
} catch (RepositoryNotFoundException notFound) {
throw new ResourceNotFoundException(rsrc.getProjectState().getProject().getName(), notFound);
} catch (ConfigInvalidException e) {
throw new ResourceConflictException(String.format("invalid project.config: %s", e.getMessage()));
}
}
use of com.google.gerrit.extensions.api.projects.SetDashboardInput in project gerrit by GerritCodeReview.
the class DeleteDashboard method apply.
@Override
public Response<DashboardInfo> apply(DashboardResource resource, SetDashboardInput input) throws Exception {
if (resource.isProjectDefault()) {
SetDashboardInput in = new SetDashboardInput();
in.commitMessage = input != null ? input.commitMessage : null;
return defaultSetter.get().apply(resource, in);
}
// TODO: Implement delete of dashboards by API.
throw new MethodNotAllowedException("cannot delete non-default dashboard");
}
Aggregations