Search in sources :

Example 26 with AssertException

use of org.olat.core.logging.AssertException in project OpenOLAT by OpenOLAT.

the class CourseEditorTreeModel method insertCourseNodeAt.

/**
 * @param newNode
 * @param parentNode
 * @param pos
 */
public CourseEditorTreeNode insertCourseNodeAt(CourseNode newNode, CourseNode parentNode, int pos) {
    // update editor tree model
    CourseEditorTreeNode ctnParent = (CourseEditorTreeNode) getNodeById(parentNode.getIdent());
    if (ctnParent == null)
        throw new AssertException("Corrupt CourseEditorTreeModel.");
    CourseEditorTreeNode newCetn = new CourseEditorTreeNode(newNode);
    newCetn.setNewnode(true);
    newCetn.setDirty(true);
    ctnParent.insert(newCetn, pos);
    log.debug("insertCourseNodeAt - nodeId: " + newNode.getIdent());
    return newCetn;
}
Also used : AssertException(org.olat.core.logging.AssertException)

Example 27 with AssertException

use of org.olat.core.logging.AssertException in project OpenOLAT by OpenOLAT.

the class CourseEditorTreeModel method markUnDeleted.

/**
 * marks an couse node and all it's children as undeleted
 * @param courseNode
 */
public void markUnDeleted(CourseNode courseNode) {
    CourseEditorTreeNode cetNode = (CourseEditorTreeNode) getNodeById(courseNode.getIdent());
    if (cetNode == null)
        throw new AssertException("Corrupt CourseEditorTreeModel.");
    markUnDeleted(cetNode);
}
Also used : AssertException(org.olat.core.logging.AssertException)

Example 28 with AssertException

use of org.olat.core.logging.AssertException in project OpenOLAT by OpenOLAT.

the class StatisticUpdateManagerImpl method updateStatistics.

@Override
public boolean updateStatistics(final boolean fullRecalculation, final Runnable finishedCallback) {
    synchronized (this) {
        if (!enabled_) {
            log_.warn("updateStatistics: cannot update statistics, manager is not enabled!", new Exception("updateStatistics"));
            return false;
        }
        if (updateOngoing_) {
            log_.warn("updateStatistics: cannot update statistics since an update is currently ongoing");
            return false;
        }
        updateOngoing_ = true;
    }
    Runnable r = new Runnable() {

        @Override
        public void run() {
            final long start = System.currentTimeMillis();
            try {
                log_.info("updateStatistics: initialization for update");
                long nowInMilliseconds = System.currentTimeMillis();
                long lastUpdatedInMilliseconds = getAndUpdateLastUpdated(nowInMilliseconds);
                if (fullRecalculation || (lastUpdatedInMilliseconds == -1)) {
                    Calendar nineteennintyeight = Calendar.getInstance();
                    nineteennintyeight.set(1998, 12, 31);
                    lastUpdatedInMilliseconds = nineteennintyeight.getTimeInMillis();
                }
                Date lastUpdatedDate = new Date(lastUpdatedInMilliseconds);
                Date nowDate = new Date(nowInMilliseconds);
                log_.info("updateStatistics: starting the update");
                DBFactory.getInstance().intermediateCommit();
                for (Iterator<IStatisticUpdater> it = updaters_.iterator(); it.hasNext(); ) {
                    IStatisticUpdater statisticUpdater = it.next();
                    log_.info("updateStatistics: starting updater " + statisticUpdater);
                    statisticUpdater.updateStatistic(fullRecalculation || (lastUpdatedInMilliseconds == -1), lastUpdatedDate, nowDate, StatisticUpdateManagerImpl.this);
                    log_.info("updateStatistics: done with updater " + statisticUpdater);
                    DBFactory.getInstance().intermediateCommit();
                }
            } finally {
                synchronized (StatisticUpdateManagerImpl.this) {
                    updateOngoing_ = false;
                }
                final long diff = System.currentTimeMillis() - start;
                log_.info("updateStatistics: total time for updating all statistics was " + diff + " milliseconds");
                if (finishedCallback != null) {
                    finishedCallback.run();
                }
            }
        }
    };
    try {
        taskExecutorManager.execute(r);
        log_.info("updateStatistics: starting the update in its own thread");
        return true;
    } catch (AssertException ae) {
        log_.info("updateStatistics: Could not start update due to TaskExecutorManager not yet initialized. Will be done next time Cron/User calls!");
        synchronized (StatisticUpdateManagerImpl.this) {
            updateOngoing_ = false;
        }
        return false;
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) Calendar(java.util.Calendar) AssertException(org.olat.core.logging.AssertException) Date(java.util.Date)

Example 29 with AssertException

use of org.olat.core.logging.AssertException in project OpenOLAT by OpenOLAT.

the class Response_label method render.

/**
 * @see org.olat.ims.qti.container.qtielements.QTIElement#render(StringBuilder,
 *      RenderInstructions)
 */
@Override
public void render(StringBuilder buffer, RenderInstructions ri) {
    ItemInput iinput = (ItemInput) ri.get(RenderInstructions.KEY_ITEM_INPUT);
    String responseIdent = (String) ri.get(RenderInstructions.KEY_RESPONSE_IDENT);
    // find parent render_xxx element
    String renderClass = (String) ri.get(RenderInstructions.KEY_RENDER_CLASS);
    if (renderClass == null) {
    // we don't know what to do
    } else if (renderClass.equals("choice")) {
        renderChoice(buffer, ri, iinput);
    } else if (renderClass.equals("kprim")) {
        buffer.append("<tr><td class='o_qti_item_kprim_input'><input id=\"QTI_").append(ri.get(RenderInstructions.KEY_ITEM_IDENT)).append(getQTIIdent()).append("\" type=\"radio\" class=\"radio\" name=\"");
        appendParameterIdent(buffer, ri);
        buffer.append("\" value=\"" + getQTIIdent() + ":correct");
        if (iinput != null && !iinput.isEmpty()) {
            List<String> responses = iinput.getAsList(responseIdent);
            if (responses != null && responses.contains(getQTIIdent() + ":correct"))
                buffer.append("\" checked=\"checked");
        }
        buffer.append("\" onchange=\"return setFormDirty('ofo_iq_item')\" onclick=\"return setFormDirty('ofo_iq_item')\"/>");
        buffer.append("</td><td class='o_qti_item_kprim_input'><input id=\"QTI_").append(ri.get(RenderInstructions.KEY_ITEM_IDENT)).append(getQTIIdent()).append("\" type=\"radio\" class=\"radio\" name=\"");
        appendParameterIdent(buffer, ri);
        buffer.append("\" value=\"" + getQTIIdent() + ":wrong");
        if (iinput != null && !iinput.isEmpty()) {
            List<String> responses = iinput.getAsList(responseIdent);
            if (responses != null && responses.contains(getQTIIdent() + ":wrong"))
                buffer.append("\" checked=\"checked");
        }
        buffer.append("\" onchange=\"return setFormDirty('ofo_iq_item')\" onclick=\"return setFormDirty('ofo_iq_item')\"/>");
        buffer.append("</td><td>");
        super.render(buffer, ri);
        buffer.append("</td></tr>");
        ri.put(RenderInstructions.KEY_FLOW_LABEL, new Integer(RenderInstructions.RENDER_FLOW_BLOCK));
        addBr(ri, buffer);
    } else if (renderClass.equals("fib")) {
        Integer rows = (Integer) ri.get(RenderInstructions.KEY_FIB_ROWS);
        Integer columns = (Integer) ri.get(RenderInstructions.KEY_FIB_COLUMNS);
        Integer maxlength = (Integer) ri.get(RenderInstructions.KEY_FIB_MAXLENGTH);
        if (rows == null || columns == null || maxlength == null)
            throw new AssertException("Rows and/or columns attribute not specified for render_fib.");
        if (rows.intValue() > 1) {
            // render as textarea
            buffer.append("<textarea id=\"QTI_").append(getQTIIdent()).append("\" name=\"");
            appendParameterIdent(buffer, ri);
            buffer.append("\" class='form-control' rows=\"").append(rows).append("\" cols=\"").append(columns).append("\" onchange=\"return setFormDirty('ofo_iq_item')\" onclick=\"return setFormDirty('ofo_iq_item')\">");
            if (iinput != null && !iinput.isEmpty() && iinput.getSingle(responseIdent) != null) {
                buffer.append(iinput.getSingle(getQTIIdent()));
            }
            buffer.append("</textarea>");
        } else {
            // render as input string
            buffer.append("<span> </span><input id=\"QTI_").append(getQTIIdent()).append("\" name=\"");
            appendParameterIdent(buffer, ri);
            buffer.append("\" type=\"text\" size=\"").append(columns).append("\" maxlength=\"").append(maxlength);
            if (iinput != null && !iinput.isEmpty() && iinput.getSingle(responseIdent) != null) {
                buffer.append("\" value=\"").append(StringHelper.escapeHtml(iinput.getSingle(getQTIIdent())));
            }
            buffer.append("\" onchange=\"return setFormDirty('ofo_iq_item')\" onclick=\"return setFormDirty('ofo_iq_item')\" /><span> </span>");
        }
        addBr(ri, buffer);
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) ItemInput(org.olat.ims.qti.container.ItemInput)

Example 30 with AssertException

use of org.olat.core.logging.AssertException in project OpenOLAT by OpenOLAT.

the class EPArtefactManager method filterArtefactsByDate.

/**
 * date comparison will first set startDate to 00:00:00 and set endDate to
 * 23:59:59 else there might be no results if start = end date. dateList must
 * be set according to: dateList(0) = startDate dateList(1) = endDate
 */
private void filterArtefactsByDate(List<AbstractArtefact> artefacts, List<Date> dateList) {
    if (dateList != null && dateList.size() != 0) {
        if (dateList.size() == 2) {
            Date startDate = dateList.get(0);
            Date endDate = dateList.get(1);
            Calendar cal = Calendar.getInstance();
            if (startDate == null) {
                cal.set(1970, 1, 1);
            } else {
                cal.setTime(startDate);
            }
            cal.set(Calendar.HOUR_OF_DAY, 0);
            cal.set(Calendar.MINUTE, 0);
            cal.set(Calendar.SECOND, 0);
            startDate = cal.getTime();
            cal.setTime(endDate);
            cal.set(Calendar.HOUR_OF_DAY, 23);
            cal.set(Calendar.MINUTE, 59);
            cal.set(Calendar.SECOND, 59);
            endDate = cal.getTime();
            List<AbstractArtefact> toRemove = new ArrayList<AbstractArtefact>();
            for (AbstractArtefact artefact : artefacts) {
                Date creationDate = artefact.getCreationDate();
                if (!(creationDate.before(endDate) && creationDate.after(startDate))) {
                    toRemove.add(artefact);
                }
            }
            artefacts.removeAll(toRemove);
        } else
            throw new AssertException("provided DateList must contain exactly two Date-objects");
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) Calendar(java.util.Calendar) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) ArrayList(java.util.ArrayList) Date(java.util.Date)

Aggregations

AssertException (org.olat.core.logging.AssertException)364 IOException (java.io.IOException)38 File (java.io.File)28 Identity (org.olat.core.id.Identity)28 ArrayList (java.util.ArrayList)26 HashMap (java.util.HashMap)24 Controller (org.olat.core.gui.control.Controller)22 OLATResourceable (org.olat.core.id.OLATResourceable)22 RepositoryEntry (org.olat.repository.RepositoryEntry)22 WindowControl (org.olat.core.gui.control.WindowControl)20 UnsupportedEncodingException (java.io.UnsupportedEncodingException)18 JSONException (org.json.JSONException)18 BusinessGroup (org.olat.group.BusinessGroup)18 JSONObject (org.json.JSONObject)16 UserRequest (org.olat.core.gui.UserRequest)16 VFSContainer (org.olat.core.util.vfs.VFSContainer)16 VFSItem (org.olat.core.util.vfs.VFSItem)16 Date (java.util.Date)14 Properties (java.util.Properties)14 Property (org.olat.properties.Property)14