Search in sources :

Example 1 with CurrentAuthentication

use of io.jmix.core.security.CurrentAuthentication in project jmix by jmix-framework.

the class TimeZoneIndicatorImpl method setApplicationContext.

@Autowired
public void setApplicationContext(ApplicationContext applicationContext) {
    super.setApplicationContext(applicationContext);
    CurrentAuthentication currentAuthentication = applicationContext.getBean(CurrentAuthentication.class);
    TimeZone timeZone = currentAuthentication.getTimeZone();
    TimeZoneIndicatorSupport timeZoneSupport = applicationContext.getBean(TimeZoneIndicatorSupport.class);
    component.setValue(timeZoneSupport.getDisplayNameShort(timeZone));
}
Also used : TimeZone(java.util.TimeZone) CurrentAuthentication(io.jmix.core.security.CurrentAuthentication) TimeZoneIndicatorSupport(io.jmix.ui.component.mainwindow.TimeZoneIndicatorSupport) Autowired(org.springframework.beans.factory.annotation.Autowired)

Example 2 with CurrentAuthentication

use of io.jmix.core.security.CurrentAuthentication in project jmix by jmix-framework.

the class IntegerValidator method validate.

@Override
public void validate(Object value) throws ValidationException {
    if (value == null) {
        return;
    }
    boolean result;
    if (value instanceof String) {
        try {
            Datatype<Integer> datatype = Datatypes.getNN(Integer.class);
            CurrentAuthentication currentAuthentication = AppBeans.get(CurrentAuthentication.class);
            Integer num = datatype.parse((String) value, currentAuthentication.getLocale());
            result = checkIntegerOnPositive(num);
        } catch (ParseException e) {
            result = false;
        }
    } else {
        result = value instanceof Integer && checkIntegerOnPositive((Integer) value);
    }
    if (!result) {
        String msg = message != null ? messageTools.loadString(messagesPack, message) : "Invalid value '%s'";
        throw new ValidationException(String.format(msg, value));
    }
}
Also used : CurrentAuthentication(io.jmix.core.security.CurrentAuthentication) ValidationException(io.jmix.ui.component.ValidationException) ParseException(java.text.ParseException)

Example 3 with CurrentAuthentication

use of io.jmix.core.security.CurrentAuthentication in project jmix by jmix-framework.

the class LongValidator method validate.

@Override
public void validate(Object value) throws ValidationException {
    if (value == null) {
        return;
    }
    boolean result;
    if (value instanceof String) {
        try {
            Datatype<Long> datatype = Datatypes.getNN(Long.class);
            CurrentAuthentication currentAuthentication = AppBeans.get(CurrentAuthentication.class);
            Long num = datatype.parse((String) value, currentAuthentication.getLocale());
            result = checkPositive(num);
        } catch (ParseException e) {
            result = false;
        }
    } else {
        result = value instanceof Long && checkPositive((Long) value);
    }
    if (!result) {
        String msg = message != null ? messageTools.loadString(messagesPack, message) : "Invalid value '%s'";
        throw new ValidationException(String.format(msg, value));
    }
}
Also used : CurrentAuthentication(io.jmix.core.security.CurrentAuthentication) ValidationException(io.jmix.ui.component.ValidationException) ParseException(java.text.ParseException)

Example 4 with CurrentAuthentication

use of io.jmix.core.security.CurrentAuthentication in project jmix by jmix-framework.

the class DateValidator method validate.

@Override
public void validate(Object value) throws ValidationException {
    if (value == null)
        return;
    boolean result;
    if (value instanceof String) {
        try {
            Datatype datatype = Datatypes.getNN(java.sql.Date.class);
            CurrentAuthentication currentAuthentication = AppBeans.get(CurrentAuthentication.class);
            datatype.parse((String) value, currentAuthentication.getLocale());
            result = true;
        } catch (ParseException e) {
            result = false;
        }
    } else {
        result = value instanceof Date;
    }
    if (!result) {
        String msg = message != null ? messageTools.loadString(messagesPack, message) : "Invalid value '%s'";
        throw new ValidationException(String.format(msg, value));
    }
}
Also used : CurrentAuthentication(io.jmix.core.security.CurrentAuthentication) ValidationException(io.jmix.ui.component.ValidationException) ParseException(java.text.ParseException) Date(java.util.Date) Datatype(io.jmix.core.metamodel.datatype.Datatype)

Example 5 with CurrentAuthentication

use of io.jmix.core.security.CurrentAuthentication 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));
    }
}
Also used : CurrentAuthentication(io.jmix.core.security.CurrentAuthentication) ValidationException(io.jmix.ui.component.ValidationException) ParseException(java.text.ParseException) BigDecimal(java.math.BigDecimal)

Aggregations

CurrentAuthentication (io.jmix.core.security.CurrentAuthentication)10 ValidationException (io.jmix.ui.component.ValidationException)4 ParseException (java.text.ParseException)4 DatatypeRegistry (io.jmix.core.metamodel.datatype.DatatypeRegistry)2 FormatStringsRegistry (io.jmix.core.metamodel.datatype.FormatStringsRegistry)2 Messages (io.jmix.core.Messages)1 Datatype (io.jmix.core.metamodel.datatype.Datatype)1 AppUI (io.jmix.ui.AppUI)1 TimeZoneIndicatorSupport (io.jmix.ui.component.mainwindow.TimeZoneIndicatorSupport)1 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1 TimeZone (java.util.TimeZone)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1