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.events.ActionException;
018    import com.liferay.portal.kernel.util.GetterUtil;
019    import com.liferay.portal.model.Group;
020    import com.liferay.portal.service.GroupLocalServiceUtil;
021    import com.liferay.portal.service.ServiceContext;
022    import com.liferay.portal.service.UserLocalServiceUtil;
023    import com.liferay.portal.util.PortalUtil;
024    import com.liferay.portlet.journal.model.JournalArticle;
025    
026    /**
027     * @author Eudaldo Alonso
028     */
029    public class AddDefaultJournalStructuresAction
030            extends BaseDefaultDDMStructureAction {
031    
032            @Override
033            public void run(String[] ids) throws ActionException {
034                    try {
035                            doRun(GetterUtil.getLong(ids[0]));
036                    }
037                    catch (Exception e) {
038                            throw new ActionException(e);
039                    }
040            }
041    
042            protected void doRun(long companyId) throws Exception {
043                    ServiceContext serviceContext = new ServiceContext();
044    
045                    serviceContext.setAddGuestPermissions(true);
046                    serviceContext.setAddGroupPermissions(true);
047    
048                    Group group = GroupLocalServiceUtil.getCompanyGroup(companyId);
049    
050                    serviceContext.setScopeGroupId(group.getGroupId());
051    
052                    long defaultUserId = UserLocalServiceUtil.getDefaultUserId(companyId);
053    
054                    serviceContext.setUserId(defaultUserId);
055    
056                    addDDMStructures(
057                            defaultUserId, group.getGroupId(),
058                            PortalUtil.getClassNameId(JournalArticle.class),
059                            "basic-web-content-structure.xml", serviceContext);
060            }
061    
062    }