1
1
package org .sakaiproject .content .entityproviders ;
2
2
3
- import java .text .DateFormat ;
4
- import java .text .ParseException ;
5
- import java .text .SimpleDateFormat ;
6
- import java .util .*;
7
3
import java .net .URI ;
8
4
import java .util .ArrayList ;
9
5
import java .util .Comparator ;
17
13
import lombok .Setter ;
18
14
import lombok .extern .slf4j .Slf4j ;
19
15
import org .apache .commons .lang .StringUtils ;
20
- import org .apache .commons .logging .Log ;
21
- import org .apache .commons .logging .LogFactory ;
22
16
import org .sakaiproject .authz .api .SecurityService ;
23
17
import org .sakaiproject .component .cover .ComponentManager ;
24
18
import org .sakaiproject .content .api .ContentCollection ;
27
21
import org .sakaiproject .content .api .ContentResource ;
28
22
import org .sakaiproject .content .api .ResourceTypeRegistry ;
29
23
import org .sakaiproject .content .tool .ListItem ;
30
- import org .sakaiproject .entity .api .EntityManager ;
31
- import org .sakaiproject .entity .api .EntityPermissionException ;
32
- import org .sakaiproject .entity .api .Reference ;
33
24
import org .sakaiproject .entity .api .ResourceProperties ;
34
25
import org .sakaiproject .entitybroker .EntityView ;
35
26
import org .sakaiproject .entitybroker .entityprovider .EntityProvider ;
36
27
import org .sakaiproject .entitybroker .entityprovider .annotations .EntityCustomAction ;
28
+ import org .sakaiproject .entitybroker .entityprovider .annotations .EntityId ;
29
+ import org .sakaiproject .entitybroker .entityprovider .annotations .EntityOwner ;
30
+ import org .sakaiproject .entitybroker .entityprovider .annotations .EntityTitle ;
37
31
import org .sakaiproject .entitybroker .entityprovider .capabilities .ActionsExecutable ;
38
32
import org .sakaiproject .entitybroker .entityprovider .capabilities .AutoRegisterEntityProvider ;
39
33
import org .sakaiproject .entitybroker .entityprovider .capabilities .Describeable ;
40
34
import org .sakaiproject .entitybroker .entityprovider .capabilities .Outputable ;
41
35
import org .sakaiproject .entitybroker .entityprovider .extension .Formats ;
42
36
import org .sakaiproject .entitybroker .exception .EntityNotFoundException ;
43
37
import org .sakaiproject .entitybroker .util .AbstractEntityProvider ;
44
- import org .sakaiproject .entitybroker .util .EntityDataUtils ;
45
- import org .sakaiproject .entitybroker .util .model .EntityContent ;
46
38
import org .sakaiproject .exception .IdUnusedException ;
47
39
import org .sakaiproject .exception .PermissionException ;
48
40
import org .sakaiproject .exception .ServerOverloadException ;
49
41
import org .sakaiproject .exception .TypeException ;
50
42
import org .sakaiproject .site .api .Site ;
51
43
import org .sakaiproject .site .api .SiteService ;
52
44
import org .sakaiproject .site .api .ToolConfiguration ;
53
- import org .sakaiproject .time .api .Time ;
54
- import org .sakaiproject .time .cover .TimeService ;
55
45
import org .sakaiproject .tool .api .ToolManager ;
56
46
import org .sakaiproject .tool .api .Session ;
57
47
import org .sakaiproject .tool .cover .SessionManager ;
@@ -69,9 +59,6 @@ public class ContentEntityProvider extends AbstractEntityProvider implements Ent
69
59
public static final String PREFIX = "resources." ;
70
60
public static final String SYS = "sys." ;
71
61
private static final String STATE_RESOURCES_TYPE_REGISTRY = PREFIX + SYS + "type_registry" ;
72
- private static Log log = LogFactory .getLog (ContentEntityProvider .class );
73
- private static final String PARAMETER_DEPTH = "depth" ;
74
- private static final String PARAMETER_TIMESTAMP = "timestamp" ;
75
62
76
63
@ Override
77
64
public String getEntityPrefix () {
@@ -165,183 +152,7 @@ public List<ContentItem> getContentCollectionForSite(EntityView view) {
165
152
return getSiteListItems (siteId );
166
153
167
154
}
168
- @ EntityCustomAction (action ="resources" , viewKey =EntityView .VIEW_LIST )
169
- public List <EntityContent > getResources (EntityView view , Map <String , Object > params )
170
- throws EntityPermissionException {
171
- String userId = developerHelperService .getCurrentUserId ();
172
- if (userId == null ) {
173
- throw new SecurityException (
174
- "This action is not accessible to anon and there is no current user." );
175
- }
176
-
177
- Map <String , Object > parameters = getQueryMap ((String )params .get ("queryString" ));
178
- Time timeStamp = getTime ((String )parameters .get (PARAMETER_TIMESTAMP ));
179
-
180
- int requestedDepth = 1 ;
181
- int currentDepth = 0 ;
182
- if (parameters .containsKey (PARAMETER_DEPTH )) {
183
- if ("all" .equals ((String )parameters .get (PARAMETER_DEPTH ))) {
184
- requestedDepth = Integer .MAX_VALUE ;
185
- } else {
186
- requestedDepth = Integer .parseInt ((String )parameters .get (PARAMETER_DEPTH ));
187
- }
188
- }
189
-
190
- String [] segments = view .getPathSegments ();
191
-
192
- StringBuffer resourceId = new StringBuffer ();
193
- for (int i =2 ; i <segments .length ; i ++) {
194
- resourceId .append ("/" +segments [i ]);
195
- }
196
- resourceId .append ("/" );
197
-
198
- Reference reference = entityManager .newReference (
199
- ContentHostingService .REFERENCE_ROOT +resourceId .toString ());
200
-
201
- // We could have used contentHostingService.getAllEntities(id) bit it doesn't do
202
- // permission checks on any contained resources (documentation wrong).
203
- // contentHostingService.getAllResources(String id) does do permission checks
204
- // but it doesn't include collections in it's returned list.
205
- // Also doing the recursion ourselves means that we don't loads lots of entities
206
- // when the depth of recursion is low.
207
- ContentCollection collection = null ;
208
- try {
209
- collection = contentHostingService .getCollection (reference .getId ());
210
-
211
- } catch (IdUnusedException e ) {
212
- throw new IllegalArgumentException ("IdUnusedException in Resource Entity Provider" );
213
-
214
- } catch (TypeException e ) {
215
- throw new IllegalArgumentException ("TypeException in Resource Entity Provider" );
216
-
217
- } catch (PermissionException e ) {
218
- throw new SecurityException ("PermissionException in Resource Entity Provider" );
219
- }
220
-
221
- List <EntityContent > resourceDetails = new ArrayList <EntityContent >();
222
- if (collection !=null ) {
223
- EntityContent resourceDetail = getResourceDetails (collection , currentDepth , requestedDepth , timeStamp );
224
- if (resourceDetail != null ) {
225
- resourceDetails .add (resourceDetail );
226
- } else {
227
- log .error ("Initial permission check passed but subsequent permission check failed on " + reference .getId ());
228
- }
229
- }
230
- return resourceDetails ;
231
- }
232
-
233
- /**
234
- *
235
- * @param entity The entity to load details of.
236
- * @param currentDepth How many collections we have already processed
237
- * @param requestedDepth The maximum number depth of the tree to scan.
238
- * @param timeStamp All returned details must be newer than this timestamp.
239
- * @return EntityContent containing details of all resources the user can access.
240
- * <code>null</code> is returned if the current user isn't allowed to access the resource.
241
- */
242
- private EntityContent getResourceDetails (
243
- ContentEntity entity , int currentDepth , int requestedDepth , Time timeStamp ) {
244
- boolean allowed = (entity .isCollection ()) ?
245
- contentHostingService .allowGetCollection (entity .getId ()) :
246
- contentHostingService .allowGetResource (entity .getId ());
247
- if (!allowed ) {
248
- // If the user isn't allowed to see this we return null.
249
- return null ;
250
- }
251
- EntityContent tempRd = EntityDataUtils .getResourceDetails (entity );
252
-
253
- // If it's a collection recurse down into it.
254
- if ((requestedDepth > currentDepth ) && entity .isCollection ()) {
255
-
256
- ContentCollection collection = (ContentCollection )entity ;
257
- // This is all members, no permission check has been done yet.
258
- List <ContentEntity > contents = collection .getMemberResources ();
259
-
260
- Comparator comparator = getComparator (entity );
261
- if (null != comparator ) {
262
- Collections .sort (contents , comparator );
263
- }
264
-
265
- for (Iterator <ContentEntity > i = contents .iterator (); i .hasNext ();) {
266
- ContentEntity content = i .next ();
267
- EntityContent resource = getResourceDetails (content , currentDepth +1 , requestedDepth , timeStamp );
268
-
269
- if (resource != null && resource .after (timeStamp )) {
270
- tempRd .addResourceChild (resource );
271
- }
272
- }
273
- }
274
-
275
- return tempRd ;
276
- }
277
-
278
- /**
279
- *
280
- * @param entity
281
- * @return
282
- */
283
- private Comparator getComparator (ContentEntity entity ) {
284
-
285
- boolean hasCustomSort = false ;
286
- try {
287
- hasCustomSort = entity .getProperties ().getBooleanProperty (
288
- ResourceProperties .PROP_HAS_CUSTOM_SORT );
289
-
290
- } catch (Exception e ) {
291
- // ignore -- let value of hasCustomSort stay false
292
- }
293
-
294
- if (hasCustomSort ) {
295
- return contentHostingService .newContentHostingComparator (
296
- ResourceProperties .PROP_CONTENT_PRIORITY , true );
297
- } else {
298
- return contentHostingService .newContentHostingComparator (
299
- ResourceProperties .PROP_DISPLAY_NAME , true );
300
- }
301
- }
302
-
303
- /**
304
- *
305
- * @param queryString
306
- * @return
307
- */
308
- private Map <String , Object > getQueryMap (String queryString ) {
309
-
310
- Map <String , Object > params = new HashMap <String , Object >();
311
- if (null != queryString && !queryString .isEmpty ()) {
312
- String [] strings = queryString .split ("&" );
313
- for (int i =0 ; i <strings .length ; i ++) {
314
- String parameter = strings [i ];
315
- int j = parameter .indexOf ("=" );
316
- params .put (parameter .substring (0 , j ), parameter .substring (j +1 ));
317
- }
318
- }
319
- return params ;
320
- }
321
-
322
- /**
323
- *
324
- * @param timestamp use formatter A: yyyyMMddHHmmssSSS
325
- * @return
326
- */
327
- private Time getTime (String timestamp ) {
328
155
329
- try {
330
-
331
- if (null != timestamp ) {
332
- DateFormat format = new SimpleDateFormat ("yyyyMMddHHmmssSSS" );
333
- Date date = format .parse (timestamp );
334
- Calendar c = Calendar .getInstance ();
335
- c .setTime (date );
336
-
337
- return TimeService .newTimeGmt (format .format (date ));
338
- }
339
-
340
- } catch (ParseException e ) {
341
- return TimeService .newTimeGmt ("20201231235959999" );
342
- }
343
- return null ;
344
- }
345
156
private List <ContentItem > getSiteListItems (String siteId ) {
346
157
List <ContentItem > rv = new ArrayList <ContentItem >();
347
158
String wsCollectionId = contentHostingService .getSiteCollection (siteId );
@@ -714,8 +525,6 @@ public String[] getHandledOutputFormats() {
714
525
@ Setter
715
526
private UserDirectoryService userDirectoryService ;
716
527
717
- @ Setter
718
- private EntityManager entityManager ;
719
528
720
529
721
530
0 commit comments