use of com.hortonworks.streamline.registries.dashboard.dto.WidgetDto in project streamline by hortonworks.
the class DashboardCatalogResource method deleteWidget.
@DELETE
@Path("/{dashboardId}/widgets/{widgetId}")
@Timed
public Response deleteWidget(@PathParam("dashboardId") Long dashboardId, @PathParam("widgetId") Long widgetId) {
Widget widget = dashboardCatalogService.removeWidget(dashboardId, widgetId);
if (widget != null) {
WidgetDto dto = WidgetDto.fromWidget(widget);
Set<Long> datasourceIds = dashboardCatalogService.getWidgetDatasourceMapping(widget);
dashboardCatalogService.removeWidgetDatasourceMapping(widget, datasourceIds);
dto.setDatasourceIds(datasourceIds);
return WSUtils.respondEntity(dto, OK);
}
throw EntityNotFoundException.byId(getCompositeId(dashboardId, widgetId));
}
use of com.hortonworks.streamline.registries.dashboard.dto.WidgetDto in project streamline by hortonworks.
the class DashboardCatalogResource method addWidget.
@POST
@Path("/{dashboardId}/widgets")
@Timed
public Response addWidget(@PathParam("dashboardId") Long dashboardId, WidgetDto dto) {
Widget createdWidget = dashboardCatalogService.addWidget(dashboardId, Widget.fromDto(dto));
WidgetDto resultDto = WidgetDto.fromWidget(createdWidget);
if (dto.getDatasourceIds() != null) {
dashboardCatalogService.addWidgetDatasourceMapping(createdWidget, dto.getDatasourceIds());
resultDto.setDatasourceIds(dto.getDatasourceIds());
}
return WSUtils.respondEntity(resultDto, CREATED);
}
use of com.hortonworks.streamline.registries.dashboard.dto.WidgetDto in project streamline by hortonworks.
the class DashboardCatalogResource method addOrUpdateWidget.
@PUT
@Path("/{dashboardId}/widgets/{widgetId}")
@Timed
public Response addOrUpdateWidget(@PathParam("dashboardId") Long dashboardId, @PathParam("widgetId") Long widgetId, WidgetDto dto) {
Widget widget = Widget.fromDto(dto);
Widget updatedWidget = dashboardCatalogService.addOrUpdateWidget(dashboardId, widgetId, widget);
WidgetDto resultDto = WidgetDto.fromWidget(updatedWidget);
if (dto.getDatasourceIds() != null) {
Set<Long> existing = dashboardCatalogService.getWidgetDatasourceMapping(widget);
Set<Long> newSet = dto.getDatasourceIds();
Sets.SetView<Long> mappingsToRemove = Sets.difference(ImmutableSet.copyOf(existing), ImmutableSet.copyOf(newSet));
Sets.SetView<Long> mappingsToAdd = Sets.difference(ImmutableSet.copyOf(newSet), ImmutableSet.copyOf(existing));
dashboardCatalogService.removeWidgetDatasourceMapping(widget, mappingsToRemove);
dashboardCatalogService.addWidgetDatasourceMapping(widget, mappingsToAdd);
resultDto.setDatasourceIds(dto.getDatasourceIds());
}
return WSUtils.respondEntity(resultDto, CREATED);
}
use of com.hortonworks.streamline.registries.dashboard.dto.WidgetDto in project streamline by hortonworks.
the class DashboardCatalogResource method listWidgets.
@GET
@Path("/{dashboardId}/widgets")
@Timed
public Response listWidgets(@PathParam("dashboardId") Long dashboardId, @Context UriInfo uriInfo) {
List<QueryParam> queryParams = buildDashboardIdAwareQueryParams(dashboardId, uriInfo);
Collection<Widget> widgets = dashboardCatalogService.listWidgets(queryParams);
if (widgets != null) {
List<WidgetDto> dtos = new ArrayList<>();
widgets.forEach(widget -> {
WidgetDto dto = WidgetDto.fromWidget(widget);
dto.setDatasourceIds(dashboardCatalogService.getWidgetDatasourceMapping(widget));
dtos.add(dto);
});
return WSUtils.respondEntities(dtos, OK);
}
throw EntityNotFoundException.byFilter(queryParams.toString());
}
use of com.hortonworks.streamline.registries.dashboard.dto.WidgetDto in project streamline by hortonworks.
the class DashboardCatalogResource method getWidget.
@GET
@Path("/{dashboardId}/widgets/{widgetId}")
@Timed
public Response getWidget(@PathParam("dashboardId") Long dashboardId, @PathParam("widgetId") Long widgetId) {
Widget widget = dashboardCatalogService.getWidget(dashboardId, widgetId);
if (widget != null) {
WidgetDto dto = WidgetDto.fromWidget(widget);
dto.setDatasourceIds(dashboardCatalogService.getWidgetDatasourceMapping(widget));
return WSUtils.respondEntity(dto, OK);
}
throw EntityNotFoundException.byId(getCompositeId(dashboardId, widgetId));
}
Aggregations