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