2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.persistence.influxdb.internal;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.core.items.Metadata;
18 import org.openhab.core.items.MetadataKey;
19 import org.openhab.core.items.MetadataRegistry;
20 import org.openhab.persistence.influxdb.InfluxDBPersistenceService;
23 * Logic to use items metadata from an openHAB {@link Item}
25 * @author Johannes Ott - Initial contribution
28 public class InfluxDBMetadataUtils {
30 private InfluxDBMetadataUtils() {
33 public static String calculateMeasurementNameFromMetadataIfPresent(
34 final @Nullable MetadataRegistry currentMetadataRegistry, String name, @Nullable String itemName) {
36 if (itemName == null || currentMetadataRegistry == null) {
40 MetadataKey key = new MetadataKey(InfluxDBPersistenceService.SERVICE_NAME, itemName);
41 Metadata metadata = currentMetadataRegistry.get(key);
42 if (metadata != null) {
43 String metaName = metadata.getValue();
44 if (!metaName.isBlank()) {