/** * Returns the channel group type for the given UID with the default {@link Locale}. * * @return channel group type or null if no channel group type for the given UID exists */ @Nullable public ChannelGroupType getChannelGroupType(@Nullable ChannelGroupTypeUID channelGroupTypeUID) { return getChannelGroupType(channelGroupTypeUID, null); }
/** * Returns all channel group types with the default {@link Locale}. * * @return all channel group types or empty list if no channel group type exists */ public List<ChannelGroupType> getChannelGroupTypes() { return getChannelGroupTypes(null); }
@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; }
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; }
if (channelGroupTypeRegistry != null) { channelGroupType = channelGroupTypeRegistry .getChannelGroupType(channelGroupDefinition.getTypeUID());
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; }