use of org.rx.bean.Tuple in project rxlib by RockyLOMO.
the class SystemException method setFriendlyMessage.
private void setFriendlyMessage(Map<String, Object> methodSettings, String messageName, ErrorCode errorCode, Object[] messageValues) {
if (!App.isNullOrEmpty(errorCode.value())) {
messageName += "[" + errorCode.value() + "]";
}
if (!Exception.class.equals(errorCode.cause())) {
messageName += "<" + errorCode.cause().getSimpleName() + ">";
}
String msg = as(methodSettings.get(messageName), String.class);
if (msg == null) {
Logger.debug("SystemException: Not found messageName %s", messageName);
return;
}
switch(errorCode.messageFormatter()) {
case StringFormat:
msg = String.format(msg, messageValues);
break;
case MessageFormat:
msg = MessageFormat.format(msg, messageValues);
break;
default:
String[] messageKeys = errorCode.messageKeys();
if (messageKeys.length != messageValues.length) {
Logger.debug("SystemException: MessageKeys length %s not equals messageValues length %s", messageKeys.length, messageValues.length);
return;
}
NQuery<Tuple<String, Object>> query = NQuery.of(messageKeys).select((p, i) -> Tuple.of(p, messageValues[i]));
if (data != null) {
query = query.union(NQuery.of(data.entrySet()).select(p -> Tuple.of(p.getKey(), p.getValue())).toList());
}
StringBuilder temp = new StringBuilder().append(msg);
for (Tuple<String, Object> tuple : query.orderByDescending(p -> p.left.length())) {
temp.replace(tuple.left, toJsonString(tuple.right));
}
msg = temp.toString();
break;
}
friendlyMessage = msg;
}
Aggregations