Search in sources :

Example 21 with MultiUserEvent

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

the class ProfileFormController method formOK.

@Override
protected void formOK(final UserRequest ureq) {
    User user = identityToModify.getUser();
    // update each user field
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        FormItem formItem = formItems.get(userPropertyHandler.getName());
        if (formItem.isEnabled()) {
            userPropertyHandler.updateUserFromFormItem(user, formItem);
        }
    }
    if (portraitDeleted) {
        File img = dps.getLargestPortrait(identityToModify.getName());
        if (img != null) {
            dps.deletePortrait(identityToModify);
            notifyPortraitChanged();
        }
    }
    File uploadedImage = portraitUpload.getUploadFile();
    String uploadedFilename = portraitUpload.getUploadFileName();
    if (uploadedImage != null) {
        dps.setPortrait(uploadedImage, uploadedFilename, identityToModify.getName());
        notifyPortraitChanged();
    }
    if (logoDeleted) {
        File img = dps.getLargestLogo(identityToModify.getName());
        if (img != null) {
            dps.deleteLogo(identityToModify);
            notifyPortraitChanged();
        }
    }
    if (logoUpload != null) {
        File uploadedLogo = logoUpload.getUploadFile();
        String uploadedLogoname = logoUpload.getUploadFileName();
        if (uploadedLogo != null) {
            dps.setLogo(uploadedLogo, uploadedLogoname, identityToModify.getName());
            notifyPortraitChanged();
        }
    }
    // Store the "about me" text.
    HomePageConfig conf = hpcm.loadConfigFor(identityToModify.getName());
    conf.setTextAboutMe(textAboutMe.getValue());
    hpcm.saveConfigTo(identityToModify.getName(), conf);
    // fire the appropriate event
    fireEvent(ureq, Event.DONE_EVENT);
    // update the user profile data
    CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(OresHelper.createOLATResourceableInstance(Identity.class, identityToModify.getKey()), new SyncerExecutor() {

        @Override
        public void execute() {
            UserManager um = UserManager.getInstance();
            identityToModify = (Identity) DBFactory.getInstance().loadObject(identityToModify);
            currentEmail = identityToModify.getUser().getProperty("email", null);
            identityToModify = updateIdentityFromFormData(identityToModify);
            changedEmail = identityToModify.getUser().getProperty("email", null);
            emailChanged = false;
            if ((currentEmail == null && StringHelper.containsNonWhitespace(changedEmail)) || (currentEmail != null && !currentEmail.equals(changedEmail))) {
                if (isAllowedToChangeEmailWithoutVerification(ureq) || !StringHelper.containsNonWhitespace(changedEmail)) {
                    String key = identityToModify.getUser().getProperty("emchangeKey", null);
                    TemporaryKey tempKey = rm.loadTemporaryKeyByRegistrationKey(key);
                    if (tempKey != null) {
                        rm.deleteTemporaryKey(tempKey);
                    }
                    securityManager.deleteInvalidAuthenticationsByEmail(currentEmail);
                } else {
                    emailChanged = true;
                    // change email address to old address until it is verified
                    identityToModify.getUser().setProperty("email", currentEmail);
                }
            }
            if (!um.updateUserFromIdentity(identityToModify)) {
                getWindowControl().setInfo(translate("profile.unsuccessful"));
                // reload user data from db
                identityToModify = BaseSecurityManager.getInstance().loadIdentityByKey(identityToModify.getKey());
            }
            OLATResourceable modRes = OresHelper.createOLATResourceableInstance(Identity.class, identityToModify.getKey());
            CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new MultiUserEvent("changed"), modRes);
            if (!emailChanged) {
                fireEvent(ureq, Event.FAILED_EVENT);
            }
        }
    });
    if (emailChanged) {
        removeAsListenerAndDispose(dialogCtr);
        String dialogText = "";
        if (identityToModify.equals(ureq.getIdentity())) {
            dialogText = translate("email.change.dialog.text");
        } else {
            dialogText = translate("email.change.dialog.text.usermanager");
        }
        dialogCtr = DialogBoxUIFactory.createYesNoDialog(ureq, getWindowControl(), translate("email.change.dialog.title"), dialogText);
        listenTo(dialogCtr);
        dialogCtr.activate();
    }
}
Also used : User(org.olat.core.id.User) OLATResourceable(org.olat.core.id.OLATResourceable) FormItem(org.olat.core.gui.components.form.flexible.FormItem) TemporaryKey(org.olat.registration.TemporaryKey) SyncerExecutor(org.olat.core.util.coordinate.SyncerExecutor) Identity(org.olat.core.id.Identity) File(java.io.File) MultiUserEvent(org.olat.core.util.event.MultiUserEvent) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 22 with MultiUserEvent

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

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)

Example 23 with MultiUserEvent

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

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 24 with MultiUserEvent

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

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 25 with MultiUserEvent

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

the class CourseRuntimeController method setGlossaryLinkTitle.

private void setGlossaryLinkTitle(UserRequest ureq, Boolean state) {
    if (enableGlossaryLink == null)
        return;
    String oresName = ICourse.class.getSimpleName();
    Long courseID = getOlatResourceable().getResourceableId();
    // must work with SP and CP nodes, IFrameDisplayController listens to this event and expects "ICourse" resources.
    OLATResourceable ores = OresHelper.createOLATResourceableInstance(oresName, courseID);
    if (state == null || !state.booleanValue()) {
        enableGlossaryLink.setCustomDisplayText(translate("command.glossary.on.alt"));
        setTextMarkingEnabled(false);
        ureq.getUserSession().getSingleUserEventCenter().fireEventToListenersOf(new MultiUserEvent("glossaryOff"), ores);
    } else {
        enableGlossaryLink.setCustomDisplayText(translate("command.glossary.off.alt"));
        setTextMarkingEnabled(true);
        ureq.getUserSession().getSingleUserEventCenter().fireEventToListenersOf(new MultiUserEvent("glossaryOn"), ores);
    }
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) 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