From 8cf60b7dcc22f66ab736905b26c5f30791479735 Mon Sep 17 00:00:00 2001 From: Radovan Semancik Date: Fri, 1 Mar 2019 18:26:49 +0100 Subject: [PATCH] Support for PolyString translation --- .../midpoint/prism/polystring/PolyString.java | 44 ++++++ .../PolyStringTranslationArgumentType.java | 115 ++++++++++++++++ .../types_3/PolyStringTranslationType.java | 129 ++++++++++++++++++ .../ns/_public/types_3/PolyStringType.java | 49 +++++-- .../prism/impl/marshaller/BeanMarshaller.java | 10 +- .../impl/marshaller/BeanUnmarshaller.java | 9 +- .../impl/marshaller/PrismMarshaller.java | 30 +++- .../main/resources/xml/ns/public/types-3.xsd | 73 +++++++++- .../midpoint/prism/PrismInternalTestUtil.java | 37 ++++- .../com/evolveum/midpoint/prism/TestFind.java | 2 +- .../midpoint/prism/TestPrismParsing.java | 16 +-- .../common/json/user-jack-adhoc.json | 14 +- .../common/json/user-jack-modified.json | 14 +- .../common/json/user-jack-no-ns.json | 13 +- .../test/resources/common/json/user-jack.json | 14 +- .../resources/common/xml/user-jack-adhoc.xml | 7 + .../common/xml/user-jack-modified.xml | 7 + .../resources/common/xml/user-jack-no-ns.xml | 7 + .../test/resources/common/xml/user-jack.xml | 7 + .../common/yaml/user-jack-adhoc.yaml | 10 +- .../common/yaml/user-jack-modified.yaml | 10 +- .../common/yaml/user-jack-no-ns.yaml | 9 +- .../test/resources/common/yaml/user-jack.yaml | 10 +- 23 files changed, 598 insertions(+), 38 deletions(-) create mode 100644 infra/prism-api/src/main/java/com/evolveum/prism/xml/ns/_public/types_3/PolyStringTranslationArgumentType.java create mode 100644 infra/prism-api/src/main/java/com/evolveum/prism/xml/ns/_public/types_3/PolyStringTranslationType.java diff --git a/infra/prism-api/src/main/java/com/evolveum/midpoint/prism/polystring/PolyString.java b/infra/prism-api/src/main/java/com/evolveum/midpoint/prism/polystring/PolyString.java index e3551ed0faa..841acd15469 100644 --- a/infra/prism-api/src/main/java/com/evolveum/midpoint/prism/polystring/PolyString.java +++ b/infra/prism-api/src/main/java/com/evolveum/midpoint/prism/polystring/PolyString.java @@ -25,6 +25,8 @@ import com.evolveum.midpoint.util.DebugUtil; import com.evolveum.midpoint.util.QNameUtil; import com.evolveum.midpoint.util.ShortDumpable; +import com.evolveum.midpoint.util.annotation.Experimental; +import com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType; import com.evolveum.prism.xml.ns._public.types_3.PolyStringType; import java.io.Serializable; @@ -50,9 +52,11 @@ public class PolyString implements Matchable, Recomputable, Structur public static final ItemName F_ORIG = new ItemName(PrismConstants.NS_TYPES, "orig"); public static final ItemName F_NORM = new ItemName(PrismConstants.NS_TYPES, "norm"); + public static final ItemName F_TRANSLATION = new ItemName(PrismConstants.NS_TYPES, "translation"); private final String orig; private String norm = null; + private PolyStringTranslationType translation; public PolyString(String orig) { super(); @@ -70,6 +74,11 @@ public PolyString(String orig, String norm) { this.orig = orig; this.norm = norm; } + + public PolyString(String orig, String norm, PolyStringTranslationType translation) { + this(orig, norm); + this.translation = translation; + } public String getOrig() { return orig; @@ -79,6 +88,19 @@ public String getNorm() { return norm; } + public PolyStringTranslationType getTranslation() { + return translation; + } + + /** + * Do NOT rely on this method too much. It may disappear later, e.g. when we align PolyString and PolyString type and + * make PolyString really immutable. + */ + @Experimental + public void setTranslation(PolyStringTranslationType translation) { + this.translation = translation; + } + public boolean isEmpty() { if (orig == null) { return true; @@ -111,6 +133,8 @@ public Object resolve(ItemPath subpath) { return orig; } else if (QNameUtil.match(F_NORM, itemName)) { return norm; + } else if (QNameUtil.match(F_TRANSLATION, itemName)) { + return translation; } else { throw new IllegalArgumentException("Unknown path segment "+itemName); } @@ -184,6 +208,7 @@ public int hashCode() { int result = 1; result = prime * result + ((norm == null) ? 0 : norm.hashCode()); result = prime * result + ((orig == null) ? 0 : orig.hashCode()); + result = prime * result + ((translation == null) ? 0 : translation.hashCode()); return result; } @@ -206,6 +231,11 @@ public boolean equals(Object obj) { return false; } else if (!orig.equals(other.orig)) return false; + if (translation == null) { + if (other.translation != null) + return false; + } else if (!translation.equals(other.translation)) + return false; return true; } @@ -241,6 +271,10 @@ public String debugDump(int indent) { sb.append(","); sb.append(norm); } + if (translation != null) { + sb.append(";translation="); + sb.append(translation.getKey()); + } sb.append(")"); return sb.toString(); } @@ -278,6 +312,15 @@ public boolean matches(String regex) { return Pattern.matches(regex, norm) || Pattern.matches(regex, orig); } + /** + * Returns true if the PolyString form contains only simple string. + * I.e. returns true if the polystring can be serialized in a simplified form of a single string. + * Returns true in case that there are language mutations, translation, etc. + */ + public boolean isSimple() { + return translation == null; + } + @Override public void checkConsistence() { if (orig == null) { @@ -299,4 +342,5 @@ public static PolyStringType toPolyStringType(PolyString value) { public static PolyString fromOrig(String orig) { return new PolyString(orig); } + } diff --git a/infra/prism-api/src/main/java/com/evolveum/prism/xml/ns/_public/types_3/PolyStringTranslationArgumentType.java b/infra/prism-api/src/main/java/com/evolveum/prism/xml/ns/_public/types_3/PolyStringTranslationArgumentType.java new file mode 100644 index 00000000000..a638f4e632a --- /dev/null +++ b/infra/prism-api/src/main/java/com/evolveum/prism/xml/ns/_public/types_3/PolyStringTranslationArgumentType.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2019 Evolveum + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2014.02.04 at 01:34:24 PM CET +// + + +package com.evolveum.prism.xml.ns._public.types_3; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; +import javax.xml.namespace.QName; + + +/** + * WARNING: this is NOT a generated code. + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "PolyStringTranslationArgumentType", propOrder = { + "value", + "translation" +}) +public class PolyStringTranslationArgumentType implements Serializable, Cloneable { + private static final long serialVersionUID = 1L; + + public static final QName COMPLEX_TYPE = new QName("http://prism.evolveum.com/xml/ns/public/types-3", "PolyStringTranslationArgumentType"); + + protected String value; + protected PolyStringTranslationType translation; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public PolyStringTranslationType getTranslation() { + return translation; + } + + public void setTranslation(PolyStringTranslationType translation) { + this.translation = translation; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((translation == null) ? 0 : translation.hashCode()); + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + PolyStringTranslationArgumentType other = (PolyStringTranslationArgumentType) obj; + if (translation == null) { + if (other.translation != null) + return false; + } else if (!translation.equals(other.translation)) + return false; + if (value == null) { + if (other.value != null) + return false; + } else if (!value.equals(other.value)) + return false; + return true; + } + + @Override + public String toString() { + return "PolyStringTranslationArgumentType(value=" + value + ", translation=" + translation + ")"; + } + + @Override + public PolyStringTranslationArgumentType clone() { + PolyStringTranslationArgumentType cloned = new PolyStringTranslationArgumentType(); + cloned.setValue(value); + if (translation != null) { + cloned.setTranslation(translation.clone()); + } + return cloned; + } +} diff --git a/infra/prism-api/src/main/java/com/evolveum/prism/xml/ns/_public/types_3/PolyStringTranslationType.java b/infra/prism-api/src/main/java/com/evolveum/prism/xml/ns/_public/types_3/PolyStringTranslationType.java new file mode 100644 index 00000000000..09025dfdfde --- /dev/null +++ b/infra/prism-api/src/main/java/com/evolveum/prism/xml/ns/_public/types_3/PolyStringTranslationType.java @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2019 Evolveum + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2014.02.04 at 01:34:24 PM CET +// + + +package com.evolveum.prism.xml.ns._public.types_3; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; +import javax.xml.namespace.QName; + + +/** + * WARNING: this is NOT a generated code. + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "PolyStringTranslationType", propOrder = { + "key", + "fallback", + "argument" +}) +public class PolyStringTranslationType implements Serializable, Cloneable { + private static final long serialVersionUID = 1L; + + public static final QName COMPLEX_TYPE = new QName("http://prism.evolveum.com/xml/ns/public/types-3", "PolyStringTranslationType"); + + @XmlElement(required = true) + protected String key; + protected String fallback; + protected final List argument = new ArrayList<>(); + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getFallback() { + return fallback; + } + + public void setFallback(String fallback) { + this.fallback = fallback; + } + + public List getArgument() { + return argument; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((argument == null) ? 0 : argument.hashCode()); + result = prime * result + ((fallback == null) ? 0 : fallback.hashCode()); + result = prime * result + ((key == null) ? 0 : key.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + PolyStringTranslationType other = (PolyStringTranslationType) obj; + if (argument == null) { + if (other.argument != null) + return false; + } else if (!argument.equals(other.argument)) + return false; + if (fallback == null) { + if (other.fallback != null) + return false; + } else if (!fallback.equals(other.fallback)) + return false; + if (key == null) { + if (other.key != null) + return false; + } else if (!key.equals(other.key)) + return false; + return true; + } + + @Override + public String toString() { + return "PolyStringTranslationType(key=" + key + ", fallback=" + fallback + ", argument=" + argument + ")"; + } + + @Override + public PolyStringTranslationType clone() { + PolyStringTranslationType cloned = new PolyStringTranslationType(); + cloned.setKey(getKey()); + cloned.setFallback(getFallback()); + for (PolyStringTranslationArgumentType argument : getArgument()) { + cloned.getArgument().add(argument.clone()); + } + return cloned; + } +} diff --git a/infra/prism-api/src/main/java/com/evolveum/prism/xml/ns/_public/types_3/PolyStringType.java b/infra/prism-api/src/main/java/com/evolveum/prism/xml/ns/_public/types_3/PolyStringType.java index 4a058a34c15..09b943264b9 100644 --- a/infra/prism-api/src/main/java/com/evolveum/prism/xml/ns/_public/types_3/PolyStringType.java +++ b/infra/prism-api/src/main/java/com/evolveum/prism/xml/ns/_public/types_3/PolyStringType.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2013 Evolveum + * Copyright (c) 2010-2019 Evolveum * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -86,15 +86,21 @@ @XmlType(name = "PolyStringType", propOrder = { "orig", "norm", + "translation", "any" }) public class PolyStringType implements DebugDumpable, Serializable, Cloneable { + private static final long serialVersionUID = 1L; public static final QName COMPLEX_TYPE = new QName("http://prism.evolveum.com/xml/ns/public/types-3", "PolyStringType"); @XmlElement(required = true) protected String orig; + protected String norm; + + protected PolyStringTranslationType translation; + @XmlAnyElement(lax = true) protected List any; @@ -111,6 +117,7 @@ public PolyStringType(String orig) { public PolyStringType(PolyString polyString) { this.orig = polyString.getOrig(); this.norm = polyString.getNorm(); + this.translation = polyString.getTranslation(); } /** @@ -160,8 +167,16 @@ public String getNorm() { public void setNorm(String value) { this.norm = value; } + + public PolyStringTranslationType getTranslation() { + return translation; + } - /** + public void setTranslation(PolyStringTranslationType translation) { + this.translation = translation; + } + + /** * Gets the value of the any property. * *

@@ -197,6 +212,15 @@ public boolean isEmpty() { return orig.isEmpty(); } + /** + * Returns true if the PolyString form contains only simple string. + * I.e. returns true if the polystring can be serialized in a simplified form of a single string. + * Returns true in case that there are language mutations, translation, etc. + */ + public boolean isSimple() { + return translation == null; + } + /** * Plus method for ease of use of PolyStrings in groovy (mapped from + operator). */ @@ -215,7 +239,7 @@ public PolyStringType plus(PolyStringType operand) { } public PolyString toPolyString() { - return new PolyString(orig, norm); + return new PolyString(orig, norm, translation); } /** @@ -231,11 +255,6 @@ public String toString() { return orig; } - @Override - public String debugDump() { - return debugDump(0); - } - @Override public String debugDump(int indent) { StringBuilder sb = new StringBuilder(); @@ -246,6 +265,10 @@ public String debugDump(int indent) { sb.append(","); sb.append(norm); } + if (translation != null) { + sb.append(";translation="); + sb.append(translation.getKey()); + } sb.append(")"); return sb.toString(); @@ -256,6 +279,9 @@ public PolyStringType clone() { PolyStringType poly = new PolyStringType(); poly.setNorm(getNorm()); poly.setOrig(getOrig()); + if (translation != null) { + poly.setTranslation(translation.clone()); + } copyContent(getAny(), poly.getAny()); return poly; @@ -504,6 +530,7 @@ public int hashCode() { result = prime * result + ((any == null || any.isEmpty()) ? 0 : any.hashCode()); result = prime * result + ((norm == null) ? 0 : norm.hashCode()); result = prime * result + ((orig == null) ? 0 : orig.hashCode()); + result = prime * result + ((translation == null) ? 0 : translation.hashCode()); return result; } @@ -534,10 +561,16 @@ public boolean equals(Object obj) { return false; } else if (!orig.equals(other.orig)) return false; + if (translation == null) { + if (other.translation != null) + return false; + } else if (!translation.equals(other.translation)) + return false; return true; } public static PolyStringType fromOrig(String name) { return name != null ? new PolyStringType(name) : null; } + } diff --git a/infra/prism-impl/src/main/java/com/evolveum/midpoint/prism/impl/marshaller/BeanMarshaller.java b/infra/prism-impl/src/main/java/com/evolveum/midpoint/prism/impl/marshaller/BeanMarshaller.java index 7581dbd45c7..f4c4042fd0a 100644 --- a/infra/prism-impl/src/main/java/com/evolveum/midpoint/prism/impl/marshaller/BeanMarshaller.java +++ b/infra/prism-impl/src/main/java/com/evolveum/midpoint/prism/impl/marshaller/BeanMarshaller.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2018 Evolveum + * Copyright (c) 2010-2019 Evolveum * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -89,9 +89,13 @@ public XNodeImpl marshall(@Nullable T bean, @Nullable SerializationContext c // avoiding chatty PolyString serializations (namespace declaration + orig + norm) if (bean instanceof PolyString) { - bean = (T) ((PolyString) bean).getOrig(); + if (((PolyString)bean).isSimple()) { + bean = (T) ((PolyString) bean).getOrig(); + } } else if (bean instanceof PolyStringType) { - bean = (T) ((PolyStringType) bean).getOrig(); + if (((PolyStringType)bean).isSimple()) { + bean = (T) ((PolyStringType) bean).getOrig(); + } } if (bean instanceof Containerable) { diff --git a/infra/prism-impl/src/main/java/com/evolveum/midpoint/prism/impl/marshaller/BeanUnmarshaller.java b/infra/prism-impl/src/main/java/com/evolveum/midpoint/prism/impl/marshaller/BeanUnmarshaller.java index 78b1027755c..3a31ae7dddb 100644 --- a/infra/prism-impl/src/main/java/com/evolveum/midpoint/prism/impl/marshaller/BeanUnmarshaller.java +++ b/infra/prism-impl/src/main/java/com/evolveum/midpoint/prism/impl/marshaller/BeanUnmarshaller.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2018 Evolveum + * Copyright (c) 2010-2019 Evolveum * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1156,7 +1156,12 @@ private Object unmarshalPolyStringFromMap(MapXNodeImpl map, Class beanClass, throw new SchemaException("Null polystring orig in "+map); } String norm = map.getParsedPrimitiveValue(QNameUtil.nullNamespace(PolyString.F_NORM), DOMUtil.XSD_STRING); - Object value = new PolyStringType(new PolyString(orig, norm)); + PolyStringTranslationType translation = null; + XNodeImpl xTranslation = map.get(QNameUtil.nullNamespace(PolyString.F_TRANSLATION)); + if (xTranslation != null) { + translation = unmarshal(xTranslation, PolyStringTranslationType.class, pc); + } + Object value = new PolyStringType(new PolyString(orig, norm, translation)); return toCorrectPolyStringClass(value, beanClass, map); } diff --git a/infra/prism-impl/src/main/java/com/evolveum/midpoint/prism/impl/marshaller/PrismMarshaller.java b/infra/prism-impl/src/main/java/com/evolveum/midpoint/prism/impl/marshaller/PrismMarshaller.java index f79f9a6a455..a306a5b688e 100644 --- a/infra/prism-impl/src/main/java/com/evolveum/midpoint/prism/impl/marshaller/PrismMarshaller.java +++ b/infra/prism-impl/src/main/java/com/evolveum/midpoint/prism/impl/marshaller/PrismMarshaller.java @@ -30,6 +30,7 @@ import com.evolveum.midpoint.util.logging.TraceManager; import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType; import com.evolveum.prism.xml.ns._public.types_3.EvaluationTimeType; +import com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType; import com.evolveum.prism.xml.ns._public.types_3.PolyStringType; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.Validate; @@ -453,10 +454,31 @@ private XNodeImpl serializePropertyValue(@NotNull PrismPropertyValue valu } } - private XNodeImpl serializePolyString(PolyString realValue) { - PrimitiveXNodeImpl xprim = new PrimitiveXNodeImpl<>(); - xprim.setValue(realValue, PolyStringType.COMPLEX_TYPE); - return xprim; + private XNodeImpl serializePolyString(PolyString realValue) throws SchemaException { + if (realValue.isSimple()) { + PrimitiveXNodeImpl xprim = new PrimitiveXNodeImpl<>(); + xprim.setValue(realValue, PolyStringType.COMPLEX_TYPE); + return xprim; + + } else { + MapXNodeImpl xmap = new MapXNodeImpl(); + + PrimitiveXNodeImpl xorig = new PrimitiveXNodeImpl<>(); + xorig.setValue(realValue.getOrig(), DOMUtil.XSD_STRING); + xmap.put(PolyString.F_ORIG, xorig); + + PrimitiveXNodeImpl xnorm = new PrimitiveXNodeImpl<>(); + xnorm.setValue(realValue.getNorm(), DOMUtil.XSD_STRING); + xmap.put(PolyString.F_NORM, xnorm); + + PolyStringTranslationType translation = realValue.getTranslation(); + if (translation != null) { + XNodeImpl xTranslation = beanMarshaller.marshall(translation); + xmap.put(PolyString.F_TRANSLATION, xTranslation); + } + + return xmap; + } } @NotNull diff --git a/infra/prism-impl/src/main/resources/xml/ns/public/types-3.xsd b/infra/prism-impl/src/main/resources/xml/ns/public/types-3.xsd index bf624c0a00f..0ea40e96044 100644 --- a/infra/prism-impl/src/main/resources/xml/ns/public/types-3.xsd +++ b/infra/prism-impl/src/main/resources/xml/ns/public/types-3.xsd @@ -30,7 +30,7 @@ Basic Prism types. - Version: 3.9 + Version: 4.0-SNAPSHOT Recommended namespace prefix: t @@ -87,6 +87,16 @@ + + + + Definition of string value by using localization key and parameters. + + + 4.0 + + + @@ -99,6 +109,67 @@ + + + + Definition of string value by using localization key and parameters. + + + 4.0 + + + + + + + Key used to look up the localized message format in the localization catalogs. + + + + + + + Value of the string to be used in case that the key is not found in the localization catalogs. + + + + + + + Arguments for the translation. Arguments refer to placeholders in the format string in the localization catalog. + + + + + + + + + + Arguments for localization translation. Arguments refer to placeholders in the format string in the localization catalog. + + + 4.0 + + + + + + + Literal value for the localization argument. + + + + + + + Value of the localization argument is to be determined by using another localization key. + + + + + + diff --git a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/PrismInternalTestUtil.java b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/PrismInternalTestUtil.java index 7550dbfe58d..eaf7ce5c053 100644 --- a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/PrismInternalTestUtil.java +++ b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/PrismInternalTestUtil.java @@ -55,6 +55,8 @@ import com.evolveum.midpoint.prism.xml.XmlTypeConverter; import com.evolveum.midpoint.util.DOMUtil; import com.evolveum.midpoint.util.exception.SchemaException; +import com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationArgumentType; +import com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType; import com.evolveum.prism.xml.ns._public.types_3.PolyStringType; import com.evolveum.prism.xml.ns._public.types_3.RawType; @@ -300,9 +302,13 @@ public static void displayTestTitle(String testName) { } public static void assertUserJack(PrismObject user, boolean expectRawInConstructions) throws SchemaException { + assertUserJack(user, expectRawInConstructions, true); + } + + public static void assertUserJack(PrismObject user, boolean expectRawInConstructions, boolean expectFullPolyName) throws SchemaException { user.checkConsistence(); user.assertDefinitions("test"); - assertUserJackContent(user, expectRawInConstructions); + assertUserJackContent(user, expectRawInConstructions, expectFullPolyName); assertUserJackExtension(user); assertVisitor(user, 71); @@ -321,7 +327,7 @@ public static void assertUserJack(PrismObject user, boolean expectRawI // NameItemPathSegment.WILDCARD), false, 5); } - public static void assertUserJackContent(PrismObject user, boolean expectRawInConstructions) throws SchemaException { + public static void assertUserJackContent(PrismObject user, boolean expectRawInConstructions, boolean expectFullPolyName) throws SchemaException { PrismContext prismContext = user.getPrismContext(); assertEquals("Wrong oid", USER_JACK_OID, user.getOid()); assertEquals("Wrong version", "42", user.getVersion()); @@ -340,7 +346,7 @@ public static void assertUserJackContent(PrismObject user, boolean exp assertPropertyValue(user, "special", "got it!"); assertPropertyDefinition(user, "special", DOMUtil.XSD_STRING, 0, 1); - assertPropertyValue(user, "polyName", new PolyString("Džek Sperou","dzek sperou")); + asssertJackPolyName(user, expectFullPolyName); assertPropertyDefinition(user, "polyName", PolyStringType.COMPLEX_TYPE, 0, 1); ItemPath enabledPath = USER_ENABLED_PATH; @@ -422,6 +428,31 @@ public static void assertUserJackContent(PrismObject user, boolean exp } + private static void asssertJackPolyName(PrismObject user, boolean expectFullPolyName) { + ItemName propQName = new ItemName(NS_FOO, "polyName"); + PrismProperty polyNameProp = user.findProperty(propQName); + asssertJackPolyName(polyNameProp, user, expectFullPolyName); + } + + public static void asssertJackPolyName(PrismProperty polyNameProp, PrismObject user, boolean expectFullPolyName) { + assertNotNull("No polyName in "+user, polyNameProp); + PolyString polyName = polyNameProp.getAnyRealValue(); + assertEquals("Wrong polyName.orig in "+user, "Džek Sperou", polyName.getOrig()); + assertEquals("Wrong polyName.norm in "+user, "dzek sperou", polyName.getNorm()); + if (expectFullPolyName) { + PolyStringTranslationType translation = polyName.getTranslation(); + assertNotNull("No polyName.translation in "+user, translation); + assertEquals("Wrong polyName.translation.key in "+user, "JACK", translation.getKey()); + assertEquals("Wrong polyName.translation.fallback in "+user, "Jack", translation.getFallback()); + List arguments = translation.getArgument(); + assertNotNull("No polyName.translation.argument list in "+user, arguments); + assertEquals("Wrong number of polyName.translation.argument in "+user, 1, arguments.size()); + PolyStringTranslationArgumentType argument = arguments.get(0); + assertNotNull("No polyName.translation.argument in "+user, argument); + assertEquals("Wrong polyName.translation.argument.value in "+user, "Sparrow", argument.getValue()); + } + } + private static void assertUserJackExtension(PrismObject user) throws SchemaException { PrismContext prismContext = user.getPrismContext(); PrismContainer extension = user.getExtension(); diff --git a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestFind.java b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestFind.java index 9d2466743ae..b4daf2b22c6 100644 --- a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestFind.java +++ b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestFind.java @@ -77,7 +77,7 @@ public void testFindPolyString() throws SchemaException, SAXException, IOExcepti PrismProperty nameProperty = findProperty(user, path); // THEN - assertEquals("Wrong property value (path="+path+")", PrismTestUtil.createPolyString(USER_JACK_POLYNAME_ORIG), nameProperty.getRealValue()); + PrismInternalTestUtil.asssertJackPolyName(nameProperty, user, true); assertTrue("QName found something other", nameProperty == (PrismProperty) user.findProperty(UserType.F_POLY_NAME)); } diff --git a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPrismParsing.java b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPrismParsing.java index 42b48064a1c..0a8b9e9d2e2 100644 --- a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPrismParsing.java +++ b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPrismParsing.java @@ -122,7 +122,7 @@ public void test120PrismParseFileObject() throws Exception { System.out.println(user.debugDump()); assertNotNull(user); - assertUserJack(user, true); + assertUserJack(user, true, false); } @Test @@ -149,7 +149,7 @@ public void test200RoundTrip() throws Exception { final String TEST_NAME = "test200RoundTrip"; PrismInternalTestUtil.displayTestTitle(TEST_NAME); - roundTrip(getFile(USER_JACK_FILE_BASENAME)); + roundTrip(getFile(USER_JACK_FILE_BASENAME), true); } @Test @@ -157,7 +157,7 @@ public void test210RoundTripNoNs() throws Exception { final String TEST_NAME = "test210RoundTripNoNs"; PrismInternalTestUtil.displayTestTitle(TEST_NAME); - roundTrip(getFile(USER_JACK_NO_NS_BASENAME)); + roundTrip(getFile(USER_JACK_NO_NS_BASENAME), true); } @Test @@ -165,11 +165,11 @@ public void test220RoundTripObject() throws Exception { final String TEST_NAME = "test220RoundTripObject"; PrismInternalTestUtil.displayTestTitle(TEST_NAME); - roundTrip(getFile(USER_JACK_OBJECT_BASENAME)); + roundTrip(getFile(USER_JACK_OBJECT_BASENAME), false); } - private void roundTrip(File file) throws SchemaException, SAXException, IOException { + private void roundTrip(File file, boolean expectFullPolyName) throws SchemaException, SAXException, IOException { // GIVEN PrismContext prismContext = constructInitializedPrismContext(); @@ -180,7 +180,7 @@ private void roundTrip(File file) throws SchemaException, SAXException, IOExcept assertNotNull(originalUser); // precondition - assertUserJack(originalUser, true); + assertUserJack(originalUser, true, expectFullPolyName); // WHEN // We need to serialize with composite objects during roundtrip, otherwise the result will not be equal @@ -199,7 +199,7 @@ private void roundTrip(File file) throws SchemaException, SAXException, IOExcept System.out.println(parsedUser.debugDump()); assertNotNull(parsedUser); - assertUserJack(parsedUser, true); + assertUserJack(parsedUser, true, expectFullPolyName); ObjectDelta diff = DiffUtil.diff(originalUser, parsedUser); System.out.println("Diff:"); @@ -412,7 +412,7 @@ public void test500UserElisabethRoundTrip() throws Exception { protected void assertUserAdhoc(PrismObject user, boolean expectRawInConstructions) throws SchemaException { user.checkConsistence(); - assertUserJackContent(user, expectRawInConstructions); + assertUserJackContent(user, expectRawInConstructions, true); assertUserExtensionAdhoc(user); assertVisitor(user, 58); } diff --git a/infra/prism-impl/src/test/resources/common/json/user-jack-adhoc.json b/infra/prism-impl/src/test/resources/common/json/user-jack-adhoc.json index caf45d9670d..c58d3546df0 100644 --- a/infra/prism-impl/src/test/resources/common/json/user-jack-adhoc.json +++ b/infra/prism-impl/src/test/resources/common/json/user-jack-adhoc.json @@ -16,7 +16,19 @@ "givenName" : "Jack", "familyName" : "Sparrow", "additionalNames" : [ "Captain", "Jackie" ], - "polyName" : "Džek Sperou", + "polyName" : { + "@ns" : "http://prism.evolveum.com/xml/ns/public/types-3", + "orig" : "Džek Sperou", + "norm" : "dzek sperou", + "translation" : { + "key" : "JACK", + "fallback" : "Jack", + "argument" : [ { + "value" : "Sparrow" + } + ] + } + }, "assignment" : [ { "id" : 1111, "description" : "Assignment 1" diff --git a/infra/prism-impl/src/test/resources/common/json/user-jack-modified.json b/infra/prism-impl/src/test/resources/common/json/user-jack-modified.json index a4391725434..13c72f35826 100644 --- a/infra/prism-impl/src/test/resources/common/json/user-jack-modified.json +++ b/infra/prism-impl/src/test/resources/common/json/user-jack-modified.json @@ -33,7 +33,19 @@ "givenName" : "Jack", "familyName" : "Sparrow", "additionalNames" : [ "Jackie" ], - "polyName" : "Džek Sperou", + "polyName" : { + "@ns" : "http://prism.evolveum.com/xml/ns/public/types-3", + "orig" : "Džek Sperou", + "norm" : "dzek sperou", + "translation" : { + "key" : "JACK", + "fallback" : "Jack", + "argument" : [ { + "value" : "Sparrow" + } + ] + } + }, "locality" : "World's End", "assignment" : [ { "id" : 1111, diff --git a/infra/prism-impl/src/test/resources/common/json/user-jack-no-ns.json b/infra/prism-impl/src/test/resources/common/json/user-jack-no-ns.json index ad2427d677a..8c8d989fe65 100644 --- a/infra/prism-impl/src/test/resources/common/json/user-jack-no-ns.json +++ b/infra/prism-impl/src/test/resources/common/json/user-jack-no-ns.json @@ -30,7 +30,18 @@ "givenName" : "Jack", "familyName" : "Sparrow", "additionalNames" : [ "Captain", "Jackie" ], - "polyName" : "Džek Sperou", + "polyName" : { + "orig" : "Džek Sperou", + "norm" : "dzek sperou", + "translation" : { + "key" : "JACK", + "fallback" : "Jack", + "argument" : [ { + "value" : "Sparrow" + } + ] + } + }, "assignment" : [ { "id" : 1111, "description" : "Assignment 1" diff --git a/infra/prism-impl/src/test/resources/common/json/user-jack.json b/infra/prism-impl/src/test/resources/common/json/user-jack.json index 9290c6066a8..30f0454c47d 100644 --- a/infra/prism-impl/src/test/resources/common/json/user-jack.json +++ b/infra/prism-impl/src/test/resources/common/json/user-jack.json @@ -33,7 +33,19 @@ "givenName" : "Jack", "familyName" : "Sparrow", "additionalNames" : [ "Captain", "Jackie" ], - "polyName" : "Džek Sperou", + "polyName" : { + "@ns" : "http://prism.evolveum.com/xml/ns/public/types-3", + "orig" : "Džek Sperou", + "norm" : "dzek sperou", + "translation" : { + "key" : "JACK", + "fallback" : "Jack", + "argument" : [ { + "value" : "Sparrow" + } + ] + } + }, "assignment" : [ { "id" : 1111, "description" : "Assignment 1" diff --git a/infra/prism-impl/src/test/resources/common/xml/user-jack-adhoc.xml b/infra/prism-impl/src/test/resources/common/xml/user-jack-adhoc.xml index f5c14516493..09524378505 100644 --- a/infra/prism-impl/src/test/resources/common/xml/user-jack-adhoc.xml +++ b/infra/prism-impl/src/test/resources/common/xml/user-jack-adhoc.xml @@ -39,6 +39,13 @@ Džek Sperou dzek sperou + + JACK + Jack + + Sparrow + + diff --git a/infra/prism-impl/src/test/resources/common/xml/user-jack-modified.xml b/infra/prism-impl/src/test/resources/common/xml/user-jack-modified.xml index ace6ddd2fcc..9181d85af22 100644 --- a/infra/prism-impl/src/test/resources/common/xml/user-jack-modified.xml +++ b/infra/prism-impl/src/test/resources/common/xml/user-jack-modified.xml @@ -43,6 +43,13 @@ Džek Sperou dzek sperou + + JACK + Jack + + Sparrow + + World's End diff --git a/infra/prism-impl/src/test/resources/common/xml/user-jack-no-ns.xml b/infra/prism-impl/src/test/resources/common/xml/user-jack-no-ns.xml index 4e967c0f7b5..9e87717398e 100644 --- a/infra/prism-impl/src/test/resources/common/xml/user-jack-no-ns.xml +++ b/infra/prism-impl/src/test/resources/common/xml/user-jack-no-ns.xml @@ -51,6 +51,13 @@ Džek Sperou dzek sperou + + JACK + Jack + + Sparrow + + diff --git a/infra/prism-impl/src/test/resources/common/xml/user-jack.xml b/infra/prism-impl/src/test/resources/common/xml/user-jack.xml index 4f83ff30026..7328d3e1aea 100644 --- a/infra/prism-impl/src/test/resources/common/xml/user-jack.xml +++ b/infra/prism-impl/src/test/resources/common/xml/user-jack.xml @@ -59,6 +59,13 @@ Džek Sperou dzek sperou + + JACK + Jack + + Sparrow + + diff --git a/infra/prism-impl/src/test/resources/common/yaml/user-jack-adhoc.yaml b/infra/prism-impl/src/test/resources/common/yaml/user-jack-adhoc.yaml index 40dd8e2879e..c5d496c9cd9 100644 --- a/infra/prism-impl/src/test/resources/common/yaml/user-jack-adhoc.yaml +++ b/infra/prism-impl/src/test/resources/common/yaml/user-jack-adhoc.yaml @@ -15,7 +15,15 @@ user: additionalNames: - "Captain" - "Jackie" - polyName: "Džek Sperou" + polyName: + '@ns': "http://prism.evolveum.com/xml/ns/public/types-3" + orig: "Džek Sperou" + norm: "dzek sperou" + translation: + key: "JACK" + fallback: "Jack" + argument: + - value: "Sparrow" assignment: - id: 1111 description: "Assignment 1" diff --git a/infra/prism-impl/src/test/resources/common/yaml/user-jack-modified.yaml b/infra/prism-impl/src/test/resources/common/yaml/user-jack-modified.yaml index 8f1db4572ac..075abcf820c 100644 --- a/infra/prism-impl/src/test/resources/common/yaml/user-jack-modified.yaml +++ b/infra/prism-impl/src/test/resources/common/yaml/user-jack-modified.yaml @@ -25,7 +25,15 @@ user: familyName: "Sparrow" additionalNames: - "Jackie" - polyName: "Džek Sperou" + polyName: + '@ns': "http://prism.evolveum.com/xml/ns/public/types-3" + orig: "Džek Sperou" + norm: "dzek sperou" + translation: + key: "JACK" + fallback: "Jack" + argument: + - value: "Sparrow" locality: "World's End" assignment: - id: 1111 diff --git a/infra/prism-impl/src/test/resources/common/yaml/user-jack-no-ns.yaml b/infra/prism-impl/src/test/resources/common/yaml/user-jack-no-ns.yaml index 6781d78d97b..fa1d628901a 100644 --- a/infra/prism-impl/src/test/resources/common/yaml/user-jack-no-ns.yaml +++ b/infra/prism-impl/src/test/resources/common/yaml/user-jack-no-ns.yaml @@ -23,7 +23,14 @@ user: additionalNames: - "Captain" - "Jackie" - polyName: "Džek Sperou" + polyName: + orig: "Džek Sperou" + norm: "dzek sperou" + translation: + key: "JACK" + fallback: "Jack" + argument: + - value: "Sparrow" assignment: - id: 1111 description: "Assignment 1" diff --git a/infra/prism-impl/src/test/resources/common/yaml/user-jack.yaml b/infra/prism-impl/src/test/resources/common/yaml/user-jack.yaml index 9264e724cf5..85138046f71 100644 --- a/infra/prism-impl/src/test/resources/common/yaml/user-jack.yaml +++ b/infra/prism-impl/src/test/resources/common/yaml/user-jack.yaml @@ -25,7 +25,15 @@ user: additionalNames: - "Captain" - "Jackie" - polyName: "Džek Sperou" + polyName: + '@ns': "http://prism.evolveum.com/xml/ns/public/types-3" + orig: "Džek Sperou" + norm: "dzek sperou" + translation: + key: "JACK" + fallback: "Jack" + argument: + - value: "Sparrow" assignment: - id: !int 1111 description: "Assignment 1"