001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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-list-structures.xml", serviceContext);
059            }
060    
061    }