Uploaded image for project: 'Magnolia DAM Module'
  1. Magnolia DAM Module
  2. MGNLDAM-724

Adding other DamTemplatingFunction for explicitly ensuring that an asset is valid

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Workaround exists
    • Icon: Neutral Neutral
    • None
    • None
    • DAM Templating
    • None

      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)
      

        Acceptance criteria

              Unassigned Unassigned
              evystup Ervin Vystup
              Federico Navarro, Marcel Evers, Mariusz Chruscielewski, Nuno Cruz, Simon Lutz, Stef te Winkel
              AuthorX
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved:

                  Task DoD