Search in sources :

Example 1 with Layout

use of com.liferay.portal.model.Layout in project liferay-ide by liferay.

the class UserLocalServiceImpl method sendEmailAddressVerification.

/**
 * Sends an email address verification to the user.
 *
 * @param  user the verification email recipient
 * @param  emailAddress the recipient's email address
 * @param  serviceContext the service context to be applied. Must set the
 *         portal URL, main path, primary key of the layout, remote address,
 *         remote host, and agent for the user.
 * @throws PortalException if a portal exception occurred
 * @throws SystemException if a system exception occurred
 */
@Override
public void sendEmailAddressVerification(User user, String emailAddress, ServiceContext serviceContext) throws PortalException, SystemException {
    if (user.isEmailAddressVerified() && StringUtil.equalsIgnoreCase(emailAddress, user.getEmailAddress())) {
        return;
    }
    Ticket ticket = ticketLocalService.addTicket(user.getCompanyId(), User.class.getName(), user.getUserId(), TicketConstants.TYPE_EMAIL_ADDRESS, emailAddress, null, serviceContext);
    String verifyEmailAddressURL = serviceContext.getPortalURL() + serviceContext.getPathMain() + "/portal/verify_email_address?ticketKey=" + ticket.getKey();
    long plid = serviceContext.getPlid();
    if (plid > 0) {
        Layout layout = layoutLocalService.fetchLayout(plid);
        if (layout != null) {
            Group group = layout.getGroup();
            if (!layout.isPrivateLayout() && !group.isUser()) {
                verifyEmailAddressURL += "&p_l_id=" + serviceContext.getPlid();
            }
        }
    }
    String fromName = PrefsPropsUtil.getString(user.getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_NAME);
    String fromAddress = PrefsPropsUtil.getString(user.getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);
    String toName = user.getFullName();
    String toAddress = emailAddress;
    String subject = PrefsPropsUtil.getContent(user.getCompanyId(), PropsKeys.ADMIN_EMAIL_VERIFICATION_SUBJECT);
    String body = PrefsPropsUtil.getContent(user.getCompanyId(), PropsKeys.ADMIN_EMAIL_VERIFICATION_BODY);
    SubscriptionSender subscriptionSender = new SubscriptionSender();
    subscriptionSender.setBody(body);
    subscriptionSender.setCompanyId(user.getCompanyId());
    subscriptionSender.setContextAttributes("[$EMAIL_VERIFICATION_CODE$]", ticket.getKey(), "[$EMAIL_VERIFICATION_URL$]", verifyEmailAddressURL, "[$REMOTE_ADDRESS$]", serviceContext.getRemoteAddr(), "[$REMOTE_HOST$]", serviceContext.getRemoteHost(), "[$USER_ID$]", user.getUserId(), "[$USER_SCREENNAME$]", user.getScreenName());
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);
    subscriptionSender.setMailId("user", user.getUserId(), System.currentTimeMillis(), PwdGenerator.getPassword());
    subscriptionSender.setServiceContext(serviceContext);
    subscriptionSender.setSubject(subject);
    subscriptionSender.setUserId(user.getUserId());
    subscriptionSender.addRuntimeSubscribers(toAddress, toName);
    subscriptionSender.flushNotificationsAsync();
}
Also used : Ticket(com.liferay.portal.model.Ticket) Group(com.liferay.portal.model.Group) UserGroup(com.liferay.portal.model.UserGroup) User(com.liferay.portal.model.User) Layout(com.liferay.portal.model.Layout) SubscriptionSender(com.liferay.portal.util.SubscriptionSender)

Example 2 with Layout

use of com.liferay.portal.model.Layout in project liferay-ide by liferay.

the class ShindigUtil method getColumnUserPrefs.

public static String getColumnUserPrefs(String namespace, ThemeDisplay themeDisplay) {
    StringBundler sb = new StringBundler(3);
    sb.append(_COLUMN_USER_PREFS);
    sb.append(namespace);
    Layout layout = themeDisplay.getLayout();
    sb.append(layout.getPlid());
    return sb.toString();
}
Also used : Layout(com.liferay.portal.model.Layout) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 3 with Layout

use of com.liferay.portal.model.Layout in project liferay-ide by liferay.

the class BaseConfigurationAction method doProcessAction.

protected void doProcessAction(PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
    Layout layout = themeDisplay.getLayout();
    JSONObject userPrefsJSONObject = JSONFactoryUtil.createJSONObject();
    Map<String, UserPref> userPrefs = getUserPrefs(portletConfig, actionRequest);
    for (UserPref userPref : userPrefs.values()) {
        String name = userPref.getName();
        String value = ParamUtil.getString(actionRequest, name);
        userPrefsJSONObject.put(name, value);
    }
    String namespace = ShindigUtil.getPortletResourceNamespace(actionRequest, themeDisplay);
    String columnName = ShindigUtil.getColumnUserPrefs(namespace, themeDisplay);
    ExpandoValueServiceUtil.addValue(themeDisplay.getCompanyId(), Layout.class.getName(), ShindigUtil.getTableOpenSocial(), columnName, layout.getPlid(), userPrefsJSONObject.toString());
    String portletResource = ParamUtil.getString(actionRequest, "portletResource");
    SessionMessages.add(actionRequest, PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_REFRESH_PORTLET, portletResource);
    SessionMessages.add(actionRequest, PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_UPDATED_CONFIGURATION);
}
Also used : JSONObject(com.liferay.portal.kernel.json.JSONObject) Layout(com.liferay.portal.model.Layout) UserPref(org.apache.shindig.gadgets.spec.UserPref) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Example 4 with Layout

use of com.liferay.portal.model.Layout in project liferay-ide by liferay.

the class FindKBArticleAction method getCandidateLayouts.

protected List<Layout> getCandidateLayouts(long plid, boolean privateLayout, KBArticle kbArticle) throws Exception {
    List<Layout> candidateLayouts = new ArrayList<Layout>();
    Group group = GroupLocalServiceUtil.getGroup(kbArticle.getGroupId());
    if (group.isLayout()) {
        Layout layout = LayoutLocalServiceUtil.getLayout(group.getClassPK());
        candidateLayouts.add(layout);
        group = layout.getGroup();
    }
    List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(group.getGroupId(), privateLayout, LayoutConstants.TYPE_PORTLET);
    candidateLayouts.addAll(layouts);
    Layout layout = LayoutLocalServiceUtil.getLayout(plid);
    if ((layout.getGroupId() == kbArticle.getGroupId()) && layout.isTypePortlet()) {
        candidateLayouts.remove(layout);
        candidateLayouts.add(0, layout);
    }
    return candidateLayouts;
}
Also used : Group(com.liferay.portal.model.Group) Layout(com.liferay.portal.model.Layout) ArrayList(java.util.ArrayList)

Example 5 with Layout

use of com.liferay.portal.model.Layout in project liferay-ide by liferay.

the class FindKBArticleAction method getKBArticleURL.

protected PortletURL getKBArticleURL(long plid, boolean privateLayout, KBArticle kbArticle, HttpServletRequest request) throws Exception {
    PortletURL firstMatchPortletURL = null;
    List<Layout> layouts = getCandidateLayouts(plid, privateLayout, kbArticle);
    for (Layout layout : layouts) {
        LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();
        List<Portlet> portlets = layoutTypePortlet.getAllPortlets();
        for (Portlet portlet : portlets) {
            String rootPortletId = PortletConstants.getRootPortletId(portlet.getPortletId());
            if (rootPortletId.equals(PortletKeys.KNOWLEDGE_BASE_DISPLAY)) {
                PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getPortletSetup(layout, portlet.getPortletId(), StringPool.BLANK);
                long kbFolderClassNameId = PortalUtil.getClassNameId(KBFolderConstants.getClassName());
                long resourceClassNameId = GetterUtil.getLong(portletPreferences.getValue("resourceClassNameId", null), kbFolderClassNameId);
                long resourcePrimKey = GetterUtil.getLong(portletPreferences.getValue("resourcePrimKey", null), KBFolderConstants.DEFAULT_PARENT_FOLDER_ID);
                if (resourceClassNameId == kbFolderClassNameId) {
                    if (isParentFolder(resourcePrimKey, kbArticle.getKbFolderId())) {
                        return getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request);
                    }
                } else if (resourcePrimKey == kbArticle.getResourcePrimKey()) {
                    return getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request);
                }
                if (firstMatchPortletURL == null) {
                    firstMatchPortletURL = getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request);
                }
            }
            if (rootPortletId.equals(PortletKeys.KNOWLEDGE_BASE_SECTION)) {
                PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getPortletSetup(layout, portlet.getPortletId(), StringPool.BLANK);
                String[] kbArticlesSections = portletPreferences.getValues("kbArticlesSections", new String[0]);
                KBArticle rootKBArticle = KBArticleLocalServiceUtil.fetchLatestKBArticle(kbArticle.getRootResourcePrimKey(), WorkflowConstants.STATUS_APPROVED);
                if (rootKBArticle == null) {
                    continue;
                }
                String[] sections = AdminUtil.unescapeSections(rootKBArticle.getSections());
                for (String section : sections) {
                    if (!ArrayUtil.contains(kbArticlesSections, section)) {
                        continue;
                    }
                    return getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request);
                }
            }
            if (rootPortletId.equals(PortletKeys.KNOWLEDGE_BASE_ARTICLE)) {
                PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getPortletSetup(layout, portlet.getPortletId(), StringPool.BLANK);
                long resourcePrimKey = GetterUtil.getLong(portletPreferences.getValue("resourcePrimKey", null));
                KBArticle selKBArticle = KBArticleLocalServiceUtil.fetchLatestKBArticle(resourcePrimKey, WorkflowConstants.STATUS_APPROVED);
                if (selKBArticle == null) {
                    continue;
                }
                long rootResourcePrimKey = kbArticle.getRootResourcePrimKey();
                long selRootResourcePrimKey = selKBArticle.getRootResourcePrimKey();
                if (rootResourcePrimKey == selRootResourcePrimKey) {
                    return getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request);
                }
                if (firstMatchPortletURL == null) {
                    firstMatchPortletURL = getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request);
                }
            }
        }
    }
    return firstMatchPortletURL;
}
Also used : LayoutTypePortlet(com.liferay.portal.model.LayoutTypePortlet) LayoutTypePortlet(com.liferay.portal.model.LayoutTypePortlet) Portlet(com.liferay.portal.model.Portlet) KBArticle(com.liferay.knowledgebase.model.KBArticle) Layout(com.liferay.portal.model.Layout) PortletPreferences(javax.portlet.PortletPreferences) PortletURL(javax.portlet.PortletURL)

Aggregations

Layout (com.liferay.portal.model.Layout)7 Group (com.liferay.portal.model.Group)2 KBArticle (com.liferay.knowledgebase.model.KBArticle)1 JSONObject (com.liferay.portal.kernel.json.JSONObject)1 StringBundler (com.liferay.portal.kernel.util.StringBundler)1 LayoutTypePortlet (com.liferay.portal.model.LayoutTypePortlet)1 Portlet (com.liferay.portal.model.Portlet)1 Ticket (com.liferay.portal.model.Ticket)1 User (com.liferay.portal.model.User)1 UserGroup (com.liferay.portal.model.UserGroup)1 ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)1 SubscriptionSender (com.liferay.portal.util.SubscriptionSender)1 MDRAction (com.liferay.portlet.mobiledevicerules.model.MDRAction)1 MDRRuleGroupInstance (com.liferay.portlet.mobiledevicerules.model.MDRRuleGroupInstance)1 ArrayList (java.util.ArrayList)1 PortletPreferences (javax.portlet.PortletPreferences)1 PortletURL (javax.portlet.PortletURL)1 UserPref (org.apache.shindig.gadgets.spec.UserPref)1