Search in sources :

Example 6 with CustomCondition

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

the class RelatedEntitiesBean method getManyToManyCondition.

@Nullable
protected AbstractCondition getManyToManyCondition(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 parentEntityAlias = RandomStringUtils.randomAlphabetic(6);
    String entityAlias = RandomStringUtils.randomAlphabetic(6);
    String select = String.format("select %s.%s from %s %s ", entityAlias, relatedPrimaryKey, parentMetaClass, parentEntityAlias);
    String joinWhere = String.format("join %s.%s %s where %s.%s in :%s", parentEntityAlias, descriptor.getMetaProperty().getName(), entityAlias, parentEntityAlias, parentPrimaryKey, customCondition.getParam().getName());
    String whereString = String.format("{E}.%s in (%s)", relatedPrimaryKey, select + joinWhere);
    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 7 with CustomCondition

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

the class RelatedEntitiesBean method getOneToManyCondition.

@Nullable
protected AbstractCondition getOneToManyCondition(List<Object> parentIds, MetaClass metaClass, String filterComponentName, MetaDataDescriptor descriptor) {
    MetaProperty inverseField = descriptor.getMetaProperty().getInverse();
    if (inverseField == null) {
        return null;
    }
    MetaClass parentMetaClass = descriptor.getMetaClass();
    String parentPrimaryKey = metadataTools.getPrimaryKeyName(parentMetaClass);
    CustomCondition customCondition = getParentEntitiesCondition(parentIds, parentPrimaryKey, metaClass, filterComponentName, parentMetaClass);
    String whereString = String.format("{E}.%s.%s in :%s", inverseField.getName(), parentPrimaryKey, customCondition.getParam().getName());
    customCondition.setWhere(whereString);
    return customCondition;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) CustomCondition(com.haulmont.cuba.gui.components.filter.condition.CustomCondition) MetaProperty(com.haulmont.chile.core.model.MetaProperty) Nullable(javax.annotation.Nullable)

Example 8 with CustomCondition

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

the class RelatedEntitiesBean method getParentEntitiesCondition.

protected CustomCondition getParentEntitiesCondition(List<Object> parentIds, String parentPrimaryKey, CollectionDatasource datasource, String filterComponentName, MetaClass parentMetaClass) {
    String conditionName = String.format("related_%s", RandomStringUtils.randomAlphabetic(6));
    CustomCondition condition = new CustomCondition(getConditionXmlElement(conditionName, parentMetaClass), AppConfig.getMessagesPack(), filterComponentName, datasource);
    Class<?> parentPrimaryKeyClass = parentMetaClass.getPropertyNN(parentPrimaryKey).getJavaType();
    condition.setJavaClass(parentPrimaryKeyClass);
    condition.setHidden(true);
    condition.setInExpr(true);
    int randInt = new Random().nextInt((99999 - 11111) + 1) + 11111;
    String paramName = String.format("component$%s.%s%s", filterComponentName, conditionName, randInt);
    condition.setParam(getParentEntitiesParam(parentIds, parentPrimaryKey, datasource, parentPrimaryKeyClass, paramName, parentMetaClass));
    return condition;
}
Also used : CustomCondition(com.haulmont.cuba.gui.components.filter.condition.CustomCondition)

Example 9 with CustomCondition

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

the class RelatedEntitiesBean method getManyToManyCondition.

@Nullable
protected AbstractCondition getManyToManyCondition(List<Object> parentIds, CollectionDatasource datasource, String filterComponentName, String relatedPrimaryKey, MetaDataDescriptor descriptor) {
    MetaClass metaClass = descriptor.getMetaClass();
    String parentPrimaryKey = metadataTools.getPrimaryKeyName(metaClass);
    CustomCondition customCondition = getParentEntitiesCondition(parentIds, parentPrimaryKey, datasource, filterComponentName, metaClass);
    String parentEntityAlias = RandomStringUtils.randomAlphabetic(6);
    String entityAlias = RandomStringUtils.randomAlphabetic(6);
    String select = String.format("select %s.%s from %s %s ", entityAlias, relatedPrimaryKey, metaClass, parentEntityAlias);
    String joinWhere = String.format("join %s.%s %s where %s.%s in :%s", parentEntityAlias, descriptor.getMetaProperty().getName(), entityAlias, parentEntityAlias, parentPrimaryKey, customCondition.getParam().getName());
    String whereString = String.format("{E}.%s in (%s)", relatedPrimaryKey, select + joinWhere);
    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 10 with CustomCondition

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

the class RelatedEntitiesBean method getOneToManyCondition.

@Nullable
protected AbstractCondition getOneToManyCondition(List<Object> parentIds, CollectionDatasource datasource, String filterComponentName, MetaDataDescriptor descriptor) {
    MetaProperty inverseField = descriptor.getMetaProperty().getInverse();
    if (inverseField == null) {
        return null;
    }
    MetaClass metaClass = descriptor.getMetaClass();
    String parentPrimaryKey = metadataTools.getPrimaryKeyName(metaClass);
    CustomCondition customCondition = getParentEntitiesCondition(parentIds, parentPrimaryKey, datasource, filterComponentName, metaClass);
    String whereString = String.format("{E}.%s.%s in :%s", inverseField.getName(), parentPrimaryKey, customCondition.getParam().getName());
    customCondition.setWhere(whereString);
    return customCondition;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) CustomCondition(com.haulmont.cuba.gui.components.filter.condition.CustomCondition) MetaProperty(com.haulmont.chile.core.model.MetaProperty) Nullable(javax.annotation.Nullable)

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