]> git.basschouten.com Git - openhab-addons.git/blob
7a101541124baacd896b3d6a84043129f5a84f02
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.persistence.influxdb.internal;
14
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;
21
22 /**
23  * Logic to use items metadata from an openHAB {@link Item}
24  *
25  * @author Johannes Ott - Initial contribution
26  */
27 @NonNullByDefault
28 public class InfluxDBMetadataUtils {
29
30     private InfluxDBMetadataUtils() {
31     }
32
33     public static String calculateMeasurementNameFromMetadataIfPresent(
34             final @Nullable MetadataRegistry currentMetadataRegistry, String name, @Nullable String itemName) {
35
36         if (itemName == null || currentMetadataRegistry == null) {
37             return name;
38         }
39
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()) {
45                 name = metaName;
46             }
47         }
48
49         return name;
50     }
51 }