Search in sources :

Example 1 with CategoryAttributeValue

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

the class GlobalPersistentAttributesLoadChecker method isLoaded.

@Override
public boolean isLoaded(Object entity, String property) {
    MetaClass metaClass = metadata.getClassNN(entity.getClass());
    if (isDynamicAttribute(property)) {
        @SuppressWarnings("unchecked") Map<String, CategoryAttributeValue> dynamicAttributes = ((BaseGenericIdEntity) entity).getDynamicAttributes();
        if (dynamicAttributes == null) {
            return false;
        }
        String attributeCode = decodeAttributeCode(property);
        return dynamicAttributes.containsKey(attributeCode);
    }
    MetaProperty metaProperty = metaClass.getPropertyNN(property);
    if (!metadataTools.isPersistent(metaProperty)) {
        List<String> relatedProperties = metadataTools.getRelatedProperties(metaProperty);
        if (relatedProperties.isEmpty()) {
            return true;
        } else {
            for (String relatedProperty : relatedProperties) {
                if (!isLoaded(entity, relatedProperty))
                    return false;
            }
            return true;
        }
    }
    PropertyLoadedState isLoaded = isLoadedCommonCheck(entity, property);
    if (isLoaded != PropertyLoadedState.UNKNOWN) {
        return isLoaded == PropertyLoadedState.YES;
    }
    return isLoadedSpecificCheck(entity, property, metaClass, metaProperty);
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) BaseGenericIdEntity(com.haulmont.cuba.core.entity.BaseGenericIdEntity) MetaProperty(com.haulmont.chile.core.model.MetaProperty) CategoryAttributeValue(com.haulmont.cuba.core.entity.CategoryAttributeValue)

Example 2 with CategoryAttributeValue

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

the class DynamicAttributesEntity method setValue.

@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));
        }
    }
}
Also used : CategoryAttributeValue(com.haulmont.cuba.core.entity.CategoryAttributeValue)

Aggregations

CategoryAttributeValue (com.haulmont.cuba.core.entity.CategoryAttributeValue)2 MetaClass (com.haulmont.chile.core.model.MetaClass)1 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 BaseGenericIdEntity (com.haulmont.cuba.core.entity.BaseGenericIdEntity)1