use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class RelatedEntitiesSupportImpl method getMetaProperty.
protected MetaProperty getMetaProperty(RelatedEntitiesBuilder builder, MetaClass metaClass) {
MetaProperty metaProperty = builder.getMetaProperty();
if (metaProperty != null) {
return metaProperty;
}
String property = builder.getProperty();
if (!Strings.isNullOrEmpty(property)) {
return metaClass.getProperty(property);
}
throw new IllegalStateException("'metaProperty' or 'property' can't be null");
}
use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class RelatedEntitiesSupportImpl method buildScreen.
protected Screen buildScreen(RelatedEntitiesBuilder builder) {
MetaClass metaClass = getMetaClass(builder);
MetaProperty metaProperty = getMetaProperty(builder, metaClass);
Screen screen = createScreen(builder, metaClass, metaProperty);
boolean found = ComponentsHelper.walkComponents(screen.getWindow(), screenComponent -> {
if (screenComponent instanceof Filter) {
Filter filter = (Filter) screenComponent;
DataLoader dataLoader = filter.getDataLoader();
MetaClass actualMetaClass = dataLoader.getContainer().getEntityMetaClass();
MetaClass relatedMetaClass = metaProperty.getRange().asClass();
MetaClass effectiveMetaClass = extendedEntities.getEffectiveMetaClass(relatedMetaClass);
if (Objects.equals(actualMetaClass, effectiveMetaClass)) {
Collection selectedEntities = builder.getSelectedEntities() == null ? Collections.emptyList() : builder.getSelectedEntities();
String configurationName = generateConfigurationName(builder, metaProperty);
DesignTimeConfiguration configuration = createFilterConfiguration((Filter) screenComponent, configurationName);
JpqlFilter jpqlFilter = createJpqlFilter(filter.getDataLoader(), metaProperty, metaClass, selectedEntities);
configuration.getRootLogicalFilterComponent().add(jpqlFilter);
configuration.setFilterComponentDefaultValue(jpqlFilter.getParameterName(), jpqlFilter.getValue());
filter.setCurrentConfiguration(configuration);
return true;
}
}
return false;
});
if (!found) {
screen.addAfterShowListener(event -> {
ScreenContext screenContext = UiControllerUtils.getScreenContext(event.getSource());
screenContext.getNotifications().create(Notifications.NotificationType.WARNING).withCaption(messages.getMessage("actions.Related.FilterNotFound")).show();
});
}
return screen;
}
use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class BulkEditorWindow method createView.
/**
* Creates a view, loading only necessary properties.
* Referenced entities will be loaded with a MINIMAL view.
*
* @param meta meta class
* @return View instance
*/
protected View createView(MetaClass meta) {
View view = new View(meta.getJavaClass(), false);
for (MetaProperty metaProperty : meta.getProperties()) {
if (!managedFields.containsKey(metaProperty.getName()) && !managedEmbeddedProperties.contains(metaProperty.getName())) {
continue;
}
switch(metaProperty.getType()) {
case DATATYPE:
case ENUM:
view.addProperty(metaProperty.getName());
break;
case EMBEDDED:
{
// build view for embedded property
FetchPlan propView = createEmbeddedView(metaProperty.getRange().asClass(), metaProperty.getName());
view.addProperty(metaProperty.getName(), propView);
break;
}
case ASSOCIATION:
case COMPOSITION:
FetchPlan propView = viewRepository.getView(metaProperty.getRange().asClass(), View.MINIMAL);
// in some cases JPA loads extended entities as instance of base class which leads to ClassCastException
// loading property lazy prevents this from happening
view.addProperty(metaProperty.getName(), propView);
break;
default:
throw new IllegalStateException("unknown property type");
}
}
return view;
}
use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class BulkEditorWindow method createEmbeddedView.
protected View createEmbeddedView(MetaClass meta, String fqnPrefix) {
View view = new View(meta.getJavaClass(), false);
for (MetaProperty metaProperty : meta.getProperties()) {
String fqn = fqnPrefix + "." + metaProperty.getName();
if (!managedFields.containsKey(fqn)) {
continue;
}
switch(metaProperty.getType()) {
case DATATYPE:
case ENUM:
view.addProperty(metaProperty.getName());
break;
case EMBEDDED:
{
FetchPlan propView = createEmbeddedView(metaProperty.getRange().asClass(), fqn);
view.addProperty(metaProperty.getName(), propView);
break;
}
case ASSOCIATION:
case COMPOSITION:
FetchPlan propView = viewRepository.getView(metaProperty.getRange().asClass(), View.MINIMAL);
// in some cases JPA loads extended entities as instance of base class which leads to ClassCastException
// loading property lazy prevents this from happening
view.addProperty(metaProperty.getName(), propView);
break;
default:
throw new IllegalStateException("unknown property type");
}
}
return view;
}
use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class BulkEditorWindow method createNestedEmbeddedDatasources.
protected void createNestedEmbeddedDatasources(Datasource masterDs, MetaClass metaClass, String fqnPrefix) {
for (MetaProperty metaProperty : metaClass.getProperties()) {
if (MetaProperty.Type.ASSOCIATION == metaProperty.getType() || MetaProperty.Type.COMPOSITION == metaProperty.getType() || MetaProperty.Type.EMBEDDED == metaProperty.getType()) {
String fqn = metaProperty.getName();
if (StringUtils.isNotEmpty(fqnPrefix)) {
fqn = fqnPrefix + "." + fqn;
}
if (managedEmbeddedProperties.contains(fqn) && metadataTools.isEmbedded(metaProperty)) {
MetaClass propertyMetaClass = metaProperty.getRange().asClass();
@SuppressWarnings("unchecked") NestedDatasource<Entity> propertyDs = new EmbeddedDatasourceImpl();
propertyDs.setup(fqn + "Ds", masterDs, metaProperty.getName());
propertyDs.setAllowCommit(false);
createNestedEmbeddedDatasources(propertyDs, propertyMetaClass, fqn);
datasources.put(fqn, propertyDs);
dsContext.register(propertyDs);
}
}
}
}
Aggregations