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);
}
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;
}
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);
}
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);
}
Aggregations