Search in sources :

Example 1 with EntityValues

use of io.jmix.core.entity.EntityValues in project jmix by jmix-framework.

the class DynAttrManagerImpl method loadValues.

protected List<CategoryAttributeValue> loadValues(MetaClass metaClass, Collection<AccessConstraint<?>> accessConstraints, List<Object> entityIds) {
    List<CategoryAttributeValue> mainAttributeValues = findValuesByEntityIds(metaClass, entityIds);
    List<CategoryAttributeValue> entityValues = mainAttributeValues.stream().filter(v -> v.getObjectEntityValueId() != null).collect(Collectors.toList());
    List<CategoryAttributeValue> collectionValues = mainAttributeValues.stream().filter(v -> BooleanUtils.isTrue(v.getCategoryAttribute().getIsCollection())).collect(Collectors.toList());
    if (collectionValues.isEmpty()) {
        fetchEntityValues(accessConstraints, entityValues);
        return mainAttributeValues;
    } else {
        List<CategoryAttributeValue> reloadedCollectionValues = fetchCollectionValues(collectionValues);
        List<CategoryAttributeValue> values = new ArrayList<>(mainAttributeValues.size());
        for (CategoryAttributeValue value : reloadedCollectionValues) {
            if (value.getCategoryAttribute().getDataType() == AttributeType.ENTITY && value.getChildValues() != null) {
                for (CategoryAttributeValue child : value.getChildValues()) {
                    if (child.getDeleteTs() == null) {
                        entityValues.add(child);
                    }
                }
            }
        }
        fetchEntityValues(accessConstraints, entityValues);
        for (CategoryAttributeValue value : reloadedCollectionValues) {
            if (value.getChildValues() != null) {
                value.setTransientCollectionValue(value.getChildValues().stream().filter(v -> v.getDeleteTs() == null).map(CategoryAttributeValue::getValue).collect(Collectors.toList()));
            }
        }
        for (CategoryAttributeValue value : mainAttributeValues) {
            if (!reloadedCollectionValues.contains(value)) {
                values.add(value);
            }
        }
        values.addAll(reloadedCollectionValues);
        return values;
    }
}
Also used : EntitySystemAccess(io.jmix.core.entity.EntitySystemAccess) MetaClass(io.jmix.core.metamodel.model.MetaClass) java.util(java.util) io.jmix.dynattr(io.jmix.dynattr) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) io.jmix.core(io.jmix.core) CrudEntityContext(io.jmix.core.accesscontext.CrudEntityContext) BooleanUtils(org.apache.commons.lang3.BooleanUtils) Multimap(com.google.common.collect.Multimap) EntityValues(io.jmix.core.entity.EntityValues) BigDecimal(java.math.BigDecimal) HashMultimap(com.google.common.collect.HashMultimap) CategoryAttribute(io.jmix.dynattr.model.CategoryAttribute) CategoryAttributeValue(io.jmix.dynattr.model.CategoryAttributeValue) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) PersistenceHints(io.jmix.data.PersistenceHints) EntityManager(javax.persistence.EntityManager) Collectors(java.util.stream.Collectors) Component(org.springframework.stereotype.Component) Stream(java.util.stream.Stream) LocalDate(java.time.LocalDate) ReflectionHelper(io.jmix.core.common.util.ReflectionHelper) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) AccessConstraint(io.jmix.core.constraint.AccessConstraint) StoreAwareLocator(io.jmix.data.StoreAwareLocator) CategoryAttributeValue(io.jmix.dynattr.model.CategoryAttributeValue)

Aggregations

HashMultimap (com.google.common.collect.HashMultimap)1 Multimap (com.google.common.collect.Multimap)1 io.jmix.core (io.jmix.core)1 CrudEntityContext (io.jmix.core.accesscontext.CrudEntityContext)1 ReflectionHelper (io.jmix.core.common.util.ReflectionHelper)1 AccessConstraint (io.jmix.core.constraint.AccessConstraint)1 EntitySystemAccess (io.jmix.core.entity.EntitySystemAccess)1 EntityValues (io.jmix.core.entity.EntityValues)1 MetaClass (io.jmix.core.metamodel.model.MetaClass)1 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)1 PersistenceHints (io.jmix.data.PersistenceHints)1 StoreAwareLocator (io.jmix.data.StoreAwareLocator)1 io.jmix.dynattr (io.jmix.dynattr)1 CategoryAttribute (io.jmix.dynattr.model.CategoryAttribute)1 CategoryAttributeValue (io.jmix.dynattr.model.CategoryAttributeValue)1 BigDecimal (java.math.BigDecimal)1 LocalDate (java.time.LocalDate)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1