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