use of org.olat.resource.OLATResourceManager in project OpenOLAT by OpenOLAT.
the class GroupMgmtTest method setUp.
/**
* Set up a course with learn group and group area
* @see org.olat.test.OlatJerseyTestCase#setUp()
*/
@Before
@Override
public void setUp() throws Exception {
super.setUp();
conn = new RestConnection();
// create a course with learn group
owner1 = JunitTestHelper.createAndPersistIdentityAsUser("rest-one");
owner2 = JunitTestHelper.createAndPersistIdentityAsUser("rest-two");
owner3 = JunitTestHelper.createAndPersistIdentityAsUser("rest-three");
part1 = JunitTestHelper.createAndPersistIdentityAsUser("rest-four");
part2 = JunitTestHelper.createAndPersistIdentityAsUser("rest-five");
part3 = JunitTestHelper.createAndPersistIdentityAsUser("rest-six");
OLATResourceManager rm = OLATResourceManager.getInstance();
// create course and persist as OLATResourceImpl
OLATResourceable resourceable = OresHelper.createOLATResourceableInstance("junitcourse", System.currentTimeMillis());
course = rm.findOrPersistResourceable(resourceable);
RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
RepositoryEntry re = rs.create("administrator", "-", "rest-re", null, course);
DBFactory.getInstance().commit();
assertNotNull(re);
// create learn group
// 1) context one: learning groups
RepositoryEntry c1 = JunitTestHelper.createAndPersistRepositoryEntry();
// create groups without waiting list
g1 = businessGroupService.createBusinessGroup(null, "rest-g1", null, 0, 10, false, false, c1);
g2 = businessGroupService.createBusinessGroup(null, "rest-g2", null, 0, 10, false, false, c1);
DBFactory.getInstance().commit();
// permission to see owners and participants
businessGroupService.updateDisplayMembers(g1, false, false, false, false, false, false, false);
businessGroupService.updateDisplayMembers(g2, true, true, false, false, false, false, false);
// members g1
businessGroupRelationDao.addRole(owner1, g1, GroupRoles.coach.name());
businessGroupRelationDao.addRole(owner2, g1, GroupRoles.coach.name());
businessGroupRelationDao.addRole(part1, g1, GroupRoles.participant.name());
businessGroupRelationDao.addRole(part2, g1, GroupRoles.participant.name());
// members g2
businessGroupRelationDao.addRole(owner1, g2, GroupRoles.coach.name());
businessGroupRelationDao.addRole(part1, g2, GroupRoles.participant.name());
// 2) context two: right groups
RepositoryEntry c2 = JunitTestHelper.createAndPersistRepositoryEntry();
// groups
g3 = businessGroupService.createBusinessGroup(null, "rest-g3", null, -1, -1, false, false, c2);
g4 = businessGroupService.createBusinessGroup(null, "rest-g4", null, -1, -1, false, false, c2);
DBFactory.getInstance().commit();
// members
businessGroupRelationDao.addRole(owner1, g3, GroupRoles.participant.name());
businessGroupRelationDao.addRole(owner2, g4, GroupRoles.participant.name());
// 3) collaboration tools
CollaborationTools collabTools1 = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g1);
collabTools1.setToolEnabled(CollaborationTools.TOOL_FORUM, true);
collabTools1.setToolEnabled(CollaborationTools.TOOL_WIKI, true);
collabTools1.saveNews("<p>Hello world</p>");
try {
collabTools1.createForumController(null, null, true, false, null);
} catch (Exception e) {
// will fail but generate the forum key
}
CollaborationTools collabTools2 = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g2);
collabTools2.setToolEnabled(CollaborationTools.TOOL_FORUM, true);
// simulate user clicks
DBFactory.getInstance().closeSession();
// 4) fill forum for g1
NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(g1);
Property forumKeyProperty = npm.findProperty(null, null, CollaborationTools.PROP_CAT_BG_COLLABTOOLS, CollaborationTools.KEY_FORUM);
ForumManager fm = ForumManager.getInstance();
Forum forum = fm.loadForum(forumKeyProperty.getLongValue());
m1 = fm.createMessage(forum, owner1, false);
m1.setTitle("Thread-1");
m1.setBody("Body of Thread-1");
fm.addTopMessage(m1);
m2 = fm.createMessage(forum, owner2, false);
m2.setTitle("Thread-2");
m2.setBody("Body of Thread-2");
fm.addTopMessage(m2);
DBFactory.getInstance().intermediateCommit();
m3 = fm.createMessage(forum, owner3, false);
m3.setTitle("Message-1.1");
m3.setBody("Body of Message-1.1");
fm.replyToMessage(m3, m1);
m4 = fm.createMessage(forum, part1, false);
m4.setTitle("Message-1.1.1");
m4.setBody("Body of Message-1.1.1");
fm.replyToMessage(m4, m3);
m5 = fm.createMessage(forum, part2, false);
m5.setTitle("Message-1.2");
m5.setBody("Body of Message-1.2");
fm.replyToMessage(m5, m1);
DBFactory.getInstance().intermediateCommit();
}
use of org.olat.resource.OLATResourceManager in project OpenOLAT by OpenOLAT.
the class RepositoryEntriesTest method createRepository.
private RepositoryEntry createRepository(String displayName) {
OLATResourceManager rm = OLATResourceManager.getInstance();
// create course and persist as OLATResourceImpl
OLATResource r = rm.createOLATResourceInstance("DummyType");
DBFactory.getInstance().saveObject(r);
DBFactory.getInstance().intermediateCommit();
RepositoryEntry d = repositoryService.create(displayName, "-", displayName, "Repo entry", r);
DBFactory.getInstance().commit();
return d;
}
use of org.olat.resource.OLATResourceManager in project OpenOLAT by OpenOLAT.
the class UserMgmtTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
if (setuped)
return;
// create identities
owner1 = JunitTestHelper.createAndPersistIdentityAsUser("user-rest-zero");
assertNotNull(owner1);
id1 = JunitTestHelper.createAndPersistIdentityAsUser("user-rest-one-" + UUID.randomUUID().toString());
id2 = JunitTestHelper.createAndPersistIdentityAsUser("user-rest-two");
dbInstance.intermediateCommit();
id2.getUser().setProperty("telMobile", "39847592");
id2.getUser().setProperty("gender", "female");
id2.getUser().setProperty("birthDay", "20091212");
dbInstance.updateObject(id2.getUser());
dbInstance.intermediateCommit();
id3 = JunitTestHelper.createAndPersistIdentityAsUser("user-rest-three");
OlatRootFolderImpl id3HomeFolder = new OlatRootFolderImpl(FolderConfig.getUserHome(id3.getName()), null);
VFSContainer id3PublicFolder = (VFSContainer) id3HomeFolder.resolve("public");
if (id3PublicFolder == null) {
id3PublicFolder = id3HomeFolder.createChildContainer("public");
}
VFSItem portrait = id3PublicFolder.resolve("portrait.jpg");
if (portrait == null) {
URL portraitUrl = CoursesElementsTest.class.getResource("portrait.jpg");
File ioPortrait = new File(portraitUrl.toURI());
FileUtils.copyFileToDirectory(ioPortrait, ((LocalImpl) id3PublicFolder).getBasefile(), false);
}
OLATResourceManager rm = OLATResourceManager.getInstance();
// create course and persist as OLATResourceImpl
OLATResourceable resourceable = OresHelper.createOLATResourceableInstance("junitcourse", System.currentTimeMillis());
OLATResource course = rm.createOLATResourceInstance(resourceable);
dbInstance.saveObject(course);
dbInstance.intermediateCommit();
// create learn group
// 1) context one: learning groups
RepositoryEntry c1 = JunitTestHelper.createAndPersistRepositoryEntry();
// create groups without waiting list
g1externalId = UUID.randomUUID().toString();
g1 = businessGroupService.createBusinessGroup(null, "user-rest-g1", null, g1externalId, "all", 0, 10, false, false, c1);
g2 = businessGroupService.createBusinessGroup(null, "user-rest-g2", null, 0, 10, false, false, c1);
// members g1
businessGroupRelationDao.addRole(id1, g1, GroupRoles.coach.name());
businessGroupRelationDao.addRole(id2, g1, GroupRoles.participant.name());
// members g2
businessGroupRelationDao.addRole(id2, g2, GroupRoles.coach.name());
businessGroupRelationDao.addRole(id1, g2, GroupRoles.participant.name());
// 2) context two: right groups
RepositoryEntry c2 = JunitTestHelper.createAndPersistRepositoryEntry();
// groups
g3ExternalId = UUID.randomUUID().toString();
g3 = businessGroupService.createBusinessGroup(null, "user-rest-g3", null, g3ExternalId, "all", -1, -1, false, false, c2);
g4 = businessGroupService.createBusinessGroup(null, "user-rest-g4", null, -1, -1, false, false, c2);
// members
businessGroupRelationDao.addRole(id1, g3, GroupRoles.participant.name());
businessGroupRelationDao.addRole(id2, g4, GroupRoles.participant.name());
dbInstance.closeSession();
// add some collaboration tools
CollaborationTools g1CTSMngr = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g1);
g1CTSMngr.setToolEnabled(CollaborationTools.TOOL_FORUM, true);
// create the forum
Forum g1Forum = g1CTSMngr.getForum();
Message m1 = ForumManager.getInstance().createMessage(g1Forum, id1, false);
m1.setTitle("Thread-1");
m1.setBody("Body of Thread-1");
ForumManager.getInstance().addTopMessage(m1);
dbInstance.commitAndCloseSession();
// add some folder tool
CollaborationTools g2CTSMngr = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g2);
g2CTSMngr.setToolEnabled(CollaborationTools.TOOL_FOLDER, true);
OlatRootFolderImpl g2Folder = new OlatRootFolderImpl(g2CTSMngr.getFolderRelPath(), null);
g2Folder.getBasefile().mkdirs();
VFSItem groupPortrait = g2Folder.resolve("portrait.jpg");
if (groupPortrait == null) {
URL portraitUrl = UserMgmtTest.class.getResource("portrait.jpg");
File ioPortrait = new File(portraitUrl.toURI());
FileUtils.copyFileToDirectory(ioPortrait, g2Folder.getBasefile(), false);
}
dbInstance.commitAndCloseSession();
// prepare some courses
Identity author = JunitTestHelper.createAndPersistIdentityAsUser("auth-" + UUID.randomUUID().toString());
RepositoryEntry entry = JunitTestHelper.deployDemoCourse(author);
if (!repositoryService.hasRole(id1, entry, GroupRoles.participant.name())) {
repositoryService.addRole(id1, entry, GroupRoles.participant.name());
}
demoCourse = CourseFactory.loadCourse(entry);
TreeVisitor visitor = new TreeVisitor(new Visitor() {
@Override
public void visit(INode node) {
if (node instanceof FOCourseNode) {
if (demoForumNode == null) {
demoForumNode = (FOCourseNode) node;
Forum courseForum = demoForumNode.loadOrCreateForum(demoCourse.getCourseEnvironment());
Message message1 = ForumManager.getInstance().createMessage(courseForum, id1, false);
message1.setTitle("Thread-1");
message1.setBody("Body of Thread-1");
ForumManager.getInstance().addTopMessage(message1);
}
} else if (node instanceof BCCourseNode) {
if (demoBCCourseNode == null) {
demoBCCourseNode = (BCCourseNode) node;
OlatNamedContainerImpl container = BCCourseNode.getNodeFolderContainer(demoBCCourseNode, demoCourse.getCourseEnvironment());
VFSItem example = container.resolve("singlepage.html");
if (example == null) {
try {
InputStream htmlUrl = UserMgmtTest.class.getResourceAsStream("singlepage.html");
VFSLeaf htmlLeaf = container.createChildLeaf("singlepage.html");
IOUtils.copy(htmlUrl, htmlLeaf.getOutputStream(false));
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
}, demoCourse.getRunStructure().getRootNode(), false);
visitor.visitAll();
dbInstance.commitAndCloseSession();
setuped = true;
}
use of org.olat.resource.OLATResourceManager in project openolat by klemens.
the class UserMgmtTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
if (setuped)
return;
// create identities
owner1 = JunitTestHelper.createAndPersistIdentityAsUser("user-rest-zero");
assertNotNull(owner1);
id1 = JunitTestHelper.createAndPersistIdentityAsUser("user-rest-one-" + UUID.randomUUID().toString());
id2 = JunitTestHelper.createAndPersistIdentityAsUser("user-rest-two");
dbInstance.intermediateCommit();
id2.getUser().setProperty("telMobile", "39847592");
id2.getUser().setProperty("gender", "female");
id2.getUser().setProperty("birthDay", "20091212");
dbInstance.updateObject(id2.getUser());
dbInstance.intermediateCommit();
id3 = JunitTestHelper.createAndPersistIdentityAsUser("user-rest-three");
OlatRootFolderImpl id3HomeFolder = new OlatRootFolderImpl(FolderConfig.getUserHome(id3.getName()), null);
VFSContainer id3PublicFolder = (VFSContainer) id3HomeFolder.resolve("public");
if (id3PublicFolder == null) {
id3PublicFolder = id3HomeFolder.createChildContainer("public");
}
VFSItem portrait = id3PublicFolder.resolve("portrait.jpg");
if (portrait == null) {
URL portraitUrl = CoursesElementsTest.class.getResource("portrait.jpg");
File ioPortrait = new File(portraitUrl.toURI());
FileUtils.copyFileToDirectory(ioPortrait, ((LocalImpl) id3PublicFolder).getBasefile(), false);
}
OLATResourceManager rm = OLATResourceManager.getInstance();
// create course and persist as OLATResourceImpl
OLATResourceable resourceable = OresHelper.createOLATResourceableInstance("junitcourse", System.currentTimeMillis());
OLATResource course = rm.createOLATResourceInstance(resourceable);
dbInstance.saveObject(course);
dbInstance.intermediateCommit();
// create learn group
// 1) context one: learning groups
RepositoryEntry c1 = JunitTestHelper.createAndPersistRepositoryEntry();
// create groups without waiting list
g1externalId = UUID.randomUUID().toString();
g1 = businessGroupService.createBusinessGroup(null, "user-rest-g1", null, g1externalId, "all", 0, 10, false, false, c1);
g2 = businessGroupService.createBusinessGroup(null, "user-rest-g2", null, 0, 10, false, false, c1);
// members g1
businessGroupRelationDao.addRole(id1, g1, GroupRoles.coach.name());
businessGroupRelationDao.addRole(id2, g1, GroupRoles.participant.name());
// members g2
businessGroupRelationDao.addRole(id2, g2, GroupRoles.coach.name());
businessGroupRelationDao.addRole(id1, g2, GroupRoles.participant.name());
// 2) context two: right groups
RepositoryEntry c2 = JunitTestHelper.createAndPersistRepositoryEntry();
// groups
g3ExternalId = UUID.randomUUID().toString();
g3 = businessGroupService.createBusinessGroup(null, "user-rest-g3", null, g3ExternalId, "all", -1, -1, false, false, c2);
g4 = businessGroupService.createBusinessGroup(null, "user-rest-g4", null, -1, -1, false, false, c2);
// members
businessGroupRelationDao.addRole(id1, g3, GroupRoles.participant.name());
businessGroupRelationDao.addRole(id2, g4, GroupRoles.participant.name());
dbInstance.closeSession();
// add some collaboration tools
CollaborationTools g1CTSMngr = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g1);
g1CTSMngr.setToolEnabled(CollaborationTools.TOOL_FORUM, true);
// create the forum
Forum g1Forum = g1CTSMngr.getForum();
Message m1 = ForumManager.getInstance().createMessage(g1Forum, id1, false);
m1.setTitle("Thread-1");
m1.setBody("Body of Thread-1");
ForumManager.getInstance().addTopMessage(m1);
dbInstance.commitAndCloseSession();
// add some folder tool
CollaborationTools g2CTSMngr = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g2);
g2CTSMngr.setToolEnabled(CollaborationTools.TOOL_FOLDER, true);
OlatRootFolderImpl g2Folder = new OlatRootFolderImpl(g2CTSMngr.getFolderRelPath(), null);
g2Folder.getBasefile().mkdirs();
VFSItem groupPortrait = g2Folder.resolve("portrait.jpg");
if (groupPortrait == null) {
URL portraitUrl = UserMgmtTest.class.getResource("portrait.jpg");
File ioPortrait = new File(portraitUrl.toURI());
FileUtils.copyFileToDirectory(ioPortrait, g2Folder.getBasefile(), false);
}
dbInstance.commitAndCloseSession();
// prepare some courses
Identity author = JunitTestHelper.createAndPersistIdentityAsUser("auth-" + UUID.randomUUID().toString());
RepositoryEntry entry = JunitTestHelper.deployDemoCourse(author);
if (!repositoryService.hasRole(id1, entry, GroupRoles.participant.name())) {
repositoryService.addRole(id1, entry, GroupRoles.participant.name());
}
demoCourse = CourseFactory.loadCourse(entry);
TreeVisitor visitor = new TreeVisitor(new Visitor() {
@Override
public void visit(INode node) {
if (node instanceof FOCourseNode) {
if (demoForumNode == null) {
demoForumNode = (FOCourseNode) node;
Forum courseForum = demoForumNode.loadOrCreateForum(demoCourse.getCourseEnvironment());
Message message1 = ForumManager.getInstance().createMessage(courseForum, id1, false);
message1.setTitle("Thread-1");
message1.setBody("Body of Thread-1");
ForumManager.getInstance().addTopMessage(message1);
}
} else if (node instanceof BCCourseNode) {
if (demoBCCourseNode == null) {
demoBCCourseNode = (BCCourseNode) node;
OlatNamedContainerImpl container = BCCourseNode.getNodeFolderContainer(demoBCCourseNode, demoCourse.getCourseEnvironment());
VFSItem example = container.resolve("singlepage.html");
if (example == null) {
try {
InputStream htmlUrl = UserMgmtTest.class.getResourceAsStream("singlepage.html");
VFSLeaf htmlLeaf = container.createChildLeaf("singlepage.html");
IOUtils.copy(htmlUrl, htmlLeaf.getOutputStream(false));
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
}, demoCourse.getRunStructure().getRootNode(), false);
visitor.visitAll();
dbInstance.commitAndCloseSession();
setuped = true;
}
use of org.olat.resource.OLATResourceManager in project openolat by klemens.
the class GroupMgmtTest method setUp.
/**
* Set up a course with learn group and group area
* @see org.olat.test.OlatJerseyTestCase#setUp()
*/
@Before
@Override
public void setUp() throws Exception {
super.setUp();
conn = new RestConnection();
// create a course with learn group
owner1 = JunitTestHelper.createAndPersistIdentityAsUser("rest-one");
owner2 = JunitTestHelper.createAndPersistIdentityAsUser("rest-two");
owner3 = JunitTestHelper.createAndPersistIdentityAsUser("rest-three");
part1 = JunitTestHelper.createAndPersistIdentityAsUser("rest-four");
part2 = JunitTestHelper.createAndPersistIdentityAsUser("rest-five");
part3 = JunitTestHelper.createAndPersistIdentityAsUser("rest-six");
OLATResourceManager rm = OLATResourceManager.getInstance();
// create course and persist as OLATResourceImpl
OLATResourceable resourceable = OresHelper.createOLATResourceableInstance("junitcourse", System.currentTimeMillis());
course = rm.findOrPersistResourceable(resourceable);
RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
RepositoryEntry re = rs.create("administrator", "-", "rest-re", null, course);
DBFactory.getInstance().commit();
assertNotNull(re);
// create learn group
// 1) context one: learning groups
RepositoryEntry c1 = JunitTestHelper.createAndPersistRepositoryEntry();
// create groups without waiting list
g1 = businessGroupService.createBusinessGroup(null, "rest-g1", null, 0, 10, false, false, c1);
g2 = businessGroupService.createBusinessGroup(null, "rest-g2", null, 0, 10, false, false, c1);
DBFactory.getInstance().commit();
// permission to see owners and participants
businessGroupService.updateDisplayMembers(g1, false, false, false, false, false, false, false);
businessGroupService.updateDisplayMembers(g2, true, true, false, false, false, false, false);
// members g1
businessGroupRelationDao.addRole(owner1, g1, GroupRoles.coach.name());
businessGroupRelationDao.addRole(owner2, g1, GroupRoles.coach.name());
businessGroupRelationDao.addRole(part1, g1, GroupRoles.participant.name());
businessGroupRelationDao.addRole(part2, g1, GroupRoles.participant.name());
// members g2
businessGroupRelationDao.addRole(owner1, g2, GroupRoles.coach.name());
businessGroupRelationDao.addRole(part1, g2, GroupRoles.participant.name());
// 2) context two: right groups
RepositoryEntry c2 = JunitTestHelper.createAndPersistRepositoryEntry();
// groups
g3 = businessGroupService.createBusinessGroup(null, "rest-g3", null, -1, -1, false, false, c2);
g4 = businessGroupService.createBusinessGroup(null, "rest-g4", null, -1, -1, false, false, c2);
DBFactory.getInstance().commit();
// members
businessGroupRelationDao.addRole(owner1, g3, GroupRoles.participant.name());
businessGroupRelationDao.addRole(owner2, g4, GroupRoles.participant.name());
// 3) collaboration tools
CollaborationTools collabTools1 = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g1);
collabTools1.setToolEnabled(CollaborationTools.TOOL_FORUM, true);
collabTools1.setToolEnabled(CollaborationTools.TOOL_WIKI, true);
collabTools1.saveNews("<p>Hello world</p>");
try {
collabTools1.createForumController(null, null, true, false, null);
} catch (Exception e) {
// will fail but generate the forum key
}
CollaborationTools collabTools2 = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g2);
collabTools2.setToolEnabled(CollaborationTools.TOOL_FORUM, true);
// simulate user clicks
DBFactory.getInstance().closeSession();
// 4) fill forum for g1
NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(g1);
Property forumKeyProperty = npm.findProperty(null, null, CollaborationTools.PROP_CAT_BG_COLLABTOOLS, CollaborationTools.KEY_FORUM);
ForumManager fm = ForumManager.getInstance();
Forum forum = fm.loadForum(forumKeyProperty.getLongValue());
m1 = fm.createMessage(forum, owner1, false);
m1.setTitle("Thread-1");
m1.setBody("Body of Thread-1");
fm.addTopMessage(m1);
m2 = fm.createMessage(forum, owner2, false);
m2.setTitle("Thread-2");
m2.setBody("Body of Thread-2");
fm.addTopMessage(m2);
DBFactory.getInstance().intermediateCommit();
m3 = fm.createMessage(forum, owner3, false);
m3.setTitle("Message-1.1");
m3.setBody("Body of Message-1.1");
fm.replyToMessage(m3, m1);
m4 = fm.createMessage(forum, part1, false);
m4.setTitle("Message-1.1.1");
m4.setBody("Body of Message-1.1.1");
fm.replyToMessage(m4, m3);
m5 = fm.createMessage(forum, part2, false);
m5.setTitle("Message-1.2");
m5.setBody("Body of Message-1.2");
fm.replyToMessage(m5, m1);
DBFactory.getInstance().intermediateCommit();
}
Aggregations