[MGNLUI-4298] Get item by url fragment does not return proper item when rootPath is configured in JcrContentConnector Created: 02/Oct/17  Updated: 08/Mar/21  Resolved: 08/Mar/21

Status: Closed
Project: Magnolia UI
Component/s: None
Affects Version/s: 5.5.6
Fix Version/s: None

Type: Bug Priority: Neutral
Reporter: Sang Ngo Huu Assignee: Unassigned
Resolution: Won't Fix Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Relates
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

 Description   

There is a problem in line String fullFragment = ("/".equals(getRootPath()) ? "" : getRootPath()) + urlFragment;
If the rootPath is configured, the fragment will be appended more rootPath, although the fragment is full path here.
eg: rootPath: /data/products
In linkedField: /data/products/cars/car1
Value when debugging: fullFragment: /data/products/data/products/cars/car1

So It causes a problem in choose dialog: item is not re-selected when open choose dialog in linkField

@Override
    public JcrItemId getItemIdByUrlFragment(String urlFragment) {
        try {
            String fullFragment = ("/".equals(getRootPath()) ? "" : getRootPath()) + urlFragment;
            String nodePath = JcrItemUtil.parseNodeIdentifier(fullFragment);
            nodePath = !StringUtils.isBlank(nodePath) ? nodePath : getRootPath();
            JcrItemId nodeItemId = JcrItemUtil.getItemId(getWorkspace(), nodePath);
            if (nodeItemId == null || !JcrItemUtil.isPropertyItemId(fullFragment)) {
                return nodeItemId;
            } else {
                return new JcrPropertyItemId(nodeItemId, parsePropertyName(fullFragment));
            }
        } catch (RepositoryException e) {
            log.error("Failed to obtain JCR id for fragment: " + e.getMessage(), e);
            return null;
        }
    }

Generated at Mon Feb 12 09:15:18 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.