Search in sources :

Example 6 with Stream2JSONInputStream

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

the class BindingResource method getAll.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get all bindings.", response = BindingInfoDTO.class, responseContainer = "Set")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = BindingInfoDTO.class, responseContainer = "Set") })
public Response getAll(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = "language") String language) {
    final Locale locale = LocaleUtil.getLocale(language);
    Set<BindingInfo> bindingInfos = bindingInfoRegistry.getBindingInfos(locale);
    return Response.ok(new Stream2JSONInputStream(bindingInfos.stream().map(b -> map(b, locale)))).build();
}
Also used : Locale(java.util.Locale) PathParam(javax.ws.rs.PathParam) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) BindingInfoDTO(org.eclipse.smarthome.core.binding.dto.BindingInfoDTO) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) ApiParam(io.swagger.annotations.ApiParam) ApiResponses(io.swagger.annotations.ApiResponses) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) Component(org.osgi.service.component.annotations.Component) Consumes(javax.ws.rs.Consumes) Locale(java.util.Locale) Map(java.util.Map) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) HeaderParam(javax.ws.rs.HeaderParam) ConfigurationService(org.eclipse.smarthome.io.rest.core.config.ConfigurationService) URI(java.net.URI) Api(io.swagger.annotations.Api) Status(javax.ws.rs.core.Response.Status) Configuration(org.eclipse.smarthome.config.core.Configuration) RESTResource(org.eclipse.smarthome.io.rest.RESTResource) Context(javax.ws.rs.core.Context) Logger(org.slf4j.Logger) Set(java.util.Set) IOException(java.io.IOException) Stream2JSONInputStream(org.eclipse.smarthome.io.rest.Stream2JSONInputStream) ReferencePolicy(org.osgi.service.component.annotations.ReferencePolicy) ConfigDescriptionRegistry(org.eclipse.smarthome.config.core.ConfigDescriptionRegistry) Role(org.eclipse.smarthome.core.auth.Role) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) BindingInfoRegistry(org.eclipse.smarthome.core.binding.BindingInfoRegistry) HttpHeaders(javax.ws.rs.core.HttpHeaders) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) BindingInfo(org.eclipse.smarthome.core.binding.BindingInfo) PUT(javax.ws.rs.PUT) UriInfo(javax.ws.rs.core.UriInfo) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) ConfigUtil(org.eclipse.smarthome.config.core.ConfigUtil) LocaleUtil(org.eclipse.smarthome.io.rest.LocaleUtil) BindingInfo(org.eclipse.smarthome.core.binding.BindingInfo) 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 7 with Stream2JSONInputStream

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

the class ChannelTypeResource method getAll.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets all available channel types.", response = ChannelTypeDTO.class, responseContainer = "Set")
@ApiResponses(value = @ApiResponse(code = 200, message = "OK", response = ChannelTypeDTO.class, responseContainer = "Set"))
public Response getAll(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = HttpHeaders.ACCEPT_LANGUAGE) String language) {
    Locale locale = LocaleUtil.getLocale(language);
    Stream<ChannelTypeDTO> channelStream = channelTypeRegistry.getChannelTypes(locale).stream().map(c -> convertToChannelTypeDTO(c, locale));
    return Response.ok(new Stream2JSONInputStream(channelStream)).build();
}
Also used : Locale(java.util.Locale) ChannelTypeDTO(org.eclipse.smarthome.core.thing.dto.ChannelTypeDTO) 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 8 with Stream2JSONInputStream

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

the class ExtensionResource method getTypes.

@GET
@Path("/types")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get all extension types.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = String.class) })
public Response getTypes(@HeaderParam("Accept-Language") @ApiParam(value = "language") String language) {
    logger.debug("Received HTTP GET request at '{}'", uriInfo.getPath());
    Locale locale = LocaleUtil.getLocale(language);
    Stream<ExtensionType> extensionTypeStream = getAllExtensionTypes(locale).stream().distinct();
    return Response.ok(new Stream2JSONInputStream(extensionTypeStream)).build();
}
Also used : Locale(java.util.Locale) ExtensionType(org.eclipse.smarthome.core.extension.ExtensionType) 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)

Example 9 with Stream2JSONInputStream

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

the class ThingTypeResource method getAll.

@GET
@RolesAllowed({ Role.USER })
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets all available thing types without config description, channels and properties.", response = StrippedThingTypeDTO.class, responseContainer = "Set")
@ApiResponses(value = @ApiResponse(code = 200, message = "OK", response = StrippedThingTypeDTO.class, responseContainer = "Set"))
public Response getAll(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = HttpHeaders.ACCEPT_LANGUAGE) String language) {
    Locale locale = LocaleUtil.getLocale(language);
    Stream<StrippedThingTypeDTO> typeStream = thingTypeRegistry.getThingTypes(locale).stream().map(t -> convertToStrippedThingTypeDTO(t, locale));
    return Response.ok(new Stream2JSONInputStream(typeStream)).build();
}
Also used : Locale(java.util.Locale) Stream2JSONInputStream(org.eclipse.smarthome.io.rest.Stream2JSONInputStream) StrippedThingTypeDTO(org.eclipse.smarthome.core.thing.dto.StrippedThingTypeDTO) 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)

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