001    /**
002     * Copyright (c) 2000-2013 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.dynamicdatalists.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.dynamicdatalists.model.DDLRecord;
022    import com.liferay.portlet.dynamicdatalists.service.base.DDLRecordServiceBaseImpl;
023    import com.liferay.portlet.dynamicdatalists.service.permission.DDLRecordSetPermission;
024    import com.liferay.portlet.dynamicdatamapping.storage.Fields;
025    
026    import java.io.Serializable;
027    
028    import java.util.Locale;
029    import java.util.Map;
030    
031    /**
032     * Provides the remote service for accessing, adding, deleting, and updating
033     * dynamic data list (DDL) records. Its methods include permission checks.
034     *
035     * @author Brian Wing Shun Chan
036     * @author Eduardo Lundgren
037     */
038    public class DDLRecordServiceImpl extends DDLRecordServiceBaseImpl {
039    
040            @Override
041            public DDLRecord addRecord(
042                            long groupId, long recordSetId, int displayIndex, Fields fields,
043                            ServiceContext serviceContext)
044                    throws PortalException, SystemException {
045    
046                    DDLRecordSetPermission.check(
047                            getPermissionChecker(), recordSetId, ActionKeys.ADD_RECORD);
048    
049                    return ddlRecordLocalService.addRecord(
050                            getGuestOrUserId(), groupId, recordSetId, displayIndex, fields,
051                            serviceContext);
052            }
053    
054            @Override
055            public DDLRecord addRecord(
056                            long groupId, long recordSetId, int displayIndex,
057                            Map<String, Serializable> fieldsMap, ServiceContext serviceContext)
058                    throws PortalException, SystemException {
059    
060                    DDLRecordSetPermission.check(
061                            getPermissionChecker(), recordSetId, ActionKeys.ADD_RECORD);
062    
063                    return ddlRecordLocalService.addRecord(
064                            getGuestOrUserId(), groupId, recordSetId, displayIndex, fieldsMap,
065                            serviceContext);
066            }
067    
068            @Override
069            public void deleteRecord(long recordId)
070                    throws PortalException, SystemException {
071    
072                    DDLRecord record = ddlRecordLocalService.getDDLRecord(recordId);
073    
074                    DDLRecordSetPermission.check(
075                            getPermissionChecker(), record.getRecordSetId(), ActionKeys.DELETE);
076    
077                    ddlRecordLocalService.deleteRecord(record);
078            }
079    
080            @Override
081            public DDLRecord deleteRecordLocale(
082                            long recordId, Locale locale, ServiceContext serviceContext)
083                    throws PortalException, SystemException {
084    
085                    DDLRecord record = ddlRecordLocalService.getDDLRecord(recordId);
086    
087                    DDLRecordSetPermission.check(
088                            getPermissionChecker(), record.getRecordSetId(), ActionKeys.UPDATE);
089    
090                    return ddlRecordLocalService.deleteRecordLocale(
091                            recordId, locale, serviceContext);
092            }
093    
094            @Override
095            public DDLRecord getRecord(long recordId)
096                    throws PortalException, SystemException {
097    
098                    DDLRecord record = ddlRecordLocalService.getDDLRecord(recordId);
099    
100                    DDLRecordSetPermission.check(
101                            getPermissionChecker(), record.getRecordSetId(), ActionKeys.VIEW);
102    
103                    return record;
104            }
105    
106            @Override
107            public void revertRecordVersion(
108                            long recordId, String version, ServiceContext serviceContext)
109                    throws PortalException, SystemException {
110    
111                    DDLRecord record = ddlRecordLocalService.getDDLRecord(recordId);
112    
113                    DDLRecordSetPermission.check(
114                            getPermissionChecker(), record.getRecordSetId(), ActionKeys.UPDATE);
115    
116                    ddlRecordLocalService.revertRecordVersion(
117                            getGuestOrUserId(), recordId, version, serviceContext);
118            }
119    
120            @Override
121            public DDLRecord updateRecord(
122                            long recordId, boolean majorVersion, int displayIndex,
123                            Fields fields, boolean mergeFields, ServiceContext serviceContext)
124                    throws PortalException, SystemException {
125    
126                    DDLRecord record = ddlRecordLocalService.getDDLRecord(recordId);
127    
128                    DDLRecordSetPermission.check(
129                            getPermissionChecker(), record.getRecordSetId(), ActionKeys.UPDATE);
130    
131                    return ddlRecordLocalService.updateRecord(
132                            getUserId(), recordId, majorVersion, displayIndex, fields,
133                            mergeFields, serviceContext);
134            }
135    
136            @Override
137            public DDLRecord updateRecord(
138                            long recordId, int displayIndex,
139                            Map<String, Serializable> fieldsMap, boolean mergeFields,
140                            ServiceContext serviceContext)
141                    throws PortalException, SystemException {
142    
143                    DDLRecord record = ddlRecordLocalService.getDDLRecord(recordId);
144    
145                    DDLRecordSetPermission.check(
146                            getPermissionChecker(), record.getRecordSetId(), ActionKeys.UPDATE);
147    
148                    return ddlRecordLocalService.updateRecord(
149                            getUserId(), recordId, displayIndex, fieldsMap, mergeFields,
150                            serviceContext);
151            }
152    
153    }