Project

General

Profile

« Previous | Next » 

Revision 18049c0b

Added by Andreas Kohlbecker about 4 years ago

ref #8867 copy image attributions & licenses to the manifest

View differences:

cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/iiif/ManifestController.java
200 200

  
201 201
            // extractAndAddDesciptions(canvas, mediaMetadata);
202 202
            mediaMetadata = deduplicateMetadata(mediaMetadata);
203
            canvas = addAttributionAndLicense(media, canvas);
204
            copyAttributionAndLicenseToMetadata(canvas);
203
            canvas = addAttributionAndLicense(media, canvas, mediaMetadata);
204
            canvas.addLicense("https://creativecommons.org/publicdomain/zero/1.0/deed.de");
205 205
            orderMedatadaItems(canvas);
206 206
            canvas.addMetadata(mediaMetadata.toArray(new MetadataEntry[mediaMetadata.size()]));
207 207
            canvases.add(canvas);
......
224 224
        }
225 225
        List<MetadataEntry> entityMetadata = entityMetadata(entityMediaContext.getEntity());
226 226
        manifest.addMetadata(entityMetadata.toArray(new MetadataEntry[entityMetadata.size()]));
227
        copyAttributionAndLicenseToManifest(manifest);
227 228

  
228 229
        return manifest;
229 230
    }
......
233 234
     * to show attribution and licenses, therefore we copy this data to
234 235
     * also to the metadata
235 236
     *
237
     * <b>NOTE:</b> This method expects that the canvas anntributions and
238
     * licenses are not localized!!!!
239
     *
236 240
     * @param canvas
237 241
     */
238
    private void copyAttributionAndLicenseToMetadata(Canvas canvas) {
239
        if(canvas.getAttribution() != null){
240
            canvas.addMetadata("Attibution", canvas.getAttribution().getValues().stream().collect(Collectors.joining(", ")));
242
    private void copyAttributionAndLicenseToManifest(Manifest manifest) {
243

  
244
         PropertyValue attributions = new PropertyValue();
245
         List<URI> licenses = new ArrayList<>();
246
         String firstAttributionString = null;
247
         boolean hasAttributions = false;
248
         boolean hasLicenses = false;
249
         boolean hasDiversAttributions = false;
250
         boolean hasDiversLicenses = false;
251
         String firstLicensesString = null;
252

  
253

  
254
        for (Sequence sequence : manifest.getSequences()) {
255
            for (Canvas canvas : sequence.getCanvases()) {
256
                if (canvas.getAttribution() != null) {
257
                    canvas.getAttribution().getValues().stream().forEachOrdered(val -> attributions.addValue(val));
258
                    String thisAttributionString = canvas.getAttribution().getValues()
259
                                .stream()
260
                                .sorted()
261
                                .collect(Collectors.joining());
262
                    if(firstAttributionString == null){
263
                        firstAttributionString = thisAttributionString;
264
                        hasAttributions = true;
265
                    } else {
266
                        hasDiversAttributions |=  !firstAttributionString.equals(thisAttributionString);
267
                    }
268
                }
269
                if (canvas.getLicenses() != null && canvas.getLicenses().size() > 0) {
270
                    licenses.addAll(canvas.getLicenses());
271
                    String thisLicensesString = canvas.getLicenses()
272
                                .stream()
273
                                .map(URI::toString)
274
                                .sorted()
275
                                .collect(Collectors.joining());
276
                    if(firstLicensesString == null){
277
                        firstLicensesString = thisLicensesString;
278
                        hasLicenses = true;
279
                    } else {
280
                        hasDiversLicenses |=  !firstLicensesString.equals(thisLicensesString);
281
                    }
282
                }
283
            }
241 284
        }
242
        if(canvas.getLicenses() != null && canvas.getLicenses().size() > 0){
243
            String licenses = canvas.getLicenses().stream().map(uri -> htmlLink(uri)).collect(Collectors.joining("," ));
244
            canvas.addMetadata("License", licenses);
285
        String diversityInfo = "";
286

  
287
        if(hasAttributions || hasLicenses){
288
            String dataTypes ;
289
            if(hasAttributions && hasLicenses) {
290
                dataTypes = "attributions and licenses";
291
            } else if(hasAttributions){
292
                dataTypes = "attributions";
293
            } else {
294
                dataTypes = "licenses";
295
            }
296
            if(hasDiversAttributions || hasDiversLicenses){
297
                diversityInfo = "Individual " + dataTypes + " per Item:";
298
            } else {
299
                diversityInfo = "Same " + dataTypes + " for any Item:";
300
            }
245 301
        }
302
        manifest.addAttribution(diversityInfo, attributions.getValues().toArray(
303
                    new String[attributions.getValues().size()]
304
                ));
305
        licenses.stream()
306
            .map(URI::toString)
307
            .sorted()
308
            .distinct()
309
            .forEachOrdered(l -> manifest.addLicense(l));
246 310

  
247 311
    }
248 312

  
......
358 422
        return metadata;
359 423
    }
360 424

  
361
    private <T extends Resource<T>> T addAttributionAndLicense(IdentifiableEntity<?> entity, T resource) {
425
    private <T extends Resource<T>> T addAttributionAndLicense(IdentifiableEntity<?> entity, T resource, List<MetadataEntry> metadata) {
362 426

  
363 427
        List<Language> languages = LocaleContext.getLanguages();
364 428

  
365
        PropertyValue attributions = new PropertyValue();
429
        List<String> rightsTexts = new ArrayList<>();
430
        List<String> creditTexts = new ArrayList<>();
366 431
        List<URI> license = new ArrayList<>();
367 432

  
368 433
        if(entity.getRights() != null && entity.getRights().size() > 0){
......
385 450
                    // may only apply to RightsType.accessRights
386 451
                    rightText += " " + right.getAgent().getTitleCache();
387 452
                }
388
                attributions.addValue(rightText);
389
            }
390
            if(attributions.getValues().size() > 0){
391
                // metadata.add(new MetadataEntry(new PropertyValue("Copyright"), rightsTexts));
453
                rightsTexts.add(rightText);
454
                //if(metadata.add(e))
392 455
            }
393 456
        }
394 457
        if(entity.getCredits() != null && entity.getCredits().size() > 0){
......
404 467
                    // may only apply to RightsType.accessRights
405 468
                    creditText += " " + credit.getAgent().getTitleCache();
406 469
                }
407
                attributions.addValue(creditText);
470
                creditTexts.add(creditText);
471
            }
472
        }
473

  
474
        if(rightsTexts.size() > 0){
475
            String joinedRights = rightsTexts.stream().collect(Collectors.joining(", "));
476
            resource.addAttribution(joinedRights);
477
            if(metadata != null){
478
                metadata.add(new MetadataEntry(new PropertyValue("Copyright"), new PropertyValue(joinedRights)));
479
            }
480
        }
481
        if(creditTexts.size() > 0){
482
            String joinedCredits = creditTexts.stream().collect(Collectors.joining(", "));
483
            resource.addAttribution(joinedCredits);
484
            if(metadata != null){
485
                metadata.add(new MetadataEntry(new PropertyValue("Credit"), new PropertyValue(joinedCredits)));
408 486
            }
409 487
        }
410
        resource.setAttribution(attributions);
411 488
        resource.setLicenses(license);
412 489
        return resource;
413 490
    }

Also available in: Unified diff