use of com.haulmont.cuba.gui.components.filter.condition.PropertyCondition in project cuba by cuba-platform.
the class ParamWrapper method getValue.
@Override
public Object getValue() {
Object value = param.getValue();
if (value instanceof String && !StringUtils.isEmpty((String) value) && !((String) value).startsWith(ParametersHelper.CASE_INSENSITIVE_MARKER)) {
// try to wrap value for case-insensitive "like" search
if (condition instanceof PropertyCondition || condition instanceof DynamicAttributesCondition) {
String escapedValue = value.toString();
if (condition.getEntityMetaClass() != null) {
String thisStore = AppBeans.get(MetadataTools.class).getStoreName(condition.getEntityMetaClass());
GlobalConfig config = AppBeans.get(Configuration.class).getConfig(GlobalConfig.class);
if (config.getDisableEscapingLikeForDataStores() == null || !config.getDisableEscapingLikeForDataStores().contains(thisStore)) {
escapedValue = QueryUtils.escapeForLike(escapedValue);
}
} else {
escapedValue = QueryUtils.escapeForLike(escapedValue);
}
Op op = condition.getOperator();
if (Op.CONTAINS.equals(op) || op.equals(Op.DOES_NOT_CONTAIN)) {
value = wrapValueForLike(escapedValue);
} else if (Op.STARTS_WITH.equals(op)) {
value = wrapValueForLike(escapedValue, false, true);
} else if (Op.ENDS_WITH.equals(op)) {
value = wrapValueForLike(escapedValue, true, false);
}
} else if (condition instanceof CustomCondition) {
String where = ((CustomCondition) condition).getWhere();
Op op = condition.getOperator();
Matcher matcher = LIKE_PATTERN.matcher(where);
if (matcher.find()) {
String stringValue = value.toString();
boolean escape = StringUtils.isNotEmpty(matcher.group(3));
if (escape) {
String escapeChar = matcher.group(4);
if (StringUtils.isNotEmpty(escapeChar)) {
stringValue = QueryUtils.escapeForLike(stringValue, escapeChar);
}
}
if (Op.STARTS_WITH.equals(op)) {
value = wrapValueForLike(stringValue, false, true);
} else if (Op.ENDS_WITH.equals(op)) {
value = wrapValueForLike(stringValue, true, false);
} else {
value = wrapValueForLike(stringValue);
}
}
}
} else if (value instanceof Entity) {
value = ((Entity) value).getId();
} else if (value instanceof Collection) {
List<Object> list = new ArrayList<>(((Collection) value).size());
for (Object obj : ((Collection) value)) {
list.add(obj instanceof Entity ? ((Entity) obj).getId() : obj);
}
value = list;
} else if (value instanceof EnumClass) {
value = ((EnumClass) value).getId();
}
return value;
}
use of com.haulmont.cuba.gui.components.filter.condition.PropertyCondition in project cuba by cuba-platform.
the class RelatedEntitiesBean method getNonOptimizedCondition.
protected PropertyCondition getNonOptimizedCondition(MetaClass metaClass, List<Object> ids, Filter component, String filterComponentName, String primaryKey) {
PropertyConditionDescriptor conditionDescriptor = new PropertyConditionDescriptor(primaryKey, primaryKey, AppConfig.getMessagesPack(), filterComponentName, ((FilterImplementation) component).getEntityMetaClass(), ((FilterImplementation) component).getEntityAlias());
PropertyCondition condition = (PropertyCondition) conditionDescriptor.createCondition();
condition.setInExpr(true);
condition.setHidden(true);
condition.setOperator(Op.IN);
@SuppressWarnings("ConstantConditions") Class idType = metaClass.getProperty(primaryKey).getJavaType();
Param param = Param.Builder.getInstance().setName(paramBuilder.createParamName(condition)).setJavaClass(idType).setEntityWhere("").setEntityView("").setMetaClass(((FilterImplementation) component).getEntityMetaClass()).setProperty(metaClass.getProperty(primaryKey)).setInExpr(true).setRequired(true).build();
param.setValue(ids);
condition.setParam(param);
return condition;
}
use of com.haulmont.cuba.gui.components.filter.condition.PropertyCondition in project cuba by cuba-platform.
the class PropertyConditionDescriptor method createCondition.
@Override
public AbstractCondition createCondition() {
OpManager opManager = AppBeans.get(OpManager.class);
MetadataTools metadataTools = AppBeans.get(MetadataTools.class);
PropertyCondition propertyCondition = new PropertyCondition(this, entityAlias, propertiesPath);
MetaPropertyPath propertyPath = datasourceMetaClass.getPropertyPath(name);
if (propertyPath == null) {
throw new IllegalStateException(String.format("Unable to find property '%s' in entity %s", name, datasourceMetaClass));
}
MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(propertyPath);
EnumSet<Op> ops = opManager.availableOps(propertyMetaClass, propertyPath.getMetaProperty());
propertyCondition.setOperator(ops.iterator().next());
return propertyCondition;
}
Aggregations