Skip to content
Snippets Groups Projects
Commit 858314b6 authored by srosse's avatar srosse
Browse files

OO-1616: remove the doInSync needed for course creation via REST API

parent 996a9b45
No related branches found
No related tags found
No related merge requests found
......@@ -213,8 +213,9 @@ public class CourseFactory extends BasicManager {
* @param learningObjectives Learning objectives of root node
* @return an empty course with a single root node.
*/
public static ICourse createEmptyCourse(OLATResourceable ores, String shortTitle, String longTitle, String learningObjectives) {
PersistingCourseImpl newCourse = new PersistingCourseImpl(ores.getResourceableId());
public static ICourse createEmptyCourse(RepositoryEntry courseEntry, String shortTitle, String longTitle, String learningObjectives) {
OLATResource courseResource = courseEntry.getOlatResource();
PersistingCourseImpl newCourse = new PersistingCourseImpl(courseResource.getResourceableId());
// Put new course in course cache
loadedCourses.put(newCourse.getResourceableId() ,newCourse);
......
......@@ -134,8 +134,8 @@ public class PersistingCourseImpl implements ICourse, OLATResourceable, Serializ
}
PersistingCourseImpl(RepositoryEntry courseEntry) {
this.courseTitle = courseEntry.getDisplayname();
this.resourceableId = courseEntry.getOlatResource().getResourceableId();
courseTitle = courseEntry.getDisplayname();
resourceableId = courseEntry.getOlatResource().getResourceableId();
// prepare filesystem and set course base path and course folder paths
prepareFilesystem();
courseConfig = CourseConfigManagerImpl.getInstance().loadConfigFor(this); // load or init defaults
......
......@@ -144,7 +144,7 @@ public class CourseHandler implements RepositoryHandler {
RepositoryEntry re = repositoryService.create(initialAuthor, null, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
DBFactory.getInstance().commit();
ICourse course = CourseFactory.createEmptyCourse(resource, "New Course", "New Course", "");
ICourse course = CourseFactory.createEmptyCourse(re, "New Course", "New Course", "");
course = CourseFactory.openCourseEditSession(re.getOlatResource().getResourceableId());
String shortDisplayname = Formatter.truncateOnly(displayname, 25);
......
......@@ -494,44 +494,38 @@ public class CoursesWebService {
}
try {
OLATResource resource = OLATResourceManager.getInstance().createOLATResourceInstance(CourseModule.class);
// create a repository entry
RepositoryEntry addedEntry = createCourseRepositoryEntry(initialAuthor, reDisplayName, softKey, externalId, externalRef, managedFlags, resource);
// create an empty course
CourseFactory.createEmptyCourse(resource, shortTitle, longTitle, learningObjectives);
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
OLATResource resource = OLATResourceManager.getInstance().createOLATResourceInstance(CourseModule.class);
RepositoryEntry addedEntry = repositoryService.create(initialAuthor, null, "-", shortTitle, null, resource, 0);
if(StringHelper.containsNonWhitespace(softKey) && softKey.length() <= 30) {
addedEntry.setSoftkey(softKey);
}
addedEntry.setExternalId(externalId);
addedEntry.setExternalRef(externalRef);
addedEntry.setManagedFlagsString(managedFlags);
if(RepositoryEntryManagedFlag.isManaged(addedEntry, RepositoryEntryManagedFlag.membersmanagement)) {
addedEntry.setAllowToLeaveOption(RepositoryEntryAllowToLeaveOptions.never);
} else {
addedEntry.setAllowToLeaveOption(RepositoryEntryAllowToLeaveOptions.atAnyTime);//default
}
if(membersOnly) {
addedEntry.setMembersOnly(true);
addedEntry.setAccess(RepositoryEntry.ACC_OWNERS);
} else {
addedEntry.setAccess(access);
}
CoreSpringFactory.getImpl(RepositoryService.class).update(addedEntry);
addedEntry = repositoryService.update(addedEntry);
// create an empty course
CourseFactory.createEmptyCourse(addedEntry, shortTitle, longTitle, learningObjectives);
return prepareCourse(addedEntry, shortTitle, longTitle, courseConfigVO);
} catch (Exception e) {
throw new WebApplicationException(e);
}
}
private static RepositoryEntry createCourseRepositoryEntry(Identity initialAuthor, String shortTitle,
String softKey, String externalId, String externalRef, String managedFlags, OLATResourceable oresable) {
// create a repository entry
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
OLATResource ores = OLATResourceManager.getInstance().findOrPersistResourceable(oresable);
RepositoryEntry addedEntry = repositoryService.create(initialAuthor, null, "-", shortTitle, null, ores, 0);
if(StringHelper.containsNonWhitespace(softKey) && softKey.length() <= 30) {
addedEntry.setSoftkey(softKey);
}
addedEntry.setExternalId(externalId);
addedEntry.setExternalRef(externalRef);
addedEntry.setManagedFlagsString(managedFlags);
if(RepositoryEntryManagedFlag.isManaged(addedEntry, RepositoryEntryManagedFlag.membersmanagement)) {
addedEntry.setAllowToLeaveOption(RepositoryEntryAllowToLeaveOptions.never);
} else {
addedEntry.setAllowToLeaveOption(RepositoryEntryAllowToLeaveOptions.atAnyTime);//default
}
return addedEntry;//!!!no update at this point
}
private static ICourse prepareCourse(RepositoryEntry addedEntry, String shortTitle, String longTitle, CourseConfigVO courseConfigVO) {
// set root node title
String courseShortTitle = addedEntry.getDisplayname();
......@@ -576,7 +570,6 @@ public class CoursesWebService {
CourseFactory.saveCourse(course.getResourceableId());
CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
course = CourseFactory.loadCourse(course.getResourceableId());
return course;
return CourseFactory.loadCourse(addedEntry);
}
}
......@@ -29,17 +29,18 @@ package org.olat.course.config;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import org.junit.Before;
import org.junit.Test;
import org.olat.core.commons.persistence.DBFactory;
import org.olat.core.id.OLATResourceable;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
import org.olat.core.util.resource.OresHelper;
import org.olat.core.commons.persistence.DB;
import org.olat.core.util.vfs.VFSItem;
import org.olat.course.CourseFactory;
import org.olat.course.CourseModule;
import org.olat.course.ICourse;
import org.olat.repository.RepositoryEntry;
import org.olat.repository.RepositoryService;
import org.olat.resource.OLATResource;
import org.olat.resource.OLATResourceManager;
import org.olat.test.OlatTestCase;
import org.springframework.beans.factory.annotation.Autowired;
/**
* Description: <br>
......@@ -50,54 +51,43 @@ import org.olat.test.OlatTestCase;
* @author patrick
*/
public class CourseConfigManagerImplTest extends OlatTestCase {
private static OLog log = Tracing.createLoggerFor(CourseConfigManagerImplTest.class);
private static ICourse course1;
private static boolean isSetup = false;
/**
* SetUp is called before each test.
*/
@Before
public void setUp() {
if (isSetup) return;
try {
// create course and persist as OLATResourceImpl
OLATResourceable resourceable = OresHelper.createOLATResourceableInstance("junitConfigCourse", new Long(System.currentTimeMillis()));
course1 = CourseFactory.createEmptyCourse(resourceable, "JUnitCourseConfig", "JUnitCourseConfig Long Title",
"objective 1 objective 2 objective 3");
DBFactory.getInstance().closeSession();
isSetup = true;
} catch (Exception e) {
log.error("Exception in setUp(): " + e);
e.printStackTrace();
}
}
@Autowired
private DB dbInstance;
@Autowired
private RepositoryService repositoryService;
@Autowired
private OLATResourceManager resourceManager;
@Test
public void testConfigFileCRUD() {
// create course and persist as OLATResourceImpl
OLATResource resource = resourceManager.createOLATResourceInstance(CourseModule.class);
RepositoryEntry addedEntry = repositoryService.create("Ayanami", "-", "JUnit course configuration course", "A JUnit course", resource);
ICourse course = CourseFactory.createEmptyCourse(addedEntry, "JUnitCourseConfig", "JUnitCourseConfig Long Title",
"objective 1 objective 2 objective 3");
dbInstance.commitAndCloseSession();
/*
* a new created course gets its configuration upon the first load with
* default values
*/
CourseConfigManager ccm = CourseConfigManagerImpl.getInstance();
CourseConfig cc1 = ccm.loadConfigFor(course1);
CourseConfig cc1 = ccm.loadConfigFor(course);
assertNotNull("CourseConfiguration is not null", cc1);
/*
* update values
*/
ccm.saveConfigTo(course1, cc1);
ccm.saveConfigTo(course, cc1);
cc1 = null;
// check the saved values
cc1 = ccm.loadConfigFor(course1);
cc1 = ccm.loadConfigFor(course);
assertNotNull("CourseConfiguration is not null", cc1);
/*
* delete configuration
*/
ccm.deleteConfigOf(course1);
VFSItem cc1File = CourseConfigManagerImpl.getConfigFile(course1);
ccm.deleteConfigOf(course);
VFSItem cc1File = CourseConfigManagerImpl.getConfigFile(course);
assertFalse("CourseConfig file no longer exists.", cc1File != null);
}
}
\ No newline at end of file
......@@ -52,15 +52,14 @@ import org.olat.core.gui.control.info.WindowControlInfo;
import org.olat.core.gui.translator.Translator;
import org.olat.core.id.Identity;
import org.olat.core.id.IdentityEnvironment;
import org.olat.core.id.OLATResourceable;
import org.olat.core.id.Roles;
import org.olat.core.id.context.BusinessControl;
import org.olat.core.id.context.ContextEntry;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
import org.olat.core.util.Util;
import org.olat.core.util.resource.OresHelper;
import org.olat.course.CourseFactory;
import org.olat.course.CourseModule;
import org.olat.course.groupsandrights.CourseGroupManager;
import org.olat.course.nodes.ENCourseNode;
import org.olat.course.properties.CoursePropertyManager;
......@@ -70,6 +69,9 @@ import org.olat.course.run.userview.UserCourseEnvironmentImpl;
import org.olat.group.BusinessGroup;
import org.olat.group.BusinessGroupService;
import org.olat.repository.RepositoryEntry;
import org.olat.repository.RepositoryService;
import org.olat.resource.OLATResource;
import org.olat.resource.OLATResourceManager;
import org.olat.test.JunitTestHelper;
import org.olat.test.OlatTestCase;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -98,6 +100,10 @@ public class EnrollmentManagerConcurrentTest extends OlatTestCase implements Win
private static Translator testTranslator = null;
private static BusinessGroup bgWithWaitingList = null;
@Autowired
private RepositoryService repositoryService;
@Autowired
private OLATResourceManager resourceManager;
@Autowired
private BusinessGroupService businessGroupService;
@Autowired
......@@ -151,8 +157,10 @@ public class EnrollmentManagerConcurrentTest extends OlatTestCase implements Win
public void testEnroll() throws Exception {
log.info("testEnroll: start...");
ENCourseNode enNode = new ENCourseNode();
OLATResourceable ores = OresHelper.createOLATResourceableTypeWithoutCheck("TestCourse");
CourseEnvironment cenv = CourseFactory.createEmptyCourse(ores, "Test", "Test", "learningObjectives").getCourseEnvironment();
OLATResource resource = resourceManager.createOLATResourceInstance(CourseModule.class);
RepositoryEntry addedEntry = repositoryService.create("Ayanami", "-", "Enrollment test course 1", "A JUnit course", resource);
CourseEnvironment cenv = CourseFactory.createEmptyCourse(addedEntry, "Test", "Test", "learningObjectives").getCourseEnvironment();
// 1. enroll wg1 user
IdentityEnvironment ienv = new IdentityEnvironment();
ienv.setIdentity(wg1);
......@@ -247,8 +255,9 @@ public class EnrollmentManagerConcurrentTest extends OlatTestCase implements Win
}
ENCourseNode enNode = new ENCourseNode();
OLATResourceable ores = OresHelper.createOLATResourceableTypeWithoutCheck("TestEnrollmentCourse");
CourseEnvironment cenv = CourseFactory.createEmptyCourse(ores, "Test-Enroll", "Test", "Test enrollment with concurrent users").getCourseEnvironment();
OLATResource resource = resourceManager.createOLATResourceInstance(CourseModule.class);
RepositoryEntry addedEntry = repositoryService.create("Ayanami", "-", "Enrollment test course 2", "A JUnit course", resource);
CourseEnvironment cenv = CourseFactory.createEmptyCourse(addedEntry, "Test-Enroll", "Test", "Test enrollment with concurrent users").getCourseEnvironment();
BusinessGroup group = businessGroupService.createBusinessGroup(id1, "Enrollment", "Enroll", new Integer(1), new Integer(10), true, false, null);
Assert.assertNotNull(group);
dbInstance.commitAndCloseSession();
......
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