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            public DDLRecord addRecord(
041                            long groupId, long recordSetId, int displayIndex, Fields fields,
042                            ServiceContext serviceContext)
043                    throws PortalException, SystemException {
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            public DDLRecord addRecord(
054                            long groupId, long recordSetId, int displayIndex,
055                            Map<String, Serializable> fieldsMap, ServiceContext serviceContext)
056                    throws PortalException, SystemException {
057    
058                    DDLRecordSetPermission.check(
059                            getPermissionChecker(), recordSetId, ActionKeys.ADD_RECORD);
060    
061                    return ddlRecordLocalService.addRecord(
062                            getGuestOrUserId(), groupId, recordSetId, displayIndex, fieldsMap,
063                            serviceContext);
064            }
065    
066            public DDLRecord deleteRecordLocale(
067                            long recordId, Locale locale, ServiceContext serviceContext)
068                    throws PortalException, SystemException {
069    
070                    DDLRecord record = ddlRecordLocalService.getDDLRecord(recordId);
071    
072                    DDLRecordSetPermission.check(
073                            getPermissionChecker(), record.getRecordSetId(), ActionKeys.UPDATE);
074    
075                    return ddlRecordLocalService.deleteRecordLocale(
076                            recordId, locale, serviceContext);
077            }
078    
079            public DDLRecord getRecord(long recordId)
080                    throws PortalException, SystemException {
081    
082                    DDLRecord record = ddlRecordLocalService.getDDLRecord(recordId);
083    
084                    DDLRecordSetPermission.check(
085                            getPermissionChecker(), record.getRecordSetId(), ActionKeys.VIEW);
086    
087                    return record;
088            }
089    
090            public DDLRecord updateRecord(
091                            long recordId, boolean majorVersion, int displayIndex,
092                            Fields fields, boolean mergeFields, ServiceContext serviceContext)
093                    throws PortalException, SystemException {
094    
095                    DDLRecord record = ddlRecordLocalService.getDDLRecord(recordId);
096    
097                    DDLRecordSetPermission.check(
098                            getPermissionChecker(), record.getRecordSetId(), ActionKeys.UPDATE);
099    
100                    return ddlRecordLocalService.updateRecord(
101                            getUserId(), recordId, majorVersion, displayIndex, fields,
102                            mergeFields, serviceContext);
103            }
104    
105            public DDLRecord updateRecord(
106                            long recordId, int displayIndex,
107                            Map<String, Serializable> fieldsMap, boolean mergeFields,
108                            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                    return ddlRecordLocalService.updateRecord(
117                            getUserId(), recordId, displayIndex, fieldsMap, mergeFields,
118                            serviceContext);
119            }
120    
121    }