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