001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.model;
016    
017    import com.liferay.portal.kernel.events.Action;
018    import com.liferay.portal.kernel.events.ActionException;
019    import com.liferay.portal.kernel.util.ParamUtil;
020    import com.liferay.portal.kernel.util.StringPool;
021    import com.liferay.portal.kernel.util.UnicodeProperties;
022    import com.liferay.portal.kernel.util.Validator;
023    import com.liferay.portal.service.LayoutLocalServiceUtil;
024    import com.liferay.portlet.journal.service.JournalContentSearchLocalServiceUtil;
025    
026    import javax.servlet.http.HttpServletRequest;
027    import javax.servlet.http.HttpServletResponse;
028    
029    /**
030     * @author Raymond Augé
031     */
032    public class LayoutTypeArticleConfigurationUpdateAction extends Action {
033    
034            @Override
035            public void run(HttpServletRequest request, HttpServletResponse response)
036                    throws ActionException {
037    
038                    try {
039                            long groupId = ParamUtil.getLong(request, "groupId");
040                            boolean privateLayout = ParamUtil.getBoolean(
041                                    request, "privateLayout");
042                            long layoutId = ParamUtil.getLong(request, "layoutId");
043    
044                            Layout layout = LayoutLocalServiceUtil.getLayout(
045                                    groupId, privateLayout, layoutId);
046    
047                            UnicodeProperties typeSettingsProperties =
048                                    layout.getTypeSettingsProperties();
049    
050                            String articleId = typeSettingsProperties.getProperty("article-id");
051    
052                            if (Validator.isNull(articleId)) {
053                                    return;
054                            }
055    
056                            JournalContentSearchLocalServiceUtil.updateContentSearch(
057                                    layout.getGroupId(), layout.isPrivateLayout(),
058                                    layout.getLayoutId(), StringPool.BLANK, articleId, true);
059                    }
060                    catch (Exception e) {
061                            throw new ActionException(e);
062                    }
063            }
064    
065    }