Search in sources :

Example 11 with CustomCondition

use of com.haulmont.cuba.gui.components.filter.condition.CustomCondition in project cuba by cuba-platform.

the class RelatedEntitiesBean method getManyToOneCondition.

@Nullable
protected AbstractCondition getManyToOneCondition(List<Object> parentIds, MetaClass metaClass, String filterComponentName, String relatedPrimaryKey, MetaDataDescriptor descriptor) {
    MetaClass parentMetaClass = descriptor.getMetaClass();
    String parentPrimaryKey = metadataTools.getPrimaryKeyName(parentMetaClass);
    CustomCondition customCondition = getParentEntitiesCondition(parentIds, parentPrimaryKey, metaClass, filterComponentName, parentMetaClass);
    String entityAlias = RandomStringUtils.randomAlphabetic(6);
    String subQuery = String.format("select %s.%s.%s from %s %s where %s.%s in :%s", entityAlias, descriptor.getMetaProperty().getName(), relatedPrimaryKey, parentMetaClass.getName(), entityAlias, entityAlias, parentPrimaryKey, customCondition.getParam().getName());
    String whereString = String.format("{E}.%s in (%s)", relatedPrimaryKey, subQuery);
    customCondition.setWhere(whereString);
    return customCondition;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) CustomCondition(com.haulmont.cuba.gui.components.filter.condition.CustomCondition) Nullable(javax.annotation.Nullable)

Example 12 with CustomCondition

use of com.haulmont.cuba.gui.components.filter.condition.CustomCondition in project cuba by cuba-platform.

the class FilteringLookupAction method createCustomCondition.

protected CustomCondition createCustomCondition(Filter filterComponent) {
    CustomCondition condition = new CustomCondition(createConditionXmlElement(), AppConfig.getMessagesPack(), getFilterComponentName(filterComponent), ((FilterImplementation) filterComponent).getEntityMetaClass());
    condition.setUnary(true);
    condition.setHidden(true);
    condition.setWhere(whereClause.replaceAll("\\?", ":" + condition.getParamName()));
    condition.setJoin(joinClause);
    ConditionParamBuilder paramBuilder = AppBeans.get(ConditionParamBuilder.class);
    Param param = Param.Builder.getInstance().setName(paramBuilder.createParamName(condition)).setJavaClass(Boolean.class).setEntityWhere("").setEntityView("").setMetaClass(((FilterImplementation) filterComponent).getEntityMetaClass()).setInExpr(true).setRequired(true).build();
    param.setValue(true);
    condition.setParam(param);
    return condition;
}
Also used : ConditionParamBuilder(com.haulmont.cuba.gui.components.filter.ConditionParamBuilder) CustomCondition(com.haulmont.cuba.gui.components.filter.condition.CustomCondition) Param(com.haulmont.cuba.gui.components.filter.Param)

Aggregations

CustomCondition (com.haulmont.cuba.gui.components.filter.condition.CustomCondition)12 MetaClass (com.haulmont.chile.core.model.MetaClass)6 Nullable (javax.annotation.Nullable)6 MetaProperty (com.haulmont.chile.core.model.MetaProperty)2 ConditionParamBuilder (com.haulmont.cuba.gui.components.filter.ConditionParamBuilder)2 Param (com.haulmont.cuba.gui.components.filter.Param)2 Node (com.haulmont.bali.datastruct.Node)1 EnumClass (com.haulmont.chile.core.datatypes.impl.EnumClass)1 Entity (com.haulmont.cuba.core.entity.Entity)1 Op (com.haulmont.cuba.core.global.filter.Op)1 ConditionsTree (com.haulmont.cuba.gui.components.filter.ConditionsTree)1 FilterParser (com.haulmont.cuba.gui.components.filter.FilterParser)1 DynamicAttributesCondition (com.haulmont.cuba.gui.components.filter.condition.DynamicAttributesCondition)1 PropertyCondition (com.haulmont.cuba.gui.components.filter.condition.PropertyCondition)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Matcher (java.util.regex.Matcher)1