Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

Commit

Permalink
avoid overriding default value of properties when value in tango DB i…
Browse files Browse the repository at this point in the history
…s "not specified"
  • Loading branch information
gwen-soleil committed Jul 16, 2020
1 parent 161ab14 commit ab2c3a6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ private void setEnumLabelsPrivate(final String[] enumLabels) throws DevFailed {
}
// find duplicate values
final List<String> inputList = Arrays.asList(enumLabels);
final Set<String> inputSet = new HashSet<String>(inputList);
final Set<String> inputSet = new HashSet<>(inputList);
if (inputSet.size() < inputList.size()) {
throw DevFailedUtils.newDevFailed(ExceptionMessages.ATTR_OPT_PROP, "duplicate enum values not allowed");
}
Expand Down Expand Up @@ -630,7 +630,7 @@ public void setRootAttribute(final String rootAttribute) {
}

void persist(final String deviceName, final String attributeName) throws DevFailed {
final Map<String, String[]> properties = new HashMap<String, String[]>();
final Map<String, String[]> properties = new HashMap<>();
properties.put(Constants.LABEL, new String[]{getLabel()});
if (!isFwdAttribute) {
properties.put(Constants.FORMAT, new String[]{getFormat()});
Expand Down Expand Up @@ -664,13 +664,11 @@ void load(final String deviceName, final String attributeName) throws DevFailed
final AttributePropertiesManager attributePropertiesManager = new AttributePropertiesManager(deviceName);
final Map<String, String[]> propValues = attributePropertiesManager.getAttributePropertiesFromDB(attributeName);
// use a second map for attribute props that have one value
final Map<String, String> propValuesSingle = new CaseInsensitiveMap<String>(propValues.size());
final Map<String, String> propValuesSingle = new CaseInsensitiveMap<>(propValues.size());
for (final Entry<String, String[]> 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)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
/**
* Copyright (C) : 2012
*
* Synchrotron Soleil
* L'Orme des merisiers
* Saint Aubin
* BP48
* 91192 GIF-SUR-YVETTE CEDEX
*
* <p>
* Synchrotron Soleil
* L'Orme des merisiers
* Saint Aubin
* BP48
* 91192 GIF-SUR-YVETTE CEDEX
* <p>
* This file is part of Tango.
*
* <p>
* 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.
*
* <p>
* 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.
*
* <p>
* You should have received a copy of the GNU Lesser General Public License
* along with Tango. If not, see <http://www.gnu.org/licenses/>.
*/
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;
Expand All @@ -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 {

Expand Down Expand Up @@ -83,10 +81,8 @@ private Map<String, String> getAttributePropertiesFromDBSingle(final String attr
for (final Entry<String, String[]> 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();
Expand All @@ -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<String, String[]> prop = DatabaseFactory.getDatabase().getAttributeProperties(deviceName,
attributeName);
if (prop.get(propertyName) != null) {
Expand Down Expand Up @@ -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<String, String[]> propInsert = new HashMap<String, String[]>();
propInsert.put(propertyName, new String[] { value });
propInsert.put(propertyName, new String[]{value});
DatabaseFactory.getDatabase().setAttributeProperties(deviceName, attributeName, propInsert);
// }
xlogger.exit();
Expand Down Expand Up @@ -184,9 +180,9 @@ public void setAttributePropertiesInDB(final String attributeName, final Map<Str
if (presentValue != null) {
isADefaultValue = presentValue.isEmpty()
&& (value.equalsIgnoreCase(Constants.NOT_SPECIFIED)
|| value.equalsIgnoreCase(Constants.NO_DIPLAY_UNIT)
|| value.equalsIgnoreCase(Constants.NO_UNIT) || value
.equalsIgnoreCase(Constants.NO_STD_UNIT));
|| value.equalsIgnoreCase(Constants.NO_DIPLAY_UNIT)
|| value.equalsIgnoreCase(Constants.NO_UNIT) || value
.equalsIgnoreCase(Constants.NO_STD_UNIT));
}
if (!isADefaultValue) {
if (presentValue == null) {
Expand Down

0 comments on commit ab2c3a6

Please sign in to comment.