Search in sources :

Example 1 with QTIChangeLogMessage

use of org.olat.ims.qti.QTIChangeLogMessage in project OpenOLAT by OpenOLAT.

the class IQRunController method createChangelogMsg.

/**
 * @param ureq
 * @return
 */
private StringBuilder createChangelogMsg(UserRequest ureq) {
    /*
		 * TODO:pb:is ImsRepositoryResolver the right place for getting the change log?
		 */
    // re could be null, but if we are here it should not be null!
    Roles userRoles = ureq.getUserSession().getRoles();
    boolean showAll = userRoles.isAuthor() || userRoles.isOLATAdmin();
    // get changelog
    Formatter formatter = Formatter.getInstance(ureq.getLocale());
    ImsRepositoryResolver resolver = new ImsRepositoryResolver(referenceTestEntry);
    QTIChangeLogMessage[] qtiChangeLog = resolver.getDocumentChangeLog();
    StringBuilder qtiChangelog = new StringBuilder();
    if (qtiChangeLog.length > 0) {
        // there are resource changes
        Arrays.sort(qtiChangeLog);
        for (int i = qtiChangeLog.length - 1; i >= 0; i--) {
            // show latest change first
            if (!showAll && qtiChangeLog[i].isPublic()) {
                // logged in person is a normal user, hence public messages only
                Date msgDate = new Date(qtiChangeLog[i].getTimestmp());
                qtiChangelog.append("\nChange date: ").append(formatter.formatDateAndTime(msgDate)).append("\n");
                String msg = StringHelper.escapeHtml(qtiChangeLog[i].getLogMessage());
                qtiChangelog.append(msg);
                qtiChangelog.append("\n********************************\n");
            } else if (showAll) {
                // logged in person is an author, olat admin, owner, show all messages
                Date msgDate = new Date(qtiChangeLog[i].getTimestmp());
                qtiChangelog.append("\nChange date: ").append(formatter.formatDateAndTime(msgDate)).append("\n");
                String msg = StringHelper.escapeHtml(qtiChangeLog[i].getLogMessage());
                qtiChangelog.append(msg);
                qtiChangelog.append("\n********************************\n");
            }
        // else non public messages are not shown to normal user
        }
    }
    return qtiChangelog;
}
Also used : QTIChangeLogMessage(org.olat.ims.qti.QTIChangeLogMessage) Formatter(org.olat.core.util.Formatter) ImsRepositoryResolver(org.olat.ims.qti.process.ImsRepositoryResolver) Roles(org.olat.core.id.Roles) Date(java.util.Date)

Example 2 with QTIChangeLogMessage

use of org.olat.ims.qti.QTIChangeLogMessage in project OpenOLAT by OpenOLAT.

the class ImsRepositoryResolver method getDocumentChangeLog.

/**
 * reads the files in the ../changelog directory, and generates a
 * <code>QTIChangeLogMessage</code> per file.
 *
 * @return qti changelog messages or an empty array if no changelog exists.
 * @see QTIChangeLogMessage
 */
public QTIChangeLogMessage[] getDocumentChangeLog() {
    VFSContainer dirRoot = new LocalFolderImpl(fUnzippedDirRoot);
    VFSContainer dirChangelog = (VFSContainer) dirRoot.resolve("changelog");
    if (dirChangelog == null) {
        // no change log
        return new QTIChangeLogMessage[0];
    }
    List<VFSItem> items = dirChangelog.getItems();
    // PRECONDITION: only changelog files in the changelog directory
    QTIChangeLogMessage[] logArr = new QTIChangeLogMessage[items.size()];
    String filName;
    String msg;
    int i = 0;
    java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH_mm_ss");
    for (Iterator<VFSItem> iter = items.iterator(); iter.hasNext(); ) {
        VFSLeaf file = (VFSLeaf) iter.next();
        filName = file.getName();
        String[] parts = filName.split("\\.");
        msg = FileUtils.load(file.getInputStream(), "utf-8");
        try {
            logArr[i] = new QTIChangeLogMessage(msg, parts[1].equals("all"), formatter.parse(parts[0]).getTime());
            i++;
        } catch (ParseException e) {
            log.error("", e);
        }
    }
    return logArr;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl) QTIChangeLogMessage(org.olat.ims.qti.QTIChangeLogMessage) ParseException(java.text.ParseException)

Example 3 with QTIChangeLogMessage

use of org.olat.ims.qti.QTIChangeLogMessage in project OpenOLAT by OpenOLAT.

the class QTIEditorMainController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
 */
@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (source == deleteDialog) {
        // event from delete dialog
        if (DialogBoxUIFactory.isYesEvent(event)) {
            // yes, delete
            GenericQtiNode clickedNode = (GenericQtiNode) deleteDialog.getUserObject();
            doDelete(clickedNode);
            event(ureq, menuTree, new Event(MenuTree.COMMAND_TREENODE_CLICKED));
            // ask user to confirm referenced media removal
            if (deletableMediaFiles != null && deletableMediaFiles.size() > 0) {
                String msg = translate("delete.item.media", deletableMediaFiles.toString());
                deleteMediaDialog = activateYesNoDialog(ureq, null, msg, deleteMediaDialog);
            }
            updateWarning();
        }
        // cleanup controller
        removeAsListenerAndDispose(deleteDialog);
        deleteDialog = null;
    } else if (source == deleteMediaDialog) {
        // event from deleteMediaDialog
        if (DialogBoxUIFactory.isYesEvent(event)) {
            // yes, delete
            qtiPackage.removeMediaFiles(deletableMediaFiles);
            deleteMediaDialog = null;
            deletableMediaFiles = null;
        }
    } else if (event instanceof NodeBeforeChangeEvent) {
        NodeBeforeChangeEvent nce = (NodeBeforeChangeEvent) event;
        // active node changed some data
        String activeQtiNodeId = menuTree.getSelectedNodeId();
        GenericQtiNode activeQtiNode = menuTreeModel.getQtiNode(activeQtiNodeId);
        // force rerendering for ajax mode
        menuTree.setDirty(true);
        /*
			 * mementos are only created in restricted mode
			 */
        if (isRestrictedEdit()) {
            String key = nce.getSectionIdent() + "/" + nce.getItemIdent() + "/" + nce.getQuestionIdent() + "/" + nce.getResponseIdent();
            if (!history.containsKey(key)) {
                Memento memento = activeQtiNode.createMemento();
                history.put(key, memento);
                qtiPackage.serializeChangelog(history);
            }
        }
        /*
			 * generate a Memento, store it for further use
			 */
        if (nce.hasNewTitle) {
            // update the treemodel to reflect the change of the underlying qti node
            activeQtiNode.setMenuTitleAndAlt(nce.getNewTitle());
            main.contextPut("qtititle", menuTreeModel.getQtiRootNode().getAltText());
        }
    } else if (source == proceedRestricedEditDialog) {
        // restricted edit warning
        if (DialogBoxUIFactory.isYesEvent(event)) {
            // remove dialog and continue with real content
            columnLayoutCtr.setCol3(mainPanel);
            columnLayoutCtr.hideCol1(false);
            columnLayoutCtr.hideCol2(false);
            removeAsListenerAndDispose(proceedRestricedEditDialog);
            proceedRestricedEditDialog = null;
        } else {
            // remove lock as user is not interested in restricted edit
            // and quick editor
            removeLocksAndExit(ureq);
        }
    } else if (source == cfc) {
        // dispose the content only controller we live in
        // remove modal dialog and cleanup exit process
        // modal dialog must be removed before fire DONE event
        // within the saveAndExit() call, otherwise the wrong
        // gui stack is popped see also OLAT-3056
        cmcExit.deactivate();
        removeAsListenerAndDispose(cmcExit);
        cmcExit = null;
        if (event == Event.CANCELLED_EVENT) {
        // nothing to do, back to editor
        } else {
            QTIChangeLogMessage clm = new QTIChangeLogMessage(changeLog, chngMsgFrom.hasInformLearners());
            qtiPackage.commitChangelog(clm);
            StringBuilder traceMsg = new StringBuilder(chngMsgFrom.hasInformLearners() ? "Visible for ALL \n" : "Visible for GROUP only \n");
            logAudit(traceMsg.append(changeLog).toString(), null);
            // save, remove locks and tmp files
            saveAndExit(ureq);
        }
        removeAsListenerAndDispose(cfc);
        cfc = null;
    } else if (source == chngMsgFrom) {
        if (event == Event.DONE_EVENT) {
            // the changemessage is created and user is willing to send it
            String userMsg = chngMsgFrom.getUserMsg();
            changeLog = changeEmail.getBodyText();
            if (StringHelper.containsNonWhitespace(userMsg)) {
                changeEmail.setBodyText("<p>" + userMsg + "</p>\n<pre>" + changeLog + "</pre>");
            }
            // else nothing was added!
            changeEmail.setSubject("Change log for " + startedWithTitle);
            cfc = new ContactFormController(ureq, getWindowControl(), true, false, false, changeEmail);
            listenTo(cfc);
            exitPanel.setContent(cfc.getInitialComponent());
            return;
        } else {
            // cancel button was pressed
            // just go back to the editor - remove modal dialog
            cmcExit.deactivate();
        }
    } else if (source == selectQItemCtrl) {
        cmc.deactivate();
        cleanUp();
        if (event instanceof QItemViewEvent) {
            QItemViewEvent e = (QItemViewEvent) event;
            List<QuestionItemView> items = e.getItemList();
            doSelectInsertionPoint(ureq, CMD_TOOLS_ADD_QPOOL, items);
        }
    } else if (source == importTableWizard) {
        ItemsPackage importPackage = (ItemsPackage) importTableWizard.getRunContext().get("importPackage");
        getWindowControl().pop();
        cleanUp();
        if (event == Event.DONE_EVENT || event == Event.CHANGED_EVENT) {
            doSelectInsertionPoint(ureq, CMD_TOOLS_ADD_QPOOL, importPackage);
        }
    } else if (createConvertedTestController == source) {
        cmc.deactivate();
        if (event == Event.DONE_EVENT) {
            showInfo("test.converted");
            RepositoryEntry convertedEntry = createConvertedTestController.getAddedEntry();
            String businessPath = "[RepositoryEntry:" + convertedEntry.getKey() + "]";
            NewControllerFactory.getInstance().launch(businessPath, ureq, getWindowControl());
        }
        cleanUp();
    } else if (source == insertCtrl) {
        // catch insert operations
        cmc.deactivate();
        if (event == Event.DONE_EVENT) {
            TreePosition tp = insertCtrl.getInsertPosition();
            if (tp != null) {
                doInsert(ureq, tp, insertCtrl.getUserObject());
                updateWarning();
            }
        }
        cleanUp();
    } else if (source == moveCtrl) {
        cmc.deactivate();
        if (Event.DONE_EVENT == event) {
            TreePosition tp = moveCtrl.getInsertPosition();
            if (tp != null) {
                doMove(tp);
                // force rerendering for ajax mode
                menuTree.setDirty(true);
                updateWarning();
            }
        }
        cleanUp();
    } else if (source == copyCtrl) {
        cmc.deactivate();
        if (Event.DONE_EVENT == event) {
            TreePosition tp = copyCtrl.getInsertPosition();
            if (tp != null) {
                doCopy(ureq, tp);
                updateWarning();
            }
        }
        cleanUp();
    }
}
Also used : GenericQtiNode(org.olat.ims.qti.editor.tree.GenericQtiNode) RepositoryEntry(org.olat.repository.RepositoryEntry) ItemsPackage(org.olat.ims.qti.questionimport.ItemsPackage) TreePosition(org.olat.core.gui.components.tree.TreePosition) Memento(org.olat.core.util.memento.Memento) QTIChangeLogMessage(org.olat.ims.qti.QTIChangeLogMessage) ContactFormController(org.olat.modules.co.ContactFormController) QItemViewEvent(org.olat.modules.qpool.ui.events.QItemViewEvent) Event(org.olat.core.gui.control.Event) QItemViewEvent(org.olat.modules.qpool.ui.events.QItemViewEvent) QuestionItemView(org.olat.modules.qpool.QuestionItemView)

Example 4 with QTIChangeLogMessage

use of org.olat.ims.qti.QTIChangeLogMessage in project openolat by klemens.

the class IQRunController method createChangelogMsg.

/**
 * @param ureq
 * @return
 */
private StringBuilder createChangelogMsg(UserRequest ureq) {
    /*
		 * TODO:pb:is ImsRepositoryResolver the right place for getting the change log?
		 */
    // re could be null, but if we are here it should not be null!
    Roles userRoles = ureq.getUserSession().getRoles();
    boolean showAll = userRoles.isAuthor() || userRoles.isOLATAdmin();
    // get changelog
    Formatter formatter = Formatter.getInstance(ureq.getLocale());
    ImsRepositoryResolver resolver = new ImsRepositoryResolver(referenceTestEntry);
    QTIChangeLogMessage[] qtiChangeLog = resolver.getDocumentChangeLog();
    StringBuilder qtiChangelog = new StringBuilder();
    if (qtiChangeLog.length > 0) {
        // there are resource changes
        Arrays.sort(qtiChangeLog);
        for (int i = qtiChangeLog.length - 1; i >= 0; i--) {
            // show latest change first
            if (!showAll && qtiChangeLog[i].isPublic()) {
                // logged in person is a normal user, hence public messages only
                Date msgDate = new Date(qtiChangeLog[i].getTimestmp());
                qtiChangelog.append("\nChange date: ").append(formatter.formatDateAndTime(msgDate)).append("\n");
                String msg = StringHelper.escapeHtml(qtiChangeLog[i].getLogMessage());
                qtiChangelog.append(msg);
                qtiChangelog.append("\n********************************\n");
            } else if (showAll) {
                // logged in person is an author, olat admin, owner, show all messages
                Date msgDate = new Date(qtiChangeLog[i].getTimestmp());
                qtiChangelog.append("\nChange date: ").append(formatter.formatDateAndTime(msgDate)).append("\n");
                String msg = StringHelper.escapeHtml(qtiChangeLog[i].getLogMessage());
                qtiChangelog.append(msg);
                qtiChangelog.append("\n********************************\n");
            }
        // else non public messages are not shown to normal user
        }
    }
    return qtiChangelog;
}
Also used : QTIChangeLogMessage(org.olat.ims.qti.QTIChangeLogMessage) Formatter(org.olat.core.util.Formatter) ImsRepositoryResolver(org.olat.ims.qti.process.ImsRepositoryResolver) Roles(org.olat.core.id.Roles) Date(java.util.Date)

Example 5 with QTIChangeLogMessage

use of org.olat.ims.qti.QTIChangeLogMessage in project openolat by klemens.

the class QTIEditorMainController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
 */
@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (source == deleteDialog) {
        // event from delete dialog
        if (DialogBoxUIFactory.isYesEvent(event)) {
            // yes, delete
            GenericQtiNode clickedNode = (GenericQtiNode) deleteDialog.getUserObject();
            doDelete(clickedNode);
            event(ureq, menuTree, new Event(MenuTree.COMMAND_TREENODE_CLICKED));
            // ask user to confirm referenced media removal
            if (deletableMediaFiles != null && deletableMediaFiles.size() > 0) {
                String msg = translate("delete.item.media", deletableMediaFiles.toString());
                deleteMediaDialog = activateYesNoDialog(ureq, null, msg, deleteMediaDialog);
            }
            updateWarning();
        }
        // cleanup controller
        removeAsListenerAndDispose(deleteDialog);
        deleteDialog = null;
    } else if (source == deleteMediaDialog) {
        // event from deleteMediaDialog
        if (DialogBoxUIFactory.isYesEvent(event)) {
            // yes, delete
            qtiPackage.removeMediaFiles(deletableMediaFiles);
            deleteMediaDialog = null;
            deletableMediaFiles = null;
        }
    } else if (event instanceof NodeBeforeChangeEvent) {
        NodeBeforeChangeEvent nce = (NodeBeforeChangeEvent) event;
        // active node changed some data
        String activeQtiNodeId = menuTree.getSelectedNodeId();
        GenericQtiNode activeQtiNode = menuTreeModel.getQtiNode(activeQtiNodeId);
        // force rerendering for ajax mode
        menuTree.setDirty(true);
        /*
			 * mementos are only created in restricted mode
			 */
        if (isRestrictedEdit()) {
            String key = nce.getSectionIdent() + "/" + nce.getItemIdent() + "/" + nce.getQuestionIdent() + "/" + nce.getResponseIdent();
            if (!history.containsKey(key)) {
                Memento memento = activeQtiNode.createMemento();
                history.put(key, memento);
                qtiPackage.serializeChangelog(history);
            }
        }
        /*
			 * generate a Memento, store it for further use
			 */
        if (nce.hasNewTitle) {
            // update the treemodel to reflect the change of the underlying qti node
            activeQtiNode.setMenuTitleAndAlt(nce.getNewTitle());
            main.contextPut("qtititle", menuTreeModel.getQtiRootNode().getAltText());
        }
    } else if (source == proceedRestricedEditDialog) {
        // restricted edit warning
        if (DialogBoxUIFactory.isYesEvent(event)) {
            // remove dialog and continue with real content
            columnLayoutCtr.setCol3(mainPanel);
            columnLayoutCtr.hideCol1(false);
            columnLayoutCtr.hideCol2(false);
            removeAsListenerAndDispose(proceedRestricedEditDialog);
            proceedRestricedEditDialog = null;
        } else {
            // remove lock as user is not interested in restricted edit
            // and quick editor
            removeLocksAndExit(ureq);
        }
    } else if (source == cfc) {
        // dispose the content only controller we live in
        // remove modal dialog and cleanup exit process
        // modal dialog must be removed before fire DONE event
        // within the saveAndExit() call, otherwise the wrong
        // gui stack is popped see also OLAT-3056
        cmcExit.deactivate();
        removeAsListenerAndDispose(cmcExit);
        cmcExit = null;
        if (event == Event.CANCELLED_EVENT) {
        // nothing to do, back to editor
        } else {
            QTIChangeLogMessage clm = new QTIChangeLogMessage(changeLog, chngMsgFrom.hasInformLearners());
            qtiPackage.commitChangelog(clm);
            StringBuilder traceMsg = new StringBuilder(chngMsgFrom.hasInformLearners() ? "Visible for ALL \n" : "Visible for GROUP only \n");
            logAudit(traceMsg.append(changeLog).toString(), null);
            // save, remove locks and tmp files
            saveAndExit(ureq);
        }
        removeAsListenerAndDispose(cfc);
        cfc = null;
    } else if (source == chngMsgFrom) {
        if (event == Event.DONE_EVENT) {
            // the changemessage is created and user is willing to send it
            String userMsg = chngMsgFrom.getUserMsg();
            changeLog = changeEmail.getBodyText();
            if (StringHelper.containsNonWhitespace(userMsg)) {
                changeEmail.setBodyText("<p>" + userMsg + "</p>\n<pre>" + changeLog + "</pre>");
            }
            // else nothing was added!
            changeEmail.setSubject("Change log for " + startedWithTitle);
            cfc = new ContactFormController(ureq, getWindowControl(), true, false, false, changeEmail);
            listenTo(cfc);
            exitPanel.setContent(cfc.getInitialComponent());
            return;
        } else {
            // cancel button was pressed
            // just go back to the editor - remove modal dialog
            cmcExit.deactivate();
        }
    } else if (source == selectQItemCtrl) {
        cmc.deactivate();
        cleanUp();
        if (event instanceof QItemViewEvent) {
            QItemViewEvent e = (QItemViewEvent) event;
            List<QuestionItemView> items = e.getItemList();
            doSelectInsertionPoint(ureq, CMD_TOOLS_ADD_QPOOL, items);
        }
    } else if (source == importTableWizard) {
        ItemsPackage importPackage = (ItemsPackage) importTableWizard.getRunContext().get("importPackage");
        getWindowControl().pop();
        cleanUp();
        if (event == Event.DONE_EVENT || event == Event.CHANGED_EVENT) {
            doSelectInsertionPoint(ureq, CMD_TOOLS_ADD_QPOOL, importPackage);
        }
    } else if (createConvertedTestController == source) {
        cmc.deactivate();
        if (event == Event.DONE_EVENT) {
            showInfo("test.converted");
            RepositoryEntry convertedEntry = createConvertedTestController.getAddedEntry();
            String businessPath = "[RepositoryEntry:" + convertedEntry.getKey() + "]";
            NewControllerFactory.getInstance().launch(businessPath, ureq, getWindowControl());
        }
        cleanUp();
    } else if (source == insertCtrl) {
        // catch insert operations
        cmc.deactivate();
        if (event == Event.DONE_EVENT) {
            TreePosition tp = insertCtrl.getInsertPosition();
            if (tp != null) {
                doInsert(ureq, tp, insertCtrl.getUserObject());
                updateWarning();
            }
        }
        cleanUp();
    } else if (source == moveCtrl) {
        cmc.deactivate();
        if (Event.DONE_EVENT == event) {
            TreePosition tp = moveCtrl.getInsertPosition();
            if (tp != null) {
                doMove(tp);
                // force rerendering for ajax mode
                menuTree.setDirty(true);
                updateWarning();
            }
        }
        cleanUp();
    } else if (source == copyCtrl) {
        cmc.deactivate();
        if (Event.DONE_EVENT == event) {
            TreePosition tp = copyCtrl.getInsertPosition();
            if (tp != null) {
                doCopy(ureq, tp);
                updateWarning();
            }
        }
        cleanUp();
    }
}
Also used : GenericQtiNode(org.olat.ims.qti.editor.tree.GenericQtiNode) RepositoryEntry(org.olat.repository.RepositoryEntry) ItemsPackage(org.olat.ims.qti.questionimport.ItemsPackage) TreePosition(org.olat.core.gui.components.tree.TreePosition) Memento(org.olat.core.util.memento.Memento) QTIChangeLogMessage(org.olat.ims.qti.QTIChangeLogMessage) ContactFormController(org.olat.modules.co.ContactFormController) QItemViewEvent(org.olat.modules.qpool.ui.events.QItemViewEvent) Event(org.olat.core.gui.control.Event) QItemViewEvent(org.olat.modules.qpool.ui.events.QItemViewEvent) QuestionItemView(org.olat.modules.qpool.QuestionItemView)

Aggregations

QTIChangeLogMessage (org.olat.ims.qti.QTIChangeLogMessage)6 ParseException (java.text.ParseException)2 Date (java.util.Date)2 TreePosition (org.olat.core.gui.components.tree.TreePosition)2 Event (org.olat.core.gui.control.Event)2 Roles (org.olat.core.id.Roles)2 Formatter (org.olat.core.util.Formatter)2 Memento (org.olat.core.util.memento.Memento)2 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2 VFSItem (org.olat.core.util.vfs.VFSItem)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 GenericQtiNode (org.olat.ims.qti.editor.tree.GenericQtiNode)2 ImsRepositoryResolver (org.olat.ims.qti.process.ImsRepositoryResolver)2 ItemsPackage (org.olat.ims.qti.questionimport.ItemsPackage)2 ContactFormController (org.olat.modules.co.ContactFormController)2 QuestionItemView (org.olat.modules.qpool.QuestionItemView)2 QItemViewEvent (org.olat.modules.qpool.ui.events.QItemViewEvent)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2