forked from liferay/liferay-portal
/
TrashEntryServiceImpl.java
156 lines (127 loc) · 4.98 KB
/
TrashEntryServiceImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/**
* Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portlet.trash.service.impl;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.trash.TrashHandler;
import com.liferay.portal.kernel.trash.TrashHandlerRegistryUtil;
import com.liferay.portal.kernel.trash.TrashRenderer;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.security.auth.PrincipalException;
import com.liferay.portal.security.permission.PermissionChecker;
import com.liferay.portal.util.PropsValues;
import com.liferay.portlet.trash.model.TrashEntry;
import com.liferay.portlet.trash.service.base.TrashEntryServiceBaseImpl;
import java.util.ArrayList;
import java.util.List;
/**
* The trash entry remote service is responsible for returning trash entries.
* For more information on trash entries services and TrashEntry, see {@link
* com.liferay.portlet.trash.service.impl.TrashEntryLocalServiceImpl}.
*
* @author Julio Camarero
*/
public class TrashEntryServiceImpl extends TrashEntryServiceBaseImpl {
/**
* Deletes the trash entries with the matching group ID considering
* permissions.
*
* @param groupId the primary key of the group
* @throws SystemException if a system exception occurred
* @throws PrincipalException if a principal exception occurred
*/
public void deleteEntries(long groupId)
throws SystemException, PrincipalException {
List<TrashEntry> entries = trashEntryLocalService.getEntries(groupId);
PermissionChecker permissionChecker = getPermissionChecker();
for (TrashEntry entry : entries) {
String className = entry.getClassName();
long classPK = entry.getClassPK();
try {
TrashHandler trashHandler =
TrashHandlerRegistryUtil.getTrashHandler(className);
TrashRenderer trashRenderer = trashHandler.getTrashRenderer(
classPK);
if (trashRenderer.hasDeletePermission(permissionChecker)) {
trashHandler.deleteTrashEntry(classPK);
}
}
catch (Exception e) {
}
}
}
/**
* Returns the trash entries with the matching group ID.
*
* @param groupId the primary key of the group
* @return the matching trash entries
* @throws SystemException if a system exception occurred
* @throws PrincipalException if a principal exception occurred
*/
public Object[] getEntries(long groupId)
throws SystemException, PrincipalException {
return getEntries(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
}
/**
* Returns a range of all the trash entries matching the group ID.
*
* @param groupId the primary key of the group
* @param start the lower bound of the range of trash entries to return
* @param end the upper bound of the range of trash entries to return (not
* inclusive)
* @param obc the comparator to order the trash entries (optionally
* <code>null</code>)
* @return the range of matching trash entries ordered by comparator
* <code>obc</code>
* @throws SystemException if a system exception occurred
* @throws PrincipalException if a system exception occurred
*/
public Object[] getEntries(
long groupId, int start, int end, OrderByComparator obc)
throws SystemException, PrincipalException {
int entriesCount = trashEntryLocalService.getEntriesCount(groupId);
List<TrashEntry> entries = trashEntryLocalService.getEntries(
groupId, 0, end + PropsValues.TRASH_SEARCH_LIMIT, obc);
List<TrashEntry> filteredEntries = new ArrayList<TrashEntry>();
PermissionChecker permissionChecker = getPermissionChecker();
for (TrashEntry entry : entries) {
String className = entry.getClassName();
long classPK = entry.getClassPK();
try {
TrashHandler trashHandler =
TrashHandlerRegistryUtil.getTrashHandler(className);
TrashRenderer trashRenderer = trashHandler.getTrashRenderer(
classPK);
if (trashRenderer.hasViewPermission(permissionChecker)) {
filteredEntries.add(entry);
}
}
catch (Exception e) {
}
}
int filteredEntriesCount = filteredEntries.size();
if ((end != QueryUtil.ALL_POS) && (start != QueryUtil.ALL_POS)) {
if (end > filteredEntriesCount) {
end = filteredEntriesCount;
}
if (start > filteredEntriesCount) {
start = filteredEntriesCount;
}
filteredEntries = filteredEntries.subList(start, end);
}
boolean approximate = entriesCount > PropsValues.TRASH_SEARCH_LIMIT;
return new Object[] {
filteredEntries, filteredEntriesCount, approximate};
}
}