Search in sources :

Example 26 with MetaProperty

use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.

the class DomainModelBuilder method produce.

public DomainModel produce() {
    Collection<MetaClass> classes = metadata.getSession().getClasses();
    DomainModel result = new DomainModel(extendedEntities, metadata);
    EntityBuilder builder = EntityBuilder.create();
    for (MetaClass aClass : classes) {
        builder.startNewEntity(aClass.getName());
        Collection<MetaProperty> props = aClass.getProperties();
        for (MetaProperty prop : props) {
            if (metadataTools.isJpa(prop))
                addProperty(builder, aClass, prop);
        }
        JpqlEntityModel entity = builder.produce();
        result.add(entity);
    }
    return result;
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) EntityBuilder(io.jmix.data.impl.jpql.model.EntityBuilder) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) JpqlEntityModel(io.jmix.data.impl.jpql.model.JpqlEntityModel)

Example 27 with MetaProperty

use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.

the class PivotScreenBuilder method getEmbeddedIdProperties.

protected List<String> getEmbeddedIdProperties(MetaClass metaClass) {
    List<String> result = new ArrayList<>();
    if (hasEmbeddedId(metaClass)) {
        MetaClass embeddedMetaClass = getEmbeddedIdMetaClass(metaClass);
        if (embeddedMetaClass == null) {
            return null;
        }
        String primaryKey = metadataTools.getPrimaryKeyName(metaClass);
        for (MetaProperty metaProperty : embeddedMetaClass.getOwnProperties()) {
            result.add(primaryKey + "." + metaProperty.getName());
        }
    }
    return result;
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 28 with MetaProperty

use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.

the class PivotScreenBuilder method removeNonExistingProperties.

protected List<String> removeNonExistingProperties(List<String> properties, MetaClass metaClass, FetchPlan fetchPlan) {
    if (!metadataTools.isJpaEntity(metaClass)) {
        return properties.stream().filter(s -> metaClass.getPropertyPath(s) != null).collect(Collectors.toList());
    }
    List<String> result = new ArrayList<>();
    fetchPlan = fetchPlan == null ? getBaseFetchPlan(metaClass) : fetchPlan;
    for (String property : properties) {
        MetaPropertyPath mpp = metaClass.getPropertyPath(property);
        if (mpp != null && metadataTools.fetchPlanContainsProperty(fetchPlan, mpp)) {
            result.add(property);
        // simple property
        } else if (fetchPlan.containsProperty(property)) {
            result.add(property);
        // id property
        } else if (isIdProperty(property, metaClass)) {
            result.add(property);
        // EmbeddedId's property
        } else if (hasEmbeddedId(metaClass) && isEmbeddedIdProperty(property, metaClass)) {
            result.add(property);
        // if metaClass contains property path, we need to check nested entities in fetch plan
        } else if (mpp != null) {
            for (MetaProperty metaProperty : mpp.getMetaProperties()) {
                MetaClass propertyMetaClass = getPropertyMetaClass(metaProperty);
                if (propertyMetaClass == null) {
                    propertyMetaClass = metaClass;
                }
                // EmbeddedId's property
                if (isEmbeddedIdProperty(property, propertyMetaClass)) {
                    result.add(property);
                // Id property
                } else if (isIdProperty(metaProperty.getName(), propertyMetaClass)) {
                    result.add(property);
                }
            }
        }
    }
    return result;
}
Also used : ListComponent(io.jmix.ui.component.ListComponent) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) MetaClass(io.jmix.core.metamodel.model.MetaClass) java.util(java.util) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) FrameOwner(io.jmix.ui.screen.FrameOwner) Autowired(org.springframework.beans.factory.annotation.Autowired) io.jmix.core(io.jmix.core) ParamsMap(io.jmix.core.common.util.ParamsMap) Frame(io.jmix.ui.component.Frame) JsonParser(com.google.gson.JsonParser) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Scope(org.springframework.context.annotation.Scope) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) UiEntityAttributeContext(io.jmix.ui.accesscontext.UiEntityAttributeContext) MapScreenOptions(io.jmix.ui.screen.MapScreenOptions) UiControllerUtils.getScreenContext(io.jmix.ui.screen.UiControllerUtils.getScreenContext) JsonSyntaxException(com.google.gson.JsonSyntaxException) Screen(io.jmix.ui.screen.Screen) Collectors(java.util.stream.Collectors) OpenMode(io.jmix.ui.screen.OpenMode) Component(org.springframework.stereotype.Component) EntityDataItem(io.jmix.ui.data.impl.EntityDataItem) DataItem(io.jmix.ui.data.DataItem) Screens(io.jmix.ui.Screens) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 29 with MetaProperty

use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.

the class PivotScreenBuilder method isEmbeddedIdProperty.

protected boolean isEmbeddedIdProperty(String property, MetaClass metaClass) {
    MetaClass embeddedMetaClass = getEmbeddedIdMetaClass(metaClass);
    if (embeddedMetaClass == null) {
        return false;
    }
    String[] propertyPathParts = property.split("\\.");
    String propertyName = propertyPathParts[propertyPathParts.length - 1];
    MetaProperty metaProperty = embeddedMetaClass.getProperty(propertyName);
    return embeddedMetaClass.getOwnProperties().contains(metaProperty);
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 30 with MetaProperty

use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.

the class EditorBuilderProcessor method initEntity.

@Nullable
protected <E> E initEntity(EditorBuilder<E> builder, @Nullable CollectionContainer<E> container) {
    E entity;
    boolean oneToOneComposition = false;
    EntityValueSource entityValueSource = null;
    HasValue<E> field = builder.getField();
    if (field instanceof HasValueSource) {
        ValueSource valueSource = ((HasValueSource) field).getValueSource();
        if (valueSource instanceof EntityValueSource) {
            entityValueSource = (EntityValueSource) valueSource;
            oneToOneComposition = isCompositionProperty(entityValueSource);
        }
    }
    if (builder.getMode() == EditMode.CREATE || (oneToOneComposition && field.getValue() == null)) {
        if (builder.getNewEntity() == null) {
            entity = metadata.create(builder.getEntityClass());
        } else {
            entity = builder.getNewEntity();
        }
        if (container instanceof Nested) {
            initializeNestedEntity(entity, (Nested) container);
        }
        if (oneToOneComposition) {
            Object ownerEntity = entityValueSource.getItem();
            MetaProperty inverseProp = entityValueSource.getMetaPropertyPath().getMetaProperty().getInverse();
            if (inverseProp != null) {
                EntityValues.setValue(entity, inverseProp.getName(), ownerEntity);
            }
        }
        if (builder.getInitializer() != null) {
            builder.getInitializer().accept(entity);
        }
    } else {
        entity = builder.getEditedEntity();
    }
    return entity;
}
Also used : EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) ValueSource(io.jmix.ui.component.data.ValueSource) EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) HasValueSource(io.jmix.ui.component.data.HasValueSource) Nested(io.jmix.ui.model.Nested) HasValueSource(io.jmix.ui.component.data.HasValueSource) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) Nullable(javax.annotation.Nullable)

Aggregations

MetaProperty (io.jmix.core.metamodel.model.MetaProperty)267 MetaClass (io.jmix.core.metamodel.model.MetaClass)162 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)53 Nullable (javax.annotation.Nullable)36 Range (io.jmix.core.metamodel.model.Range)23 Autowired (org.springframework.beans.factory.annotation.Autowired)23 Collectors (java.util.stream.Collectors)22 java.util (java.util)20 Component (org.springframework.stereotype.Component)18 Entity (io.jmix.core.Entity)17 EntityValues (io.jmix.core.entity.EntityValues)17 io.jmix.core (io.jmix.core)16 Logger (org.slf4j.Logger)15 LoggerFactory (org.slf4j.LoggerFactory)15 ArrayList (java.util.ArrayList)12 Collection (java.util.Collection)12 EntityValueSource (io.jmix.ui.component.data.meta.EntityValueSource)10 Metadata (io.jmix.core.Metadata)9 KeyValueMetaClass (io.jmix.core.impl.keyvalue.KeyValueMetaClass)9 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)8