Search in sources :

Example 71 with Formatter

use of org.olat.core.util.Formatter in project openolat by klemens.

the class LecturesBlockPDFExport method create.

public void create(List<Identity> rows, List<LectureBlockRollCall> rollCalls) throws IOException, TransformerException {
    addPageLandscape();
    String lectureBlockTitle = lectureBlock.getTitle();
    String resourceTitle = entry.getDisplayname();
    addMetadata(lectureBlockTitle, resourceTitle, teacher);
    String title = resourceTitle + " - " + lectureBlockTitle;
    title = translator.translate("attendance.list.title", new String[] { title });
    addParagraph(title, 16, true, width);
    Formatter formatter = Formatter.getInstance(translator.getLocale());
    String dates = translator.translate("pdf.table.dates", new String[] { formatter.formatDate(lectureBlock.getStartDate()), formatter.formatTimeShort(lectureBlock.getStartDate()), formatter.formatTimeShort(lectureBlock.getEndDate()) });
    addParagraph(dates, 12, true, width);
    float cellMargin = 5.0f;
    float fontSize = 10.0f;
    Row[] content = getRows(rows, rollCalls);
    int numOfRows = content.length;
    for (int offset = 0; offset < numOfRows; ) {
        offset += drawTable(content, offset, fontSize, cellMargin);
        closePage();
        if (offset < numOfRows) {
            addPageLandscape();
        }
    }
    addPageNumbers();
}
Also used : Formatter(org.olat.core.util.Formatter)

Example 72 with Formatter

use of org.olat.core.util.Formatter in project openolat by klemens.

the class EPChangelogController method getItemBundlesForSubscriptionItems.

/**
 * @param subscriptionItems
 * @return
 */
private List<SubscriptionItemBundle> getItemBundlesForSubscriptionItems(List<SubscriptionListItem> subscriptionItems) {
    List<SubscriptionItemBundle> bundles = new ArrayList<EPChangelogController.SubscriptionItemBundle>();
    Formatter f = Formatter.getInstance(getTranslator().getLocale());
    for (int i = 0; i < subscriptionItems.size(); i++) {
        SubscriptionListItem listItem = subscriptionItems.get(i);
        SubscriptionItemBundle bundle = new SubscriptionItemBundle();
        bundle.setDateString(f.formatDate(listItem.getDate()));
        String linkName = "subscrIL_" + i;
        bundle.setLinkName(linkName);
        String text = listItem.getDescription();
        FormLink link = uifactory.addFormLink(linkName, text, null, flc, Link.NONTRANSLATED);
        link.setUserObject(listItem.getUserObject());
        bundle.setCssClass(listItem.getIconCssClass());
        bundles.add(bundle);
    }
    return bundles;
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) Formatter(org.olat.core.util.Formatter) ArrayList(java.util.ArrayList) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Example 73 with Formatter

use of org.olat.core.util.Formatter in project openolat by klemens.

the class ParticipantLectureBlocksController method loadModel.

private void loadModel() {
    Date now = new Date();
    Formatter formatter = Formatter.getInstance(getLocale());
    String separator = translate("user.fullname.separator");
    List<LectureBlockAndRollCall> rollCalls = lectureService.getParticipantLectureBlocks(entry, assessedIdentity, separator);
    List<LectureBlockAuditLog> sendAppealLogs = lectureService.getAuditLog(entry, assessedIdentity, LectureBlockAuditLog.Action.sendAppeal);
    Map<Long, Date> appealDates = new HashMap<>();
    for (LectureBlockAuditLog sendAppealLog : sendAppealLogs) {
        if (sendAppealLog.getRollCallKey() != null) {
            appealDates.put(sendAppealLog.getRollCallKey(), sendAppealLog.getCreationDate());
        }
    }
    List<LectureBlockAndRollCallRow> rows = new ArrayList<>(rollCalls.size());
    for (LectureBlockAndRollCall rollCall : rollCalls) {
        LectureBlockAndRollCallRow row = new LectureBlockAndRollCallRow(rollCall);
        if (appealEnabled && !LectureBlockStatus.cancelled.equals(row.getRow().getStatus()) && rollCall.isCompulsory()) {
            int lectures = row.getRow().getEffectiveLecturesNumber();
            if (lectures <= 0) {
                lectures = row.getRow().getPlannedLecturesNumber();
            }
            int attended = row.getRow().getLecturesAttendedNumber();
            if (attended < lectures) {
                Date date = row.getRow().getDate();
                Calendar cal = Calendar.getInstance();
                cal.setTime(date);
                cal = CalendarUtils.getEndOfDay(cal);
                cal.add(Calendar.DATE, appealOffset);
                Date beginAppeal = CalendarUtils.removeTime(cal.getTime());
                cal.add(Calendar.DATE, appealPeriod);
                Date endAppeal = CalendarUtils.getEndOfDay(cal).getTime();
                Date sendAppealDate = null;
                if (row.getRow().getRollCallRef() != null) {
                    sendAppealDate = appealDates.get(row.getRow().getRollCallRef().getKey());
                }
                FormLink appealLink = null;
                if (sendAppealDate != null) {
                    String appealFrom = translate("appeal.sent", new String[] { formatter.formatDate(sendAppealDate) });
                    appealLink = uifactory.addFormLink("appeal_" + count++, "appealsend", appealFrom, null, flc, Link.LINK | Link.NONTRANSLATED);
                    appealLink.setTitle(translate("appeal.sent.tooltip", new String[] { formatter.formatDate(sendAppealDate), formatter.formatDate(beginAppeal), formatter.formatDate(endAppeal) }));
                    appealLink.setEnabled(false);
                    appealLink.setDomReplacementWrapperRequired(false);
                } else if (now.compareTo(beginAppeal) >= 0 && now.compareTo(endAppeal) <= 0) {
                    appealLink = uifactory.addFormLink("appeal_" + count++, "appeal", translate("appeal"), null, flc, Link.LINK | Link.NONTRANSLATED);
                    appealLink.setTitle(translate("appeal.tooltip", new String[] { formatter.formatDate(beginAppeal), formatter.formatDate(endAppeal) }));
                    appealLink.setUserObject(row);
                // appeal
                } else if (now.compareTo(endAppeal) > 0) {
                    // appeal closed
                    appealLink = uifactory.addFormLink("appeal_" + count++, "aclosed", "appeal.closed", null, flc, Link.LINK);
                    appealLink.setEnabled(false);
                    appealLink.setDomReplacementWrapperRequired(false);
                } else if (now.compareTo(date) >= 0) {
                    // appeal at
                    String appealFrom = translate("appeal.from", new String[] { formatter.formatDate(beginAppeal) });
                    appealLink = uifactory.addFormLink("appeal_" + count++, "appealat", appealFrom, null, flc, Link.LINK | Link.NONTRANSLATED);
                    appealLink.setEnabled(false);
                    appealLink.setDomReplacementWrapperRequired(false);
                }
                row.setAppealButton(appealLink);
            }
        }
        rows.add(row);
    }
    tableModel.setObjects(rows);
    tableEl.reset(true, true, true);
}
Also used : LectureBlockAndRollCall(org.olat.modules.lecture.model.LectureBlockAndRollCall) HashMap(java.util.HashMap) Formatter(org.olat.core.util.Formatter) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) LectureBlockAuditLog(org.olat.modules.lecture.LectureBlockAuditLog) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) Date(java.util.Date)

Example 74 with Formatter

use of org.olat.core.util.Formatter in project openolat by klemens.

the class InfoDisplayController method createInfoMessageForDisplay.

private InfoMessageForDisplay createInfoMessageForDisplay(InfoMessage info) {
    String message = info.getMessage();
    boolean html = StringHelper.isHtml(message);
    if (html) {
        message = message.toString();
    } else if (StringHelper.containsNonWhitespace(message)) {
        message = Formatter.escWithBR(info.getMessage()).toString();
        message = Formatter.formatURLsAsLinks(message);
    }
    Formatter formatter = Formatter.getInstance(getLocale());
    String modifier = null;
    if (info.getModifier() != null) {
        String formattedName = userManager.getUserDisplayName(info.getModifier());
        String creationDate = formatter.formatDateAndTime(info.getModificationDate());
        modifier = translate("display.modifier", new String[] { StringHelper.escapeHtml(formattedName), creationDate });
    }
    String authorName = userManager.getUserDisplayName(info.getAuthor());
    String creationDate = formatter.formatDateAndTime(info.getCreationDate());
    String infos;
    if (authorName.isEmpty()) {
        infos = translate("display.info.noauthor", new String[] { creationDate });
    } else {
        infos = translate("display.info", new String[] { StringHelper.escapeHtml(authorName), creationDate });
    }
    VFSLeaf attachment = infoMessageManager.getAttachment(info);
    return new InfoMessageForDisplay(info.getKey(), info.getTitle(), message, attachment, infos, modifier);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) MailFormatter(org.olat.commons.info.manager.MailFormatter) Formatter(org.olat.core.util.Formatter)

Example 75 with Formatter

use of org.olat.core.util.Formatter in project openolat by klemens.

the class SysinfoController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    Formatter format = Formatter.getInstance(getLocale());
    // runtime informations
    FormLayoutContainer runtimeCont = FormLayoutContainer.createDefaultFormLayout("runtime", getTranslator());
    formLayout.add(runtimeCont);
    formLayout.add("runtime", runtimeCont);
    String startup = format.formatDateAndTime(new Date(WebappHelper.getTimeOfServerStartup()));
    uifactory.addStaticTextElement("runtime.startup", "runtime.startup", startup, runtimeCont);
    String time = format.formatDateAndTime(new Date()) + " (" + Calendar.getInstance().getTimeZone().getDisplayName(false, TimeZone.SHORT, ureq.getLocale()) + ")";
    uifactory.addStaticTextElement("runtime.time", "runtime.time", time, runtimeCont);
    // memory
    uifactory.addMemoryView("memoryHeap", "runtime.memory", MemoryType.HEAP, runtimeCont);
    uifactory.addMemoryView("memoryNonHeap", "runtime.memory.permGen", MemoryType.NON_HEAP, runtimeCont);
    // controllers
    int controllerCnt = DefaultController.getControllerCount();
    uifactory.addStaticTextElement("controllercount", "runtime.controllercount", Integer.toString(controllerCnt), runtimeCont);
    int numOfDispatchingThreads = sessionStatsManager.getConcurrentCounter();
    uifactory.addStaticTextElement("dispatchingthreads", "runtime.dispatchingthreads", Integer.toString(numOfDispatchingThreads), runtimeCont);
    // sessions and clicks
    String sessionAndClicksPage = velocity_root + "/session_clicks.html";
    FormLayoutContainer sessionAndClicksCont = FormLayoutContainer.createCustomFormLayout("session_clicks", getTranslator(), sessionAndClicksPage);
    runtimeCont.add(sessionAndClicksCont);
    sessionAndClicksCont.setLabel("sess.and.clicks", null);
    Calendar lastLoginMonthlyLimit = Calendar.getInstance();
    // users monthly
    lastLoginMonthlyLimit.add(Calendar.MONTH, -1);
    Long userLastMonth = securityManager.countUniqueUserLoginsSince(lastLoginMonthlyLimit.getTime());
    // -1 -5 = -6 for half a year
    lastLoginMonthlyLimit.add(Calendar.MONTH, -5);
    Long userLastSixMonths = securityManager.countUniqueUserLoginsSince(lastLoginMonthlyLimit.getTime());
    // -1 -11 = -12 for one year
    lastLoginMonthlyLimit.add(Calendar.MONTH, -11);
    Long userLastYear = securityManager.countUniqueUserLoginsSince(lastLoginMonthlyLimit.getTime());
    sessionAndClicksCont.contextPut("users1month", userLastMonth.toString());
    sessionAndClicksCont.contextPut("users6month", userLastSixMonths.toString());
    sessionAndClicksCont.contextPut("usersyear", userLastYear.toString());
    // users daily
    Calendar lastLoginDailyLimit = Calendar.getInstance();
    lastLoginDailyLimit.add(Calendar.DAY_OF_YEAR, -1);
    Long userLastDay = securityManager.countUniqueUserLoginsSince(lastLoginDailyLimit.getTime());
    // -1 - 6 = -7 for last week
    lastLoginDailyLimit.add(Calendar.DAY_OF_YEAR, -6);
    Long userLast6Days = securityManager.countUniqueUserLoginsSince(lastLoginDailyLimit.getTime());
    sessionAndClicksCont.contextPut("userslastday", userLastDay.toString());
    sessionAndClicksCont.contextPut("userslastweek", userLast6Days.toString());
    // last 5 minutes
    long activeSessions = sessionStatsManager.getActiveSessions(300);
    sessionAndClicksCont.contextPut("count5Minutes", String.valueOf(activeSessions));
    SessionsStats stats = sessionStatsManager.getSessionsStatsLast(300);
    sessionAndClicksCont.contextPut("click5Minutes", String.valueOf(stats.getAuthenticatedClickCalls()));
    sessionAndClicksCont.contextPut("poll5Minutes", String.valueOf(stats.getAuthenticatedPollerCalls()));
    sessionAndClicksCont.contextPut("request5Minutes", String.valueOf(stats.getRequests()));
    sessionAndClicksCont.contextPut("minutes", String.valueOf(5));
    // last minute
    activeSessions = sessionStatsManager.getActiveSessions(60);
    sessionAndClicksCont.contextPut("count1Minute", String.valueOf(activeSessions));
    stats = sessionStatsManager.getSessionsStatsLast(60);
    sessionAndClicksCont.contextPut("click1Minute", String.valueOf(stats.getAuthenticatedClickCalls()));
    sessionAndClicksCont.contextPut("poll1Minute", String.valueOf(stats.getAuthenticatedPollerCalls()));
    sessionAndClicksCont.contextPut("request1Minute", String.valueOf(stats.getRequests()));
    sessionAndClicksCont.contextPut("oneMinute", "1");
    // server informations
    FormLayoutContainer serverCont = FormLayoutContainer.createDefaultFormLayout("server", getTranslator());
    formLayout.add(serverCont);
    formLayout.add("server", serverCont);
    // version
    uifactory.addStaticTextElement("version", "sysinfo.version", Settings.getFullVersionInfo(), serverCont);
    uifactory.addStaticTextElement("version.hg", "sysinfo.version.hg", WebappHelper.getChangeSet(), serverCont);
    String buildDate = format.formatDateAndTime(Settings.getBuildDate());
    uifactory.addStaticTextElement("version.date", "sysinfo.version.date", buildDate, serverCont);
    // cluster
    boolean clusterMode = "Cluster".equals(Settings.getClusterMode());
    MultipleSelectionElement clusterEl = uifactory.addCheckboxesHorizontal("cluster", "sysinfo.cluster", serverCont, new String[] { "xx" }, new String[] { "" });
    clusterEl.setEnabled(false);
    clusterEl.select("xx", clusterMode);
    String nodeId = StringHelper.containsNonWhitespace(Settings.getNodeInfo()) ? Settings.getNodeInfo() : "N1";
    uifactory.addStaticTextElement("node", "sysinfo.node", nodeId, serverCont);
    File baseDir = new File(WebappHelper.getContextRoot());
    String baseDirPath = null;
    try {
        baseDirPath = baseDir.getCanonicalPath();
    } catch (IOException e1) {
        baseDirPath = baseDir.getAbsolutePath();
    }
    uifactory.addStaticTextElement("sysinfo.basedir", "sysinfo.basedir", baseDirPath, serverCont);
    uifactory.addStaticTextElement("sysinfo.olatdata", "sysinfo.olatdata", WebappHelper.getUserDataRoot(), serverCont);
}
Also used : Formatter(org.olat.core.util.Formatter) Calendar(java.util.Calendar) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) IOException(java.io.IOException) Date(java.util.Date) SessionsStats(org.olat.admin.sysinfo.model.SessionsStats) MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) File(java.io.File)

Aggregations

Formatter (org.olat.core.util.Formatter)80 Date (java.util.Date)30 ArrayList (java.util.ArrayList)12 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)12 IOException (java.io.IOException)6 SubscriptionListItem (org.olat.core.commons.services.notifications.model.SubscriptionListItem)6 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)6 Identity (org.olat.core.id.Identity)6 Translator (org.olat.core.gui.translator.Translator)5 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)5 File (java.io.File)4 Calendar (java.util.Calendar)4 HashMap (java.util.HashMap)4 COSVisitorException (org.apache.pdfbox.exceptions.COSVisitorException)4 Row (org.olat.core.util.openxml.OpenXMLWorksheet.Row)4 OWASPAntiSamyXSSFilter (org.olat.core.util.filter.impl.OWASPAntiSamyXSSFilter)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 VelocityContext (org.apache.velocity.VelocityContext)2 Context (org.apache.velocity.context.Context)2