From 24e9e5cf791462e148cd641f61c908947a6e2cc5 Mon Sep 17 00:00:00 2001
From: srosse <none@none>
Date: Wed, 21 Jan 2015 09:49:56 +0100
Subject: [PATCH] OO-1393: enhance course config with chat,
 efficiencyStatement, css, glossary...

---
 .../repository/course/CoursesWebService.java  | 16 ++++
 .../olat/restapi/support/ObjectFactory.java   |  5 ++
 .../restapi/support/vo/CourseConfigVO.java    | 45 +++++++++++
 .../java/org/olat/restapi/CalendarTest.java   | 21 ++----
 .../org/olat/restapi/CourseCalendarTest.java  | 17 ++---
 .../java/org/olat/restapi/CourseTest.java     | 74 +++++++++++--------
 6 files changed, 121 insertions(+), 57 deletions(-)

diff --git a/src/main/java/org/olat/restapi/repository/course/CoursesWebService.java b/src/main/java/org/olat/restapi/repository/course/CoursesWebService.java
index 024fb05c833..eafc888f7f1 100644
--- a/src/main/java/org/olat/restapi/repository/course/CoursesWebService.java
+++ b/src/main/java/org/olat/restapi/repository/course/CoursesWebService.java
@@ -547,6 +547,22 @@ public class CoursesWebService {
 			if(StringHelper.containsNonWhitespace(courseConfigVO.getSharedFolderSoftKey())) {
 				courseConfig.setSharedFolderSoftkey(courseConfigVO.getSharedFolderSoftKey());
 			}
+			if(courseConfigVO.getCalendar() != null) {
+				courseConfig.setCalendarEnabled(courseConfigVO.getCalendar().booleanValue());
+			}
+			if(courseConfigVO.getChat() != null) {
+				courseConfig.setChatIsEnabled(courseConfigVO.getChat().booleanValue());
+			}
+			if(courseConfigVO.getEfficencyStatement() != null) {
+				courseConfig.setEfficencyStatementIsEnabled(courseConfigVO.getEfficencyStatement().booleanValue());
+			}
+			if(StringHelper.containsNonWhitespace(courseConfigVO.getCssLayoutRef())) {
+				courseConfig.setCssLayoutRef(courseConfigVO.getCssLayoutRef());
+			}
+			if(StringHelper.containsNonWhitespace(courseConfigVO.getGlossarySoftkey())) {
+				courseConfig.setGlossarySoftKey(courseConfigVO.getGlossarySoftkey());
+			}
+			CourseFactory.setCourseConfig(course.getResourceableId(), courseConfig);
 		}
 
 		CourseFactory.saveCourse(course.getResourceableId());
diff --git a/src/main/java/org/olat/restapi/support/ObjectFactory.java b/src/main/java/org/olat/restapi/support/ObjectFactory.java
index fd948827444..bb22449b1d7 100644
--- a/src/main/java/org/olat/restapi/support/ObjectFactory.java
+++ b/src/main/java/org/olat/restapi/support/ObjectFactory.java
@@ -201,6 +201,11 @@ public class ObjectFactory {
 	public static CourseConfigVO getConfig(ICourse course) {
 		CourseConfigVO vo = new CourseConfigVO();
 		CourseConfig config = course.getCourseEnvironment().getCourseConfig();
+		vo.setCalendar(new Boolean(config.isCalendarEnabled()));
+		vo.setChat(new Boolean(config.isChatEnabled()));
+		vo.setCssLayoutRef(config.getCssLayoutRef());
+		vo.setEfficencyStatement(new Boolean(config.isEfficencyStatementEnabled()));
+		vo.setGlossarySoftkey(config.getGlossarySoftKey());
 		vo.setSharedFolderSoftKey(config.getSharedFolderSoftkey());
 		return vo;
 	}
diff --git a/src/main/java/org/olat/restapi/support/vo/CourseConfigVO.java b/src/main/java/org/olat/restapi/support/vo/CourseConfigVO.java
index 4edee401ba3..6b63bd8cbea 100644
--- a/src/main/java/org/olat/restapi/support/vo/CourseConfigVO.java
+++ b/src/main/java/org/olat/restapi/support/vo/CourseConfigVO.java
@@ -36,12 +36,57 @@ import javax.xml.bind.annotation.XmlRootElement;
 @XmlRootElement(name = "courseVO")
 public class CourseConfigVO {
 	
+	private Boolean calendar;
+	private Boolean chat;
+	private String cssLayoutRef;
+	private Boolean efficencyStatement;
+	private String glossarySoftkey;
 	private String sharedFolderSoftKey;
 	
 	public CourseConfigVO() {
 		//make JAXB happy
 	}
 
+	public Boolean getCalendar() {
+		return calendar;
+	}
+
+	public void setCalendar(Boolean calendar) {
+		this.calendar = calendar;
+	}
+
+	public Boolean getChat() {
+		return chat;
+	}
+
+	public void setChat(Boolean chat) {
+		this.chat = chat;
+	}
+
+	public String getCssLayoutRef() {
+		return cssLayoutRef;
+	}
+
+	public void setCssLayoutRef(String cssLayoutRef) {
+		this.cssLayoutRef = cssLayoutRef;
+	}
+	
+	public Boolean getEfficencyStatement() {
+		return efficencyStatement;
+	}
+
+	public void setEfficencyStatement(Boolean efficencyStatement) {
+		this.efficencyStatement = efficencyStatement;
+	}
+
+	public String getGlossarySoftkey() {
+		return glossarySoftkey;
+	}
+
+	public void setGlossarySoftkey(String glossarySoftkey) {
+		this.glossarySoftkey = glossarySoftkey;
+	}
+
 	public String getSharedFolderSoftKey() {
 		return sharedFolderSoftKey;
 	}
diff --git a/src/test/java/org/olat/restapi/CalendarTest.java b/src/test/java/org/olat/restapi/CalendarTest.java
index 4e756429e48..5beedc4f3ae 100644
--- a/src/test/java/org/olat/restapi/CalendarTest.java
+++ b/src/test/java/org/olat/restapi/CalendarTest.java
@@ -100,16 +100,13 @@ public class CalendarTest extends OlatJerseyTestCase {
 		if(course1 == null) {
 			//create a course with a calendar
 			CourseConfigVO config = new CourseConfigVO();
+			config.setCalendar(Boolean.TRUE);
 			course1 = CoursesWebService.createEmptyCourse(id1, "Cal course", "Cal course", config);
-
 			dbInstance.commit();
-			ICourse course = CourseFactory.openCourseEditSession(course1.getResourceableId());
+			
+			ICourse course = CourseFactory.loadCourse(course1.getResourceableId());
 			CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig();
-			courseConfig.setCalendarEnabled(true);
-			CourseFactory.setCourseConfig(course.getResourceableId(), courseConfig);
-			CourseFactory.closeCourseEditSession(course.getResourceableId(),true);
-
-			dbInstance.commit();
+			Assert.assertTrue(courseConfig.isCalendarEnabled());
 
 			CalendarManager calendarManager = CalendarManagerFactory.getInstance().getCalendarManager();
 			KalendarRenderWrapper calendarWrapper = calendarManager.getCourseCalendar(course);
@@ -142,22 +139,16 @@ public class CalendarTest extends OlatJerseyTestCase {
 		if(course2 == null) {
 			//create a course with a calendar
 			CourseConfigVO config = new CourseConfigVO();
+			config.setCalendar(Boolean.TRUE);
 			course2 = CoursesWebService.createEmptyCourse(id2, "Cal course - 2", "Cal course - 2", config);
-
 			dbInstance.commit();
-			ICourse course = CourseFactory.openCourseEditSession(course2.getResourceableId());
-			CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig();
-			courseConfig.setCalendarEnabled(true);
-			CourseFactory.setCourseConfig(course.getResourceableId(), courseConfig);
-			CourseFactory.closeCourseEditSession(course.getResourceableId(),true);
-			
+
 			CalendarManager calendarManager = CalendarManagerFactory.getInstance().getCalendarManager();
 			KalendarRenderWrapper calendarWrapper = calendarManager.getCourseCalendar(course2);
 			Assert.assertNotNull(calendarWrapper);
 
 			RepositoryEntry entry = repositoryManager.lookupRepositoryEntry(course2, false);
 			entry = repositoryManager.setAccess(entry, RepositoryEntry.ACC_USERS, false);
-
 			dbInstance.commit();
 		}
 	}
diff --git a/src/test/java/org/olat/restapi/CourseCalendarTest.java b/src/test/java/org/olat/restapi/CourseCalendarTest.java
index 9a2dd1f2bc4..15753bbb335 100644
--- a/src/test/java/org/olat/restapi/CourseCalendarTest.java
+++ b/src/test/java/org/olat/restapi/CourseCalendarTest.java
@@ -65,8 +65,8 @@ import org.olat.core.logging.OLog;
 import org.olat.core.logging.Tracing;
 import org.olat.course.CourseFactory;
 import org.olat.course.ICourse;
-import org.olat.course.config.CourseConfig;
 import org.olat.restapi.repository.course.CoursesWebService;
+import org.olat.restapi.support.vo.CourseConfigVO;
 import org.olat.test.JunitTestHelper;
 import org.olat.test.OlatJerseyTestCase;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -96,17 +96,14 @@ public class CourseCalendarTest extends OlatJerseyTestCase {
 		try {
 			// create course and persist as OLATResourceImpl
 			auth1 = JunitTestHelper.createAndPersistIdentityAsUser("rest-course-cal-one");
-			course1 = CoursesWebService.createEmptyCourse(auth1, "course calendar", "course with calendar for REST API testing", null);
-			
-			dbInstance.commit();
-			ICourse course = CourseFactory.openCourseEditSession(course1.getResourceableId());
-			CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig();
-			courseConfig.setCalendarEnabled(true);
-			CourseFactory.setCourseConfig(course.getResourceableId(), courseConfig);
-			CourseFactory.closeCourseEditSession(course.getResourceableId(),true);
-
+			CourseConfigVO config = new CourseConfigVO();
+			config.setCalendar(Boolean.TRUE);
+			course1 = CoursesWebService.createEmptyCourse(auth1, "course calendar", "course with calendar for REST API testing", config);
 			dbInstance.commit();
 			
+			ICourse course = CourseFactory.loadCourse(course1.getResourceableId());
+			Assert.assertTrue(course.getCourseConfig().isCalendarEnabled());
+			
 			CalendarManager calendarManager = CalendarManagerFactory.getInstance().getCalendarManager();
 			KalendarRenderWrapper calendarWrapper = calendarManager.getCourseCalendar(course);
 			
diff --git a/src/test/java/org/olat/restapi/CourseTest.java b/src/test/java/org/olat/restapi/CourseTest.java
index e13961fe11f..3a57f3a0a85 100644
--- a/src/test/java/org/olat/restapi/CourseTest.java
+++ b/src/test/java/org/olat/restapi/CourseTest.java
@@ -43,8 +43,6 @@ import java.util.List;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.UriBuilder;
 
-import junit.framework.Assert;
-
 import org.apache.http.HttpResponse;
 import org.apache.http.client.methods.HttpDelete;
 import org.apache.http.client.methods.HttpGet;
@@ -53,15 +51,15 @@ import org.apache.http.util.EntityUtils;
 import org.codehaus.jackson.map.ObjectMapper;
 import org.codehaus.jackson.type.TypeReference;
 import org.junit.After;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.olat.admin.securitygroup.gui.IdentitiesAddEvent;
-import org.olat.basesecurity.BaseSecurity;
 import org.olat.basesecurity.BaseSecurityManager;
 import org.olat.basesecurity.Constants;
 import org.olat.basesecurity.GroupRoles;
 import org.olat.basesecurity.SecurityGroup;
-import org.olat.core.CoreSpringFactory;
+import org.olat.core.commons.persistence.DB;
 import org.olat.core.commons.persistence.DBFactory;
 import org.olat.core.id.Identity;
 import org.olat.core.id.Roles;
@@ -74,6 +72,7 @@ import org.olat.repository.RepositoryManager;
 import org.olat.repository.RepositoryService;
 import org.olat.repository.model.SearchRepositoryEntryParameters;
 import org.olat.restapi.repository.course.CoursesWebService;
+import org.olat.restapi.support.vo.CourseConfigVO;
 import org.olat.restapi.support.vo.CourseVO;
 import org.olat.restapi.support.vo.RepositoryEntryVO;
 import org.olat.test.JunitTestHelper;
@@ -89,10 +88,14 @@ public class CourseTest extends OlatJerseyTestCase {
 	private ICourse course1;
 	private RestConnection conn;
 	
+	@Autowired
+	private DB dbInstance;
 	@Autowired
 	private RepositoryManager repositoryManager;
 	@Autowired
 	private RepositoryService repositoryService;
+	@Autowired
+	private BaseSecurityManager securityManager;
 
 	/**
 	 * SetUp is called before each test.
@@ -142,9 +145,25 @@ public class CourseTest extends OlatJerseyTestCase {
 		assertEquals(course1.getCourseTitle(), course.getTitle());
 	}
 	
+	@Test
+	public void testGetCourseConfig() throws IOException, URISyntaxException {
+		assertTrue("Cannot login as administrator", conn.login("administrator", "openolat"));
+		
+		URI uri = conn.getContextURI().path("repo").path("courses").path(course1.getResourceableId().toString()).path("configuration").build();
+		HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
+		HttpResponse response = conn.execute(method);
+		assertEquals(200, response.getStatusLine().getStatusCode());
+		CourseConfigVO courseConfig = conn.parse(response, CourseConfigVO.class);
+		Assert.assertNotNull(courseConfig);
+		Assert.assertNotNull(courseConfig.getCssLayoutRef());
+		Assert.assertNotNull(courseConfig.getCalendar());
+		Assert.assertNotNull(courseConfig.getChat());
+		Assert.assertNotNull(courseConfig.getEfficencyStatement());
+	}
+	
 	@Test
 	public void testGetCourse_keyRoundTrip() throws IOException, URISyntaxException {
-		RepositoryEntry courseRe = RepositoryManager.getInstance().lookupRepositoryEntry(course1, false);
+		RepositoryEntry courseRe = repositoryManager.lookupRepositoryEntry(course1, false);
 		Assert.assertNotNull(courseRe);
 		assertTrue("Cannot login as administrator", conn.login("administrator", "openolat"));
 		
@@ -201,7 +220,7 @@ public class CourseTest extends OlatJerseyTestCase {
 	@Test
 	public void testDeleteCourses() throws IOException, URISyntaxException {
 		ICourse course = CoursesWebService.createEmptyCourse(admin, "courseToDel", "course to delete", null);
-		DBFactory.getInstance().intermediateCommit();
+		dbInstance.intermediateCommit();
 		
 		assertTrue(conn.login("administrator", "openolat"));
 		
@@ -233,25 +252,21 @@ public class CourseTest extends OlatJerseyTestCase {
 		EntityUtils.consume(response.getEntity());
 
 		//is auth0 author
-		BaseSecurity securityManager = BaseSecurityManager.getInstance();
 		SecurityGroup authorGroup = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
 		boolean isAuthor = securityManager.isIdentityInSecurityGroup(auth0, authorGroup);
-		DBFactory.getInstance().intermediateCommit();
+		dbInstance.intermediateCommit();
 		assertTrue(isAuthor);
 		
 		//is auth0 owner
-		RepositoryManager rm = RepositoryManager.getInstance();
-		RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
-		RepositoryEntry repositoryEntry = rm.lookupRepositoryEntry(course1, true);
+		RepositoryEntry repositoryEntry = repositoryManager.lookupRepositoryEntry(course1, true);
 		boolean isOwner = repositoryService.hasRole(auth0, repositoryEntry, GroupRoles.owner.name());
-		DBFactory.getInstance().intermediateCommit();
+		dbInstance.intermediateCommit();
 		assertTrue(isOwner);
 	}
 	
 	@Test
 	public void testGetAuthors() throws IOException, URISyntaxException {
 		//make auth1 and auth2 authors
-		BaseSecurity securityManager = BaseSecurityManager.getInstance();
 		SecurityGroup authorGroup = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
 		if(!securityManager.isIdentityInSecurityGroup(auth1, authorGroup)) {
 			securityManager.addIdentityToSecurityGroup(auth1, authorGroup);
@@ -259,17 +274,16 @@ public class CourseTest extends OlatJerseyTestCase {
 		if(!securityManager.isIdentityInSecurityGroup(auth2, authorGroup)) {
 			securityManager.addIdentityToSecurityGroup(auth2, authorGroup);
 		}
-		DBFactory.getInstance().intermediateCommit();
+		dbInstance.intermediateCommit();
 		
 		//make auth1 and auth2 owner
-		RepositoryManager rm = RepositoryManager.getInstance();
-		RepositoryEntry repositoryEntry = rm.lookupRepositoryEntry(course1, true);
+		RepositoryEntry repositoryEntry = repositoryManager.lookupRepositoryEntry(course1, true);
 		List<Identity> authors = new ArrayList<Identity>();
 		authors.add(auth1);
 		authors.add(auth2);
 		IdentitiesAddEvent identitiesAddedEvent = new IdentitiesAddEvent(authors);
-		rm.addOwners(admin, identitiesAddedEvent, repositoryEntry);
-		DBFactory.getInstance().intermediateCommit();
+		repositoryManager.addOwners(admin, identitiesAddedEvent, repositoryEntry);
+		dbInstance.intermediateCommit();
 		
 		//get them
 		assertTrue(conn.login("administrator", "openolat"));
@@ -287,7 +301,6 @@ public class CourseTest extends OlatJerseyTestCase {
 	@Test
 	public void testRemoveAuthor() throws IOException, URISyntaxException {
 		//make auth1 and auth2 authors
-		BaseSecurity securityManager = BaseSecurityManager.getInstance();
 		SecurityGroup authorGroup = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
 		if(!securityManager.isIdentityInSecurityGroup(auth1, authorGroup)) {
 			securityManager.addIdentityToSecurityGroup(auth1, authorGroup);
@@ -295,17 +308,16 @@ public class CourseTest extends OlatJerseyTestCase {
 		if(!securityManager.isIdentityInSecurityGroup(auth2, authorGroup)) {
 			securityManager.addIdentityToSecurityGroup(auth2, authorGroup);
 		}
-		DBFactory.getInstance().intermediateCommit();
+		dbInstance.intermediateCommit();
 		
 		//make auth1 and auth2 owner
-		RepositoryManager rm = RepositoryManager.getInstance();
-		RepositoryEntry repositoryEntry = rm.lookupRepositoryEntry(course1, true);
+		RepositoryEntry repositoryEntry = repositoryManager.lookupRepositoryEntry(course1, true);
 		List<Identity> authors = new ArrayList<Identity>();
 		authors.add(auth1);
 		authors.add(auth2);
 		IdentitiesAddEvent identitiesAddedEvent = new IdentitiesAddEvent(authors);
-		rm.addOwners(admin, identitiesAddedEvent, repositoryEntry);
-		DBFactory.getInstance().intermediateCommit();
+		repositoryManager.addOwners(admin, identitiesAddedEvent, repositoryEntry);
+		dbInstance.intermediateCommit();
 		//end setup
 		
 		//test
@@ -323,10 +335,10 @@ public class CourseTest extends OlatJerseyTestCase {
 		EntityUtils.consume(response2.getEntity());
 		
 		//control
-		repositoryEntry = rm.lookupRepositoryEntry(course1, true);
+		repositoryEntry = repositoryManager.lookupRepositoryEntry(course1, true);
 		assertFalse(repositoryService.hasRole(auth1, repositoryEntry, GroupRoles.owner.name()));
 		assertFalse(repositoryService.hasRole(auth2, repositoryEntry, GroupRoles.owner.name()));
-		DBFactory.getInstance().intermediateCommit();
+		dbInstance.intermediateCommit();
 	}
 	
 	@Test
@@ -339,10 +351,9 @@ public class CourseTest extends OlatJerseyTestCase {
 		EntityUtils.consume(response.getEntity());
 
 		//is auth0 coach/tutor
-		RepositoryManager rm = RepositoryManager.getInstance();
-		RepositoryEntry repositoryEntry = rm.lookupRepositoryEntry(course1, true);
+		RepositoryEntry repositoryEntry = repositoryManager.lookupRepositoryEntry(course1, true);
 		boolean isTutor = repositoryService.hasRole(auth1, repositoryEntry, GroupRoles.coach.name());
-		DBFactory.getInstance().intermediateCommit();
+		dbInstance.intermediateCommit();
 		assertTrue(isTutor);
 	}
 	
@@ -356,10 +367,9 @@ public class CourseTest extends OlatJerseyTestCase {
 		EntityUtils.consume(response.getEntity());
 
 		//is auth2 participant
-		RepositoryManager rm = RepositoryManager.getInstance();
-		RepositoryEntry repositoryEntry = rm.lookupRepositoryEntry(course1, true);
+		RepositoryEntry repositoryEntry = repositoryManager.lookupRepositoryEntry(course1, true);
 		boolean isParticipant = repositoryService.hasRole(auth2, repositoryEntry, GroupRoles.participant.name());
-		DBFactory.getInstance().intermediateCommit();
+		dbInstance.intermediateCommit();
 		assertTrue(isParticipant);
 	}
 	
-- 
GitLab