use of io.jmix.ui.component.ValidationException in project jmix by jmix-framework.
the class DoubleValidator method validate.
@Override
public void validate(Object value) throws ValidationException {
if (value == null) {
return;
}
boolean result;
if (value instanceof String) {
try {
Datatype<Double> datatype = Datatypes.getNN(Double.class);
CurrentAuthentication currentAuthentication = AppBeans.get(CurrentAuthentication.class);
Double num = datatype.parse((String) value, currentAuthentication.getLocale());
result = checkDoubleOnPositive(num);
} catch (ParseException e) {
result = false;
}
} else {
result = (value instanceof Double && checkDoubleOnPositive((Double) value)) || (value instanceof BigDecimal && checkBigDecimalOnPositive((BigDecimal) value));
}
if (!result) {
String msg = message != null ? messageTools.loadString(messagesPack, message) : "Invalid value '%s'";
throw new ValidationException(String.format(msg, value));
}
}
use of io.jmix.ui.component.ValidationException in project jmix by jmix-framework.
the class CronValidator method validate.
@Override
public void validate(Object value) throws ValidationException {
if (value != null) {
ServerInfoService serverInfoService = AppBeans.get(ServerInfoService.NAME);
Messages messages = AppBeans.get("cuba_Messages");
try {
new CronSequenceGenerator(value.toString(), serverInfoService.getTimeZone());
} catch (Exception e) {
throw new ValidationException(messages.getMessage(CronValidator.class, "validation.cronInvalid"));
}
}
}
use of io.jmix.ui.component.ValidationException in project jmix by jmix-framework.
the class FutureOrPresentValidator method accept.
@Override
public void accept(T value) throws ValidationException {
// consider null value is valid
if (value == null) {
return;
}
TimeValidator timeConstraint = ValidatorHelper.getTimeConstraint(timeSource, value);
if (timeConstraint == null) {
throw new IllegalArgumentException("FutureOrPresentValidator doesn't support following type: '" + value.getClass() + "'");
}
timeConstraint.setCheckSeconds(checkSeconds);
if (!timeConstraint.isFutureOrPresent()) {
String message = getMessage();
if (message == null) {
message = messages.getMessage("validation.constraints.futureOrPresent");
}
throw new ValidationException(message);
}
}
use of io.jmix.ui.component.ValidationException in project jmix by jmix-framework.
the class FutureValidator method accept.
@Override
public void accept(T value) throws ValidationException {
// consider null value is valid
if (value == null) {
return;
}
TimeValidator timeConstraint = ValidatorHelper.getTimeConstraint(timeSource, value);
if (timeConstraint == null) {
throw new IllegalArgumentException("FutureValidator doesn't support following type: '" + value.getClass() + "'");
}
timeConstraint.setCheckSeconds(checkSeconds);
if (!timeConstraint.isFuture()) {
String message = getMessage();
if (message == null) {
message = messages.getMessage("validation.constraints.future");
}
throw new ValidationException(message);
}
}
use of io.jmix.ui.component.ValidationException in project jmix by jmix-framework.
the class MinValidator method accept.
@Override
public void accept(T value) throws ValidationException {
// consider null value is valid
if (value == null) {
return;
}
NumberConstraint constraint = getNumberConstraint(value);
if (constraint == null || value instanceof Double || value instanceof Float) {
throw new IllegalArgumentException("MinValidator doesn't support following type: '" + value.getClass() + "'");
}
if (!constraint.isMin(min)) {
String message = getMessage();
if (message == null) {
message = messages.getMessage("validation.constraints.min");
}
String formattedValue = formatValue(value);
String formattedMin = formatValue(min);
throw new ValidationException(getTemplateErrorMessage(message, ParamsMap.of("value", formattedValue, "min", formattedMin)));
}
}
Aggregations