1
14
15 package com.liferay.portlet.asset.service.impl;
16
17 import com.liferay.portal.kernel.exception.PortalException;
18 import com.liferay.portal.kernel.exception.SystemException;
19 import com.liferay.portal.kernel.json.JSONArray;
20 import com.liferay.portal.kernel.util.ListUtil;
21 import com.liferay.portal.kernel.util.OrderByComparator;
22 import com.liferay.portal.security.permission.ActionKeys;
23 import com.liferay.portal.security.permission.PermissionChecker;
24 import com.liferay.portal.service.ServiceContext;
25 import com.liferay.portlet.asset.model.AssetCategory;
26 import com.liferay.portlet.asset.service.base.AssetCategoryServiceBaseImpl;
27 import com.liferay.portlet.asset.service.permission.AssetCategoryPermission;
28
29 import java.util.Iterator;
30 import java.util.List;
31 import java.util.Locale;
32 import java.util.Map;
33
34
43 public class AssetCategoryServiceImpl extends AssetCategoryServiceBaseImpl {
44
45 public AssetCategory addCategory(
46 long parentCategoryId, Map<Locale, String> titleMap,
47 long vocabularyId, String[] categoryProperties,
48 ServiceContext serviceContext)
49 throws PortalException, SystemException {
50
51 AssetCategoryPermission.check(
52 getPermissionChecker(), serviceContext.getScopeGroupId(),
53 parentCategoryId, ActionKeys.ADD_CATEGORY);
54
55 return assetCategoryLocalService.addCategory(
56 null, getUserId(), parentCategoryId, titleMap, vocabularyId,
57 categoryProperties, serviceContext);
58 }
59
60 public void deleteCategory(long categoryId)
61 throws PortalException, SystemException {
62
63 AssetCategoryPermission.check(
64 getPermissionChecker(), categoryId, ActionKeys.DELETE);
65
66 assetCategoryLocalService.deleteCategory(categoryId);
67 }
68
69 public List<AssetCategory> getCategories(String className, long classPK)
70 throws PortalException, SystemException {
71
72 return filterCategories(
73 assetCategoryLocalService.getCategories(className, classPK));
74 }
75
76 public AssetCategory getCategory(long categoryId)
77 throws PortalException, SystemException {
78
79 AssetCategoryPermission.check(
80 getPermissionChecker(), categoryId, ActionKeys.VIEW);
81
82 return assetCategoryLocalService.getCategory(categoryId);
83 }
84
85 public List<AssetCategory> getChildCategories(
86 long parentCategoryId, int start, int end, OrderByComparator obc)
87 throws PortalException, SystemException {
88
89 return filterCategories(
90 assetCategoryLocalService.getChildCategories(
91 parentCategoryId, start, end, obc));
92 }
93
94 public List<AssetCategory> getVocabularyCategories(
95 long vocabularyId, int start, int end, OrderByComparator obc)
96 throws PortalException, SystemException {
97
98 return filterCategories(
99 assetCategoryLocalService.getVocabularyCategories(
100 vocabularyId, start, end, obc));
101 }
102
103 public List<AssetCategory> getVocabularyRootCategories(
104 long vocabularyId, int start, int end, OrderByComparator obc)
105 throws PortalException, SystemException {
106
107 return filterCategories(
108 assetCategoryLocalService.getVocabularyRootCategories(
109 vocabularyId, start, end, obc));
110 }
111
112 public JSONArray search(
113 long groupId, String name, String[] categoryProperties, int start,
114 int end)
115 throws SystemException {
116
117 return assetCategoryLocalService.search(
118 groupId, name, categoryProperties, start, end);
119 }
120
121 public AssetCategory updateCategory(
122 long categoryId, long parentCategoryId,
123 Map<Locale, String> titleMap, long vocabularyId,
124 String[] categoryProperties, ServiceContext serviceContext)
125 throws PortalException, SystemException {
126
127 AssetCategoryPermission.check(
128 getPermissionChecker(), categoryId, ActionKeys.UPDATE);
129
130 return assetCategoryLocalService.updateCategory(
131 getUserId(), categoryId, parentCategoryId, titleMap, vocabularyId,
132 categoryProperties, serviceContext);
133 }
134
135 protected List<AssetCategory> filterCategories(
136 List<AssetCategory> categories)
137 throws PortalException {
138
139 PermissionChecker permissionChecker = getPermissionChecker();
140
141 categories = ListUtil.copy(categories);
142
143 Iterator<AssetCategory> itr = categories.iterator();
144
145 while (itr.hasNext()) {
146 AssetCategory category = itr.next();
147
148 if (!AssetCategoryPermission.contains(
149 permissionChecker, category, ActionKeys.VIEW)) {
150
151 itr.remove();
152 }
153 }
154
155 return categories;
156 }
157
158 }