use of io.jmix.core.entity.KeyValueEntity 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.core.entity.KeyValueEntity in project jmix by jmix-framework.
the class KeyValueCollectionLoaderImpl method load.
@Override
public void load() {
if (container == null)
throw new IllegalStateException("container is null");
if (query == null && delegate == null)
throw new IllegalStateException("both query and delegate are null");
ValueLoadContext loadContext = createLoadContext();
if (!sendPreLoadEvent(loadContext)) {
return;
}
List<KeyValueEntity> list;
if (delegate == null) {
list = dataManager.loadValues(loadContext);
} else {
list = delegate.apply(loadContext);
}
if (dataContext != null) {
List<KeyValueEntity> mergedList = new ArrayList<>(list.size());
for (KeyValueEntity entity : list) {
mergedList.add(dataContext.merge(entity));
}
container.setItems(mergedList);
} else {
container.setItems(list);
}
sendPostLoadEvent(list);
}
use of io.jmix.core.entity.KeyValueEntity in project jmix by jmix-framework.
the class CorePersistentAttributesLoadChecker method isLoaded.
@Override
public boolean isLoaded(Object entity, String property) {
if (entity instanceof KeyValueEntity) {
KeyValueEntity keyValue = (KeyValueEntity) entity;
return keyValue.getInstanceMetaClass() != null && keyValue.getInstanceMetaClass().findProperty(property) != null;
}
MetaClass metaClass = metadata.getClass(entity.getClass());
if (ObjectPathUtils.isSpecialPath(property)) {
return metadataTools.isAdditionalProperty(metaClass, property);
}
MetaProperty metaProperty = metaClass.getProperty(property);
if (!metadataTools.isJpa(metaProperty)) {
List<String> dependsOnProperties = metadataTools.getDependsOnProperties(metaProperty);
if (dependsOnProperties.isEmpty()) {
return true;
} else {
for (String relatedProperty : dependsOnProperties) {
if (!isLoaded(entity, relatedProperty))
return false;
}
return true;
}
}
PropertyLoadedState isLoaded = isLoadedCommonCheck(entity, property);
if (isLoaded != PropertyLoadedState.UNKNOWN) {
return isLoaded == PropertyLoadedState.YES;
}
return isLoadedSpecificCheck(entity, property, metaClass, metaProperty);
}
use of io.jmix.core.entity.KeyValueEntity in project jmix by jmix-framework.
the class OrderBasedEntityIdsLoader method loadNextIds.
@Override
public ResultHolder loadNextIds(EnqueueingSession session, int batchSize) {
String entityName = session.getEntityName();
MetaClass entityClass = metadata.getClass(entityName);
String orderingPropertyName = session.getOrderingProperty();
MetaProperty orderingProperty = entityClass.getProperty(orderingPropertyName);
String lastProcessedRawOrderingValue = session.getLastProcessedValue();
MetaProperty primaryKeyProperty = metadataTools.getPrimaryKeyProperty(entityClass);
if (primaryKeyProperty == null) {
throw new RuntimeException(String.format("Entity '%s' doesn't have primary key", entityName));
}
String primaryKeyPropertyName = primaryKeyProperty.getName();
ResultHolder result;
if (metadataTools.isEmbedded(orderingProperty)) {
log.warn("Sorted loading by embedded property is not supported - perform in-memory loading of all ids");
result = loadAllInMemory(entityClass);
} else {
Object lastProcessedValue = convertRawValue(orderingProperty, lastProcessedRawOrderingValue);
ValueLoadContext valueLoadContext = createValueLoadContext(entityClass, primaryKeyPropertyName, orderingPropertyName, lastProcessedValue, batchSize);
List<KeyValueEntity> loadedValues = loadValues(valueLoadContext);
List<Object> ids = loadedValues.stream().map(v -> v.getValue("objectId")).collect(Collectors.toList());
Object lastLoadedOrderingValue = resolveLastLoadedOrderingValue(loadedValues, primaryKeyPropertyName, orderingPropertyName);
result = new ResultHolder(ids, lastLoadedOrderingValue);
}
return result;
}
use of io.jmix.core.entity.KeyValueEntity in project jmix by jmix-framework.
the class EntityListValueFragment method removeEntityValue.
@Subscribe("entitiesTable.remove")
public void removeEntityValue(Action.ActionPerformedEvent event) {
KeyValueEntity item = entitiesDc.getItemOrNull();
if (item != null) {
entitiesDc.getMutableItems().remove(item);
tableValues.remove(item);
}
}
Aggregations