[MGNLREST-130] Provide Reference resolver for DAM Created: 19/Oct/17  Updated: 12/Mar/18  Resolved: 09/Mar/18

Status: Closed
Project: Magnolia REST Framework
Component/s: None
Affects Version/s: None
Fix Version/s: 2.1

Type: Improvement Priority: Neutral
Reporter: Sang Ngo Huu Assignee: Ngoc Nguyenthanh
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: 0d
Time Spent: 3d 7h
Original Estimate: 3d

Issue Links:
relation
is related to MGNLREST-151 Get link to asset rendition Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Documentation update required:
Yes
Date of First Response:
Epic Link: REST Phase2
Sprint: Saigon 131, Saigon 132, Saigon 133, Saigon 134, Saigon 135, Saigon 136, Saigon 137
Story Points: 8

 Description   

Implements `AssetReferenceResolver` for resolving Asset item key (jcr:uuid).

Allows to configure options: expansion, include download link, include `DublinCore` metadata, include renditions (should be handled by MGNLREST-151)



 Comments   
Comment by Ngoc Nguyenthanh [ 09/Mar/18 ]
 Solution
  • Allows to configure output format by using `info.magnolia.rest.reference.dam.ConfiguredAssetReferenceResolverDefinition`
  • Implements a JAX-RS custom writer `AssetWriter` to manipulate the json output of an `Asset`
Usages

Defines a configurable asset resolver by using `info.magnolia.rest.reference.dam.ConfiguredAssetReferenceResolverDefinition`

references:
  - name: assetReference
    propertyName: image
    referenceResolver:
      expand: true
      includeAssetMetadata: false
      includeDownloadLink: true
      class: info.magnolia.rest.reference.dam.ConfiguredAssetReferenceResolverDefinition

It's also allows to resolve without output configuration needed. It'll print out of data of the Asset

references:
  - name: assetReference
    propertyName: image
    referenceResolver:
      implementationClass: info.magnolia.rest.reference.dam.AssetReferenceResolver

The definition supports 3 options

  • `expand` : `false` will disable: asset metadata, @link, expanded properties. However if the `includeDownloadLink` is enabled, a link will be returned as a String.
  • `includeAssetMetadata`: a 'metadata` section will be included when turned on.
  • `includeDownloadLink`: a `@link` property will be added when enabled.

The end result will look like

    "image": {
        "@name": "flickr-surfer-mandolin-373088839_7da451ccc8_b.jpg",
        "@path": "/flickr-surfer-mandolin-373088839_7da451ccc8_b/flickr-surfer-mandolin-373088839_7da451ccc8_b.jpg",
        "@id": "jcr:d01deefa-dba9-4708-8cfa-604320720253",
        "@link": "/magnoliaTest/dam/jcr:d01deefa-dba9-4708-8cfa-604320720253/flickr-surfer-mandolin-373088839_7da451ccc8_b.jpg",
        "metadata": {
            "fileName": "flickr-surfer-mandolin-373088839_7da451ccc8_b.jpg",
            "mimeType": "image/jpeg",
            "caption": "Mandolin",
            "fileSize": "327927",
            "height": "681",
            "width": "1024",
            "format": "image/jpeg",
            "rights": "by-sa/2.0/",
            "creator": [
                "superuser"
            ],
            "date": "2018-02-27T14:33:43.335+07:00",
            "created": "2015-01-29T03:28:44.217+07:00",
            "modified": "2018-02-27T14:33:43.335+07:00"
        }
    },

If the `expand` is disabled but `includeDownloadLink` is enabled, the result will be as:

"image": "/magnoliaTest/dam/jcr:d01deefa-dba9-4708-8cfa-604320720253/flickr-surfer-mandolin-373088839_7da451ccc8_b.jpg",

Otherwise, the asset item key will be returned when all flags are off

"image": "jcr:d01deefa-dba9-4708-8cfa-604320720253"

metadata will be include DublinCore properties as well as Magnolia extended properties for Asset

contributor , coverage , creator , date , description , format , identifier , language , publisher , relation , rights , source , subject , title , type
  • Magnolia properties include
fileName, mimeType, caption, comment, fileSize, height, width, created, modified
  • Expanded asset will include
@name, @path, @id, @nodetype

Note: We're only write non-empty properties. It means that the json structure may change depends on the property values.

@nodetype is only visible when AssetProvider is an instance of info.magnolia.dam.jcr.JcrAssetProvider

See info.magnolia.integrationtests.rest.delivery.jcr.v2.AssetReferenceResolverTest for more cases

Generated at Mon Feb 12 06:56:54 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.