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 |
---|
title | Open the component in the translator with the customize link |
---|
|
See Customizing components to see how done if you have not done this before. |
Expand |
---|
title | Build 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 |
---|
title | We 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 |
---|
| function MatchFile(FileName)
return true
end |
|
Expand |
---|
title | Let'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 |
---|
| function MatchFile(FileName)
local JustFileName = FILfilename(FileName)
trace(JustFileName);
return true;
end |
These are the concepts we have used: |
Expand |
---|
title | Start the new MatchFile logic with getting the list of prefixes and removing white space |
---|
| We’ll apply /wiki/spaces/IXB/pages/3181903910 and write this as a function:
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 AddedSee Custom Fields to understand how this was created. |
Expand |
---|
title | Extract 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 |
---|
| 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 |
---|
title | Break the comma delimited string into a list |
---|
|
So we add one line after line 2: Code Block |
---|
| IdList = IdList:split(",") |
Iterating through a Lua table as list Trimming white space You should see something like: Image AddedConcepts used: |
Expand |
---|
title | Make 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 |
---|
| 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 AddedConcepts used: |
Expand |
---|
title | Now 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: Code Block | function MatchFile(FileName)
local IdList = APPidList()
local JustFileName = FILfilename(FileName)
|
---|
| 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 AddedFIL Library used to get the file nameConcepts used: |
...