use of org.olat.course.tree.CourseEditorTreeNode in project OpenOLAT by OpenOLAT.
the class ChooseNodeController method doCreateNode.
private void doCreateNode(String type) {
ICourse course = CourseFactory.getCourseEditSession(courseOres.getResourceableId());
// user chose a position to insert a new node
CourseNodeConfiguration newNodeConfig = CourseNodeFactory.getInstance().getCourseNodeConfiguration(type);
createdNode = newNodeConfig.getInstance();
// Set some default values
String title = new String(newNodeConfig.getLinkText(getLocale()));
createdNode.setShortTitle(title);
createdNode.setNoAccessExplanation(translate("form.noAccessExplanation.default"));
// Insert it now
CourseEditorTreeModel editorTreeModel = course.getEditorTreeModel();
if (editorTreeModel.getRootNode().equals(currentNode)) {
// root, add as last child
int pos = currentNode.getChildCount();
CourseNode selectedNode = currentNode.getCourseNode();
editorTreeModel.insertCourseNodeAt(createdNode, selectedNode, pos);
} else {
CourseEditorTreeNode parentNode = (CourseEditorTreeNode) currentNode.getParent();
CourseNode selectedNode = parentNode.getCourseNode();
int pos = currentNode.getPosition();
editorTreeModel.insertCourseNodeAt(createdNode, selectedNode, pos + 1);
}
CourseFactory.saveCourseEditorTreeModel(course.getResourceableId());
}
use of org.olat.course.tree.CourseEditorTreeNode in project OpenOLAT by OpenOLAT.
the class CustomDBController method updateDBList.
private void updateDBList(FormItemContainer formLayout) {
ICourse course = CourseFactory.loadCourse(courseKey);
CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
CourseNode rootNode = ((CourseEditorTreeNode) course.getEditorTreeModel().getRootNode()).getCourseNode();
Property p = cpm.findCourseNodeProperty(rootNode, null, null, CustomDBMainController.CUSTOM_DB);
List<String> databases = new ArrayList<>();
if (p != null && p.getTextValue() != null) {
String[] dbs = p.getTextValue().split(":");
for (String db : dbs) {
databases.add(db);
}
}
List<String> currentlyUsed = courseDbManager.getUsedCategories(course);
for (String db : currentlyUsed) {
if (!databases.contains(db)) {
databases.add(db);
}
}
int count = 0;
for (String db : databases) {
if (!StringHelper.containsNonWhitespace(db))
continue;
uifactory.addStaticExampleText("category_" + count, "customDb.category", db, formLayout);
String url = Settings.getServerContextPathURI() + RestSecurityHelper.SUB_CONTEXT + "/repo/courses/" + courseKey + "/db/" + db;
uifactory.addStaticExampleText("url_" + count, "customDb.url", url, formLayout);
final FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("buttonLayout_" + count, getTranslator());
formLayout.add(buttonLayout);
FormLink resetDb = uifactory.addFormLink("db-reset_" + count, "customDb.reset", "customDb.reset", buttonLayout, Link.BUTTON_SMALL);
resetDb.setUserObject(db);
resetDb.setVisible(!readOnly);
resetDbs.add(resetDb);
FormLink deleteDb = uifactory.addFormLink("db-delete_" + count, "delete", "delete", buttonLayout, Link.BUTTON_SMALL);
deleteDb.setUserObject(db);
deleteDb.setVisible(!readOnly);
deleteDbs.add(deleteDb);
FormLink exportDb = uifactory.addFormLink("db-export_" + count, "customDb.export", "customDb.export", buttonLayout, Link.BUTTON_SMALL);
exportDb.setUserObject(db);
exportDbs.add(exportDb);
count++;
}
}
use of org.olat.course.tree.CourseEditorTreeNode in project OpenOLAT by OpenOLAT.
the class AssessmentHelper method getAssessableNodes.
/**
* Get all assessable nodes including the root node (if assessable)
*
* @param editorModel
* @param excludeNode Node that should be excluded in the list, e.g. the
* current node or null if all assessable nodes should be used
* @return List of assessable course nodes
*/
public static List<CourseNode> getAssessableNodes(final CourseEditorTreeModel editorModel, final CourseNode excludeNode) {
CourseEditorTreeNode rootNode = (CourseEditorTreeNode) editorModel.getRootNode();
final List<CourseNode> nodes = new ArrayList<CourseNode>();
// visitor class: takes all assessable nodes if not the exclude node and
// puts
// them into the nodes list
Visitor visitor = new Visitor() {
@Override
public void visit(INode node) {
CourseEditorTreeNode editorNode = (CourseEditorTreeNode) node;
CourseNode courseNode = editorModel.getCourseNode(node.getIdent());
if (!editorNode.isDeleted() && (courseNode != excludeNode)) {
if (checkIfNodeIsAssessable(courseNode)) {
nodes.add(courseNode);
}
}
}
};
// not visit beginning at the root node
TreeVisitor tv = new TreeVisitor(visitor, rootNode, false);
tv.visitAll();
return nodes;
}
use of org.olat.course.tree.CourseEditorTreeNode in project openolat by klemens.
the class CoursesContactElementTest method testFullConfig.
@Test
public void testFullConfig() throws IOException, URISyntaxException {
assertTrue(conn.login("administrator", "openolat"));
// create an contact node
URI newContactUri = getElementsUri(course1).path("contact").queryParam("parentNodeId", rootNodeId).queryParam("position", "0").queryParam("shortTitle", "Contact-1").queryParam("longTitle", "Contact-long-1").queryParam("objectives", "Contact-objectives-1").queryParam("coaches", "true").queryParam("participants", "true").queryParam("groups", "").queryParam("areas", "").queryParam("to", "test@frentix.com;test2@frentix.com").queryParam("defaultSubject", "Hello by contact 1").queryParam("defaultBody", "Hello by contact 1 body").build();
HttpPut method = conn.createPut(newContactUri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
// check the return values
assertEquals(200, response.getStatusLine().getStatusCode());
CourseNodeVO contactNode = conn.parse(response, CourseNodeVO.class);
assertNotNull(contactNode);
assertNotNull(contactNode.getId());
// check the persisted value
ICourse course = CourseFactory.loadCourse(course1.getResourceableId());
TreeNode node = course.getEditorTreeModel().getNodeById(contactNode.getId());
assertNotNull(node);
CourseEditorTreeNode editorCourseNode = (CourseEditorTreeNode) node;
CourseNode courseNode = editorCourseNode.getCourseNode();
ModuleConfiguration config = courseNode.getModuleConfiguration();
assertNotNull(config);
assertEquals(config.getBooleanEntry(CONFIG_KEY_EMAILTOCOACHES), true);
assertEquals(config.getBooleanEntry(CONFIG_KEY_EMAILTOPARTICIPANTS), true);
@SuppressWarnings("unchecked") List<String> tos = (List<String>) config.get(CONFIG_KEY_EMAILTOADRESSES);
assertNotNull(tos);
assertEquals(2, tos.size());
assertEquals(config.get(CONFIG_KEY_MSUBJECT_DEFAULT), "Hello by contact 1");
assertEquals(config.get(CONFIG_KEY_MBODY_DEFAULT), "Hello by contact 1 body");
}
use of org.olat.course.tree.CourseEditorTreeNode in project openolat by klemens.
the class CourseHandler method importResource.
@Override
public RepositoryEntry importResource(Identity initialAuthor, String initialAuthorAlt, String displayname, String description, boolean withReferences, Locale locale, File file, String filename) {
OLATResource newCourseResource = OLATResourceManager.getInstance().createOLATResourceInstance(CourseModule.class);
ICourse course = CourseFactory.importCourseFromZip(newCourseResource, file);
// cfc.release();
if (course == null) {
return null;
}
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
RepositoryEntry re = repositoryService.create(initialAuthor, null, "", displayname, description, newCourseResource, RepositoryEntry.ACC_OWNERS);
DBFactory.getInstance().commit();
// create empty run structure
course = CourseFactory.openCourseEditSession(course.getResourceableId());
Structure runStructure = course.getRunStructure();
runStructure.getRootNode().removeAllChildren();
CourseFactory.saveCourse(course.getResourceableId());
// import references
CourseEditorTreeNode rootNode = (CourseEditorTreeNode) course.getEditorTreeModel().getRootNode();
importReferences(rootNode, course, initialAuthor, locale, withReferences);
if (withReferences && course.getCourseConfig().hasCustomSharedFolder()) {
importSharedFolder(course, initialAuthor);
}
if (withReferences && course.getCourseConfig().hasGlossary()) {
importGlossary(course, initialAuthor);
}
// create group management / import groups
CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
File fImportBaseDirectory = course.getCourseExportDataDir().getBasefile();
CourseEnvironmentMapper envMapper = cgm.importCourseBusinessGroups(fImportBaseDirectory);
envMapper.setAuthor(initialAuthor);
// upgrade course
course = CourseFactory.loadCourse(cgm.getCourseResource());
course.postImport(fImportBaseDirectory, envMapper);
// rename root nodes, but only when user modified the course title
boolean doUpdateTitle = true;
File repoConfigXml = new File(fImportBaseDirectory, "repo.xml");
if (repoConfigXml.exists()) {
RepositoryEntryImport importConfig;
try {
importConfig = RepositoryEntryImportExport.getConfiguration(new FileInputStream(repoConfigXml));
if (importConfig != null) {
if (displayname.equals(importConfig.getDisplayname())) {
// do not update if title was not modified during import
// user does not expect to have an updated title and there is a chance
// the root node title is not the same as the course title
doUpdateTitle = false;
}
}
} catch (FileNotFoundException e) {
// ignore
}
}
if (doUpdateTitle) {
// do not use truncate!
course.getRunStructure().getRootNode().setShortTitle(Formatter.truncateOnly(displayname, 25));
course.getRunStructure().getRootNode().setLongTitle(displayname);
}
// course.saveRunStructure();
CourseEditorTreeNode editorRootNode = ((CourseEditorTreeNode) course.getEditorTreeModel().getRootNode());
// do not use truncate!
editorRootNode.getCourseNode().setShortTitle(Formatter.truncateOnly(displayname, 25));
editorRootNode.getCourseNode().setLongTitle(displayname);
// mark entire structure as dirty/new so the user can re-publish
markDirtyNewRecursively(editorRootNode);
// root has already been created during export. Unmark it.
editorRootNode.setNewnode(false);
// save and close edit session
CourseFactory.saveCourse(course.getResourceableId());
CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
RepositoryEntryImportExport imp = new RepositoryEntryImportExport(fImportBaseDirectory);
if (imp.anyExportedPropertiesAvailable()) {
re = imp.importContent(re, getMediaContainer(re));
}
// import reminders
importReminders(re, fImportBaseDirectory, envMapper, initialAuthor);
// clean up export folder
cleanExportAfterImport(fImportBaseDirectory);
return re;
}
Aggregations