Search in sources :

Example 6 with GroupImpl

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

the class LockTest method testSaveEvent.

@Test
public void testSaveEvent() {
    Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("lock-save-event-");
    dbInstance.closeSession();
    log.info("Created identity=" + identity);
    // The group has no creation date -> commit will fail
    GroupImpl entry = new GroupImpl();
    entry.setName("bar");
    try {
        dbInstance.saveObject(entry);
        dbInstance.commit();
        fail("Should generate an error");
    } catch (DBRuntimeException dre) {
        log.info("DB connection is in error-state");
    }
    // DB transaction must be in error state for this test
    try {
        Locker locker = clusterCoordinator.getLocker();
        assertTrue(locker instanceof ClusterLocker);
        log.info("ClusterLocker created");
        Event event = new SignOnOffEvent(identity, false);
        log.info("START locker.event(event)");
        ((ClusterLocker) locker).event(event);
        log.info("DONE locker.event(event)");
    } catch (Exception ex) {
        log.error("", ex);
        fail("BLOCKER : ClusterLocker.event is not error-safe, db exception could happen and de-register event-listener");
    }
}
Also used : Locker(org.olat.core.util.coordinate.Locker) DBRuntimeException(org.olat.core.logging.DBRuntimeException) GroupImpl(org.olat.basesecurity.model.GroupImpl) SignOnOffEvent(org.olat.core.util.SignOnOffEvent) SignOnOffEvent(org.olat.core.util.SignOnOffEvent) Event(org.olat.core.gui.control.Event) Identity(org.olat.core.id.Identity) DBRuntimeException(org.olat.core.logging.DBRuntimeException) Test(org.junit.Test)

Example 7 with GroupImpl

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

the class OLATUpgrade_10_0_0 method processSecurityGroup.

private void processSecurityGroup(Group group, String role, SecurityGroup secGroup) {
    if (secGroup == null)
        return;
    List<SecurityGroupMembershipImpl> oldMemberships = getMembershipsOfSecurityGroup(secGroup);
    for (SecurityGroupMembershipImpl oldMembership : oldMemberships) {
        GroupMembershipImpl membership = new GroupMembershipImpl();
        membership.setCreationDate(oldMembership.getCreationDate());
        membership.setLastModified(oldMembership.getLastModified());
        membership.setGroup(group);
        membership.setIdentity(oldMembership.getIdentity());
        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);
    }
}
Also used : SecurityGroupMembershipImpl(org.olat.basesecurity.SecurityGroupMembershipImpl) GroupImpl(org.olat.basesecurity.model.GroupImpl) GroupMembership(org.olat.basesecurity.GroupMembership) GroupMembershipImpl(org.olat.basesecurity.model.GroupMembershipImpl) SecurityGroupMembershipImpl(org.olat.basesecurity.SecurityGroupMembershipImpl)

Example 8 with GroupImpl

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

the class LockTest method testSaveEvent.

@Test
public void testSaveEvent() {
    Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("lock-save-event-");
    dbInstance.closeSession();
    log.info("Created identity=" + identity);
    // The group has no creation date -> commit will fail
    GroupImpl entry = new GroupImpl();
    entry.setName("bar");
    try {
        dbInstance.saveObject(entry);
        dbInstance.commit();
        fail("Should generate an error");
    } catch (DBRuntimeException dre) {
        log.info("DB connection is in error-state");
    }
    // DB transaction must be in error state for this test
    try {
        Locker locker = clusterCoordinator.getLocker();
        assertTrue(locker instanceof ClusterLocker);
        log.info("ClusterLocker created");
        Event event = new SignOnOffEvent(identity, false);
        log.info("START locker.event(event)");
        ((ClusterLocker) locker).event(event);
        log.info("DONE locker.event(event)");
    } catch (Exception ex) {
        log.error("", ex);
        fail("BLOCKER : ClusterLocker.event is not error-safe, db exception could happen and de-register event-listener");
    }
}
Also used : Locker(org.olat.core.util.coordinate.Locker) DBRuntimeException(org.olat.core.logging.DBRuntimeException) GroupImpl(org.olat.basesecurity.model.GroupImpl) SignOnOffEvent(org.olat.core.util.SignOnOffEvent) SignOnOffEvent(org.olat.core.util.SignOnOffEvent) Event(org.olat.core.gui.control.Event) Identity(org.olat.core.id.Identity) DBRuntimeException(org.olat.core.logging.DBRuntimeException) Test(org.junit.Test)

Example 9 with GroupImpl

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

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 10 with GroupImpl

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

the class OLATUpgrade_10_0_0 method processSecurityGroup.

private void processSecurityGroup(Group group, String role, SecurityGroup secGroup) {
    if (secGroup == null)
        return;
    List<SecurityGroupMembershipImpl> oldMemberships = getMembershipsOfSecurityGroup(secGroup);
    for (SecurityGroupMembershipImpl oldMembership : oldMemberships) {
        GroupMembershipImpl membership = new GroupMembershipImpl();
        membership.setCreationDate(oldMembership.getCreationDate());
        membership.setLastModified(oldMembership.getLastModified());
        membership.setGroup(group);
        membership.setIdentity(oldMembership.getIdentity());
        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);
    }
}
Also used : SecurityGroupMembershipImpl(org.olat.basesecurity.SecurityGroupMembershipImpl) GroupImpl(org.olat.basesecurity.model.GroupImpl) GroupMembership(org.olat.basesecurity.GroupMembership) GroupMembershipImpl(org.olat.basesecurity.model.GroupMembershipImpl) SecurityGroupMembershipImpl(org.olat.basesecurity.SecurityGroupMembershipImpl)

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