AnsweredAssumed Answered

Using core:include in Gel Scripts

Question asked by gcubed Champion on Mar 3, 2014
Latest reply on Mar 4, 2014 by Dave

 

Is anyone using core:include for reusable gel script components?

I have been looking over our scripts and I see a lot of code snippets (login, logout, read,…) that are the same.

I have played around with core:include and found it works as advertised with the benefit of reducing the script verbiage.  Has anyone stubbed their toes using core:include or see any issue with it in a production environment?

Here is the test script I was using to test-out core:include for Login/Logout/ReadProjects.

<?xml version="1.0" encoding="utf-8"?>
<gel:script
    xmlns:core="jelly:core"
    xmlns:xog="http://www.niku.com/xog"
    xmlns:x="jelly:org.apache.commons.jelly.tags.xml.XMLTagLibrary"
    xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
    xmlns:soap="jelly:com.niku.union.gel.SOAPTagLibrary"
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:nikuq="http://www.niku.com/xog/Query"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <gel:out>Starting Test Include</gel:out>
    <!-- Setup our script exception catch -->
    <core:catch var="exception">
        <gel:parameter var="XogUserName" />
        <gel:parameter var="XogPassword" />
        <!-- Wrap our script in a loop so we can use break to exit cleanly -->
        <core:set var="scriptBreak" value="[1]" />
        <core:forEach var="dummy" items="${scriptBreak}">
            <!-- Login -->
            <core:include file="gel/Login_Include.xml" />
            <core:if test="${XogSessionId == null}">
                <core:break />
            </core:if>
            <!-- Get our xogReadProjects soap:message query -->
            <core:include file="gel/XogReadProjects_Include.xml" />
            <!-- Add a filter to our read -->
            <gel:parse var="readProjectFilter">
                <Filter name="projectID" criteria="OR">PRJ00000539,PRJ00000645,PRJ00000728</Filter>
            </gel:parse>
            <gel:set value="${readProjectFilter}" select="$xogReadProjects//Query" insert="true" />
            <!-- Save our results into a file just to see what we get -->
            <gel:serialize fileName="xogReadProjects1.xml" var="${xogReadProjects}" />
            <!-- Invoke our soap endpoint -->
            <soap:invoke endpoint="${XogUrl}" var="projectResults">
                <soap:message>
                    <gel:include select="$xogReadProjects" />
                </soap:message>
            </soap:invoke>
            <!-- Save our results into a file just to see what we get -->
            <gel:serialize fileName="projectResults1.xml" var="${projectResults}" />
            <!-- Logout -->
            <core:include file="gel/Logout_Include.xml" />
        </core:forEach>
        <gel:out>Finish Test Include</gel:out>
    </core:catch>
    <core:if test="${exception != null}">
        <gel:log level="FATAL" message="    ${exception}" />
    </core:if>
</gel:script>

 

V/r,

Gene

Outcomes