001
014
015 package com.liferay.portlet.asset.service.impl;
016
017 import com.liferay.asset.kernel.model.AssetCategoryProperty;
018 import com.liferay.portal.kernel.exception.PortalException;
019 import com.liferay.portal.kernel.log.Log;
020 import com.liferay.portal.kernel.log.LogFactoryUtil;
021 import com.liferay.portal.kernel.security.permission.ActionKeys;
022 import com.liferay.portlet.asset.service.base.AssetCategoryPropertyServiceBaseImpl;
023 import com.liferay.portlet.asset.service.permission.AssetCategoryPermission;
024
025 import java.util.ArrayList;
026 import java.util.List;
027
028
032 public class AssetCategoryPropertyServiceImpl
033 extends AssetCategoryPropertyServiceBaseImpl {
034
035 @Override
036 public AssetCategoryProperty addCategoryProperty(
037 long entryId, String key, String value)
038 throws PortalException {
039
040 AssetCategoryPermission.check(
041 getPermissionChecker(), entryId, ActionKeys.UPDATE);
042
043 return assetCategoryPropertyLocalService.addCategoryProperty(
044 getUserId(), entryId, key, value);
045 }
046
047 @Override
048 public void deleteCategoryProperty(long categoryPropertyId)
049 throws PortalException {
050
051 AssetCategoryProperty assetCategoryProperty =
052 assetCategoryPropertyLocalService.getAssetCategoryProperty(
053 categoryPropertyId);
054
055 AssetCategoryPermission.check(
056 getPermissionChecker(), assetCategoryProperty.getCategoryId(),
057 ActionKeys.UPDATE);
058
059 assetCategoryPropertyLocalService.deleteCategoryProperty(
060 categoryPropertyId);
061 }
062
063 @Override
064 public List<AssetCategoryProperty> getCategoryProperties(long entryId) {
065 try {
066 if (AssetCategoryPermission.contains(
067 getPermissionChecker(), entryId, ActionKeys.VIEW)) {
068
069 return assetCategoryPropertyLocalService.getCategoryProperties(
070 entryId);
071 }
072 }
073 catch (PortalException pe) {
074 if (_log.isDebugEnabled()) {
075 _log.debug(
076 "Unable to get asset category property for asset entry " +
077 entryId,
078 pe);
079 }
080 }
081
082 return new ArrayList<>();
083 }
084
085 @Override
086 public List<AssetCategoryProperty> getCategoryPropertyValues(
087 long companyId, String key) {
088
089 return filterAssetCategoryProperties(
090 assetCategoryPropertyLocalService.getCategoryPropertyValues(
091 companyId, key));
092 }
093
094 @Override
095 public AssetCategoryProperty updateCategoryProperty(
096 long userId, long categoryPropertyId, String key, String value)
097 throws PortalException {
098
099 AssetCategoryProperty assetCategoryProperty =
100 assetCategoryPropertyLocalService.getAssetCategoryProperty(
101 categoryPropertyId);
102
103 AssetCategoryPermission.check(
104 getPermissionChecker(), assetCategoryProperty.getCategoryId(),
105 ActionKeys.UPDATE);
106
107 return assetCategoryPropertyLocalService.updateCategoryProperty(
108 userId, categoryPropertyId, key, value);
109 }
110
111 @Override
112 public AssetCategoryProperty updateCategoryProperty(
113 long categoryPropertyId, String key, String value)
114 throws PortalException {
115
116 return updateCategoryProperty(0, categoryPropertyId, key, value);
117 }
118
119 protected List<AssetCategoryProperty> filterAssetCategoryProperties(
120 List<AssetCategoryProperty> assetCategoryProperties) {
121
122 List<AssetCategoryProperty> filteredAssetCategoryProperties =
123 new ArrayList<>(assetCategoryProperties.size());
124
125 for (AssetCategoryProperty assetCategoryProperty :
126 assetCategoryProperties) {
127
128 try {
129 if (AssetCategoryPermission.contains(
130 getPermissionChecker(),
131 assetCategoryProperty.getCategoryId(),
132 ActionKeys.VIEW)) {
133
134 filteredAssetCategoryProperties.add(assetCategoryProperty);
135 }
136 }
137 catch (PortalException pe) {
138 continue;
139 }
140 }
141
142 return filteredAssetCategoryProperties;
143 }
144
145 private static final Log _log = LogFactoryUtil.getLog(
146 AssetCategoryPropertyServiceImpl.class);
147
148 }