001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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)
038                    throws Exception {
039    
040                    long recordId = ParamUtil.getLong(request, "recordId");
041    
042                    DDLRecord record = null;
043    
044                    if (recordId > 0) {
045                            record = DDLRecordLocalServiceUtil.getRecord(recordId);
046                    }
047    
048                    request.setAttribute(WebKeys.DYNAMIC_DATA_LISTS_RECORD, record);
049            }
050    
051            public static void getRecord(PortletRequest portletRequest)
052                    throws Exception {
053    
054                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
055                            portletRequest);
056    
057                    getRecord(request);
058            }
059    
060            public static void getRecordSet(HttpServletRequest request)
061                    throws Exception {
062    
063                    long recordSetId = ParamUtil.getLong(request, "recordSetId");
064    
065                    DDLRecordSet recordSet = null;
066    
067                    if (Validator.isNotNull(recordSetId)) {
068                            recordSet = DDLRecordSetLocalServiceUtil.getRecordSet(recordSetId);
069                    }
070    
071                    request.setAttribute(WebKeys.DYNAMIC_DATA_LISTS_RECORD_SET, recordSet);
072            }
073    
074            public static void getRecordSet(PortletRequest portletRequest)
075                    throws Exception {
076    
077                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
078                            portletRequest);
079    
080                    getRecordSet(request);
081            }
082    
083    }