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 groupId, long parentStructureId, long classNameId,
041                            String structureKey, Map<Locale, String> nameMap,
042                            Map<Locale, String> descriptionMap, String xsd, String storageType,
043                            int type, 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, parentStructureId, classNameId, structureKey,
054                            nameMap, 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, long parentStructureId,
149                            Map<Locale, String> nameMap, Map<Locale, String> descriptionMap,
150                            String xsd, ServiceContext serviceContext)
151                    throws PortalException, SystemException {
152    
153                    DDMStructurePermission.check(
154                            getPermissionChecker(), structureId, ActionKeys.UPDATE);
155    
156                    return ddmStructureLocalService.updateStructure(
157                            structureId, parentStructureId, nameMap, descriptionMap, xsd,
158                            serviceContext);
159            }
160    
161            public DDMStructure updateStructure(
162                            long groupId, long parentStructureId, String structureKey,
163                            Map<Locale, String> nameMap, Map<Locale, String> descriptionMap,
164                            String xsd, ServiceContext serviceContext)
165                    throws PortalException, SystemException {
166    
167                    DDMStructurePermission.check(
168                            getPermissionChecker(), groupId, structureKey, ActionKeys.UPDATE);
169    
170                    return ddmStructureLocalService.updateStructure(
171                            groupId, parentStructureId, structureKey, nameMap, descriptionMap,
172                            xsd, serviceContext);
173            }
174    
175    }