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