001    /**
002     * Copyright (c) 2000-present 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.dynamicdatamapping.util;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.json.JSONArray;
019    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
020    import com.liferay.portal.kernel.util.OrderByComparator;
021    import com.liferay.portal.service.ServiceContext;
022    import com.liferay.portal.theme.ThemeDisplay;
023    import com.liferay.portlet.dynamicdatamapping.model.DDMForm;
024    import com.liferay.portlet.dynamicdatamapping.model.DDMFormLayout;
025    import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
026    import com.liferay.portlet.dynamicdatamapping.model.DDMStructureVersion;
027    import com.liferay.portlet.dynamicdatamapping.model.DDMTemplate;
028    import com.liferay.portlet.dynamicdatamapping.storage.Field;
029    import com.liferay.portlet.dynamicdatamapping.storage.Fields;
030    
031    import java.io.Serializable;
032    
033    import javax.portlet.PortletRequest;
034    
035    /**
036     * @author Eduardo Lundgren
037     * @author Marcellus Tavares
038     * @author Leonardo Barros
039     */
040    public class DDMUtil {
041    
042            public static DDM getDDM() {
043                    PortalRuntimePermission.checkGetBeanProperty(DDMUtil.class);
044    
045                    return _ddm;
046            }
047    
048            public static DDMDisplay getDDMDisplay(long classNameId)
049                    throws PortalException {
050    
051                    return getDDM().getDDMDisplay(classNameId);
052            }
053    
054            public static DDMForm getDDMForm(long classNameId, long classPK)
055                    throws PortalException {
056    
057                    return getDDM().getDDMForm(classNameId, classPK);
058            }
059    
060            public static DDMForm getDDMForm(PortletRequest portletRequest)
061                    throws PortalException {
062    
063                    return getDDM().getDDMForm(portletRequest);
064            }
065    
066            public static JSONArray getDDMFormFieldsJSONArray(
067                    DDMStructure ddmStructure, String script) {
068    
069                    return getDDM().getDDMFormFieldsJSONArray(ddmStructure, script);
070            }
071    
072            public static JSONArray getDDMFormFieldsJSONArray(
073                    DDMStructureVersion ddmStructureVersion, String script) {
074    
075                    return getDDM().getDDMFormFieldsJSONArray(ddmStructureVersion, script);
076            }
077    
078            public static DDMPermissionHandler getDDMPermissionHandler(
079                    long classNameId) {
080    
081                    return getDDM().getDDMPermissionHandler(classNameId);
082            }
083    
084            public static DDMFormLayout getDefaultDDMFormLayout(DDMForm ddmForm) {
085                    return getDDM().getDefaultDDMFormLayout(ddmForm);
086            }
087    
088            public static Serializable getDisplayFieldValue(
089                            ThemeDisplay themeDisplay, Serializable fieldValue, String type)
090                    throws Exception {
091    
092                    return getDDM().getDisplayFieldValue(themeDisplay, fieldValue, type);
093            }
094    
095            public static Fields getFields(
096                            long ddmStructureId, long ddmTemplateId,
097                            ServiceContext serviceContext)
098                    throws PortalException {
099    
100                    return getDDM().getFields(
101                            ddmStructureId, ddmTemplateId, serviceContext);
102            }
103    
104            public static Fields getFields(
105                            long ddmStructureId, long ddmTemplateId, String fieldNamespace,
106                            ServiceContext serviceContext)
107                    throws PortalException {
108    
109                    return getDDM().getFields(
110                            ddmStructureId, ddmTemplateId, fieldNamespace, serviceContext);
111            }
112    
113            public static Fields getFields(
114                            long ddmStructureId, ServiceContext serviceContext)
115                    throws PortalException {
116    
117                    return getDDM().getFields(ddmStructureId, serviceContext);
118            }
119    
120            public static Fields getFields(
121                            long ddmStructureId, String fieldNamespace,
122                            ServiceContext serviceContext)
123                    throws PortalException {
124    
125                    return getDDM().getFields(
126                            ddmStructureId, fieldNamespace, serviceContext);
127            }
128    
129            public static String[] getFieldsDisplayValues(Field fieldsDisplayField)
130                    throws Exception {
131    
132                    return getDDM().getFieldsDisplayValues(fieldsDisplayField);
133            }
134    
135            public static Serializable getIndexedFieldValue(
136                            Serializable fieldValue, String type)
137                    throws Exception {
138    
139                    return getDDM().getIndexedFieldValue(fieldValue, type);
140            }
141    
142            public static OrderByComparator<DDMStructure> getStructureOrderByComparator(
143                    String orderByCol, String orderByType) {
144    
145                    return getDDM().getStructureOrderByComparator(orderByCol, orderByType);
146            }
147    
148            public static OrderByComparator<DDMTemplate> getTemplateOrderByComparator(
149                    String orderByCol, String orderByType) {
150    
151                    return getDDM().getTemplateOrderByComparator(orderByCol, orderByType);
152            }
153    
154            public static Fields mergeFields(Fields newFields, Fields existingFields) {
155                    return getDDM().mergeFields(newFields, existingFields);
156            }
157    
158            public void setDDM(DDM ddm) {
159                    PortalRuntimePermission.checkSetBeanProperty(getClass());
160    
161                    _ddm = ddm;
162            }
163    
164            private static DDM _ddm;
165    
166    }