Search in sources :

Example 1 with KeyValueEntity

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

the class CustomValueCollectionDatasource method loadData.

@Override
protected void loadData(Map<String, Object> params) {
    Collection<KeyValueEntity> entities = getEntities(params);
    detachListener(data.values());
    data.clear();
    if (entities != null) {
        for (KeyValueEntity entity : entities) {
            data.put(entity.getId(), entity);
            attachListener(entity);
            entity.setInstanceMetaClass(metaClass);
        }
    }
}
Also used : KeyValueEntity(io.jmix.core.entity.KeyValueEntity)

Example 2 with KeyValueEntity

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

the class CustomValueGroupDatasource method loadData.

@Override
protected void loadData(Map<String, Object> params) {
    Collection<KeyValueEntity> entities = getEntities(params);
    detachListener(data.values());
    data.clear();
    if (entities != null) {
        for (KeyValueEntity entity : entities) {
            data.put(entity.getId(), entity);
            attachListener(entity);
            entity.setInstanceMetaClass(metaClass);
        }
    }
}
Also used : KeyValueEntity(io.jmix.core.entity.KeyValueEntity)

Example 3 with KeyValueEntity

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

the class CustomValueHierarchicalDatasource method loadData.

@Override
protected void loadData(Map<String, Object> params) {
    Collection<KeyValueEntity> entities = getEntities(params);
    detachListener(data.values());
    data.clear();
    if (entities != null) {
        for (KeyValueEntity entity : entities) {
            data.put(entity.getId(), entity);
            attachListener(entity);
            entity.setInstanceMetaClass(metaClass);
        }
    }
}
Also used : KeyValueEntity(io.jmix.core.entity.KeyValueEntity)

Example 4 with KeyValueEntity

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

the class ValueDatasourceDelegate method loadData.

protected void loadData(Map<String, Object> params) {
    if (ds.needLoading()) {
        ValueLoadContext context = beforeLoadValues(params);
        if (context == null) {
            return;
        }
        try {
            List<KeyValueEntity> entities = ds.dataSupplier.loadValues(context);
            afterLoadValues(params, context, entities);
        } catch (Throwable e) {
            ds.dataLoadError = e;
        }
    }
}
Also used : ValueLoadContext(com.haulmont.cuba.core.global.ValueLoadContext) KeyValueEntity(io.jmix.core.entity.KeyValueEntity)

Example 5 with KeyValueEntity

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

the class JmixTableFormatter method getTableData.

protected JmixTableData getTableData(TemplateTableDescription templateTableDescription, Map<String, List<KeyValueEntity>> transformedData, Map<String, Set<JmixTableData.ColumnInfo>> headerMap, Map<String, List<BandData>> childrenBands) {
    for (TemplateTableBand band : templateTableDescription.getTemplateTableBands()) {
        String bandName = band.getBandName();
        if (bandName.startsWith(HEADER_BAND_PREFIX)) {
            break;
        }
        List<BandData> bandDataList = childrenBands.get(bandName);
        if (bandDataList == null) {
            throw new ReportingException(String.format("Report template has an unknown band [%s]", bandName));
        }
        List<KeyValueEntity> entities = new ArrayList<>();
        Set<JmixTableData.ColumnInfo> headers = new LinkedHashSet<>();
        bandDataList.forEach(bandData -> {
            Map<String, Object> data = bandData.getData();
            final String pkName;
            final boolean pkInFetchPlan;
            if (data instanceof EntityMap) {
                Entity instance = ((EntityMap) data).getInstance();
                pkName = metadataTools.getPrimaryKeyName(metadata.getClass(instance));
                FetchPlan fetchPlan = ((EntityMap) data).getFetchPlan();
                pkInFetchPlan = fetchPlan != null && pkName != null && fetchPlan.containsProperty(pkName);
            } else {
                pkName = null;
                pkInFetchPlan = false;
            }
            KeyValueEntity entityRow = new KeyValueEntity();
            for (TemplateTableColumn column : band.getColumns()) {
                String key = column.getKey();
                Object value = data.get(key);
                if (INSTANCE_NAME_KEY.equals(key)) {
                    return;
                }
                if (checkAddHeader(pkName, pkInFetchPlan, key)) {
                    checkInstanceNameLoaded(value);
                    String transformationKey = transformationKey(key);
                    if (isFormat(bandName, key)) {
                        String formattedValue = getFormattedValue(bandName, key, value);
                        entityRow.setValue(transformationKey, formattedValue);
                    } else {
                        entityRow.setValue(transformationKey, value);
                    }
                }
            }
            if (headers.isEmpty() || headers.size() < data.size()) {
                for (TemplateTableColumn column : band.getColumns()) {
                    String key = column.getKey();
                    Object value = data.get(key);
                    if (INSTANCE_NAME_KEY.equals(key)) {
                        return;
                    }
                    if (checkAddHeader(pkName, pkInFetchPlan, key)) {
                        String transformationKey = transformationKey(key);
                        if (value != null) {
                            Class valueClass = getColumnClass(bandName, key, value);
                            headers.add(new JmixTableData.ColumnInfo(transformationKey, valueClass, column.getCaption(), column.getPosition()));
                        } else {
                            headers.add(new JmixTableData.ColumnInfo(transformationKey, String.class, column.getCaption(), column.getPosition()));
                        }
                    }
                }
            }
            entities.add(entityRow);
        });
        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) ReportingException(io.jmix.reports.exception.ReportingException) JmixTableData(io.jmix.reports.entity.JmixTableData) EntityMap(io.jmix.reports.app.EntityMap) TemplateTableColumn(io.jmix.reports.entity.table.TemplateTableColumn) TemplateTableBand(io.jmix.reports.entity.table.TemplateTableBand) KeyValueEntity(io.jmix.core.entity.KeyValueEntity) BandData(com.haulmont.yarg.structure.BandData)

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