001    /**
002     * Copyright (c) 2000-2012 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)
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    }