use of org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl 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.core.commons.modules.bc.vfs.OlatNamedContainerImpl in project openolat by klemens.
the class FileDocumentFactoryTest method testCreateHtmlDocument.
@Test
public void testCreateHtmlDocument() {
String filePath = "SearchTestFolder";
String htmlFileName = "test.html";
String htmlText = "<html><head><meta name=\"generator\" content=\"olat-tinymce-1\"><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body>" + "<H1>Test HTML Seite fuer JUnit Test</H1>" + "Dies ist<br />der Test Text" + // Text = 'Dies ist der Test Text'
"</body></html>";
// must include '\u00A0' !!! 19.5.2010/cg
String text = "Test HTML Seite fuer JUnit Test Dies ist der Test\u00A0Text";
// Create a test HTML File
OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(rootPath, null);
OlatNamedContainerImpl namedFolder = new OlatNamedContainerImpl(filePath, rootFolder);
VFSLeaf leaf = (VFSLeaf) namedFolder.resolve(htmlFileName);
if (leaf != null) {
leaf.delete();
}
leaf = namedFolder.createChildLeaf(htmlFileName);
FileUtils.save(leaf.getOutputStream(false), htmlText, "utf-8");
try {
SearchResourceContext resourceContext = new SearchResourceContext();
resourceContext.setBusinessControlFor(OresHelper.createOLATResourceableType("FileDocumentFactoryTest"));
resourceContext.setFilePath(filePath + "/" + leaf.getName());
Document htmlDocument = fileDocumentFactory.createDocument(resourceContext, leaf);
// 1. Check content
String content = htmlDocument.get(OlatDocument.CONTENT_FIELD_NAME);
assertEquals("Wrong HTML content=" + content.trim() + " , must be =" + text.trim(), text.trim(), content.trim());
// 2. Check resourceUrl
String resourceUrl = htmlDocument.get(OlatDocument.RESOURCEURL_FIELD_NAME);
assertEquals("Wrong ResourceUrl", "[FileDocumentFactoryTest:0][path=" + filePath + "/" + htmlFileName + "]", resourceUrl);
// 3. Check File-Type
String fileType = htmlDocument.get(OlatDocument.FILETYPE_FIELD_NAME);
assertEquals("Wrong file-type", "type.file.html", fileType);
} catch (IOException e) {
fail("IOException=" + e.getMessage());
} catch (DocumentAccessException e) {
fail("DocumentAccessException=" + e.getMessage());
}
}
use of org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl in project openolat by klemens.
the class CoursesFoldersTest method deleteFolder.
@Test
public void deleteFolder() throws IOException, URISyntaxException {
// add some folders
OlatNamedContainerImpl folder = BCCourseNode.getNodeFolderContainer((BCCourseNode) bcNode, course1.getCourseEnvironment());
VFSItem item = folder.resolve("FolderToDelete");
if (item == null) {
folder.createChildContainer("FolderToDelete");
}
assertTrue(conn.login("administrator", "openolat"));
URI uri = UriBuilder.fromUri(getNodeURI()).path("files").path("FolderToDelete").build();
HttpDelete method = conn.createDelete(uri, MediaType.APPLICATION_JSON);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
VFSItem deletedItem = folder.resolve("FolderToDelete");
assertNull(deletedItem);
}
use of org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl in project openolat by klemens.
the class CoursesFoldersTest method testUploadFile.
@Test
public void testUploadFile() throws IOException, URISyntaxException {
assertTrue(conn.login("administrator", "openolat"));
URI uri = UriBuilder.fromUri(getNodeURI()).path("files").build();
// create single page
URL fileUrl = CoursesFoldersTest.class.getResource("singlepage.html");
assertNotNull(fileUrl);
File file = new File(fileUrl.toURI());
HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
conn.addMultipart(method, file.getName(), file);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
OlatNamedContainerImpl folder = BCCourseNode.getNodeFolderContainer((BCCourseNode) bcNode, course1.getCourseEnvironment());
VFSItem item = folder.resolve(file.getName());
assertNotNull(item);
}
use of org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl in project openolat by klemens.
the class SharedFolderManager method getNamedSharedFolder.
/**
* @param re The repository entry of the shared folder
* @param urlCompliant Encode the name to be file save
* @return The container
*/
public VFSContainer getNamedSharedFolder(RepositoryEntry re, boolean urlCompliant) {
String name = re.getDisplayname();
if (urlCompliant) {
name = RequestUtil.normalizeFilename(name);
}
OlatRootFolderImpl folder = getSharedFolder(re.getOlatResource());
return folder == null ? null : new OlatNamedContainerImpl(name, folder);
}
Aggregations