/** * Returns the channel type for the given UID with the default {@link Locale}. * * @return channel type or null if no channel type for the given UID exists */ @Nullable public ChannelType getChannelType(@Nullable ChannelTypeUID channelTypeUID) { return getChannelType(channelTypeUID, null); }
/** * Returns all channel types with the default {@link Locale}. * * @return all channel types or empty list if no channel type exists */ public List<ChannelType> getChannelTypes() { return getChannelTypes(null); }
private ChannelType getChannelType(final ChannelTypeUID channelTypeUID) { ChannelType _channelType = null; if (this.channelTypeRegistry!=null) { _channelType=this.channelTypeRegistry.getChannelType(channelTypeUID, this.localeProvider.getLocale()); } return _channelType; }
@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 = localeService.getLocale(language); Stream<ChannelTypeDTO> channelStream = channelTypeRegistry.getChannelTypes(locale).stream() .map(c -> convertToChannelTypeDTO(c, locale)); return Response.ok(new Stream2JSONInputStream(channelStream)).build(); }
@Override public ChannelBuilder createChannelBuilder(ChannelUID channelUID, ChannelTypeUID channelTypeUID) { ChannelType channelType = channelTypeRegistry.getChannelType(channelTypeUID); if (channelType == null) { throw new IllegalArgumentException(String.format("Channel type '%s' is not known", channelTypeUID)); } return ThingFactoryHelper.createChannelBuilder(channelUID, channelType, configDescriptionRegistry); };
/** * Returns the channel type for a given channel and locale. * * <p> * <strong>Attention:</strong> If you iterate over multiple channels to find the according channel types, please * fetch the thing type first using * {@link ThingTypeRegistry#getThingType(ThingTypeUID)} and use * {@link ThingType#getChannelType(ChannelUID)} afterwards. * * @param channel channel * @param locale locale (can be null) * @return channel type or null if no channel type was found */ public ChannelType getChannelType(Channel channel, Locale locale) { ChannelTypeUID channelTypeUID = channel.getChannelTypeUID(); if (channelTypeUID != null) { return channelTypeRegistry.getChannelType(channelTypeUID, locale); } return null; }
private boolean channelTypeDefinesDimension(@Nullable ChannelTypeUID channelTypeUID) { if (channelTypeUID == null) { return false; } ChannelType channelType = channelTypeRegistry.getChannelType(channelTypeUID); return channelType != null && getDimension(channelType.getItemType()) != null; }
@GET @Path("/{channelTypeUID}") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Gets channel type by UID.", response = ChannelTypeDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Channel type with provided channelTypeUID does not exist.", response = ChannelTypeDTO.class), @ApiResponse(code = 404, message = "No content") }) public Response getByUID(@PathParam("channelTypeUID") @ApiParam(value = "channelTypeUID") String channelTypeUID, @HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = HttpHeaders.ACCEPT_LANGUAGE) String language) { Locale locale = localeService.getLocale(language); ChannelType channelType = channelTypeRegistry.getChannelType(new ChannelTypeUID(channelTypeUID), locale); if (channelType != null) { return Response.ok(convertToChannelTypeDTO(channelType, locale)).build(); } else { return Response.noContent().build(); } }
@PathParam("channelTypeUID") @ApiParam(value = "channelTypeUID") String channelTypeUID) { ChannelTypeUID ctUID = new ChannelTypeUID(channelTypeUID); ChannelType channelType = channelTypeRegistry.getChannelType(ctUID); if (channelType == null) { return Response.status(Status.NOT_FOUND).build();
@Nullable @Override public ProfileTypeUID getSuggestedProfileTypeUID(Channel channel, @Nullable String itemType) { ChannelType channelType = channelTypeRegistry.getChannelType(channel.getChannelTypeUID()); if (channelType == null) { switch (channel.getKind()) { case STATE: return SystemProfiles.DEFAULT; case TRIGGER: return null; default: throw new IllegalArgumentException("Unsupported channel kind: " + channel.getKind()); } } else { return getSuggestedProfileTypeUID(channelType, itemType); } }
@Override public List<ChannelBuilder> createChannelBuilders(ChannelGroupUID channelGroupUID, ChannelGroupTypeUID channelGroupTypeUID) { ChannelGroupType channelGroupType = channelGroupTypeRegistry.getChannelGroupType(channelGroupTypeUID); if (channelGroupType == null) { throw new IllegalArgumentException( String.format("Channel group type '%s' is not known", channelGroupTypeUID)); } List<ChannelBuilder> channelBuilders = new ArrayList<>(); for (ChannelDefinition channelDefinition : channelGroupType.getChannelDefinitions()) { ChannelType channelType = channelTypeRegistry.getChannelType(channelDefinition.getChannelTypeUID()); if (channelType != null) { ChannelUID channelUID = new ChannelUID(channelGroupUID, channelDefinition.getId()); channelBuilders.add(ThingFactoryHelper.createChannelBuilder(channelUID, channelType, configDescriptionRegistry)); } } return channelBuilders; }
if (channelLabel == null || channelDescription == null) { ChannelTypeUID channelTypeUID = channelDefinition.getChannelTypeUID(); ChannelType channelType = channelTypeRegistry.getChannelType(channelTypeUID, locale); if (channelType != null) { ChannelType localizedChannelType = channelTypeI18nLocalizationService
ChannelType channelType = channelTypeRegistry.getChannelType(channel.getChannelTypeUID());
private String getCategory(Channel channel) { if (channel.getChannelTypeUID() != null) { ChannelType channelType = channelTypeRegistry.getChannelType(channel.getChannelTypeUID(), localeProvider.getLocale()); if (channelType != null) { return channelType.getCategory(); } } return null; }
private @Nullable URI getChannelConfigDescriptionURI(URI uri) { String stringUID = uri.getSchemeSpecificPart(); if (uri.getFragment() != null) { stringUID = stringUID + "#" + uri.getFragment(); } ChannelUID channelUID = new ChannelUID(stringUID); ThingUID thingUID = channelUID.getThingUID(); // First, get the thing so we get access to the channel type via the channel Thing thing = thingRegistry.get(thingUID); if (thing == null) { return null; } Channel channel = thing.getChannel(channelUID.getId()); if (channel == null) { return null; } ChannelType channelType = channelTypeRegistry.getChannelType(channel.getChannelTypeUID()); if (channelType == null) { return null; } // Get the config description URI for this channel type URI configURI = channelType.getConfigDescriptionURI(); return configURI; }
private Map<String, Object> normalizeConfiguration(Map<String, Object> properties, ChannelTypeUID channelTypeUID, ChannelUID channelUID) { if (properties == null || properties.isEmpty()) { return properties; } ChannelType channelType = channelTypeRegistry.getChannelType(channelTypeUID); if (channelType == null) { return properties; } List<ConfigDescription> configDescriptions = new ArrayList<>(2); if (channelType.getConfigDescriptionURI() != null) { ConfigDescription typeConfigDesc = configDescRegistry .getConfigDescription(channelType.getConfigDescriptionURI()); if (typeConfigDesc != null) { configDescriptions.add(typeConfigDesc); } } if (getConfigDescriptionURI(channelUID) != null) { ConfigDescription channelConfigDesc = configDescRegistry .getConfigDescription(getConfigDescriptionURI(channelUID)); if (channelConfigDesc != null) { configDescriptions.add(channelConfigDesc); } } if (configDescriptions.isEmpty()) { return properties; } return ConfigUtil.normalizeTypes(properties, configDescriptions); }
private Predicate<ProfileType> matchesChannelUID(String channelTypeUID, Locale locale) { if (channelTypeUID == null) { return t -> true; } ChannelType channelType = channelTypeRegistry.getChannelType(new ChannelTypeUID(channelTypeUID), locale); if (channelType == null) { // requested to filter against an unknown channel type -> do not return a ProfileType return t -> false; } switch (channelType.getKind()) { case STATE: return t -> stateProfileMatchesProfileType(t, channelType); case TRIGGER: return t -> triggerProfileMatchesProfileType(t, channelType); } return t -> false; }
private String getLabel(Channel channel) { if (channel.getLabel() != null) { return channel.getLabel(); } else { final Locale locale = localeProvider.getLocale(); if (channel.getChannelTypeUID() != null) { final ChannelType channelType = channelTypeRegistry.getChannelType(channel.getChannelTypeUID(), locale); if (channelType != null) { return channelType.getLabel(); } } } return null; }
private void createLinkIfNotAdvanced(Channel channel) { if (autoLinks) { if (channel.getChannelTypeUID() != null) { ChannelType type = channelTypeRegistry.getChannelType(channel.getChannelTypeUID()); if (type != null && type.isAdvanced()) { return; } } ItemChannelLink link = new ItemChannelLink(deriveItemName(channel.getUID()), channel.getUID()); itemChannelLinkRegistry.add(link); } }
policy = channelpolicy; } else { ChannelType channelType = channelTypeRegistry.getChannelType(channel.getChannelTypeUID()); if (channelType != null && channelType.getAutoUpdatePolicy() != null) { policy = channelType.getAutoUpdatePolicy();