[MGNLDAM-724] Adding other DamTemplatingFunction for explicitly ensuring that an asset is valid Created: 19/Sep/17  Updated: 10/Oct/23  Resolved: 10/Oct/23

Status: Closed
Project: Magnolia DAM Module
Component/s: DAM Templating
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Neutral
Reporter: Ervin Vystup Assignee: Unassigned
Resolution: Workaround exists Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
relation
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)
Visible to:
Federico Navarro, Marcel Evers, Mariusz Chruscielewski, Nuno Cruz, Simon Lutz, Stef te Winkel
Epic Link: AuthorX Support
Team: AuthorX

 Description   

We think that having a function for explicitly ensuring an asset is valid would be a useful addition to the DamTemplatingFunctions. Something similar to the code below:

    /**
     * Checks whether a given asset id is valid or not. Covered cases:
     * <li>
     *     <ul>If assetId is null or empty, then return false</ul>
     *     <ul>If assetId is not a valid uuid, then return false</ul>
     *     <ul>If assetId points to a non-existing node, then return false</ul>
     *     <ul>If assetId points to an existing node without binary data, then return false</ul>
     * </li>
     * @param assetId
     * @return
     */
    public boolean isValidAsset(String assetId) {
        Asset asset = getAsset(assetId);

        if (asset == null) {
            return false;
        }

        try {
            return asset.getContentStream() != null && asset.getContentStream().available() > 0;
        } catch (IOException e) {
            LOG.warn("The content associated with asset {} does not exist or cannot be accessed.", assetId, e);
        }

        return true;
    }

Could you consider adding such a function to the DamTemplatingFunctions?

Workaround
The method getAsset() already checks for null.

asset = getAsset(assetId)

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