// Path: src/main/java/com/liferay/support/tools/common/ParamContext.java
// public abstract class ParamContext {
// 
// 	protected ThemeDisplay themeDisplay;
// 	protected ServiceContext serviceContext;
// 
// 	public ThemeDisplay getThemeDisplay() {
// 		return themeDisplay;
// 	}
// 
// 	public void setThemeDisplay(ThemeDisplay themeDisplay) {
// 		this.themeDisplay = themeDisplay;
// 	}
// 
// 	public ServiceContext getServiceContext() {
// 		return serviceContext;
// 	}
// 
// 	public void setServiceContext(ServiceContext serviceContext) {
// 		this.serviceContext = serviceContext;
// 	}
// 
// }
// 
// Path: src/main/java/com/liferay/support/tools/utils/CommonUtil.java
// @Component(immediate = true, service = CommonUtil.class)
// public class CommonUtil {
// 
// 	/**
// 	 * Page Command Pairs
// 	 * 
// 	 * @return jsp file name corresponding to the command.
// 	 */
// 	public Map<String, String> getPageFromMode() {
// 		return LDFPortletKeys.renderJSPs;
// 	}
// 
// 	/**
// 	 * Convert 
// 	 * @param source
// 	 * @return
// 	 */
// 	static public String[] convertToStringArray(String source) {
// 		if(source.length() == 0) {
// 			return new String[0];
// 		}
// 		
// 		return source.split(",",0);
// 	}
// 	
// 	/**
// 	 * Convert string array to long array
// 	 * 
// 	 * @param source String array of ids
// 	 * @return long array of ids
// 	 */
// 	static public long[] convertStringToLongArray(String[] source) {
// 		if (Validator.isNull(source) || source.length <= 0) {
// 			return null;
// 		}
// 
// 		return Arrays.stream(source).distinct().mapToLong(Long::parseLong).toArray();
// 	}
// 
// 	/**
// 	 * Filter roles
// 	 * 
// 	 * Depending on role types, the processes to apply roles are different. This
// 	 * method filter either Organization / Site roles or Regular roles.
// 	 * 
// 	 * @param roleIds role ids. This can be mix of reguler / organization / site roles.
// 	 * @return Filtered roleids in each array.
// 	 * @throws PortalException
// 	 */
// 	public Map<Integer, List<Role>> filterRoles(long[] roleIds) throws PortalException {
// 
// 		if (Validator.isNull(roleIds) || roleIds.length == 0) {
// 			return new ConcurrentHashMap<Integer, List<Role>>();
// 		}
// 
// 		List<Role> roles = _roleLocalService.getRoles(roleIds);
// 		return roles.stream().collect(Collectors.groupingBy(Role::getType));
// 	}
// 
// 
// 	/**
// 	 * Create Faker
// 	 * 
// 	 * @param locale Language to create Faker object based on.
// 	 * @return Faker object.
// 	 */
// 	public Faker createFaker(String locale) {
// 		// For generating dummy user name
// 		Faker faker = new Faker(new Locale(Locale.ENGLISH.toLanguageTag()));
// 
// 		try {
// 			Faker fakerTmp = new Faker(new Locale(locale));
// 			faker = fakerTmp;
// 		} catch (Exception e) {
// 			e.printStackTrace();
// 		}
// 
// 		return faker;
// 	}
// 	
// 	@Reference
// 	private RoleLocalService _roleLocalService;
// 	
// 	private static final Log _log = LogFactoryUtil.getLog(CommonUtil.class);			
// }


import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.LocaleUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.support.tools.common.ParamContext;
import com.liferay.support.tools.utils.CommonUtil;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.portlet.ActionRequest;

	/**
	 * Constructor
	 * 
	 * @param actionRequest
	 * @throws PortalException
	 */
	public JournalContext(ActionRequest actionRequest) throws PortalException {
		ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

		// Fetch data
		numberOfArticles = ParamUtil.getLong(actionRequest, "numberOfArticles", 1);
		baseTitle = ParamUtil.getString(actionRequest, "baseTitle", "");
		baseArticle = ParamUtil.getString(actionRequest, "baseArticle", "");
		folderId = ParamUtil.getLong(actionRequest, "folderId", 0);
		totalParagraphs = ParamUtil.getInteger(actionRequest, "totalParagraphs", 0);
		titleWords = ParamUtil.getInteger(actionRequest, "titleWords", 0);
		randomAmount = ParamUtil.getInteger(actionRequest, "randomAmount", 0);
		createContentsType = ParamUtil.getLong(actionRequest, "createContentsType", 0);
		linkLists = ParamUtil.getString(actionRequest, "linkLists", "");
		ddmStructureId = ParamUtil.getLong(actionRequest, "ddmStructureId", 0);
		ddmTemplateId = ParamUtil.getLong(actionRequest, "ddmTemplateId", 0);

		// Locales
		String[] defLang = { LocaleUtil.getDefault().toString() };
		locales = ParamUtil.getStringValues(actionRequest, "locales", defLang);

		// Sites
		String[] groupsStrIds = ParamUtil.getStringValues(actionRequest, "groupIds",
				new String[] { String.valueOf(themeDisplay.getScopeGroupId()) });
// Path: src/main/java/com/liferay/support/tools/common/ParamContext.java
// public abstract class ParamContext {
// 
// 	protected ThemeDisplay themeDisplay;
// 	protected ServiceContext serviceContext;
// 
// 	public ThemeDisplay getThemeDisplay() {
// 		return themeDisplay;
// 	}
// 
// 	public void setThemeDisplay(ThemeDisplay themeDisplay) {
// 		this.themeDisplay = themeDisplay;
// 	}
// 
// 	public ServiceContext getServiceContext() {
// 		return serviceContext;
// 	}
// 
// 	public void setServiceContext(ServiceContext serviceContext) {
// 		this.serviceContext = serviceContext;
// 	}
// 
// }
// 
// Path: src/main/java/com/liferay/support/tools/utils/CommonUtil.java
// @Component(immediate = true, service = CommonUtil.class)
// public class CommonUtil {
// 
// 	/**
// 	 * Page Command Pairs
// 	 * 
// 	 * @return jsp file name corresponding to the command.
// 	 */
// 	public Map<String, String> getPageFromMode() {
// 		return LDFPortletKeys.renderJSPs;
// 	}
// 
// 	/**
// 	 * Convert 
// 	 * @param source
// 	 * @return
// 	 */
// 	static public String[] convertToStringArray(String source) {
// 		if(source.length() == 0) {
// 			return new String[0];
// 		}
// 		
// 		return source.split(",",0);
// 	}
// 	
// 	/**
// 	 * Convert string array to long array
// 	 * 
// 	 * @param source String array of ids
// 	 * @return long array of ids
// 	 */
// 	static public long[] convertStringToLongArray(String[] source) {
// 		if (Validator.isNull(source) || source.length <= 0) {
// 			return null;
// 		}
// 
// 		return Arrays.stream(source).distinct().mapToLong(Long::parseLong).toArray();
// 	}
// 
// 	/**
// 	 * Filter roles
// 	 * 
// 	 * Depending on role types, the processes to apply roles are different. This
// 	 * method filter either Organization / Site roles or Regular roles.
// 	 * 
// 	 * @param roleIds role ids. This can be mix of reguler / organization / site roles.
// 	 * @return Filtered roleids in each array.
// 	 * @throws PortalException
// 	 */
// 	public Map<Integer, List<Role>> filterRoles(long[] roleIds) throws PortalException {
// 
// 		if (Validator.isNull(roleIds) || roleIds.length == 0) {
// 			return new ConcurrentHashMap<Integer, List<Role>>();
// 		}
// 
// 		List<Role> roles = _roleLocalService.getRoles(roleIds);
// 		return roles.stream().collect(Collectors.groupingBy(Role::getType));
// 	}
// 
// 
// 	/**
// 	 * Create Faker
// 	 * 
// 	 * @param locale Language to create Faker object based on.
// 	 * @return Faker object.
// 	 */
// 	public Faker createFaker(String locale) {
// 		// For generating dummy user name
// 		Faker faker = new Faker(new Locale(Locale.ENGLISH.toLanguageTag()));
// 
// 		try {
// 			Faker fakerTmp = new Faker(new Locale(locale));
// 			faker = fakerTmp;
// 		} catch (Exception e) {
// 			e.printStackTrace();
// 		}
// 
// 		return faker;
// 	}
// 	
// 	@Reference
// 	private RoleLocalService _roleLocalService;
// 	
// 	private static final Log _log = LogFactoryUtil.getLog(CommonUtil.class);			
// }


// Path: src/main/java/com/liferay/support/tools/journal/JournalContext.java
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.LocaleUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.support.tools.common.ParamContext;
import com.liferay.support.tools.utils.CommonUtil;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.portlet.ActionRequest;


	/**
	 * Constructor
	 * 
	 * @param actionRequest
	 * @throws PortalException
	 */
	public JournalContext(ActionRequest actionRequest) throws PortalException {
		ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

		// Fetch data
		numberOfArticles = ParamUtil.getLong(actionRequest, "numberOfArticles", 1);
		baseTitle = ParamUtil.getString(actionRequest, "baseTitle", "");
		baseArticle = ParamUtil.getString(actionRequest, "baseArticle", "");
		folderId = ParamUtil.getLong(actionRequest, "folderId", 0);
		totalParagraphs = ParamUtil.getInteger(actionRequest, "totalParagraphs", 0);
		titleWords = ParamUtil.getInteger(actionRequest, "titleWords", 0);
		randomAmount = ParamUtil.getInteger(actionRequest, "randomAmount", 0);
		createContentsType = ParamUtil.getLong(actionRequest, "createContentsType", 0);
		linkLists = ParamUtil.getString(actionRequest, "linkLists", "");
		ddmStructureId = ParamUtil.getLong(actionRequest, "ddmStructureId", 0);
		ddmTemplateId = ParamUtil.getLong(actionRequest, "ddmTemplateId", 0);

		// Locales
		String[] defLang = { LocaleUtil.getDefault().toString() };
		locales = ParamUtil.getStringValues(actionRequest, "locales", defLang);

		// Sites
		String[] groupsStrIds = ParamUtil.getStringValues(actionRequest, "groupIds",
				new String[] { String.valueOf(themeDisplay.getScopeGroupId()) });
		groupIds = CommonUtil.convertStringToLongArray(groupsStrIds);