Search in sources :

Example 1 with WebuiRequestContext

use of org.exoplatform.webui.application.WebuiRequestContext in project social by Meeds-io.

the class UISpaceMember method validateInvitedUser.

/**
 * Validates invited users for checking if any error happens.
 *
 * @throws Exception
 */
private void validateInvitedUser(String userNameForInvite) throws Exception {
    WebuiRequestContext requestContext = WebuiRequestContext.getCurrentInstance();
    UIApplication uiApp = requestContext.getUIApplication();
    String[] invitedUserList = userNameForInvite.split(",");
    String invitedUser = null;
    ApplicationMessage appMsg = null;
    invitedUserNames = null;
    List<String> validUsers = new ArrayList<String>();
    List<String> invitedUsers = new ArrayList<String>();
    List<String> memberUsers = new ArrayList<String>();
    List<String> notExistUsers = new ArrayList<String>();
    for (String userStr : invitedUserList) {
        invitedUser = userStr.trim();
        if (invitedUser.length() == 0) {
            continue;
        }
        if (isMember(invitedUser)) {
            memberUsers.add(invitedUser);
        } else if (isNotExisted(invitedUser)) {
            notExistUsers.add(invitedUser);
        } else if (hasInvited(invitedUser)) {
            invitedUsers.add(invitedUser);
        } else {
            validUsers.add(invitedUser);
        }
    }
    if (validUsers.size() > 0) {
        setUsersName(StringUtils.join(validUsers, ','));
        invitedUserNames = StringUtils.join(validUsers, ',');
    }
    if (notExistUsers.size() > 0) {
        setHasErr(true);
        appMsg = new ApplicationMessage("UISpaceMember.msg.user-not-exist", notExistUsers.toArray(new String[notExistUsers.size()]), ApplicationMessage.WARNING);
        appMsg.setArgsLocalized(false);
        uiApp.addMessage(appMsg);
    }
    if (invitedUsers.size() > 0) {
        setHasErr(true);
        appMsg = new ApplicationMessage("UISpaceMember.msg.user-is-invited", invitedUsers.toArray(new String[invitedUsers.size()]), ApplicationMessage.WARNING);
        appMsg.setArgsLocalized(false);
        uiApp.addMessage(appMsg);
    }
    if (memberUsers.size() > 0) {
        setHasErr(true);
        appMsg = new ApplicationMessage("UISpaceMember.msg.user-is-member", memberUsers.toArray(new String[memberUsers.size()]), ApplicationMessage.WARNING);
        appMsg.setArgsLocalized(false);
        uiApp.addMessage(appMsg);
    }
}
Also used : ApplicationMessage(org.exoplatform.web.application.ApplicationMessage) WebuiRequestContext(org.exoplatform.webui.application.WebuiRequestContext) ArrayList(java.util.ArrayList) UIApplication(org.exoplatform.webui.core.UIApplication)

Example 2 with WebuiRequestContext

use of org.exoplatform.webui.application.WebuiRequestContext in project social by Meeds-io.

the class UISpaceNavigationNodeSelector method save.

public void save() {
    WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
    try {
        userPortal.saveNode(getRootNode().getNode(), getRootNode());
        DescriptionService descriptionService = getApplicationComponent(DescriptionService.class);
        Map<String, Map<Locale, State>> i18nizedLabels = this.userNodeLabels;
        for (String treeNodeId : i18nizedLabels.keySet()) {
            TreeNode node = findNode(treeNodeId);
            if (node != null) {
                Map<Locale, State> labels = i18nizedLabels.get(treeNodeId);
                node.setI18nizedLabels(labels);
                if (labels != null && labels.size() > 0) {
                    descriptionService.setDescriptions(node.getNode().getId(), labels);
                }
            }
        }
    } catch (NavigationServiceException ex) {
        context.getUIApplication().addMessage(new ApplicationMessage("UINavigationNodeSelector.msg." + ex.getError().name(), null, ApplicationMessage.ERROR));
    }
}
Also used : DescriptionService(org.exoplatform.portal.mop.description.DescriptionService) Locale(java.util.Locale) NavigationServiceException(org.exoplatform.portal.mop.navigation.NavigationServiceException) State(org.exoplatform.portal.mop.Described.State) ApplicationMessage(org.exoplatform.web.application.ApplicationMessage) WebuiRequestContext(org.exoplatform.webui.application.WebuiRequestContext) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with WebuiRequestContext

use of org.exoplatform.webui.application.WebuiRequestContext in project social by Meeds-io.

the class BaseUIActivity method setActivity.

public void setActivity(ExoSocialActivity activity) {
    WebuiRequestContext requestContext = WebuiRequestContext.getCurrentInstance();
    ResourceBundle resourceBundle = requestContext.getApplicationResourceBundle();
    this.activity = activity;
    Identity identity = Utils.getIdentityManager().getIdentity(activity.getUserId(), true);
    setOwnerIdentity(identity);
    UIFormTextAreaInput commentTextArea = new UIFormTextAreaInput("CommentTextarea" + activity.getId(), "CommentTextarea", null);
    commentTextArea.setHTMLAttribute(HTML_ATTRIBUTE_TITLE, resourceBundle.getString("BaseUIActivity.label.Add_your_comment"));
    addChild(commentTextArea);
    try {
        refresh();
    } catch (ActivityStorageException e) {
        LOG.error(e.getMessage(), e);
    }
}
Also used : ActivityStorageException(org.exoplatform.social.core.storage.ActivityStorageException) UIFormTextAreaInput(org.exoplatform.webui.form.UIFormTextAreaInput) WebuiRequestContext(org.exoplatform.webui.application.WebuiRequestContext) ResourceBundle(java.util.ResourceBundle) Identity(org.exoplatform.social.core.identity.model.Identity)

Example 4 with WebuiRequestContext

use of org.exoplatform.webui.application.WebuiRequestContext in project social by Meeds-io.

the class BaseUIActivity method getI18N.

/**
 * Allow child can be override this method to process I18N
 * @param activity
 * @return
 */
protected ExoSocialActivity getI18N(ExoSocialActivity activity) {
    WebuiRequestContext requestContext = WebuiRequestContext.getCurrentInstance();
    I18NActivityProcessor i18NActivityProcessor = getApplicationComponent(I18NActivityProcessor.class);
    if (activity.getTitleId() != null) {
        Locale userLocale = requestContext.getLocale();
        activity = i18NActivityProcessor.process(activity, userLocale);
    }
    return activity;
}
Also used : Locale(java.util.Locale) WebuiRequestContext(org.exoplatform.webui.application.WebuiRequestContext) I18NActivityProcessor(org.exoplatform.social.core.processor.I18NActivityProcessor)

Example 5 with WebuiRequestContext

use of org.exoplatform.webui.application.WebuiRequestContext in project social by Meeds-io.

the class UIExperienceSection method saveProfileInfo.

/**
 * Saves input information into profile.<br>
 *
 * @return Integer value (0: save complete; 1,2: an error has occurs)
 * @throws Exception
 */
@SuppressWarnings("unchecked")
private int saveProfileInfo() throws Exception {
    ArrayList<HashMap<String, Object>> experiences = new ArrayList<HashMap<String, Object>>();
    UIFormStringInput uiStringInput = null;
    UIFormTextAreaInput uiFormTextAreaInput = null;
    UICheckBoxInput uiCheckBox = null;
    UIFormDateTimeInput uiDateTimeInput = null;
    String company = null;
    String position = null;
    String description = null;
    String skills = null;
    String startDate = null;
    String endDate = null;
    Boolean isCurrent = null;
    // Check if there is any exception during parsing Date Time field
    boolean isDateTimeException = false;
    Date sDate = null;
    Date eDate = null;
    Date today = new Date();
    WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
    UIApplication uiApplication = context.getUIApplication();
    Profile p = getProfile();
    List<UIComponent> listUIComp = getChilds();
    // List of children not include UITitleBar child.
    int totalUIComponent = listUIComp.size() - 1;
    int errorCode = 0;
    if (totalUIComponent == 0) {
        if (p != null) {
            Profile updateProfile = new Profile(p.getIdentity());
            updateProfile.setId(p.getId());
            updateProfile.setProperty(Profile.EXPERIENCES, experiences);
            Utils.getIdentityManager().updateExperienceSection(updateProfile);
        }
        return errorCode;
    }
    for (int i = 1; i <= totalUIComponent; i += 7) {
        HashMap<String, Object> uiMap = new HashMap<String, Object>();
        uiStringInput = (UIFormStringInput) listUIComp.get(i);
        company = uiStringInput.getValue();
        if ((company == null) || (company.length() == 0)) {
            uiApplication.addMessage(new ApplicationMessage(INVALID_COMPANY_MANDATORY, null, 1));
            errorCode = 1;
        }
        uiStringInput = (UIFormStringInput) listUIComp.get(i + 1);
        position = uiStringInput.getValue();
        if ((position == null) || (position.length() == 0)) {
            uiApplication.addMessage(new ApplicationMessage(INVALID_POSITION_MANDATORY, null, 1));
            errorCode = 1;
        }
        uiFormTextAreaInput = (UIFormTextAreaInput) listUIComp.get(i + 2);
        description = uiFormTextAreaInput.getValue();
        uiFormTextAreaInput = (UIFormTextAreaInput) listUIComp.get(i + 3);
        skills = uiFormTextAreaInput.getValue();
        isDateTimeException = false;
        uiDateTimeInput = (UIFormDateTimeInput) listUIComp.get(i + 4);
        Locale locale = context.getParentAppRequestContext().getLocale();
        String currentPattern = uiDateTimeInput.getDatePattern_();
        SimpleDateFormat sf = new SimpleDateFormat(currentPattern, locale);
        // Specify whether or not date/time parsing is to be lenient.
        sf.setLenient(false);
        Calendar cal = Calendar.getInstance();
        String startDateInput = uiDateTimeInput.getValue();
        if (startDateInput != null && startDateInput.length() > 0) {
            try {
                cal.setTime(sf.parse(startDateInput));
                startDate = calendarToString(cal);
            } catch (Exception e) {
                uiApplication.addMessage(new ApplicationMessage(INVALID_START_DATE_FORMAT, new String[] { currentPattern }, 1));
                errorCode = 1;
                isDateTimeException = true;
            }
        } else {
            startDate = null;
        }
        uiDateTimeInput = (UIFormDateTimeInput) listUIComp.get(i + 5);
        String endDateInput = uiDateTimeInput.getValue();
        if (endDateInput != null && endDateInput.length() > 0) {
            try {
                cal.setTime(sf.parse(endDateInput));
            } catch (Exception e) {
                uiApplication.addMessage(new ApplicationMessage(INVALID_END_DATE_FORMAT, new String[] { currentPattern }, 1));
                errorCode = 1;
                isDateTimeException = true;
            }
        } else {
            endDate = null;
        }
        // Only check other conditions if there is not any Date Time exception
        if (!isDateTimeException) {
            uiCheckBox = (UICheckBoxInput) listUIComp.get(i + 6);
            isCurrent = uiCheckBox.getValue();
            if (startDate == null && (endDate != null || isCurrent.booleanValue()) || "".equals(startDate) && ("".equals(endDate) || isCurrent.booleanValue())) {
                uiApplication.addMessage(new ApplicationMessage(INVALID_START_DATE_MANDATORY, null, 1));
                errorCode = 1;
            }
            if (startDate != null && !"".equals(startDate)) {
                endDate = calendarToString(cal);
                sDate = stringToDate(startDate);
                eDate = stringToDate(endDate);
                if (endDate != null && !"".equals(endDate) && sDate.after(today)) {
                    uiApplication.addMessage(new ApplicationMessage(START_DATE_AFTER_TODAY, null, 1));
                    errorCode = 1;
                }
                if (!isCurrent) {
                    if ((endDate == null) || (endDate.length() == 0)) {
                        uiApplication.addMessage(new ApplicationMessage(INVALID_END_DATE_MANDATORY, null, 1));
                        errorCode = 1;
                    }
                    if ((eDate != null) && eDate.after(today)) {
                        uiApplication.addMessage(new ApplicationMessage(END_DATE_AFTER_TODAY, null, 1));
                        errorCode = 1;
                    }
                    if ((sDate != null) && sDate.after(eDate)) {
                        uiApplication.addMessage(new ApplicationMessage(STARTDATE_BEFORE_ENDDATE, null, 1));
                        errorCode = 1;
                    }
                } else {
                    endDate = null;
                }
            }
        }
        uiMap.put(Profile.EXPERIENCES_COMPANY, escapeHtml(company));
        uiMap.put(Profile.EXPERIENCES_POSITION, escapeHtml(position));
        uiMap.put(Profile.EXPERIENCES_DESCRIPTION, escapeHtml(description));
        uiMap.put(Profile.EXPERIENCES_SKILLS, escapeHtml(skills));
        uiMap.put(Profile.EXPERIENCES_START_DATE, startDate);
        uiMap.put(Profile.EXPERIENCES_END_DATE, endDate);
        uiMap.put(Profile.EXPERIENCES_IS_CURRENT, isCurrent);
        experiences.add(uiMap);
    }
    if (errorCode == 1) {
        return errorCode;
    }
    p.setProperty(Profile.EXPERIENCES, experiences);
    Utils.getIdentityManager().updateProfile(p);
    return errorCode;
}
Also used : Locale(java.util.Locale) HashMap(java.util.HashMap) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) WebuiRequestContext(org.exoplatform.webui.application.WebuiRequestContext) UIComponent(org.exoplatform.webui.core.UIComponent) UIApplication(org.exoplatform.webui.core.UIApplication) UIFormStringInput(org.exoplatform.webui.form.UIFormStringInput) Date(java.util.Date) Profile(org.exoplatform.social.core.identity.model.Profile) ParseException(java.text.ParseException) UIFormTextAreaInput(org.exoplatform.webui.form.UIFormTextAreaInput) UIFormDateTimeInput(org.exoplatform.webui.form.UIFormDateTimeInput) ApplicationMessage(org.exoplatform.web.application.ApplicationMessage) UICheckBoxInput(org.exoplatform.webui.form.input.UICheckBoxInput) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

WebuiRequestContext (org.exoplatform.webui.application.WebuiRequestContext)129 UIApplication (org.exoplatform.webui.core.UIApplication)18 ApplicationMessage (org.exoplatform.web.application.ApplicationMessage)17 Node (javax.jcr.Node)15 ResourceBundle (java.util.ResourceBundle)14 ArrayList (java.util.ArrayList)11 Writer (java.io.Writer)9 UserNode (org.exoplatform.portal.mop.user.UserNode)9 JavascriptManager (org.exoplatform.web.application.JavascriptManager)9 UIComponent (org.exoplatform.webui.core.UIComponent)9 HashMap (java.util.HashMap)8 PortalRequestContext (org.exoplatform.portal.application.PortalRequestContext)8 MimeResponse (javax.portlet.MimeResponse)7 ExoContainer (org.exoplatform.container.ExoContainer)7 IOException (java.io.IOException)6 Locale (java.util.Locale)6 UIJCRExplorer (org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer)6 MissingResourceException (java.util.MissingResourceException)5 PathNotFoundException (javax.jcr.PathNotFoundException)5 SiteSearchService (org.exoplatform.services.wcm.search.SiteSearchService)5