use of com.haulmont.cuba.security.entity.Group in project cuba by cuba-platform.
the class DataManagerCommit2Test method testViewAfterCommitModified.
@Test
public void testViewAfterCommitModified() throws Exception {
Group group2 = dataManager.load(LoadContext.create(Group.class).setId(this.group2.getId()).setView(View.MINIMAL));
assertFalse(PersistenceHelper.isLoaded(group2, "createTs"));
LoadContext<User> loadContext = LoadContext.create(User.class).setId(userId).setView(view);
User user = dataManager.load(loadContext);
user.setName("testUser-changed");
user.setGroup(group2);
View userView = new View(User.class, true).addProperty("login").addProperty("name").addProperty("group", new View(Group.class).addProperty("name").addProperty("createTs"));
User committedUser = dataManager.commit(user, userView);
assertTrue(PersistenceHelper.isLoaded(committedUser.getGroup(), "createTs"));
}
use of com.haulmont.cuba.security.entity.Group in project cuba by cuba-platform.
the class DataManagerCommit2Test method setUp.
@Before
public void setUp() throws Exception {
metadata = cont.metadata();
persistence = cont.persistence();
dataManager = AppBeans.get(DataManager.class);
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
Group group = em.find(Group.class, groupId);
Role role = em.find(Role.class, UUID.fromString("0c018061-b26f-4de2-a5be-dff348347f93"));
group2 = metadata.create(Group.class);
group2.setName("Group2-" + group2.getId());
em.persist(group2);
User user = metadata.create(User.class);
userId = user.getId();
user.setName("testUser");
user.setLogin("login" + userId);
user.setPassword("000");
user.setGroup(group);
em.persist(user);
UserRole userRole = new UserRole();
userRoleId = userRole.getId();
userRole.setRole(role);
userRole.setUser(user);
em.persist(userRole);
tx.commit();
}
view = new View(User.class, true).addProperty("login").addProperty("loginLowerCase").addProperty("name").addProperty("password").addProperty("group", new View(Group.class).addProperty("name")).addProperty("userRoles", new View(UserRole.class));
}
use of com.haulmont.cuba.security.entity.Group in project cuba by cuba-platform.
the class DataManagerCommitTest method setUp.
@Before
public void setUp() throws Exception {
dataManager = AppBeans.get(DataManager.class);
try (Transaction tx = cont.persistence().createTransaction()) {
EntityManager em = cont.persistence().getEntityManager();
Group group = em.find(Group.class, groupId);
Role role = em.find(Role.class, UUID.fromString("0c018061-b26f-4de2-a5be-dff348347f93"));
User user = new User();
userId = user.getId();
user.setName("testUser");
user.setLogin("login" + userId);
user.setPassword("000");
user.setGroup(group);
em.persist(user);
UserRole userRole = new UserRole();
userRoleId = userRole.getId();
userRole.setRole(role);
userRole.setUser(user);
em.persist(userRole);
tx.commit();
}
view = new View(User.class, true).addProperty("login").addProperty("loginLowerCase").addProperty("name").addProperty("password").addProperty("group", new View(Group.class).addProperty("name")).addProperty("userRoles", new View(UserRole.class));
}
use of com.haulmont.cuba.security.entity.Group in project cuba by cuba-platform.
the class DataManagerDistinctResultsTest method setUp.
@Before
public void setUp() throws Exception {
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Group group = new Group();
groupId = group.getId();
group.setName("testGroup");
em.persist(group);
Role role1 = new Role();
role1Id = role1.getId();
role1.setName("role1");
em.persist(role1);
Role role2 = new Role();
role2Id = role2.getId();
role2.setName("role2");
em.persist(role2);
for (int i = 0; i < QTY; i++) {
User user = new User();
user.setName("user" + StringUtils.leftPad(String.valueOf(i), 2, '0'));
user.setLogin(user.getName());
user.setGroup(group);
em.persist(user);
UserRole userRole1 = new UserRole();
userRole1.setUser(user);
userRole1.setRole(role1);
em.persist(userRole1);
UserRole userRole2 = new UserRole();
userRole2.setUser(user);
userRole2.setRole(role2);
em.persist(userRole2);
}
tx.commit();
} finally {
tx.end();
}
}
use of com.haulmont.cuba.security.entity.Group in project cuba by cuba-platform.
the class EclipseLinkQueriesTest method testJoinOnWithToManyView.
// join on, view contains ToMany attribute
@Test
public void testJoinOnWithToManyView() throws Exception {
try (Transaction tx = cont.persistence().createTransaction()) {
EntityManager em = cont.entityManager();
View view = new View(Group.class).addProperty("constraints");
TypedQuery<Group> query = em.createQuery("select g from sec$Group g join sys$QueryResult qr on qr.entityId = g.id where qr.queryKey = 1", Group.class);
query.setView(view);
List<Group> result = query.getResultList();
tx.commit();
}
}
Aggregations