diff --git a/modules/client/src/com/haulmont/cuba/client/ClientConfig.java b/modules/client/src/com/haulmont/cuba/client/ClientConfig.java index 700bbbdc8b..c69f459c22 100644 --- a/modules/client/src/com/haulmont/cuba/client/ClientConfig.java +++ b/modules/client/src/com/haulmont/cuba/client/ClientConfig.java @@ -17,6 +17,7 @@ import com.haulmont.cuba.core.config.type.CommaSeparatedStringListTypeFactory; import com.haulmont.cuba.core.config.type.Factory; import java.util.List; +import java.util.regex.Pattern; /** * Configuration parameters interface used by the WEB and DESKTOP layers. @@ -50,6 +51,12 @@ public interface ClientConfig extends Config { int getMaxUploadSizeMb(); void setMaxUploadSizeMb(int value); + + @Factory(factory = UniqueConstraintViolationPatternFactory.class) + @Source(type = SourceType.DATABASE) + @Property("cuba.uniqueConstraintViolationPattern") + Pattern getUniqueConstraintViolationPattern(); + /** * @return Whether to enable sorting of datasource data on DB (using separate SELECT with ORDER BY clause). */ diff --git a/modules/global/src/com/haulmont/cuba/core/global/UniqueConstraintViolationPatternFactory.java b/modules/client/src/com/haulmont/cuba/client/UniqueConstraintViolationPatternFactory.java similarity index 89% rename from modules/global/src/com/haulmont/cuba/core/global/UniqueConstraintViolationPatternFactory.java rename to modules/client/src/com/haulmont/cuba/client/UniqueConstraintViolationPatternFactory.java index 5d367dbd11..8b072ea890 100644 --- a/modules/global/src/com/haulmont/cuba/core/global/UniqueConstraintViolationPatternFactory.java +++ b/modules/client/src/com/haulmont/cuba/client/UniqueConstraintViolationPatternFactory.java @@ -1,45 +1,47 @@ -/* - * Copyright (c) 2008-2014 Haulmont. All rights reserved. - * Use is subject to license terms, see http://www.cuba-platform.com/license for details. - */ - -package com.haulmont.cuba.core.global; - -import com.haulmont.cuba.core.app.PersistenceManagerService; -import com.haulmont.cuba.core.config.type.TypeFactory; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; - -/** - * @author zlatoverov - * @version $Id$ - */ -public class UniqueConstraintViolationPatternFactory extends TypeFactory { - - @Override - public Object build(String value) { - Messages messages = AppBeans.get(Messages.NAME); - Logger log = LoggerFactory.getLogger(getClass()); - PersistenceManagerService pmService = AppBeans.get(PersistenceManagerService.NAME); - String defaultConstraintViolationPattern = pmService.getUniqueConstraintViolationPattern(); - Pattern constraintViolationPattern; - - if (StringUtils.isBlank(value)) { - constraintViolationPattern = Pattern.compile(defaultConstraintViolationPattern); - } else { - try { - constraintViolationPattern = Pattern.compile(value); - } catch (PatternSyntaxException e) { - constraintViolationPattern = Pattern.compile(defaultConstraintViolationPattern); - log.warn(String.format(messages.getMainMessage("incorrectRegexp"), - "cuba.uniqueConstraintViolationPattern"), e); - } - } - - return constraintViolationPattern; - } -} +/* + * Copyright (c) 2008-2016 Haulmont. All rights reserved. + * Use is subject to license terms, see http://www.cuba-platform.com/license for details. + */ + +package com.haulmont.cuba.client; + +import com.haulmont.cuba.core.app.PersistenceManagerService; +import com.haulmont.cuba.core.config.type.TypeFactory; +import com.haulmont.cuba.core.global.AppBeans; +import com.haulmont.cuba.core.global.Messages; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +/** + * @author zlatoverov + * @version $Id$ + */ +public class UniqueConstraintViolationPatternFactory extends TypeFactory { + + @Override + public Object build(String value) { + Messages messages = AppBeans.get(Messages.NAME); + Logger log = LoggerFactory.getLogger(getClass()); + PersistenceManagerService pmService = AppBeans.get(PersistenceManagerService.NAME); + String defaultConstraintViolationPattern = pmService.getUniqueConstraintViolationPattern(); + Pattern constraintViolationPattern; + + if (StringUtils.isBlank(value)) { + constraintViolationPattern = Pattern.compile(defaultConstraintViolationPattern); + } else { + try { + constraintViolationPattern = Pattern.compile(value); + } catch (PatternSyntaxException e) { + constraintViolationPattern = Pattern.compile(defaultConstraintViolationPattern); + log.warn(String.format(messages.getMainMessage("incorrectRegexp"), + "cuba.uniqueConstraintViolationPattern"), e); + } + } + + return constraintViolationPattern; + } +} diff --git a/modules/global/src/com/haulmont/cuba/core/global/ExceptionHandlersConfig.java b/modules/global/src/com/haulmont/cuba/core/global/ExceptionHandlersConfig.java deleted file mode 100644 index 55a8e4169c..0000000000 --- a/modules/global/src/com/haulmont/cuba/core/global/ExceptionHandlersConfig.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2008-2014 Haulmont. All rights reserved. - * Use is subject to license terms, see http://www.cuba-platform.com/license for details. - */ - -package com.haulmont.cuba.core.global; - -import com.haulmont.cuba.core.config.Config; -import com.haulmont.cuba.core.config.Property; -import com.haulmont.cuba.core.config.Source; -import com.haulmont.cuba.core.config.SourceType; -import com.haulmont.cuba.core.config.type.Factory; - -import java.util.regex.Pattern; - -/** - * @author zlatoverov - * @version $Id$ - */ -@Source(type = SourceType.DATABASE) -public interface ExceptionHandlersConfig extends Config { - - @Factory(factory = UniqueConstraintViolationPatternFactory.class) - @Property("cuba.uniqueConstraintViolationPattern") - Pattern getUniqueConstraintViolationPattern(); - -} \ No newline at end of file diff --git a/modules/gui/src/com/haulmont/cuba/gui/exception/UniqueConstraintViolationHandler.java b/modules/gui/src/com/haulmont/cuba/gui/exception/UniqueConstraintViolationHandler.java index 0f6d04d8f2..64244fdfaf 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/exception/UniqueConstraintViolationHandler.java +++ b/modules/gui/src/com/haulmont/cuba/gui/exception/UniqueConstraintViolationHandler.java @@ -5,7 +5,7 @@ package com.haulmont.cuba.gui.exception; -import com.haulmont.cuba.core.global.ExceptionHandlersConfig; +import com.haulmont.cuba.client.ClientConfig; import com.haulmont.cuba.core.global.Messages; import com.haulmont.cuba.gui.WindowManager; import com.haulmont.cuba.gui.components.Frame; @@ -31,7 +31,7 @@ public class UniqueConstraintViolationHandler implements GenericExceptionHandler protected Messages messages; @Inject - protected ExceptionHandlersConfig exceptionHandlersConfig; + protected ClientConfig clientConfig; @Override public boolean handle(Throwable exception, WindowManager windowManager) { @@ -50,7 +50,7 @@ public class UniqueConstraintViolationHandler implements GenericExceptionHandler } protected boolean doHandle(Throwable throwable, WindowManager windowManager) { - Pattern pattern = exceptionHandlersConfig.getUniqueConstraintViolationPattern(); + Pattern pattern = clientConfig.getUniqueConstraintViolationPattern(); String constraintName = ""; Matcher matcher = pattern.matcher(throwable.toString());