001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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            public void run(HttpServletRequest request, HttpServletResponse response)
035                    throws ActionException {
036    
037                    try {
038                            long groupId = ParamUtil.getLong(request, "groupId");
039                            boolean privateLayout = ParamUtil.getBoolean(
040                                    request, "privateLayout");
041                            long layoutId = ParamUtil.getLong(request, "layoutId");
042    
043                            Layout layout = LayoutLocalServiceUtil.getLayout(
044                                    groupId, privateLayout, layoutId);
045    
046                            UnicodeProperties typeSettingsProperties =
047                                    layout.getTypeSettingsProperties();
048    
049                            String articleId = typeSettingsProperties.getProperty("article-id");
050    
051                            if (Validator.isNull(articleId)) {
052                                    return;
053                            }
054    
055                            JournalContentSearchLocalServiceUtil.updateContentSearch(
056                                    layout.getGroupId(), layout.isPrivateLayout(),
057                                    layout.getLayoutId(), StringPool.BLANK, articleId, true);
058                    }
059                    catch (Exception e) {
060                            throw new ActionException(e);
061                    }
062            }
063    
064    }