Search in sources :

Example 11 with Metadata

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;
    }
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) Metadata(com.haulmont.cuba.core.global.Metadata) MetaClass(com.haulmont.chile.core.model.MetaClass)

Example 12 with Metadata

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));
}
Also used : ViewRepository(com.haulmont.cuba.core.global.ViewRepository) UserRole(com.haulmont.cuba.security.entity.UserRole) Metadata(com.haulmont.cuba.core.global.Metadata) View(com.haulmont.cuba.core.global.View)

Example 13 with Metadata

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);
}
Also used : ExtendedEntities(com.haulmont.cuba.core.global.ExtendedEntities) Metadata(com.haulmont.cuba.core.global.Metadata)

Example 14 with Metadata

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);
    }
}
Also used : RestorablePermissionDatasource(com.haulmont.cuba.gui.app.security.ds.RestorablePermissionDatasource) PermissionVariant(com.haulmont.cuba.gui.app.security.entity.PermissionVariant) AttributePermissionVariant(com.haulmont.cuba.gui.app.security.entity.AttributePermissionVariant) Datasource(com.haulmont.cuba.gui.data.Datasource) PermissionType(com.haulmont.cuba.security.entity.PermissionType) RestorablePermissionDatasource(com.haulmont.cuba.gui.app.security.ds.RestorablePermissionDatasource) UUID(java.util.UUID) AppBeans(com.haulmont.cuba.core.global.AppBeans) Metadata(com.haulmont.cuba.core.global.Metadata) Objects(java.util.Objects) UiPermissionVariant(com.haulmont.cuba.gui.app.security.entity.UiPermissionVariant) Permission(com.haulmont.cuba.security.entity.Permission) Role(com.haulmont.cuba.security.entity.Role) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Permission(com.haulmont.cuba.security.entity.Permission) Metadata(com.haulmont.cuba.core.global.Metadata)

Example 15 with Metadata

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));
}
Also used : Messages(com.haulmont.cuba.core.global.Messages) MetaClass(com.haulmont.chile.core.model.MetaClass) Metadata(com.haulmont.cuba.core.global.Metadata)

Aggregations

Metadata (com.haulmont.cuba.core.global.Metadata)25 MetaClass (com.haulmont.chile.core.model.MetaClass)6 PostConstruct (javax.annotation.PostConstruct)3 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)2 EntityManager (com.haulmont.cuba.core.EntityManager)2 Transaction (com.haulmont.cuba.core.Transaction)2 AppBeans (com.haulmont.cuba.core.global.AppBeans)2 ExtendedEntities (com.haulmont.cuba.core.global.ExtendedEntities)2 MetadataTools (com.haulmont.cuba.core.global.MetadataTools)2 FilterEntity (com.haulmont.cuba.security.entity.FilterEntity)2 Collection (java.util.Collection)2 Before (org.junit.Before)2 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)1 Config (com.haulmont.cuba.core.entity.Config)1 Entity (com.haulmont.cuba.core.entity.Entity)1 ReferenceToEntity (com.haulmont.cuba.core.entity.ReferenceToEntity)1 Messages (com.haulmont.cuba.core.global.Messages)1 Scripting (com.haulmont.cuba.core.global.Scripting)1 View (com.haulmont.cuba.core.global.View)1 ViewRepository (com.haulmont.cuba.core.global.ViewRepository)1