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