From afa043e61c515fee2d3dbfd769925d8ed4c269b5 Mon Sep 17 00:00:00 2001 From: Viktor Kovtun <viktor.kovtun@id.ethz.ch> Date: Fri, 18 Dec 2020 11:25:16 +0100 Subject: [PATCH] SSDM-10397 Refactored NumberFieldSearchConditionTranslator.translateNumberProperty(). --- .../NumberFieldSearchConditionTranslator.java | 19 +++++++------------ .../StringFieldSearchConditionTranslator.java | 7 +++---- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/search/translator/condition/NumberFieldSearchConditionTranslator.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/search/translator/condition/NumberFieldSearchConditionTranslator.java index f6130be574f..3e05263d370 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/search/translator/condition/NumberFieldSearchConditionTranslator.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/search/translator/condition/NumberFieldSearchConditionTranslator.java @@ -112,19 +112,18 @@ public class NumberFieldSearchConditionTranslator implements IConditionTranslato throw new UserFailureException("The data type of property " + criterion.getFieldName() + " has to be one of " + VALID_DATA_TYPES + " instead of " + casting + "."); } - final boolean internalProperty = TranslatorUtils.isPropertyInternal(criterion.getFieldName()); translateNumberProperty(tableMapper, args, sqlBuilder, aliases, value, - criterion.getFieldName(), internalProperty); + criterion.getFieldName()); break; } case ANY_PROPERTY: { final AbstractNumberValue value = criterion.getFieldValue(); - translateNumberProperty(tableMapper, args, sqlBuilder, aliases, value, null, null); + translateNumberProperty(tableMapper, args, sqlBuilder, aliases, value, null); break; } - + case ANY_FIELD: { throw new IllegalArgumentException(); @@ -134,7 +133,7 @@ public class NumberFieldSearchConditionTranslator implements IConditionTranslato static void translateNumberProperty(final TableMapper tableMapper, final List<Object> args, final StringBuilder sqlBuilder, final Map<String, JoinInformation> aliases, final AbstractNumberValue value, - final String fullPropertyName, final Boolean internalProperty) + final String fullPropertyName) { final JoinInformation attributeTypesJoinInformation = aliases.get(tableMapper.getAttributeTypesTable()); final String entityTypesSubTableAlias = attributeTypesJoinInformation.getSubTableAlias(); @@ -148,16 +147,12 @@ public class NumberFieldSearchConditionTranslator implements IConditionTranslato sqlBuilder.append(CASE).append(SP).append(WHEN).append(SP); } - if (internalProperty != null) + if (fullPropertyName != null) { + final boolean internalProperty = TranslatorUtils.isPropertyInternal(fullPropertyName); TranslatorUtils.appendInternalExternalConstraint(sqlBuilder, args, entityTypesSubTableAlias, internalProperty); - sqlBuilder.append(SP).append(AND); - } - - if (fullPropertyName != null) - { - sqlBuilder.append(SP).append(attributeTypesJoinInformation.getSubTableAlias()) + sqlBuilder.append(SP).append(AND).append(SP).append(attributeTypesJoinInformation.getSubTableAlias()) .append(PERIOD).append(ColumnNames.CODE_COLUMN).append(SP).append(EQ).append(SP).append(QU); args.add(TranslatorUtils.normalisePropertyName(fullPropertyName)); diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/search/translator/condition/StringFieldSearchConditionTranslator.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/search/translator/condition/StringFieldSearchConditionTranslator.java index ef777404ba8..9bb8454811b 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/search/translator/condition/StringFieldSearchConditionTranslator.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/search/translator/condition/StringFieldSearchConditionTranslator.java @@ -107,7 +107,7 @@ public class StringFieldSearchConditionTranslator implements IConditionTranslato value, null); break; } - + case ANY_FIELD: { throw new IllegalArgumentException(); @@ -161,12 +161,11 @@ public class StringFieldSearchConditionTranslator implements IConditionTranslato } // Delegating translation for number properties - if (casting.equals(DataTypeCode.INTEGER.toString()) - || casting.equals(DataTypeCode.REAL.toString())) + if (casting.equals(DataTypeCode.INTEGER.toString()) || casting.equals(DataTypeCode.REAL.toString())) { NumberFieldSearchConditionTranslator.translateNumberProperty(tableMapper, args, sqlBuilder, - aliases, convertStringValueToNumberValue(value), fullPropertyName, internalProperty); + aliases, convertStringValueToNumberValue(value), fullPropertyName); sqlBuilder.append(RP); return; } -- GitLab