Search in sources :

Example 6 with ItemNode

use of org.olat.ims.qti.editor.tree.ItemNode in project openolat by klemens.

the class QTIStatisticResourceResult method buildQTICourseNodeSubTree.

private void buildQTICourseNodeSubTree(QTIDocument qtiDoc, GenericTreeNode rootNode) {
    for (Section section : qtiDoc.getAssessment().getSections()) {
        GenericTreeNode sectionNode = new SectionNode(section, null);
        sectionNode.setUserObject(section);
        rootNode.addChild(sectionNode);
        for (Item item : section.getItems()) {
            GenericTreeNode itemNode = new ItemNode(item);
            itemNode.setIdent(Long.toString(CodeHelper.getForeverUniqueID()));
            if (sectionNode.getDelegate() == null) {
                sectionNode.setDelegate(itemNode);
            }
            itemNode.setUserObject(item);
            sectionNode.addChild(itemNode);
        }
    }
}
Also used : Item(org.olat.ims.qti.editor.beecom.objects.Item) ItemNode(org.olat.ims.qti.editor.tree.ItemNode) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) Section(org.olat.ims.qti.editor.beecom.objects.Section) SectionNode(org.olat.ims.qti.editor.tree.SectionNode)

Example 7 with ItemNode

use of org.olat.ims.qti.editor.tree.ItemNode in project openolat by klemens.

the class QTIEditorMainController method doConvertItemToQtiNode.

private GenericQtiNode doConvertItemToQtiNode(QuestionItemView qitemv) {
    VFSContainer editorContainer = qtiPackage.getBaseDir();
    Item theItem = qtiQpoolServiceProvider.exportToQTIEditor(qitemv, editorContainer);
    GenericQtiNode node = new ItemNode(theItem, qtiPackage);
    return node;
}
Also used : Item(org.olat.ims.qti.editor.beecom.objects.Item) ItemNode(org.olat.ims.qti.editor.tree.ItemNode) VFSContainer(org.olat.core.util.vfs.VFSContainer) GenericQtiNode(org.olat.ims.qti.editor.tree.GenericQtiNode)

Example 8 with ItemNode

use of org.olat.ims.qti.editor.tree.ItemNode in project openolat by klemens.

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 9 with ItemNode

use of org.olat.ims.qti.editor.tree.ItemNode in project openolat by klemens.

the class QTIEditorMainController method doInsert.

private void doInsert(UserRequest ureq, TreePosition tp, Object toInsert) {
    // new node
    GenericQtiNode parentTargetNode = (GenericQtiNode) tp.getParentTreeNode();
    if (toInsert instanceof GenericQtiNode) {
        doInsert(parentTargetNode, (GenericQtiNode) toInsert, tp.getChildpos());
    } else if (toInsert instanceof QuestionItemView) {
        QuestionItemView item = (QuestionItemView) toInsert;
        GenericQtiNode insertNode = doConvertItemToQtiNode(item);
        doInsert(parentTargetNode, insertNode, tp.getChildpos());
    } else if (toInsert instanceof Collection) {
        int position = tp.getChildpos();
        @SuppressWarnings("unchecked") Collection<QuestionItemView> items = (Collection<QuestionItemView>) toInsert;
        for (QuestionItemView item : items) {
            GenericQtiNode insertNode = doConvertItemToQtiNode(item);
            doInsert(parentTargetNode, insertNode, position++);
        }
    } else if (toInsert instanceof ItemsPackage) {
        ItemsPackage itemsToImport = (ItemsPackage) toInsert;
        List<ItemAndMetadata> items = itemsToImport.getItems();
        int pos = tp.getChildpos();
        for (ItemAndMetadata item : items) {
            GenericQtiNode insertNode = new ItemNode(item.getItem(), qtiPackage);
            doInsert(parentTargetNode, insertNode, pos++);
        }
    }
    event(ureq, menuTree, new Event(MenuTree.COMMAND_TREENODE_CLICKED));
    qtiPackage.serializeQTIDocument();
    updateWarning();
}
Also used : ItemNode(org.olat.ims.qti.editor.tree.ItemNode) GenericQtiNode(org.olat.ims.qti.editor.tree.GenericQtiNode) Collection(java.util.Collection) QItemViewEvent(org.olat.modules.qpool.ui.events.QItemViewEvent) Event(org.olat.core.gui.control.Event) ArrayList(java.util.ArrayList) ContactList(org.olat.core.util.mail.ContactList) List(java.util.List) ItemAndMetadata(org.olat.ims.qti.questionimport.ItemAndMetadata) QuestionItemView(org.olat.modules.qpool.QuestionItemView) ItemsPackage(org.olat.ims.qti.questionimport.ItemsPackage)

Example 10 with ItemNode

use of org.olat.ims.qti.editor.tree.ItemNode in project OpenOLAT by OpenOLAT.

the class QTIStatisticResourceResult method buildQTICourseNodeSubTree.

private void buildQTICourseNodeSubTree(QTIDocument qtiDoc, GenericTreeNode rootNode) {
    for (Section section : qtiDoc.getAssessment().getSections()) {
        GenericTreeNode sectionNode = new SectionNode(section, null);
        sectionNode.setUserObject(section);
        rootNode.addChild(sectionNode);
        for (Item item : section.getItems()) {
            GenericTreeNode itemNode = new ItemNode(item);
            itemNode.setIdent(Long.toString(CodeHelper.getForeverUniqueID()));
            if (sectionNode.getDelegate() == null) {
                sectionNode.setDelegate(itemNode);
            }
            itemNode.setUserObject(item);
            sectionNode.addChild(itemNode);
        }
    }
}
Also used : Item(org.olat.ims.qti.editor.beecom.objects.Item) ItemNode(org.olat.ims.qti.editor.tree.ItemNode) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) Section(org.olat.ims.qti.editor.beecom.objects.Section) SectionNode(org.olat.ims.qti.editor.tree.SectionNode)

Aggregations

ItemNode (org.olat.ims.qti.editor.tree.ItemNode)16 Item (org.olat.ims.qti.editor.beecom.objects.Item)14 Section (org.olat.ims.qti.editor.beecom.objects.Section)10 GenericQtiNode (org.olat.ims.qti.editor.tree.GenericQtiNode)10 SectionNode (org.olat.ims.qti.editor.tree.SectionNode)10 AssessmentNode (org.olat.ims.qti.editor.tree.AssessmentNode)6 Event (org.olat.core.gui.control.Event)4 INode (org.olat.core.util.nodes.INode)4 VFSContainer (org.olat.core.util.vfs.VFSContainer)4 ChoiceQuestion (org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)4 Question (org.olat.ims.qti.editor.beecom.objects.Question)4 ItemAndMetadata (org.olat.ims.qti.questionimport.ItemAndMetadata)4 QItemViewEvent (org.olat.modules.qpool.ui.events.QItemViewEvent)4 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Component (org.olat.core.gui.components.Component)2 JSAndCSSComponent (org.olat.core.gui.components.htmlheader.jscss.JSAndCSSComponent)2