Search in sources :

Example 41 with Group

use of com.haulmont.cuba.security.entity.Group in project cuba by cuba-platform.

the class DynamicAttributesTest method testCollectionOfEntitiesAttribute.

@Test
public void testCollectionOfEntitiesAttribute() {
    LoadContext<User> loadContext = LoadContext.create(User.class).setId(user.getId()).setLoadDynamicAttributes(true);
    User loadedUser = dataManager.load(loadContext);
    List<Group> groupsCollection = loadedUser.getValue("+userGroupCollectionAttribute");
    assertEquals(2, groupsCollection.size());
    loadedUser.setValue("+userGroupCollectionAttribute", Lists.newArrayList(group));
    dataManager.commit(loadedUser);
    loadedUser = dataManager.load(loadContext);
    groupsCollection = loadedUser.getValue("+userGroupCollectionAttribute");
    assertEquals(1, groupsCollection.size());
    assertEquals(group, groupsCollection.get(0));
    loadedUser.setValue("+userGroupCollectionAttribute", Lists.newArrayList(group, group2));
    dataManager.commit(loadedUser);
    groupsCollection = loadedUser.getValue("+userGroupCollectionAttribute");
    assertEquals(2, groupsCollection.size());
}
Also used : Group(com.haulmont.cuba.security.entity.Group) User(com.haulmont.cuba.security.entity.User)

Example 42 with Group

use of com.haulmont.cuba.security.entity.Group in project cuba by cuba-platform.

the class EclipseLinkQueriesTest method testJoinOnWithToManyView2.

// join on, view contains ToMany attribute, fetch = JOIN
@Test
public void testJoinOnWithToManyView2() throws Exception {
    try (Transaction tx = cont.persistence().createTransaction()) {
        EntityManager em = cont.entityManager();
        View view = new View(Group.class).addProperty("constraints", new View(Constraint.class, View.LOCAL), FetchMode.JOIN);
        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();
    }
}
Also used : Group(com.haulmont.cuba.security.entity.Group) Constraint(com.haulmont.cuba.security.entity.Constraint) View(com.haulmont.cuba.core.global.View) Test(org.junit.Test)

Example 43 with Group

use of com.haulmont.cuba.security.entity.Group in project cuba by cuba-platform.

the class EclipseLinkQueriesTest method testJoinOnWithParentReference.

// join on, view contains parent attribute
@Test
public void testJoinOnWithParentReference() throws Exception {
    try (Transaction tx = cont.persistence().createTransaction()) {
        EntityManager em = cont.entityManager();
        View view = new View(Group.class).addProperty("parent");
        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();
    }
}
Also used : Group(com.haulmont.cuba.security.entity.Group) View(com.haulmont.cuba.core.global.View) Test(org.junit.Test)

Example 44 with Group

use of com.haulmont.cuba.security.entity.Group in project cuba by cuba-platform.

the class EclipseLinkQueriesTest method testCrossJoinViewParentReference.

// cross join, view with the reference to the parent entity
@Test
public void testCrossJoinViewParentReference() throws Exception {
    List<Group> result;
    try (Transaction tx = cont.persistence().createTransaction()) {
        EntityManager em = cont.entityManager();
        View view = new View(Group.class).addProperty("parent");
        TypedQuery<Group> query = em.createQuery("select g from sec$Group g, sec$User u where u.group = g", Group.class);
        query.setView(view);
        result = query.getResultList();
        tx.commit();
    }
    for (Group g : result) {
        g = reserialize(g);
        if (g.equals(rootGroup))
            assertNull(g.getParent());
        else if (g.equals(group))
            assertEquals(rootGroup, g.getParent());
    }
}
Also used : Group(com.haulmont.cuba.security.entity.Group) View(com.haulmont.cuba.core.global.View) Test(org.junit.Test)

Example 45 with Group

use of com.haulmont.cuba.security.entity.Group in project cuba by cuba-platform.

the class EclipseLinkQueriesTest method testCrossJoinWithToManyView.

// cross join, view has ToMany reference
@Test
public void testCrossJoinWithToManyView() throws Exception {
    List<Group> result;
    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, sec$User u where u.group = g", Group.class);
        query.setView(view);
        result = query.getResultList();
        tx.commit();
    }
    for (Group group : result) {
        group = reserialize(group);
        group.getConstraints().size();
    }
}
Also used : Group(com.haulmont.cuba.security.entity.Group) View(com.haulmont.cuba.core.global.View) Test(org.junit.Test)

Aggregations

Group (com.haulmont.cuba.security.entity.Group)79 User (com.haulmont.cuba.security.entity.User)65 Test (org.junit.Test)60 UUID (java.util.UUID)30 Datasource (com.haulmont.cuba.gui.data.Datasource)29 Ignore (org.junit.Ignore)29 Component (com.haulmont.cuba.gui.components.Component)24 ArrayList (java.util.ArrayList)24 Assert.assertEquals (org.junit.Assert.assertEquals)24 Assert.assertTrue (org.junit.Assert.assertTrue)24 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)23 List (java.util.List)20 View (com.haulmont.cuba.core.global.View)15 Assert.assertNotNull (org.junit.Assert.assertNotNull)12 DsBuilder (com.haulmont.cuba.gui.data.DsBuilder)11 DatasourceImpl (com.haulmont.cuba.gui.data.impl.DatasourceImpl)10 Before (org.junit.Before)10 LookupPickerField (com.haulmont.cuba.gui.components.LookupPickerField)9 EntityManager (com.haulmont.cuba.core.EntityManager)8 Transaction (com.haulmont.cuba.core.Transaction)7