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.util;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.json.JSONArray;
020    import com.liferay.portal.kernel.json.JSONObject;
021    import com.liferay.portal.kernel.search.Hits;
022    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
023    import com.liferay.portal.service.ServiceContext;
024    import com.liferay.portal.theme.ThemeDisplay;
025    import com.liferay.portlet.dynamicdatalists.model.DDLRecord;
026    import com.liferay.portlet.dynamicdatalists.model.DDLRecordSet;
027    
028    import java.util.List;
029    
030    import javax.portlet.PortletPreferences;
031    import javax.portlet.RenderRequest;
032    import javax.portlet.RenderResponse;
033    
034    import javax.servlet.http.HttpServletRequest;
035    
036    /**
037     * @author Eduardo Lundgren
038     * @author Marcellus Tavares
039     */
040    @ProviderType
041    public class DDLUtil {
042    
043            public static DDL getDDL() {
044                    PortalRuntimePermission.checkGetBeanProperty(DDLUtil.class);
045    
046                    return _ddl;
047            }
048    
049            public static JSONObject getRecordJSONObject(DDLRecord record)
050                    throws Exception {
051    
052                    return getDDL().getRecordJSONObject(record);
053            }
054    
055            public static JSONObject getRecordJSONObject(
056                            DDLRecord record, boolean latestRecordVersion)
057                    throws Exception {
058    
059                    return getDDL().getRecordJSONObject(record, latestRecordVersion);
060            }
061    
062            public static List<DDLRecord> getRecords(Hits hits) throws Exception {
063                    return getDDL().getRecords(hits);
064            }
065    
066            public static JSONArray getRecordSetJSONArray(DDLRecordSet recordSet)
067                    throws Exception {
068    
069                    return getDDL().getRecordSetJSONArray(recordSet);
070            }
071    
072            public static JSONArray getRecordsJSONArray(List<DDLRecord> records)
073                    throws Exception {
074    
075                    return getDDL().getRecordsJSONArray(records);
076            }
077    
078            public static JSONArray getRecordsJSONArray(
079                            List<DDLRecord> records, boolean latestRecordVersion)
080                    throws Exception {
081    
082                    return getDDL().getRecordsJSONArray(records, latestRecordVersion);
083            }
084    
085            public static String getTemplateContent(
086                            long ddmTemplateId, DDLRecordSet recordSet,
087                            ThemeDisplay themeDisplay, RenderRequest renderRequest,
088                            RenderResponse renderResponse)
089                    throws Exception {
090    
091                    return getDDL().getTemplateContent(
092                            ddmTemplateId, recordSet, themeDisplay, renderRequest,
093                            renderResponse);
094            }
095    
096            /**
097             * @deprecated As of 7.0.0, with no direct replacement
098             */
099            @Deprecated
100            public static boolean isEditable(
101                            HttpServletRequest request, String portletId, long groupId)
102                    throws Exception {
103    
104                    return getDDL().isEditable(request, portletId, groupId);
105            }
106    
107            /**
108             * @deprecated As of 7.0.0, with no direct replacement
109             */
110            @Deprecated
111            public static boolean isEditable(
112                            PortletPreferences preferences, String portletId, long groupId)
113                    throws Exception {
114    
115                    return getDDL().isEditable(preferences, portletId, groupId);
116            }
117    
118            public static DDLRecord updateRecord(
119                            long recordId, long recordSetId, boolean mergeFields,
120                            boolean checkPermission, ServiceContext serviceContext)
121                    throws Exception {
122    
123                    return getDDL().updateRecord(
124                            recordId, recordSetId, mergeFields, checkPermission,
125                            serviceContext);
126            }
127    
128            public static DDLRecord updateRecord(
129                            long recordId, long recordSetId, boolean mergeFields,
130                            ServiceContext serviceContext)
131                    throws Exception {
132    
133                    return getDDL().updateRecord(
134                            recordId, recordSetId, mergeFields, serviceContext);
135            }
136    
137            public void setDDL(DDL ddl) {
138                    PortalRuntimePermission.checkSetBeanProperty(getClass());
139    
140                    _ddl = ddl;
141            }
142    
143            private static DDL _ddl;
144    
145    }