@Nullable public CategoryAttribute getAttributeForMetaClass(MetaClass metaClass, String code) { code = DynamicAttributesUtils.decodeAttributeCode(code); MetaClass targetMetaClass = resolveTargetMetaClass(metaClass); Map<String, CategoryAttribute> attributes = attributesCache.get(targetMetaClass.getName()); if (attributes != null) { return attributes.get(code); } return null; }
/** * Get special meta property path object for dynamic attribute by code */ @Nullable public MetaPropertyPath getMetaPropertyPath(MetaClass metaClass, String attributeCode) { attributeCode = decodeAttributeCode(attributeCode); CategoryAttribute attribute = dynamicAttributes.getAttributeForMetaClass(metaClass, attributeCode); if (attribute != null) { return DynamicAttributesUtils.getMetaPropertyPath(metaClass, attribute); } else { return null; } }
@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 @SuppressWarnings("unchecked") public void setValue(String name, Object value) { mainItem.setValue(name, value); //if we set an attribute from another type of entity, we need to set reference to CategoryAttribute manually //this is workaround to make #PL-5770 logic works with modern RuntimePropertiesDatasource String attributeCode = DynamicAttributesUtils.decodeAttributeCode(name); Map<String, CategoryAttributeValue> dynamicAttributes = mainItem.getDynamicAttributes(); if (dynamicAttributes != null) { CategoryAttributeValue categoryAttributeValue = dynamicAttributes.get(attributeCode); if (categoryAttributeValue != null && categoryAttributeValue.getCategoryAttribute() == null) { categoryAttributeValue.setCategoryAttribute(attributesMap.get(attributeCode)); } } }
String attributeCode = decodeAttributeCode(property); return entityDynamicAttributes.containsKey(attributeCode) || dynamicAttributes.getAttributeForMetaClass(metaClass, property) != null;
if (DynamicAttributesUtils.isDynamicAttribute(property)) { Preconditions.checkState(dynamicAttributes != null, "Dynamic attributes should be loaded explicitly"); String attributeCode = DynamicAttributesUtils.decodeAttributeCode(property); CategoryAttributeValue categoryAttributeValue = dynamicAttributes.get(attributeCode); Object oldValue = categoryAttributeValue != null ? categoryAttributeValue.getValue() : null;