Search in sources :

Example 1 with CategoryAttribute

use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.

the class ConverterHelper method getActualMetaProperties.

public static List<MetaProperty> getActualMetaProperties(MetaClass metaClass, Entity entity) {
    List<MetaProperty> result = new ArrayList<MetaProperty>(metaClass.getProperties());
    if (entity instanceof BaseGenericIdEntity && ((BaseGenericIdEntity) entity).getDynamicAttributes() != null) {
        Collection<CategoryAttribute> dynamicAttributes = AppBeans.get(DynamicAttributes.NAME, DynamicAttributes.class).getAttributesForMetaClass(metaClass);
        for (CategoryAttribute dynamicAttribute : dynamicAttributes) {
            result.add(DynamicAttributesUtils.getMetaPropertyPath(metaClass, dynamicAttribute).getMetaProperty());
        }
    }
    Collections.sort(result, PROPERTY_COMPARATOR);
    return result;
}
Also used : CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) BaseGenericIdEntity(com.haulmont.cuba.core.entity.BaseGenericIdEntity) MetaProperty(com.haulmont.chile.core.model.MetaProperty) DynamicAttributes(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributes)

Example 2 with CategoryAttribute

use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.

the class DynamicAttributesConditionFrame method fillAttributeSelect.

protected void fillAttributeSelect(Category category) {
    UUID attrId = condition.getCategoryAttributeId();
    CategoryAttribute selectedAttribute = null;
    Map<String, Object> attributesMap = new TreeMap<>();
    for (CategoryAttribute attribute : category.getCategoryAttrs()) {
        attributesMap.put(attribute.getLocaleName(), attribute);
        if (attribute.getId().equals(attrId)) {
            selectedAttribute = attribute;
        }
    }
    attributeLookup.setOptionsMap(attributesMap);
    attributeLookup.setValue(selectedAttribute);
}
Also used : CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute)

Example 3 with CategoryAttribute

use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.

the class DynamicAttributesConditionFrame method initComponents.

@Override
protected void initComponents() {
    super.initComponents();
    categoryLookup.addValueChangeListener(e -> {
        if (e.getValue() != null) {
            fillAttributeSelect((Category) e.getValue());
        }
    });
    attributeLookup.addValueChangeListener(e -> {
        if (e.getValue() != null) {
            CategoryAttribute categoryAttribute = (CategoryAttribute) e.getValue();
            fillOperationSelect(categoryAttribute);
        }
    });
}
Also used : CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute)

Example 4 with CategoryAttribute

use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.

the class DynamicAttributesConditionFrame method commit.

@Override
public boolean commit() {
    if (!super.commit())
        return false;
    String error = checkCondition();
    if (error != null) {
        showNotification(messages.getMainMessage(error), Frame.NotificationType.TRAY);
        return false;
    }
    CategoryAttribute attribute = attributeLookup.getValue();
    String alias = condition.getEntityAlias();
    String cavAlias = "cav" + RandomStringUtils.randomNumeric(5);
    String paramName;
    String operation = operationLookup.<Op>getValue().forJpql();
    Op op = operationLookup.getValue();
    Class javaClass = DynamicAttributesUtils.getAttributeClass(attribute);
    String propertyPath = Strings.isNullOrEmpty(condition.getPropertyPath()) ? "" : "." + condition.getPropertyPath();
    ConditionParamBuilder paramBuilder = AppBeans.get(ConditionParamBuilder.class);
    paramName = paramBuilder.createParamName(condition);
    String cavEntityId = referenceToEntitySupport.getReferenceIdPropertyName(condition.getDatasource().getMetaClass());
    String where;
    if (op == Op.NOT_EMPTY) {
        where = "(exists (select " + cavAlias + " from sys$CategoryAttributeValue " + cavAlias + " where " + cavAlias + ".entity." + cavEntityId + "=" + "{E}" + propertyPath + ".id and " + cavAlias + ".categoryAttribute.id='" + attributeLookup.<CategoryAttribute>getValue().getId() + "'))";
    } else {
        String valueFieldName = "stringValue";
        if (Entity.class.isAssignableFrom(javaClass))
            valueFieldName = "entityValue." + referenceToEntitySupport.getReferenceIdPropertyName(metadata.getClassNN(javaClass));
        else if (String.class.isAssignableFrom(javaClass))
            valueFieldName = "stringValue";
        else if (Integer.class.isAssignableFrom(javaClass))
            valueFieldName = "intValue";
        else if (Double.class.isAssignableFrom(javaClass))
            valueFieldName = "doubleValue";
        else if (Boolean.class.isAssignableFrom(javaClass))
            valueFieldName = "booleanValue";
        else if (Date.class.isAssignableFrom(javaClass))
            valueFieldName = "dateValue";
        if (!attribute.getIsCollection()) {
            condition.setJoin(", sys$CategoryAttributeValue " + cavAlias + " ");
            String paramStr = " ? ";
            where = cavAlias + ".entity." + cavEntityId + "=" + "{E}" + propertyPath + ".id and " + cavAlias + "." + valueFieldName + " " + operation + (op.isUnary() ? " " : paramStr) + "and " + cavAlias + ".categoryAttribute.id='" + attributeLookup.<CategoryAttribute>getValue().getId() + "'";
            where = where.replace("?", ":" + paramName);
        } else {
            where = "(exists (select " + cavAlias + " from sys$CategoryAttributeValue " + cavAlias + " where " + cavAlias + ".entity." + cavEntityId + "=" + "{E}" + propertyPath + ".id and " + cavAlias + "." + valueFieldName + " = :" + paramName + " and " + cavAlias + ".categoryAttribute.id='" + attributeLookup.<CategoryAttribute>getValue().getId() + "'))";
        }
    }
    condition.setWhere(where);
    condition.setUnary(op.isUnary());
    condition.setEntityParamView(null);
    condition.setEntityParamWhere(null);
    condition.setInExpr(Op.IN.equals(op) || Op.NOT_IN.equals(op));
    condition.setOperator(operationLookup.<Op>getValue());
    Class paramJavaClass = op.isUnary() ? Boolean.class : javaClass;
    condition.setJavaClass(javaClass);
    Param param = Param.Builder.getInstance().setName(paramName).setJavaClass(paramJavaClass).setDataSource(condition.getDatasource()).setProperty(DynamicAttributesUtils.getMetaPropertyPath(null, attribute).getMetaProperty()).setInExpr(condition.getInExpr()).setRequired(condition.getRequired()).setCategoryAttrId(attribute.getId()).build();
    Object defaultValue = condition.getParam().getDefaultValue();
    param.setDefaultValue(defaultValue);
    condition.setParam(param);
    condition.setCategoryId(categoryLookup.<Category>getValue().getId());
    condition.setCategoryAttributeId(attributeLookup.<CategoryAttribute>getValue().getId());
    condition.setIsCollection(BooleanUtils.isTrue(attributeLookup.<CategoryAttribute>getValue().getIsCollection()));
    condition.setLocCaption(attribute.getLocaleName());
    condition.setCaption(caption.getValue());
    return true;
}
Also used : Op(com.haulmont.cuba.core.global.filter.Op) ConditionParamBuilder(com.haulmont.cuba.gui.components.filter.ConditionParamBuilder) CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) Category(com.haulmont.cuba.core.entity.Category) Param(com.haulmont.cuba.gui.components.filter.Param) MetaClass(com.haulmont.chile.core.model.MetaClass)

Example 5 with CategoryAttribute

use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.

the class AbstractTableLoader method addDynamicAttributes.

protected void addDynamicAttributes(Table component, Datasource ds, List<Table.Column> availableColumns) {
    if (metadataTools.isPersistent(ds.getMetaClass())) {
        Set<CategoryAttribute> attributesToShow = dynamicAttributesGuiTools.getAttributesToShowOnTheScreen(ds.getMetaClass(), context.getFullFrameId(), component.getId());
        if (CollectionUtils.isNotEmpty(attributesToShow)) {
            ds.setLoadDynamicAttributes(true);
            for (CategoryAttribute attribute : attributesToShow) {
                final MetaPropertyPath metaPropertyPath = DynamicAttributesUtils.getMetaPropertyPath(ds.getMetaClass(), attribute);
                Object columnWithSameId = IterableUtils.find(availableColumns, o -> o.getId().equals(metaPropertyPath));
                if (columnWithSameId != null) {
                    continue;
                }
                final Table.Column column = new Table.Column(metaPropertyPath);
                column.setCaption(LocaleHelper.isLocalizedValueDefined(attribute.getLocaleNames()) ? attribute.getLocaleName() : StringUtils.capitalize(attribute.getName()));
                if (attribute.getDataType().equals(PropertyType.STRING)) {
                    column.setMaxTextLength(clientConfig.getDynamicAttributesTableColumnMaxTextLength());
                }
                if (attribute.getDataType().equals(PropertyType.ENUMERATION)) {
                    column.setFormatter(value -> LocaleHelper.getEnumLocalizedValue((String) value, attribute.getEnumerationLocales()));
                }
                component.addColumn(column);
            }
        }
        dynamicAttributesGuiTools.listenDynamicAttributesChanges(ds);
    }
}
Also used : CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Aggregations

CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)34 MetaClass (com.haulmont.chile.core.model.MetaClass)15 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)12 MetaProperty (com.haulmont.chile.core.model.MetaProperty)10 Nullable (javax.annotation.Nullable)6 Element (org.dom4j.Element)5 DynamicAttributesMetaProperty (com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesMetaProperty)4 MetadataTools (com.haulmont.cuba.core.global.MetadataTools)4 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)4 DynamicAttributesGuiTools (com.haulmont.cuba.gui.dynamicattributes.DynamicAttributesGuiTools)4 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)3 Joiner (com.google.common.base.Joiner)2 Strings (com.google.common.base.Strings)2 Dom4j (com.haulmont.bali.util.Dom4j)2 Enumeration (com.haulmont.chile.core.datatypes.Enumeration)2 BaseGenericIdEntity (com.haulmont.cuba.core.entity.BaseGenericIdEntity)2 Category (com.haulmont.cuba.core.entity.Category)2 Entity (com.haulmont.cuba.core.entity.Entity)2 AppBeans (com.haulmont.cuba.core.global.AppBeans)2 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)2