You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
« Previous
Version 30
Next »
This is good example how we can Eliminate bottlenecks with IguanaX by building a custom file reader component which has a simple interface for a unique purpose rather using a general purpose no code solution - see The problem with no-code solutions
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 JJ99, others XYZ etc. depending on the source.
Let’s do it!
Import a custom version of the file reader from git@bitbucket.org:interfaceware/file_tutorial.git
Create component +FROM URL
Copy paste the URL from here:
git@bitbucket.org:interfaceware/file_tutorial.git
This component generates some test files to make it easier to learn how to make a custom file reader.
Click on the Customize and Copy and Edit button so you can alter the source code
See Customizing components to see how done if you have not done this before.
Click on MatchRules.lua to see where we need to alter the code
Navigate to MatchRules.lua in the Project Tree. This is the function we need to alter:
function MatchFile(FileName)
return true
end
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. We need this function to return true when the matching criteria are met.
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.
function MatchFile(FileName)
local JustFileName = FILfilename(FileName)
trace(JustFileName)
return true
end
These are the concepts we have used:
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:
See Custom Fields to understand how this was created.
Extract the prefixes from the custom fields
Now we need to extract the fields from the custom configuration. So replace the contents of the MatchRules.lua file with this new content:
function APPidList()
local IdList = component.fields()["ClientList"]
return IdList
end
function MatchFile(FileName)
local IdList = APPidList()
trace(IdList)
local JustFileName = FILfilename(FileName)
trace(JustFileName)
return true
end
Concepts used:
Break the comma delimited string into a list
So we add one line after line 2:
IdList = IdList:split(",")
You should see something like:
Concepts used:
Make a function which takes the prefix and sees if the filename starts with it
So now we make a function to determine if the file name matches
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:
Concepts used:
Now change the matching code so we go through all the of the list
Let’s modify the code to go through the entire list of prefixes:
for i = 1, #IdList do
if APPmatchPrefix(IdList[i], JustFileName) then
return true
end
end
return false -- we didn't match anything
And this is what you should see:
Concepts used:
Commit your changes, alter the component to run on the new commit and run it!
And done! The next steps are how you could further refine the code
Make the configuration more robust by striping white space from the list ClientList
That would involve looping through the list and removing white space from each ID:
Concepts:
There is no limit to how you can streamline the usage of a custom component - if that helps address a bottleneck, then it is well worth it.