Search in sources :

Example 1 with WidgetDto

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));
}
Also used : Widget(com.hortonworks.streamline.registries.dashboard.entites.Widget) WidgetDto(com.hortonworks.streamline.registries.dashboard.dto.WidgetDto) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Timed(com.codahale.metrics.annotation.Timed)

Example 2 with WidgetDto

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);
}
Also used : Widget(com.hortonworks.streamline.registries.dashboard.entites.Widget) WidgetDto(com.hortonworks.streamline.registries.dashboard.dto.WidgetDto) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Example 3 with WidgetDto

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);
}
Also used : Sets(com.google.common.collect.Sets) Widget(com.hortonworks.streamline.registries.dashboard.entites.Widget) WidgetDto(com.hortonworks.streamline.registries.dashboard.dto.WidgetDto) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) PUT(javax.ws.rs.PUT)

Example 4 with WidgetDto

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());
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) Widget(com.hortonworks.streamline.registries.dashboard.entites.Widget) ArrayList(java.util.ArrayList) WidgetDto(com.hortonworks.streamline.registries.dashboard.dto.WidgetDto) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 5 with WidgetDto

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));
}
Also used : Widget(com.hortonworks.streamline.registries.dashboard.entites.Widget) WidgetDto(com.hortonworks.streamline.registries.dashboard.dto.WidgetDto) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)5 WidgetDto (com.hortonworks.streamline.registries.dashboard.dto.WidgetDto)5 Widget (com.hortonworks.streamline.registries.dashboard.entites.Widget)5 Path (javax.ws.rs.Path)5 GET (javax.ws.rs.GET)2 Sets (com.google.common.collect.Sets)1 QueryParam (com.hortonworks.registries.common.QueryParam)1 ArrayList (java.util.ArrayList)1 DELETE (javax.ws.rs.DELETE)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1