AnsweredAssumed Answered

gel:serialize for non-xml file generation

Question asked by SanjayKoshtiDiscover on Oct 6, 2014
Latest reply on Oct 11, 2014 by gcubed

Hi, we have file generation process which generates non-xml tab-spearated file.


Our file generation process works without any issues when run manually. But when scheduled it fails some times.

Error: complete exception trace: org.apache.commons.jelly.JellyTagException:
null:74:67: <gel:forEach> java.lang.NullPointerException


Following is the sample code for file generation


*************************************************
<gel:script
  xmlns:core="jelly:core"
  xmlns:file="jelly:com.niku.union.gel.FileTagLibrary"
  xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
  xmlns:nikuq="http://www.niku.com/xog/Query"
  xmlns:soap="jelly:com.niku.union.gel.SOAPTagLibrary"
  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:util="jelly:util"
  xmlns:xog="http://www.niku.com/xog"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <!-- Get Validables -->
  <core:set value="${g_loglevel}" var="LogLevel"/>

  <gel:log level="{LogLevel}">LogLevel = ${LogLevel}</gel:log>
  <gel:log level="{LogLevel}">g_loglevel = ${g_loglevel}</gel:log>
  <gel:log level="{LogLevel}">g_xogurl = ${g_xogurl}</gel:log>
  <gel:log level="{LogLevel}">g_xoguser = ${g_xoguser}</gel:log>
  <gel:log level="{LogLevel}">g_xogpass = ${g_xogpass}</gel:log>
  <gel:log level="{LogLevel}">g_sftppathout = ${g_sftppathout}</gel:log>
  <gel:log level="{LogLevel}">g_sftpfilein = ${g_sftpfilein}</gel:log>
  <gel:log level="{LogLevel}">g_sftpfileout = ${g_sftpfileout}</gel:log>
  <gel:log level="{LogLevel}">g_sftpnsql = ${g_sftpnsql}</gel:log>

  <!-- Construct the Query API request for the NSQL query "DFS_RES_DWH_SFTP" -->
  <gel:parse var="xoginput">
    <Query xmlns="http://www.niku.com/xog/Query">
      <Code>${g_sftpnsql}</Code>
    </Query>
  </gel:parse>
  <soap:invoke endpoint="${g_xogurl}" var="xogresponse">
    <soap:message>
      <soapenv:Envelope>
        <soapenv:Header>
          <xog:Auth>
            <Username>${g_xoguser}</Username>
            <Password>${g_xogpass}</Password>
          </xog:Auth>
        </soapenv:Header>
        <soapenv:Body>
          <gel:include select="$xoginput"/>
        </soapenv:Body>
      </soapenv:Envelope>
    </soap:message>
  </soap:invoke>

  <!-- Extract the sessionID so we may logout later -->
  <gel:set asString="true" select="$xogresponse/soapenv:Envelope/soapenv:Body/xog:SessionID/text()" var="sessionID"/>
  <gel:out>SessionID = ${sessionID}</gel:out>

  <!-- Extract the records -->
  <gel:set select="$xogresponse/soapenv:Envelope/soapenv:Body/nikuq:QueryResult/nikuq:Records" var="records"/>
  <gel:set asString="true" select="$records" var="recordstext"/>
  <gel:out>${recordstext}</gel:out>

  <!-- Create a tab-delimited file from the results -->
  <file:writeFile delimiter="&#x9;" embedded="true" fileName="${g_sftppathout}/${g_sftpfileout}">

    <!-- Start - Column Headers go here -->
    <file:line>
       <file:column value="Unique ID"/>
       <file:column value="Time Period Internal ID"/>
       <file:column value="Time Period Start"/>
       <file:column value="Time Period Finish"/>
       <file:column value="Task Assignment Internal ID"/>
       <file:column value="Task Internal ID"/>
       <file:column value="Task Name"/>
       <file:column value="Investment Internal ID"/>
       <file:column value="Investment ID"/>
       <file:column value="Actuals"/>
    </file:line>
    <!-- End - Column Headers go here -->

    <gel:forEach select="$records//nikuq:Record" var="xog_record">
      <file:line>
        <gel:forEach select="$xog_record/*" var="xog_data">
          <gel:set asString="true" select="$xog_data/text()" var="xog_data"/>
   <!--gel:log level="{LogLevel}">File column data = ${xog_data}</gel:log-->
          <file:column value="${xog_data}"/>
        </gel:forEach>
      </file:line>
    </gel:forEach>
  </file:writeFile>

  <gel:log level="{LogLevel}">File Generated = "${g_sftppathout}/${g_sftpfileout}"</gel:log>

  <!-- Now log out -->
  <soap:invoke endpoint="${g_xogurl}" var="logout">
    <soap:message>
      <soapenv:Envelope>
        <soapenv:Header>
          <xog:Auth>
            <xog:SessionID>${sessionID}</xog:SessionID>
          </xog:Auth>
        </soapenv:Header>
        <soapenv:Body>
          <xog:Logout/>
        </soapenv:Body>
      </soapenv:Envelope>
    </soap:message>
  </soap:invoke>
</gel:script>

*************************************************

Support has asked to use "<gel:serialize>" tab to resolve but as it is not a XML file, not sure how do I use it.Can some one share sample code for using "<gel:serialize>" with non-XML file generation?

Outcomes