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