Example usage for org.springframework.dao DuplicateKeyException getCause

List of usage examples for org.springframework.dao DuplicateKeyException getCause

Introduction

In this page you can find the example usage for org.springframework.dao DuplicateKeyException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.jutge.joc.porra.service.AccountService.java

@SuppressWarnings({ "rawtypes", "unchecked" })
private void handleDuplicatekeyException(final DuplicateKeyException exception) throws SignupException {
    final Throwable cause = exception.getCause();
    if (cause instanceof MongoException) {
        final Locale locale = LocaleContextHolder.getLocale();
        final MongoException mongoException = (MongoException) cause;
        final String exceptionMessage = mongoException.getMessage();
        List errorMessages = new ArrayList();
        if (exceptionMessage.indexOf("account.$_id_") != -1) {
            final String message = this.messageSource.getMessage("exception.accountNameTaken", null, locale);
            final MessageBox messageBox = new MessageBox("accountNameTaken", message, new ArrayList<String>());
            errorMessages.add(messageBox);
        } else if (exceptionMessage.indexOf("account.$email") != -1) {
            final String message = this.messageSource.getMessage("exception.accountEmailTaken", null, locale);
            final MessageBox messageBox = new MessageBox("accountEmailTaken", message, new ArrayList<String>());
            errorMessages.add(messageBox);
        }// ww w .ja v  a 2s  . c  o  m
        throw new SignupException(errorMessages);
    } else {
        this.logger.error(exception.getMessage());
    }
}