diff --git a/server/src/main/java/org/tango/server/attribute/AttributePropertiesImpl.java b/server/src/main/java/org/tango/server/attribute/AttributePropertiesImpl.java index 9aa95d53..aad093c9 100644 --- a/server/src/main/java/org/tango/server/attribute/AttributePropertiesImpl.java +++ b/server/src/main/java/org/tango/server/attribute/AttributePropertiesImpl.java @@ -480,7 +480,7 @@ private void setEnumLabelsPrivate(final String[] enumLabels) throws DevFailed { } // find duplicate values final List inputList = Arrays.asList(enumLabels); - final Set inputSet = new HashSet(inputList); + final Set inputSet = new HashSet<>(inputList); if (inputSet.size() < inputList.size()) { throw DevFailedUtils.newDevFailed(ExceptionMessages.ATTR_OPT_PROP, "duplicate enum values not allowed"); } @@ -630,7 +630,7 @@ public void setRootAttribute(final String rootAttribute) { } void persist(final String deviceName, final String attributeName) throws DevFailed { - final Map properties = new HashMap(); + final Map properties = new HashMap<>(); properties.put(Constants.LABEL, new String[]{getLabel()}); if (!isFwdAttribute) { properties.put(Constants.FORMAT, new String[]{getFormat()}); @@ -664,13 +664,11 @@ void load(final String deviceName, final String attributeName) throws DevFailed final AttributePropertiesManager attributePropertiesManager = new AttributePropertiesManager(deviceName); final Map propValues = attributePropertiesManager.getAttributePropertiesFromDB(attributeName); // use a second map for attribute props that have one value - final Map propValuesSingle = new CaseInsensitiveMap(propValues.size()); + final Map propValuesSingle = new CaseInsensitiveMap<>(propValues.size()); for (final Entry entry : propValues.entrySet()) { final String[] value = entry.getValue(); - if (value.length == 1) { + if (value.length == 1 && !value[0].equalsIgnoreCase(Constants.NOT_SPECIFIED)) { propValuesSingle.put(entry.getKey(), value[0]); - } else if (value.length == 0) { - propValuesSingle.put(entry.getKey(), ""); } } // if (propValues.containsKey(ROOT_ATTRIBUTE)) { diff --git a/server/src/main/java/org/tango/server/properties/AttributePropertiesManager.java b/server/src/main/java/org/tango/server/properties/AttributePropertiesManager.java index 9f10e473..000db1cc 100644 --- a/server/src/main/java/org/tango/server/properties/AttributePropertiesManager.java +++ b/server/src/main/java/org/tango/server/properties/AttributePropertiesManager.java @@ -1,34 +1,30 @@ /** * Copyright (C) : 2012 - * - * Synchrotron Soleil - * L'Orme des merisiers - * Saint Aubin - * BP48 - * 91192 GIF-SUR-YVETTE CEDEX - * + *

+ * Synchrotron Soleil + * L'Orme des merisiers + * Saint Aubin + * BP48 + * 91192 GIF-SUR-YVETTE CEDEX + *

* This file is part of Tango. - * + *

* Tango is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + *

* Tango is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + *

* You should have received a copy of the GNU Lesser General Public License * along with Tango. If not, see . */ package org.tango.server.properties; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; - +import fr.esrf.Tango.DevFailed; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.ext.XLogger; @@ -37,13 +33,15 @@ import org.tango.server.Constants; import org.tango.utils.CaseInsensitiveMap; -import fr.esrf.Tango.DevFailed; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; /** * Manage attribute properties persistancy in tango db. * * @author ABEILLE - * */ public final class AttributePropertiesManager { @@ -83,10 +81,8 @@ private Map getAttributePropertiesFromDBSingle(final String attr for (final Entry entry : prop.entrySet()) { final String name = entry.getKey(); final String[] value = entry.getValue(); - if (value.length > 0) { + if (value.length > 0 && !value[0].equalsIgnoreCase(Constants.NOT_SPECIFIED)) { result.put(name, value[0]); - } else { - result.put(name, ""); } } xlogger.exit(); @@ -107,7 +103,7 @@ public void removeAttributeProperties(final String... attributeNames) throws Dev */ public String getAttributePropertyFromDB(final String attributeName, final String propertyName) throws DevFailed { xlogger.entry(propertyName); - String[] result = new String[] {}; + String[] result = new String[]{}; final Map prop = DatabaseFactory.getDatabase().getAttributeProperties(deviceName, attributeName); if (prop.get(propertyName) != null) { @@ -151,9 +147,9 @@ public void setAttributePropertyInDB(final String attributeName, final String pr // DatabaseFactory.getDatabase().setAttributeProperties(deviceName, attributeName, propInsert); // } // } else { - logger.debug("update in DB {}, property {}= {}", new Object[] { attributeName, propertyName, value }); + logger.debug("update in DB {}, property {}= {}", new Object[]{attributeName, propertyName, value}); final Map propInsert = new HashMap(); - propInsert.put(propertyName, new String[] { value }); + propInsert.put(propertyName, new String[]{value}); DatabaseFactory.getDatabase().setAttributeProperties(deviceName, attributeName, propInsert); // } xlogger.exit(); @@ -184,9 +180,9 @@ public void setAttributePropertiesInDB(final String attributeName, final Map