mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-04 20:28:00 +08:00
PL-6812 Move cuba.uniqueConstraintViolationPattern to ClientConfig interface
This commit is contained in:
parent
dec5a474ef
commit
a605d82796
@ -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).
|
||||
*/
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
||||
}
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user