[MGNLDAM-790] Using assets in different workspaces: AssetCompositeIdKeyTranslator denies flexible usage Created: 27/May/19  Updated: 12/Mar/21  Resolved: 12/Mar/21

Status: Closed
Project: Magnolia DAM Module
Component/s: DAM API
Affects Version/s: 2.4.1, 2.5
Fix Version/s: None

Type: Improvement Priority: Neutral
Reporter: Christian Ringele Assignee: Unassigned
Resolution: Obsolete Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

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)
Date of First Response:

 Description   

Use case:

  • Using assets in different workspaces (and apps).
    -> The Assets ap/dam workspace should not be changed.

Situation / Problem:
The whole dam api is very flexibel build:

  • Registering a different assetProvided allows to configure using a different workspace where the asset is fetched from.
  • AssetCompositeIdKeyTranslator allows you to configure the workspace to target/fetch from.
  • The dam download servlet would work 1:1 as it delegates to the asset provided

But there is one flaw that forces you to override/implement classes:
1. The AssetCompositeIdKeyTranslator uses hardcoded the item key in line 72:

ItemKey itemKey = new ItemKey(DamConstants.DEFAULT_JCR_PROVIDER_ID, session.getNode(path).getIdentifier());

That means "jcr" is always stored as assetProvider id -> the second registered assetProvider will never be used.
2. Also another problem is the 'downloadPath' module configuration of the dam module -> it defines the download path in the uri which is by default /dam/ to target the DamDownload Servlet. In my case I also need to use a different servlet (need to to pdf -> image conversions). Which is impossible as it will awlays add /dam/ to the asset link.
3. Class info.magnolia.dam.jcr.JcrAssetProvider should not du a new of the Asset impl it provides. AND that method should be at least protected!!

Asset createAsset(final Node assetNode) {
        if (AssetNodeTypes.isAsset(assetNode)) {
            log.debug("Created asset linked to the following node '{}'", NodeUtil.getPathIfPossible(assetNode));
            return new JcrAsset(this, new I18nNodeWrapper(assetNode));
        }
        throw new IllegalArgumentException("Node '" + NodeUtil.getPathIfPossible(assetNode) + "' is not defining an asset but another item type");
    }

Solution:
1. Let on the class AssetCompositeIdKeyTranslator also the AssetProviderID be configurable.
Also the class should provide a method "getWorkspaceName()" that extends of it can access it.
2. Define on the AssetProvider the 'downloadPath' and not globally in the module itself.
3. Let it be configured on the AssetProvider and/or being Injected form Guice.



 Comments   
Comment by Roman Kovařík [ 12/Mar/21 ]

AssetCompositeIdKeyTranslator is deprecated in favour of https://git.magnolia-cms.com/projects/MODULES/repos/dam/browse/magnolia-dam-app/src/main/java/info/magnolia/dam/app/data/AssetConverter.java#68

Generated at Mon Feb 12 05:03:18 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.