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.Map;
029    
030    /**
031     * @author Brian Wing Shun Chan
032     * @author Eduardo Lundgren
033     */
034    public class DDLRecordServiceImpl extends DDLRecordServiceBaseImpl {
035    
036            @Override
037            public DDLRecord addRecord(
038                            long groupId, long recordSetId, int displayIndex, Fields fields,
039                            ServiceContext serviceContext)
040                    throws PortalException, SystemException {
041    
042                    DDLRecordSetPermission.check(
043                            getPermissionChecker(), recordSetId, ActionKeys.ADD_RECORD);
044    
045                    return ddlRecordLocalService.addRecord(
046                            getGuestOrUserId(), groupId, recordSetId, displayIndex, fields,
047                            serviceContext);
048            }
049    
050            @Override
051            public DDLRecord addRecord(
052                            long groupId, long recordSetId, int displayIndex,
053                            Map<String, Serializable> fieldsMap, ServiceContext serviceContext)
054                    throws PortalException, SystemException {
055    
056                    DDLRecordSetPermission.check(
057                            getPermissionChecker(), recordSetId, ActionKeys.ADD_RECORD);
058    
059                    return ddlRecordLocalService.addRecord(
060                            getGuestOrUserId(), groupId, recordSetId, displayIndex, fieldsMap,
061                            serviceContext);
062            }
063    
064            @Override
065            public DDLRecord getRecord(long recordId)
066                    throws PortalException, SystemException {
067    
068                    DDLRecord record = ddlRecordLocalService.getDDLRecord(recordId);
069    
070                    DDLRecordSetPermission.check(
071                            getPermissionChecker(), record.getRecordSetId(), ActionKeys.VIEW);
072    
073                    return record;
074            }
075    
076            @Override
077            public DDLRecord updateRecord(
078                            long recordId, boolean majorVersion, int displayIndex,
079                            Fields fields, boolean mergeFields, ServiceContext serviceContext)
080                    throws PortalException, SystemException {
081    
082                    DDLRecord record = ddlRecordLocalService.getDDLRecord(recordId);
083    
084                    DDLRecordSetPermission.check(
085                            getPermissionChecker(), record.getRecordSetId(), ActionKeys.UPDATE);
086    
087                    return ddlRecordLocalService.updateRecord(
088                            getUserId(), recordId, majorVersion, displayIndex, fields,
089                            mergeFields, serviceContext);
090            }
091    
092            @Override
093            public DDLRecord updateRecord(
094                            long recordId, int displayIndex,
095                            Map<String, Serializable> fieldsMap, boolean mergeFields,
096                            ServiceContext serviceContext)
097                    throws PortalException, SystemException {
098    
099                    DDLRecord record = ddlRecordLocalService.getDDLRecord(recordId);
100    
101                    DDLRecordSetPermission.check(
102                            getPermissionChecker(), record.getRecordSetId(), ActionKeys.UPDATE);
103    
104                    return ddlRecordLocalService.updateRecord(
105                            getUserId(), recordId, displayIndex, fieldsMap, mergeFields,
106                            serviceContext);
107            }
108    
109    }