/** * Creates a new channel definition builder. * * @param channelDefinition the channel definition the builder should be initialized by */ public ChannelDefinitionBuilder(final ChannelDefinition channelDefinition) { this(channelDefinition.getId(), channelDefinition.getChannelTypeUID()); this.properties = channelDefinition.getProperties(); this.label = channelDefinition.getLabel(); this.description = channelDefinition.getDescription(); this.autoUpdatePolicy = channelDefinition.getAutoUpdatePolicy(); }
/** * Build a channel definition. * * @return channel definition */ public ChannelDefinition build() { return new ChannelDefinition(id, channelTypeUID, label, description, properties, autoUpdatePolicy); }
@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; }
public ChannelGroupType createLocalizedChannelGroupType(Bundle bundle, ChannelGroupType channelGroupType, @Nullable Locale locale) { ChannelGroupTypeUID channelGroupTypeUID = channelGroupType.getUID(); String defaultLabel = channelGroupType.getLabel(); String label = thingTypeI18nUtil.getChannelGroupLabel(bundle, channelGroupTypeUID, defaultLabel, locale); String description = thingTypeI18nUtil.getChannelGroupDescription(bundle, channelGroupTypeUID, channelGroupType.getDescription(), locale); List<ChannelDefinition> localizedChannelDefinitions = channelI18nUtil.createLocalizedChannelDefinitions(bundle, channelGroupType.getChannelDefinitions(), channelDefinition -> thingTypeI18nUtil.getChannelLabel(bundle, channelGroupTypeUID, channelDefinition, channelDefinition.getLabel(), locale), channelDefinition -> thingTypeI18nUtil.getChannelDescription(bundle, channelGroupTypeUID, channelDefinition, channelDefinition.getDescription(), locale), locale); ChannelGroupTypeBuilder builder = ChannelGroupTypeBuilder .instance(channelGroupTypeUID, label == null ? defaultLabel : label) .isAdvanced(channelGroupType.isAdvanced()).withCategory(channelGroupType.getCategory()) .withChannelDefinitions(localizedChannelDefinitions); if (description != null) { builder.withDescription(description); } return builder.build(); }
private String inferChannelGroupKey(ChannelGroupTypeUID channelGroupTypeUID, ChannelDefinition channel, String lastSegment) { return "channel-group-type." + channelGroupTypeUID.getBindingId() + "." + channelGroupTypeUID.getId() + ".channel." + channel.getId() + "." + lastSegment; }
String channelDescription = channelDescriptionResolver.apply(channelDefinition); if (channelLabel == null || channelDescription == null) { ChannelTypeUID channelTypeUID = channelDefinition.getChannelTypeUID(); ChannelType channelType = channelTypeRegistry.getChannelType(channelTypeUID, locale); if (channelType != null) {
modelChannels.forEach(_function); final Consumer<ChannelDefinition> _function_1 = (ChannelDefinition it) -> { boolean _add = addedChannelIds.add(it.getId()); if (_add) { final ChannelType channelType = this.getChannelType(it.getChannelTypeUID()); if ((channelType != null)) { String _id = it.getId(); ChannelUID _channelUID = new ChannelUID(thingTypeUID, thingUID, _id); Channel _build = ChannelBuilder.create(_channelUID, channelType.getItemType()).withType(it.getChannelTypeUID()).withAutoUpdatePolicy(channelType.getAutoUpdatePolicy()).build(); channels.add(_build); } else { GenericThingProvider.logger.warn( "Could not create channel \'{}\' for thing \'{}\', because channel type \'{}\' could not be found.", it.getId(), thingUID, it.getChannelTypeUID());
thingType.getChannelDefinitions(), channelDefinition -> thingTypeI18nUtil.getChannelLabel(bundle, thingTypeUID, channelDefinition, channelDefinition.getLabel(), locale), channelDefinition -> thingTypeI18nUtil.getChannelDescription(bundle, thingTypeUID, channelDefinition, channelDefinition.getDescription(), locale), locale);
private String inferThingTypeKey(ThingTypeUID thingTypeUID, ChannelDefinition channel, String lastSegment) { return "thing-type." + thingTypeUID.getBindingId() + "." + thingTypeUID.getId() + ".channel." + channel.getId() + "." + lastSegment; }
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(); }
protected List<ChannelDefinition> toChannelDefinitions(List<ChannelXmlResult> channelTypeReferences, Map<String, ChannelType> channelTypes) throws ConversionException { List<ChannelDefinition> channelTypeDefinitions = null; if ((channelTypeReferences != null) && (channelTypeReferences.size() > 0)) { channelTypeDefinitions = new ArrayList<>(channelTypeReferences.size()); if (channelTypes != null) { for (ChannelXmlResult channelTypeReference : channelTypeReferences) { String id = channelTypeReference.getId(); String typeId = channelTypeReference.getTypeId(); String typeUID = String.format("%s:%s", this.channelGroupTypeUID.getBindingId(), typeId); ChannelType channelType = channelTypes.get(typeUID); if (channelType != null) { ChannelDefinition channelDefinition = new ChannelDefinition(id, channelType.getUID()); channelTypeDefinitions.add(channelDefinition); } else { throw new ConversionException("The channel type for '" + typeUID + "' is missing!"); } } } else { throw new ConversionException("Missing the definition of channel types!"); } } return channelTypeDefinitions; }
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; }
protected List<ChannelDefinition> toChannelDefinitions(List<ChannelXmlResult> channelTypeReferences) throws ConversionException { List<ChannelDefinition> channelTypeDefinitions = null; if ((channelTypeReferences != null) && (channelTypeReferences.size() > 0)) { channelTypeDefinitions = new ArrayList<>(channelTypeReferences.size()); for (ChannelXmlResult channelTypeReference : channelTypeReferences) { String id = channelTypeReference.getId(); String typeId = channelTypeReference.getTypeId(); String typeUID = String.format("%s:%s", this.thingTypeUID.getBindingId(), typeId); int systemPrefixIdx = typeId.indexOf(XmlHelper.SYSTEM_NAMESPACE_PREFIX); if (systemPrefixIdx != -1) { typeUID = XmlHelper.getSystemUID(typeId); } // Convert the channel properties into a map Map<String, String> propertiesMap = new HashMap<>(); for (NodeValue property : channelTypeReference.getProperties()) { propertiesMap.put(property.getAttributes().get("name"), (String) property.getValue()); } ChannelDefinition channelDefinition = new ChannelDefinition(id, new ChannelTypeUID(typeUID), propertiesMap, channelTypeReference.getLabel(), channelTypeReference.getDescription()); channelTypeDefinitions.add(channelDefinition); } } return channelTypeDefinitions; }