Search in sources :

Example 1 with InfoMessage

use of org.olat.commons.info.InfoMessage in project OpenOLAT by OpenOLAT.

the class InfoMessagesWebService method createEmptyCourse.

/**
 * Creates a new info message
 * @response.representation.200.qname {http://www.example.com}infoMessageVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The info message
 * @response.representation.200.example {@link org.olat.commons.info.restapi.Examples#SAMPLE_INFOMESSAGEVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @param resName The OLAT Resourceable name
 * @param resId The OLAT Resourceable id
 * @param resSubPath The resource sub path (optional)
 * @param businessPath The business path
 * @param authorKey The identity key of the author
 * @param title The title
 * @param message The message
 * @param request The HTTP request
 * @return It returns the id of the newly info message
 */
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response createEmptyCourse(@QueryParam("resName") final String resName, @QueryParam("resId") final Long resId, @QueryParam("resSubPath") String resSubPath, @QueryParam("businessPath") String businessPath, @QueryParam("authorKey") Long authorKey, @QueryParam("title") String title, @QueryParam("message") String message, @Context HttpServletRequest request) {
    if (!isAuthor(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    OLATResourceable ores = new OLATResourceable() {

        @Override
        public String getResourceableTypeName() {
            return resName;
        }

        @Override
        public Long getResourceableId() {
            return resId;
        }
    };
    Identity author;
    UserRequest ureq = getUserRequest(request);
    if (authorKey == null) {
        author = ureq.getIdentity();
    } else {
        BaseSecurity securityManager = BaseSecurityManager.getInstance();
        author = securityManager.loadIdentityByKey(authorKey, false);
        if (author == null) {
            return Response.serverError().status(Status.UNAUTHORIZED).build();
        }
    }
    InfoMessageFrontendManager messageManager = CoreSpringFactory.getImpl(InfoMessageFrontendManager.class);
    InfoMessage msg = messageManager.createInfoMessage(ores, resSubPath, businessPath, author);
    msg.setTitle(title);
    msg.setMessage(message);
    messageManager.sendInfoMessage(msg, null, ureq.getLocale(), ureq.getIdentity(), Collections.<Identity>emptyList());
    InfoMessageVO infoVO = new InfoMessageVO(msg);
    return Response.ok(infoVO).build();
}
Also used : InfoMessageFrontendManager(org.olat.commons.info.InfoMessageFrontendManager) OLATResourceable(org.olat.core.id.OLATResourceable) InfoMessage(org.olat.commons.info.InfoMessage) Identity(org.olat.core.id.Identity) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) BaseSecurity(org.olat.basesecurity.BaseSecurity) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 2 with InfoMessage

use of org.olat.commons.info.InfoMessage in project OpenOLAT by OpenOLAT.

the class InfoDisplayController method loadMessages.

/**
 * This is the main method which push the messages in the layout container,
 * and clean-up old links.
 */
protected void loadMessages() {
    // first clear the current message if any
    for (Long key : previousDisplayKeys) {
        flc.contextRemove("info.date." + key);
        if (flc.getComponent("info.delete." + key) != null) {
            flc.remove("info.delete." + key);
        }
        if (flc.getComponent("info.edit." + key) != null) {
            flc.remove("info.edit." + key);
        }
    }
    previousDisplayKeys.clear();
    deleteLinks.clear();
    List<InfoMessage> msgs = infoMessageManager.loadInfoMessageByResource(ores, resSubPath, businessPath, after, null, 0, maxResults);
    List<InfoMessageForDisplay> infoDisplays = new ArrayList<>(msgs.size());
    Map<Long, VFSLeaf> keyToDisplay = new HashMap<>();
    for (InfoMessage info : msgs) {
        previousDisplayKeys.add(info.getKey());
        InfoMessageForDisplay infoDisplay = createInfoMessageForDisplay(info);
        infoDisplays.add(infoDisplay);
        if (infoDisplay.getAttachment() != null) {
            keyToDisplay.put(info.getKey(), infoDisplay.getAttachment());
        }
        String dateCmpName = "info.date." + info.getKey();
        DateElement dateEl = DateComponentFactory.createDateElementWithYear(dateCmpName, info.getCreationDate());
        flc.add(dateCmpName, dateEl);
        if (secCallback.canEdit(info)) {
            String editName = "info.edit." + info.getKey();
            FormLink link = uifactory.addFormLink(editName, "edit", "edit", flc, Link.BUTTON_SMALL);
            link.setElementCssClass("o_sel_info_edit_msg");
            link.setUserObject(info);
            editLinks.add(link);
            flc.add(link);
        }
        if (secCallback.canDelete()) {
            String delName = "info.delete." + info.getKey();
            FormLink link = uifactory.addFormLink(delName, "delete", "delete", flc, Link.BUTTON_SMALL);
            link.setElementCssClass("o_sel_info_delete_msg");
            link.setUserObject(info);
            deleteLinks.add(link);
            flc.add(link);
        }
    }
    flc.contextPut("infos", infoDisplays);
    infoKeyToAttachment = keyToDisplay;
    int numOfInfos = infoMessageManager.countInfoMessageByResource(ores, resSubPath, businessPath, null, null);
    oldMsgsLink.setVisible((msgs.size() < numOfInfos));
    newMsgsLink.setVisible((msgs.size() == numOfInfos) && (numOfInfos > maxResultsConfig) && (maxResultsConfig > 0));
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) HashMap(java.util.HashMap) DateElement(org.olat.core.gui.components.date.DateElement) ArrayList(java.util.ArrayList) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) InfoMessage(org.olat.commons.info.InfoMessage)

Example 3 with InfoMessage

use of org.olat.commons.info.InfoMessage in project openolat by klemens.

the class InfoPeekViewController method init.

private void init(UserRequest ureq) {
    TableGuiConfiguration tableConfig = new TableGuiConfiguration();
    tableConfig.setTableEmptyMessage(translate("peekview.noInfos"));
    tableConfig.setDisplayTableHeader(false);
    tableConfig.setCustomCssClass("o_portlet_table");
    tableConfig.setDisplayRowCount(false);
    tableConfig.setPageingEnabled(false);
    tableConfig.setDownloadOffered(false);
    tableConfig.setSortingEnabled(false);
    removeAsListenerAndDispose(tableController);
    tableController = new TableController(tableConfig, ureq, getWindowControl(), getTranslator());
    tableController.addColumnDescriptor(new CustomRenderColumnDescriptor("peekview.title", 0, null, ureq.getLocale(), ColumnDescriptor.ALIGNMENT_LEFT, new InfoNodeRenderer()));
    String resSubPath = courseNode.getIdent();
    List<InfoMessage> infos = infoService.loadInfoMessageByResource(ores, resSubPath, null, null, null, 0, 5);
    InfosTableModel model = new InfosTableModel(infos);
    tableController.setTableDataModel(model);
    listenTo(tableController);
}
Also used : CustomRenderColumnDescriptor(org.olat.core.gui.components.table.CustomRenderColumnDescriptor) InfoMessage(org.olat.commons.info.InfoMessage) TableController(org.olat.core.gui.components.table.TableController) TableGuiConfiguration(org.olat.core.gui.components.table.TableGuiConfiguration)

Example 4 with InfoMessage

use of org.olat.commons.info.InfoMessage in project openolat by klemens.

the class InfoDisplayController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (source == newInfoLink) {
        InfoMessage msg = infoMessageManager.createInfoMessage(ores, resSubPath, businessPath, getIdentity());
        start = new CreateInfoStep(ureq, sendMailOptions, msg);
        newInfoWizard = new StepsMainRunController(ureq, getWindowControl(), start, new FinishedCallback(), new CancelCallback(), translate("create_message"), "o_sel_info_messages_create_wizard");
        listenTo(newInfoWizard);
        getWindowControl().pushAsModalDialog(newInfoWizard.getInitialComponent());
    } else if (deleteLinks.contains(source)) {
        InfoMessage msg = (InfoMessage) source.getUserObject();
        popupDelete(ureq, msg);
    } else if (editLinks.contains(source)) {
        InfoMessage msg = (InfoMessage) source.getUserObject();
        popupEdit(ureq, msg);
    } else if (source == oldMsgsLink) {
        maxResults = -1;
        after = null;
        loadMessages();
    } else if (source == newMsgsLink) {
        maxResults = maxResultsConfig;
        after = afterConfig;
        loadMessages();
    } else {
        super.formInnerEvent(ureq, source, event);
    }
}
Also used : InfoMessage(org.olat.commons.info.InfoMessage) StepsMainRunController(org.olat.core.gui.control.generic.wizard.StepsMainRunController)

Example 5 with InfoMessage

use of org.olat.commons.info.InfoMessage in project openolat by klemens.

the class InfoDisplayController method loadMessages.

/**
 * This is the main method which push the messages in the layout container,
 * and clean-up old links.
 */
protected void loadMessages() {
    // first clear the current message if any
    for (Long key : previousDisplayKeys) {
        flc.contextRemove("info.date." + key);
        if (flc.getComponent("info.delete." + key) != null) {
            flc.remove("info.delete." + key);
        }
        if (flc.getComponent("info.edit." + key) != null) {
            flc.remove("info.edit." + key);
        }
    }
    previousDisplayKeys.clear();
    deleteLinks.clear();
    List<InfoMessage> msgs = infoMessageManager.loadInfoMessageByResource(ores, resSubPath, businessPath, after, null, 0, maxResults);
    List<InfoMessageForDisplay> infoDisplays = new ArrayList<>(msgs.size());
    Map<Long, VFSLeaf> keyToDisplay = new HashMap<>();
    for (InfoMessage info : msgs) {
        previousDisplayKeys.add(info.getKey());
        InfoMessageForDisplay infoDisplay = createInfoMessageForDisplay(info);
        infoDisplays.add(infoDisplay);
        if (infoDisplay.getAttachment() != null) {
            keyToDisplay.put(info.getKey(), infoDisplay.getAttachment());
        }
        String dateCmpName = "info.date." + info.getKey();
        DateElement dateEl = DateComponentFactory.createDateElementWithYear(dateCmpName, info.getCreationDate());
        flc.add(dateCmpName, dateEl);
        if (secCallback.canEdit(info)) {
            String editName = "info.edit." + info.getKey();
            FormLink link = uifactory.addFormLink(editName, "edit", "edit", flc, Link.BUTTON_SMALL);
            link.setElementCssClass("o_sel_info_edit_msg");
            link.setUserObject(info);
            editLinks.add(link);
            flc.add(link);
        }
        if (secCallback.canDelete()) {
            String delName = "info.delete." + info.getKey();
            FormLink link = uifactory.addFormLink(delName, "delete", "delete", flc, Link.BUTTON_SMALL);
            link.setElementCssClass("o_sel_info_delete_msg");
            link.setUserObject(info);
            deleteLinks.add(link);
            flc.add(link);
        }
    }
    flc.contextPut("infos", infoDisplays);
    infoKeyToAttachment = keyToDisplay;
    int numOfInfos = infoMessageManager.countInfoMessageByResource(ores, resSubPath, businessPath, null, null);
    oldMsgsLink.setVisible((msgs.size() < numOfInfos));
    newMsgsLink.setVisible((msgs.size() == numOfInfos) && (numOfInfos > maxResultsConfig) && (maxResultsConfig > 0));
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) HashMap(java.util.HashMap) DateElement(org.olat.core.gui.components.date.DateElement) ArrayList(java.util.ArrayList) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) InfoMessage(org.olat.commons.info.InfoMessage)

Aggregations

InfoMessage (org.olat.commons.info.InfoMessage)24 OLATResourceable (org.olat.core.id.OLATResourceable)8 InfoMessageFrontendManager (org.olat.commons.info.InfoMessageFrontendManager)6 Identity (org.olat.core.id.Identity)6 ArrayList (java.util.ArrayList)4 Document (org.apache.lucene.document.Document)4 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)4 SearchResourceContext (org.olat.search.service.SearchResourceContext)4 InfoMessageDocument (org.olat.search.service.document.InfoMessageDocument)4 Date (java.util.Date)2 HashMap (java.util.HashMap)2 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 BaseSecurity (org.olat.basesecurity.BaseSecurity)2 InfoMessageImpl (org.olat.commons.info.model.InfoMessageImpl)2 DBQuery (org.olat.core.commons.persistence.DBQuery)2 NotificationsManager (org.olat.core.commons.services.notifications.NotificationsManager)2 Publisher (org.olat.core.commons.services.notifications.Publisher)2 SubscriptionInfo (org.olat.core.commons.services.notifications.SubscriptionInfo)2