use of org.olat.core.util.nodes.INode in project openolat by klemens.
the class NodeExportVisitor method visit.
private void visit(Visitor visitor, INode node) {
visitor.visit(node);
for (int i = node.getChildCount(); i-- > 0; ) {
INode subNode = node.getChildAt(i);
visit(visitor, subNode);
}
}
use of org.olat.core.util.nodes.INode in project openolat by klemens.
the class ModifyCourseEvent method visitPublishModel.
private static void visitPublishModel(TreeNode node, PublishTreeModel publishTreeModel, Collection<String> nodeToPublish) {
int numOfChildren = node.getChildCount();
for (int i = 0; i < numOfChildren; i++) {
INode child = node.getChildAt(i);
if (child instanceof TreeNode && publishTreeModel.isVisible(child)) {
nodeToPublish.add(child.getIdent());
visitPublishModel((TreeNode) child, publishTreeModel, nodeToPublish);
}
}
}
use of org.olat.core.util.nodes.INode in project openolat by klemens.
the class MyForumsWebService method getForums.
/**
* Retrieves a list of forums on a user base. All forums of groups
* where the user is participant/tutor + all forums in course where
* the user is a participant (owner, tutor or participant)
* @response.representation.200.qname {http://www.example.com}forumVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The forums
* @response.representation.200.example {@link org.olat.modules.fo.restapi.Examples#SAMPLE_FORUMVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @param identityKey The key of the user (IdentityImpl)
* @param httpRequest The HTTP request
* @return The forums
*/
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getForums(@PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
Roles roles;
Identity retrievedUser = getIdentity(httpRequest);
if (retrievedUser == null) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
} else if (!identityKey.equals(retrievedUser.getKey())) {
if (isAdmin(httpRequest)) {
retrievedUser = BaseSecurityManager.getInstance().loadIdentityByKey(identityKey);
roles = BaseSecurityManager.getInstance().getRoles(retrievedUser);
} else {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
} else {
roles = getRoles(httpRequest);
}
Map<Long, Long> groupNotified = new HashMap<Long, Long>();
Map<Long, Collection<Long>> courseNotified = new HashMap<Long, Collection<Long>>();
final Set<Long> subscriptions = new HashSet<Long>();
NotificationsManager man = NotificationsManager.getInstance();
{
// collect subscriptions
List<String> notiTypes = Collections.singletonList("Forum");
List<Subscriber> subs = man.getSubscribers(retrievedUser, notiTypes);
for (Subscriber sub : subs) {
String resName = sub.getPublisher().getResName();
Long forumKey = Long.parseLong(sub.getPublisher().getData());
subscriptions.add(forumKey);
if ("BusinessGroup".equals(resName)) {
Long groupKey = sub.getPublisher().getResId();
groupNotified.put(groupKey, forumKey);
} else if ("CourseModule".equals(resName)) {
Long courseKey = sub.getPublisher().getResId();
if (!courseNotified.containsKey(courseKey)) {
courseNotified.put(courseKey, new ArrayList<Long>());
}
courseNotified.get(courseKey).add(forumKey);
}
}
}
final List<ForumVO> forumVOs = new ArrayList<ForumVO>();
final IdentityEnvironment ienv = new IdentityEnvironment(retrievedUser, roles);
for (Map.Entry<Long, Collection<Long>> e : courseNotified.entrySet()) {
final Long courseKey = e.getKey();
final Collection<Long> forumKeys = e.getValue();
final ICourse course = CourseFactory.loadCourse(courseKey);
new CourseTreeVisitor(course, ienv).visit(new Visitor() {
@Override
public void visit(INode node) {
if (node instanceof FOCourseNode) {
FOCourseNode forumNode = (FOCourseNode) node;
ForumVO forumVo = ForumCourseNodeWebService.createForumVO(course, forumNode, subscriptions);
if (forumKeys.contains(forumVo.getForumKey())) {
forumVOs.add(forumVo);
}
}
}
}, new VisibleTreeFilter());
}
/*
RepositoryManager rm = RepositoryManager.getInstance();
ACService acManager = CoreSpringFactory.getImpl(ACService.class);
SearchRepositoryEntryParameters repoParams = new SearchRepositoryEntryParameters(retrievedUser, roles, "CourseModule");
repoParams.setOnlyExplicitMember(true);
List<RepositoryEntry> entries = rm.genericANDQueryWithRolesRestriction(repoParams, 0, -1, true);
for(RepositoryEntry entry:entries) {
AccessResult result = acManager.isAccessible(entry, retrievedUser, false);
if(result.isAccessible()) {
try {
final ICourse course = CourseFactory.loadCourse(entry.getOlatResource());
final IdentityEnvironment ienv = new IdentityEnvironment(retrievedUser, roles);
new CourseTreeVisitor(course, ienv).visit(new Visitor() {
@Override
public void visit(INode node) {
if(node instanceof FOCourseNode) {
FOCourseNode forumNode = (FOCourseNode)node;
ForumVO forumVo = ForumCourseNodeWebService.createForumVO(course, forumNode, subscriptions);
forumVOs.add(forumVo);
}
}
});
} catch (Exception e) {
log.error("", e);
}
}
}*/
// start found forums in groups
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
SearchBusinessGroupParams params = new SearchBusinessGroupParams(retrievedUser, true, true);
params.addTools(CollaborationTools.TOOL_FORUM);
List<BusinessGroup> groups = bgs.findBusinessGroups(params, null, 0, -1);
// list forum keys
List<Long> groupIds = new ArrayList<Long>();
Map<Long, BusinessGroup> groupsMap = new HashMap<Long, BusinessGroup>();
for (BusinessGroup group : groups) {
if (groupNotified.containsKey(group.getKey())) {
ForumVO forumVo = new ForumVO();
forumVo.setName(group.getName());
forumVo.setGroupKey(group.getKey());
forumVo.setForumKey(groupNotified.get(group.getKey()));
forumVo.setSubscribed(true);
forumVOs.add(forumVo);
groupIds.remove(group.getKey());
} else {
groupIds.add(group.getKey());
groupsMap.put(group.getKey(), group);
}
}
PropertyManager pm = PropertyManager.getInstance();
List<Property> forumProperties = pm.findProperties(OresHelper.calculateTypeName(BusinessGroup.class), groupIds, PROP_CAT_BG_COLLABTOOLS, KEY_FORUM);
for (Property prop : forumProperties) {
Long forumKey = prop.getLongValue();
if (forumKey != null && groupsMap.containsKey(prop.getResourceTypeId())) {
BusinessGroup group = groupsMap.get(prop.getResourceTypeId());
ForumVO forumVo = new ForumVO();
forumVo.setName(group.getName());
forumVo.setGroupKey(group.getKey());
forumVo.setForumKey(prop.getLongValue());
forumVo.setSubscribed(false);
forumVOs.add(forumVo);
}
}
ForumVOes voes = new ForumVOes();
voes.setForums(forumVOs.toArray(new ForumVO[forumVOs.size()]));
voes.setTotalCount(forumVOs.size());
return Response.ok(voes).build();
}
use of org.olat.core.util.nodes.INode in project openolat by klemens.
the class MenuTreeRenderer method render.
/**
* @see org.olat.core.gui.render.ui.ComponentRenderer#render(org.olat.core.gui.render.Renderer,
* org.olat.core.gui.render.StringOutput, org.olat.core.gui.components.Component,
* org.olat.core.gui.render.URLBuilder, org.olat.core.gui.translator.Translator,
* org.olat.core.gui.render.RenderResult, java.lang.String[])
*/
@Override
public void render(Renderer renderer, StringOutput target, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
MenuTree tree = (MenuTree) source;
if (tree.getMenuTreeItem() != null) {
tree.getMenuTreeItem().clearVisibleNodes();
}
TreeNode root = tree.getTreeModel().getRootNode();
// tree is completely empty
if (root == null)
return;
INode selNode = tree.getSelectedNode();
Collection<String> openNodeIds = tree.getOpenNodeIds();
List<INode> selPath = new ArrayList<>(5);
INode cur = selNode;
if (cur == null && !tree.isUnselectNodes()) {
cur = root;
} else if (cur == null && tree.isUnselectNodes() && openNodeIds.isEmpty()) {
// always open the root
openNodeIds.add(root.getIdent());
}
// selected nodeid of the root node
while (cur != null) {
selPath.add(0, cur);
cur = cur.getParent();
}
List<DndElement> elements = new ArrayList<>();
AJAXFlags flags = renderer.getGlobalSettings().getAjaxFlags();
target.append("\n<div class='o_tree");
// marker classes to differentiate rendering when root node is visible
if (!tree.isRootVisible()) {
target.append(" o_tree_root_hidden");
} else {
target.append(" o_tree_root_visible");
}
if (tree.isInsertToolEnabled()) {
target.append(" o_tree_insert_tool");
}
// add element CSS
if (StringHelper.containsNonWhitespace(tree.getElementCssClass())) {
target.append(" ").append(tree.getElementCssClass());
}
target.append("'><ul class=\"o_tree_l0\">");
if (tree.isRootVisible()) {
renderLevel(renderer, target, 0, root, selPath, openNodeIds, elements, ubu, flags, tree);
} else {
selPath.remove(0);
int chdCnt = root.getChildCount();
for (int i = 0; i < chdCnt; i++) {
TreeNode curChd = (TreeNode) root.getChildAt(i);
renderLevel(renderer, target, 0, curChd, selPath, openNodeIds, elements, ubu, flags, tree);
}
}
target.append("</ul>");
appendDragAndDropScript(elements, tree, target).append("</div>");
}
use of org.olat.core.util.nodes.INode in project openolat by klemens.
the class MenuTreeRenderer method renderLevel.
private void renderLevel(Renderer renderer, StringOutput target, int level, TreeNode curRoot, List<INode> selPath, Collection<String> openNodeIds, List<DndElement> dndElements, URLBuilder ubu, AJAXFlags flags, MenuTree tree) {
INode curSel = null;
if (level < selPath.size()) {
curSel = selPath.get(level);
}
boolean selected = (!selPath.isEmpty() && selPath.get(selPath.size() - 1) == curRoot);
boolean hasInsertionPoint = isInsertionPointUnderNode(curRoot, tree);
boolean hasChildren = hasVisibleChildren(curRoot, tree);
boolean renderChildren = isRenderChildren(curSel, curRoot, selected, tree, openNodeIds) || hasInsertionPoint;
renderInsertionPoint(target, Position.up, level, curRoot, ubu, flags, tree);
// item icon css class and icon decorator (for each icon quadrant a div, eclipse style)
String cssClass = curRoot.getCssClass();
target.append("<li class='");
// add custom css class
target.append(cssClass, cssClass != null);
if (selected) {
target.append(" active");
} else if (curSel == curRoot) {
// add css class to identify parents of active element
target.append(" active_parent");
}
String ident = curRoot.getIdent();
target.append("' data-nodeid='").append(ident).append("'>");
target.append("<div id='dd").append(ident).append("' class='o_tree_l").append(level);
if (tree.isDragEnabled() || tree.isDropEnabled()) {
target.append(" o_dnd_item");
}
if (selected) {
target.append(" active");
}
target.append("'>");
if (tree.isDragEnabled() || tree.isDropEnabled()) {
appendDragAndDropElement(curRoot, tree, dndElements, ubu, flags);
}
if (hasChildren || hasInsertionPoint) {
renderOpenClose(curRoot, target, level, renderChildren, ubu, flags, tree);
}
// Render menu item as link, also for active elements
// mark active item as strong for accessibility reasons
renderLink(renderer, curRoot, level, selected, renderChildren, curSel, target, ubu, flags, tree);
if (selected && tree.isInsertToolEnabled()) {
renderInsertCallout(target, curRoot, ubu, flags, tree);
}
target.append("</div>");
// append div to drop as sibling
if (!renderChildren && (tree.isDragEnabled() || tree.isDropSiblingEnabled())) {
appendSiblingDropObj(curRoot, level, tree, target, false);
}
if (renderChildren) {
// open / close ul
renderChildren(renderer, target, level, curRoot, selPath, openNodeIds, dndElements, ubu, flags, tree);
// append div to drop as sibling after the children
if (tree.isDragEnabled() || tree.isDropSiblingEnabled()) {
appendSiblingDropObj(curRoot, level, tree, target, true);
}
}
// close item level
target.append("</li>");
renderInsertionPoint(target, Position.down, level, curRoot, ubu, flags, tree);
}
Aggregations