/** * Get special meta property path object for dynamic attribute by code */ @Nullable public static MetaPropertyPath getMetaPropertyPath(MetaClass metaClass, String attributeCode) { return AppBeans.get(DynamicAttributesTools.NAME, DynamicAttributesTools.class) .getMetaPropertyPath(metaClass, attributeCode); }
/** * For collection dynamic attributes the method returns a list of formatted collection items joined with the comma, * for non-collection dynamic attribute a formatted value is returned. * * @see DynamicAttributesTools#getDynamicAttributeValueAsString(MetaProperty, Object) */ public static String getDynamicAttributeValueAsString(MetaProperty metaProperty, Object value) { return AppBeans.get(DynamicAttributesTools.NAME, DynamicAttributesTools.class) .getDynamicAttributeValueAsString(metaProperty, value); } }
String value; if (DynamicAttributesUtils.isDynamicAttribute(columnId)) { metaProperty = dynamicAttributesTools.getMetaPropertyPath(item.getMetaClass(), columnId).getMetaProperty(); value = dynamicAttributesTools.getDynamicAttributeValueAsString(metaProperty, item.getValueEx(columnId)); } else { value = item.getValueEx(columnId);
/** * Get special meta property path object for dynamic attribute id */ @Nullable public static MetaPropertyPath getMetaPropertyPath(MetaClass metaClass, UUID attributeId) { return AppBeans.get(DynamicAttributesTools.NAME, DynamicAttributesTools.class) .getMetaPropertyPath(metaClass, attributeId); }
@Override public Object generateCell(com.vaadin.v7.ui.Table source, Object itemId, Object columnId) { Property property = source.getItem(itemId).getItemProperty(columnId); Object value = property.getValue(); if (value == null) { return null; } String stringValue = value.toString(); if (columnId instanceof MetaPropertyPath) { MetaProperty metaProperty = ((MetaPropertyPath) columnId).getMetaProperty(); if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) { stringValue = dynamicAttributesTools.getDynamicAttributeValueAsString(metaProperty, value); } } String cellValue = stringValue; boolean isMultiLineCell = StringUtils.contains(stringValue, "\n"); if (isMultiLineCell) { cellValue = StringUtils.replaceChars(cellValue, '\n', ' '); } int maxTextLength = column.getMaxTextLength(); if (stringValue.length() > maxTextLength + MAX_TEXT_LENGTH_GAP || isMultiLineCell) { return StringUtils.abbreviate(cellValue, maxTextLength); } else { return cellValue; } } }
protected Set<String> filterRemovedAttributes(MetaClass metaClass, Set<String> attributes) { // filter attributes that do not exists in entity anymore return attributes.stream() .filter(attributeName -> { if (DynamicAttributesUtils.isDynamicAttribute(attributeName)) { return dynamicAttributesTools.getMetaPropertyPath(metaClass, attributeName) != null; } else { return metaClass.getPropertyPath(attributeName) != null; } }) .collect(Collectors.toSet()); }
} else { if (DynamicAttributesUtils.isDynamicAttribute(propertyPath.getMetaProperty())) { stringValue = dynamicAttributesTools.getDynamicAttributeValueAsString(propertyPath.getMetaProperty(), value); } else { stringValue = value == null ? null : value.toString();
protected MetaPropertyPath resolveMetaPropertyPath(MetaClass metaClass, String property) { MetaPropertyPath mpp = metaClass.getPropertyPath(property); if (mpp == null && DynamicAttributesUtils.isDynamicAttribute(property)) { mpp = dynamicAttributesTools.getMetaPropertyPath(metaClass, property); } return mpp; }
return dynamicAttributesTools.getDynamicAttributeValueAsString(property, value);
/** * Returns a {@link MetaPropertyPath} which can include the special MetaProperty for a dynamic attribute. * * @param metaClass originating meta-class * @param propertyPath path to the attribute * @return MetaPropertyPath instance */ @Nullable public MetaPropertyPath resolveMetaPropertyPath(MetaClass metaClass, String propertyPath) { checkNotNullArgument(metaClass, "metaClass is null"); MetaPropertyPath metaPropertyPath = metaClass.getPropertyPath(propertyPath); if (metaPropertyPath == null && DynamicAttributesUtils.isDynamicAttribute(propertyPath)) { metaPropertyPath = dynamicAttributesTools.getMetaPropertyPath(metaClass, propertyPath); } return metaPropertyPath; }
@Override public void applyColumnSettings(Element element) { super.applyColumnSettings(element); Element groupPropertiesElement = element.element("groupProperties"); if (groupPropertiesElement != null) { MetaClass metaClass = ((EntityTableItems) getItems()).getEntityMetaClass(); List elements = groupPropertiesElement.elements("property"); List<MetaPropertyPath> properties = new ArrayList<>(elements.size()); for (Object o : elements) { String id = ((Element) o).attributeValue("id"); MetaPropertyPath property = DynamicAttributesUtils.isDynamicAttribute(id) ? dynamicAttributesTools.getMetaPropertyPath(metaClass, id) : metaClass.getPropertyPath(id); if (property != null) { properties.add(property); } else { LoggerFactory.getLogger(WebGroupTable.class) .warn("Ignored group property '{}'", id); } } groupBy(properties.toArray()); } }
protected void loadEditable(FieldGroup fieldGroup, FieldGroup.FieldConfig field) { if (fieldGroup.isEditable()) { MetaClass metaClass = rds.resolveCategorizedEntityClass(); MetaPropertyPath propertyPath = dynamicAttributesTools.getMetaPropertyPath(metaClass, field.getProperty()); checkNotNullArgument(propertyPath, "Could not resolve property path '%s' in '%s'", field.getId(), metaClass); boolean editableFromPermissions = security.isEntityAttrUpdatePermitted(metaClass, propertyPath.toString()); if (!editableFromPermissions) { field.setEditable(false); } boolean visibleFromPermissions = security.isEntityAttrReadPermitted(metaClass, propertyPath.toString()); if (!visibleFromPermissions) { field.setVisible(false); } } }