use of com.haulmont.cuba.core.global.Metadata in project cuba by cuba-platform.
the class EntitySerializationExceptionHandler method isEntityClass.
private boolean isEntityClass(String className) {
Metadata metadata = AppBeans.get(Metadata.NAME);
try {
Class entityClass = ReflectionHelper.loadClass(className);
MetaClass metaClass = metadata.getClass(entityClass);
return metaClass != null;
} catch (ClassNotFoundException e) {
return false;
}
}
use of com.haulmont.cuba.core.global.Metadata in project cuba by cuba-platform.
the class SerializationTest method getView.
protected View getView() {
Metadata metadata = AppBeans.get(Metadata.NAME);
ViewRepository viewRepository = metadata.getViewRepository();
View userLocalView = viewRepository.getView(User.class, View.LOCAL);
View roleLocalView = viewRepository.getView(Role.class, View.LOCAL);
return new View(userLocalView, "test", true).addProperty("group", viewRepository.getView(Group.class, View.LOCAL)).addProperty("userRoles", new View(UserRole.class).addProperty("user", userLocalView).addProperty("role", roleLocalView));
}
use of com.haulmont.cuba.core.global.Metadata in project cuba by cuba-platform.
the class WebTokenList method isInversePropertyAssignableFromDsClass.
protected boolean isInversePropertyAssignableFromDsClass(MetaProperty inverseProp) {
Metadata metadata = AppBeans.get(Metadata.NAME);
ExtendedEntities extendedEntities = metadata.getExtendedEntities();
Class inversePropClass = extendedEntities.getEffectiveClass(inverseProp.getDomain());
Class dsClass = extendedEntities.getEffectiveClass(datasource.getMetaClass());
// noinspection unchecked
return inversePropClass.isAssignableFrom(dsClass);
}
use of com.haulmont.cuba.core.global.Metadata in project cuba by cuba-platform.
the class PermissionUiHelper method createPermissionItem.
/**
* Add or edit permission item in datasource
* @param ds Datasource
* @param roleDs Role datasource
* @param permissionTarget Permission identifier
* @param type Permission type
* @param value Permission value
*/
public static void createPermissionItem(CollectionDatasource<Permission, UUID> ds, Datasource<Role> roleDs, final String permissionTarget, PermissionType type, Integer value) {
Permission permission = null;
for (Permission p : ds.getItems()) {
if (Objects.equals(p.getTarget(), permissionTarget)) {
permission = p;
break;
}
}
if (permission == null) {
// restore entity instead of create
if (ds instanceof RestorablePermissionDatasource) {
RestorablePermissionDatasource datasource = (RestorablePermissionDatasource) ds;
permission = datasource.findRemovedEntity(p -> p != null && Objects.equals(p.getTarget(), permissionTarget));
if (permission != null) {
datasource.restoreEntity(permission);
}
}
}
if (permission == null) {
Metadata metadata = AppBeans.get(Metadata.NAME);
Permission newPermission = metadata.create(Permission.class);
newPermission.setRole(roleDs.getItem());
newPermission.setTarget(permissionTarget);
newPermission.setType(type);
newPermission.setValue(value);
ds.addItem(newPermission);
} else {
permission.setValue(value);
}
}
use of com.haulmont.cuba.core.global.Metadata in project cuba by cuba-platform.
the class BeanValidator method getDefaultErrorMessage.
public String getDefaultErrorMessage() {
Messages messages = AppBeans.get(Messages.NAME);
Metadata metadata = AppBeans.get(Metadata.NAME);
MetaClass metaClass = metadata.getClass(beanClass);
return messages.formatMainMessage("validation.defaultMsg", messages.getTools().getPropertyCaption(metaClass, beanProperty));
}
Aggregations