001    /**
002     * Copyright (c) 2000-2012 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            public DDLRecord addRecord(
037                            long groupId, long recordSetId, int displayIndex, Fields fields,
038                            ServiceContext serviceContext)
039                    throws PortalException, SystemException {
040    
041                    DDLRecordSetPermission.check(
042                            getPermissionChecker(), recordSetId, ActionKeys.ADD_RECORD);
043    
044                    return ddlRecordLocalService.addRecord(
045                            getUserId(), groupId, recordSetId, displayIndex, fields,
046                            serviceContext);
047            }
048    
049            public DDLRecord addRecord(
050                            long groupId, long recordSetId, int displayIndex,
051                            Map<String, Serializable> fieldsMap, ServiceContext serviceContext)
052                    throws PortalException, SystemException {
053    
054                    DDLRecordSetPermission.check(
055                            getPermissionChecker(), recordSetId, ActionKeys.ADD_RECORD);
056    
057                    return ddlRecordLocalService.addRecord(
058                            getUserId(), groupId, recordSetId, displayIndex, fieldsMap,
059                            serviceContext);
060            }
061    
062            public DDLRecord getRecord(long recordId)
063                    throws PortalException, SystemException {
064    
065                    DDLRecord record = ddlRecordLocalService.getDDLRecord(recordId);
066    
067                    DDLRecordSetPermission.check(
068                            getPermissionChecker(), record.getRecordSetId(), ActionKeys.VIEW);
069    
070                    return record;
071            }
072    
073            public DDLRecord updateRecord(
074                            long recordId, boolean majorVersion, int displayIndex,
075                            Fields fields, boolean mergeFields, ServiceContext serviceContext)
076                    throws PortalException, SystemException {
077    
078                    DDLRecord record = ddlRecordLocalService.getDDLRecord(recordId);
079    
080                    DDLRecordSetPermission.check(
081                            getPermissionChecker(), record.getRecordSetId(), ActionKeys.UPDATE);
082    
083                    return ddlRecordLocalService.updateRecord(
084                            getUserId(), recordId, majorVersion, displayIndex, fields,
085                            mergeFields, serviceContext);
086            }
087    
088            public DDLRecord updateRecord(
089                            long recordId, int displayIndex,
090                            Map<String, Serializable> fieldsMap, boolean mergeFields,
091                            ServiceContext serviceContext)
092                    throws PortalException, SystemException {
093    
094                    DDLRecord record = ddlRecordLocalService.getDDLRecord(recordId);
095    
096                    DDLRecordSetPermission.check(
097                            getPermissionChecker(), record.getRecordSetId(), ActionKeys.UPDATE);
098    
099                    return ddlRecordLocalService.updateRecord(
100                            getUserId(), recordId, displayIndex, fieldsMap, mergeFields,
101                            serviceContext);
102            }
103    
104    }