[MAGNOLIA-4400] templating: introduce a possibility to get node by identifier Created: 03/May/12  Updated: 26/Sep/12  Resolved: 25/Sep/12

Status: Closed
Project: Magnolia
Component/s: templating
Affects Version/s: 4.5
Fix Version/s: 4.5.5

Type: Improvement Priority: Major
Reporter: Zdenek Skodik Assignee: Milan Divilek
Resolution: Fixed Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
duplicate
is duplicated by MAGNOLIA-4432 Add function to retrieve node based o... Closed
relation
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)
Date of First Response:

 Description   

TemplatingFunctions lets you retrieve a node by path, similarly you should have a possibility to do by identifier so that you'll not need to go via MgnlContext necessarily.



 Comments   
Comment by Edgar Vonk [ 29/Jun/12 ]

In the meantime: what do you suggest as a good workaround? You mentioned the MgnlContext but I don't think this is made available to JSPs in Magnolia 4.5 is it? The old 'ctx' object is no longer there. Of course we could write our own JSP tag but we would preferably not.

Comment by Edgar Vonk [ 03/Jul/12 ]

Update: in the meantime I have written our own simple JSP tag as a workaround:

public class GetNodeFromUUIDTag extends TagSupport {

    private final static Logger log = LoggerFactory.getLogger(GetNodeFromUUIDTag.class);

    private String uuid;
    private String node;

    @Override
    public int doEndTag() throws JspException {
        Node jcrNode = null;

        try {
            jcrNode = MgnlContext.getJCRSession("website").getNodeByIdentifier(this.uuid);
            ContentMap contentMap = new ContentMap(jcrNode);

            pageContext.setAttribute(this.node, contentMap);

        } catch (LoginException e) {
            log.error("failed to log in to JCR repository", e);
            throw new JspException(e);
        } catch (RepositoryException e) {
            log.error("problem accessing JCR repository", e);
            throw new JspException(e);
        }

        return EVAL_PAGE;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public void setNode(String node) {
        this.node = node;
    }
}

Comment by Jan Haderka [ 24/Aug/12 ]

SessionUtilTest.java - MockUtil.init() should be done in @Before and reseting the session should be done in @After methods not as part of the tests.
Same for JspTemplatingFunctionTest.java

Comment by Jan Haderka [ 18/Sep/12 ]
+        } catch (LoginException e) {
+            log.error("Exeption during node Search by identifier: '" + id + "' in repository: '" + repository + "'", e);
+        } catch (PathNotFoundException e) {
+            log.error("Exeption during node Search by identifier: '" + id + "' in repository: '" + repository + "'", e);
+        } catch (RepositoryException e) {
+            log.error("Exeption during node Search by identifier: '" + id + "' in repository: '" + repository + "'", e);
+        } catch (IllegalArgumentException e) {
+            log.error("Exeption during node Search by identifier: '" + id + "' in repository: '" + repository + "'", e);
+        }

If you treat all exceptions the same, there's no need to catch one by one, first 3 are all of the same type - RepositoryException}}

{{JSPTemplatingFuncitons.contentByIdentifier(): if( repository.isEmpty()) }}

What if repo is null? Use StringUtils to make the check.
... same goes for related testGetContentByIdentifier() it needs to be changed after changing the code.

Also since you default to website repo, in the test, you should test also retrieval of content from some other repo to be sure you don't default to website always.

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