use of com.haulmont.cuba.core.global.UserSessionSource in project cuba by cuba-platform.
the class FilterConditionUtils method formatParamValue.
public static String formatParamValue(Param param, Object value) {
// noinspection unchecked
Datatype datatype = Datatypes.get(param.getJavaClass());
MetaProperty property = param.getProperty();
if (property != null) {
TemporalType tt = (TemporalType) property.getAnnotations().get(MetadataTools.TEMPORAL_ANN_NAME);
if (tt == TemporalType.DATE) {
datatype = Datatypes.getNN(java.sql.Date.class);
}
}
if (datatype != null) {
UserSessionSource userSessionSource = AppBeans.get(UserSessionSource.class);
return datatype.format(value, userSessionSource.getLocale());
}
return value.toString();
}
use of com.haulmont.cuba.core.global.UserSessionSource in project cuba by cuba-platform.
the class DoubleValidator method validate.
@Override
public void validate(Object value) throws ValidationException {
boolean result;
if (value instanceof String) {
try {
Datatype<Double> datatype = Datatypes.getNN(Double.class);
UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
Double num = datatype.parse((String) value, sessionSource.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 ? messages.getTools().loadString(messagesPack, message) : "Invalid value '%s'";
throw new ValidationException(String.format(msg, value));
}
}
use of com.haulmont.cuba.core.global.UserSessionSource in project cuba by cuba-platform.
the class IntegerValidator method validate.
@Override
public void validate(Object value) throws ValidationException {
boolean result;
if (value instanceof String) {
try {
Datatype<Integer> datatype = Datatypes.getNN(Integer.class);
UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
Integer num = datatype.parse((String) value, sessionSource.getLocale());
result = checkIntegerOnPositive(num);
} catch (ParseException e) {
result = false;
}
} else {
result = value instanceof Integer && checkIntegerOnPositive((Integer) value);
}
if (!result) {
String msg = message != null ? messages.getTools().loadString(messagesPack, message) : "Invalid value '%s'";
throw new ValidationException(String.format(msg, value));
}
}
use of com.haulmont.cuba.core.global.UserSessionSource in project cuba by cuba-platform.
the class LongValidator method validate.
@Override
public void validate(Object value) throws ValidationException {
boolean result;
if (value instanceof String) {
try {
Datatype<Long> datatype = Datatypes.getNN(Long.class);
UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
Long num = datatype.parse((String) value, sessionSource.getLocale());
result = checkPositive(num);
} catch (ParseException e) {
result = false;
}
} else {
result = value instanceof Long && checkPositive((Long) value);
}
if (!result) {
String msg = message != null ? messages.getTools().loadString(messagesPack, message) : "Invalid value '%s'";
throw new ValidationException(String.format(msg, value));
}
}
use of com.haulmont.cuba.core.global.UserSessionSource in project cuba by cuba-platform.
the class AggregatableDelegate method doAggregation.
protected Map<AggregationInfo, String> doAggregation(Collection<K> itemIds, AggregationInfo[] aggregationInfos) {
final Map<AggregationInfo, String> aggregationResults = new HashMap<>();
for (AggregationInfo aggregationInfo : aggregationInfos) {
final Object value = doPropertyAggregation(aggregationInfo, itemIds);
String formattedValue;
if (aggregationInfo.getFormatter() != null) {
// noinspection unchecked
formattedValue = aggregationInfo.getFormatter().format(value);
} else {
MetaPropertyPath propertyPath = aggregationInfo.getPropertyPath();
final Range range = propertyPath.getRange();
if (range.isDatatype()) {
if (aggregationInfo.getType() != AggregationInfo.Type.COUNT) {
Class resultClass;
if (aggregationInfo.getStrategy() == null) {
Class rangeJavaClass = propertyPath.getRangeJavaClass();
Aggregation aggregation = Aggregations.get(rangeJavaClass);
resultClass = aggregation.getResultClass();
} else {
resultClass = aggregationInfo.getStrategy().getResultClass();
}
UserSessionSource userSessionSource = AppBeans.get(UserSessionSource.NAME);
Locale locale = userSessionSource.getLocale();
formattedValue = Datatypes.getNN(resultClass).format(value, locale);
} else {
formattedValue = value.toString();
}
} else {
if (aggregationInfo.getStrategy() != null) {
Class resultClass = aggregationInfo.getStrategy().getResultClass();
UserSessionSource userSessionSource = AppBeans.get(UserSessionSource.NAME);
Locale locale = userSessionSource.getLocale();
formattedValue = Datatypes.getNN(resultClass).format(value, locale);
} else {
formattedValue = value.toString();
}
}
}
aggregationResults.put(aggregationInfo, formattedValue);
}
return aggregationResults;
}
Aggregations