Search in sources :

Example 6 with KeyValueEntity

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

the class JmixTableFormatter method getTableData.

private JmixTableData getTableData(Map<String, List<KeyValueEntity>> transformedData, Map<String, Set<JmixTableData.ColumnInfo>> headerMap, Map<String, List<BandData>> childrenBands) {
    childrenBands.forEach((bandName, bandDataList) -> {
        if (bandName.startsWith(HEADER_BAND_PREFIX)) {
            return;
        }
        List<KeyValueEntity> entities = new ArrayList<>();
        Set<JmixTableData.ColumnInfo> headers = new HashSet<>();
        Set<String> emptyHeaders = new LinkedHashSet<>();
        bandDataList.forEach(bandData -> {
            Map<String, Object> data = bandData.getData();
            final Entity instance;
            final String pkName;
            final boolean pkInFetchPlan;
            if (data instanceof EntityMap) {
                instance = ((EntityMap) data).getInstance();
                pkName = metadataTools.getPrimaryKeyName(metadata.getClass(instance));
                FetchPlan fetchPlan = ((EntityMap) data).getFetchPlan();
                pkInFetchPlan = fetchPlan != null && pkName != null && fetchPlan.containsProperty(pkName);
            } else {
                instance = null;
                pkName = null;
                pkInFetchPlan = false;
            }
            KeyValueEntity entityRow = new KeyValueEntity();
            data.forEach((name, value) -> {
                if (INSTANCE_NAME_KEY.equals(name)) {
                    return;
                }
                if (checkAddHeader(pkName, pkInFetchPlan, name)) {
                    if (instance != null) {
                        name = messageTools.getPropertyCaption(metadata.getClass(instance), name);
                    }
                    checkInstanceNameLoaded(value);
                    String transformationKey = transformationKey(name);
                    if (isFormat(bandName, name)) {
                        String formattedValue = getFormattedValue(bandData.getName(), name, value);
                        entityRow.setValue(transformationKey, formattedValue);
                    } else {
                        entityRow.setValue(transformationKey, value);
                    }
                }
            });
            if (headers.isEmpty() || headers.size() < data.size()) {
                data.forEach((name, value) -> {
                    if (INSTANCE_NAME_KEY.equals(name)) {
                        return;
                    }
                    if (checkAddHeader(pkName, pkInFetchPlan, name)) {
                        if (instance != null) {
                            name = messageTools.getPropertyCaption(metadata.getClass(instance), name);
                        }
                        if (name != null && value != null) {
                            Class valueClass = getColumnClass(bandData.getName(), name, value);
                            headers.add(new JmixTableData.ColumnInfo(transformationKey(name), valueClass, name));
                        }
                        if (name != null && value == null) {
                            emptyHeaders.add(transformationKey(name));
                        }
                    }
                });
            }
            entities.add(entityRow);
        });
        emptyHeaders.forEach(header -> {
            if (!containsHeader(headers, header))
                headers.add(new JmixTableData.ColumnInfo(header, String.class, header));
        });
        headers.removeIf(header -> containsLowerCaseDuplicate(header, headers));
        transformedData.put(bandName, entities);
        headerMap.put(bandName, headers);
    });
    return new JmixTableData(transformedData, headerMap);
}
Also used : KeyValueEntity(io.jmix.core.entity.KeyValueEntity) JmixTableData(io.jmix.reports.entity.JmixTableData) EntityMap(io.jmix.reports.app.EntityMap) KeyValueEntity(io.jmix.core.entity.KeyValueEntity)

Example 7 with KeyValueEntity

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

the class KeyValueCollectionLoaderImpl method load.

@Override
public void load() {
    if (container == null)
        throw new IllegalStateException("container is null");
    if (query == null && delegate == null)
        throw new IllegalStateException("both query and delegate are null");
    ValueLoadContext loadContext = createLoadContext();
    if (!sendPreLoadEvent(loadContext)) {
        return;
    }
    List<KeyValueEntity> list;
    if (delegate == null) {
        list = dataManager.loadValues(loadContext);
    } else {
        list = delegate.apply(loadContext);
    }
    if (dataContext != null) {
        List<KeyValueEntity> mergedList = new ArrayList<>(list.size());
        for (KeyValueEntity entity : list) {
            mergedList.add(dataContext.merge(entity));
        }
        container.setItems(mergedList);
    } else {
        container.setItems(list);
    }
    sendPostLoadEvent(list);
}
Also used : ValueLoadContext(io.jmix.core.ValueLoadContext) KeyValueEntity(io.jmix.core.entity.KeyValueEntity)

Example 8 with KeyValueEntity

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

the class CorePersistentAttributesLoadChecker method isLoaded.

@Override
public boolean isLoaded(Object entity, String property) {
    if (entity instanceof KeyValueEntity) {
        KeyValueEntity keyValue = (KeyValueEntity) entity;
        return keyValue.getInstanceMetaClass() != null && keyValue.getInstanceMetaClass().findProperty(property) != null;
    }
    MetaClass metaClass = metadata.getClass(entity.getClass());
    if (ObjectPathUtils.isSpecialPath(property)) {
        return metadataTools.isAdditionalProperty(metaClass, property);
    }
    MetaProperty metaProperty = metaClass.getProperty(property);
    if (!metadataTools.isJpa(metaProperty)) {
        List<String> dependsOnProperties = metadataTools.getDependsOnProperties(metaProperty);
        if (dependsOnProperties.isEmpty()) {
            return true;
        } else {
            for (String relatedProperty : dependsOnProperties) {
                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(io.jmix.core.metamodel.model.MetaClass) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) KeyValueEntity(io.jmix.core.entity.KeyValueEntity)

Example 9 with KeyValueEntity

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

the class OrderBasedEntityIdsLoader method loadNextIds.

@Override
public ResultHolder loadNextIds(EnqueueingSession session, int batchSize) {
    String entityName = session.getEntityName();
    MetaClass entityClass = metadata.getClass(entityName);
    String orderingPropertyName = session.getOrderingProperty();
    MetaProperty orderingProperty = entityClass.getProperty(orderingPropertyName);
    String lastProcessedRawOrderingValue = session.getLastProcessedValue();
    MetaProperty primaryKeyProperty = metadataTools.getPrimaryKeyProperty(entityClass);
    if (primaryKeyProperty == null) {
        throw new RuntimeException(String.format("Entity '%s' doesn't have primary key", entityName));
    }
    String primaryKeyPropertyName = primaryKeyProperty.getName();
    ResultHolder result;
    if (metadataTools.isEmbedded(orderingProperty)) {
        log.warn("Sorted loading by embedded property is not supported - perform in-memory loading of all ids");
        result = loadAllInMemory(entityClass);
    } else {
        Object lastProcessedValue = convertRawValue(orderingProperty, lastProcessedRawOrderingValue);
        ValueLoadContext valueLoadContext = createValueLoadContext(entityClass, primaryKeyPropertyName, orderingPropertyName, lastProcessedValue, batchSize);
        List<KeyValueEntity> loadedValues = loadValues(valueLoadContext);
        List<Object> ids = loadedValues.stream().map(v -> v.getValue("objectId")).collect(Collectors.toList());
        Object lastLoadedOrderingValue = resolveLastLoadedOrderingValue(loadedValues, primaryKeyPropertyName, orderingPropertyName);
        result = new ResultHolder(ids, lastLoadedOrderingValue);
    }
    return result;
}
Also used : DataManager(io.jmix.core.DataManager) MetaClass(io.jmix.core.metamodel.model.MetaClass) Logger(org.slf4j.Logger) TransactionDefinition(org.springframework.transaction.TransactionDefinition) ValueLoadContext(io.jmix.core.ValueLoadContext) KeyValueEntity(io.jmix.core.entity.KeyValueEntity) EntityIdsLoader(io.jmix.search.index.queue.EntityIdsLoader) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Metadata(io.jmix.core.Metadata) EntityManager(javax.persistence.EntityManager) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) ArrayList(java.util.ArrayList) EnqueueingSession(io.jmix.search.index.queue.entity.EnqueueingSession) Query(javax.persistence.Query) List(java.util.List) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) MetadataTools(io.jmix.core.MetadataTools) Collections(java.util.Collections) Nullable(javax.annotation.Nullable) StoreAwareLocator(io.jmix.data.StoreAwareLocator) MetaClass(io.jmix.core.metamodel.model.MetaClass) ValueLoadContext(io.jmix.core.ValueLoadContext) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) KeyValueEntity(io.jmix.core.entity.KeyValueEntity)

Example 10 with KeyValueEntity

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

the class EntityListValueFragment method removeEntityValue.

@Subscribe("entitiesTable.remove")
public void removeEntityValue(Action.ActionPerformedEvent event) {
    KeyValueEntity item = entitiesDc.getItemOrNull();
    if (item != null) {
        entitiesDc.getMutableItems().remove(item);
        tableValues.remove(item);
    }
}
Also used : KeyValueEntity(io.jmix.core.entity.KeyValueEntity)

Aggregations

KeyValueEntity (io.jmix.core.entity.KeyValueEntity)23 ValueLoadContext (io.jmix.core.ValueLoadContext)3 MetaClass (io.jmix.core.metamodel.model.MetaClass)3 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)3 EntityMap (io.jmix.reports.app.EntityMap)2 JmixTableData (io.jmix.reports.entity.JmixTableData)2 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 EntityManager (javax.persistence.EntityManager)2 Query (javax.persistence.Query)2 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)2 ValueLoadContext (com.haulmont.cuba.core.global.ValueLoadContext)1 BandData (com.haulmont.yarg.structure.BandData)1 Customer (dataaccess.ex1.entity.Customer)1 Customer (datamodel.ex1.entity.Customer)1 DataManager (io.jmix.core.DataManager)1 Entity (io.jmix.core.Entity)1 Metadata (io.jmix.core.Metadata)1 MetadataTools (io.jmix.core.MetadataTools)1 EntityListParameterValue (io.jmix.dashboards.model.parameter.type.EntityListParameterValue)1