Skip to content

Commit

Permalink
MID-3362 better translations for raw values in expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Nov 21, 2022
1 parent e151c09 commit eef4be0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,16 @@ private static LocalizableMessage createExpressionEvaluatorArg(JAXBElement<?> ev
if (QNameUtil.match(SchemaConstants.C_VALUE, evaluator.getName()) && evaluator.getValue() instanceof RawType) {
RawType raw = (RawType) evaluator.getValue();
try {
String fallback = raw.extractString("(a complex value)");
try {
msg = toStringValue(raw.getValue());
} catch (SchemaException ex) {
// intentionally ignore
msg = createMessage(fallback, fallback);
}

String rawString = raw.extractString("(a complex value)");
sb.append(rawString);
msg = createMessage(rawString, rawString);
} catch (RuntimeException e) {
String invalid = "(an invalid value)";
sb.append(invalid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
import java.util.Locale;
import javax.xml.datatype.XMLGregorianCalendar;

import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.SingleLocalizableMessage;

import com.evolveum.prism.xml.ns._public.types_3.RawType;

import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.testng.AssertJUnit;
Expand Down Expand Up @@ -54,6 +57,11 @@ public void test010DisplayConstruction() {

@Test
public void test020ResourceAttributeDefinitionType() {
final Date date = new Date();

DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
final String formattedDate = df.format(date);

ResourceAttributeDefinitionType def = new ResourceAttributeDefinitionType();
def.ref(new ItemPathType(ItemPath.create(UserType.F_ASSIGNMENT)));
def.outbound(new MappingType()
Expand All @@ -63,6 +71,11 @@ public void test020ResourceAttributeDefinitionType() {
.expressionEvaluator(new ObjectFactory().createScript(new ScriptExpressionEvaluatorType()
.code("some code here")))
.expressionEvaluator(new ObjectFactory().createAsIs(new AsIsExpressionEvaluatorType()))
.expressionEvaluator(new ObjectFactory().createValue(
new RawType(new PrismPropertyValueImpl<>(
XmlTypeConverter.createXMLGregorianCalendar(date)), DOMUtil.XSD_DATETIME, prismContext)
))
.expressionEvaluator(new ObjectFactory().createValue(new byte[] { 1, 2, 3 }))
)
);

Expand All @@ -71,7 +84,7 @@ public void test020ResourceAttributeDefinitionType() {
LocalizableMessage msg = ValueDisplayUtil.toStringValue(ppv);

String value = localizationService.translate(msg);
AssertJUnit.assertEquals("assignment = (a complex expression), (a complex expression)", value);
AssertJUnit.assertEquals("assignment = (a complex expression), (a complex expression), " + formattedDate + ", (a complex expression)", value);
}

@Test
Expand Down

0 comments on commit eef4be0

Please sign in to comment.