use of com.haulmont.cuba.core.global.MetadataTools in project cuba by cuba-platform.
the class DynamicAttributesUtils method getDynamicAttributeValueAsString.
/**
* For collection dynamic attributes the method returns a list of formatted collection items joined with the comma,
* for non-collection dynamic attribute a formatted value is returned
*/
public static String getDynamicAttributeValueAsString(MetaProperty metaProperty, Object value) {
CategoryAttribute categoryAttribute = getCategoryAttribute(metaProperty);
MetadataTools metadataTools = AppBeans.get(MetadataTools.class);
if (categoryAttribute.getIsCollection()) {
if (value instanceof Collection) {
List<String> valuesList = ((Collection<Object>) value).stream().map(item -> metadataTools.format(item, metaProperty)).collect(Collectors.toList());
return Joiner.on(", ").join(valuesList);
}
}
return metadataTools.format(value, metaProperty);
}
use of com.haulmont.cuba.core.global.MetadataTools in project cuba by cuba-platform.
the class EntityImportView method addSystemProperties.
public EntityImportView addSystemProperties() {
Metadata metadata = AppBeans.get(Metadata.class);
MetaClass metaClass = metadata.getClassNN(entityClass);
MetadataTools metadataTools = metadata.getTools();
metaClass.getProperties().stream().filter(metadataTools::isSystem).forEach(metaProperty -> addLocalProperty(metaProperty.getName()));
return this;
}
use of com.haulmont.cuba.core.global.MetadataTools in project cuba by cuba-platform.
the class MetadataTest method testPersistentAndTransientProperties.
@Test
public void testPersistentAndTransientProperties() throws Exception {
MetadataTools tools = cont.metadata().getTools();
// User
MetaClass metaClass = cont.metadata().getSession().getClassNN(User.class);
assertTrue(tools.isPersistent(metaClass.getPropertyNN("id")));
assertTrue(tools.isPersistent(metaClass, metaClass.getPropertyNN("id")));
assertTrue(tools.isPersistent(metaClass.getPropertyNN("createTs")));
assertTrue(tools.isPersistent(metaClass.getPropertyNN("login")));
assertTrue(tools.isPersistent(metaClass.getPropertyNN("group")));
assertTrue(tools.isPersistent(metaClass.getPropertyNN("userRoles")));
// EntityLogItem
metaClass = cont.metadata().getSession().getClassNN(EntityLogItem.class);
assertTrue(tools.isPersistent(metaClass.getPropertyNN("user")));
assertFalse(tools.isPersistent(metaClass.getPropertyNN("attributes")));
assertTrue(tools.isNotPersistent(metaClass.getPropertyNN("attributes")));
// Folder
metaClass = cont.metadata().getSession().getClassNN(Folder.class);
assertTrue(tools.isPersistent(metaClass.getPropertyNN("name")));
assertTrue(tools.isNotPersistent(new Folder(), "itemStyle"));
// UserSessionEntity
metaClass = cont.metadata().getSession().getClassNN(UserSessionEntity.class);
// see JavaDocs on isPersistent() for the reason
assertTrue(tools.isPersistent(metaClass.getPropertyNN("id")));
assertTrue(tools.isNotPersistent(metaClass, metaClass.getPropertyNN("id")));
assertTrue(tools.isNotPersistent(metadata.create(metaClass), "id"));
assertTrue(tools.isNotPersistent(metaClass.getPropertyNN("login")));
assertTrue(tools.isNotPersistent(metaClass, metaClass.getPropertyNN("login")));
// TestTransientEntity
metaClass = cont.metadata().getSession().getClassNN(TestNotPersistentEntity.class);
// see JavaDocs on isPersistent() for the reason
assertTrue(tools.isPersistent(metaClass.getPropertyNN("id")));
assertTrue(tools.isNotPersistent(metaClass, metaClass.getPropertyNN("id")));
assertTrue(tools.isNotPersistent(metadata.create(metaClass), "id"));
assertTrue(tools.isNotPersistent(metaClass.getPropertyNN("name")));
assertTrue(tools.isNotPersistent(metaClass.getPropertyNN("info")));
assertTrue(tools.isNotPersistent(metaClass.getPropertyNN("embeddedRef")));
assertFalse(tools.isEmbedded(metaClass.getPropertyNN("embeddedRef")));
}
use of com.haulmont.cuba.core.global.MetadataTools in project cuba by cuba-platform.
the class WebAbstractField method initBeanValidator.
protected void initBeanValidator() {
MetadataTools metadataTools = AppBeans.get(MetadataTools.NAME);
MetaClass propertyEnclosingMetaClass = metadataTools.getPropertyEnclosingMetaClass(metaPropertyPath);
Class enclosingJavaClass = propertyEnclosingMetaClass.getJavaClass();
if (enclosingJavaClass != KeyValueEntity.class && !DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
BeanValidation beanValidation = AppBeans.get(BeanValidation.NAME);
javax.validation.Validator validator = beanValidation.getValidator();
BeanDescriptor beanDescriptor = validator.getConstraintsForClass(enclosingJavaClass);
if (beanDescriptor.isBeanConstrained()) {
addValidator(new BeanValidator(enclosingJavaClass, metaProperty.getName()));
}
}
}
use of com.haulmont.cuba.core.global.MetadataTools in project cuba by cuba-platform.
the class WebAbstractTextField method setValue.
@Override
public void setValue(Object value) {
if (!(value instanceof String)) {
String formattedValue;
Datatype<String> stringDatatype = Datatypes.getNN(String.class);
Datatype datatype = getActualDatatype();
if (datatype != null && stringDatatype != datatype) {
formattedValue = datatype.format(value, locale);
} else {
MetadataTools metadataTools = AppBeans.get(MetadataTools.NAME);
formattedValue = metadataTools.format(value);
}
super.setValue(formattedValue);
} else {
super.setValue(value);
}
}
Aggregations