001    /**
002     * Copyright (c) 2000-2011 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.security.permission.ActionKeys;
020    import com.liferay.portal.service.ServiceContext;
021    import com.liferay.portlet.dynamicdatamapping.model.DDMTemplate;
022    import com.liferay.portlet.dynamicdatamapping.service.base.DDMTemplateServiceBaseImpl;
023    import com.liferay.portlet.dynamicdatamapping.service.permission.DDMPermission;
024    import com.liferay.portlet.dynamicdatamapping.service.permission.DDMTemplatePermission;
025    
026    import java.util.List;
027    import java.util.Locale;
028    import java.util.Map;
029    
030    /**
031     * @author Brian Wing Shun Chan
032     * @author Eduardo Lundgren
033     */
034    public class DDMTemplateServiceImpl extends DDMTemplateServiceBaseImpl {
035    
036            public DDMTemplate addTemplate(
037                            long groupId, long structureId, Map<Locale, String> nameMap,
038                            Map<Locale, String> descriptionMap, String type, String mode,
039                            String language, String script, ServiceContext serviceContext)
040                    throws PortalException, SystemException {
041    
042                    DDMPermission.check(
043                            getPermissionChecker(), serviceContext.getScopeGroupId(),
044                            ActionKeys.ADD_TEMPLATE);
045    
046                    return ddmTemplateLocalService.addTemplate(
047                            getUserId(), groupId, structureId, nameMap, descriptionMap, type,
048                            mode, language, script, serviceContext);
049            }
050    
051            public void deleteTemplate(long templateId)
052                    throws PortalException, SystemException {
053    
054                    DDMTemplatePermission.check(
055                            getPermissionChecker(), templateId, ActionKeys.DELETE);
056    
057                    ddmTemplateLocalService.deleteTemplate(templateId);
058            }
059    
060            public DDMTemplate getTemplate(long templateId)
061                    throws PortalException, SystemException {
062    
063                    DDMTemplatePermission.check(
064                            getPermissionChecker(), templateId, ActionKeys.VIEW);
065    
066                    return ddmTemplateLocalService.getTemplate(templateId);
067            }
068    
069            public List<DDMTemplate> getTemplates(
070                            long structureId, String type, String mode)
071                    throws SystemException {
072    
073                    return ddmTemplatePersistence.findByS_T_M(structureId, type, mode);
074            }
075    
076            public DDMTemplate updateTemplate(
077                            long templateId, Map<Locale, String> nameMap,
078                            Map<Locale, String> descriptionMap, String type, String mode,
079                            String language, String script, ServiceContext serviceContext)
080                    throws PortalException, SystemException {
081    
082                    DDMTemplatePermission.check(
083                            getPermissionChecker(), templateId, ActionKeys.UPDATE);
084    
085                    return ddmTemplateLocalService.updateTemplate(
086                            templateId, nameMap, descriptionMap, type, mode, language, script,
087                            serviceContext);
088            }
089    
090    }