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.configuration;
016    
017    import com.liferay.portal.kernel.util.Validator;
018    import com.liferay.portlet.exportimport.lar.PortletDataHandlerKeys;
019    import com.liferay.portlet.exportimport.lar.UserIdStrategy;
020    
021    import java.util.LinkedHashMap;
022    import java.util.Map;
023    
024    import javax.portlet.PortletRequest;
025    
026    /**
027     * @author Akos Thurzo
028     */
029    public class ExportImportConfigurationParameterMapFactory {
030    
031            public static Map<String, String[]> buildParameterMap() {
032                    return buildParameterMap(
033                            PortletDataHandlerKeys.DATA_STRATEGY_MIRROR_OVERWRITE, true, false,
034                            true, false, false, false, true, true, true, true, true, true, true,
035                            true, UserIdStrategy.CURRENT_USER_ID);
036            }
037    
038            public static Map<String, String[]> buildParameterMap(
039                    PortletRequest portletRequest) {
040    
041                    Map<String, String[]> parameterMap = new LinkedHashMap<>(
042                            portletRequest.getParameterMap());
043    
044                    if (!parameterMap.containsKey(PortletDataHandlerKeys.DATA_STRATEGY)) {
045                            parameterMap.put(
046                                    PortletDataHandlerKeys.DATA_STRATEGY,
047                                    new String[] {
048                                            PortletDataHandlerKeys.DATA_STRATEGY_MIRROR_OVERWRITE
049                                    });
050                    }
051    
052                    /*if (!parameterMap.containsKey(
053                                    PortletDataHandlerKeys.DELETE_MISSING_LAYOUTS)) {
054    
055                            parameterMap.put(
056                                    PortletDataHandlerKeys.DELETE_MISSING_LAYOUTS,
057                                    new String[] {Boolean.TRUE.toString()});
058                    }*/
059    
060                    if (!parameterMap.containsKey(
061                                    PortletDataHandlerKeys.DELETE_PORTLET_DATA)) {
062    
063                            parameterMap.put(
064                                    PortletDataHandlerKeys.DELETE_PORTLET_DATA,
065                                    new String[] {Boolean.FALSE.toString()});
066                    }
067    
068                    if (!parameterMap.containsKey(
069                                    PortletDataHandlerKeys.LAYOUT_SET_PROTOTYPE_LINK_ENABLED)) {
070    
071                            parameterMap.put(
072                                    PortletDataHandlerKeys.LAYOUT_SET_PROTOTYPE_LINK_ENABLED,
073                                    new String[] {Boolean.FALSE.toString()});
074                    }
075    
076                    if (!parameterMap.containsKey(
077                                    PortletDataHandlerKeys.LAYOUT_SET_SETTINGS)) {
078    
079                            parameterMap.put(
080                                    PortletDataHandlerKeys.LAYOUT_SET_SETTINGS,
081                                    new String[] {Boolean.FALSE.toString()});
082                    }
083    
084                    if (!parameterMap.containsKey(PortletDataHandlerKeys.LOGO)) {
085                            parameterMap.put(
086                                    PortletDataHandlerKeys.LOGO,
087                                    new String[] {Boolean.FALSE.toString()});
088                    }
089    
090                    if (!parameterMap.containsKey(
091                                    PortletDataHandlerKeys.PORTLET_CONFIGURATION)) {
092    
093                            parameterMap.put(
094                                    PortletDataHandlerKeys.PORTLET_CONFIGURATION,
095                                    new String[] {Boolean.TRUE.toString()});
096                    }
097    
098                    if (!parameterMap.containsKey(PortletDataHandlerKeys.PORTLET_DATA)) {
099                            parameterMap.put(
100                                    PortletDataHandlerKeys.PORTLET_DATA,
101                                    new String[] {Boolean.FALSE.toString()});
102                    }
103    
104                    if (!parameterMap.containsKey(
105                                    PortletDataHandlerKeys.PORTLET_DATA_ALL)) {
106    
107                            parameterMap.put(
108                                    PortletDataHandlerKeys.PORTLET_DATA_ALL,
109                                    new String[] {Boolean.FALSE.toString()});
110                    }
111    
112                    if (!parameterMap.containsKey(PortletDataHandlerKeys.THEME_REFERENCE)) {
113                            parameterMap.put(
114                                    PortletDataHandlerKeys.THEME_REFERENCE,
115                                    new String[] {Boolean.FALSE.toString()});
116                    }
117    
118                    if (!parameterMap.containsKey(
119                                    PortletDataHandlerKeys.UPDATE_LAST_PUBLISH_DATE)) {
120    
121                            parameterMap.put(
122                                    PortletDataHandlerKeys.UPDATE_LAST_PUBLISH_DATE,
123                                    new String[] {Boolean.TRUE.toString()});
124                    }
125    
126                    if (!parameterMap.containsKey(
127                                    PortletDataHandlerKeys.USER_ID_STRATEGY)) {
128    
129                            parameterMap.put(
130                                    PortletDataHandlerKeys.USER_ID_STRATEGY,
131                                    new String[] {UserIdStrategy.CURRENT_USER_ID});
132                    }
133    
134                    return parameterMap;
135            }
136    
137            public static Map<String, String[]> buildParameterMap(
138                    String dataStrategy, Boolean deleteMissingLayouts,
139                    Boolean deletePortletData, Boolean ignoreLastPublishDate,
140                    Boolean layoutSetPrototypeLinkEnabled, Boolean layoutSetSettings,
141                    Boolean logo, Boolean permissions, Boolean portletConfiguration,
142                    Boolean portletConfigurationAll, Boolean portletData,
143                    Boolean portletDataAll, Boolean portletSetupAll, Boolean themeReference,
144                    Boolean updateLastPublishDate, String userIdStrategy) {
145    
146                    Map<String, String[]> parameterMap = new LinkedHashMap<>();
147    
148                    // Data strategy
149    
150                    String dataStrategyParameter =
151                            PortletDataHandlerKeys.DATA_STRATEGY_MIRROR_OVERWRITE;
152    
153                    if (Validator.isNotNull(dataStrategy)) {
154                            parameterMap.put(
155                                    PortletDataHandlerKeys.DATA_STRATEGY,
156                                    new String[] {dataStrategyParameter});
157                    }
158    
159                    // Delete missing layouts
160    
161                    boolean deleteMissingLayoutsParameter = true;
162    
163                    if (deleteMissingLayouts != null) {
164                            deleteMissingLayoutsParameter = deleteMissingLayouts.booleanValue();
165                    }
166    
167                    parameterMap.put(
168                            PortletDataHandlerKeys.DELETE_MISSING_LAYOUTS,
169                            new String[] {String.valueOf(deleteMissingLayoutsParameter)});
170    
171                    // Delete portlet data
172    
173                    boolean deletePortletDataParameter = false;
174    
175                    if (deletePortletData != null) {
176                            deletePortletDataParameter = deletePortletData.booleanValue();
177                    }
178    
179                    parameterMap.put(
180                            PortletDataHandlerKeys.DELETE_PORTLET_DATA,
181                            new String[] {String.valueOf(deletePortletDataParameter)});
182    
183                    // Ignore last publish date
184    
185                    boolean ignoreLastPublishDateParameter = true;
186    
187                    if (ignoreLastPublishDate != null) {
188                            ignoreLastPublishDateParameter =
189                                    ignoreLastPublishDate.booleanValue();
190                    }
191    
192                    parameterMap.put(
193                            PortletDataHandlerKeys.IGNORE_LAST_PUBLISH_DATE,
194                            new String[] {String.valueOf(ignoreLastPublishDateParameter)});
195    
196                    // Layout set prototype link enabled
197    
198                    boolean layoutSetPrototypeLinkEnabledParameter = false;
199    
200                    if (layoutSetPrototypeLinkEnabled != null) {
201                            layoutSetPrototypeLinkEnabledParameter =
202                                    layoutSetPrototypeLinkEnabled.booleanValue();
203                    }
204    
205                    parameterMap.put(
206                            PortletDataHandlerKeys.LAYOUT_SET_PROTOTYPE_LINK_ENABLED,
207                            new String[] {
208                                    String.valueOf(layoutSetPrototypeLinkEnabledParameter)
209                            });
210    
211                    // Layout set settings
212    
213                    boolean layoutSetSettingsParameter = false;
214    
215                    if (layoutSetSettings != null) {
216                            layoutSetSettingsParameter = layoutSetSettings.booleanValue();
217                    }
218    
219                    parameterMap.put(
220                            PortletDataHandlerKeys.LAYOUT_SET_SETTINGS,
221                            new String[] {String.valueOf(layoutSetSettingsParameter)});
222    
223                    // Logo
224    
225                    boolean logoParameter = false;
226    
227                    if (logo != null) {
228                            logoParameter = logo.booleanValue();
229                    }
230    
231                    parameterMap.put(
232                            PortletDataHandlerKeys.LOGO,
233                            new String[] {String.valueOf(logoParameter)});
234    
235                    // Permissions
236    
237                    boolean permissionsParameter = true;
238    
239                    if (permissions != null) {
240                            permissionsParameter = permissions.booleanValue();
241                    }
242    
243                    parameterMap.put(
244                            PortletDataHandlerKeys.PERMISSIONS,
245                            new String[] {String.valueOf(permissionsParameter)});
246    
247                    // Portlet configuration
248    
249                    boolean portletConfigurationParameter = true;
250    
251                    if (portletConfiguration != null) {
252                            portletConfigurationParameter = portletConfiguration.booleanValue();
253                    }
254    
255                    parameterMap.put(
256                            PortletDataHandlerKeys.PORTLET_CONFIGURATION,
257                            new String[] {String.valueOf(portletConfigurationParameter)});
258    
259                    // Portlet configuration all
260    
261                    boolean portletConfigurationAllParameter = true;
262    
263                    if (portletConfigurationAll != null) {
264                            portletConfigurationAllParameter =
265                                    portletConfigurationAll.booleanValue();
266                    }
267    
268                    parameterMap.put(
269                            PortletDataHandlerKeys.PORTLET_CONFIGURATION_ALL,
270                            new String[] {String.valueOf(portletConfigurationAllParameter)});
271    
272                    // Portlet data
273    
274                    boolean portletDataParameter = false;
275    
276                    if (portletData != null) {
277                            portletDataParameter = portletData.booleanValue();
278                    }
279    
280                    parameterMap.put(
281                            PortletDataHandlerKeys.PORTLET_DATA,
282                            new String[] {String.valueOf(portletDataParameter)});
283    
284                    // Portlet data all
285    
286                    boolean portletDataAllParameter = false;
287    
288                    if (portletDataAll != null) {
289                            portletDataAllParameter = portletDataAll.booleanValue();
290                    }
291    
292                    parameterMap.put(
293                            PortletDataHandlerKeys.PORTLET_DATA_ALL,
294                            new String[] {String.valueOf(portletDataAllParameter)});
295    
296                    // Portlet setup all
297    
298                    boolean portletSetupAllParameter = true;
299    
300                    if (portletSetupAll != null) {
301                            portletSetupAllParameter = portletSetupAll.booleanValue();
302                    }
303    
304                    parameterMap.put(
305                            PortletDataHandlerKeys.PORTLET_SETUP_ALL,
306                            new String[] {String.valueOf(portletSetupAllParameter)});
307    
308                    // Theme reference
309    
310                    boolean themeReferenceParameter = false;
311    
312                    if (themeReference != null) {
313                            themeReferenceParameter = themeReference.booleanValue();
314                    }
315    
316                    parameterMap.put(
317                            PortletDataHandlerKeys.THEME_REFERENCE,
318                            new String[] {String.valueOf(themeReferenceParameter)});
319    
320                    // Update last publish date
321    
322                    boolean updateLastPublishDateParameter = true;
323    
324                    if (updateLastPublishDate != null) {
325                            updateLastPublishDateParameter =
326                                    updateLastPublishDate.booleanValue();
327                    }
328    
329                    parameterMap.put(
330                            PortletDataHandlerKeys.UPDATE_LAST_PUBLISH_DATE,
331                            new String[] {String.valueOf(updateLastPublishDateParameter)});
332    
333                    // User id strategy
334    
335                    String userIdStrategyParameter = UserIdStrategy.CURRENT_USER_ID;
336    
337                    if (Validator.isNotNull(userIdStrategy)) {
338                            userIdStrategyParameter = userIdStrategy;
339                    }
340    
341                    parameterMap.put(
342                            PortletDataHandlerKeys.USER_ID_STRATEGY,
343                            new String[] {userIdStrategyParameter});
344    
345                    return parameterMap;
346            }
347    
348    }