Skip to content

Instantly share code, notes, and snippets.

@nguyen-thom
Created March 23, 2018 03:34
Show Gist options
  • Save nguyen-thom/c7b4303ebe9c35b587065ff91c75bf23 to your computer and use it in GitHub Desktop.
Save nguyen-thom/c7b4303ebe9c35b587065ff91c75bf23 to your computer and use it in GitHub Desktop.
message converter
public class MessageConverter {
public static List<String> convertMessageError(
final CodeLookupManager codeLookupManager,
List<ValidationFailure> failureList) {
List<String> messageErrors = new ArrayList<>();
if (failureList != null) {
String message = "Unknown error: field=[#fieldName], type=[#errorType], value=[#fieldValue]";
for (ValidationFailure thisError : failureList) {
message = codeLookupManager.lookupValue(
"errorCustom",
thisError.getName().concat("_")
.concat(thisError.getType()));
if (StringUtils.isEmpty(message)) {
message = codeLookupManager.lookupValue("errorTemplates",
thisError.getType());
}
String label = codeLookupManager.lookupValue("errorLabels",
thisError.getName());
if (StringUtils.isEmpty(label)) {
label = thisError.getName();
}
String errorMessage = message.replace("[#fieldName]", label);
errorMessage = errorMessage.replace("[#errorType]",
thisError.getType());
errorMessage = errorMessage.replace("[#fieldValue]", thisError
.getValue().toString());
errorMessage = errorMessage.replace("[#extraInfo]",
thisError.getExtraInfo()[0]);
messageErrors.add(errorMessage);
}
}
return messageErrors;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment