Jahia Dev Forum > JQOM and query selector...

0 (0 Good)
0 (0 Bad)

JQOM and query selector to select [jnt:user]

by  minijoey »  2014/08/25 13:43

Hi everyone !

I have a web service that link an external database to save some properties (email and creation date) of users account found in the [jnt:user] of Jahia. I use a query statement to get every users and a foreach loop to check if the properties I'm looking for are not empty before pushing them in a JSON object. The problem is that I've more than 26.000 users in Jahia and the query selector can't catch them all and create the JSON object inside the foreach loop ... I was thinking of a "limit" in my query statement, like "get every account from 0 to 1000" and after that "get every account from 1001 to 2000", but it seems to be impossible. Any idee how to fix it ?

Here's my code, in case it could help :

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="jcr" uri="http://www.jahia.org/tags/jcr" %>
<%@ taglib prefix="query" uri="http://www.jahia.org/tags/queryLib" %>
<%@ taglib prefix="template" uri="http://www.jahia.org/tags/templateLib"%>

<jcr:jqom var="usersmaps">
    <query:selector nodeTypeName="jnt:user"/>
</jcr:jqom>

<c:url var="updateAdherentsUrl"  value='${url.base}${currentNode.path}.UpdateAdherents.do'/>

<script type="text/javascript">       
    var json = { "data" : [] };
        
    <c:forEach items="${usersmaps.nodes}" varStatus="status" var="usermapEL">
        <c:set var="src" value="${usermapEL.properties['j:externalSource'].string}" />
        <c:if test="${!empty src && src == 'rest' }">
            <c:set var="created" value="${usermapEL.properties['jcr:created'].string}" />
            <c:set var="email" value="${usermapEL.properties['j:email'].string}" />           
            <c:if test="${!empty email && !empty created}">
                json.data.push({ "email":"${email}", "created":"${created}" });
            </c:if>
        </c:if>
    </c:forEach>
</script>

Thank for your help !

  • JQOM and query selector to select [jnt:user]
    2014/08/25 13:50

    minijoey <p>Hi everyone !</p> <p>I have a web service that link an external database to save some properties (email and creation date) of users account found in the [jnt:user] of Jahia. I use a query statement to get every users and a foreach loop to check if the properties I&#39;m looking for are not empty before pushing them in a JSON object. The problem is that I&#39;ve more than 26.000 users in Jahia and the query selector can&#39;t catch them all and create the JSON object inside the foreach loop ... I was thinking of a &quot;limit&quot; in my query statement, like &quot;get every account from 0 to 1000&quot; and after that &quot;get every account from 1001 to 2000&quot;, but it seems to be impossible. Any idee how to fix it ?</p> <p>Here&#39;s my code, in case it could help :</p> <p><em>&lt;%@ taglib prefix=&quot;c&quot; uri=&quot;http://java.sun.com/jsp/jstl/core&quot; %&gt;<br /> &lt;%@ taglib prefix=&quot;jcr&quot; uri=&quot;http://www.jahia.org/tags/jcr&quot; %&gt;<br /> &lt;%@ taglib prefix=&quot;query&quot; uri=&quot;http://www.jahia.org/tags/queryLib&quot; %&gt;<br /> &lt;%@ taglib prefix=&quot;template&quot; uri=&quot;http://www.jahia.org/tags/templateLib&quot;%&gt;</em></p> <p><em>&lt;jcr:jqom var=&quot;usersmaps&quot;&gt;<br /> &nbsp;&nbsp;&nbsp; &lt;query:selector nodeTypeName=&quot;jnt:user&quot;/&gt;<br /> &lt;/jcr:jqom&gt;</em></p> <p><em>&lt;c:url var=&quot;updateAdherentsUrl&quot;&nbsp; value=&#39;${url.base}${currentNode.path}.UpdateAdherents.do&#39;/&gt;</em></p> <p><em>&lt;script type=&quot;text/javascript&quot;&gt;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<br /> &nbsp;&nbsp; &nbsp;var json = { &quot;data&quot; : [] };<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;&lt;c:forEach items=&quot;${usersmaps.nodes}&quot; varStatus=&quot;status&quot; var=&quot;usermapEL&quot;&gt;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;c:set var=&quot;src&quot; value=&quot;${usermapEL.properties[&#39;j:externalSource&#39;].string}&quot; /&gt;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;c:if test=&quot;${!empty src &amp;&amp; src == &#39;rest&#39; }&quot;&gt;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;c:set var=&quot;created&quot; value=&quot;${usermapEL.properties[&#39;jcr:created&#39;].string}&quot; /&gt;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;c:set var=&quot;email&quot; value=&quot;${usermapEL.properties[&#39;j:email&#39;].string}&quot; /&gt;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;c:if test=&quot;${!empty email &amp;&amp; !empty created}&quot;&gt;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;json.data.push({ &quot;email&quot;:&quot;${email}&quot;, &quot;created&quot;:&quot;${created}&quot; });<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;/c:if&gt;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;/c:if&gt;<br /> &nbsp;&nbsp; &nbsp;&lt;/c:forEach&gt;<br /> &lt;/script&gt;</em></p> <p>Thank for your help !</p>

  • Number of messages  2
    Registration date Aug 25, 2014
    1 (1 Good)
    0 (0 Bad)

    Re : JQOM and query selector to select [jnt:user]

    by  glucazeau »  2014/08/28 15:06

    Hello Joey,

    If you can use the query:definition tag there is a "limit" parameters that could fix your issue.

    http://downloads.jahia.com/downloads/jahia/jahia6.6.0/jahia-taglib-6.6.0.0-tlddoc/query/definition.html

    Let me know if it helped.

    Regards,

    Guillaume

  • Re : JQOM and query selector to select [jnt:user]
    2014/09/04 06:59

    glucazeau <p>Hello Joey,</p> <p>If you can use the query:definition tag there is a &quot;limit&quot; parameters that could fix your issue.</p> <p><a href="http://downloads.jahia.com/downloads/jahia/jahia6.6.0/jahia-taglib-6.6.0.0-tlddoc/query/definition.html">http://downloads.jahia.com/downloads/jahia/jahia6.6.0/jahia-taglib-6.6.0.0-tlddoc/query/definition.html</a></p> <p>Let me know if it helped.</p> <p>Regards,</p> <p>Guillaume</p>

  • Number of messages  93
    Registration date Aug 28, 2014
    0 (0 Good)
    0 (0 Bad)

    Re : JQOM and query selector to select [jnt:user]

    by  minijoey »  2014/09/04 06:59

    Hi glucazeau !

    Thanks for your answer and the link, it helped me to understand how to properly use the query:definition tag. But in fact, what I was trying to do is nearly impossible in JCR (or I didn't found the right tutorial haha) so I created an external java class in my Java Resources folder to make the dynamic query request with the parameters I get from the form in my JSP file.

    Just remember that query tag is not as flexible as we could think, and creating an external query including GET method parameters from a form is a better and easier way to communicate from JSP to MySQL server when you have to make custom and dynamic request.

    Anyway, thanks for your help, I'm happy to see that someone answered me !

    Best regards

    Joey

  • Re : JQOM and query selector to select [jnt:user]
    2014/09/04 06:59

    minijoey <p>Hi glucazeau !</p> <p>Thanks for your answer and the link, it helped me to understand how to properly use the query:definition tag. But in fact, what I was trying to do is nearly impossible in JCR (or I didn&#39;t found the right tutorial haha) so I created an external java class in my Java Resources folder to make the dynamic query request with the parameters I get from the form in my JSP file.</p> <p>Just remember that query tag is not as flexible as we could think, and creating an external query including GET method parameters from a form is a better and easier way to communicate from JSP to MySQL server when you have to make custom and dynamic request.</p> <p>Anyway, thanks for your help, I&#39;m happy to see that someone answered me !</p> <p>Best regards</p> <p>Joey</p>

  • Number of messages  2
    Registration date Sep 4, 2014
    Contact
    Share
    Feedback

    Get in touch

    Whether you are a current user or if you are just evaluating Jahia, we are here to help.

    Contact us

    Share this page