001    /**
002     * Copyright (c) 2000-2012 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.NoSuchContentSearchException;
025    import com.liferay.portlet.journal.service.JournalContentSearchLocalServiceUtil;
026    
027    import javax.servlet.http.HttpServletRequest;
028    import javax.servlet.http.HttpServletResponse;
029    
030    /**
031     * @author Raymond Augé
032     */
033    public class LayoutTypeArticleConfigurationDeleteAction extends Action {
034    
035            @Override
036            public void run(HttpServletRequest request, HttpServletResponse response)
037                    throws ActionException {
038    
039                    try {
040                            long groupId = ParamUtil.getLong(request, "groupId");
041                            boolean privateLayout = ParamUtil.getBoolean(
042                                    request, "privateLayout");
043                            long layoutId = ParamUtil.getLong(request, "layoutId");
044    
045                            Layout layout = LayoutLocalServiceUtil.getLayout(
046                                    groupId, privateLayout, layoutId);
047    
048                            UnicodeProperties typeSettingsProperties =
049                                    layout.getTypeSettingsProperties();
050    
051                            String articleId = typeSettingsProperties.getProperty("article-id");
052    
053                            if (Validator.isNull(articleId)) {
054                                    return;
055                            }
056    
057                            try {
058                                    JournalContentSearchLocalServiceUtil.deleteArticleContentSearch(
059                                            layout.getGroupId(), layout.isPrivateLayout(),
060                                            layout.getLayoutId(), StringPool.BLANK, articleId);
061                            }
062                            catch (NoSuchContentSearchException nscse) {
063                            }
064                    }
065                    catch (Exception e) {
066                            throw new ActionException(e);
067                    }
068            }
069    
070    }