Details
-
Improvement
-
Resolution: Workaround exists
-
Neutral
-
None
-
None
-
None
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)
Checklists
Acceptance criteria