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.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     * The implementation of the asset tag property service.
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             * @throws SystemException if a system exception occurred
044             */
045            public AssetTagProperty addTagProperty(long tagId, String key, String value)
046                    throws PortalException, SystemException {
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             * @throws SystemException if a system exception occurred
063             */
064            public void deleteTagProperty(long tagPropertyId)
065                    throws PortalException, SystemException {
066    
067                    AssetTagProperty assetTagProperty =
068                            assetTagPropertyLocalService.getTagProperty(tagPropertyId);
069    
070                    AssetTagPermission.check(
071                            getPermissionChecker(), assetTagProperty.getTagId(),
072                            ActionKeys.UPDATE);
073    
074                    assetTagPropertyLocalService.deleteTagProperty(tagPropertyId);
075            }
076    
077            /**
078             * Returns all the asset tag property instances with the specified tag ID.
079             *
080             * @param  tagId the primary key of the tag
081             * @return the matching asset tag properties
082             * @throws SystemException if a system exception occurred
083             */
084            public List<AssetTagProperty> getTagProperties(long tagId)
085                    throws SystemException {
086    
087                    return assetTagPropertyLocalService.getTagProperties(tagId);
088            }
089    
090            /**
091             * Returns asset tag properties with the specified group and key.
092             *
093             * @param  companyId the primary key of the company
094             * @param  key the key that refers to some value
095             * @return the matching asset tag properties
096             * @throws SystemException if a system exception occurred
097             */
098            public List<AssetTagProperty> getTagPropertyValues(
099                            long companyId, String key)
100                    throws SystemException {
101    
102                    return assetTagPropertyLocalService.getTagPropertyValues(
103                            companyId, key);
104            }
105    
106            /**
107             * Updates the asset tag property.
108             *
109             * @param  tagPropertyId the primary key of the asset tag property
110             * @param  key the new key to be associated to the value
111             * @param  value the new value to which the key will refer
112             * @return the updated asset tag property
113             * @throws PortalException if an asset tag property with the primary key
114             *         could not be found, if the user did not have permission to update
115             *         the asset tag, or if the key or value were invalid
116             * @throws SystemException if a system exception occurred
117             */
118            public AssetTagProperty updateTagProperty(
119                            long tagPropertyId, String key, String value)
120                    throws PortalException, SystemException {
121    
122                    AssetTagProperty assetTagProperty =
123                            assetTagPropertyLocalService.getTagProperty(tagPropertyId);
124    
125                    AssetTagPermission.check(
126                            getPermissionChecker(), assetTagProperty.getTagId(),
127                            ActionKeys.UPDATE);
128    
129                    return assetTagPropertyLocalService.updateTagProperty(
130                            tagPropertyId, key, value);
131            }
132    
133    }