001    /**
002     * Copyright (c) 2000-present 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.events;
016    
017    import com.liferay.portal.kernel.dao.orm.QueryUtil;
018    import com.liferay.portal.kernel.events.ActionException;
019    import com.liferay.portal.kernel.events.SimpleAction;
020    import com.liferay.portal.kernel.util.GetterUtil;
021    import com.liferay.portal.model.Layout;
022    import com.liferay.portal.model.LayoutPrototype;
023    import com.liferay.portal.service.LayoutPrototypeLocalServiceUtil;
024    import com.liferay.portal.service.UserLocalServiceUtil;
025    import com.liferay.portal.util.DefaultLayoutPrototypesUtil;
026    import com.liferay.portal.util.PortletKeys;
027    
028    import java.util.List;
029    
030    /**
031     * @author Sergio Gonz??lez
032     * @author Juan Fern??ndez
033     */
034    public class AddDefaultLayoutPrototypesAction extends SimpleAction {
035    
036            @Override
037            public void run(String[] ids) throws ActionException {
038                    try {
039                            doRun(GetterUtil.getLong(ids[0]));
040                    }
041                    catch (Exception e) {
042                            throw new ActionException(e);
043                    }
044            }
045    
046            protected void addBlogPage(
047                            long companyId, long defaultUserId,
048                            List<LayoutPrototype> layoutPrototypes)
049                    throws Exception {
050    
051                    Layout layout = DefaultLayoutPrototypesUtil.addLayoutPrototype(
052                            companyId, defaultUserId, "layout-prototype-blog-title",
053                            "layout-prototype-blog-description", "2_columns_iii",
054                            layoutPrototypes);
055    
056                    if (layout == null) {
057                            return;
058                    }
059    
060                    DefaultLayoutPrototypesUtil.addPortletId(
061                            layout, PortletKeys.BLOGS, "column-1");
062    
063                    DefaultLayoutPrototypesUtil.addPortletId(
064                            layout, PortletKeys.RECENT_BLOGGERS, "column-2");
065            }
066    
067            protected void doRun(long companyId) throws Exception {
068                    long defaultUserId = UserLocalServiceUtil.getDefaultUserId(companyId);
069    
070                    List<LayoutPrototype> layoutPrototypes =
071                            LayoutPrototypeLocalServiceUtil.search(
072                                    companyId, null, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
073    
074                    addBlogPage(companyId, defaultUserId, layoutPrototypes);
075            }
076    
077    }