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.events.SimpleAction;
019    import com.liferay.portal.kernel.log.Log;
020    import com.liferay.portal.kernel.log.LogFactoryUtil;
021    import com.liferay.portal.kernel.notifications.ChannelHubManagerUtil;
022    import com.liferay.portal.kernel.notifications.DuplicateChannelHubException;
023    import com.liferay.portal.kernel.util.GetterUtil;
024    
025    /**
026     * @author Edward Han
027     * @author Brian Wing Shun Chan
028     */
029    public class ChannelHubAppStartupAction extends SimpleAction {
030    
031            @Override
032            public void run(String[] ids) throws ActionException {
033                    try {
034                            long companyId = GetterUtil.getLong(ids[0]);
035    
036                            if (_log.isDebugEnabled()) {
037                                    _log.debug("Creating channel hub " + companyId);
038                            }
039    
040                            ChannelHubManagerUtil.createChannelHub(companyId);
041                    }
042                    catch (DuplicateChannelHubException dche) {
043                            if (_log.isWarnEnabled()) {
044                                    _log.warn(dche.getMessage());
045                            }
046                    }
047                    catch (Exception e) {
048                            throw new ActionException(e);
049                    }
050            }
051    
052            private static Log _log = LogFactoryUtil.getLog(
053                    ChannelHubAppStartupAction.class);
054    
055    }