001
014
015 package com.liferay.portlet.trash.service.impl;
016
017 import com.liferay.portal.kernel.dao.orm.QueryUtil;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.log.Log;
020 import com.liferay.portal.kernel.log.LogFactoryUtil;
021 import com.liferay.portal.kernel.trash.TrashHandler;
022 import com.liferay.portal.kernel.trash.TrashHandlerRegistryUtil;
023 import com.liferay.portal.kernel.util.OrderByComparator;
024 import com.liferay.portal.security.auth.PrincipalException;
025 import com.liferay.portal.security.permission.ActionKeys;
026 import com.liferay.portal.security.permission.PermissionChecker;
027 import com.liferay.portal.util.PropsValues;
028 import com.liferay.portlet.trash.model.TrashEntry;
029 import com.liferay.portlet.trash.model.TrashEntryList;
030 import com.liferay.portlet.trash.model.TrashEntrySoap;
031 import com.liferay.portlet.trash.service.base.TrashEntryServiceBaseImpl;
032
033 import java.util.ArrayList;
034 import java.util.List;
035
036
043 public class TrashEntryServiceImpl extends TrashEntryServiceBaseImpl {
044
045
053 public void deleteEntries(long groupId)
054 throws PrincipalException, SystemException {
055
056 List<TrashEntry> entries = trashEntryLocalService.getEntries(groupId);
057
058 PermissionChecker permissionChecker = getPermissionChecker();
059
060 for (TrashEntry entry : entries) {
061 String className = entry.getClassName();
062 long classPK = entry.getClassPK();
063
064 try {
065 TrashHandler trashHandler =
066 TrashHandlerRegistryUtil.getTrashHandler(className);
067
068 if (trashHandler.hasTrashPermission(
069 permissionChecker, 0, classPK, ActionKeys.DELETE)) {
070
071 trashHandler.deleteTrashEntry(classPK);
072 }
073 }
074 catch (Exception e) {
075 _log.error(e, e);
076 }
077 }
078 }
079
080
088 public TrashEntryList getEntries(long groupId)
089 throws PrincipalException, SystemException {
090
091 return getEntries(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
092 }
093
094
108 public TrashEntryList getEntries(
109 long groupId, int start, int end, OrderByComparator obc)
110 throws PrincipalException, SystemException {
111
112 TrashEntryList trashEntriesList = new TrashEntryList();
113
114 int entriesCount = trashEntryLocalService.getEntriesCount(groupId);
115
116 boolean approximate = entriesCount > PropsValues.TRASH_SEARCH_LIMIT;
117
118 trashEntriesList.setApproximate(approximate);
119
120 List<TrashEntry> entries = trashEntryLocalService.getEntries(
121 groupId, 0, end + PropsValues.TRASH_SEARCH_LIMIT, obc);
122
123 List<TrashEntry> filteredEntries = new ArrayList<TrashEntry>();
124
125 PermissionChecker permissionChecker = getPermissionChecker();
126
127 for (TrashEntry entry : entries) {
128 String className = entry.getClassName();
129 long classPK = entry.getClassPK();
130
131 try {
132 TrashHandler trashHandler =
133 TrashHandlerRegistryUtil.getTrashHandler(className);
134
135 if (trashHandler.hasTrashPermission(
136 permissionChecker, 0, classPK, ActionKeys.VIEW)) {
137
138 filteredEntries.add(entry);
139 }
140 }
141 catch (Exception e) {
142 _log.error(e, e);
143 }
144 }
145
146 int filteredEntriesCount = filteredEntries.size();
147
148 if ((end != QueryUtil.ALL_POS) && (start != QueryUtil.ALL_POS)) {
149 if (end > filteredEntriesCount) {
150 end = filteredEntriesCount;
151 }
152
153 if (start > filteredEntriesCount) {
154 start = filteredEntriesCount;
155 }
156
157 filteredEntries = filteredEntries.subList(start, end);
158 }
159
160 trashEntriesList.setArray(TrashEntrySoap.toSoapModels(filteredEntries));
161 trashEntriesList.setCount(filteredEntriesCount);
162
163 return trashEntriesList;
164 }
165
166 private static Log _log = LogFactoryUtil.getLog(
167 TrashEntryServiceImpl.class);
168
169 }