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