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.dynamicdatamapping.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.util.OrderByComparator;
020    import com.liferay.portal.kernel.util.ParamUtil;
021    import com.liferay.portal.security.permission.ActionKeys;
022    import com.liferay.portal.service.ServiceContext;
023    import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
024    import com.liferay.portlet.dynamicdatamapping.service.base.DDMStructureServiceBaseImpl;
025    import com.liferay.portlet.dynamicdatamapping.service.permission.DDMPermission;
026    import com.liferay.portlet.dynamicdatamapping.service.permission.DDMStructurePermission;
027    
028    import java.util.List;
029    import java.util.Locale;
030    import java.util.Map;
031    
032    /**
033     * @author Brian Wing Shun Chan
034     * @author Bruno Basto
035     * @author Marcellus Tavares
036     */
037    public class DDMStructureServiceImpl extends DDMStructureServiceBaseImpl {
038    
039            public DDMStructure addStructure(
040                            long userId, long groupId, long classNameId,
041                            Map<Locale, String> nameMap, Map<Locale, String> descriptionMap,
042                            String xsd, ServiceContext serviceContext)
043                    throws PortalException, SystemException {
044    
045                    String ddmResource = ParamUtil.getString(serviceContext, "ddmResource");
046    
047                    DDMPermission.check(
048                            getPermissionChecker(), serviceContext.getScopeGroupId(),
049                            ddmResource, ActionKeys.ADD_STRUCTURE);
050    
051                    return ddmStructureLocalService.addStructure(
052                            getUserId(), groupId, classNameId, nameMap, descriptionMap, xsd,
053                            serviceContext);
054            }
055    
056            public DDMStructure addStructure(
057                            long groupId, long parentStructureId, long classNameId,
058                            String structureKey, Map<Locale, String> nameMap,
059                            Map<Locale, String> descriptionMap, String xsd, String storageType,
060                            int type, ServiceContext serviceContext)
061                    throws PortalException, SystemException {
062    
063                    String ddmResource = ParamUtil.getString(serviceContext, "ddmResource");
064    
065                    DDMPermission.check(
066                            getPermissionChecker(), serviceContext.getScopeGroupId(),
067                            ddmResource, ActionKeys.ADD_STRUCTURE);
068    
069                    return ddmStructureLocalService.addStructure(
070                            getUserId(), groupId, parentStructureId, classNameId, structureKey,
071                            nameMap, descriptionMap, xsd, storageType, type, serviceContext);
072            }
073    
074            public DDMStructure addStructure(
075                            long userId, long groupId, String parentStructureKey,
076                            long classNameId, String structureKey, Map<Locale, String> nameMap,
077                            Map<Locale, String> descriptionMap, String xsd, String storageType,
078                            int type, ServiceContext serviceContext)
079                    throws PortalException, SystemException {
080    
081                    String ddmResource = ParamUtil.getString(serviceContext, "ddmResource");
082    
083                    DDMPermission.check(
084                            getPermissionChecker(), serviceContext.getScopeGroupId(),
085                            ddmResource, ActionKeys.ADD_STRUCTURE);
086    
087                    return ddmStructureLocalService.addStructure(
088                            userId, groupId, parentStructureKey, classNameId, structureKey,
089                            nameMap, descriptionMap, xsd, storageType, type, serviceContext);
090            }
091    
092            public DDMStructure copyStructure(
093                            long structureId, Map<Locale, String> nameMap,
094                            Map<Locale, String> descriptionMap, ServiceContext serviceContext)
095                    throws PortalException, SystemException {
096    
097                    String ddmResource = ParamUtil.getString(serviceContext, "ddmResource");
098    
099                    DDMPermission.check(
100                            getPermissionChecker(), serviceContext.getScopeGroupId(),
101                            ddmResource, ActionKeys.ADD_STRUCTURE);
102    
103                    return ddmStructureLocalService.copyStructure(
104                            getUserId(), structureId, nameMap, descriptionMap, serviceContext);
105            }
106    
107            public void deleteStructure(long structureId)
108                    throws PortalException, SystemException {
109    
110                    DDMStructurePermission.check(
111                            getPermissionChecker(), structureId, ActionKeys.DELETE);
112    
113                    ddmStructureLocalService.deleteStructure(structureId);
114            }
115    
116            public DDMStructure fetchStructure(long groupId, String structureKey)
117                    throws PortalException, SystemException {
118    
119                    DDMStructure ddmStructure = ddmStructurePersistence.fetchByG_S(
120                            groupId, structureKey);
121    
122                    if (ddmStructure != null) {
123                            DDMStructurePermission.check(
124                                    getPermissionChecker(), ddmStructure, ActionKeys.VIEW);
125                    }
126    
127                    return ddmStructure;
128            }
129    
130            public DDMStructure getStructure(long structureId)
131                    throws PortalException, SystemException {
132    
133                    DDMStructurePermission.check(
134                            getPermissionChecker(), structureId, ActionKeys.VIEW);
135    
136                    return ddmStructurePersistence.findByPrimaryKey(structureId);
137            }
138    
139            public DDMStructure getStructure(long groupId, String structureKey)
140                    throws PortalException, SystemException {
141    
142                    DDMStructurePermission.check(
143                            getPermissionChecker(), groupId, structureKey, ActionKeys.VIEW);
144    
145                    return ddmStructureLocalService.getStructure(groupId, structureKey);
146            }
147    
148            public DDMStructure getStructure(
149                    long groupId, String structureKey, boolean includeGlobalStructures)
150                    throws PortalException, SystemException {
151    
152                    DDMStructurePermission.check(
153                            getPermissionChecker(), groupId, structureKey, ActionKeys.VIEW);
154    
155                    return ddmStructureLocalService.getStructure(
156                            groupId, structureKey, includeGlobalStructures);
157            }
158    
159            public List<DDMStructure> getStructures(long groupId)
160                    throws SystemException {
161    
162                    return ddmStructurePersistence.filterFindByGroupId(groupId);
163            }
164    
165            public List<DDMStructure> getStructures(long[] groupIds)
166                    throws SystemException {
167    
168                    return ddmStructurePersistence.filterFindByGroupId(groupIds);
169            }
170    
171            public List<DDMStructure> search(
172                            long companyId, long[] groupIds, long[] classNameIds,
173                            String keywords, int start, int end,
174                            OrderByComparator orderByComparator)
175                    throws SystemException {
176    
177                    return ddmStructureFinder.filterFindByKeywords(
178                            companyId, groupIds, classNameIds, keywords, start, end,
179                            orderByComparator);
180            }
181    
182            public List<DDMStructure> search(
183                            long companyId, long[] groupIds, long[] classNameIds, String name,
184                            String description, String storageType, int type,
185                            boolean andOperator, int start, int end,
186                            OrderByComparator orderByComparator)
187                    throws SystemException {
188    
189                    return ddmStructureFinder.filterFindByC_G_C_N_D_S_T(
190                            companyId, groupIds, classNameIds, name, description, storageType,
191                            type, andOperator, start, end, orderByComparator);
192            }
193    
194            public int searchCount(
195                            long companyId, long[] groupIds, long[] classNameIds,
196                            String keywords)
197                    throws SystemException {
198    
199                    return ddmStructureFinder.filterCountByKeywords(
200                            companyId, groupIds, classNameIds, keywords);
201            }
202    
203            public int searchCount(
204                            long companyId, long[] groupIds, long[] classNameIds, String name,
205                            String description, String storageType, int type,
206                            boolean andOperator)
207                    throws SystemException {
208    
209                    return ddmStructureFinder.filterCountByC_G_C_N_D_S_T(
210                            companyId, groupIds, classNameIds, name, description, storageType,
211                            type, andOperator);
212            }
213    
214            public DDMStructure updateStructure(
215                            long structureId, long parentStructureId,
216                            Map<Locale, String> nameMap, Map<Locale, String> descriptionMap,
217                            String xsd, ServiceContext serviceContext)
218                    throws PortalException, SystemException {
219    
220                    DDMStructurePermission.check(
221                            getPermissionChecker(), structureId, ActionKeys.UPDATE);
222    
223                    return ddmStructureLocalService.updateStructure(
224                            structureId, parentStructureId, nameMap, descriptionMap, xsd,
225                            serviceContext);
226            }
227    
228            public DDMStructure updateStructure(
229                            long groupId, long parentStructureId, String structureKey,
230                            Map<Locale, String> nameMap, Map<Locale, String> descriptionMap,
231                            String xsd, ServiceContext serviceContext)
232                    throws PortalException, SystemException {
233    
234                    DDMStructurePermission.check(
235                            getPermissionChecker(), groupId, structureKey, ActionKeys.UPDATE);
236    
237                    return ddmStructureLocalService.updateStructure(
238                            groupId, parentStructureId, structureKey, nameMap, descriptionMap,
239                            xsd, serviceContext);
240            }
241    
242    }