Search in sources :

Example 36 with MetaClass

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

the class RelatedEntitiesBean method getManyToOneCondition.

@Nullable
protected AbstractCondition getManyToOneCondition(List<Object> parentIds, CollectionDatasource datasource, String filterComponentName, String relatedPrimaryKey, MetaDataDescriptor descriptor) {
    MetaClass metaClass = descriptor.getMetaClass();
    String parentPrimaryKey = metadataTools.getPrimaryKeyName(metaClass);
    CustomCondition customCondition = getParentEntitiesCondition(parentIds, parentPrimaryKey, datasource, filterComponentName, metaClass);
    String entityAlias = RandomStringUtils.randomAlphabetic(6);
    String subQuery = String.format("select %s.%s.%s from %s %s where %s.%s in :%s", entityAlias, descriptor.getMetaProperty().getName(), relatedPrimaryKey, metaClass.getName(), entityAlias, entityAlias, parentPrimaryKey, customCondition.getParam().getName());
    String whereString = String.format("{E}.%s in (%s)", relatedPrimaryKey, subQuery);
    customCondition.setWhere(whereString);
    return customCondition;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) CustomCondition(com.haulmont.cuba.gui.components.filter.condition.CustomCondition) Nullable(javax.annotation.Nullable)

Example 37 with MetaClass

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

the class DsContextLoader method loadRuntimePropsDatasource.

protected RuntimePropsDatasource loadRuntimePropsDatasource(Element element) {
    String id = getDatasourceId(element);
    MetaClass metaClass = loadMetaClass(element);
    String mainDsId = element.attributeValue("mainDs");
    if (mainDsId == null) {
        throw new IllegalStateException("RuntimePropsDs attributes not specified");
    }
    String categorizedEntityClassName = element.attributeValue("categorizedEntityClass");
    MetaClass categorizedEntityMetaClass = null;
    if (StringUtils.isNotBlank(categorizedEntityClassName)) {
        final Class<?> aClass = ReflectionHelper.getClass(categorizedEntityClassName);
        categorizedEntityMetaClass = metadata.getSession().getClass(aClass);
    }
    builder.reset().setMetaClass(metaClass).setId(id);
    RuntimePropsDatasource datasource = builder.buildRuntimePropsDatasource(mainDsId, categorizedEntityMetaClass);
    loadDatasources(element, datasource);
    return datasource;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass)

Example 38 with MetaClass

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

the class DsContextLoader method loadMetaClass.

protected MetaClass loadMetaClass(Element element) {
    final String className = element.attributeValue("class");
    if (className == null)
        return null;
    final Class<?> aClass = ReflectionHelper.getClass(className);
    final MetaClass metaClass = metadata.getSession().getClass(aClass);
    if (metaClass == null)
        throw new IllegalStateException(String.format("Can't find metaClass '%s'", className));
    return metaClass;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass)

Example 39 with MetaClass

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

the class DsContextLoader method loadHierarchicalDatasource.

protected Datasource loadHierarchicalDatasource(Element element) {
    MetaClass metaClass = loadMetaClass(element);
    if (metaClass == null)
        throw new DevelopmentException("'class' attribute is not set for the datasource");
    initCollectionDatasourceAttributes(element, metaClass);
    HierarchicalDatasource datasource = builder.setDsClass(getDatasourceClass(element)).buildHierarchicalDatasource();
    String hierarchyProperty = element.attributeValue("hierarchyProperty");
    if (!StringUtils.isEmpty(hierarchyProperty)) {
        datasource.setHierarchyPropertyName(hierarchyProperty);
    }
    if (datasource instanceof CollectionDatasource.Suspendable)
        ((CollectionDatasource.Suspendable) datasource).setSuspended(true);
    loadQuery(element, datasource);
    loadDatasources(element, datasource);
    return datasource;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) DevelopmentException(com.haulmont.cuba.core.global.DevelopmentException)

Example 40 with MetaClass

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

the class DsContextLoader method initPropertyDatasourceAttributes.

private void initPropertyDatasourceAttributes(Element element, Datasource ds, String property) {
    String id = getDatasourceId(element);
    MetaClass metaClass = ds.getMetaClass();
    // check property existense
    metaClass.getPropertyNN(property);
    builder.reset().setMetaClass(metaClass).setId(id).setMaster(ds).setProperty(property).setAllowCommit(getAllowCommit(element));
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass)

Aggregations

MetaClass (com.haulmont.chile.core.model.MetaClass)302 MetaProperty (com.haulmont.chile.core.model.MetaProperty)103 Entity (com.haulmont.cuba.core.entity.Entity)54 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)36 Nullable (javax.annotation.Nullable)25 BaseGenericIdEntity (com.haulmont.cuba.core.entity.BaseGenericIdEntity)24 Element (org.dom4j.Element)21 java.util (java.util)18 Inject (javax.inject.Inject)17 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)16 Test (org.junit.Test)15 EntityManager (com.haulmont.cuba.core.EntityManager)14 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)14 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)13 Metadata (com.haulmont.cuba.core.global.Metadata)13 Logger (org.slf4j.Logger)13 LoggerFactory (org.slf4j.LoggerFactory)13 MetadataTools (com.haulmont.cuba.core.global.MetadataTools)12 Collectors (java.util.stream.Collectors)11 Range (com.haulmont.chile.core.model.Range)10