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