use of io.jmix.reports.entity.JmixTableData 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 io.jmix.reports.entity.JmixTableData in project jmix by jmix-framework.
the class JmixTableFormatter method transformData.
protected JmixTableData transformData(BandData rootBand) {
TemplateTableDescription templateTableDescription = ((ReportTemplate) reportTemplate).getTemplateTableDescription();
Map<String, List<KeyValueEntity>> transformedData = new LinkedHashMap<>();
Map<String, Set<JmixTableData.ColumnInfo>> headerMap = new HashMap<>();
Map<String, List<BandData>> childrenBands = rootBand.getChildrenBands();
if (templateTableDescription.getTemplateTableBands().size() > 0) {
return getTableData(templateTableDescription, transformedData, headerMap, childrenBands);
} else {
return getTableData(transformedData, headerMap, childrenBands);
}
}
use of io.jmix.reports.entity.JmixTableData in project jmix by jmix-framework.
the class JmixTableFormatter method renderDocument.
@Override
public void renderDocument() {
JmixTableData dto = transformData(rootBand);
byte[] serializedData = standardSerialization.serialize(dto);
try {
IOUtils.write(serializedData, outputStream);
} catch (IOException e) {
throw new RuntimeException("An error occurred while rendering chart", e);
}
}
use of io.jmix.reports.entity.JmixTableData 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);
}
use of io.jmix.reports.entity.JmixTableData in project jmix by jmix-framework.
the class ShowReportTableScreen method drawTables.
protected void drawTables(JmixTableData dto) {
Map<String, List<KeyValueEntity>> data = dto.getData();
Map<String, Set<JmixTableData.ColumnInfo>> headerMap = dto.getHeaders();
tablesVBoxLayout.removeAll();
if (data == null || data.isEmpty())
return;
data.forEach((dataSetName, keyValueEntities) -> {
if (CollectionUtils.isNotEmpty(keyValueEntities)) {
KeyValueCollectionContainer container = createContainer(dataSetName, keyValueEntities, headerMap);
Table table = createTable(dataSetName, container, headerMap);
GroupBoxLayout groupBox = uiComponents.create(GroupBoxLayout.class);
groupBox.setCaption(dataSetName);
groupBox.add(table);
groupBox.expand(table);
tablesVBoxLayout.add(groupBox);
tablesVBoxLayout.expand(groupBox);
}
});
}
Aggregations