Search in sources :

Example 1 with Stream2JSONInputStream

use of org.eclipse.smarthome.io.rest.Stream2JSONInputStream in project smarthome by eclipse.

the class ConfigDescriptionResource method getAll.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets all available config descriptions.", response = ConfigDescriptionDTO.class, responseContainer = "List")
@ApiResponses(value = @ApiResponse(code = 200, message = "OK", response = ConfigDescriptionDTO.class, responseContainer = "List"))
public Response getAll(@HeaderParam("Accept-Language") @ApiParam(value = "Accept-Language") String language) {
    Locale locale = LocaleUtil.getLocale(language);
    Collection<ConfigDescription> configDescriptions = configDescriptionRegistry.getConfigDescriptions(locale);
    return Response.ok(new Stream2JSONInputStream(configDescriptions.stream().map(ConfigDescriptionDTOMapper::map))).build();
}
Also used : Locale(java.util.Locale) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) Stream2JSONInputStream(org.eclipse.smarthome.io.rest.Stream2JSONInputStream) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with Stream2JSONInputStream

use of org.eclipse.smarthome.io.rest.Stream2JSONInputStream in project smarthome by eclipse.

the class ExtensionResource method getExtensions.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get all extensions.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = String.class) })
public Response getExtensions(@HeaderParam("Accept-Language") @ApiParam(value = "language") String language) {
    logger.debug("Received HTTP GET request at '{}'", uriInfo.getPath());
    Locale locale = LocaleUtil.getLocale(language);
    return Response.ok(new Stream2JSONInputStream(getAllExtensions(locale))).build();
}
Also used : Locale(java.util.Locale) Stream2JSONInputStream(org.eclipse.smarthome.io.rest.Stream2JSONInputStream) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with Stream2JSONInputStream

use of org.eclipse.smarthome.io.rest.Stream2JSONInputStream in project smarthome by eclipse.

the class ItemResource method getItems.

@GET
@RolesAllowed({ Role.USER, Role.ADMIN })
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get all available items.", response = EnrichedItemDTO.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = EnrichedItemDTO.class, responseContainer = "List") })
public Response getItems(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = "language") @Nullable String language, @QueryParam("type") @ApiParam(value = "item type filter", required = false) @Nullable String type, @QueryParam("tags") @ApiParam(value = "item tag filter", required = false) @Nullable String tags, @DefaultValue("false") @QueryParam("recursive") @ApiParam(value = "get member items recursivly", required = false) boolean recursive, @QueryParam("fields") @ApiParam(value = "limit output to the given fields (comma separated)", required = false) @Nullable String fields) {
    final Locale locale = LocaleUtil.getLocale(language);
    logger.debug("Received HTTP GET request at '{}'", uriInfo.getPath());
    Stream<EnrichedItemDTO> itemStream = getItems(type, tags).stream().map(item -> EnrichedItemDTOMapper.map(item, recursive, null, uriInfo.getBaseUri(), locale));
    itemStream = dtoMapper.limitToFields(itemStream, fields);
    return Response.ok(new Stream2JSONInputStream(itemStream)).build();
}
Also used : Locale(java.util.Locale) EnrichedItemDTO(org.eclipse.smarthome.io.rest.core.item.EnrichedItemDTO) Stream2JSONInputStream(org.eclipse.smarthome.io.rest.Stream2JSONInputStream) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with Stream2JSONInputStream

use of org.eclipse.smarthome.io.rest.Stream2JSONInputStream in project smarthome by eclipse.

the class ThingResource method getAll.

@GET
@RolesAllowed({ Role.USER, Role.ADMIN })
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get all available things.", response = EnrichedThingDTO.class, responseContainer = "Set")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = EnrichedThingDTO.class, responseContainer = "Set") })
public Response getAll(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = "language") String language) {
    final Locale locale = LocaleUtil.getLocale(language);
    Stream<EnrichedThingDTO> thingStream = thingRegistry.stream().map(t -> convertToEnrichedThingDTO(t, locale)).distinct();
    return Response.ok(new Stream2JSONInputStream(thingStream)).build();
}
Also used : Locale(java.util.Locale) Channel(org.eclipse.smarthome.core.thing.Channel) ItemFactory(org.eclipse.smarthome.core.items.ItemFactory) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) URISyntaxException(java.net.URISyntaxException) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) ApiParam(io.swagger.annotations.ApiParam) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) Consumes(javax.ws.rs.Consumes) Locale(java.util.Locale) ConfigStatusService(org.eclipse.smarthome.config.core.status.ConfigStatusService) Map(java.util.Map) Thing(org.eclipse.smarthome.core.thing.Thing) DefaultValue(javax.ws.rs.DefaultValue) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) ManagedItemProvider(org.eclipse.smarthome.core.items.ManagedItemProvider) HeaderParam(javax.ws.rs.HeaderParam) BadRequestException(javax.ws.rs.BadRequestException) URI(java.net.URI) Configuration(org.eclipse.smarthome.config.core.Configuration) DELETE(javax.ws.rs.DELETE) RESTResource(org.eclipse.smarthome.io.rest.RESTResource) Context(javax.ws.rs.core.Context) ConfigStatusInfo(org.eclipse.smarthome.config.core.status.ConfigStatusInfo) EnrichedThingDTO(org.eclipse.smarthome.io.rest.core.thing.EnrichedThingDTO) Collection(java.util.Collection) Set(java.util.Set) ReferencePolicy(org.osgi.service.component.annotations.ReferencePolicy) ConfigDescriptionRegistry(org.eclipse.smarthome.config.core.ConfigDescriptionRegistry) ThingTypeRegistry(org.eclipse.smarthome.core.thing.type.ThingTypeRegistry) Role(org.eclipse.smarthome.core.auth.Role) ManagedItemChannelLinkProvider(org.eclipse.smarthome.core.thing.link.ManagedItemChannelLinkProvider) List(java.util.List) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) Stream(java.util.stream.Stream) HttpHeaders(javax.ws.rs.core.HttpHeaders) Response(javax.ws.rs.core.Response) ManagedThingProvider(org.eclipse.smarthome.core.thing.ManagedThingProvider) FirmwareStatusDTO(org.eclipse.smarthome.core.thing.firmware.dto.FirmwareStatusDTO) Entry(java.util.Map.Entry) JSONResponse(org.eclipse.smarthome.io.rest.JSONResponse) EnrichedThingDTOMapper(org.eclipse.smarthome.io.rest.core.thing.EnrichedThingDTOMapper) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) UriInfo(javax.ws.rs.core.UriInfo) ThingDTOMapper(org.eclipse.smarthome.core.thing.dto.ThingDTOMapper) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) ThingHelper(org.eclipse.smarthome.core.thing.util.ThingHelper) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) LocaleUtil(org.eclipse.smarthome.io.rest.LocaleUtil) ChannelDTOMapper(org.eclipse.smarthome.core.thing.dto.ChannelDTOMapper) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) HashMap(java.util.HashMap) ApiResponses(io.swagger.annotations.ApiResponses) ArrayList(java.util.ArrayList) Component(org.osgi.service.component.annotations.Component) FirmwareStatusInfo(org.eclipse.smarthome.core.thing.firmware.FirmwareStatusInfo) FirmwareUID(org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUID) ChannelDTO(org.eclipse.smarthome.core.thing.dto.ChannelDTO) FirmwareUpdateService(org.eclipse.smarthome.core.thing.firmware.FirmwareUpdateService) Api(io.swagger.annotations.Api) Status(javax.ws.rs.core.Response.Status) ThingDTO(org.eclipse.smarthome.core.thing.dto.ThingDTO) POST(javax.ws.rs.POST) ConfigValidationException(org.eclipse.smarthome.config.core.validation.ConfigValidationException) ThingStatusInfoI18nLocalizationService(org.eclipse.smarthome.core.thing.i18n.ThingStatusInfoI18nLocalizationService) Logger(org.slf4j.Logger) IOException(java.io.IOException) ThingStatusInfo(org.eclipse.smarthome.core.thing.ThingStatusInfo) Stream2JSONInputStream(org.eclipse.smarthome.io.rest.Stream2JSONInputStream) ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink) ItemRegistry(org.eclipse.smarthome.core.items.ItemRegistry) ThingRegistry(org.eclipse.smarthome.core.thing.ThingRegistry) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) ChannelTypeRegistry(org.eclipse.smarthome.core.thing.type.ChannelTypeRegistry) ApiResponse(io.swagger.annotations.ApiResponse) ItemChannelLinkRegistry(org.eclipse.smarthome.core.thing.link.ItemChannelLinkRegistry) PUT(javax.ws.rs.PUT) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) ConfigUtil(org.eclipse.smarthome.config.core.ConfigUtil) EnrichedThingDTO(org.eclipse.smarthome.io.rest.core.thing.EnrichedThingDTO) Stream2JSONInputStream(org.eclipse.smarthome.io.rest.Stream2JSONInputStream) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 5 with Stream2JSONInputStream

use of org.eclipse.smarthome.io.rest.Stream2JSONInputStream in project smarthome by eclipse.

the class ThingTypeResource method getFirmwares.

@GET
@Path("/{thingTypeUID}/firmwares")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get all available firmwares for provided thingType", response = StrippedThingTypeDTO.class, responseContainer = "Set")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 204, message = "No firmwares found.") })
public Response getFirmwares(@PathParam("thingTypeUID") @ApiParam(value = "thingTypeUID") String thingTypeUID, @HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = HttpHeaders.ACCEPT_LANGUAGE) String language) {
    ThingTypeUID athingTypeUID = new ThingTypeUID(thingTypeUID);
    Collection<Firmware> firmwares = firmwareRegistry.getFirmwares(athingTypeUID, LocaleUtil.getLocale(language));
    if (firmwares.isEmpty()) {
        return Response.status(Status.NO_CONTENT).build();
    }
    Stream<FirmwareDTO> firmwareStream = firmwares.stream().map(this::convertToFirmwareDTO);
    return Response.ok(null, MediaType.TEXT_PLAIN).entity(new Stream2JSONInputStream(firmwareStream)).build();
}
Also used : FirmwareDTO(org.eclipse.smarthome.core.thing.firmware.dto.FirmwareDTO) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) Firmware(org.eclipse.smarthome.core.thing.binding.firmware.Firmware) Stream2JSONInputStream(org.eclipse.smarthome.io.rest.Stream2JSONInputStream) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)9 ApiResponses (io.swagger.annotations.ApiResponses)9 GET (javax.ws.rs.GET)9 Produces (javax.ws.rs.Produces)9 Stream2JSONInputStream (org.eclipse.smarthome.io.rest.Stream2JSONInputStream)9 Locale (java.util.Locale)8 RolesAllowed (javax.annotation.security.RolesAllowed)4 Path (javax.ws.rs.Path)4 ConfigDescription (org.eclipse.smarthome.config.core.ConfigDescription)3 Api (io.swagger.annotations.Api)2 ApiParam (io.swagger.annotations.ApiParam)2 ApiResponse (io.swagger.annotations.ApiResponse)2 IOException (java.io.IOException)2 URI (java.net.URI)2 Collections (java.util.Collections)2 Map (java.util.Map)2 Set (java.util.Set)2 Consumes (javax.ws.rs.Consumes)2 HeaderParam (javax.ws.rs.HeaderParam)2 PUT (javax.ws.rs.PUT)2