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.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            public DDMTemplate addTemplate(
040                            long groupId, long structureId, Map<Locale, String> nameMap,
041                            Map<Locale, String> descriptionMap, String type, String mode,
042                            String language, String script, ServiceContext serviceContext)
043                    throws PortalException, SystemException {
044    
045                    String ddmResource = GetterUtil.getString(
046                            serviceContext.getAttribute("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            public List<DDMTemplate> copyTemplates(
058                            long structureId, long newStructureId, String type,
059                            ServiceContext serviceContext)
060                    throws PortalException, SystemException {
061    
062                    String ddmResource = GetterUtil.getString(
063                            serviceContext.getAttribute("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            public void deleteTemplate(long templateId)
074                    throws PortalException, SystemException {
075    
076                    DDMTemplatePermission.check(
077                            getPermissionChecker(), templateId, ActionKeys.DELETE);
078    
079                    ddmTemplateLocalService.deleteTemplate(templateId);
080            }
081    
082            public DDMTemplate getTemplate(long templateId)
083                    throws PortalException, SystemException {
084    
085                    DDMTemplatePermission.check(
086                            getPermissionChecker(), templateId, ActionKeys.VIEW);
087    
088                    return ddmTemplateLocalService.getTemplate(templateId);
089            }
090    
091            public List<DDMTemplate> getTemplates(
092                            long structureId, String type, String mode)
093                    throws SystemException {
094    
095                    return ddmTemplatePersistence.findByS_T_M(structureId, type, mode);
096            }
097    
098            public List<DDMTemplate> search(
099                            long companyId, long groupId, long structureId, String keywords,
100                            String type, String mode, int start, int end,
101                            OrderByComparator orderByComparator)
102                    throws SystemException {
103    
104                    return ddmTemplateFinder.filterFindByKeywords(
105                            companyId, groupId, structureId, keywords, type, mode, start, end,
106                            orderByComparator);
107            }
108    
109            public List<DDMTemplate> search(
110                            long companyId, long groupId, long structureId, String name,
111                            String description, String type, String mode, String language,
112                            boolean andOperator, int start, int end,
113                            OrderByComparator orderByComparator)
114                    throws SystemException {
115    
116                    return ddmTemplateFinder.filterFindByC_G_S_N_D_T_M_L(
117                            companyId, groupId, structureId, name, description, type, mode,
118                            language, andOperator, start, end, orderByComparator);
119            }
120    
121            public int searchCount(
122                            long companyId, long groupId, long structureId, String keywords,
123                            String type, String mode)
124                    throws SystemException {
125    
126                    return ddmTemplateFinder.filterCountByKeywords(
127                            companyId, groupId, structureId, keywords, type, mode);
128            }
129    
130            public int searchCount(
131                            long companyId, long groupId, long structureId, String name,
132                            String description, String type, String mode, String language,
133                            boolean andOperator)
134                    throws SystemException {
135    
136                    return ddmTemplateFinder.filterCountByC_G_S_N_D_T_M_L(
137                            companyId, groupId, structureId, name, description, type, mode,
138                            language, andOperator);
139            }
140    
141            public DDMTemplate updateTemplate(
142                            long templateId, Map<Locale, String> nameMap,
143                            Map<Locale, String> descriptionMap, String type, String mode,
144                            String language, String script, ServiceContext serviceContext)
145                    throws PortalException, SystemException {
146    
147                    DDMTemplatePermission.check(
148                            getPermissionChecker(), templateId, ActionKeys.UPDATE);
149    
150                    return ddmTemplateLocalService.updateTemplate(
151                            templateId, nameMap, descriptionMap, type, mode, language, script,
152                            serviceContext);
153            }
154    
155    }