[MGNLDAM-718] Class cast exception in getItem of AbstractAssetContainer Created: 26/Jul/17  Updated: 12/Mar/21  Resolved: 12/Mar/21

Status: Closed
Project: Magnolia DAM Module
Component/s: DAM External App
Affects Version/s: 2.2.5
Fix Version/s: None

Type: Bug Priority: Neutral
Reporter: Viet Nguyen Assignee: Unassigned
Resolution: Obsolete Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Zip Archive files.zip    
Issue Links:
causality
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)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:

 Description   

Steps to reproduce extracted from comment of Panagiotis in SUPPORT-7697:

In the attached zip files.zip , at screen1.png is where we get the exception whenever click the List View icon. If we are at the Tree View and search for an asset, it automatically swaps to the List View(Search View) without causing any issue. Also in the attached files you can see that in the SearchAssetContainer
we extend an exact copy of info.magnolia.dam.external.app.contentview.AbstractAssetContainer with only difference line 131 where we tried to bypass the mentioned exception with a custom code. Although this works fine now for the Content App implementation, when is used as a dialog in other apps, seems that the info.magnolia.dam.external.app.contentview.AbstractAssetContainer is still called.Method info.magnolia.dam.external.app.contentview.AbstractAssetContainer.getItem(...) never called by us directly but from the Magnolia framework (probably WorkbenchPresenter or WorkbenchViewImpl) trying to pass an empty HashSet.

Issue at line 161 of info.magnolia.dam.external.app.contentview.AbstractAssetContainer.getItem(Object)
Grep code:

159 @Override
160 public BeanItem<info.magnolia.dam.api.Item> getItem(Object itemId) {
161 if (itemId != null && ItemKey.isValid(((ItemKey) itemId).asString())) {
162 try {
163 info.magnolia.dam.api.Item item = getAssetProvider().getItem((ItemKey) itemId);
163 info.magnolia.dam.api.Item item = getAssetProvider().getItem((ItemKey) itemId);
164 return new BeanItem<info.magnolia.dam.api.Item>(item);
165 } catch (AssetProvider.AssetNotFoundException e) {
166 log.error("Failed to retrieve item with given id: " + e.getMessage(), e);
167 } catch (AssetProvider.IllegalItemKeyException e) {
168 log.error("Failed to handle item id: " + e.getMessage(), e);
169 }
170 }
171 return null;
172 }


 Comments   
Comment by Viet Nguyen [ 26/Jul/17 ]

We didn't catch all error cases even-though it does not happen frequently but absolutely it would help potential customers.

Comment by Marty Glaubitz [ 10/Jan/19 ]

I hit the same issue. In my opinion it's a bug in the ListViewImpl in the Method select, line number 247

@Override
public void select(List<Object> itemIds) {
    if (itemIds == null) {
        table.setValue(null);
        return;
    }

    // convert to set before comparing with actual table selection (which is also a set underneath)
    Set<Object> uniqueItemIds = new HashSet<>(itemIds); // source of the problem
    if (uniqueItemIds.equals(table.getValue())) {
        // selection already in sync, nothing to do
        return;
    }

    table.setValue(uniqueItemIds);
    // do not #setCurrentPageFirstItemId because AbstractJcrContainer's index resolution is super slow.
}

Solved it the same way @Viet Nguyen did

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

Closing as DAM external app has been deprecated in favour of https://docs.magnolia-cms.com/product-docs/Connector-Packs/DAM-Connector-Pack.html#_seamless_integration_with_your_content

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