Search in sources :

Example 1 with ViewRepository

use of com.haulmont.cuba.core.global.ViewRepository 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) Metadata(com.haulmont.cuba.core.global.Metadata) View(com.haulmont.cuba.core.global.View)

Example 2 with ViewRepository

use of com.haulmont.cuba.core.global.ViewRepository in project cuba by cuba-platform.

the class LoadSubstitutionsTest method testQuerySubstitutions.

@Test
public void testQuerySubstitutions() throws Exception {
    ViewRepository viewRepository = AppBeans.get(ViewRepository.NAME);
    View userView = new View(new View.ViewParams().src(viewRepository.getView(User.class, View.LOCAL)));
    View substitutedUserView = new View(User.class);
    substitutedUserView.addProperty("login");
    View substitutionsView = new View(UserSubstitution.class);
    substitutionsView.addProperty("substitutedUser", substitutedUserView);
    substitutionsView.addProperty("startDate");
    userView.addProperty("substitutions", substitutionsView);
    User loadedUser;
    try (Transaction tx = cont.persistence().createTransaction()) {
        EntityManager em = cont.persistence().getEntityManager();
        loadedUser = em.find(User.class, user.getId(), userView);
        tx.commit();
    }
    assertNotNull(loadedUser);
    assertNotNull(loadedUser.getSubstitutions());
    Assertions.assertEquals(1, loadedUser.getSubstitutions().size());
    UserSubstitution loadedSubstitution = loadedUser.getSubstitutions().iterator().next();
    assertEquals(user, loadedSubstitution.getUser());
    assertEquals(substitutedUser, loadedSubstitution.getSubstitutedUser());
}
Also used : ViewRepository(com.haulmont.cuba.core.global.ViewRepository) EntityManager(com.haulmont.cuba.core.EntityManager) User(com.haulmont.cuba.security.entity.User) Transaction(com.haulmont.cuba.core.Transaction) UserSubstitution(com.haulmont.cuba.security.entity.UserSubstitution) View(com.haulmont.cuba.core.global.View)

Aggregations

View (com.haulmont.cuba.core.global.View)2 ViewRepository (com.haulmont.cuba.core.global.ViewRepository)2 EntityManager (com.haulmont.cuba.core.EntityManager)1 Transaction (com.haulmont.cuba.core.Transaction)1 Metadata (com.haulmont.cuba.core.global.Metadata)1 User (com.haulmont.cuba.security.entity.User)1 UserSubstitution (com.haulmont.cuba.security.entity.UserSubstitution)1