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.DDMTemplate;
024    import com.liferay.portlet.dynamicdatamapping.service.base.DDMTemplateServiceBaseImpl;
025    import com.liferay.portlet.dynamicdatamapping.service.permission.DDMPermission;
026    import com.liferay.portlet.dynamicdatamapping.service.permission.DDMTemplatePermission;
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 Eduardo Lundgren
035     * @author Marcellus Tavares
036     */
037    public class DDMTemplateServiceImpl extends DDMTemplateServiceBaseImpl {
038    
039            @Override
040            public DDMTemplate addTemplate(
041                            long groupId, long structureId, Map<Locale, String> nameMap,
042                            Map<Locale, String> descriptionMap, String type, String mode,
043                            String language, String script, 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_TEMPLATE);
051    
052                    return ddmTemplateLocalService.addTemplate(
053                            getUserId(), groupId, structureId, nameMap, descriptionMap, type,
054                            mode, language, script, serviceContext);
055            }
056    
057            @Override
058            public List<DDMTemplate> copyTemplates(
059                            long structureId, long newStructureId, String type,
060                            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_TEMPLATE);
068    
069                    return ddmTemplateLocalService.copyTemplates(
070                            getUserId(), structureId, newStructureId, type, serviceContext);
071            }
072    
073            @Override
074            public void deleteTemplate(long templateId)
075                    throws PortalException, SystemException {
076    
077                    DDMTemplatePermission.check(
078                            getPermissionChecker(), templateId, ActionKeys.DELETE);
079    
080                    ddmTemplateLocalService.deleteTemplate(templateId);
081            }
082    
083            @Override
084            public DDMTemplate getTemplate(long templateId)
085                    throws PortalException, SystemException {
086    
087                    DDMTemplatePermission.check(
088                            getPermissionChecker(), templateId, ActionKeys.VIEW);
089    
090                    return ddmTemplateLocalService.getTemplate(templateId);
091            }
092    
093            @Override
094            public List<DDMTemplate> getTemplates(
095                            long structureId, String type, String mode)
096                    throws SystemException {
097    
098                    return ddmTemplatePersistence.findByS_T_M(structureId, type, mode);
099            }
100    
101            @Override
102            public List<DDMTemplate> search(
103                            long companyId, long groupId, long structureId, String keywords,
104                            String type, String mode, int start, int end,
105                            OrderByComparator orderByComparator)
106                    throws SystemException {
107    
108                    return ddmTemplateFinder.filterFindByKeywords(
109                            companyId, groupId, structureId, keywords, type, mode, start, end,
110                            orderByComparator);
111            }
112    
113            @Override
114            public List<DDMTemplate> search(
115                            long companyId, long groupId, long structureId, String name,
116                            String description, String type, String mode, String language,
117                            boolean andOperator, int start, int end,
118                            OrderByComparator orderByComparator)
119                    throws SystemException {
120    
121                    return ddmTemplateFinder.filterFindByC_G_S_N_D_T_M_L(
122                            companyId, groupId, structureId, name, description, type, mode,
123                            language, andOperator, start, end, orderByComparator);
124            }
125    
126            @Override
127            public int searchCount(
128                            long companyId, long groupId, long structureId, String keywords,
129                            String type, String mode)
130                    throws SystemException {
131    
132                    return ddmTemplateFinder.filterCountByKeywords(
133                            companyId, groupId, structureId, keywords, type, mode);
134            }
135    
136            @Override
137            public int searchCount(
138                            long companyId, long groupId, long structureId, String name,
139                            String description, String type, String mode, String language,
140                            boolean andOperator)
141                    throws SystemException {
142    
143                    return ddmTemplateFinder.filterCountByC_G_S_N_D_T_M_L(
144                            companyId, groupId, structureId, name, description, type, mode,
145                            language, andOperator);
146            }
147    
148            @Override
149            public DDMTemplate updateTemplate(
150                            long templateId, Map<Locale, String> nameMap,
151                            Map<Locale, String> descriptionMap, String type, String mode,
152                            String language, String script, ServiceContext serviceContext)
153                    throws PortalException, SystemException {
154    
155                    DDMTemplatePermission.check(
156                            getPermissionChecker(), templateId, ActionKeys.UPDATE);
157    
158                    return ddmTemplateLocalService.updateTemplate(
159                            templateId, nameMap, descriptionMap, type, mode, language, script,
160                            serviceContext);
161            }
162    
163    }