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.security.permission.ActionKeys;
021    import com.liferay.portal.service.ServiceContext;
022    import com.liferay.portlet.dynamicdatamapping.model.DDMTemplate;
023    import com.liferay.portlet.dynamicdatamapping.service.base.DDMTemplateServiceBaseImpl;
024    import com.liferay.portlet.dynamicdatamapping.service.permission.DDMPermission;
025    import com.liferay.portlet.dynamicdatamapping.service.permission.DDMTemplatePermission;
026    
027    import java.util.List;
028    import java.util.Locale;
029    import java.util.Map;
030    
031    /**
032     * @author Brian Wing Shun Chan
033     * @author Eduardo Lundgren
034     */
035    public class DDMTemplateServiceImpl extends DDMTemplateServiceBaseImpl {
036    
037            public DDMTemplate addTemplate(
038                            long groupId, long structureId, Map<Locale, String> nameMap,
039                            Map<Locale, String> descriptionMap, String type, String mode,
040                            String language, String script, ServiceContext serviceContext)
041                    throws PortalException, SystemException {
042    
043                    String ddmResource = GetterUtil.getString(
044                            serviceContext.getAttribute("ddmResource"));
045    
046                    DDMPermission.check(
047                            getPermissionChecker(), serviceContext.getScopeGroupId(),
048                            ddmResource, ActionKeys.ADD_TEMPLATE);
049    
050                    return ddmTemplateLocalService.addTemplate(
051                            getUserId(), groupId, structureId, nameMap, descriptionMap, type,
052                            mode, language, script, serviceContext);
053            }
054    
055            public List<DDMTemplate> copyTemplates(
056                            long structureId, long newStructureId, String type,
057                            ServiceContext serviceContext)
058                    throws PortalException, SystemException {
059    
060                    String ddmResource = GetterUtil.getString(
061                            serviceContext.getAttribute("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 DDMTemplate updateTemplate(
097                            long templateId, Map<Locale, String> nameMap,
098                            Map<Locale, String> descriptionMap, String type, String mode,
099                            String language, String script, ServiceContext serviceContext)
100                    throws PortalException, SystemException {
101    
102                    DDMTemplatePermission.check(
103                            getPermissionChecker(), templateId, ActionKeys.UPDATE);
104    
105                    return ddmTemplateLocalService.updateTemplate(
106                            templateId, nameMap, descriptionMap, type, mode, language, script,
107                            serviceContext);
108            }
109    
110    }