private ChannelGroupType createLocalizedChannelGroupType(Bundle bundle, ChannelGroupType channelGroupType, Locale locale) { LocalizedChannelTypeKey localizedChannelTypeKey = getLocalizedChannelTypeKey(channelGroupType.getUID(), locale); ChannelGroupType cachedEntry = localizedChannelGroupTypeCache.get(localizedChannelTypeKey); if (cachedEntry != null) { return cachedEntry; } if (this.thingTypeI18nUtil != null) { ChannelGroupTypeUID channelGroupTypeUID = channelGroupType.getUID(); String label = this.thingTypeI18nUtil.getChannelGroupLabel(bundle, channelGroupTypeUID, channelGroupType.getLabel(), locale); String description = this.thingTypeI18nUtil.getChannelGroupDescription(bundle, channelGroupTypeUID, channelGroupType.getDescription(), locale); ChannelGroupType localizedChannelType = new ChannelGroupType(channelGroupTypeUID, channelGroupType.isAdvanced(), label, description, channelGroupType.getChannelDefinitions()); localizedChannelGroupTypeCache.put(localizedChannelTypeKey, localizedChannelType); return localizedChannelType; } return channelGroupType; }
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 List<ChannelGroupDefinitionDTO> convertToChannelGroupDefinitionDTOs( List<ChannelGroupDefinition> channelGroupDefinitions, Locale locale) { List<ChannelGroupDefinitionDTO> channelGroupDefinitionDTOs = new ArrayList<>(); for (ChannelGroupDefinition channelGroupDefinition : channelGroupDefinitions) { String id = channelGroupDefinition.getId(); ChannelGroupType channelGroupType = channelGroupTypeRegistry .getChannelGroupType(channelGroupDefinition.getTypeUID(), locale); // Default to the channelGroupDefinition label to override the // channelGroupType String label = channelGroupDefinition.getLabel(); if (label == null) { label = channelGroupType.getLabel(); } // Default to the channelGroupDefinition description to override the // channelGroupType String description = channelGroupDefinition.getDescription(); if (description == null) { description = channelGroupType.getDescription(); } List<ChannelDefinition> channelDefinitions = channelGroupType.getChannelDefinitions(); List<ChannelDefinitionDTO> channelDefinitionDTOs = convertToChannelDefinitionDTOs(channelDefinitions, locale); channelGroupDefinitionDTOs .add(new ChannelGroupDefinitionDTO(id, label, description, channelDefinitionDTOs)); } return channelGroupDefinitionDTOs; }
private List<ChannelGroupDefinition> createLocalizedChannelGroupDefinitions(final Bundle bundle, final List<ChannelGroupDefinition> channelGroupDefinitions, final Function<ChannelGroupDefinition, @Nullable String> channelGroupLabelResolver, final Function<ChannelGroupDefinition, @Nullable String> channelGroupDescriptionResolver, final @Nullable Locale locale) { List<ChannelGroupDefinition> localizedChannelGroupDefinitions = new ArrayList<>(channelGroupDefinitions.size()); for (final ChannelGroupDefinition channelGroupDefinition : channelGroupDefinitions) { String channelGroupLabel = channelGroupLabelResolver.apply(channelGroupDefinition); String channelGroupDescription = channelGroupDescriptionResolver.apply(channelGroupDefinition); if (channelGroupLabel == null || channelGroupDescription == null) { ChannelGroupTypeUID channelGroupTypeUID = channelGroupDefinition.getTypeUID(); ChannelGroupType channelGroupType = channelGroupTypeRegistry.getChannelGroupType(channelGroupTypeUID, locale); if (channelGroupType != null) { if (channelGroupLabel == null) { channelGroupLabel = thingTypeI18nUtil.getChannelGroupLabel(bundle, channelGroupTypeUID, channelGroupType.getLabel(), locale); } if (channelGroupDescription == null) { channelGroupDescription = thingTypeI18nUtil.getChannelGroupDescription(bundle, channelGroupTypeUID, channelGroupType.getDescription(), locale); } } } localizedChannelGroupDefinitions.add(new ChannelGroupDefinition(channelGroupDefinition.getId(), channelGroupDefinition.getTypeUID(), channelGroupLabel, channelGroupDescription)); } return localizedChannelGroupDefinitions; }
@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; }
/** * Build the {@link ChannelGroupType} with the given values * * @return the created {@link ChannelGroupType} */ public ChannelGroupType build() { return new ChannelGroupType(channelGroupTypeUID, advanced, label, description, category, channelDefinitions); }
private void removeCachedChannelGroupTypes(ChannelGroupType channelGroupType) { for (Iterator<Entry<LocalizedChannelTypeKey, ChannelGroupType>> iterator = this.localizedChannelGroupTypeCache .entrySet().iterator(); iterator.hasNext();) { Entry<LocalizedChannelTypeKey, ChannelGroupType> entry = iterator.next(); if (entry.getKey().uid.equals(channelGroupType.getUID())) { iterator.remove(); } } }
List<ChannelDefinition> channelGroupChannelDefinitions = channelGroupType.getChannelDefinitions(); for (ChannelDefinition channelDefinition : channelGroupChannelDefinitions) { Channel channel = createChannel(channelDefinition, thingUID, channelGroupDefinition.getId(),
public ChannelGroupType toChannelGroupType(Map<String, ChannelType> channelTypes) throws ConversionException { ChannelGroupType channelGroupType = new ChannelGroupType(this.channelGroupTypeUID, this.advanced, this.label, this.description, toChannelDefinitions(this.channelTypeReferences, channelTypes)); return channelGroupType; }
@Override public ChannelGroupType getChannelGroupType(ChannelGroupTypeUID channelGroupTypeUID, Locale locale) { Collection<Entry<Bundle, List<ChannelGroupType>>> channelGroupTypesList = this.bundleChannelGroupTypesMap .entrySet(); if (channelGroupTypesList != null) { for (Entry<Bundle, List<ChannelGroupType>> channelGroupTypes : channelGroupTypesList) { for (ChannelGroupType channelGroupType : channelGroupTypes.getValue()) { if (channelGroupType.getUID().equals(channelGroupTypeUID)) { return createLocalizedChannelGroupType(channelGroupTypes.getKey(), channelGroupType, locale); } } } } return null; }