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;
}
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);
}
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);
}
});
}
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;
}
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);
}
}
Aggregations