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()); }
protected MetaPropertyPath resolveMetaPropertyPath(MetaClass metaClass, String property) { MetaPropertyPath mpp = metaClass.getPropertyPath(property); if (mpp == null && DynamicAttributesUtils.isDynamicAttribute(property)) { mpp = DynamicAttributesUtils.getMetaPropertyPath(metaClass, property); } return mpp; }
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; }
protected MetaPropertyPath resolveMetaPropertyPath(MetaClass metaClass, String property) { MetaPropertyPath mpp = metaClass.getPropertyPath(property); if (mpp == null && DynamicAttributesUtils.isDynamicAttribute(property)) { mpp = DynamicAttributesUtils.getMetaPropertyPath(metaClass, property); } return mpp; }
@Nullable protected Field createCurrencyField(ComponentGenerationContext context, MetaPropertyPath mpp) { if (DynamicAttributesUtils.isDynamicAttribute(mpp.getMetaProperty())) return null; Object currencyAnnotation = mpp.getMetaProperty().getAnnotations().get(CurrencyValue.class.getName()); if (currencyAnnotation == null) { return null; } CurrencyField component = uiComponents.create(CurrencyField.class); setValueSource(component, context); return component; }
/** * 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 @SuppressWarnings("unchecked") public <V> V getValue(String property) { if (DynamicAttributesUtils.isDynamicAttribute(property)) { if (PersistenceHelper.isNew(this) && dynamicAttributes == null) { dynamicAttributes = new HashMap<>(); } Preconditions.checkState(dynamicAttributes != null, "Dynamic attributes should be loaded explicitly"); CategoryAttributeValue categoryAttributeValue = dynamicAttributes.get(DynamicAttributesUtils.decodeAttributeCode(property)); if (categoryAttributeValue != null) { return (V) categoryAttributeValue.getValue(); } else { return null; } } else { return super.getValue(property); } }
@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 boolean propertyWritingAllowed(MetaProperty metaProperty, Entity entity) { return !"id".equals(metaProperty.getName()) && (DynamicAttributesUtils.isDynamicAttribute(metaProperty) || (entity instanceof AbstractNotPersistentEntity) || !metadataTools.isPersistent(metaProperty) || (metadataTools.isPersistent(metaProperty) && PersistenceHelper.isLoaded(entity, metaProperty.getName()))); }
public Param(Builder builder) { name = builder.name; setJavaClass(builder.javaClass); entityWhere = builder.entityWhere; entityView = (builder.entityView != null) ? builder.entityView : View.MINIMAL; property = builder.property; inExpr = builder.inExpr; required = builder.required; categoryAttrId = builder.categoryAttrId; isDateInterval = builder.isDateInterval; useUserTimeZone = builder.useUserTimeZone; if (DynamicAttributesUtils.isDynamicAttribute(builder.property)) { CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(builder.property); if (categoryAttribute.getDataType() == PropertyType.ENUMERATION) { type = Type.RUNTIME_ENUM; } } }
protected boolean isCollectionDynamicAttribute(MetaProperty metaProperty) { if (DynamicAttributesUtils.isDynamicAttribute(metaProperty.getName())) { CategoryAttribute attribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty); return attribute != null && BooleanUtils.isTrue(attribute.getIsCollection()); } return false; } }
private String getCollectionString(Object collection) { if (DynamicAttributesUtils.isDynamicAttribute(propertyName)) { Metadata metadata = AppBeans.get(Metadata.class); com.haulmont.chile.core.model.MetaClass metaClass = metadata.getClassNN(metaClassName); MetaPropertyPath path = DynamicAttributesUtils.getMetaPropertyPath(metaClass, propertyName); return metadata.getTools().format(collection, path.getMetaProperty()); } return String.valueOf(beforeValue); }
@Override public void setDatasource(Datasource datasource, String property) { super.setDatasource(datasource, property); // vaadin8 support in value source if (datasource != null && !DynamicAttributesUtils.isDynamicAttribute(property)) { MetaProperty metaProperty = datasource.getMetaClass() .getPropertyNN(property); Object annotation = metaProperty.getAnnotations() .get(CurrencyValue.class.getName()); if (annotation == null) { return; } //noinspection unchecked Map<String, Object> annotationProperties = (Map<String, Object>) annotation; String currencyName = (String) annotationProperties.get("currency"); component.setCurrency(currencyName); String labelPosition = ((com.haulmont.cuba.core.entity.annotation.CurrencyLabelPosition) annotationProperties.get("labelPosition")).name(); setCurrencyLabelPosition(CurrencyLabelPosition.valueOf(labelPosition)); } }
/** * Enforce the datasource to change modified status if dynamic attribute is changed */ @SuppressWarnings("unchecked") public void listenDynamicAttributesChanges(final Datasource datasource) { if (datasource != null && datasource.getLoadDynamicAttributes()) { datasource.addItemPropertyChangeListener(e -> { if (DynamicAttributesUtils.isDynamicAttribute(e.getProperty())) { ((DatasourceImplementation) datasource).modified(e.getItem()); } }); } }
protected String getColumnCaption(Object columnId, Column column) { String caption = column.getCaption(); if (caption != null) { return caption; } if (!(columnId instanceof MetaPropertyPath)) { return StringUtils.capitalize(getColumnCaption(columnId)); } MetaPropertyPath mpp = (MetaPropertyPath) columnId; MetaProperty metaProperty = mpp.getMetaProperty(); if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) { CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty); if (LocaleHelper.isLocalizedValueDefined(categoryAttribute.getLocaleNames())) { return categoryAttribute.getLocaleName(); } caption = StringUtils.capitalize(categoryAttribute.getName()); } else { caption = StringUtils.capitalize(getColumnCaption(columnId)); } return caption; }
protected EntityPropertyDiff(com.haulmont.chile.core.model.MetaProperty metaProperty) { metaClassName = metaProperty.getDomain().getName(); propertyName = metaProperty.getName(); if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) { CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty); propertyCaption = categoryAttribute.getLocaleName(); } else { MessageTools messageTools = AppBeans.get(MessageTools.NAME); propertyCaption = messageTools.getPropertyCaption(metaProperty.getDomain(), metaProperty.getName()); } }
protected void initBeanValidator(Field<?> component, MetaPropertyPath metaPropertyPath) { MetaProperty metaProperty = metaPropertyPath.getMetaProperty(); MetaClass propertyEnclosingMetaClass = metadataTools.getPropertyEnclosingMetaClass(metaPropertyPath); Class enclosingJavaClass = propertyEnclosingMetaClass.getJavaClass(); if (enclosingJavaClass != KeyValueEntity.class && !DynamicAttributesUtils.isDynamicAttribute(metaProperty)) { javax.validation.Validator validator = beanValidation.getValidator(); BeanDescriptor beanDescriptor = validator.getConstraintsForClass(enclosingJavaClass); if (beanDescriptor.isBeanConstrained()) { component.addValidator(beanLocator.getPrototype(BeanPropertyValidator.NAME, enclosingJavaClass, metaProperty.getName())); } } }
@SuppressWarnings("unchecked") @Override protected void valueBindingConnected(ValueSource<V> valueSource) { super.valueBindingConnected(valueSource); if (valueSource instanceof EntityValueSource) { MetaPropertyPath propertyPath = ((EntityValueSource) valueSource).getMetaPropertyPath(); MetaProperty metaProperty = propertyPath.getMetaProperty(); if (metaProperty.getRange().isEnum()) { //noinspection unchecked setOptions(new EnumOptions(metaProperty.getJavaType())); } if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) { CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty); if (categoryAttribute != null && categoryAttribute.getDataType() == PropertyType.ENUMERATION) { setOptionsMap((Map<String, V>) categoryAttribute.getLocalizedEnumerationMap()); } } } }
@SuppressWarnings("unchecked") @Override protected void valueBindingConnected(ValueSource<V> valueSource) { super.valueBindingConnected(valueSource); if (valueSource instanceof EntityValueSource) { MetaPropertyPath propertyPath = ((EntityValueSource) valueSource).getMetaPropertyPath(); MetaProperty metaProperty = propertyPath.getMetaProperty(); if (metaProperty.getRange().isEnum()) { //noinspection unchecked setOptions(new EnumOptions(metaProperty.getRange().asEnumeration().getJavaClass())); } if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) { CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty); if (categoryAttribute != null && categoryAttribute.getDataType() == PropertyType.ENUMERATION) { setOptionsMap((Map<String, I>) categoryAttribute.getLocalizedEnumerationMap()); } } } }
@SuppressWarnings("unchecked") @Override protected void valueBindingConnected(ValueSource<V> valueSource) { super.valueBindingConnected(valueSource); if (valueSource instanceof EntityValueSource) { MetaPropertyPath propertyPath = ((EntityValueSource) valueSource).getMetaPropertyPath(); MetaProperty metaProperty = propertyPath.getMetaProperty(); if (metaProperty.getRange().isEnum()) { //noinspection unchecked setOptions(new EnumOptions(metaProperty.getRange().asEnumeration().getJavaClass())); } if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) { CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty); if (categoryAttribute != null && categoryAttribute.getDataType() == PropertyType.ENUMERATION) { setOptionsMap((Map<String, I>) categoryAttribute.getLocalizedEnumerationMap()); } } } }