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.backgroundtask;
016    
017    import com.liferay.portal.kernel.util.ArrayUtil;
018    import com.liferay.portal.kernel.util.Constants;
019    import com.liferay.portal.kernel.util.Validator;
020    
021    import java.io.Serializable;
022    
023    import java.util.Date;
024    import java.util.HashMap;
025    import java.util.Map;
026    
027    /**
028     * @author Michael C. Han
029     */
030    public class BackgroundTaskContextMapFactory {
031    
032            public static Map<String, Serializable> buildTaskContextMap(
033                    long userId, long groupId, boolean privateLayout, long[] layoutIds,
034                    Map<String, String[]> parameterMap, String cmd, Date startDate,
035                    Date endDate, String fileName) {
036    
037                    Map<String, Serializable> taskContextMap =
038                            new HashMap<String, Serializable>();
039    
040                    if (cmd != null) {
041                            taskContextMap.put(Constants.CMD, cmd);
042                    }
043    
044                    if (endDate != null) {
045                            taskContextMap.put("endDate", endDate);
046                    }
047    
048                    taskContextMap.put("fileName", fileName);
049                    taskContextMap.put("groupId", groupId);
050    
051                    if (ArrayUtil.isNotEmpty(layoutIds)) {
052                            taskContextMap.put("layoutIds", layoutIds);
053                    }
054    
055                    if (parameterMap != null) {
056                            HashMap<String, String[]> serializableParameterMap =
057                                    new HashMap<String, String[]>(parameterMap);
058    
059                            taskContextMap.put("parameterMap", serializableParameterMap);
060                    }
061    
062                    taskContextMap.put("privateLayout", privateLayout);
063    
064                    if (startDate != null) {
065                            taskContextMap.put("startDate", startDate);
066                    }
067    
068                    taskContextMap.put("userId", userId);
069    
070                    return taskContextMap;
071            }
072    
073            public static Map<String, Serializable> buildTaskContextMap(
074                    long userId, long plid, long groupId, String portletId,
075                    Map<String, String[]> parameterMap, String cmd, Date startDate,
076                    Date endDate, String fileName) {
077    
078                    Map<String, Serializable> taskContextMap =
079                            new HashMap<String, Serializable>();
080    
081                    if (cmd != null) {
082                            taskContextMap.put(Constants.CMD, cmd);
083                    }
084    
085                    if (endDate != null) {
086                            taskContextMap.put("endDate", endDate);
087                    }
088    
089                    taskContextMap.put("fileName", fileName);
090                    taskContextMap.put("groupId", groupId);
091    
092                    if (parameterMap != null) {
093                            HashMap<String, String[]> serializableParameterMap =
094                                    new HashMap<String, String[]>(parameterMap);
095    
096                            taskContextMap.put("parameterMap", serializableParameterMap);
097                    }
098    
099                    taskContextMap.put("plid", plid);
100    
101                    if (Validator.isNotNull(portletId)) {
102                            taskContextMap.put("portletId", portletId);
103                    }
104    
105                    if (startDate != null) {
106                            taskContextMap.put("startDate", startDate);
107                    }
108    
109                    taskContextMap.put("userId", userId);
110    
111                    return taskContextMap;
112            }
113    
114    }