Search in sources :

Example 1 with ChannelTypeDTO

use of org.eclipse.smarthome.core.thing.dto.ChannelTypeDTO in project smarthome by eclipse.

the class ChannelTypeResource method convertToChannelTypeDTO.

private ChannelTypeDTO convertToChannelTypeDTO(ChannelType channelType, Locale locale) {
    final ConfigDescription configDescription;
    if (channelType.getConfigDescriptionURI() != null) {
        configDescription = this.configDescriptionRegistry.getConfigDescription(channelType.getConfigDescriptionURI(), locale);
    } else {
        configDescription = null;
    }
    List<ConfigDescriptionParameterDTO> parameters;
    List<ConfigDescriptionParameterGroupDTO> parameterGroups;
    if (configDescription != null) {
        ConfigDescriptionDTO configDescriptionDTO = ConfigDescriptionDTOMapper.map(configDescription);
        parameters = configDescriptionDTO.parameters;
        parameterGroups = configDescriptionDTO.parameterGroups;
    } else {
        parameters = new ArrayList<>(0);
        parameterGroups = new ArrayList<>(0);
    }
    return new ChannelTypeDTO(channelType.getUID().toString(), channelType.getLabel(), channelType.getDescription(), channelType.getCategory(), channelType.getItemType(), channelType.getKind(), parameters, parameterGroups, channelType.getState(), channelType.getTags(), channelType.isAdvanced());
}
Also used : ConfigDescriptionParameterDTO(org.eclipse.smarthome.config.core.dto.ConfigDescriptionParameterDTO) ConfigDescriptionParameterGroupDTO(org.eclipse.smarthome.config.core.dto.ConfigDescriptionParameterGroupDTO) ConfigDescriptionDTO(org.eclipse.smarthome.config.core.dto.ConfigDescriptionDTO) ChannelTypeDTO(org.eclipse.smarthome.core.thing.dto.ChannelTypeDTO) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription)

Example 2 with ChannelTypeDTO

use of org.eclipse.smarthome.core.thing.dto.ChannelTypeDTO 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)

Aggregations

ChannelTypeDTO (org.eclipse.smarthome.core.thing.dto.ChannelTypeDTO)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Locale (java.util.Locale)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 ConfigDescription (org.eclipse.smarthome.config.core.ConfigDescription)1 ConfigDescriptionDTO (org.eclipse.smarthome.config.core.dto.ConfigDescriptionDTO)1 ConfigDescriptionParameterDTO (org.eclipse.smarthome.config.core.dto.ConfigDescriptionParameterDTO)1 ConfigDescriptionParameterGroupDTO (org.eclipse.smarthome.config.core.dto.ConfigDescriptionParameterGroupDTO)1 Stream2JSONInputStream (org.eclipse.smarthome.io.rest.Stream2JSONInputStream)1