Search in sources :

Example 1 with StrippedThingTypeDTO

use of org.openhab.core.thing.dto.StrippedThingTypeDTO in project openhab-core by openhab.

the class ThingTypeResource method getAll.

@GET
@RolesAllowed({ Role.USER, Role.ADMIN })
@Produces(MediaType.APPLICATION_JSON)
@Operation(operationId = "getThingTypes", summary = "Gets all available thing types without config description, channels and properties.", responses = { @ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = StrippedThingTypeDTO.class), uniqueItems = true))) })
public Response getAll(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @Parameter(description = "language") @Nullable String language, @QueryParam("bindingId") @Parameter(description = "filter by binding Id") @Nullable String bindingId) {
    Locale locale = localeService.getLocale(language);
    Stream<StrippedThingTypeDTO> typeStream = thingTypeRegistry.getThingTypes(locale).stream().map(thingType -> StrippedThingTypeDTOMapper.map(thingType, locale));
    if (bindingId != null) {
        typeStream = typeStream.filter(type -> type.UID.startsWith(bindingId + ':'));
    }
    return Response.ok(new Stream2JSONInputStream(typeStream)).build();
}
Also used : Locale(java.util.Locale) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) RESTConstants(org.openhab.core.io.rest.RESTConstants) ConfigDescriptionParameterGroupDTO(org.openhab.core.config.core.dto.ConfigDescriptionParameterGroupDTO) ConfigDescriptionRegistry(org.openhab.core.config.core.ConfigDescriptionRegistry) ChannelTypeRegistry(org.openhab.core.thing.type.ChannelTypeRegistry) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) Nullable(org.eclipse.jdt.annotation.Nullable) Locale(java.util.Locale) ThingTypeDTO(org.openhab.core.thing.dto.ThingTypeDTO) HeaderParam(javax.ws.rs.HeaderParam) URI(java.net.URI) ConfigDescription(org.openhab.core.config.core.ConfigDescription) Schema(io.swagger.v3.oas.annotations.media.Schema) ConfigDescriptionDTOMapper(org.openhab.core.config.core.dto.ConfigDescriptionDTOMapper) ConfigDescriptionParameterDTO(org.openhab.core.config.core.dto.ConfigDescriptionParameterDTO) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault) ChannelGroupDefinition(org.openhab.core.thing.type.ChannelGroupDefinition) ThingTypeRegistry(org.openhab.core.thing.type.ThingTypeRegistry) Parameter(io.swagger.v3.oas.annotations.Parameter) LocaleService(org.openhab.core.io.rest.LocaleService) List(java.util.List) Stream(java.util.stream.Stream) HttpHeaders(javax.ws.rs.core.HttpHeaders) Response(javax.ws.rs.core.Response) Role(org.openhab.core.auth.Role) JaxrsApplicationSelect(org.osgi.service.jaxrs.whiteboard.propertytypes.JaxrsApplicationSelect) ChannelGroupTypeRegistry(org.openhab.core.thing.type.ChannelGroupTypeRegistry) Tag(io.swagger.v3.oas.annotations.tags.Tag) JSONRequired(org.osgi.service.jaxrs.whiteboard.propertytypes.JSONRequired) StrippedThingTypeDTOMapper(org.openhab.core.thing.dto.StrippedThingTypeDTOMapper) PathParam(javax.ws.rs.PathParam) ChannelGroupType(org.openhab.core.thing.type.ChannelGroupType) ThingType(org.openhab.core.thing.type.ThingType) GET(javax.ws.rs.GET) StrippedThingTypeDTO(org.openhab.core.thing.dto.StrippedThingTypeDTO) RESTResource(org.openhab.core.io.rest.RESTResource) ChannelDefinition(org.openhab.core.thing.type.ChannelDefinition) BridgeType(org.openhab.core.thing.type.BridgeType) ArrayList(java.util.ArrayList) ChannelGroupDefinitionDTO(org.openhab.core.thing.dto.ChannelGroupDefinitionDTO) Content(io.swagger.v3.oas.annotations.media.Content) Component(org.osgi.service.component.annotations.Component) Operation(io.swagger.v3.oas.annotations.Operation) JaxrsName(org.osgi.service.jaxrs.whiteboard.propertytypes.JaxrsName) ConfigDescriptionDTO(org.openhab.core.config.core.dto.ConfigDescriptionDTO) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) JaxrsWhiteboardConstants(org.osgi.service.jaxrs.whiteboard.JaxrsWhiteboardConstants) Activate(org.osgi.service.component.annotations.Activate) JaxrsResource(org.osgi.service.jaxrs.whiteboard.propertytypes.JaxrsResource) ThingTypeUID(org.openhab.core.thing.ThingTypeUID) ChannelDefinitionDTO(org.openhab.core.thing.dto.ChannelDefinitionDTO) Logger(org.slf4j.Logger) Stream2JSONInputStream(org.openhab.core.io.rest.Stream2JSONInputStream) ChannelType(org.openhab.core.thing.type.ChannelType) ArraySchema(io.swagger.v3.oas.annotations.media.ArraySchema) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) Stream2JSONInputStream(org.openhab.core.io.rest.Stream2JSONInputStream) StrippedThingTypeDTO(org.openhab.core.thing.dto.StrippedThingTypeDTO) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation)

Aggregations

Operation (io.swagger.v3.oas.annotations.Operation)1 Parameter (io.swagger.v3.oas.annotations.Parameter)1 ArraySchema (io.swagger.v3.oas.annotations.media.ArraySchema)1 Content (io.swagger.v3.oas.annotations.media.Content)1 Schema (io.swagger.v3.oas.annotations.media.Schema)1 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)1 Tag (io.swagger.v3.oas.annotations.tags.Tag)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Locale (java.util.Locale)1 Stream (java.util.stream.Stream)1 RolesAllowed (javax.annotation.security.RolesAllowed)1 GET (javax.ws.rs.GET)1 HeaderParam (javax.ws.rs.HeaderParam)1 Path (javax.ws.rs.Path)1 PathParam (javax.ws.rs.PathParam)1 Produces (javax.ws.rs.Produces)1 QueryParam (javax.ws.rs.QueryParam)1