Search in sources :

Example 6 with MultiUserEvent

use of org.olat.core.util.event.MultiUserEvent in project OpenOLAT by OpenOLAT.

the class InfoMessageFrontendManagerImpl method sendInfoMessage.

@Override
public boolean sendInfoMessage(InfoMessage infoMessage, MailFormatter mailFormatter, Locale locale, Identity from, List<Identity> tos) {
    infoMessageManager.saveInfoMessage(infoMessage);
    boolean send = false;
    if (tos != null && !tos.isEmpty()) {
        Set<Long> identityKeySet = new HashSet<Long>();
        ContactList contactList = new ContactList("Infos");
        for (Identity to : tos) {
            if (identityKeySet.contains(to.getKey()))
                continue;
            contactList.add(to);
            identityKeySet.add(to.getKey());
        }
        try {
            String subject = null;
            String body = null;
            if (mailFormatter != null) {
                subject = mailFormatter.getSubject(infoMessage);
                body = mailFormatter.getBody(infoMessage);
            }
            if (!StringHelper.containsNonWhitespace(subject)) {
                subject = infoMessage.getTitle();
            }
            if (!StringHelper.containsNonWhitespace(body)) {
                body = infoMessage.getMessage();
            }
            File attachment = null;
            if (StringHelper.containsNonWhitespace(infoMessage.getAttachmentPath())) {
                File root = getStoragePath().getBasefile();
                attachment = new File(root, infoMessage.getAttachmentPath());
            }
            MailContext context = new MailContextImpl(mailFormatter.getBusinessPath());
            MailBundle bundle = new MailBundle();
            bundle.setContext(context);
            bundle.setFromId(from);
            bundle.setContactList(contactList);
            if (attachment != null) {
                bundle.setContent(subject, body, attachment);
            } else {
                bundle.setContent(subject, body);
            }
            MailerResult result = mailManager.sendMessage(bundle);
            send = result.isSuccessful();
        } catch (Exception e) {
            log.error("Cannot send info messages", e);
        }
    }
    infoSubscriptionManager.markPublisherNews(infoMessage.getOLATResourceable(), infoMessage.getResSubPath());
    MultiUserEvent mue = new MultiUserEvent("new_info_message");
    coordinatorManager.getCoordinator().getEventBus().fireEventToListenersOf(mue, oresFrontend);
    return send;
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) ContactList(org.olat.core.util.mail.ContactList) IOException(java.io.IOException) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle) File(java.io.File) MultiUserEvent(org.olat.core.util.event.MultiUserEvent) HashSet(java.util.HashSet)

Example 7 with MultiUserEvent

use of org.olat.core.util.event.MultiUserEvent in project OpenOLAT by OpenOLAT.

the class LanguageChooserController method formInnerEvent.

/**
 * @see org.olat.core.gui.components.form.flexible.FormDefaultController#formInnerEvent(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.components.form.flexible.FormItem,
 *      org.olat.core.gui.components.form.flexible.FormEvent)
 */
@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    Locale loc = I18nManager.getInstance().getLocaleOrDefault(getSelectedLanguage());
    MultiUserEvent mue = new LanguageChangedEvent(loc, ureq);
    ureq.getUserSession().setLocale(loc);
    ureq.getUserSession().putEntry("negotiated-locale", loc);
    I18nManager.updateLocaleInfoToThread(ureq.getUserSession());
    OLATResourceable wrappedLocale = OresHelper.createOLATResourceableType(Locale.class);
    ureq.getUserSession().getSingleUserEventCenter().fireEventToListenersOf(mue, wrappedLocale);
    // Update in velocity for flag
    flc.contextPut("languageCode", loc.toString());
}
Also used : Locale(java.util.Locale) OLATResourceable(org.olat.core.id.OLATResourceable) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

Example 8 with MultiUserEvent

use of org.olat.core.util.event.MultiUserEvent in project OpenOLAT by OpenOLAT.

the class EditorMainController method launchPublishingWizard.

private void launchPublishingWizard(UserRequest ureq, ICourse course, boolean requestOnClose) {
    // ignore enter
    if (publishStepsController != null)
        return;
    /*
		 * start follwoing steps -> cancel wizardf does not touch data
		 * (M) Mandatory (O) Optional
		 * - (M)Step 00  -> show selection tree to choose changed nodes to be published
		 * ...........-> calculate errors & warnings
		 * ...........(next|finish) available if no errors or nothing to publish
		 * - (O)Step 00A -> review errors & warnings
		 * ...........(previous|next|finish) available
		 * - (O)Step 00B -> review publish changes that will happen
		 * ...........(previous|next|finish) available
		 * - (O)Step 01  -> change general access to course
		 * ...........(previous|finish) available
		 * - FinishCallback -> apply course nodes change set
		 * .................-> apply general access changes.
		 */
    Step start = new PublishStep00(ureq, cetm, course);
    /*
		 * callback executed in case wizard is finished.
		 */
    StepRunnerCallback finish = new StepRunnerCallback() {

        @Override
        public Step execute(UserRequest ureq1, WindowControl wControl1, StepsRunContext runContext) {
            // all information to do now is within the runContext saved
            boolean hasChanges = false;
            PublishProcess publishManager = (PublishProcess) runContext.get("publishProcess");
            PublishEvents publishEvents = publishManager.getPublishEvents();
            if (runContext.containsKey("validPublish") && ((Boolean) runContext.get("validPublish")).booleanValue()) {
                @SuppressWarnings("unchecked") Collection<String> selectedNodeIds = (Collection<String>) runContext.get("publishSetCreatedFor");
                hasChanges = (selectedNodeIds != null) && (selectedNodeIds.size() > 0);
                if (hasChanges) {
                    publishManager.applyPublishSet(ureq1.getIdentity(), ureq1.getLocale(), false);
                }
            }
            if (runContext.containsKey("accessAndProperties")) {
                CourseAccessAndProperties accessAndProperties = (CourseAccessAndProperties) runContext.get("accessAndProperties");
                // fires an EntryChangedEvent for repository entry notifying
                // about modification.
                publishManager.changeAccessAndProperties(getIdentity(), accessAndProperties);
                hasChanges = true;
            }
            CourseCatalog courseCatalog = (CourseCatalog) runContext.get("categories");
            if (courseCatalog != null) {
                publishManager.publishToCatalog(courseCatalog.getChoiceValue(), courseCatalog.getCategoryLabels());
            }
            if (publishEvents.getPostPublishingEvents().size() > 0) {
                for (MultiUserEvent event : publishEvents.getPostPublishingEvents()) {
                    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(event, ores);
                }
            }
            // signal correct completion and tell if changes were made or not.
            return hasChanges ? StepsMainRunController.DONE_MODIFIED : StepsMainRunController.DONE_UNCHANGED;
        }
    };
    publishStepsController = new StepsMainRunController(ureq, getWindowControl(), start, finish, null, translate("publish.wizard.title"), "o_sel_course_publish_wizard");
    listenTo(publishStepsController);
    publishStepsController.getRunContext().put("requestOnClose", requestOnClose);
    getWindowControl().pushAsModalDialog(publishStepsController.getInitialComponent());
}
Also used : Step(org.olat.core.gui.control.generic.wizard.Step) CheckList_1_CheckboxStep(org.olat.course.nodes.cl.ui.wizard.CheckList_1_CheckboxStep) WindowControl(org.olat.core.gui.control.WindowControl) StepsRunContext(org.olat.core.gui.control.generic.wizard.StepsRunContext) Collection(java.util.Collection) StepsMainRunController(org.olat.core.gui.control.generic.wizard.StepsMainRunController) MultiUserEvent(org.olat.core.util.event.MultiUserEvent) StepRunnerCallback(org.olat.core.gui.control.generic.wizard.StepRunnerCallback) CheckListStepRunnerCallback(org.olat.course.nodes.cl.ui.wizard.CheckListStepRunnerCallback) UserRequest(org.olat.core.gui.UserRequest)

Example 9 with MultiUserEvent

use of org.olat.core.util.event.MultiUserEvent in project OpenOLAT by OpenOLAT.

the class QuickPublishController method doAutoPublish.

private boolean doAutoPublish() {
    ICourse course = CourseFactory.loadCourse(courseOres);
    CourseEditorTreeModel cetm = course.getEditorTreeModel();
    PublishProcess publishProcess = PublishProcess.getInstance(course, cetm, getLocale());
    PublishTreeModel publishTreeModel = publishProcess.getPublishTreeModel();
    if (publishTreeModel.hasPublishableChanges()) {
        List<String> nodeToPublish = new ArrayList<String>();
        visitPublishModel(publishTreeModel.getRootNode(), publishTreeModel, nodeToPublish);
        // only add selection if changes were possible
        for (Iterator<String> selectionIt = nodeToPublish.iterator(); selectionIt.hasNext(); ) {
            String ident = selectionIt.next();
            TreeNode node = publishProcess.getPublishTreeModel().getNodeById(ident);
            if (!publishTreeModel.isSelectable(node)) {
                selectionIt.remove();
            }
        }
        publishProcess.createPublishSetFor(nodeToPublish);
        PublishSetInformations set = publishProcess.testPublishSet(getLocale());
        StatusDescription[] status = set.getWarnings();
        // publish not possible when there are errors
        StringBuilder errMsg = new StringBuilder();
        for (int i = 0; i < status.length; i++) {
            if (status[i].isError()) {
                errMsg.append(status[i].getLongDescription(getLocale()));
                logError("Status error by publish: " + status[i].getLongDescription(getLocale()), null);
            }
        }
        if (errMsg.length() > 0) {
            getWindowControl().setWarning(errMsg.toString());
            return false;
        }
        PublishEvents publishEvents = publishProcess.getPublishEvents();
        try {
            publishProcess.applyPublishSet(getIdentity(), getLocale(), false);
        } catch (Exception e) {
            logError("", e);
        }
        if (publishEvents.getPostPublishingEvents().size() > 0) {
            for (MultiUserEvent event : publishEvents.getPostPublishingEvents()) {
                CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(event, courseOres);
            }
        }
    }
    return true;
}
Also used : CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) PublishTreeModel(org.olat.course.tree.PublishTreeModel) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) TreeNode(org.olat.core.gui.components.tree.TreeNode) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

Example 10 with MultiUserEvent

use of org.olat.core.util.event.MultiUserEvent in project OpenOLAT by OpenOLAT.

the class AuthoringEditAccessController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (source == propPupForm) {
        if (event == Event.DONE_EVENT) {
            // inform user about inconsistent configuration: doesn't make sense to set a repositoryEntry canReference=true if it is only accessible to owners
            if (!entry.getCanReference() && propPupForm.canReference() && (propPupForm.getAccess() < RepositoryEntry.ACC_OWNERS_AUTHORS && !propPupForm.isMembersOnly())) {
                showError("warn.config.reference.no.access");
            }
            int access = propPupForm.getAccess();
            int numOfBookingConfigs = acCtr.getNumOfBookingConfigurations();
            entry = repositoryManager.setAccessAndProperties(entry, access, propPupForm.isMembersOnly(), propPupForm.canCopy(), propPupForm.canReference(), propPupForm.canDownload());
            if (entry == null) {
                showWarning("repositoryentry.not.existing");
                fireEvent(ureq, Event.CLOSE_EVENT);
            } else {
                boolean managedBookings = RepositoryEntryManagedFlag.isManaged(entry, RepositoryEntryManagedFlag.bookings);
                if (access == RepositoryEntry.ACC_USERS || access == RepositoryEntry.ACC_USERS_GUESTS) {
                    if ((!managedBookings && acModule.isEnabled()) || numOfBookingConfigs > 0) {
                        editproptabpubVC.put("accesscontrol", acCtr.getInitialComponent());
                        editproptabpubVC.contextPut("isGuestAccess", Boolean.valueOf(access == RepositoryEntry.ACC_USERS_GUESTS));
                    }
                } else {
                    editproptabpubVC.remove(acCtr.getInitialComponent());
                }
                // inform anybody interested about this change
                MultiUserEvent modifiedEvent = new EntryChangedEvent(entry, getIdentity(), Change.modifiedAccess, "authoring");
                CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(modifiedEvent, entry);
                CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(modifiedEvent, RepositoryService.REPOSITORY_EVENT_ORES);
                fireEvent(ureq, Event.CHANGED_EVENT);
            }
        }
    } else if (source == leaveForm) {
        if (event == Event.DONE_EVENT) {
            RepositoryEntryAllowToLeaveOptions leaveSetting = leaveForm.getSelectedLeaveSetting();
            entry = repositoryManager.setLeaveSetting(entry, leaveSetting);
            if (entry == null) {
                showWarning("repositoryentry.not.existing");
                fireEvent(ureq, Event.CLOSE_EVENT);
            } else {
                MultiUserEvent modifiedEvent = new EntryChangedEvent(entry, getIdentity(), Change.modifiedAccess, "authorings");
                CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(modifiedEvent, entry);
                CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(modifiedEvent, RepositoryService.REPOSITORY_EVENT_ORES);
                fireEvent(ureq, Event.CHANGED_EVENT);
            }
        }
    } else if (acCtr == source) {
        if (event == Event.CHANGED_EVENT) {
            fireEvent(ureq, Event.CHANGED_EVENT);
        }
    }
}
Also used : EntryChangedEvent(org.olat.repository.controllers.EntryChangedEvent) RepositoryEntryAllowToLeaveOptions(org.olat.repository.RepositoryEntryAllowToLeaveOptions) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

Aggregations

MultiUserEvent (org.olat.core.util.event.MultiUserEvent)48 OLATResourceable (org.olat.core.id.OLATResourceable)16 EntryChangedEvent (org.olat.repository.controllers.EntryChangedEvent)10 ArrayList (java.util.ArrayList)8 File (java.io.File)6 Date (java.util.Date)6 HashSet (java.util.HashSet)6 Identity (org.olat.core.id.Identity)6 SyncerExecutor (org.olat.core.util.coordinate.SyncerExecutor)6 EventBus (org.olat.core.util.event.EventBus)6 List (java.util.List)4 Locale (java.util.Locale)4 Publisher (org.olat.core.commons.services.notifications.Publisher)4 Subscriber (org.olat.core.commons.services.notifications.Subscriber)4 ICourse (org.olat.course.ICourse)3 IOException (java.io.IOException)2 Collection (java.util.Collection)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 JMSException (javax.jms.JMSException)2 ObjectMessage (javax.jms.ObjectMessage)2