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