Created
March 23, 2018 03:34
-
-
Save nguyen-thom/c7b4303ebe9c35b587065ff91c75bf23 to your computer and use it in GitHub Desktop.
message converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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