Creating the Copy Files in Directory workflow

This task creates the top-level workflow, called Copy Files in Directory, in the same module as the List directory, Copy File, and Make connection details for Invoke Command workflows. It contains the other workflows that you created in the tasks in this section.

This page includes the following topics related to the task:

Before you begin

To create and use this workflow, you must have completed all the previous tasks in this section. The following workflows must already exist:

  • List directory
  • Make connection details for Invoke Command
  • Copy File

The following module configuration items must exist:

  • CMD_Adapter
  • DirectoryCommand
  • CopyCommand

To create the Copy Files in Directory workflow

  1. In the  Development Studio Project Navigator tree, right-click Samples and select New Process.
  2. In the Create New Process dialog box, perform the following actions:
    1. Type Copy Files in Directory in the Process Name field.
    2. Ensure that the Expose Process option In Schedules is selected.
    3. Type a description in the Description field.
      For example, type This workflow reads a specified directory and runs the copy command on each file found in the directory.
  3. Click OK.
    The new workflow name is added to the module in the Project Navigator, and the design canvas displays the new workflow with only the Start and End activities. The Copy Files in Directory workflow is displayed on a new tab, and any other open workflows are on different tabs. 

To configure the Start activity

  1. Double-click the Start activity on the design canvas.

  2. On the Properties tab of the Property Panel for the Start activity, create the first input parameter as follows:

    1. In the Input Parameter Name field, type source dir.

    2. Press Tab and verify that the name in the corresponding Context Name field is the same as in the Input Parameter Name field and that the Required check box is selected.

  3. Repeat step 2 to create the second input parameter, typing destination directory in the Input Parameter Name field, as shown in the following figure:


    Input parameters for Start activity

  4. Click OK to close the Property Panel for the Start activity and return to the design canvas.

  5. Click  to save the workflow.

To add the Make connections details for Invoke Command workflow

  1. Drag the Make connections details for Invoke Command workflow to the process canvas and connect it to the Start and End activities.

  2. Double-click the Call Process activity to open the Property Panel for the Call Process activity for the Make connections details for Invoke Command workflow.

     Development Studio created the output mappings automatically.

  3. In the Call process input mapping section of the Property Panel, double-click in the Input Name/Value field that corresponds to the adapter output context item.

    The Properties tab for that input is displayed.

  4. On the Properties tab, for Input Parameter type, select Module Configuration.

  5. Expand the configuration group, expand the Samples module, and expand the Samples group.

  6. Select CMD_Adapter from the Samples group, as shown in the following figure; then click OK.

    Properties tab showing selected module configuration item

  7. Click OK to close the Properties tab and display the Property Panel for the Call Process activity, as shown in the following figure.

    Property Panel for the Call Process activity

  8. Click OK to close the Property Panel and return to the design canvas.

  9. Save the workflow.

To add the List directory workflow

  1. Drag the List directory workflow to the process canvas and connect it to the workflow between the Make connections details for Invoke Command workflow and the End activity.

  2. Save the Copy Files in Directory workflow.

  3. Double-click the Call Process activity to open the Property Panel for the Call Process activity for the List directory workflow.

     Development Studio created the output mappings automatically.

  4. In the Call process input mapping section of the Property Panel, double-click in the Input Name/Value field that corresponds to the adapter name context item.

    The Properties tab for that input is displayed.

  5. On the Properties tab, select Module Configuration for Input Parameter type.

  6. Expand the configuration group, expand the Samples module, and expand the Samples group.

  7. Select CMD_Adapter from the Samples group and then click OK.

  8. Repeat steps 4 through 7 to select the DirectoryCommand configuration item for the directory command context item.

  9. In the Call process input mapping section of the Property Panel, double-click in the Input Name/Value field that corresponds to the directory name output context item.

  10. For Input Parameter type, select Context item.

  11. Use the Context Browser to select the source dir context item, and then click OK.

    The Property Panel shows all the input and output mappings, as shown in the following figure.

    Property Panel with input and output mappings for the called process

  12. Click OK to close the Property Panel.

  13. Save Copy Files in Directory workflow.

To test the Copy Files in Directory workflow

  1. In the toolbar below the menu bar, click ExecuteProcessAction .

    If you have not already logged on to the grid,  Development Studio displays the Login dialog box. Development Studio uses the peers and adapters on the grid to test the workflow.

  2. If you have not already logged on to the grid, log on; otherwise, proceed to step 3.

  3. In the Execution Mode dialog box, select Test as if triggered by a rule, schedule or SOAP, and then click OK.

  4. In the Job Input Parameters dialog box, double-click in the Value field for the source dir parameter and type the name of the directory from which you want to copy the files.

  5. Double-click in the Value field for the destination directory parameter, and type the name of the directory to which you want to copy the files.

    Even though the Copy Files in Directory workflow does not use the destination directory yet, you are required to provide the name. The following figure shows the Job Input Parameters dialog box with values for the source directory and destination.

    Example input parameters for testing the workflow

  6. Click OK.

     Development Studio runs the Copy Files in Directory workflow. The console window opens below the process canvas, and the Process Log tab displays the results of the workflow execution. These are the same results that are posted to the processes.log file when the workflow is run on the grid. On the process canvas, the Call Process activities have brown boxes around them to indicate that they have been executed.

  7. Verify that the last line in the console window is The process terminated in the completed state.

    This message indicates that the workflow that you created ran to completion.

    Do not clear or close the console window.

  8. (optional) Review the contents of the console window.

    This is the information that would have been written to the log file if the workflow had been run on the grid.

To gather sample data

  1. Open a text editor and create a blank document.

  2. Copy the entire contents of the console window's Process Log tab and paste it in the blank document.

  3. Save the document as temp.txt.

  4. Search temp.txt for directory list.

  5. Copy the contents of the directory list, beginning with <result> and ending with </result>.

    Do not copy the square bracket at the end of the results.

  6. Paste the directory list results in a new blank document and save it as dir_list_sample.txt.

  7. In the dir_list_sample.txt file, change every instance of <DIR> to &amp;lt;DIR&amp;gt;.
    The transform editor that you use in the subsequent activity would treat <DIR> as badly formed XML. This step replaces it with equivalent valid XML.

  8. Save the dir_list_sample.txt file.

    An example dir_list_sample.txt follows:

    <result>
    <line index="2"> Volume Serial Number is 6850-9DBA</line>
      <line index="3"> Directory of c:\pictures</line>
      <line index="4">12/23/2010  04:52 PM    &lt;DIR&gt;          .</line>
      <line index="5">12/23/2010  04:52 PM    &lt;DIR&gt;          ..</line>
      <line index="6">12/14/2007  02:21 PM            33,063 IMG_0307.JPG</line>
      <line index="7">12/14/2007  02:21 PM            28,606 IMG_0308.JPG</line>
      <line index="8">12/14/2007  02:21 PM            24,724 IMG_0309.JPG</line>
      <line index="9">12/14/2007  02:21 PM            31,945 IMG_0310.JPG</line>
      <line index="10">12/14/2007  02:21 PM            30,995 IMG_0311.JPG</line>
      <line index="11">12/14/2007  02:21 PM            24,573 IMG_0312.JPG</line>
      <line index="12">12/14/2007  02:21 PM            24,799 IMG_0313.JPG</line>
      <line index="13">12/14/2007  02:21 PM            23,329 IMG_0314.JPG</line>
      <line index="14">12/14/2007  02:21 PM            22,762 IMG_0315.JPG</line>
      <line index="15">12/14/2007  02:21 PM            25,046 IMG_0316.JPG</line>
      <line index="16">12/14/2007  02:21 PM            19,980 IMG_0317.JPG</line>
      <line index="17">12/14/2007  02:21 PM            25,837 IMG_0318.JPG</line>
      <line index="18">12/14/2007  02:21 PM            25,277 IMG_0319.JPG</line>
      <line index="19">12/14/2007  02:21 PM            24,467 IMG_0320.JPG</line>
      <line index="20">12/14/2007  02:21 PM            25,258 IMG_0321.JPG</line>
      <line index="21">12/14/2007  02:21 PM            26,491 IMG_0322.JPG</line>
      <line index="22">12/14/2007  02:21 PM            28,935 IMG_0323.JPG</line>
      <line index="23">12/14/2007  02:21 PM            24,494 IMG_0324.JPG</line>
      <line index="24">12/14/2007  02:21 PM            25,990 IMG_0325.JPG</line>
      <line index="25">12/14/2007  02:21 PM            29,667 IMG_0326.JPG</line>
      <line index="26">12/14/2007  02:21 PM            28,715 IMG_0327.JPG</line>
      <line index="27">12/14/2007  02:21 PM            32,567 IMG_0328.JPG</line>
      <line index="28">              22 File(s)        587,520 bytes</line>
      <line index="29">               2 Dir(s)   1,633,210,368 bytes free</line>
    </result>
  9. In the console window, click Clear and then click Close.

To add a For activity

  1. Drag a For activity to the design canvas, and connect it to the Copy Files in Directory workflow between the List directory Call Process activity and the End activity.

    Each For activity includes a For component and an End For component. Connect the For component to the List directory activity and the End For component to the End activity.

  2. Double-click the For activity to open its Property Panel.

  3. Select Context item as the type of input parameter.

  4. Use the Context Browser to select the directory list context item.

  5. In the Transform area, select the Advanced transform editor.

  6. Use the Advanced transform editor to extract the file information from the directory list as follows:

    1. In the Sample Source pane of the Transform Editor Setup Wizard, select My Samples and click  to create a new sample.

    2. In the File Name field of the Input dialog box, type sample directory list, and then click OK.

      In the bottom pane of the Select Resource dialog box, <value/> is displayed.

    3. Use a text editor to open the dir_list_sample.txt file and copy its entire contents.

      Copy from <result> to </result>, including all of the angle brackets.

    4. In the bottom pane of the Select Resource dialog box, delete the <value/> text and paste the result text that you copied from the dir_list_sample.txt file.

    5. Click , and then click Finish.

      The Transform Editor Setup Wizard closes and the XPath transform editor displays the directory list result text in the left pane, as shown in the next figure.

    6. (optional) If the Document pane is not visible at the bottom of the XPath transform editor, drag the divider up from the bottom to open the Document pane.

      XPath transform editor including the Document pane
       

    7. Use the Document pane to extract the lines that contain file names so that the For activity can process them (using the following steps). In this case, the lines containing file names are those that do not contain &lt;DIR&gt;or that do not begin with a space.

      1. In the XPath transform editor Document entry field type //line[ ] .
      2. Place the cursor between the square brackets; from the Groups list, select String, and from the Functions list, select Starts with; and click Insert.
        The Documententry field contains the following text:

        //line[ starts-with(., "text") ]
      3. Delete text and type a blank in its place.
        The Document entry field contains the following text:

        //line[ starts-with(., " ") ]
      4. Place the cursor after the closing parenthesis and before the closing square bracket; from the Groups list, select Operators, and from the Functions list, select Or; and click Insert.
        The Documententry field contains the following text:

        //line[ starts-with(., " ") or ]
      5. Place the cursor after or and before the closing square bracket; from the Groups list, select String, and from the Functions list, select Contains; and click Insert.
        The Documententry field contains the following text:

        //line[ starts-with(., " ")  or contains(., "text")   ]
      6. Delete text and type <DIR> in its place.
        The Document entry field contains the following text:

        //line[ starts-with(., " ")  or contains(., "<DIR>")   ]
      7. In the Document pane, click Generate Preview .
        This expression extracts the lines that do not contain file names, as shown in the following figure.

        Preview Drawer showing results of the XPath expression

        Note

        Ensure that the Format XML check box is selected.

      8. Highlight the entire contents of the square brackets, except for the spaces adjacent to the brackets; from the Groups list, select Boolean, and from the Functions list, select Not; and click Insert.
        The Document entry field contains the following text:

        //line[ not(starts-with(., " ")  or contains(., "<DIR>"))  ]
      9. In the Document pane, click Generate Preview .
        Now the expression extracts the lines that do contain file names, as shown in the following figure.

        Preview Drawer showing results of the final XPath expression

    8. Click Save and Exit to close the XPath transform editor.
      The Transform field on the Properties tab on the Property Panel for the For activity displays the expression that you created.
  7. On the Properties tab, select Context item as the output context type.

  8. Use the Context Browser to create a new context item called directory item.

  9. Click OK to close the Property Panel for the For activity.

To create the Assign activity in the For activity

  1. Drag an Assign activity from the Activity Palette to the process canvas.

  2. Connect the Assign activity to the workflow between the For component and the End For component.

  3. Double-click the new Assign activity to open its Property Panel.

  4. On the Properties tab of the Property Panel for the Assign activity, click  to add a new assign statement.

  5. On the Properties tab for the assign statement, select Context item as the input parameter type, and use the Context Browser to select the directory list context item.

  6. Use the Basic transform editor to extract the file name from the information in the directory list context item as follows:

    1. On the Properties tab, click Basic to open the Basic transform editor.

    2. Click  to open a sample from the resource area.

      The Select Resource dialog box is displayed.

    3. Highlight the My Samples folder and click  to create a new sample.

    4. In the File Name field of the Input dialog box, type directory item, and then click OK.
      In the bottom pane of the Select Resource dialog box, <value/> is displayed.

    5. Use a text editor to open the dir_list_sample.txt file and copy one line that contains a file name.

      Copy from <line> to </line>, including all of the angle brackets.

    6. In the bottom pane of the Select Resource dialog box, delete the <value/> text and paste the line that you copied.

    7. Click , and then click OK.

      The Select Resource dialog box closes and the Basic transform editor displays the sample line in the left pane.

    8. In the Basic transform editor, in the Function field, select String> Substring.

    9. In the first Operand field, type 40.

    10. In the second Operand field, type 256.

    11. In the upper\-right corner of the Basic transform editor, click Generate Preview.

      The Preview pane displays the file name.

    12. Click OK to close the Basic transform editor.

      The Transform field on the Properties tab on the Property panel displays Gets the Substring of length 256.0 starting at 40.0.

  7. On the Properties tab, for Output Context Type select Context item.

  8. Use the Context Browser to create a new context item called source file.

  9. Click OK to close the Properties*tab for the first assign statement.

  10. On the Properties tab of the Property Panel for the Assign activity, click  to add another assign statement.

  11. On the Properties tab for the assign statement, select String as the input parameter type.

  12. Right-click in the text entry field and select Local Context Item> Source dir.

     Development Studio inserts the source dir context item in the field.

  13. Type a backslash immediately after the context item.

  14. Right-click in the text entry field immediately after the backslash and select Local Context Item> Source file.

     Development Studio inserts the source file context item in the field, as shown in the following figure.

    Input source context items

  15. Use the Context Browser to select the source file context item as the output context item.

    This task changes the value of the source file context item.

  16. Click OK to close the Properties tab for the assign statement.

  17. Click OK to close the Properties tab for the Assign activity.

  18. Save the workflow.

To add the Copy File workflow

  1. Drag the Copy File workflow to the process canvas.

  2. Connect the Copy File workflow to the Copy Files in Directory workflow in the For activity, between the Assign activity and the End For component.

     Development Studio briefly displays a message that it has automatically mapped three of three inputs.

  3. Save the workflow.

The following figure shows the process canvas view of the finished Copy Files in Directory workflow.

Completed Copy Files in Directory workflow


Was this page helpful? Yes No Submitting... Thank you

Comments