Search in sources :

Example 1 with BandData

use of com.haulmont.yarg.structure.BandData in project jmix by jmix-framework.

the class ChartFormatter method convertPieChart.

protected String convertPieChart(PieChartDescription description) {
    List<Map<String, Object>> data = new ArrayList<>();
    List<BandData> childrenByName = rootBand.getChildrenByName(description.getBandName());
    for (BandData bandData : childrenByName) {
        data.add(bandData.getData());
    }
    return beanFactory.getBean(ChartToJsonConverter.class, metadataTools.getInstanceName(((ReportTemplate) reportTemplate).getReport())).convertPieChart(description, data);
}
Also used : ArrayList(java.util.ArrayList) Map(java.util.Map) BandData(com.haulmont.yarg.structure.BandData)

Example 2 with BandData

use of com.haulmont.yarg.structure.BandData in project jmix by jmix-framework.

the class JmixHtmlFormatter method getBandModel.

@Override
protected Map getBandModel(BandData band) {
    Map<String, Object> model = new HashMap<>();
    Map<String, Object> bands = new HashMap<>();
    for (String bandName : band.getChildrenBands().keySet()) {
        List<BandData> subBands = band.getChildrenBands().get(bandName);
        List<Map> bandModels = new ArrayList<>();
        for (BandData child : subBands) bandModels.add(getBandModel(child));
        bands.put(bandName, bandModels);
    }
    model.put("bands", bands);
    Map<String, Object> data = new HashMap<>();
    for (String key : band.getData().keySet()) {
        if (band.getData().get(key) instanceof Enum)
            data.put(key, defaultFormat(band.getData().get(key)));
        else
            data.put(key, band.getData().get(key));
    }
    model.put("fields", data);
    return model;
}
Also used : BandData(com.haulmont.yarg.structure.BandData)

Example 3 with BandData

use of com.haulmont.yarg.structure.BandData 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)

Example 4 with BandData

use of com.haulmont.yarg.structure.BandData in project jmix by jmix-framework.

the class ChartFormatter method convertSerialChart.

private String convertSerialChart(SerialChartDescription description) {
    List<Map<String, Object>> data = new ArrayList<>();
    List<BandData> childrenByName = rootBand.getChildrenByName(description.getBandName());
    for (BandData bandData : childrenByName) {
        data.add(bandData.getData());
    }
    return beanFactory.getBean(ChartToJsonConverter.class, metadataTools.getInstanceName(((ReportTemplate) reportTemplate).getReport())).convertSerialChart(description, data);
}
Also used : ArrayList(java.util.ArrayList) Map(java.util.Map) BandData(com.haulmont.yarg.structure.BandData)

Aggregations

BandData (com.haulmont.yarg.structure.BandData)4 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 KeyValueEntity (io.jmix.core.entity.KeyValueEntity)1 EntityMap (io.jmix.reports.app.EntityMap)1 JmixTableData (io.jmix.reports.entity.JmixTableData)1 TemplateTableBand (io.jmix.reports.entity.table.TemplateTableBand)1 TemplateTableColumn (io.jmix.reports.entity.table.TemplateTableColumn)1 ReportingException (io.jmix.reports.exception.ReportingException)1