/** * 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); }
private ChannelType getChannelType(final ChannelTypeUID channelTypeUID) { ChannelType _channelType = null; if (this.channelTypeRegistry!=null) { _channelType=this.channelTypeRegistry.getChannelType(channelTypeUID, this.localeProvider.getLocale()); } return _channelType; }
@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); } }
private List<ChannelDefinitionDTO> convertToChannelDefinitionDTOs(List<ChannelDefinition> channelDefinitions, Locale locale) { List<ChannelDefinitionDTO> channelDefinitionDTOs = new ArrayList<>(); for (ChannelDefinition channelDefinition : channelDefinitions) { ChannelType channelType = channelTypeRegistry.getChannelType(channelDefinition.getChannelTypeUID(), locale); if (channelType == null) { logger.warn("Cannot find channel type: {}", channelDefinition.getChannelTypeUID()); return null; } // Default to the channelDefinition label to override the // channelType String label = channelDefinition.getLabel(); if (label == null) { label = channelType.getLabel(); } // Default to the channelDefinition description to override the // channelType String description = channelDefinition.getDescription(); if (description == null) { description = channelType.getDescription(); } ChannelDefinitionDTO channelDefinitionDTO = new ChannelDefinitionDTO(channelDefinition.getId(), channelDefinition.getChannelTypeUID().toString(), label, description, channelType.getTags(), channelType.getCategory(), channelType.getState(), channelType.isAdvanced(), channelDefinition.getProperties()); channelDefinitionDTOs.add(channelDefinitionDTO); } return channelDefinitionDTOs; }
private boolean isInitializable(Thing thing, ThingType thingType) { if (!isComplete(thingType, thing.getUID(), tt -> tt.getConfigDescriptionURI(), thing.getConfiguration())) { return false; } for (Channel channel : thing.getChannels()) { ChannelType channelType = channelTypeRegistry.getChannelType(channel.getChannelTypeUID()); if (!isComplete(channelType, channel.getUID(), ct -> ct.getConfigDescriptionURI(), channel.getConfiguration())) { return false; } } return true; }
private static Channel createChannel(ChannelDefinition channelDefinition, ThingUID thingUID, String groupId, ConfigDescriptionRegistry configDescriptionRegistry) { ChannelType type = withChannelTypeRegistry(channelTypeRegistry -> { return (channelTypeRegistry != null) ? channelTypeRegistry.getChannelType(channelDefinition.getChannelTypeUID()) : null; }); if (type == null) { logger.warn( "Could not create channel '{}' for thing type '{}', because channel type '{}' could not be found.", channelDefinition.getId(), thingUID, channelDefinition.getChannelTypeUID()); return null; } ChannelUID channelUID = new ChannelUID(thingUID, groupId, channelDefinition.getId()); ChannelBuilder channelBuilder = createChannelBuilder(channelUID, type, configDescriptionRegistry); // If we want to override the label, add it... final String label = channelDefinition.getLabel(); if (label != null) { channelBuilder = channelBuilder.withLabel(label); } // If we want to override the description, add it... final String description = channelDefinition.getDescription(); if (description != null) { channelBuilder = channelBuilder.withDescription(description); } channelBuilder = channelBuilder.withProperties(channelDefinition.getProperties()); return channelBuilder.build(); }