001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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 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 = ParamUtil.getString(serviceContext, "ddmResource");
047    
048                    DDMPermission.check(
049                            getPermissionChecker(), serviceContext.getScopeGroupId(),
050                            ddmResource, ActionKeys.ADD_STRUCTURE);
051    
052                    return ddmStructureLocalService.addStructure(
053                            getUserId(), groupId, classNameId, structureKey, nameMap,
054                            descriptionMap, xsd, storageType, type, serviceContext);
055            }
056    
057            public DDMStructure copyStructure(
058                            long structureId, Map<Locale, String> nameMap,
059                            Map<Locale, String> descriptionMap, ServiceContext serviceContext)
060                    throws PortalException, SystemException {
061    
062                    String ddmResource = ParamUtil.getString(serviceContext, "ddmResource");
063    
064                    DDMPermission.check(
065                            getPermissionChecker(), serviceContext.getScopeGroupId(),
066                            ddmResource, ActionKeys.ADD_STRUCTURE);
067    
068                    return ddmStructureLocalService.copyStructure(
069                            getUserId(), structureId, nameMap, descriptionMap, serviceContext);
070            }
071    
072            public void deleteStructure(long structureId)
073                    throws PortalException, SystemException {
074    
075                    DDMStructurePermission.check(
076                            getPermissionChecker(), structureId, ActionKeys.DELETE);
077    
078                    ddmStructureLocalService.deleteStructure(structureId);
079            }
080    
081            public DDMStructure fetchStructure(long groupId, String structureKey)
082                    throws PortalException, SystemException {
083    
084                    DDMStructure ddmStructure = ddmStructurePersistence.fetchByG_S(
085                            groupId, structureKey);
086    
087                    if (ddmStructure != null) {
088                            DDMStructurePermission.check(
089                                    getPermissionChecker(), ddmStructure, ActionKeys.VIEW);
090                    }
091    
092                    return ddmStructure;
093            }
094    
095            public DDMStructure getStructure(long structureId)
096                    throws PortalException, SystemException {
097    
098                    DDMStructurePermission.check(
099                            getPermissionChecker(), structureId, ActionKeys.VIEW);
100    
101                    return ddmStructurePersistence.findByPrimaryKey(structureId);
102            }
103    
104            public List<DDMStructure> search(
105                            long companyId, long[] groupIds, long[] classNameIds,
106                            String keywords, int start, int end,
107                            OrderByComparator orderByComparator)
108                    throws SystemException {
109    
110                    return ddmStructureFinder.filterFindByKeywords(
111                            companyId, groupIds, classNameIds, keywords, start, end,
112                            orderByComparator);
113            }
114    
115            public List<DDMStructure> search(
116                            long companyId, long[] groupIds, long[] classNameIds, String name,
117                            String description, String storageType, int type,
118                            boolean andOperator, int start, int end,
119                            OrderByComparator orderByComparator)
120                    throws SystemException {
121    
122                    return ddmStructureFinder.filterFindByC_G_C_N_D_S_T(
123                            companyId, groupIds, classNameIds, name, description, storageType,
124                            type, andOperator, start, end, orderByComparator);
125            }
126    
127            public int searchCount(
128                            long companyId, long[] groupIds, long[] classNameIds,
129                            String keywords)
130                    throws SystemException {
131    
132                    return ddmStructureFinder.filterCountByKeywords(
133                            companyId, groupIds, classNameIds, keywords);
134            }
135    
136            public int searchCount(
137                            long companyId, long[] groupIds, long[] classNameIds, String name,
138                            String description, String storageType, int type,
139                            boolean andOperator)
140                    throws SystemException {
141    
142                    return ddmStructureFinder.filterCountByC_G_C_N_D_S_T(
143                            companyId, groupIds, classNameIds, name, description, storageType,
144                            type, andOperator);
145            }
146    
147            public DDMStructure updateStructure(
148                            long structureId, Map<Locale, String> nameMap,
149                            Map<Locale, String> descriptionMap, String xsd,
150                            ServiceContext serviceContext)
151                    throws PortalException, SystemException {
152    
153                    DDMStructurePermission.check(
154                            getPermissionChecker(), structureId, ActionKeys.UPDATE);
155    
156                    return ddmStructureLocalService.updateStructure(
157                            structureId, nameMap, descriptionMap, xsd, serviceContext);
158            }
159    
160            public DDMStructure updateStructure(
161                            long groupId, String structureKey, Map<Locale, String> nameMap,
162                            Map<Locale, String> descriptionMap, String xsd,
163                            ServiceContext serviceContext)
164                    throws PortalException, SystemException {
165    
166                    DDMStructurePermission.check(
167                            getPermissionChecker(), groupId, structureKey, ActionKeys.UPDATE);
168    
169                    return ddmStructureLocalService.updateStructure(
170                            groupId, structureKey, nameMap, descriptionMap, xsd,
171                            serviceContext);
172            }
173    
174    }