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));
}
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());
}
Aggregations