use of io.jmix.dynattr.DynamicAttributesState in project jmix by jmix-framework.
the class DynAttrEntityStateInitializer method initEntity.
@Override
public void initEntity(Object entity) {
DynamicAttributesState state = new DynamicAttributesState(getEntityEntry(entity));
state.setDynamicAttributes(new DynamicAttributes());
addExtraState(entity, state);
}
use of io.jmix.dynattr.DynamicAttributesState in project jmix by jmix-framework.
the class DynAttrLifecycleListener method entityReload.
@Override
public void entityReload(DataStoreEntityReloadEvent event) {
LoadContext<?> loadContext = event.getLoadContext();
SaveContext saveContext = event.getSaveContext();
Object entity = saveContext.getEntitiesToSave().stream().filter(e -> Objects.equals(EntityValues.getId(e), loadContext.getId())).findFirst().orElse(null);
DynamicAttributesState state = getExtraState(entity, DynamicAttributesState.class);
if (state != null) {
DynamicAttributes dynamicAttributes = state.getDynamicAttributes();
if (dynamicAttributes != null) {
loadContext.setHint(DynAttrQueryHints.LOAD_DYN_ATTR, true);
}
}
}
use of io.jmix.dynattr.DynamicAttributesState in project jmix by jmix-framework.
the class DynAttrAwareEntityTransformer method transformForCollectionContainer.
@Override
public <E> E transformForCollectionContainer(E editedEntity, CollectionContainer<E> container) {
boolean needDynamicAttributes = false;
boolean dynamicAttributesAreLoaded = true;
DynamicAttributesState state = EntitySystemAccess.getExtraState(editedEntity, DynamicAttributesState.class);
if (state != null) {
dynamicAttributesAreLoaded = state.getDynamicAttributes() != null;
}
if (container instanceof HasLoader) {
DataLoader loader = ((HasLoader) container).getLoader();
if (loader instanceof CollectionLoader) {
Map<String, Serializable> hints = loader.getHints();
needDynamicAttributes = hints != null && Boolean.TRUE.equals(hints.get(DynAttrQueryHints.LOAD_DYN_ATTR));
}
}
FetchPlan fetchPlan = container.getFetchPlan();
if (fetchPlan != null && !entityStates.isLoadedWithFetchPlan(editedEntity, fetchPlan)) {
return dataManager.load(Id.of(editedEntity)).fetchPlan(fetchPlan).hint(DynAttrQueryHints.LOAD_DYN_ATTR, needDynamicAttributes).one();
} else if (needDynamicAttributes && !dynamicAttributesAreLoaded) {
dynAttrManager.loadValues(Collections.singletonList(editedEntity), fetchPlan, accessConstraintsRegistry.getConstraints());
return editedEntity;
} else {
return editedEntity;
}
}
use of io.jmix.dynattr.DynamicAttributesState in project jmix by jmix-framework.
the class AttributeRecalculationManager method evaluateNewValue.
protected Object evaluateNewValue(Object entity, String script) {
Map<String, Object> values = new HashMap<>();
DynamicAttributesState extraState = EntitySystemAccess.getExtraState(entity, DynamicAttributesState.class);
if (extraState != null && extraState.getDynamicAttributes() != null) {
DynamicAttributes dynamicAttributes = extraState.getDynamicAttributes();
for (String key : dynamicAttributes.getKeys()) {
values.put(key, dynamicAttributes.getValue(key));
}
}
Map<String, Object> params = new HashMap<>();
params.put("entity", entity);
params.put("dynamicAttributes", values);
return scriptEvaluator.evaluate(new StaticScriptSource(script), params);
}
Aggregations