use of org.olat.core.util.nodes.INode in project openolat by klemens.
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.core.util.nodes.INode in project openolat by klemens.
the class BCWebService method getFolders.
/**
* Retrieves metadata of the course node
* @response.representation.200.qname {http://www.example.com}folderVOes
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The course node metadatas
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_FOLDERVOes}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course or parentNode not found
* @param courseId The course resourceable's id
* @param nodeId The node's id
* @param httpRequest The HTTP request
* @return The persisted structure element (fully populated)
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getFolders(@PathParam("courseId") Long courseId, @Context HttpServletRequest httpRequest) {
final ICourse course = CoursesWebService.loadCourse(courseId);
if (course == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (!CourseWebService.isCourseAccessible(course, false, httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
final UserRequest ureq = getUserRequest(httpRequest);
RepositoryEntry entry = RepositoryManager.getInstance().lookupRepositoryEntry(course, true);
ACService acManager = CoreSpringFactory.getImpl(ACService.class);
AccessResult result = acManager.isAccessible(entry, ureq.getIdentity(), false);
if (!result.isAccessible()) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
final Set<String> subscribed = new HashSet<String>();
NotificationsManager man = NotificationsManager.getInstance();
List<String> notiTypes = Collections.singletonList("FolderModule");
List<Subscriber> subs = man.getSubscribers(ureq.getIdentity(), notiTypes);
for (Subscriber sub : subs) {
Long courseKey = sub.getPublisher().getResId();
if (courseId.equals(courseKey)) {
subscribed.add(sub.getPublisher().getSubidentifier());
break;
}
}
final List<FolderVO> folderVOs = new ArrayList<FolderVO>();
new CourseTreeVisitor(course, ureq.getUserSession().getIdentityEnvironment()).visit(new Visitor() {
@Override
public void visit(INode node) {
if (node instanceof BCCourseNode) {
BCCourseNode bcNode = (BCCourseNode) node;
FolderVO folder = createFolderVO(ureq.getUserSession().getIdentityEnvironment(), course, bcNode, subscribed);
folderVOs.add(folder);
}
}
}, new VisibleTreeFilter());
FolderVOes voes = new FolderVOes();
voes.setFolders(folderVOs.toArray(new FolderVO[folderVOs.size()]));
voes.setTotalCount(folderVOs.size());
return Response.ok(voes).build();
}
use of org.olat.core.util.nodes.INode in project openolat by klemens.
the class CourseRuntimeController method initTools.
private void initTools(Dropdown tools, ICourse course, final UserCourseEnvironmentImpl uce) {
// 1) administrative tools
if (reSecurity.isEntryAdmin() || reSecurity.isCourseCoach() || reSecurity.isGroupCoach() || hasCourseRight(CourseRights.RIGHT_COURSEEDITOR) || hasCourseRight(CourseRights.RIGHT_MEMBERMANAGEMENT) || hasCourseRight(CourseRights.RIGHT_GROUPMANAGEMENT) || hasCourseRight(CourseRights.RIGHT_ARCHIVING) || hasCourseRight(CourseRights.RIGHT_STATISTICS) || hasCourseRight(CourseRights.RIGHT_DB) || hasCourseRight(CourseRights.RIGHT_ASSESSMENT) || hasCourseRight(CourseRights.RIGHT_ASSESSMENT_MODE)) {
tools.setI18nKey("header.tools");
tools.setElementCssClass("o_sel_course_tools");
if (uce != null && (reSecurity.isEntryAdmin() || hasCourseRight(CourseRights.RIGHT_COURSEEDITOR))) {
boolean managed = RepositoryEntryManagedFlag.isManaged(getRepositoryEntry(), RepositoryEntryManagedFlag.editcontent);
boolean readOnly = uce.isCourseReadOnly();
editLink = LinkFactory.createToolLink("edit.cmd", translate("command.openeditor"), this, "o_icon_courseeditor");
editLink.setElementCssClass("o_sel_course_editor");
editLink.setEnabled(!corrupted && !managed);
editLink.setVisible(!readOnly);
tools.addComponent(editLink);
folderLink = LinkFactory.createToolLink("cfd", translate("command.coursefolder"), this, "o_icon_coursefolder");
folderLink.setElementCssClass("o_sel_course_folder");
tools.addComponent(folderLink);
tools.addComponent(new Spacer(""));
}
if (reSecurity.isEntryAdmin() || hasCourseRight(CourseRights.RIGHT_GROUPMANAGEMENT) || hasCourseRight(CourseRights.RIGHT_MEMBERMANAGEMENT)) {
membersLink = LinkFactory.createToolLink("unifiedusermngt", translate("command.opensimplegroupmngt"), this, "o_icon_membersmanagement");
membersLink.setElementCssClass("o_sel_course_members");
tools.addComponent(membersLink);
}
if (reSecurity.isEntryAdmin() || reSecurity.isCourseCoach() || reSecurity.isGroupCoach() || hasCourseRight(CourseRights.RIGHT_ASSESSMENT)) {
assessmentLink = LinkFactory.createToolLink("assessment", translate("command.openassessment"), this, "o_icon_assessment_tool");
assessmentLink.setElementCssClass("o_sel_course_assessment_tool");
tools.addComponent(assessmentLink);
}
if (reSecurity.isEntryAdmin() || hasCourseRight(CourseRights.RIGHT_ARCHIVING)) {
archiverLink = LinkFactory.createToolLink("archiver", translate("command.openarchiver"), this, "o_icon_archive_tool");
tools.addComponent(archiverLink);
}
tools.addComponent(new Spacer(""));
if (reSecurity.isEntryAdmin() || hasCourseRight(CourseRights.RIGHT_STATISTICS)) {
courseStatisticLink = LinkFactory.createToolLink("statistic", translate("command.openstatistic"), this, "o_icon_statistics_tool");
tools.addComponent(courseStatisticLink);
}
if (uce != null && (reSecurity.isEntryAdmin() || reSecurity.isCourseCoach() || reSecurity.isGroupCoach() || hasCourseRight(CourseRights.RIGHT_STATISTICS))) {
final AtomicInteger testNodes = new AtomicInteger();
final AtomicInteger surveyNodes = new AtomicInteger();
new TreeVisitor(new Visitor() {
@Override
public void visit(INode node) {
if (((CourseNode) node).isStatisticNodeResultAvailable(uce, QTIType.test, QTIType.onyx)) {
testNodes.incrementAndGet();
} else if (((CourseNode) node).isStatisticNodeResultAvailable(uce, QTIType.survey)) {
surveyNodes.incrementAndGet();
}
}
}, course.getRunStructure().getRootNode(), true).visitAll();
if (testNodes.intValue() > 0) {
testStatisticLink = LinkFactory.createToolLink("qtistatistic", translate("command.openteststatistic"), this, "o_icon_statistics_tool");
tools.addComponent(testStatisticLink);
}
if (surveyNodes.intValue() > 0) {
surveyStatisticLink = LinkFactory.createToolLink("qtistatistic", translate("command.opensurveystatistic"), this, "o_icon_statistics_tool");
tools.addComponent(surveyStatisticLink);
}
}
tools.addComponent(new Spacer(""));
if (reSecurity.isEntryAdmin() || hasCourseRight(CourseRights.RIGHT_COURSEEDITOR)) {
areaLink = LinkFactory.createToolLink("careas", translate("command.courseareas"), this, "o_icon_courseareas");
areaLink.setElementCssClass("o_sel_course_areas");
tools.addComponent(areaLink);
}
if (courseDBManager.isEnabled() && (reSecurity.isEntryAdmin() || hasCourseRight(CourseRights.RIGHT_DB))) {
dbLink = LinkFactory.createToolLink("customDb", translate("command.opendb"), this, "o_icon_coursedb");
tools.addComponent(dbLink);
}
ordersLink = LinkFactory.createToolLink("bookings", translate("details.orders"), this, "o_sel_repo_booking");
ordersLink.setIconLeftCSS("o_icon o_icon-fw o_icon_booking");
ordersLink.setElementCssClass("o_sel_course_ac_tool");
boolean booking = acService.isResourceAccessControled(getRepositoryEntry().getOlatResource(), null);
ordersLink.setVisible(!corrupted && booking);
tools.addComponent(ordersLink);
}
}
use of org.olat.core.util.nodes.INode in project openolat by klemens.
the class CourseRuntimeController method isAllowedToLeave.
private boolean isAllowedToLeave(UserCourseEnvironmentImpl uce) {
if (uce.getParticipatingGroups().size() > 0) {
CourseNode rootNode = uce.getCourseEnvironment().getRunStructure().getRootNode();
OLATResource courseResource = uce.getCourseEnvironment().getCourseGroupManager().getCourseResource();
AtomicBoolean bool = new AtomicBoolean(false);
new TreeVisitor(new Visitor() {
@Override
public void visit(INode node) {
if (!bool.get() && node instanceof ENCourseNode) {
try {
ENCourseNode enNode = (ENCourseNode) node;
boolean cancelEnrollEnabled = enNode.getModuleConfiguration().getBooleanSafe(ENCourseNode.CONF_CANCEL_ENROLL_ENABLED);
if (!cancelEnrollEnabled && enNode.isUsedForEnrollment(uce.getParticipatingGroups(), courseResource)) {
bool.set(true);
}
} catch (Exception e) {
logError("", e);
}
}
}
}, rootNode, true).visitAll();
if (bool.get()) {
// is in a enrollment group
return false;
}
}
return (uce.isParticipant() || !uce.getParticipatingGroups().isEmpty());
}
use of org.olat.core.util.nodes.INode in project openolat by klemens.
the class NavigationHandler method addSubTreeModel.
private void addSubTreeModel(TreeNode parent, TreeModel modelToAppend) {
// ignore root and directly add children.
// need to clone children so that are not detached from their original
// parent (which is the cp treemodel)
// parent.addChild(modelToAppend.getRootNode());
TreeNode root = modelToAppend.getRootNode();
int chdCnt = root.getChildCount();
// full cloning of ETH webclass energie takes about 4/100 of a second
for (int i = chdCnt; i > 0; i--) {
INode chd = root.getChildAt(i - 1);
INode chdc = (INode) XStreamHelper.xstreamClone(chd);
if (chdc instanceof GenericTreeNode) {
((GenericTreeNode) chdc).setIdent(chd.getIdent());
}
// always insert before already existing course building block children
parent.insert(chdc, 0);
}
copyIdent(parent, root);
}
Aggregations