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.DDMStructure;
022    import com.liferay.portlet.dynamicdatamapping.service.base.DDMStructureServiceBaseImpl;
023    import com.liferay.portlet.dynamicdatamapping.service.permission.DDMPermission;
024    import com.liferay.portlet.dynamicdatamapping.service.permission.DDMStructurePermission;
025    
026    import java.util.Locale;
027    import java.util.Map;
028    
029    /**
030     * @author Brian Wing Shun Chan
031     * @author Bruno Basto
032     */
033    public class DDMStructureServiceImpl extends DDMStructureServiceBaseImpl {
034    
035            public DDMStructure addStructure(
036                            long groupId, long classNameId, String structureKey,
037                            Map<Locale, String> nameMap, Map<Locale, String> descriptionMap,
038                            String xsd, String storageType, int type,
039                            ServiceContext serviceContext)
040                    throws PortalException, SystemException {
041    
042                    DDMPermission.check(
043                            getPermissionChecker(), serviceContext.getScopeGroupId(),
044                            ActionKeys.ADD_STRUCTURE);
045    
046                    return ddmStructureLocalService.addStructure(
047                            getUserId(), groupId, classNameId, structureKey, nameMap,
048                            descriptionMap, xsd, storageType, type, serviceContext);
049            }
050    
051            public DDMStructure copyStructure(
052                            long structureId, ServiceContext serviceContext)
053                    throws PortalException, SystemException {
054    
055                    DDMPermission.check(
056                            getPermissionChecker(), serviceContext.getScopeGroupId(),
057                            ActionKeys.ADD_STRUCTURE);
058    
059                    return ddmStructureLocalService.copyStructure(
060                            getUserId(), structureId, serviceContext);
061            }
062    
063            public void deleteStructure(long structureId)
064                    throws PortalException, SystemException {
065    
066                    DDMStructurePermission.check(
067                            getPermissionChecker(), structureId, ActionKeys.DELETE);
068    
069                    ddmStructureLocalService.deleteStructure(structureId);
070            }
071    
072            public DDMStructure fetchStructure(long groupId, String structureKey)
073                    throws PortalException, SystemException {
074    
075                    DDMStructure ddmStructure = ddmStructurePersistence.fetchByG_S(
076                            groupId, structureKey);
077    
078                    if (ddmStructure != null) {
079                            DDMStructurePermission.check(
080                                    getPermissionChecker(), ddmStructure, ActionKeys.VIEW);
081                    }
082    
083                    return ddmStructure;
084            }
085    
086            public DDMStructure getStructure(long structureId)
087                    throws PortalException, SystemException {
088    
089                    DDMStructurePermission.check(
090                            getPermissionChecker(), structureId, ActionKeys.VIEW);
091    
092                    return ddmStructurePersistence.findByPrimaryKey(structureId);
093            }
094    
095            public DDMStructure updateStructure(
096                            long structureId, Map<Locale, String> nameMap,
097                            Map<Locale, String> descriptionMap, String xsd,
098                            ServiceContext serviceContext)
099                    throws PortalException, SystemException {
100    
101                    DDMStructurePermission.check(
102                            getPermissionChecker(), structureId, ActionKeys.UPDATE);
103    
104                    return ddmStructureLocalService.updateStructure(
105                            structureId, nameMap, descriptionMap, xsd, serviceContext);
106            }
107    
108            public DDMStructure updateStructure(
109                            long groupId, String structureKey, Map<Locale, String> nameMap,
110                            Map<Locale, String> descriptionMap, String xsd,
111                            ServiceContext serviceContext)
112                    throws PortalException, SystemException {
113    
114                    DDMStructurePermission.check(
115                            getPermissionChecker(), groupId, structureKey, ActionKeys.UPDATE);
116    
117                    return ddmStructureLocalService.updateStructure(
118                            groupId, structureKey, nameMap, descriptionMap, xsd,
119                            serviceContext);
120            }
121    
122    }