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 DDLRecord deleteRecordLocale(
070                            long recordId, Locale locale, ServiceContext serviceContext)
071                    throws PortalException, SystemException {
072    
073                    DDLRecord record = ddlRecordLocalService.getDDLRecord(recordId);
074    
075                    DDLRecordSetPermission.check(
076                            getPermissionChecker(), record.getRecordSetId(), ActionKeys.UPDATE);
077    
078                    return ddlRecordLocalService.deleteRecordLocale(
079                            recordId, locale, serviceContext);
080            }
081    
082            @Override
083            public DDLRecord getRecord(long recordId)
084                    throws PortalException, SystemException {
085    
086                    DDLRecord record = ddlRecordLocalService.getDDLRecord(recordId);
087    
088                    DDLRecordSetPermission.check(
089                            getPermissionChecker(), record.getRecordSetId(), ActionKeys.VIEW);
090    
091                    return record;
092            }
093    
094            @Override
095            public DDLRecord updateRecord(
096                            long recordId, boolean majorVersion, int displayIndex,
097                            Fields fields, boolean mergeFields, ServiceContext serviceContext)
098                    throws PortalException, SystemException {
099    
100                    DDLRecord record = ddlRecordLocalService.getDDLRecord(recordId);
101    
102                    DDLRecordSetPermission.check(
103                            getPermissionChecker(), record.getRecordSetId(), ActionKeys.UPDATE);
104    
105                    return ddlRecordLocalService.updateRecord(
106                            getUserId(), recordId, majorVersion, displayIndex, fields,
107                            mergeFields, serviceContext);
108            }
109    
110            @Override
111            public DDLRecord updateRecord(
112                            long recordId, int displayIndex,
113                            Map<String, Serializable> fieldsMap, boolean mergeFields,
114                            ServiceContext serviceContext)
115                    throws PortalException, SystemException {
116    
117                    DDLRecord record = ddlRecordLocalService.getDDLRecord(recordId);
118    
119                    DDLRecordSetPermission.check(
120                            getPermissionChecker(), record.getRecordSetId(), ActionKeys.UPDATE);
121    
122                    return ddlRecordLocalService.updateRecord(
123                            getUserId(), recordId, displayIndex, fieldsMap, mergeFields,
124                            serviceContext);
125            }
126    
127    }