Search in sources :

Example 1 with ChannelTypeDTO

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

the class ChannelTypeResource method getAll.

@GET
@Produces(MediaType.APPLICATION_JSON)
@Operation(operationId = "getChannelTypes", summary = "Gets all available channel types.", responses = { @ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ChannelTypeDTO.class), uniqueItems = true))) })
public Response getAll(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @Parameter(description = "language") @Nullable String language, @QueryParam("prefixes") @Parameter(description = "filter UIDs by prefix (multiple comma-separated prefixes allowed, for example: 'system,mqtt')") @Nullable String prefixes) {
    Locale locale = localeService.getLocale(language);
    Stream<ChannelTypeDTO> channelStream = channelTypeRegistry.getChannelTypes(locale).stream().map(c -> convertToChannelTypeDTO(c, locale));
    if (prefixes != null) {
        Predicate<ChannelTypeDTO> filter = ct -> false;
        for (String prefix : prefixes.split(",")) {
            filter = filter.or(ct -> ct.UID.startsWith(prefix + ":"));
        }
        channelStream = channelStream.filter(filter);
    }
    return Response.ok(new Stream2JSONInputStream(channelStream)).build();
}
Also used : Locale(java.util.Locale) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) 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) HeaderParam(javax.ws.rs.HeaderParam) URI(java.net.URI) ConfigDescription(org.openhab.core.config.core.ConfigDescription) SecurityRequirement(io.swagger.v3.oas.annotations.security.SecurityRequirement) 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) Predicate(java.util.function.Predicate) Set(java.util.Set) 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) Tag(io.swagger.v3.oas.annotations.tags.Tag) ProfileType(org.openhab.core.thing.profiles.ProfileType) JSONRequired(org.osgi.service.jaxrs.whiteboard.propertytypes.JSONRequired) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) RESTResource(org.openhab.core.io.rest.RESTResource) ChannelTypeDTO(org.openhab.core.thing.dto.ChannelTypeDTO) HashSet(java.util.HashSet) 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) ChannelKind(org.openhab.core.thing.type.ChannelKind) ProfileTypeRegistry(org.openhab.core.thing.profiles.ProfileTypeRegistry) 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) TriggerProfileType(org.openhab.core.thing.profiles.TriggerProfileType) Status(javax.ws.rs.core.Response.Status) Stream2JSONInputStream(org.openhab.core.io.rest.Stream2JSONInputStream) ChannelType(org.openhab.core.thing.type.ChannelType) ArraySchema(io.swagger.v3.oas.annotations.media.ArraySchema) ChannelTypeUID(org.openhab.core.thing.type.ChannelTypeUID) Reference(org.osgi.service.component.annotations.Reference) ChannelTypeDTO(org.openhab.core.thing.dto.ChannelTypeDTO) Stream2JSONInputStream(org.openhab.core.io.rest.Stream2JSONInputStream) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation)

Example 2 with ChannelTypeDTO

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

the class ChannelTypeResource method convertToChannelTypeDTO.

private ChannelTypeDTO convertToChannelTypeDTO(ChannelType channelType, Locale locale) {
    final URI descURI = channelType.getConfigDescriptionURI();
    final ConfigDescription configDescription = descURI == null ? null : configDescriptionRegistry.getConfigDescription(descURI, locale);
    final ConfigDescriptionDTO configDescriptionDTO = configDescription == null ? null : ConfigDescriptionDTOMapper.map(configDescription);
    final List<ConfigDescriptionParameterDTO> parameters = configDescriptionDTO == null ? List.of() : configDescriptionDTO.parameters;
    final List<ConfigDescriptionParameterGroupDTO> parameterGroups = configDescriptionDTO == null ? List.of() : configDescriptionDTO.parameterGroups;
    return new ChannelTypeDTO(channelType.getUID().toString(), channelType.getLabel(), channelType.getDescription(), channelType.getCategory(), channelType.getItemType(), channelType.getKind(), parameters, parameterGroups, channelType.getState(), channelType.getTags(), channelType.isAdvanced(), channelType.getCommandDescription());
}
Also used : ConfigDescriptionParameterDTO(org.openhab.core.config.core.dto.ConfigDescriptionParameterDTO) ConfigDescriptionParameterGroupDTO(org.openhab.core.config.core.dto.ConfigDescriptionParameterGroupDTO) ConfigDescriptionDTO(org.openhab.core.config.core.dto.ConfigDescriptionDTO) ChannelTypeDTO(org.openhab.core.thing.dto.ChannelTypeDTO) ConfigDescription(org.openhab.core.config.core.ConfigDescription) URI(java.net.URI)

Aggregations

URI (java.net.URI)2 ConfigDescription (org.openhab.core.config.core.ConfigDescription)2 ConfigDescriptionDTO (org.openhab.core.config.core.dto.ConfigDescriptionDTO)2 ConfigDescriptionParameterDTO (org.openhab.core.config.core.dto.ConfigDescriptionParameterDTO)2 ConfigDescriptionParameterGroupDTO (org.openhab.core.config.core.dto.ConfigDescriptionParameterGroupDTO)2 ChannelTypeDTO (org.openhab.core.thing.dto.ChannelTypeDTO)2 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 SecurityRequirement (io.swagger.v3.oas.annotations.security.SecurityRequirement)1 Tag (io.swagger.v3.oas.annotations.tags.Tag)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Locale (java.util.Locale)1 Set (java.util.Set)1 Predicate (java.util.function.Predicate)1 Stream (java.util.stream.Stream)1