/** * Maps channel DTO into channel object. * * @param channelDTO the channel DTO * @return the channel object */ public static Channel map(ChannelDTO channelDTO) { ChannelUID channelUID = new ChannelUID(channelDTO.uid); ChannelTypeUID channelTypeUID = new ChannelTypeUID(channelDTO.channelTypeUID); return ChannelBuilder.create(channelUID, channelDTO.itemType) .withConfiguration(new Configuration(channelDTO.configuration)).withLabel(channelDTO.label) .withDescription(channelDTO.description).withProperties(channelDTO.properties).withType(channelTypeUID) .withDefaultTags(channelDTO.defaultTags).withKind(ChannelKind.parse(channelDTO.kind)).build(); } }
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(); }
/** * Creates a channel builder from the given channel. * * @param channel the channel to be changed * @return channel builder */ public static ChannelBuilder create(Channel channel) { ChannelBuilder channelBuilder = create(channel.getUID(), channel.getAcceptedItemType()) .withConfiguration(channel.getConfiguration()).withDefaultTags(channel.getDefaultTags()) .withKind(channel.getKind()).withProperties(channel.getProperties()) .withType(channel.getChannelTypeUID()); String label = channel.getLabel(); if (label != null) { channelBuilder.withLabel(label); } String description = channel.getDescription(); if (description != null) { channelBuilder.withDescription(description); } return channelBuilder; }
channelBuilder = channelBuilder.withDescription(description);