74
74
@ RequestMapping ("/api/record" )
75
75
public class FullRecordController extends AbstractErrorHandlingSearchController {
76
76
private static final Logger LOG = LoggerFactory .getLogger (FullRecordController .class );
77
- private final String VIEWER_PID = "viewerPid" ;
78
- private final String VIEWER_TYPE = "viewerType" ;
79
- private final String STREAMING_URL = "streamingUrl" ;
80
- private final String STREAMING_TYPE = "streamingType" ;
81
- private final String APPLICATION_X_PDF_VALUE = "application/x-pdf" ;
77
+ protected static final String VIEWER_PID = "viewerPid" ;
78
+ protected static final String VIEWER_TYPE = "viewerType" ;
79
+ protected static final String STREAMING_URL = "streamingUrl" ;
80
+ protected static final String STREAMING_TYPE = "streamingType" ;
81
+ private static final String APPLICATION_X_PDF_VALUE = "application/x-pdf" ;
82
+ protected static final String AV_MIMETYPE_REGEX = "(" + AUDIO_MIMETYPE_REGEX + ")|(" + VIDEO_MIMETYPE_REGEX + ")" ;
82
83
83
84
@ Autowired
84
85
private AccessControlService aclService ;
@@ -99,7 +100,7 @@ public class FullRecordController extends AbstractErrorHandlingSearchController
99
100
@ Autowired
100
101
private ObjectAclFactory objectAclFactory ;
101
102
102
- @ Autowired ( required = true )
103
+ @ Autowired
103
104
private XSLViewResolver xslViewResolver ;
104
105
@ Autowired
105
106
private RepositoryObjectLoader repositoryObjectLoader ;
@@ -272,65 +273,88 @@ public String handlePdfViewerRequest(@PathVariable("pid") String pidString, Mode
272
273
SimpleIdRequest idRequest = new SimpleIdRequest (pid , principals );
273
274
ContentObjectRecord briefObject = queryLayer .getObjectById (idRequest );
274
275
275
- String viewerPid = null ;
276
+ String viewerPid ;
276
277
if (ResourceType .Work .nameEquals (briefObject .getResourceType ())) {
277
- viewerPid = accessCopiesService .getFirstMatchingChild (briefObject ,
278
- Arrays .asList (APPLICATION_PDF_VALUE , APPLICATION_X_PDF_VALUE ), principals ).getId ();
278
+ var child = accessCopiesService .getFirstMatchingChild (briefObject ,
279
+ Arrays .asList (APPLICATION_PDF_VALUE , APPLICATION_X_PDF_VALUE ), principals );
280
+ if (child == null ) {
281
+ throw new NotFoundException ("Cannot find child PDF for " + pidString );
282
+ }
283
+ viewerPid = child .getId ();
279
284
} else {
280
- accessCopiesService .getDatastreamPid (briefObject , principals , PDF_MIMETYPE_REGEX );
285
+ viewerPid = accessCopiesService .getDatastreamPid (briefObject , principals , PDF_MIMETYPE_REGEX );
286
+ if (viewerPid == null ) {
287
+ throw new IllegalArgumentException ("Resource is not a PDF: " + pidString );
288
+ }
281
289
}
282
290
283
- model .addAttribute ("viewerPid" , viewerPid );
291
+ model .addAttribute (VIEWER_PID , viewerPid );
284
292
model .addAttribute ("briefObject" , briefObject );
285
293
model .addAttribute ("template" , "ajax" );
286
294
287
295
return "fullRecord/pdfViewer" ;
288
296
}
289
297
290
298
private Map <String , Object > getViewerProperties (ContentObjectRecord briefObject , AccessGroupSet principals ) {
291
- String viewerType = null ;
292
- String viewerPid = null ;
293
- String streamingUrl = null ;
294
- String streamingType = null ;
299
+ String viewerType ;
300
+ String viewerPid ;
295
301
ContentObjectRecord workStreamingContent = null ;
296
302
297
303
boolean imageViewerNeeded = accessCopiesService .hasViewableFiles (briefObject , principals );
304
+ if (imageViewerNeeded ) {
305
+ return makeViewerProperties ("clover" , null , null , null );
306
+ }
298
307
299
- if (!imageViewerNeeded ) {
308
+ boolean hasStreamingContent = briefObject .getContentStatus ().contains (FacetConstants .HAS_STREAMING );
309
+ if (!hasStreamingContent ) {
300
310
workStreamingContent = accessCopiesService .getFirstStreamingChild (briefObject , principals );
301
311
}
302
312
303
- if (imageViewerNeeded ) {
313
+ if (hasStreamingContent || workStreamingContent != null ) {
314
+ return makeStreamingProperties ((workStreamingContent != null ) ? workStreamingContent : briefObject );
315
+ }
316
+
317
+ viewerPid = accessCopiesService .getDatastreamPid (briefObject , principals , AV_MIMETYPE_REGEX );
318
+
319
+ if (viewerPid != null ) {
304
320
viewerType = "clover" ;
305
- } else if (briefObject .getContentStatus ().contains (FacetConstants .HAS_STREAMING ) || workStreamingContent != null ) {
306
- viewerType = "streaming" ;
307
- streamingUrl = (workStreamingContent != null ) ? workStreamingContent .getStreamingUrl () :
308
- briefObject .getStreamingUrl ();
309
- streamingType = (workStreamingContent != null ) ? workStreamingContent .getStreamingType () :
310
- briefObject .getStreamingType ();
311
321
} else {
312
- viewerPid = accessCopiesService .getDatastreamPid (briefObject , principals ,
313
- "(" + AUDIO_MIMETYPE_REGEX + ")|(" + VIDEO_MIMETYPE_REGEX + ")" );
314
-
315
- if (viewerPid != null ) {
316
- viewerType = "clover" ;
317
- } else {
318
- viewerPid = accessCopiesService .getDatastreamPid (briefObject , principals , PDF_MIMETYPE_REGEX );
319
- if (viewerPid != null ) {
320
- viewerType = "pdf" ;
321
- }
322
- }
322
+ viewerPid = accessCopiesService .getDatastreamPid (briefObject , principals , PDF_MIMETYPE_REGEX );
323
+ viewerType = viewerPid != null ? "pdf" : null ;
324
+ }
325
+
326
+ // When the viewer object is not the current object, check if the user has access to view the viewer object
327
+ if (noAccessToViewChildObject (viewerPid , briefObject , principals )) {
328
+ viewerPid = null ;
329
+ viewerType = null ;
323
330
}
324
331
332
+ return makeViewerProperties (viewerType , viewerPid , null , null );
333
+ }
334
+
335
+ private Map <String , Object > makeStreamingProperties (ContentObjectRecord briefObject ) {
336
+ return makeViewerProperties ("streaming" ,
337
+ null ,
338
+ briefObject .getStreamingUrl (),
339
+ briefObject .getStreamingType ());
340
+ }
341
+
342
+ private Map <String , Object > makeViewerProperties (String viewType , String viewerPid ,
343
+ String streamingUrl , String streamingType ) {
325
344
var viewerProperties = new HashMap <String , Object >();
326
- viewerProperties .put (VIEWER_TYPE , viewerType );
345
+ viewerProperties .put (VIEWER_TYPE , viewType );
327
346
viewerProperties .put (VIEWER_PID , viewerPid );
328
347
viewerProperties .put (STREAMING_URL , streamingUrl );
329
348
viewerProperties .put (STREAMING_TYPE , streamingType );
330
-
331
349
return viewerProperties ;
332
350
}
333
351
352
+ private boolean noAccessToViewChildObject (String viewerPid , ContentObjectRecord briefObject ,
353
+ AccessGroupSet principals ) {
354
+ return viewerPid != null && !briefObject .getId ().equals (viewerPid )
355
+ && !aclService .hasAccess (PIDs .get (viewerPid ), principals , Permission .viewOriginal );
356
+ }
357
+
334
358
/**
335
359
* Get list of digital exhibits associated with an object
336
360
* @param briefObject
0 commit comments