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.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            @Override
040            public DDMStructure addStructure(
041                            long groupId, long classNameId, String structureKey,
042                            Map<Locale, String> nameMap, Map<Locale, String> descriptionMap,
043                            String xsd, String storageType, int type,
044                            ServiceContext serviceContext)
045                    throws PortalException, SystemException {
046    
047                    String ddmResource = ParamUtil.getString(serviceContext, "ddmResource");
048    
049                    DDMPermission.check(
050                            getPermissionChecker(), serviceContext.getScopeGroupId(),
051                            ddmResource, ActionKeys.ADD_STRUCTURE);
052    
053                    return ddmStructureLocalService.addStructure(
054                            getUserId(), groupId, classNameId, structureKey, nameMap,
055                            descriptionMap, xsd, storageType, type, serviceContext);
056            }
057    
058            @Override
059            public DDMStructure copyStructure(
060                            long structureId, Map<Locale, String> nameMap,
061                            Map<Locale, String> descriptionMap, ServiceContext serviceContext)
062                    throws PortalException, SystemException {
063    
064                    String ddmResource = ParamUtil.getString(serviceContext, "ddmResource");
065    
066                    DDMPermission.check(
067                            getPermissionChecker(), serviceContext.getScopeGroupId(),
068                            ddmResource, ActionKeys.ADD_STRUCTURE);
069    
070                    return ddmStructureLocalService.copyStructure(
071                            getUserId(), structureId, nameMap, descriptionMap, serviceContext);
072            }
073    
074            @Override
075            public void deleteStructure(long structureId)
076                    throws PortalException, SystemException {
077    
078                    DDMStructurePermission.check(
079                            getPermissionChecker(), structureId, ActionKeys.DELETE);
080    
081                    ddmStructureLocalService.deleteStructure(structureId);
082            }
083    
084            @Override
085            public DDMStructure fetchStructure(long groupId, String structureKey)
086                    throws PortalException, SystemException {
087    
088                    DDMStructure ddmStructure = ddmStructurePersistence.fetchByG_S(
089                            groupId, structureKey);
090    
091                    if (ddmStructure != null) {
092                            DDMStructurePermission.check(
093                                    getPermissionChecker(), ddmStructure, ActionKeys.VIEW);
094                    }
095    
096                    return ddmStructure;
097            }
098    
099            @Override
100            public DDMStructure getStructure(long structureId)
101                    throws PortalException, SystemException {
102    
103                    DDMStructurePermission.check(
104                            getPermissionChecker(), structureId, ActionKeys.VIEW);
105    
106                    return ddmStructurePersistence.findByPrimaryKey(structureId);
107            }
108    
109            @Override
110            public List<DDMStructure> search(
111                            long companyId, long[] groupIds, long[] classNameIds,
112                            String keywords, int start, int end,
113                            OrderByComparator orderByComparator)
114                    throws SystemException {
115    
116                    return ddmStructureFinder.filterFindByKeywords(
117                            companyId, groupIds, classNameIds, keywords, start, end,
118                            orderByComparator);
119            }
120    
121            @Override
122            public List<DDMStructure> search(
123                            long companyId, long[] groupIds, long[] classNameIds, String name,
124                            String description, String storageType, int type,
125                            boolean andOperator, int start, int end,
126                            OrderByComparator orderByComparator)
127                    throws SystemException {
128    
129                    return ddmStructureFinder.filterFindByC_G_C_N_D_S_T(
130                            companyId, groupIds, classNameIds, name, description, storageType,
131                            type, andOperator, start, end, orderByComparator);
132            }
133    
134            @Override
135            public int searchCount(
136                            long companyId, long[] groupIds, long[] classNameIds,
137                            String keywords)
138                    throws SystemException {
139    
140                    return ddmStructureFinder.filterCountByKeywords(
141                            companyId, groupIds, classNameIds, keywords);
142            }
143    
144            @Override
145            public int searchCount(
146                            long companyId, long[] groupIds, long[] classNameIds, String name,
147                            String description, String storageType, int type,
148                            boolean andOperator)
149                    throws SystemException {
150    
151                    return ddmStructureFinder.filterCountByC_G_C_N_D_S_T(
152                            companyId, groupIds, classNameIds, name, description, storageType,
153                            type, andOperator);
154            }
155    
156            @Override
157            public DDMStructure updateStructure(
158                            long structureId, Map<Locale, String> nameMap,
159                            Map<Locale, String> descriptionMap, String xsd,
160                            ServiceContext serviceContext)
161                    throws PortalException, SystemException {
162    
163                    DDMStructurePermission.check(
164                            getPermissionChecker(), structureId, ActionKeys.UPDATE);
165    
166                    return ddmStructureLocalService.updateStructure(
167                            structureId, nameMap, descriptionMap, xsd, serviceContext);
168            }
169    
170            @Override
171            public DDMStructure updateStructure(
172                            long groupId, String structureKey, Map<Locale, String> nameMap,
173                            Map<Locale, String> descriptionMap, String xsd,
174                            ServiceContext serviceContext)
175                    throws PortalException, SystemException {
176    
177                    DDMStructurePermission.check(
178                            getPermissionChecker(), groupId, structureKey, ActionKeys.UPDATE);
179    
180                    return ddmStructureLocalService.updateStructure(
181                            groupId, structureKey, nameMap, descriptionMap, xsd,
182                            serviceContext);
183            }
184    
185    }