Search in sources :

Example 1 with CubaProperties

use of com.haulmont.cuba.CubaProperties in project jmix by jmix-framework.

the class AppFolderEditWindow method create.

public static FolderEditWindow create(boolean isAppFolder, boolean adding, Folder folder, TablePresentations presentations, Runnable commitHandler) {
    CubaProperties cubaProperties = AppBeans.get(CubaProperties.class);
    String className = isAppFolder ? cubaProperties.getAppFolderEditWindowClassName() : cubaProperties.getFolderEditWindowClassName();
    if (className != null || !isAppFolder) {
        return new FolderEditWindow(adding, folder, presentations, commitHandler);
    } else {
        return new AppFolderEditWindow(adding, (AppFolder) folder, presentations, commitHandler);
    }
}
Also used : CubaProperties(com.haulmont.cuba.CubaProperties)

Example 2 with CubaProperties

use of com.haulmont.cuba.CubaProperties in project jmix by jmix-framework.

the class PropertyCondition method updateText.

@Override
protected void updateText() {
    Metadata metadata = AppBeans.get(Metadata.class);
    MetadataTools metadataTools = metadata.getTools();
    String nameToUse = !Strings.isNullOrEmpty(propertiesPath) ? propertiesPath : name;
    boolean useCrossDataStoreRefId = false;
    boolean stringType = false;
    String thisStore = metaClass.getStore().getName();
    MetaPropertyPath propertyPath = metaClass.getPropertyPath(name);
    if (propertyPath != null) {
        MetaProperty metaProperty = propertyPath.getMetaProperty();
        String refIdProperty = metadataTools.getCrossDataStoreReferenceIdProperty(thisStore, propertyPath.getMetaProperty());
        if (refIdProperty != null) {
            useCrossDataStoreRefId = true;
            int lastdDot = nameToUse.lastIndexOf('.');
            if (lastdDot == -1) {
                nameToUse = refIdProperty;
            } else {
                nameToUse = nameToUse.substring(0, lastdDot + 1) + refIdProperty;
            }
        }
        stringType = String.class.equals(metaProperty.getJavaType());
    }
    if (operator == Op.DATE_INTERVAL) {
        text = dateIntervalConditionToJpql(nameToUse);
        return;
    }
    StringBuilder sb = new StringBuilder();
    StringBuilder sbJoin = new StringBuilder();
    if (operator == Op.NOT_IN) {
        sb.append("((");
    }
    String path = (metaClass instanceof KeyValueMetaClass && Strings.isNullOrEmpty(propertiesPath)) ? entityAlias : entityAlias + "." + nameToUse;
    String joinAlias = nameToUse.replace(".", "_") + RandomStringUtils.randomAlphabetic(5);
    if (Param.Type.ENTITY == param.getType() && !useCrossDataStoreRefId) {
        String primaryKeyName = metadataTools.getPrimaryKeyName(metadata.getClassNN(param.getJavaClass()));
        if (operator == Op.NOT_IN) {
            sbJoin.append("left join ").append(path).append(" ").append(joinAlias);
            sb.append(joinAlias).append(".").append(primaryKeyName);
        } else {
            sb.append(path).append(".").append(primaryKeyName);
        }
    } else {
        sb.append(path);
    }
    if (operator != Op.NOT_EMPTY) {
        PersistenceManagerClient persistenceManager = AppBeans.get(PersistenceManagerClient.class);
        if (operator == Op.EQUAL && stringType) /*&& persistenceManager.emulateEqualsByLike(thisStore)*/
        {
            sb.append(" ").append(Op.CONTAINS.forJpql());
        } else if (operator == Op.NOT_EQUAL && stringType) /*&& persistenceManager.emulateEqualsByLike(thisStore)*/
        {
            sb.append(" ").append(Op.DOES_NOT_CONTAIN.forJpql());
        } else {
            sb.append(" ").append(operator.forJpql());
        }
    }
    if (!operator.isUnary()) {
        sb.append(" :").append(param.getName());
        if (operator == Op.ENDS_WITH || operator == Op.STARTS_WITH || operator == Op.CONTAINS || operator == Op.DOES_NOT_CONTAIN) {
            CubaProperties properties = AppBeans.get(CubaProperties.class);
            if (properties.getDisableEscapingLikeForDataStores() == null || !properties.getDisableEscapingLikeForDataStores().contains(thisStore)) {
                sb.append(" ESCAPE '").append(QueryUtils.ESCAPE_CHARACTER).append("' ");
            }
        }
        if (operator == Op.NOT_IN) {
            if (Param.Type.ENTITY == param.getType() && !useCrossDataStoreRefId) {
                String primaryKeyName = metadataTools.getPrimaryKeyName(metadata.getClassNN(param.getJavaClass()));
                sb.append(") or (").append(joinAlias).append(".").append(primaryKeyName).append(" is null)) ");
            } else {
                sb.append(") or (").append(path).append(" is null)) ");
            }
        }
    }
    if (operator == Op.NOT_EMPTY) {
        sb.append(BooleanUtils.isTrue((Boolean) param.getValue()) ? " is not null" : " is null");
    }
    text = sb.toString();
    join = sbJoin.toString();
}
Also used : MetadataTools(io.jmix.core.MetadataTools) CubaProperties(com.haulmont.cuba.CubaProperties) KeyValueMetaClass(io.jmix.core.impl.keyvalue.KeyValueMetaClass) Metadata(com.haulmont.cuba.core.global.Metadata) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) PersistenceManagerClient(com.haulmont.cuba.client.sys.PersistenceManagerClient) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 3 with CubaProperties

use of com.haulmont.cuba.CubaProperties in project jmix by jmix-framework.

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 = condition.getEntityMetaClass().getStore().getName();
                CubaProperties properties = AppBeans.get(CubaProperties.class);
                if (properties.getDisableEscapingLikeForDataStores() == null || !properties.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 = EntityValues.getId(((Entity) value));
    } else if (value instanceof Collection) {
        List<Object> list = new ArrayList<>(((Collection) value).size());
        for (Object obj : ((Collection) value)) {
            list.add(obj instanceof Entity ? EntityValues.getId(((Entity) obj)) : obj);
        }
        value = list;
    } else if (value instanceof EnumClass) {
        value = ((EnumClass) value).getId();
    }
    return value;
}
Also used : Op(com.haulmont.cuba.core.global.filter.Op) Entity(io.jmix.core.Entity) CustomCondition(com.haulmont.cuba.gui.components.filter.condition.CustomCondition) Matcher(java.util.regex.Matcher) DynamicAttributesCondition(com.haulmont.cuba.gui.components.filter.condition.DynamicAttributesCondition) ArrayList(java.util.ArrayList) CubaProperties(com.haulmont.cuba.CubaProperties) PropertyCondition(com.haulmont.cuba.gui.components.filter.condition.PropertyCondition) EnumClass(io.jmix.core.metamodel.datatype.impl.EnumClass) Collection(java.util.Collection)

Aggregations

CubaProperties (com.haulmont.cuba.CubaProperties)3 PersistenceManagerClient (com.haulmont.cuba.client.sys.PersistenceManagerClient)1 Metadata (com.haulmont.cuba.core.global.Metadata)1 Op (com.haulmont.cuba.core.global.filter.Op)1 CustomCondition (com.haulmont.cuba.gui.components.filter.condition.CustomCondition)1 DynamicAttributesCondition (com.haulmont.cuba.gui.components.filter.condition.DynamicAttributesCondition)1 PropertyCondition (com.haulmont.cuba.gui.components.filter.condition.PropertyCondition)1 Entity (io.jmix.core.Entity)1 MetadataTools (io.jmix.core.MetadataTools)1 KeyValueMetaClass (io.jmix.core.impl.keyvalue.KeyValueMetaClass)1 EnumClass (io.jmix.core.metamodel.datatype.impl.EnumClass)1 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)1 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Matcher (java.util.regex.Matcher)1