Search in sources :

Example 41 with MetaProperty

use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.

the class AbstractViewRepository method loadView.

protected void loadView(Element rootElem, Element viewElem, View view, boolean systemProperties, Set<ViewInfo> visited) {
    final MetaClass metaClass = metadata.getClassNN(view.getEntityClass());
    final String viewName = view.getName();
    Set<String> propertyNames = new HashSet<>();
    for (Element propElem : (List<Element>) viewElem.elements("property")) {
        String propertyName = propElem.attributeValue("name");
        if (propertyNames.contains(propertyName)) {
            throw new DevelopmentException(String.format("View %s/%s definition error: view declared property %s twice", metaClass.getName(), viewName, propertyName));
        }
        propertyNames.add(propertyName);
        MetaProperty metaProperty = metaClass.getProperty(propertyName);
        if (metaProperty == null) {
            throw new DevelopmentException(String.format("View %s/%s definition error: property %s doesn't exists", metaClass.getName(), viewName, propertyName));
        }
        View refView = null;
        String refViewName = propElem.attributeValue("view");
        MetaClass refMetaClass;
        Range range = metaProperty.getRange();
        if (range == null) {
            throw new RuntimeException("cannot find range for meta property: " + metaProperty);
        }
        final List<Element> propertyElements = Dom4j.elements(propElem, "property");
        boolean inlineView = !propertyElements.isEmpty();
        if (!range.isClass() && (refViewName != null || inlineView)) {
            throw new DevelopmentException(String.format("View %s/%s definition error: property %s is not an entity", metaClass.getName(), viewName, propertyName));
        }
        if (refViewName != null) {
            refMetaClass = getMetaClass(propElem, range);
            refView = retrieveView(refMetaClass, refViewName, visited);
            if (refView == null) {
                for (Element e : Dom4j.elements(rootElem, "view")) {
                    if (refMetaClass.equals(getMetaClass(e.attributeValue("entity"), e.attributeValue("class"))) && refViewName.equals(e.attributeValue("name"))) {
                        refView = deployView(rootElem, e, visited);
                        break;
                    }
                }
                if (refView == null) {
                    MetaClass originalMetaClass = metadata.getExtendedEntities().getOriginalMetaClass(refMetaClass);
                    if (originalMetaClass != null) {
                        refView = retrieveView(originalMetaClass, refViewName, visited);
                    }
                }
                if (refView == null) {
                    throw new DevelopmentException(String.format("View %s/%s definition error: unable to find/deploy referenced view %s/%s", metaClass.getName(), viewName, range.asClass().getName(), refViewName));
                }
            }
        }
        if (inlineView) {
            // try to import anonymous views
            Class rangeClass = range.asClass().getJavaClass();
            if (refView != null) {
                // system properties are already in the source view
                refView = new View(refView, rangeClass, "", false);
            } else {
                ViewProperty existingProperty = view.getProperty(propertyName);
                if (existingProperty != null && existingProperty.getView() != null) {
                    refView = new View(existingProperty.getView(), rangeClass, "", systemProperties);
                } else {
                    refView = new View(rangeClass, systemProperties);
                }
            }
            loadView(rootElem, propElem, refView, systemProperties, visited);
        }
        FetchMode fetchMode = FetchMode.AUTO;
        String fetch = propElem.attributeValue("fetch");
        if (fetch != null)
            fetchMode = FetchMode.valueOf(fetch);
        view.addProperty(propertyName, refView, fetchMode);
    }
}
Also used : Element(org.dom4j.Element) Range(com.haulmont.chile.core.model.Range) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 42 with MetaProperty

use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.

the class MetadataLoader method postProcessClass.

protected void postProcessClass(MetaClass metaClass) {
    for (MetaProperty property : metaClass.getOwnProperties()) {
        postProcessProperty(metaClass, property);
    }
    Collection<MetaClass> missingDescendants = new HashSet<>(1);
    findMissingDescendants(metaClass, missingDescendants);
    if (!missingDescendants.isEmpty()) {
        CollectionUtils.addAll(metaClass.getDescendants(), missingDescendants.iterator());
        MetaClass ancestorMetaClass = metaClass.getAncestor();
        while (ancestorMetaClass != null) {
            CollectionUtils.addAll(ancestorMetaClass.getDescendants(), missingDescendants.iterator());
            ancestorMetaClass = ancestorMetaClass.getAncestor();
        }
    }
    MetaClass ancestorMetaClass = metaClass.getAncestor();
    while (ancestorMetaClass != null) {
        ((MetaClassImpl) metaClass).addAncestor(ancestorMetaClass);
        ancestorMetaClass = ancestorMetaClass.getAncestor();
    }
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 43 with MetaProperty

use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.

the class MetadataLoader method addMetaAnnotationsFromXml.

/**
 * Initialize entity annotations from definition in <code>metadata.xml</code>.
 * <p>Can be overridden in application projects to handle application-specific annotations.</p>
 *
 * @param xmlAnnotations map of class name to annotations map
 * @param metaClass      MetaClass instance to assign annotations
 */
protected void addMetaAnnotationsFromXml(List<XmlAnnotations> xmlAnnotations, MetaClass metaClass) {
    for (XmlAnnotations xmlAnnotation : xmlAnnotations) {
        MetaClass metaClassFromXml = session.getClassNN(ReflectionHelper.getClass(xmlAnnotation.entityClass));
        Class extendedClass = extendedEntities.getExtendedClass(metaClassFromXml);
        MetaClass effectiveMetaClass = extendedClass != null ? session.getClassNN(extendedClass) : metaClassFromXml;
        if (effectiveMetaClass.equals(metaClass)) {
            for (Map.Entry<String, XmlAnnotation> entry : xmlAnnotation.annotations.entrySet()) {
                assignMetaAnnotationValueFromXml(entry.getKey(), entry.getValue(), metaClass.getAnnotations());
            }
            for (XmlAnnotations attributeAnnotation : xmlAnnotation.attributeAnnotations) {
                MetaProperty property = metaClass.getPropertyNN(attributeAnnotation.entityClass);
                for (Map.Entry<String, XmlAnnotation> entry : attributeAnnotation.annotations.entrySet()) {
                    assignMetaAnnotationValueFromXml(entry.getKey(), entry.getValue(), property.getAnnotations());
                }
            }
            break;
        }
    }
}
Also used : XmlAnnotations(com.haulmont.cuba.core.sys.MetadataBuildSupport.XmlAnnotations) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaClass(com.haulmont.chile.core.model.MetaClass) XmlAnnotation(com.haulmont.cuba.core.sys.MetadataBuildSupport.XmlAnnotation) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 44 with MetaProperty

use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.

the class PrintUtils method printClass.

public static String printClass(MetaClass metaClass) {
    StringBuilder builder = new StringBuilder();
    builder.append(metaClass.getName()).append("\n");
    for (MetaProperty metaProperty : metaClass.getOwnProperties()) {
        builder.append(shift(metaProperty.getName() + ": " + metaProperty.getRange()));
    }
    return builder.toString();
}
Also used : MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 45 with MetaProperty

use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.

the class DynamicAttributesMetaClass method getPropertyPath.

@Override
public MetaPropertyPath getPropertyPath(String propertyPath) {
    MetaProperty currentProperty;
    currentProperty = this.getProperty(propertyPath);
    if (currentProperty == null)
        return null;
    return new MetaPropertyPath(this, currentProperty);
}
Also used : MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Aggregations

MetaProperty (com.haulmont.chile.core.model.MetaProperty)157 MetaClass (com.haulmont.chile.core.model.MetaClass)102 Entity (com.haulmont.cuba.core.entity.Entity)44 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)26 BaseGenericIdEntity (com.haulmont.cuba.core.entity.BaseGenericIdEntity)21 Range (com.haulmont.chile.core.model.Range)13 Nullable (javax.annotation.Nullable)11 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)10 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)9 java.util (java.util)9 Element (org.dom4j.Element)9 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)8 Collectors (java.util.stream.Collectors)6 Inject (javax.inject.Inject)6 Query (com.haulmont.cuba.core.Query)5 SoftDelete (com.haulmont.cuba.core.entity.SoftDelete)5 Collection (java.util.Collection)5 MessageTools (com.haulmont.cuba.core.global.MessageTools)4 PropertyDatasource (com.haulmont.cuba.gui.data.PropertyDatasource)4 Logger (org.slf4j.Logger)4