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