[MGNLDAM-902] AssetPreviewProvider throws exception for missing mime type Created: 21/Oct/20  Updated: 30/Aug/21  Resolved: 26/Aug/21

Status: Closed
Project: Magnolia DAM Module
Component/s: DAM App
Affects Version/s: 3.0.3
Fix Version/s: 3.0.10

Type: Bug Priority: Neutral
Reporter: Richard Gange Assignee: Milan Divilek
Resolution: Fixed Votes: 1
Labels: VN-Testing, maintenance, metadata, ui-team-support
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: XML File dam.tours.shark_brian_warrick_0824..JPG.xml     Text File magnolia-error.log    
Issue Links:
relation
is related to MGNLDAM-886 Dam Choose Dialog - Crash if Asset is... Closed
is related to MGNLDAM-900 damLinkField does not allow to select... Closed
is related to MAGNOLIA-6576 MIMEMapping needs rewrite Open
is related to MGNLDAM-912 Improve support for custom asset meta... Open
Template:
Acceptance criteria:
Empty
Task DoD:
[X]* Doc/release notes changes? Comment present?
[X]* Downstream builds green?
[X]* Solution information and context easily available?
[X]* Tests
[X]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[X]* Steps to reproduce, expected, and actual results filled
[X]* Affected version filled
Release notes required:
Yes
Date of First Response:
Epic Link: Migrate Assets
Sprint: UI FW 34, UI FW 35
Story Points: 3

 Description   

If an asset is missing its mime type then this will cause an unhandled exception to occur when linking to the asset. It's unclear how someone might end up with this missing metadata but I am reporting the issue in the case we get some more clarity later. See AssetPreviewProvider.java#73.

Reproduce

  • Export an asset from the dam. Say /tours/shark_brian_warrick_0824.JPG
  • Delete the asset from the dam.
  • In the export file remove the mime type property. See dam.tours.shark_brian_warrick_0824..JPG.xml
  • Import the modified xml.
  • Try to link to the asset using the MTK Text & Image component.

Expected
We should check for a missing mime type and provide an option for fixing the problem. Use the extension to look up the mime type in the server configuration.

Actual
Whole chooser grid is broken.
magnolia-error.log

ERROR info.magnolia.admincentral.AdmincentralErrorHandler 14.10.2020 23:56:00 -- AdmincentralUI has encountered an unhandled exception.
java.lang.IllegalArgumentException: Could not parse ''
	at com.google.common.net.MediaType.parse(MediaType.java:1013) ~[guava-28.2-jre.jar:?]
	at info.magnolia.dam.app.imageprovider.AssetPreviewProvider.lambda$getResource$0(AssetPreviewProvider.java:73) ~[magnolia-dam-app-3.0.3.jar:?]

Workaround
Fix the mime type with a script

import info.magnolia.jcr.util.NodeUtil
import org.apache.jackrabbit.commons.predicate.NodeTypePredicate
import javax.jcr.PropertyType
 
session = ctx.getJCRSession("dam")
 
children = (NodeUtil.collectAllChildren(session.rootNode,
    new NodeTypePredicate("mgnl:asset", true))).iterator()
    
mimeMappings = ctx.getJCRSession("config").getRootNode().getNode("server").getNode("MIMEMapping")
 
while (children.hasNext()) {
    child = children.next()

    if (child.hasNode("jcr:content")) {
        contentNode = child.getNode("jcr:content")
    
        if (!contentNode.hasProperty("jcr:mimeType")) {
            println "Repairing jcr:mimeType property @ " + contentNode.path
            extensionProperty = contentNode.getProperty("extension")
            mimeType = (mimeMappings.getNode(extensionProperty.getValue().getString().toLowerCase())).getProperty("mime-type").getString()
            contentNode.setProperty("jcr:mimeType", mimeType)
            session.save()
        }
    }
}

Notes
If the mime type is missing try and look it up using the extension.
We also need a special case for folders. MGNLDAM-900



 Comments   
Comment by Frank Sommer [ 29/Jan/21 ]

@rgange Why this ticket was closed? I get this error on my project with Magnolia 6.2.3 and DAM 3.0.3.

Comment by Richard Gange [ 04/Feb/21 ]

Hello frank.sommer-

The reason I closed it is because we are unsure how this happens in the wild. I can artificially recreate the problem but I don't see how admincentral creates the issue. Most likely if you have assets in this state they were created by some other means. OR perhaps they were created a long time ago and have not aged well.

In any case, I think the best course of action is to repair the problem assets and give them appropriate mime type metadata. You could use a groovy script for it.

HTH
Rich

Comment by Richard Gange [ 14/Apr/21 ]

First we should do MAGNOLIA-6576. Then we should create a fallback mechanism inside JcrAsset#getMimeType().

By falling back to nothing we hit the parse exception as described in the ticket. If mimeType is empty then try to look up the mime type based on extension. If it cannot be lookup with extensions then the ultimate fallback should be application/octet-stream.

Comment by Roman Kovařík [ 13/Aug/21 ]

For release notes: dam link chooser does not crash if mime type of an asset is missing.

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