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