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.portlet.exportimport.messaging;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.messaging.Message;
019    import com.liferay.portal.kernel.messaging.MessageStatus;
020    import com.liferay.portal.kernel.util.GetterUtil;
021    import com.liferay.portal.kernel.util.MapUtil;
022    import com.liferay.portlet.exportimport.model.ExportImportConfiguration;
023    import com.liferay.portlet.exportimport.service.ExportImportConfigurationLocalServiceUtil;
024    import com.liferay.portlet.exportimport.staging.StagingUtil;
025    
026    import java.io.Serializable;
027    
028    import java.util.Map;
029    
030    /**
031     * @author Bruno Farache
032     * @author Raymond Aug??
033     * @author Daniel Kocsis
034     */
035    public class LayoutsLocalPublisherMessageListener
036            extends BasePublisherMessageListener {
037    
038            @Override
039            protected void doReceive(Message message, MessageStatus messageStatus)
040                    throws PortalException {
041    
042                    long exportImportConfigurationId = GetterUtil.getLong(
043                            message.getPayload());
044    
045                    ExportImportConfiguration exportImportConfiguration =
046                            ExportImportConfigurationLocalServiceUtil.
047                                    getExportImportConfiguration(exportImportConfigurationId);
048    
049                    messageStatus.setPayload(exportImportConfiguration);
050    
051                    Map<String, Serializable> settingsMap =
052                            exportImportConfiguration.getSettingsMap();
053    
054                    long userId = MapUtil.getLong(settingsMap, "userId");
055                    long sourceGroupId = MapUtil.getLong(settingsMap, "sourceGroupId");
056                    long targetGroupId = MapUtil.getLong(settingsMap, "targetGroupId");
057                    boolean privateLayout = MapUtil.getBoolean(
058                            settingsMap, "privateLayout");
059                    long[] layoutIds = GetterUtil.getLongValues(
060                            settingsMap.get("layoutIds"));
061                    Map<String, String[]> parameterMap =
062                            (Map<String, String[]>)settingsMap.get("parameterMap");
063    
064                    initThreadLocals(userId, parameterMap);
065    
066                    try {
067                            StagingUtil.publishLayouts(
068                                    userId, sourceGroupId, targetGroupId, privateLayout, layoutIds,
069                                    parameterMap);
070                    }
071                    finally {
072                            resetThreadLocals();
073                    }
074            }
075    
076    }