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