001    /**
002     * Copyright (c) 2000-2013 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.model.GroupConstants;
021    import com.liferay.portal.service.GroupLocalServiceUtil;
022    import com.liferay.portal.service.ServiceContext;
023    import com.liferay.portal.service.UserLocalServiceUtil;
024    import com.liferay.portal.util.PortalUtil;
025    import com.liferay.portlet.dynamicdatalists.model.DDLRecordSet;
026    
027    /**
028     * @author Michael C. Han
029     */
030    public class AddDefaultDDMStructuresAction
031            extends BaseDefaultDDMStructureAction {
032    
033            @Override
034            public void run(String[] ids) throws ActionException {
035                    try {
036                            doRun(GetterUtil.getLong(ids[0]));
037                    }
038                    catch (Exception e) {
039                            throw new ActionException(e);
040                    }
041            }
042    
043            protected void doRun(long companyId) throws Exception {
044                    ServiceContext serviceContext = new ServiceContext();
045    
046                    Group group = GroupLocalServiceUtil.getGroup(
047                            companyId, GroupConstants.GUEST);
048    
049                    serviceContext.setScopeGroupId(group.getGroupId());
050    
051                    long defaultUserId = UserLocalServiceUtil.getDefaultUserId(companyId);
052    
053                    serviceContext.setUserId(defaultUserId);
054    
055                    addDDMStructures(
056                            defaultUserId, group.getGroupId(),
057                            PortalUtil.getClassNameId(DDLRecordSet.class),
058                            "dynamic-data-mapping-structures.xml", serviceContext);
059            }
060    
061    }