3 Replies Latest reply on Aug 11, 2017 4:31 PM by Cheng Fang

    Inheritance and properties

    Richard Moore Expert

      I have two steps that are repeated in a job with different properties. Is there a way to call/include jsl for these two steps passing a different set of properties each time?

       

      Generic Include JSL:

       

       

       

      <step id="convertCobolData">
      <batchlet ref="convertCobolData">
      <properties>
      <property name="resource" value="?"/>
      <property name="copybook" value="?"/>
      <property name="mapping" value="?"/>
      <property name="output" value="?"/>
      </properties>
      </batchlet>

      <end on="COMPLETED" exit-status="COMPLETED"/>

      <fail on="*" exit-status="FAILED"/>

      </step>

      <step id="deleteInput">

       

      <batchlet ref="deleteFile">
      <properties>
      <property name="resource" value="?"/>
      </properties>
      </batchlet>

      <end on="COMPLETED" exit-status="COMPLETED"/>

      <fail on="*" exit-status="FAILED"/>

      </step>


      Job:
      1. Call include jsl with value for resource, copybook, mapping, and output values for file1.
      2. Call include jsl with value for resource, copybook, mapping, and output values for file2.
        • 1. Re: Inheritance and properties
          Cheng Fang Master

          You can declare an abstract step that only includes the common part.  The abstract step can reside in the same job xml file as the child steps, or in a separate file.  In later case, the inheriting child step should have jsl-name attribute pointing to the job definition containing the parent.

           

          Then have your step1 and step2 both inherit from the abstract step.

           

          step1 and step2 each contain their own step properties.

           

          Some examples:

          jsr352/test-apps/chunkSkipRetry/src/main/resources/META-INF/batch-jobs at master · jberet/jsr352 · GitHub

          • 2. Re: Inheritance and properties
            Richard Moore Expert

            So if I setup the following abstract job, steps, flows how do I inherit it from my concrete job and pass the properties needed for the two batchlets (convertCobolData and deleteFile) in the abstract job?

             

            <job id="concreteCobolDataConverter" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0">

             

               <step id="conversion1" parent="conversionFlow" jsl-name="abstractCobolDataConverter">

                  <!-- custom property values for conversion1: resource, copybook, mapping, and output. -->

               </step>

             

               <step id="conversion2" parent="conversionFlow" jsl-name="abstractCobolDataConverter">

                  <!-- custom property values for conversion2: resource, copybook, mapping, and output. -->

               </step>

             

            </job>

             

             

            <job id="abstractCobolDataConverter" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0">

               <step id="step0" abstract="true">
                  <batchlet ref="convertCobolData"/>

                  <!-- requires properties: resource, copybook, mapping, and output. -->
               </step>

             

               <step id="step1" abstract="true">

                  <batchlet ref="deleteFile"/>

                  <!-- requires properties: resource -->

               </step>



               <flow id="conversionFlow" abstract="true">
                  <step id="flow0.step0" parent="step0"/>

                  <step id="flow0.step1" parent="step1"/>
               </flow>

            </job>

            • 3. Re: Inheritance and properties
              Cheng Fang Master

              You can try using #{jobProperties['X']}?:defaultValue;

               

              in your abstract step, declare the batchlet with all its batch properties:

               

              <batchlet ref="xxx">

              <properties>

              <property name="a" value="#{jobProperties['a']}?:defaultValue;"/>

              </properties>

               

              in child step,

               

              <step id="step1" parent="step0" jsl-name="xxx">

              <properties>

              <property name="a" value="a value"/>

              </properties>

              </step>

               

              in another child step:

               

              <step id="step2" parent="step0" jsl-name="xxx">

              <properties>

              <property name="a" value="a different value"/>

              </properties>

              </step>

               

              but as you can see, it becomes quite verbose.  Unless you have many common parts between child steps and parent steps, you might just as well use the batchelt directly in step1 and step2 (i.e., without using inheritance).