Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This is good example how we can Eliminate bottlenecks with IguanaX. This is the problem. A large lab needs to have a file reading component which can feed files from different customers based on prefix of the file, i.e. some files start with JJ333JJ99, others XYZ etc. depending on the source.

...

Expand
titleOpen the component in the translator with the customize link

See Customizing components to see how done if you have not done this before.

Expand
titleBuild a custom configuration

See Custom Fields - We can add ClientList which will be a comma delimited list of the prefixes we want to filter on:

Image Removed

Expand
titleWe need to modify the matching algorithm - what do we start with?

The file reader component is deliberately simple and uses /wiki/spaces/IXB/pages/3181903910 to make it more obvious how to modify the code to meet new needs. So this is what we are starting off with. We need this function to return true when the matching criteria are met.

https://bitbucket.org/interfaceware/fromfile/src/main/MatchRules.lua

Code Block
languagelua
function MatchFile(FileName)
   return true
end
Expand
titleLet's extract the filename so we can look at it:

Change the matching to add in two lines :so we can see the filenames we need to filter on.

Code Block
languagelua
function MatchFile(FileName)
   local JustFileName = FILfilename(FileName)
   trace(JustFileName);
   return true;
end

These are the concepts we have used:

We’ll apply /wiki/spaces/IXB/pages/3181903910 and write this as a function:

Expand
titleStart the new MatchFile logic with getting the list of prefixes and removing white space
Code Block
Examine the custom configuration in the component

To simplify the tutorial we have set these up already. Click on the config.json and you should see:

Image Added

See Custom Fields to understand how this was created.

Expand
titleExtract the prefixes from the custom fields

Now we need to extract the fields from the custom configuration. So we start with this function:

Code Block
languagelua
function APPidList()
   local IdList = component.fields()["ClientList"]
   IdList =return IdList:split(",")
end

function forMatchFile(FileName)
i = 1, #IdList do
      IdList[i]local IdList = IdList[i]:trimWSAPPidList()
   endtrace(IdList)
   returnlocal IdListJustFileName end

function MatchFile= FILfilename(FileName)
   local IdList = APPidList();trace(JustFileName)
   return true
end

These are the concepts we have Concepts used:

Expand
titleBreak the comma delimited string into a list

So we add one line after line 2:

Code Block
languagelua
IdList = IdList:split(",")
  • Iterating through a Lua table as list

  • Trimming white space

    You should see something like:

    Image Added

    Concepts used:

    Expand
    titleMake a function which takes the ID prefix and sees if the filename starts with it

    So now we make a function to determine if the file name matches

    Code Block
    languagelua
    function APPmatchPrefix(Prefix, FileName)
       local Part = FileName:sub(1, #Prefix)
       trace(Part, Prefix)
       return (Part == Prefix)
    end

    And we’ll call it as part of the MatchFile routine:

    Image Added

    Concepts used:

    Expand
    titleNow put all the matching logic togetherchange the matching code so we go through all the of the list

    We write the new MatchFile function based on the functions we have written already:

    function MatchFile(FileName) local IdList = APPidList() local JustFileName = FILfilename(FileName)
    Code Block
    languagelua
    for i = 1, #IdList do
      
       if APPmatchPrefix(IdList[i], JustFileName) then  
            return true;
          end
       end
    end

    Concepts usedAnd this is what you should see:

    A function Image Added

    FIL Library used to get the file name

    Concepts used:

    ...