From bebf94401be6d4d30e96a2063c428f883bb867c2 Mon Sep 17 00:00:00 2001 From: Teo Sarca Date: Sun, 3 Dec 2017 21:34:33 +0200 Subject: [PATCH] JSONLookupValue.concat https://github.com/metasfresh/metasfresh-webui-api/issues/711 --- .../window/datatypes/json/JSONLookupValue.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/de/metas/ui/web/window/datatypes/json/JSONLookupValue.java b/src/main/java/de/metas/ui/web/window/datatypes/json/JSONLookupValue.java index 489bc253d..3ba3aea30 100644 --- a/src/main/java/de/metas/ui/web/window/datatypes/json/JSONLookupValue.java +++ b/src/main/java/de/metas/ui/web/window/datatypes/json/JSONLookupValue.java @@ -11,6 +11,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.common.base.Joiner; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableMap; @@ -138,6 +139,23 @@ public static JSONLookupValue unknown(final int id) return of(id, "<" + id + ">"); } + public static final JSONLookupValue concat(final JSONLookupValue lookupValue1, final JSONLookupValue lookupValue2) + { + if (lookupValue1 == null) + { + return lookupValue2; + } + if (lookupValue2 == null) + { + return lookupValue1; + } + + final String key = Joiner.on("_").skipNulls().join(lookupValue1.getKey(), lookupValue2.getKey()); + final String caption = Joiner.on(" ").skipNulls().join(lookupValue1.getCaption(), lookupValue2.getCaption()); + return JSONLookupValue.of(key, caption); + + } + // IMPORTANT: when changing this property name, pls also check/change de.metas.handlingunits.attribute.impl.AbstractAttributeValue.extractKey(Map, I_M_Attribute) private static final String PROPERTY_Key = "key"; @JsonProperty(PROPERTY_Key)