use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class DomainModelBuilder method produce.
public DomainModel produce() {
Collection<MetaClass> classes = metadata.getSession().getClasses();
DomainModel result = new DomainModel(extendedEntities, metadata);
EntityBuilder builder = EntityBuilder.create();
for (MetaClass aClass : classes) {
builder.startNewEntity(aClass.getName());
Collection<MetaProperty> props = aClass.getProperties();
for (MetaProperty prop : props) {
if (metadataTools.isJpa(prop))
addProperty(builder, aClass, prop);
}
JpqlEntityModel entity = builder.produce();
result.add(entity);
}
return result;
}
use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class PivotScreenBuilder method getEmbeddedIdProperties.
protected List<String> getEmbeddedIdProperties(MetaClass metaClass) {
List<String> result = new ArrayList<>();
if (hasEmbeddedId(metaClass)) {
MetaClass embeddedMetaClass = getEmbeddedIdMetaClass(metaClass);
if (embeddedMetaClass == null) {
return null;
}
String primaryKey = metadataTools.getPrimaryKeyName(metaClass);
for (MetaProperty metaProperty : embeddedMetaClass.getOwnProperties()) {
result.add(primaryKey + "." + metaProperty.getName());
}
}
return result;
}
use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class PivotScreenBuilder method removeNonExistingProperties.
protected List<String> removeNonExistingProperties(List<String> properties, MetaClass metaClass, FetchPlan fetchPlan) {
if (!metadataTools.isJpaEntity(metaClass)) {
return properties.stream().filter(s -> metaClass.getPropertyPath(s) != null).collect(Collectors.toList());
}
List<String> result = new ArrayList<>();
fetchPlan = fetchPlan == null ? getBaseFetchPlan(metaClass) : fetchPlan;
for (String property : properties) {
MetaPropertyPath mpp = metaClass.getPropertyPath(property);
if (mpp != null && metadataTools.fetchPlanContainsProperty(fetchPlan, mpp)) {
result.add(property);
// simple property
} else if (fetchPlan.containsProperty(property)) {
result.add(property);
// id property
} else if (isIdProperty(property, metaClass)) {
result.add(property);
// EmbeddedId's property
} else if (hasEmbeddedId(metaClass) && isEmbeddedIdProperty(property, metaClass)) {
result.add(property);
// if metaClass contains property path, we need to check nested entities in fetch plan
} else if (mpp != null) {
for (MetaProperty metaProperty : mpp.getMetaProperties()) {
MetaClass propertyMetaClass = getPropertyMetaClass(metaProperty);
if (propertyMetaClass == null) {
propertyMetaClass = metaClass;
}
// EmbeddedId's property
if (isEmbeddedIdProperty(property, propertyMetaClass)) {
result.add(property);
// Id property
} else if (isIdProperty(metaProperty.getName(), propertyMetaClass)) {
result.add(property);
}
}
}
}
return result;
}
use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class PivotScreenBuilder method isEmbeddedIdProperty.
protected boolean isEmbeddedIdProperty(String property, MetaClass metaClass) {
MetaClass embeddedMetaClass = getEmbeddedIdMetaClass(metaClass);
if (embeddedMetaClass == null) {
return false;
}
String[] propertyPathParts = property.split("\\.");
String propertyName = propertyPathParts[propertyPathParts.length - 1];
MetaProperty metaProperty = embeddedMetaClass.getProperty(propertyName);
return embeddedMetaClass.getOwnProperties().contains(metaProperty);
}
use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class EditorBuilderProcessor method initEntity.
@Nullable
protected <E> E initEntity(EditorBuilder<E> builder, @Nullable CollectionContainer<E> container) {
E entity;
boolean oneToOneComposition = false;
EntityValueSource entityValueSource = null;
HasValue<E> field = builder.getField();
if (field instanceof HasValueSource) {
ValueSource valueSource = ((HasValueSource) field).getValueSource();
if (valueSource instanceof EntityValueSource) {
entityValueSource = (EntityValueSource) valueSource;
oneToOneComposition = isCompositionProperty(entityValueSource);
}
}
if (builder.getMode() == EditMode.CREATE || (oneToOneComposition && field.getValue() == null)) {
if (builder.getNewEntity() == null) {
entity = metadata.create(builder.getEntityClass());
} else {
entity = builder.getNewEntity();
}
if (container instanceof Nested) {
initializeNestedEntity(entity, (Nested) container);
}
if (oneToOneComposition) {
Object ownerEntity = entityValueSource.getItem();
MetaProperty inverseProp = entityValueSource.getMetaPropertyPath().getMetaProperty().getInverse();
if (inverseProp != null) {
EntityValues.setValue(entity, inverseProp.getName(), ownerEntity);
}
}
if (builder.getInitializer() != null) {
builder.getInitializer().accept(entity);
}
} else {
entity = builder.getEditedEntity();
}
return entity;
}
Aggregations