Search in sources :

Example 21 with StepRunnerCallback

use of org.olat.core.gui.control.generic.wizard.StepRunnerCallback in project OpenOLAT by OpenOLAT.

the class UserImportController method doOpenImportWizard.

private void doOpenImportWizard(UserRequest ureq) {
    // use fallback translator for user property translation
    setTranslator(um.getPropertyHandlerTranslator(getTranslator()));
    userPropertyHandlers = um.getUserPropertyHandlersFor(usageIdentifyer, true);
    Step start = new ImportStep00(ureq, canCreateOLATPassword);
    // 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
            ImportReport report = new ImportReport();
            runContext.put("report", report);
            try {
                if (runContext.containsKey("validImport") && ((Boolean) runContext.get("validImport")).booleanValue()) {
                    // create new users and persist
                    int count = 0;
                    @SuppressWarnings("unchecked") List<TransientIdentity> newIdents = (List<TransientIdentity>) runContext.get("newIdents");
                    Map<TransientIdentity, Identity> newPersistedIdentities = new HashMap<>();
                    for (TransientIdentity newIdent : newIdents) {
                        Identity newIdentity = doCreateAndPersistIdentity(newIdent, report);
                        if (newIdentity != null) {
                            newPersistedIdentities.put(newIdent, newIdentity);
                        }
                        if (++count % 10 == 0) {
                            dbInstance.commitAndCloseSession();
                        }
                    }
                    dbInstance.commitAndCloseSession();
                    Boolean updateUsers = (Boolean) runContext.get("updateUsers");
                    Boolean updatePasswords = (Boolean) runContext.get("updatePasswords");
                    @SuppressWarnings("unchecked") List<UpdateIdentity> updateIdents = (List<UpdateIdentity>) runContext.get("updateIdents");
                    for (UpdateIdentity updateIdent : updateIdents) {
                        doUpdateIdentity(updateIdent, updateUsers, updatePasswords, report);
                        if (++count % 10 == 0) {
                            dbInstance.commitAndCloseSession();
                        }
                    }
                    dbInstance.commitAndCloseSession();
                    @SuppressWarnings("unchecked") List<Long> ownGroups = (List<Long>) runContext.get("ownerGroups");
                    @SuppressWarnings("unchecked") List<Long> partGroups = (List<Long>) runContext.get("partGroups");
                    if ((ownGroups != null && ownGroups.size() > 0) || (partGroups != null && partGroups.size() > 0)) {
                        @SuppressWarnings("unchecked") List<Identity> allIdents = (List<Identity>) runContext.get("idents");
                        Boolean sendMailObj = (Boolean) runContext.get("sendMail");
                        boolean sendmail = sendMailObj == null ? true : sendMailObj.booleanValue();
                        processGroupAdditionForAllIdents(allIdents, ownGroups, partGroups, sendmail);
                    } else {
                        Boolean sendMailObj = (Boolean) runContext.get("sendMail");
                        if (sendMailObj != null && sendMailObj) {
                            sendMailToNewIdentities(newPersistedIdentities);
                        }
                    }
                    report.setHasChanges(true);
                }
            } catch (Exception any) {
                logError("", any);
                report.addError("Unexpected error, see log files or call your system administrator");
            }
            // signal correct completion and tell if changes were made or not.
            return report.isHasChanges() ? StepsMainRunController.DONE_MODIFIED : StepsMainRunController.DONE_UNCHANGED;
        }
    };
    importStepsController = new StepsMainRunController(ureq, getWindowControl(), start, finish, null, translate("title"), "o_sel_user_import_wizard");
    listenTo(importStepsController);
    getWindowControl().pushAsModalDialog(importStepsController.getInitialComponent());
}
Also used : HashMap(java.util.HashMap) Step(org.olat.core.gui.control.generic.wizard.Step) WindowControl(org.olat.core.gui.control.WindowControl) StepsRunContext(org.olat.core.gui.control.generic.wizard.StepsRunContext) List(java.util.List) ArrayList(java.util.ArrayList) StepsMainRunController(org.olat.core.gui.control.generic.wizard.StepsMainRunController) Identity(org.olat.core.id.Identity) StepRunnerCallback(org.olat.core.gui.control.generic.wizard.StepRunnerCallback) UserRequest(org.olat.core.gui.UserRequest)

Example 22 with StepRunnerCallback

use of org.olat.core.gui.control.generic.wizard.StepRunnerCallback in project OpenOLAT by OpenOLAT.

the class UsermanagerUserSearchForm method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
 */
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == searchform) {
        if (event == Event.DONE_EVENT) {
            // form validation was ok
            identitiesList = findIdentitiesFromSearchForm();
            initUserListCtr(ureq, identitiesList, null);
            userListVC.put("userlist", tableCtr.getInitialComponent());
            userListVC.contextPut("emptyList", (identitiesList.size() == 0 ? Boolean.TRUE : Boolean.FALSE));
            panel.setContent(userListVC);
            // fxdiff BAKS-7 Resume function
            ContextEntry currentEntry = getWindowControl().getBusinessControl().getCurrentContextEntry();
            if (currentEntry != null) {
                currentEntry.setTransientState(searchform.getStateEntry());
            }
            addToHistory(ureq, tableCtr);
        } else if (event == Event.CANCELLED_EVENT) {
            fireEvent(ureq, Event.CANCELLED_EVENT);
        }
    } else if (source == tableCtr) {
        if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
            TableEvent te = (TableEvent) event;
            String actionid = te.getActionId();
            if (actionid.equals(ExtendedIdentitiesTableDataModel.COMMAND_SELECTUSER)) {
                int rowid = te.getRowId();
                Identity foundIdentity = tdm.getObject(rowid);
                // Tell parentController that a subject has been found
                fireEvent(ureq, new SingleIdentityChosenEvent(foundIdentity));
            } else if (actionid.equals(ExtendedIdentitiesTableDataModel.COMMAND_VCARD)) {
                // get identity and open new visiting card controller in new window
                int rowid = te.getRowId();
                final Identity identity = tdm.getObject(rowid);
                ControllerCreator userInfoMainControllerCreator = new ControllerCreator() {

                    @Override
                    public Controller createController(UserRequest lureq, WindowControl lwControl) {
                        return new UserInfoMainController(lureq, lwControl, identity, true, false);
                    }
                };
                // wrap the content controller into a full header layout
                ControllerCreator layoutCtrlr = BaseFullWebappPopupLayoutFactory.createAuthMinimalPopupLayout(ureq, userInfoMainControllerCreator);
                // open in new browser window
                PopupBrowserWindow pbw = getWindowControl().getWindowBackOffice().getWindowManager().createNewPopupBrowserWindowFor(ureq, layoutCtrlr);
                pbw.open(ureq);
            }
        }
        if (event instanceof TableMultiSelectEvent) {
            // Multiselect events
            TableMultiSelectEvent tmse = (TableMultiSelectEvent) event;
            if (tmse.getAction().equals(CMD_BULKEDIT)) {
                if (tmse.getSelection().isEmpty()) {
                    // empty selection
                    showWarning("msg.selectionempty");
                    return;
                }
                selectedIdentities = tdm.getIdentities(tmse.getSelection());
                // valid selection: load in wizard
                Step start = new UserBulkChangeStep00(ureq, selectedIdentities);
                // callback executed in case wizard is finished.
                StepRunnerCallback finish = new StepRunnerCallback() {

                    public Step execute(UserRequest ureq1, WindowControl wControl1, StepsRunContext runContext) {
                        // all information to do now is within the runContext saved
                        boolean hasChanges = false;
                        try {
                            if (runContext.containsKey("validChange") && ((Boolean) runContext.get("validChange")).booleanValue()) {
                                HashMap<String, String> attributeChangeMap = (HashMap<String, String>) runContext.get("attributeChangeMap");
                                HashMap<String, String> roleChangeMap = (HashMap<String, String>) runContext.get("roleChangeMap");
                                List<Long> ownGroups = (List<Long>) runContext.get("ownerGroups");
                                List<Long> partGroups = (List<Long>) runContext.get("partGroups");
                                // List<Long> mailGroups = (List<Long>) runContext.get("mailGroups");
                                if (attributeChangeMap.size() != 0 || roleChangeMap.size() != 0 || ownGroups.size() != 0 || partGroups.size() != 0) {
                                    Identity addingIdentity = ureq1.getIdentity();
                                    ubcMan.changeSelectedIdentities(selectedIdentities, attributeChangeMap, roleChangeMap, notUpdatedIdentities, isAdministrativeUser, ownGroups, partGroups, getTranslator(), addingIdentity);
                                    hasChanges = true;
                                }
                            }
                        } catch (Exception any) {
                        // return new ErrorStep
                        }
                        // signal correct completion and tell if changes were made or not.
                        return hasChanges ? StepsMainRunController.DONE_MODIFIED : StepsMainRunController.DONE_UNCHANGED;
                    }
                };
                removeAsListenerAndDispose(userBulkChangeStepsController);
                userBulkChangeStepsController = new StepsMainRunController(ureq, getWindowControl(), start, finish, null, translate("bulkChange.title"), "o_sel_user_bulk_change_wizard");
                listenTo(userBulkChangeStepsController);
                getWindowControl().pushAsModalDialog(userBulkChangeStepsController.getInitialComponent());
            } else if (tmse.getAction().equals(CMD_MAIL)) {
                if (tmse.getSelection().isEmpty()) {
                    // empty selection
                    showWarning("msg.selectionempty");
                    return;
                }
                // create e-mail message
                ContactMessage cmsg = new ContactMessage(ureq.getIdentity());
                selectedIdentities = tdm.getIdentities(tmse.getSelection());
                ContactList contacts = new ContactList(translate("mailto.userlist"));
                contacts.addAllIdentites(selectedIdentities);
                cmsg.addEmailTo(contacts);
                // create contact form controller with ContactMessage
                removeAsListenerAndDispose(contactCtr);
                contactCtr = new ContactFormController(ureq, getWindowControl(), true, false, false, cmsg);
                listenTo(contactCtr);
                mailVC.put("mailform", contactCtr.getInitialComponent());
                panel.setContent(mailVC);
            }
        }
    } else if (source == contactCtr) {
        // in any case go back to list (events: done, failed or cancel)
        panel.setContent(userListVC);
    } else if (source == userBulkChangeStepsController) {
        if (event == Event.CANCELLED_EVENT) {
            getWindowControl().pop();
        } else if (event == Event.CHANGED_EVENT) {
            getWindowControl().pop();
            Integer selIdentCount = selectedIdentities.size();
            if (notUpdatedIdentities.size() > 0) {
                Integer notUpdatedIdentCount = notUpdatedIdentities.size();
                Integer sucChanges = selIdentCount - notUpdatedIdentCount;
                String changeErrors = "";
                for (String err : notUpdatedIdentities) {
                    changeErrors += err + "<br />";
                }
                getWindowControl().setError(translate("bulkChange.partialsuccess", new String[] { sucChanges.toString(), selIdentCount.toString(), changeErrors }));
            } else {
                showInfo("bulkChange.success");
            }
            // update table model - has changed
            reloadDataModel(ureq);
        } else if (event == Event.DONE_EVENT) {
            showError("bulkChange.failed");
        }
    }
}
Also used : HashMap(java.util.HashMap) TableMultiSelectEvent(org.olat.core.gui.components.table.TableMultiSelectEvent) Step(org.olat.core.gui.control.generic.wizard.Step) WindowControl(org.olat.core.gui.control.WindowControl) StepsRunContext(org.olat.core.gui.control.generic.wizard.StepsRunContext) ContextEntry(org.olat.core.id.context.ContextEntry) ControllerCreator(org.olat.core.gui.control.creator.ControllerCreator) PopupBrowserWindow(org.olat.core.gui.control.generic.popup.PopupBrowserWindow) ContactFormController(org.olat.modules.co.ContactFormController) ContactList(org.olat.core.util.mail.ContactList) List(java.util.List) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) UserRequest(org.olat.core.gui.UserRequest) ContactList(org.olat.core.util.mail.ContactList) UserBulkChangeStep00(org.olat.admin.user.bulkChange.UserBulkChangeStep00) ContactMessage(org.olat.core.util.mail.ContactMessage) TableEvent(org.olat.core.gui.components.table.TableEvent) UserInfoMainController(org.olat.user.UserInfoMainController) SingleIdentityChosenEvent(org.olat.basesecurity.events.SingleIdentityChosenEvent) StepsMainRunController(org.olat.core.gui.control.generic.wizard.StepsMainRunController) StepRunnerCallback(org.olat.core.gui.control.generic.wizard.StepRunnerCallback)

Example 23 with StepRunnerCallback

use of org.olat.core.gui.control.generic.wizard.StepRunnerCallback in project openolat by klemens.

the class GroupController method doImportUsers.

private void doImportUsers(UserRequest ureq) {
    removeAsListenerAndDispose(userToGroupWizard);
    Step start = new UsersToGroupWizardStep00(ureq, addUserMailDefaultTempl, mandatoryEmail);
    StepRunnerCallback finish = new StepRunnerCallback() {

        @Override
        public Step execute(UserRequest ureq, WindowControl wControl, StepsRunContext runContext) {
            @SuppressWarnings("unchecked") List<Identity> choosenIdentities = (List<Identity>) runContext.get("members");
            MailTemplate customTemplate = (MailTemplate) runContext.get("mailTemplate");
            if (choosenIdentities == null || choosenIdentities.size() == 0) {
                showError("msg.selectionempty");
            } else {
                doAddIdentitiesToGroup(ureq, choosenIdentities, customTemplate);
            }
            return StepsMainRunController.DONE_MODIFIED;
        }
    };
    userToGroupWizard = new StepsMainRunController(ureq, getWindowControl(), start, finish, null, translate("overview.addusers"), "o_sel_secgroup_import_logins_wizard");
    listenTo(userToGroupWizard);
    getWindowControl().pushAsModalDialog(userToGroupWizard.getInitialComponent());
}
Also used : UsersToGroupWizardStep00(org.olat.admin.securitygroup.gui.multi.UsersToGroupWizardStep00) MailTemplate(org.olat.core.util.mail.MailTemplate) List(java.util.List) ArrayList(java.util.ArrayList) StepsMainRunController(org.olat.core.gui.control.generic.wizard.StepsMainRunController) Step(org.olat.core.gui.control.generic.wizard.Step) WindowControl(org.olat.core.gui.control.WindowControl) StepsRunContext(org.olat.core.gui.control.generic.wizard.StepsRunContext) Identity(org.olat.core.id.Identity) StepRunnerCallback(org.olat.core.gui.control.generic.wizard.StepRunnerCallback) UserRequest(org.olat.core.gui.UserRequest)

Example 24 with StepRunnerCallback

use of org.olat.core.gui.control.generic.wizard.StepRunnerCallback in project openolat by klemens.

the class QuestionListController method doOpenExcelImportQTI12.

private void doOpenExcelImportQTI12(UserRequest ureq) {
    removeAsListenerAndDispose(excelImportWizard);
    final ItemsPackage importPackage = new ItemsPackage();
    Step additionalStep = null;
    if (getSource().askEditable()) {
        additionalStep = new EditableStep(ureq);
    }
    final org.olat.ims.qti.questionimport.ImportOptions options = new org.olat.ims.qti.questionimport.ImportOptions();
    options.setShuffle(true);
    Step start = new org.olat.ims.qti.questionimport.QImport_1_InputStep(ureq, importPackage, options, additionalStep);
    StepRunnerCallback finish = new StepRunnerCallback() {

        @Override
        public Step execute(UserRequest uureq, WindowControl wControl, StepsRunContext runContext) {
            List<ItemAndMetadata> itemsToImport = importPackage.getItems();
            QTIQPoolServiceProvider spi = CoreSpringFactory.getImpl(QTIQPoolServiceProvider.class);
            List<QuestionItem> importItems = spi.importBeecomItem(getIdentity(), itemsToImport, getLocale());
            for (QuestionItem item : importItems) {
                QuestionItemAuditLogBuilder builder = qpoolService.createAuditLogBuilder(getIdentity(), Action.CREATE_QUESTION_ITEM_BY_IMPORT);
                builder.withAfter(item);
                qpoolService.persist(builder.create());
            }
            boolean editable = true;
            if (getSource().askEditable()) {
                Object editableCtx = runContext.get("editable");
                editable = (editableCtx instanceof Boolean) ? ((Boolean) editableCtx).booleanValue() : false;
            }
            qpoolService.index(importItems);
            int postImported = getSource().postImport(importItems, editable);
            if (postImported > 0) {
                getItemsTable().reset();
            }
            return StepsMainRunController.DONE_MODIFIED;
        }
    };
    excelImportWizard = new StepsMainRunController(ureq, getWindowControl(), start, finish, null, translate("import.excellike.12"), "o_sel_qpool_excel_import_wizard");
    listenTo(excelImportWizard);
    getWindowControl().pushAsModalDialog(excelImportWizard.getInitialComponent());
}
Also used : QImport_1_InputStep(org.olat.ims.qti21.questionimport.QImport_1_InputStep) Step(org.olat.core.gui.control.generic.wizard.Step) Export_1_TypeStep(org.olat.modules.qpool.ui.wizard.Export_1_TypeStep) ImportAuthor_1_ChooseMemberStep(org.olat.modules.qpool.ui.wizard.ImportAuthor_1_ChooseMemberStep) WindowControl(org.olat.core.gui.control.WindowControl) StepsRunContext(org.olat.core.gui.control.generic.wizard.StepsRunContext) QImport_1_InputStep(org.olat.ims.qti21.questionimport.QImport_1_InputStep) QTIQPoolServiceProvider(org.olat.ims.qti.qpool.QTIQPoolServiceProvider) UserRequest(org.olat.core.gui.UserRequest) AssessmentItemsPackage(org.olat.ims.qti21.questionimport.AssessmentItemsPackage) ItemsPackage(org.olat.ims.qti.questionimport.ItemsPackage) QuestionItemAuditLogBuilder(org.olat.modules.qpool.QuestionItemAuditLogBuilder) StepsMainRunController(org.olat.core.gui.control.generic.wizard.StepsMainRunController) AssessmentItemAndMetadata(org.olat.ims.qti21.questionimport.AssessmentItemAndMetadata) ItemAndMetadata(org.olat.ims.qti.questionimport.ItemAndMetadata) QuestionItem(org.olat.modules.qpool.QuestionItem) ImportOptions(org.olat.ims.qti21.questionimport.ImportOptions) StepRunnerCallback(org.olat.core.gui.control.generic.wizard.StepRunnerCallback)

Example 25 with StepRunnerCallback

use of org.olat.core.gui.control.generic.wizard.StepRunnerCallback in project openolat by klemens.

the class QuestionListController method doOpenExcelImportQTI21.

private void doOpenExcelImportQTI21(UserRequest ureq) {
    removeAsListenerAndDispose(excelImportWizard);
    Step additionalStep = null;
    if (getSource().askEditable()) {
        additionalStep = new EditableStep(ureq);
    }
    final AssessmentItemsPackage importPackage = new AssessmentItemsPackage();
    final ImportOptions options = new ImportOptions();
    options.setShuffle(true);
    Step start = new QImport_1_InputStep(ureq, importPackage, options, additionalStep);
    StepRunnerCallback finish = new StepRunnerCallback() {

        @Override
        public Step execute(UserRequest uureq, WindowControl wControl, StepsRunContext runContext) {
            QTI21QPoolServiceProvider spi = CoreSpringFactory.getImpl(QTI21QPoolServiceProvider.class);
            List<AssessmentItemAndMetadata> items = importPackage.getItems();
            List<QuestionItem> importItems = new ArrayList<>();
            for (AssessmentItemAndMetadata item : items) {
                QuestionItem importedItem = spi.importExcelItem(getIdentity(), item, getLocale());
                if (importedItem != null) {
                    importItems.add(importedItem);
                }
            }
            for (QuestionItem item : importItems) {
                QuestionItemAuditLogBuilder builder = qpoolService.createAuditLogBuilder(getIdentity(), Action.CREATE_QUESTION_ITEM_BY_IMPORT);
                builder.withAfter(item);
                qpoolService.persist(builder.create());
            }
            boolean editable = true;
            if (getSource().askEditable()) {
                Object editableCtx = runContext.get("editable");
                editable = (editableCtx instanceof Boolean) ? ((Boolean) editableCtx).booleanValue() : false;
            }
            qpoolService.index(importItems);
            int postImported = getSource().postImport(importItems, editable);
            if (postImported > 0) {
                getItemsTable().reset();
            }
            return StepsMainRunController.DONE_MODIFIED;
        }
    };
    excelImportWizard = new StepsMainRunController(ureq, getWindowControl(), start, finish, null, translate("import.excellike.21"), "o_sel_qpool_excel_import_wizard");
    listenTo(excelImportWizard);
    getWindowControl().pushAsModalDialog(excelImportWizard.getInitialComponent());
}
Also used : ArrayList(java.util.ArrayList) QImport_1_InputStep(org.olat.ims.qti21.questionimport.QImport_1_InputStep) Step(org.olat.core.gui.control.generic.wizard.Step) Export_1_TypeStep(org.olat.modules.qpool.ui.wizard.Export_1_TypeStep) ImportAuthor_1_ChooseMemberStep(org.olat.modules.qpool.ui.wizard.ImportAuthor_1_ChooseMemberStep) WindowControl(org.olat.core.gui.control.WindowControl) StepsRunContext(org.olat.core.gui.control.generic.wizard.StepsRunContext) QImport_1_InputStep(org.olat.ims.qti21.questionimport.QImport_1_InputStep) QuestionItemAuditLogBuilder(org.olat.modules.qpool.QuestionItemAuditLogBuilder) QTI21QPoolServiceProvider(org.olat.ims.qti21.pool.QTI21QPoolServiceProvider) AssessmentItemAndMetadata(org.olat.ims.qti21.questionimport.AssessmentItemAndMetadata) AssessmentItemsPackage(org.olat.ims.qti21.questionimport.AssessmentItemsPackage) StepsMainRunController(org.olat.core.gui.control.generic.wizard.StepsMainRunController) QuestionItem(org.olat.modules.qpool.QuestionItem) ImportOptions(org.olat.ims.qti21.questionimport.ImportOptions) StepRunnerCallback(org.olat.core.gui.control.generic.wizard.StepRunnerCallback) UserRequest(org.olat.core.gui.UserRequest)

Aggregations

Step (org.olat.core.gui.control.generic.wizard.Step)70 StepRunnerCallback (org.olat.core.gui.control.generic.wizard.StepRunnerCallback)70 StepsMainRunController (org.olat.core.gui.control.generic.wizard.StepsMainRunController)70 StepsRunContext (org.olat.core.gui.control.generic.wizard.StepsRunContext)58 UserRequest (org.olat.core.gui.UserRequest)56 WindowControl (org.olat.core.gui.control.WindowControl)56 ArrayList (java.util.ArrayList)14 Date (java.util.Date)12 List (java.util.List)12 ImportMember_1a_LoginListStep (org.olat.course.member.wizard.ImportMember_1a_LoginListStep)12 ImportMember_1b_ChooseMemberStep (org.olat.course.member.wizard.ImportMember_1b_ChooseMemberStep)12 Identity (org.olat.core.id.Identity)10 QImport_1_InputStep (org.olat.ims.qti21.questionimport.QImport_1_InputStep)10 BusinessGroup (org.olat.group.BusinessGroup)8 BGConfigBusinessGroup (org.olat.group.ui.wizard.BGConfigBusinessGroup)8 BGConfigToolsStep (org.olat.group.ui.wizard.BGConfigToolsStep)8 BGCopyBusinessGroup (org.olat.group.ui.wizard.BGCopyBusinessGroup)8 BGCopyPreparationStep (org.olat.group.ui.wizard.BGCopyPreparationStep)8 BGEmailSelectReceiversStep (org.olat.group.ui.wizard.BGEmailSelectReceiversStep)8 BGMergeStep (org.olat.group.ui.wizard.BGMergeStep)8