Skip to content
Snippets Groups Projects
Commit 7d967aa8 authored by srosse's avatar srosse
Browse files

Merge OpenOLAT 11.3 to OpenOLAT default branch with b010da07056156315f5c5fd0b7c313ae1391e78e

parents eed3bab6 a2abeb2b
No related branches found
No related tags found
No related merge requests found
......@@ -31,6 +31,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hibernate.LazyInitializationException;
import org.olat.core.CoreSpringFactory;
import org.olat.core.id.Identity;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
......@@ -46,6 +48,8 @@ import org.olat.course.nodes.PersistentAssessableCourseNode;
import org.olat.course.run.userview.UserCourseEnvironment;
import org.olat.modules.assessment.AssessmentEntry;
import org.olat.modules.assessment.model.AssessmentEntryStatus;
import org.olat.repository.RepositoryEntry;
import org.olat.repository.RepositoryService;
import org.olat.repository.model.RepositoryEntryLifecycle;
/**
......@@ -207,8 +211,7 @@ public class ScoreAccounting {
if(failedType == null || failedType == FailedEvaluationType.failedAsNotPassed) {
passed = Boolean.FALSE;
} else if(failedType == FailedEvaluationType.failedAsNotPassedAfterEndDate) {
CourseGroupManager cgm = userCourseEnvironment.getCourseEnvironment().getCourseGroupManager();
RepositoryEntryLifecycle lifecycle = cgm.getCourseEntry().getLifecycle();
RepositoryEntryLifecycle lifecycle = getRepositoryEntryLifecycle();
if(lifecycle != null && lifecycle.getValidTo() != null && lifecycle.getValidTo().compareTo(new Date()) < 0) {
passed = Boolean.FALSE;
}
......@@ -241,6 +244,23 @@ public class ScoreAccounting {
return se;
}
private RepositoryEntryLifecycle getRepositoryEntryLifecycle() {
CourseGroupManager cgm = userCourseEnvironment.getCourseEnvironment().getCourseGroupManager();
try {
RepositoryEntryLifecycle lifecycle = cgm.getCourseEntry().getLifecycle();
if(lifecycle != null) {
lifecycle.getValidTo();//
}
return lifecycle;
} catch (LazyInitializationException e) {
//OO-2667: only seen in 1 instance but as it's a critical place, secure the system
RepositoryEntry reloadedEntry = CoreSpringFactory.getImpl(RepositoryService.class)
.loadByKey(cgm.getCourseEntry().getKey());
userCourseEnvironment.getCourseEnvironment().updateCourseEntry(reloadedEntry);
return reloadedEntry.getLifecycle();
}
}
private boolean same(AssessmentEvaluation se, AssessmentEntry entry) {
boolean same = true;
......
......@@ -825,7 +825,6 @@ public class RepositoryManager {
updatedRe.getStatistics().getLaunchCounter();
if(updatedRe.getLifecycle() != null) {
updatedRe.getLifecycle().getKey();
System.out.println(updatedRe.getLifecycle().getValidTo());
}
dbInstance.commit();
......
......@@ -38,6 +38,7 @@ import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.hibernate.LazyInitializationException;
import org.junit.Assert;
import org.junit.Test;
import org.olat.basesecurity.BaseSecurity;
......@@ -1327,6 +1328,36 @@ public class RepositoryManagerTest extends OlatTestCase {
boolean group2CoachRole = businessGroupRelationDao.hasRole(owner, group2, GroupRoles.coach.name());
Assert.assertTrue(group2CoachRole);
}
/**
* This is a simulation of OO-2667 to make sure that the LazyInitializationException don't
* set the transaction on rollback.
*/
@Test
public void lazyLoadingCheck() {
RepositoryEntry re = repositoryService.create("Rei Ayanami", "-", "Repository entry DAO Test 5", "", null);
dbInstance.commitAndCloseSession();
RepositoryEntryLifecycle cycle = lifecycleDao.create("New cycle 1", "New cycle soft 1", false, new Date(), new Date());
re = repositoryManager.setDescriptionAndName(re, "Updated repo entry", null, null, "", null, null, null, null, null, null, cycle);
dbInstance.commitAndCloseSession();
RepositoryEntry lazyRe = repositoryManager.setAccess(re, 2, false);
dbInstance.commitAndCloseSession();
try {// produce the exception
lazyRe.getLifecycle().getValidFrom();
Assert.fail();
} catch (LazyInitializationException e) {
//
}
//load a fresh entry
RepositoryEntry entry = repositoryManager.lookupRepositoryEntry(lazyRe.getKey());
Date validFrom = entry.getLifecycle().getValidFrom();
Assert.assertNotNull(validFrom);
dbInstance.commitAndCloseSession();
}
private RepositoryEntry createRepositoryEntry(final String type, Identity owner, long i) {
OLATResourceable resourceable = OresHelper.createOLATResourceableInstance(type, new Long(i));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment