Search in sources :

Example 21 with INode

use of org.olat.core.util.nodes.INode in project OpenOLAT by OpenOLAT.

the class StatisticResult method getIndentednodeRendererMap.

private Map<String, Object> getIndentednodeRendererMap(int row) {
    if (row >= orderedNodesList_.size()) {
        throw new IllegalStateException("row count too big: " + row + ", only having " + orderedNodesList_.size() + " elements");
    }
    CourseNode node = orderedNodesList_.get(row);
    int recursionLevel = 0;
    INode parent = node.getParent();
    while (parent != null) {
        recursionLevel++;
        parent = parent.getParent();
    }
    // Store node data in hash map. This hash map serves as data model for
    // the user assessment overview table. Leave user data empty since not used in
    // this table. (use only node data)
    Map<String, Object> nodeData = new HashMap<String, Object>();
    // indent
    nodeData.put(AssessmentHelper.KEY_INDENT, new Integer(recursionLevel));
    // course node data
    nodeData.put(AssessmentHelper.KEY_TYPE, node.getType());
    nodeData.put(AssessmentHelper.KEY_TITLE_SHORT, node.getShortTitle());
    nodeData.put(AssessmentHelper.KEY_TITLE_LONG, node.getLongTitle());
    nodeData.put(AssessmentHelper.KEY_IDENTIFYER, node.getIdent());
    // plus the node
    nodeData.put(StatisticResult.KEY_NODE, node);
    return nodeData;
}
Also used : INode(org.olat.core.util.nodes.INode) HashMap(java.util.HashMap) CourseNode(org.olat.course.nodes.CourseNode)

Example 22 with INode

use of org.olat.core.util.nodes.INode in project OpenOLAT by OpenOLAT.

the class StatisticResult method doAddQueryListResultsForNodeAndChildren.

private void doAddQueryListResultsForNodeAndChildren(CourseNode node, List<Object[]> result, Set<String> groupByKeys) {
    orderedNodesList_.add(node);
    for (Iterator<?> it = result.iterator(); it.hasNext(); ) {
        Object[] columns = (Object[]) it.next();
        if (columns.length != 3) {
            throw new IllegalStateException("result should be three columns wide");
        }
        String businessPath = (String) columns[0];
        if (!businessPath.matches("\\[RepositoryEntry:.*\\]\\[CourseNode:" + node.getIdent() + "\\]")) {
            continue;
        }
        String groupByKey = String.valueOf(columns[1]);
        groupByKeys.add(groupByKey);
        int count = (Integer) columns[2];
        Map<String, Integer> nodeMap = statistic_.get(node);
        if (nodeMap == null) {
            nodeMap = new HashMap<String, Integer>();
            statistic_.put(node, nodeMap);
        }
        Integer existingCount = nodeMap.get(groupByKey);
        if (existingCount == null) {
            nodeMap.put(groupByKey, count);
        } else {
            nodeMap.put(groupByKey, existingCount + count);
        }
        it.remove();
    }
    int childCount = node.getChildCount();
    for (int i = 0; i < childCount; i++) {
        INode n = node.getChildAt(i);
        if (n instanceof CourseNode) {
            doAddQueryListResultsForNodeAndChildren((CourseNode) n, result, groupByKeys);
        }
    }
}
Also used : INode(org.olat.core.util.nodes.INode) CourseNode(org.olat.course.nodes.CourseNode)

Example 23 with INode

use of org.olat.core.util.nodes.INode in project OpenOLAT by OpenOLAT.

the class QTIEditorMainController method createChangeMessage.

/**
 * helper method to create the change log message
 *
 * @return
 */
private String createChangeMessage() {
    // FIXME:pb:break down into smaller pieces
    final StringBuilder result = new StringBuilder();
    if (isRestrictedEdit()) {
        Visitor v = new Visitor() {

            /*
				 * a history key is built as follows
				 * sectionkey+"/"+itemkey+"/"+questionkey+"/"+responsekey
				 */
            String sectionKey = null;

            Map<String, String> itemMap = new HashMap<>();

            public void visit(INode node) {
                if (node instanceof AssessmentNode) {
                    AssessmentNode an = (AssessmentNode) node;
                    String key = "null/null/null/null";
                    if (history.containsKey(key)) {
                        // some assessment top level data changed
                        Memento mem = history.get(key);
                        result.append("---+ Changes in test " + formatVariable(startedWithTitle) + ":");
                        result.append(an.createChangeMessage(mem));
                    }
                } else if (node instanceof SectionNode) {
                    SectionNode sn = (SectionNode) node;
                    String tmpKey = ((Section) sn.getUnderlyingQTIObject()).getIdent();
                    String key = tmpKey + "/null/null/null";
                    if (history.containsKey(key)) {
                        // some section only data changed
                        Memento mem = history.get(key);
                        result.append("\n---++ Section " + formatVariable(sn.getAltText()) + " changes:");
                        result.append(sn.createChangeMessage(mem));
                    }
                } else if (node instanceof ItemNode) {
                    ItemNode in = (ItemNode) node;
                    SectionNode sn = (SectionNode) in.getParent();
                    String parentSectkey = ((Section) ((SectionNode) in.getParent()).getUnderlyingQTIObject()).getIdent();
                    Item item = (Item) in.getUnderlyingQTIObject();
                    Question question = item.getQuestion();
                    String itemKey = item.getIdent();
                    String prefixKey = "null/" + itemKey;
                    String questionIdent = question != null ? question.getQuestion().getId() : "null";
                    String key = prefixKey + "/" + questionIdent + "/null";
                    StringBuilder changeMessage = new StringBuilder();
                    boolean hasChanges = false;
                    if (!itemMap.containsKey(itemKey)) {
                        Memento questMem = null;
                        Memento respMem = null;
                        if (history.containsKey(key)) {
                            // question changed!
                            questMem = history.get(key);
                            hasChanges = true;
                        }
                        // if(!hasChanges){
                        // check if a response changed
                        // new prefix for responses
                        prefixKey += "/null/";
                        // list contains org.olat.ims.qti.editor.beecom.objects.Response
                        List<Response> responses = question != null ? question.getResponses() : null;
                        if (responses != null && responses.size() > 0) {
                            // check for changes in each response
                            for (Iterator<Response> iter = responses.iterator(); iter.hasNext(); ) {
                                Response resp = iter.next();
                                if (history.containsKey(prefixKey + resp.getIdent())) {
                                    // this response changed!
                                    Memento tmpMem = history.get(prefixKey + resp.getIdent());
                                    if (respMem != null) {
                                        respMem = respMem.getTimestamp() > tmpMem.getTimestamp() ? tmpMem : respMem;
                                    } else {
                                        hasChanges = true;
                                        respMem = tmpMem;
                                    }
                                }
                            }
                        }
                        // output message
                        if (hasChanges) {
                            Memento mem = null;
                            if (questMem != null && respMem != null) {
                                // use the earlier memento
                                mem = questMem.getTimestamp() > respMem.getTimestamp() ? respMem : questMem;
                            } else if (questMem != null) {
                                mem = questMem;
                            } else if (respMem != null) {
                                mem = respMem;
                            }
                            changeMessage.append(in.createChangeMessage(mem));
                            itemMap.put(itemKey, itemKey);
                            if (!parentSectkey.equals(sectionKey)) {
                                // either this item belongs to a new section or no section
                                // is active
                                result.append("\n---++ Section " + formatVariable(sn.getAltText()) + " changes:");
                                result.append("\n").append(changeMessage);
                                sectionKey = parentSectkey;
                            } else {
                                result.append("\n").append(changeMessage);
                            }
                        }
                    }
                }
            }

            private String formatVariable(String var) {
                if (StringHelper.containsNonWhitespace(var)) {
                    return var;
                }
                return "[no entry]";
            }
        };
        TreeVisitor tv = new TreeVisitor(v, menuTreeModel.getRootNode(), false);
        tv.visitAll();
    }
    /*
		 * 
		 */
    return result.toString();
}
Also used : INode(org.olat.core.util.nodes.INode) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Visitor(org.olat.core.util.tree.Visitor) AssessmentNode(org.olat.ims.qti.editor.tree.AssessmentNode) SectionNode(org.olat.ims.qti.editor.tree.SectionNode) Section(org.olat.ims.qti.editor.beecom.objects.Section) Response(org.olat.ims.qti.editor.beecom.objects.Response) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Memento(org.olat.core.util.memento.Memento) Item(org.olat.ims.qti.editor.beecom.objects.Item) ItemNode(org.olat.ims.qti.editor.tree.ItemNode) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) Question(org.olat.ims.qti.editor.beecom.objects.Question) Map(java.util.Map) HashMap(java.util.HashMap)

Example 24 with INode

use of org.olat.core.util.nodes.INode in project OpenOLAT by OpenOLAT.

the class Item method renderOpenXML.

@Override
public void renderOpenXML(OpenXMLDocument document, RenderInstructions ri) {
    if (Boolean.TRUE.equals(ri.get(RenderInstructions.KEY_RENDER_TITLE))) {
        StringBuilder addText = new StringBuilder();
        String type = (String) ri.get(RenderInstructions.KEY_QUESTION_TYPE);
        String score = (String) ri.get(RenderInstructions.KEY_QUESTION_SCORE);
        if (StringHelper.containsNonWhitespace(type) || StringHelper.containsNonWhitespace(score)) {
            if (StringHelper.containsNonWhitespace(type)) {
                addText.append("(").append(type).append(")");
            }
            if (StringHelper.containsNonWhitespace(score)) {
                addText.append(" - ").append(score);
            }
        }
        document.appendHeading1(title, addText.toString());
    }
    Objectives itemObjectives = null;
    Presentation itemPresentation = null;
    for (int i = getChildCount(); i-- > 0; ) {
        INode next = getChildAt(i);
        if (next instanceof Objectives) {
            itemObjectives = (Objectives) next;
        } else if (next instanceof Presentation) {
            itemPresentation = (Presentation) next;
        }
    }
    if (itemObjectives != null) {
        itemObjectives.renderOpenXML(document, ri);
    }
    if (itemPresentation != null) {
        itemPresentation.renderOpenXML(document, ri);
    }
    Boolean renderResponse = (Boolean) ri.get(RenderInstructions.KEY_RENDER_CORRECT_RESPONSES);
    Integer type = (Integer) ri.get(RenderInstructions.KEY_QUESTION_OO_TYPE);
    if (renderResponse != null && renderResponse.booleanValue() && type != null && type.intValue() == Question.TYPE_ESSAY) {
        for (int i = getChildCount(); i-- > 0; ) {
            QTIElement el = (QTIElement) getChildAt(i);
            if (el instanceof ItemFeedback && "Solution".equals(el.getQTIIdent())) {
                el.renderOpenXML(document, ri);
            }
        }
    }
}
Also used : INode(org.olat.core.util.nodes.INode)

Example 25 with INode

use of org.olat.core.util.nodes.INode in project OpenOLAT by OpenOLAT.

the class UserFoldersWebService method getFolders.

/**
 * Retrieves a list of folders on a user base. All folders of groups
 * where the user is participant/tutor + all folders in course where
 * the user is a participant (owner, tutor or participant)
 * @response.representation.200.qname {http://www.example.com}folderVOes
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The folders
 * @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
 * @param identityKey The key of the user (IdentityImpl)
 * @param httpRequest The HTTP request
 * @return The folders
 */
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getFolders(@Context HttpServletRequest httpRequest) {
    Roles roles;
    Identity ureqIdentity = getIdentity(httpRequest);
    if (ureqIdentity == null) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    } else if (!identity.getKey().equals(ureqIdentity.getKey())) {
        if (isAdmin(httpRequest)) {
            ureqIdentity = identity;
            roles = BaseSecurityManager.getInstance().getRoles(identity);
        } else {
            return Response.serverError().status(Status.UNAUTHORIZED).build();
        }
    } else {
        roles = getRoles(httpRequest);
    }
    final Map<Long, Long> groupNotified = new HashMap<Long, Long>();
    final Map<Long, Collection<String>> courseNotified = new HashMap<Long, Collection<String>>();
    NotificationsManager man = NotificationsManager.getInstance();
    {
        // collect subscriptions
        List<String> notiTypes = Collections.singletonList("FolderModule");
        List<Subscriber> subs = man.getSubscribers(ureqIdentity, notiTypes);
        for (Subscriber sub : subs) {
            String resName = sub.getPublisher().getResName();
            if ("BusinessGroup".equals(resName)) {
                Long groupKey = sub.getPublisher().getResId();
                groupNotified.put(groupKey, sub.getPublisher().getResId());
            } else if ("CourseModule".equals(resName)) {
                Long courseKey = sub.getPublisher().getResId();
                if (!courseNotified.containsKey(courseKey)) {
                    courseNotified.put(courseKey, new ArrayList<String>());
                }
                courseNotified.get(courseKey).add(sub.getPublisher().getSubidentifier());
            }
        }
    }
    final List<FolderVO> folderVOs = new ArrayList<FolderVO>();
    final IdentityEnvironment ienv = new IdentityEnvironment(ureqIdentity, roles);
    for (Map.Entry<Long, Collection<String>> e : courseNotified.entrySet()) {
        final Long courseKey = e.getKey();
        final Collection<String> nodeKeys = e.getValue();
        final ICourse course = CourseFactory.loadCourse(courseKey);
        new CourseTreeVisitor(course, ienv).visit(new Visitor() {

            @Override
            public void visit(INode node) {
                if (node instanceof BCCourseNode) {
                    BCCourseNode bcNode = (BCCourseNode) node;
                    if (nodeKeys.contains(bcNode.getIdent())) {
                        FolderVO folder = BCWebService.createFolderVO(ienv, course, bcNode, courseNotified.get(course.getResourceableId()));
                        folderVOs.add(folder);
                    }
                }
            }
        }, 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 BCCourseNode) {
								BCCourseNode bcNode = (BCCourseNode)node;
								FolderVO folder = BCWebService.createFolderVO(ienv, course, bcNode, courseNotified.get(course.getResourceableId()));
								folderVOs.add(folder);
							}
						}
					});
				} catch (Exception e) {
					log.error("", e);
				}
			}
		}*/
    // start found forums in groups
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    SearchBusinessGroupParams params = new SearchBusinessGroupParams(ureqIdentity, true, true);
    params.addTools(CollaborationTools.TOOL_FOLDER);
    List<BusinessGroup> groups = bgs.findBusinessGroups(params, null, 0, -1);
    for (BusinessGroup group : groups) {
        CollaborationTools tools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(group);
        VFSContainer container = tools.getSecuredFolder(group, null, ureqIdentity, false);
        FolderVO folderVo = new FolderVO();
        folderVo.setName(group.getName());
        folderVo.setGroupKey(group.getKey());
        folderVo.setSubscribed(groupNotified.containsKey(group.getKey()));
        folderVo.setRead(container.getLocalSecurityCallback().canRead());
        folderVo.setList(container.getLocalSecurityCallback().canList());
        folderVo.setWrite(container.getLocalSecurityCallback().canWrite());
        folderVo.setDelete(container.getLocalSecurityCallback().canDelete());
        folderVOs.add(folderVo);
    }
    FolderVOes voes = new FolderVOes();
    voes.setFolders(folderVOs.toArray(new FolderVO[folderVOs.size()]));
    voes.setTotalCount(folderVOs.size());
    return Response.ok(voes).build();
}
Also used : INode(org.olat.core.util.nodes.INode) FolderVOes(org.olat.restapi.support.vo.FolderVOes) Visitor(org.olat.core.util.tree.Visitor) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) HashMap(java.util.HashMap) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) Subscriber(org.olat.core.commons.services.notifications.Subscriber) List(java.util.List) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) FolderVO(org.olat.restapi.support.vo.FolderVO) BusinessGroup(org.olat.group.BusinessGroup) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) VFSContainer(org.olat.core.util.vfs.VFSContainer) Roles(org.olat.core.id.Roles) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) BCCourseNode(org.olat.course.nodes.BCCourseNode) BusinessGroupService(org.olat.group.BusinessGroupService) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) CollaborationTools(org.olat.collaboration.CollaborationTools) Collection(java.util.Collection) Map(java.util.Map) HashMap(java.util.HashMap) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

INode (org.olat.core.util.nodes.INode)106 Visitor (org.olat.core.util.tree.Visitor)44 CourseNode (org.olat.course.nodes.CourseNode)44 ICourse (org.olat.course.ICourse)40 TreeVisitor (org.olat.core.util.tree.TreeVisitor)30 ArrayList (java.util.ArrayList)28 Identity (org.olat.core.id.Identity)26 CourseEditorTreeNode (org.olat.course.tree.CourseEditorTreeNode)24 TreeNode (org.olat.core.gui.components.tree.TreeNode)18 RepositoryEntry (org.olat.repository.RepositoryEntry)18 Test (org.junit.Test)16 BCCourseNode (org.olat.course.nodes.BCCourseNode)14 CourseTreeVisitor (org.olat.course.run.userview.CourseTreeVisitor)14 VisibleTreeFilter (org.olat.course.run.userview.VisibleTreeFilter)14 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)12 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)12 CourseEditorTreeModel (org.olat.course.tree.CourseEditorTreeModel)12 HashMap (java.util.HashMap)10 FOCourseNode (org.olat.course.nodes.FOCourseNode)10 GET (javax.ws.rs.GET)8