Search in sources :

Example 11 with GroupImpl

use of org.olat.basesecurity.model.GroupImpl in project openolat by klemens.

the class GroupDAO method createGroup.

public Group createGroup() {
    GroupImpl group = new GroupImpl();
    group.setCreationDate(new Date());
    dbInstance.getCurrentEntityManager().persist(group);
    return group;
}
Also used : GroupImpl(org.olat.basesecurity.model.GroupImpl) Date(java.util.Date)

Example 12 with GroupImpl

use of org.olat.basesecurity.model.GroupImpl in project openolat by klemens.

the class GroupDAO method addMembershipTwoWay.

/**
 * Add a membership to the group, in the set of the group too which can be
 * reloaded.
 */
public GroupMembership addMembershipTwoWay(Group group, Identity identity, String role) {
    GroupMembershipImpl membership = new GroupMembershipImpl();
    membership.setCreationDate(new Date());
    membership.setLastModified(new Date());
    membership.setGroup(group);
    membership.setIdentity(identity);
    membership.setRole(role);
    dbInstance.getCurrentEntityManager().persist(membership);
    Set<GroupMembership> members = ((GroupImpl) group).getMembers();
    if (members == null) {
        members = new HashSet<>();
        ((GroupImpl) group).setMembers(members);
    }
    members.add(membership);
    return membership;
}
Also used : GroupImpl(org.olat.basesecurity.model.GroupImpl) GroupMembership(org.olat.basesecurity.GroupMembership) GroupMembershipImpl(org.olat.basesecurity.model.GroupMembershipImpl) Date(java.util.Date)

Example 13 with GroupImpl

use of org.olat.basesecurity.model.GroupImpl in project OpenOLAT by OpenOLAT.

the class GroupDAOTest method createGroupMembership_oneWay_v2.

@Test
public void createGroupMembership_oneWay_v2() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-1-");
    Group group = groupDao.createGroup();
    groupDao.addMembershipOneWay(group, id, "author");
    dbInstance.commitAndCloseSession();
    GroupImpl loadedGroup = (GroupImpl) groupDao.loadGroup(group.getKey());
    Assert.assertNotNull(loadedGroup);
    Set<GroupMembership> members = loadedGroup.getMembers();
    Assert.assertNotNull(members);
    Assert.assertEquals(1, members.size());
}
Also used : Group(org.olat.basesecurity.Group) GroupImpl(org.olat.basesecurity.model.GroupImpl) GroupMembership(org.olat.basesecurity.GroupMembership) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 14 with GroupImpl

use of org.olat.basesecurity.model.GroupImpl in project OpenOLAT by OpenOLAT.

the class DBTest method testErrorHandling.

/**
 * testErrorHandling
 */
@Test
public void testErrorHandling() {
    GroupImpl entry = new GroupImpl();
    entry.setName("foo");
    try {
        dbInstance.saveObject(entry);
        fail("Should generate an error");
    } catch (DBRuntimeException dre) {
        assertTrue(dbInstance.isError());
        Assert.assertNotNull(dbInstance.getError());
    }
    // the close must clear the transaction
    dbInstance.closeSession();
    // a second try must work
    GroupImpl entryTwo = new GroupImpl();
    entryTwo.setName("bar");
    entryTwo.setCreationDate(new Date());
    dbInstance.saveObject(entryTwo);
    dbInstance.commitAndCloseSession();
}
Also used : DBRuntimeException(org.olat.core.logging.DBRuntimeException) GroupImpl(org.olat.basesecurity.model.GroupImpl) Date(java.util.Date) Test(org.junit.Test)

Example 15 with GroupImpl

use of org.olat.basesecurity.model.GroupImpl in project openolat by klemens.

the class GroupDAOTest method createGroupMembership_oneWay_v2.

@Test
public void createGroupMembership_oneWay_v2() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-1-");
    Group group = groupDao.createGroup();
    groupDao.addMembershipOneWay(group, id, "author");
    dbInstance.commitAndCloseSession();
    GroupImpl loadedGroup = (GroupImpl) groupDao.loadGroup(group.getKey());
    Assert.assertNotNull(loadedGroup);
    Set<GroupMembership> members = loadedGroup.getMembers();
    Assert.assertNotNull(members);
    Assert.assertEquals(1, members.size());
}
Also used : Group(org.olat.basesecurity.Group) GroupImpl(org.olat.basesecurity.model.GroupImpl) GroupMembership(org.olat.basesecurity.GroupMembership) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Aggregations

GroupImpl (org.olat.basesecurity.model.GroupImpl)18 Date (java.util.Date)8 Test (org.junit.Test)8 GroupMembership (org.olat.basesecurity.GroupMembership)8 Identity (org.olat.core.id.Identity)6 Group (org.olat.basesecurity.Group)4 GroupMembershipImpl (org.olat.basesecurity.model.GroupMembershipImpl)4 DBRuntimeException (org.olat.core.logging.DBRuntimeException)4 EntityManager (javax.persistence.EntityManager)2 SecurityGroupMembershipImpl (org.olat.basesecurity.SecurityGroupMembershipImpl)2 Event (org.olat.core.gui.control.Event)2 SignOnOffEvent (org.olat.core.util.SignOnOffEvent)2 Locker (org.olat.core.util.coordinate.Locker)2