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.asset.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.portlet.asset.model.AssetTagProperty;
021    import com.liferay.portlet.asset.service.base.AssetTagPropertyServiceBaseImpl;
022    import com.liferay.portlet.asset.service.permission.AssetTagPermission;
023    
024    import java.util.List;
025    
026    /**
027     * Provides the remote service for accessing, adding, deleting, and updating
028     * asset tag properties. Its methods include permission checks.
029     *
030     * @author Brian Wing Shun Chan
031     */
032    public class AssetTagPropertyServiceImpl
033            extends AssetTagPropertyServiceBaseImpl {
034    
035            /**
036             * Adds an asset tag property.
037             *
038             * @param  tagId the primary key of the tag
039             * @param  key the key to be associated to the value
040             * @param  value the value to which the key will refer
041             * @return the created asset tag property
042             * @throws PortalException if the user did not have permission to update the
043             *         asset tag, or if the key or value were invalid
044             * @throws SystemException if a system exception occurred
045             */
046            public AssetTagProperty addTagProperty(long tagId, String key, String value)
047                    throws PortalException, SystemException {
048    
049                    AssetTagPermission.check(
050                            getPermissionChecker(), tagId, ActionKeys.UPDATE);
051    
052                    return assetTagPropertyLocalService.addTagProperty(
053                            getUserId(), tagId, key, value);
054            }
055    
056            /**
057             * Deletes the asset tag property with the specified ID.
058             *
059             * @param  tagPropertyId the primary key of the asset tag property instance
060             * @throws PortalException if an asset tag property with the primary key
061             *         could not be found or if the user did not have permission to
062             *         update the asset tag property
063             * @throws SystemException if a system exception occurred
064             */
065            public void deleteTagProperty(long tagPropertyId)
066                    throws PortalException, SystemException {
067    
068                    AssetTagProperty assetTagProperty =
069                            assetTagPropertyLocalService.getTagProperty(tagPropertyId);
070    
071                    AssetTagPermission.check(
072                            getPermissionChecker(), assetTagProperty.getTagId(),
073                            ActionKeys.UPDATE);
074    
075                    assetTagPropertyLocalService.deleteTagProperty(tagPropertyId);
076            }
077    
078            /**
079             * Returns all the asset tag property instances with the specified tag ID.
080             *
081             * @param  tagId the primary key of the tag
082             * @return the matching asset tag properties
083             * @throws SystemException if a system exception occurred
084             */
085            public List<AssetTagProperty> getTagProperties(long tagId)
086                    throws SystemException {
087    
088                    return assetTagPropertyLocalService.getTagProperties(tagId);
089            }
090    
091            /**
092             * Returns asset tag properties with the specified group and key.
093             *
094             * @param  companyId the primary key of the company
095             * @param  key the key that refers to some value
096             * @return the matching asset tag properties
097             * @throws SystemException if a system exception occurred
098             */
099            public List<AssetTagProperty> getTagPropertyValues(
100                            long companyId, String key)
101                    throws SystemException {
102    
103                    return assetTagPropertyLocalService.getTagPropertyValues(
104                            companyId, key);
105            }
106    
107            /**
108             * Updates the asset tag property.
109             *
110             * @param  tagPropertyId the primary key of the asset tag property
111             * @param  key the new key to be associated to the value
112             * @param  value the new value to which the key will refer
113             * @return the updated asset tag property
114             * @throws PortalException if an asset tag property with the primary key
115             *         could not be found, if the user did not have permission to update
116             *         the asset tag, or if the key or value were invalid
117             * @throws SystemException if a system exception occurred
118             */
119            public AssetTagProperty updateTagProperty(
120                            long tagPropertyId, String key, String value)
121                    throws PortalException, SystemException {
122    
123                    AssetTagProperty assetTagProperty =
124                            assetTagPropertyLocalService.getTagProperty(tagPropertyId);
125    
126                    AssetTagPermission.check(
127                            getPermissionChecker(), assetTagProperty.getTagId(),
128                            ActionKeys.UPDATE);
129    
130                    return assetTagPropertyLocalService.updateTagProperty(
131                            tagPropertyId, key, value);
132            }
133    
134    }