use of io.jmix.core.metamodel.model.MetaClass in project jmix-docs by Haulmont.
the class CustomerService method printOrderProperties.
public void printOrderProperties() {
// <1>
MetaClass metaClass = metadata.getClass(Order.class);
for (MetaProperty metaProperty : metaClass.getProperties()) {
// <2>
// <3>
String propertyName = metaProperty.getName();
// <4>
MetaProperty.Type propertyType = metaProperty.getType();
// <5>
Class<?> javaType = metaProperty.getJavaType();
// <6>
Range propertyRange = metaProperty.getRange();
String info = "name: " + propertyName + "\n type: " + propertyType + "\n Java type: " + javaType + "\n range: " + propertyRange;
if (propertyRange.isClass()) {
// <7>
// <8>
MetaClass refMetaClass = propertyRange.asClass();
// <9>
Range.Cardinality cardinality = propertyRange.getCardinality();
info += "\n reference to: " + refMetaClass;
info += "\n cardinality: " + cardinality;
} else if (propertyRange.isEnum()) {
// <10>
// <11>
Enumeration<?> enumeration = propertyRange.asEnumeration();
info += "\n enum: " + enumeration;
} else if (propertyRange.isDatatype()) {
// <12>
// <13>
Datatype<Object> propertyDatatype = propertyRange.asDatatype();
info += "\n data type: " + propertyDatatype;
}
System.out.println(info);
}
}
use of io.jmix.core.metamodel.model.MetaClass in project jmix by jmix-framework.
the class EntityLoadInfoBuilder method contains.
/**
* Check whether an info about the given entity instance is contained in the collection.
*
* @param collection collection of EntityLoadInfo objects
* @param entity entity instance
* @return true if the collection contains an info about the given entity instance. View part of the info is ignored.
*/
public boolean contains(Collection<EntityLoadInfo> collection, Entity entity) {
Preconditions.checkNotNullArgument(collection, "collection is null");
Preconditions.checkNotNullArgument(entity, "entity is null");
MetaClass metaClass = metadata.getClass(entity.getClass());
for (EntityLoadInfo info : collection) {
if (metaClass.equals(info.getMetaClass()) && EntityValues.getId(entity).equals(info.getId()))
return true;
}
return false;
}
use of io.jmix.core.metamodel.model.MetaClass in project jmix by jmix-framework.
the class EntityLoadInfoBuilder method create.
/**
* Create a new info instance.
*
* @param entity entity instance
* @param viewName view name, can be null
* @return info instance
*/
public EntityLoadInfo create(Entity entity, @Nullable String viewName) {
Objects.requireNonNull(entity, "entity is null");
MetaClass metaClass = metadata.getSession().getClass(entity.getClass());
MetaProperty primaryKeyProperty = metadataTools.getPrimaryKeyProperty(metaClass);
boolean stringKey = primaryKeyProperty != null && primaryKeyProperty.getJavaType().equals(String.class);
return new EntityLoadInfo(EntityValues.getId(entity), metaClass, viewName, stringKey);
}
use of io.jmix.core.metamodel.model.MetaClass in project jmix by jmix-framework.
the class OriginalEntityLoadInfo method create.
/**
* Create a new info instance.
* @param entity entity instance
* @return info instance
*/
public static OriginalEntityLoadInfo create(Entity entity) {
Objects.requireNonNull(entity, "entity is null");
Metadata metadata = AppBeans.get(Metadata.class);
MetadataTools metadataTools = AppBeans.get(MetadataTools.class);
ExtendedEntities extendedEntities = AppBeans.get(ExtendedEntities.class);
MetaClass metaClass = metadata.getSession().getClass(entity.getClass());
MetaClass originalMetaClass = extendedEntities.getOriginalMetaClass(metaClass);
if (originalMetaClass != null) {
metaClass = originalMetaClass;
}
MetaProperty primaryKeyProperty = metadataTools.getPrimaryKeyProperty(metaClass);
boolean stringKey = primaryKeyProperty != null && primaryKeyProperty.getJavaType().equals(String.class);
return new OriginalEntityLoadInfo((UUID) EntityValues.getId(entity), metaClass, stringKey);
}
use of io.jmix.core.metamodel.model.MetaClass in project jmix by jmix-framework.
the class View method addSystemProperties.
public View addSystemProperties() {
io.jmix.core.Metadata metadata = AppBeans.get(Metadata.class);
MetadataTools metadataTools = AppBeans.get(MetadataTools.class);
MetaClass metaClass = metadata.getClass(getEntityClass());
for (String propertyName : metadataTools.getSystemProperties(metaClass)) {
addProperty(propertyName);
}
return this;
}
Aggregations