Search in sources :

Example 16 with BusinessControlFactory

use of org.olat.core.id.context.BusinessControlFactory in project openolat by klemens.

the class EPShareListController method sendInvitation.

/**
 * sends a link to the map to permitted users by email
 *
 * @param ureq
 * @param wrapper
 */
private void sendInvitation(UserRequest ureq, EPSharePolicyWrapper wrapper) {
    EPMapPolicy.Type shareType = wrapper.getType();
    List<Identity> identitiesToMail = new ArrayList<Identity>();
    Invitation invitation = null;
    if (shareType.equals(EPMapPolicy.Type.allusers)) {
        return;
    } else if (shareType.equals(EPMapPolicy.Type.invitation)) {
        invitation = wrapper.getInvitation();
    } else if (shareType.equals(EPMapPolicy.Type.group)) {
        List<BusinessGroup> groups = wrapper.getGroups();
        List<Identity> members = businessGroupService.getMembers(groups, GroupRoles.coach.name(), GroupRoles.participant.name());
        identitiesToMail.addAll(members);
    } else if (shareType.equals(EPMapPolicy.Type.user)) {
        identitiesToMail = wrapper.getIdentities();
    }
    wrapper.setInvitationSend(true);
    ContactList contactList = null;
    if (identitiesToMail.size() == 1) {
        contactList = new ContactList(identitiesToMail.get(0).getUser().getProperty(UserConstants.EMAIL, ureq.getLocale()));
    } else {
        contactList = new ContactList(translate("map.share.invitation.mail.list"));
    }
    contactList.addAllIdentites(identitiesToMail);
    String busLink = "";
    if (invitation != null) {
        contactList.add(invitation.getMail());
        busLink = getInvitationLink(invitation, map);
    } else {
        BusinessControlFactory bCF = BusinessControlFactory.getInstance();
        ContextEntry mapCE = bCF.createContextEntry(map.getOlatResource());
        ArrayList<ContextEntry> cEList = new ArrayList<ContextEntry>();
        cEList.add(mapCE);
        busLink = bCF.getAsURIString(cEList, true);
    }
    boolean success = false;
    try {
        String first = getIdentity().getUser().getProperty(UserConstants.FIRSTNAME, null);
        String last = getIdentity().getUser().getProperty(UserConstants.LASTNAME, null);
        String sender = first + " " + last;
        String[] bodyArgs = new String[] { busLink, sender };
        MailContext context = new MailContextImpl(map.getOlatResource(), null, getWindowControl().getBusinessControl().getAsString());
        MailBundle bundle = new MailBundle();
        bundle.setContext(context);
        bundle.setFrom(WebappHelper.getMailConfig("mailReplyTo"));
        bundle.setContactList(contactList);
        bundle.setContent(translate("map.share.invitation.mail.subject"), translate("map.share.invitation.mail.body", bodyArgs));
        MailerResult result = mailManager.sendMessage(bundle);
        success = result.isSuccessful();
    } catch (Exception e) {
        logError("Error on sending invitation mail to contactlist, invalid address.", e);
    }
    if (success) {
        showInfo("map.share.invitation.mail.success");
    } else {
        showError("map.share.invitation.mail.failure");
    }
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) BusinessGroup(org.olat.group.BusinessGroup) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) EPMapPolicy(org.olat.portfolio.manager.EPMapPolicy) ArrayList(java.util.ArrayList) Invitation(org.olat.basesecurity.Invitation) ContactList(org.olat.core.util.mail.ContactList) ContextEntry(org.olat.core.id.context.ContextEntry) Type(org.olat.portfolio.manager.EPMapPolicy.Type) BusinessControlFactory(org.olat.core.id.context.BusinessControlFactory) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle)

Example 17 with BusinessControlFactory

use of org.olat.core.id.context.BusinessControlFactory in project openolat by klemens.

the class EPCollectStepForm00 method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    title = uifactory.addTextElement("title", "artefact.title", 500, artefact.getTitle(), formLayout);
    title.setElementCssClass("o_sel_ep_artefact_metadata_title");
    title.setMandatory(true);
    title.setNotEmptyCheck("artefact.title.not.empty");
    title.setNotLongerThanCheck(512, "artefact.title.too.long");
    title.setVisible(!simpleMode);
    descript = uifactory.addRichTextElementForStringDataMinimalistic("description", "artefact.description", artefact.getDescription(), 7, -1, formLayout, getWindowControl());
    descript.setMaxLength(4000);
    descript.setNotLongerThanCheck(4000, "artefact.description.too.long");
    String artSource = artefact.getSource();
    if (StringHelper.containsNonWhitespace(artSource) && !simpleMode) {
        uifactory.addStaticTextElement("artefact.source", artSource, formLayout);
    }
    Date artDate = artefact.getCreationDate();
    if (artDate == null)
        artDate = new Date();
    StaticTextElement date = uifactory.addStaticTextElement("artefact.date", Formatter.getInstance(getLocale()).formatDateAndTime(artDate), formLayout);
    date.setVisible(!simpleMode);
    String busPath = artefact.getBusinessPath();
    if (StringHelper.containsNonWhitespace(busPath) && !simpleMode) {
        BusinessControlFactory bCF = BusinessControlFactory.getInstance();
        List<ContextEntry> ceList = bCF.createCEListFromString(busPath);
        String busLink = bCF.getAsURIString(ceList, true);
        if (StringHelper.containsNonWhitespace(busLink)) {
            String finalPath = "<a href=\"" + busLink + "\">" + busLink + "</a>";
            uifactory.addStaticTextElement("artefact.link", finalPath, formLayout);
        }
    }
    if (!isUsedInStepWizzard()) {
        // add form buttons
        uifactory.addFormSubmitButton("stepform.submit", formLayout);
    }
}
Also used : StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) BusinessControlFactory(org.olat.core.id.context.BusinessControlFactory) Date(java.util.Date) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 18 with BusinessControlFactory

use of org.olat.core.id.context.BusinessControlFactory in project openolat by klemens.

the class ForumNodeForumCallback method createNodeRunConstructionResult.

/**
 * @see org.olat.course.nodes.CourseNode#createNodeRunConstructionResult(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.control.WindowControl,
 *      org.olat.course.run.userview.UserCourseEnvironment,
 *      org.olat.course.run.userview.NodeEvaluation)
 */
@Override
public NodeRunConstructionResult createNodeRunConstructionResult(UserRequest ureq, WindowControl wControl, final UserCourseEnvironment userCourseEnv, NodeEvaluation ne, String nodecmd) {
    updateModuleConfigDefaults(false);
    Roles roles = ureq.getUserSession().getRoles();
    Forum theForum = loadOrCreateForum(userCourseEnv.getCourseEnvironment());
    boolean isOlatAdmin = roles.isOLATAdmin();
    boolean isGuestOnly = roles.isGuestOnly();
    // Add message id to business path if nodemcd is available
    if (nodecmd != null) {
        try {
            Long messageId = Long.valueOf(nodecmd);
            BusinessControlFactory bcf = BusinessControlFactory.getInstance();
            BusinessControl businessControl = bcf.createFromString("[Message:" + messageId + "]");
            wControl = bcf.createBusinessWindowControl(businessControl, wControl);
        } catch (NumberFormatException e) {
            // ups, nodecmd is not a message, what the heck is it then?
            log.warn("Could not create message ID from given nodemcd::" + nodecmd, e);
        }
    }
    // for guests, check if posting is allowed
    boolean pseudonymPostAllowed = false;
    boolean defaultPseudonym = false;
    boolean guestPostAllowed = false;
    if (roles.isGuestOnly()) {
        String config = getModuleConfiguration().getStringValue(FOCourseNodeEditController.GUEST_POST_ALLOWED);
        guestPostAllowed = "true".equals(config);
    } else {
        ForumModule forumModule = CoreSpringFactory.getImpl(ForumModule.class);
        String config = getModuleConfiguration().getStringValue(FOCourseNodeEditController.PSEUDONYM_POST_ALLOWED);
        pseudonymPostAllowed = forumModule.isAnonymousPostingWithPseudonymEnabled() && "true".equals(config);
        if (pseudonymPostAllowed) {
            defaultPseudonym = getModuleConfiguration().getBooleanSafe(FOCourseNodeEditController.PSEUDONYM_POST_DEFAULT, forumModule.isPseudonymForMessageEnabledByDefault());
        }
    }
    // Create subscription context and run controller
    SubscriptionContext forumSubContext = CourseModule.createSubscriptionContext(userCourseEnv.getCourseEnvironment(), this);
    ForumCallback foCallback = userCourseEnv.isCourseReadOnly() ? new ReadOnlyForumCallback(ne, isOlatAdmin, isGuestOnly) : new ForumNodeForumCallback(ne, isOlatAdmin, isGuestOnly, guestPostAllowed, pseudonymPostAllowed, defaultPseudonym, forumSubContext);
    FOCourseNodeRunController forumC = new FOCourseNodeRunController(ureq, wControl, theForum, foCallback, this);
    return new NodeRunConstructionResult(forumC);
}
Also used : BusinessControl(org.olat.core.id.context.BusinessControl) Roles(org.olat.core.id.Roles) FOCourseNodeRunController(org.olat.course.nodes.fo.FOCourseNodeRunController) NodeRunConstructionResult(org.olat.course.run.navigation.NodeRunConstructionResult) Forum(org.olat.modules.fo.Forum) ForumModule(org.olat.modules.fo.ForumModule) BusinessControlFactory(org.olat.core.id.context.BusinessControlFactory) ForumCallback(org.olat.modules.fo.ForumCallback) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext)

Example 19 with BusinessControlFactory

use of org.olat.core.id.context.BusinessControlFactory in project openolat by klemens.

the class InfoPeekViewController method getUrl.

public String getUrl(String businessPath) {
    BusinessControlFactory bCF = BusinessControlFactory.getInstance();
    List<ContextEntry> ceList = bCF.createCEListFromString(businessPath);
    StringBuilder retVal = new StringBuilder();
    retVal.append(Settings.getServerContextPathURI()).append("/url/");
    for (ContextEntry contextEntry : ceList) {
        String ceStr = contextEntry.toString();
        ceStr = ceStr.replace(':', '/');
        ceStr = ceStr.replaceFirst("\\]", "/");
        ceStr = ceStr.replaceFirst("\\[", "");
        retVal.append(ceStr);
    }
    return retVal.substring(0, retVal.length() - 1);
}
Also used : BusinessControlFactory(org.olat.core.id.context.BusinessControlFactory) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 20 with BusinessControlFactory

use of org.olat.core.id.context.BusinessControlFactory in project openolat by klemens.

the class ProjectBrokerCourseNode method createNodeRunConstructionResult.

/**
 * @see org.olat.course.nodes.CourseNode#createNodeRunConstructionResult(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.control.WindowControl,
 *      org.olat.course.run.userview.UserCourseEnvironment,
 *      org.olat.course.run.userview.NodeEvaluation)
 */
@Override
public NodeRunConstructionResult createNodeRunConstructionResult(UserRequest ureq, WindowControl wControl, UserCourseEnvironment userCourseEnv, NodeEvaluation ne, String nodecmd) {
    updateModuleConfigDefaults(false);
    Controller controller;
    // Do not allow guests to access tasks
    Roles roles = ureq.getUserSession().getRoles();
    if (roles.isGuestOnly()) {
        Translator trans = new PackageTranslator(PACKAGE, ureq.getLocale());
        String title = trans.translate(NLS_GUESTNOACCESS_TITLE);
        String message = trans.translate(NLS_GUESTNOACCESS_MESSAGE);
        controller = MessageUIFactory.createInfoMessage(ureq, wControl, title, message);
    } else {
        // Add message id to business path if nodemcd is available
        if (nodecmd != null) {
            try {
                Long projectId = Long.valueOf(nodecmd);
                BusinessControlFactory bcf = BusinessControlFactory.getInstance();
                BusinessControl businessControl = bcf.createFromString("[Project:" + projectId + "]");
                wControl = bcf.createBusinessWindowControl(businessControl, wControl);
            } catch (NumberFormatException e) {
                // ups, nodecmd is not a message, what the heck is it then?
                log.warn("Could not create message ID from given nodemcd::" + nodecmd, e);
            }
        }
        controller = ProjectBrokerControllerFactory.createRunController(ureq, wControl, userCourseEnv, this);
    }
    Controller wrapperCtrl = TitledWrapperHelper.getWrapper(ureq, wControl, controller, this, "o_projectbroker_icon");
    return new NodeRunConstructionResult(wrapperCtrl);
}
Also used : PackageTranslator(org.olat.core.gui.translator.PackageTranslator) Translator(org.olat.core.gui.translator.Translator) PackageTranslator(org.olat.core.gui.translator.PackageTranslator) BusinessControl(org.olat.core.id.context.BusinessControl) Roles(org.olat.core.id.Roles) BusinessControlFactory(org.olat.core.id.context.BusinessControlFactory) MSEditFormController(org.olat.course.nodes.ms.MSEditFormController) TaskController(org.olat.course.nodes.ta.TaskController) NodeEditController(org.olat.course.editor.NodeEditController) TabbableController(org.olat.core.gui.control.generic.tabbable.TabbableController) DropboxController(org.olat.course.nodes.ta.DropboxController) ProjectBrokerIdentityListCourseNodeController(org.olat.course.nodes.projectbroker.ProjectBrokerIdentityListCourseNodeController) AssessmentCourseNodeController(org.olat.course.assessment.ui.tool.AssessmentCourseNodeController) ProjectBrokerCourseEditorController(org.olat.course.nodes.projectbroker.ProjectBrokerCourseEditorController) ProjectListController(org.olat.course.nodes.projectbroker.ProjectListController) ReturnboxController(org.olat.course.nodes.ta.ReturnboxController) Controller(org.olat.core.gui.control.Controller) NodeRunConstructionResult(org.olat.course.run.navigation.NodeRunConstructionResult)

Aggregations

BusinessControlFactory (org.olat.core.id.context.BusinessControlFactory)20 ContextEntry (org.olat.core.id.context.ContextEntry)16 ArrayList (java.util.ArrayList)4 StaticTextElement (org.olat.core.gui.components.form.flexible.elements.StaticTextElement)4 Translator (org.olat.core.gui.translator.Translator)4 Roles (org.olat.core.id.Roles)4 BusinessControl (org.olat.core.id.context.BusinessControl)4 NodeRunConstructionResult (org.olat.course.run.navigation.NodeRunConstructionResult)4 Date (java.util.Date)2 Invitation (org.olat.basesecurity.Invitation)2 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 FormSubmit (org.olat.core.gui.components.form.flexible.impl.elements.FormSubmit)2 Controller (org.olat.core.gui.control.Controller)2 TabbableController (org.olat.core.gui.control.generic.tabbable.TabbableController)2 PackageTranslator (org.olat.core.gui.translator.PackageTranslator)2 Identity (org.olat.core.id.Identity)2 OLATResourceable (org.olat.core.id.OLATResourceable)2 ContactList (org.olat.core.util.mail.ContactList)2 MailBundle (org.olat.core.util.mail.MailBundle)2