001    /**
002     * Copyright (c) 2000-2013 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.dynamicdatalists.action;
016    
017    import com.liferay.portal.kernel.util.ParamUtil;
018    import com.liferay.portal.kernel.util.Validator;
019    import com.liferay.portal.util.PortalUtil;
020    import com.liferay.portal.util.WebKeys;
021    import com.liferay.portlet.dynamicdatalists.model.DDLRecord;
022    import com.liferay.portlet.dynamicdatalists.model.DDLRecordSet;
023    import com.liferay.portlet.dynamicdatalists.service.DDLRecordLocalServiceUtil;
024    import com.liferay.portlet.dynamicdatalists.service.DDLRecordSetLocalServiceUtil;
025    
026    import javax.portlet.PortletRequest;
027    
028    import javax.servlet.http.HttpServletRequest;
029    
030    /**
031     * @author Brian Wing Shun Chan
032     * @author Bruno Basto
033     * @author Eduardo Lundgren
034     */
035    public class ActionUtil {
036    
037            public static void getRecord(HttpServletRequest request) throws Exception {
038                    long recordId = ParamUtil.getLong(request, "recordId");
039    
040                    DDLRecord record = null;
041    
042                    if (recordId > 0) {
043                            record = DDLRecordLocalServiceUtil.getRecord(recordId);
044                    }
045    
046                    request.setAttribute(WebKeys.DYNAMIC_DATA_LISTS_RECORD, record);
047            }
048    
049            public static void getRecord(PortletRequest portletRequest)
050                    throws Exception {
051    
052                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
053                            portletRequest);
054    
055                    getRecord(request);
056            }
057    
058            public static void getRecordSet(HttpServletRequest request)
059                    throws Exception {
060    
061                    long recordSetId = ParamUtil.getLong(request, "recordSetId");
062    
063                    DDLRecordSet recordSet = null;
064    
065                    if (Validator.isNotNull(recordSetId)) {
066                            recordSet = DDLRecordSetLocalServiceUtil.getRecordSet(recordSetId);
067                    }
068    
069                    request.setAttribute(WebKeys.DYNAMIC_DATA_LISTS_RECORD_SET, recordSet);
070            }
071    
072            public static void getRecordSet(PortletRequest portletRequest)
073                    throws Exception {
074    
075                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
076                            portletRequest);
077    
078                    getRecordSet(request);
079            }
080    
081    }