use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class AbstractDataGrid method addColumnInternal.
protected void addColumnInternal(ColumnImpl<E> column, int index) {
Grid.Column<E, ?> gridColumn = component.addColumn(new EntityValueProvider<>(column.getPropertyPath()));
columns.put(column.getId(), column);
columnsOrder.add(index, column);
final String caption = StringUtils.capitalize(column.getCaption() != null ? column.getCaption() : generateColumnCaption(column));
column.setCaption(caption);
if (column.getOwner() == null) {
column.setOwner(this);
}
MetaPropertyPath propertyPath = column.getPropertyPath();
if (propertyPath != null) {
MetaProperty metaProperty = propertyPath.getMetaProperty();
MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(propertyPath);
if (metadataTools.isLob(metaProperty) && !propertyMetaClass.getStore().supportsLobSortingAndFiltering()) {
column.setSortable(false);
}
}
setupGridColumnProperties(gridColumn, column);
component.setColumnOrder(getColumnOrder());
}
use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class EntityStates method checkLoadedWithFetchPlan.
protected void checkLoadedWithFetchPlan(Object entity, FetchPlan fetchPlan, Set visited) {
if (visited.contains(entity)) {
return;
}
visited.add(entity);
for (FetchPlanProperty property : fetchPlan.getProperties()) {
MetaClass metaClass = metadata.getClass(entity);
MetaProperty metaProperty = metaClass.getProperty(property.getName());
if (!isLoaded(entity, property.getName())) {
String errorMessage = String.format("%s.%s is not loaded", entity.getClass().getSimpleName(), property.getName());
throw new IllegalArgumentException(errorMessage);
}
if (metaProperty.getRange().isClass()) {
FetchPlan propertyFetchPlan = property.getFetchPlan();
if (propertyFetchPlan != null && metadataTools.isJpa(metaProperty)) {
Object value = EntityValues.getValue(entity, metaProperty.getName());
if (value != null) {
if (!metaProperty.getRange().getCardinality().isMany()) {
checkLoadedWithFetchPlan(value, propertyFetchPlan, visited);
} else {
@SuppressWarnings("unchecked") Collection collection = (Collection) value;
for (Object item : collection) {
checkLoadedWithFetchPlan(item, propertyFetchPlan, visited);
}
}
}
}
}
}
// after check we remove item from visited because different subtrees may have different fetch plan for the same instance
visited.remove(entity);
}
use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class EntityStates method recursivelyConstructCurrentFetchPlan.
protected void recursivelyConstructCurrentFetchPlan(Entity entity, FetchPlanBuilder builder, HashSet<Object> visited) {
if (visited.contains(entity))
return;
visited.add(entity);
// Using MetaClass of the fetchPlan helps in the case when the entity is an item of a collection, and the collection
// can contain instances of different subclasses. So we don't want to add specific properties of subclasses
// to the resulting fetch plan.
MetaClass metaClass = metadata.getClass(builder.getEntityClass());
for (MetaProperty property : metaClass.getProperties()) {
if (!isLoaded(entity, property.getName()))
continue;
if (property.getRange().isClass()) {
FetchPlanBuilder propertyBuilder = fetchPlans.builder(property.getRange().asClass().getJavaClass());
// The input object graph can be large, so we use FetchMode.UNDEFINED to avoid huge SQLs with
// unpredictably high number of joins
builder.add(property.getName(), propertyBuilder, FetchMode.UNDEFINED);
if (isLoaded(entity, property.getName())) {
Object value = EntityValues.getValue(entity, property.getName());
if (value != null) {
if (value instanceof Collection) {
for (Object item : ((Collection) value)) {
recursivelyConstructCurrentFetchPlan((Entity) item, propertyBuilder, visited);
}
} else {
recursivelyConstructCurrentFetchPlan((Entity) value, propertyBuilder, visited);
}
}
}
} else {
builder.add(property.getName());
}
}
}
use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class Param method loadEntity.
protected Object loadEntity(String id) {
MetaProperty primaryKey = metadata.getTools().getPrimaryKeyProperty(metadata.getClassNN(javaClass));
Object objectId = null;
if (primaryKey != null) {
try {
objectId = primaryKey.getRange().asDatatype().parse(id);
} catch (ParseException e) {
throw new RuntimeException("Error parsing entity ID", e);
}
}
// noinspection unchecked
return dataManager.load(javaClass).fetchPlan(FetchPlan.BASE).id(objectId).optional().orElse(null);
}
use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class AddAction method isPermitted.
@Override
protected boolean isPermitted() {
if (target == null || target.getDatasource() == null) {
return false;
}
CollectionDatasource ownerDs = target.getDatasource();
if (ownerDs instanceof PropertyDatasource) {
PropertyDatasource datasource = (PropertyDatasource) ownerDs;
MetaClass parentMetaClass = datasource.getMaster().getMetaClass();
MetaProperty metaProperty = datasource.getProperty();
boolean attrPermitted = security.isEntityAttrPermitted(parentMetaClass, metaProperty.getName(), EntityAttrAccess.MODIFY);
if (!attrPermitted) {
return false;
}
}
return super.isPermitted();
}
Aggregations