This is good example of how we can Eliminate bottlenecks with IguanaX . This is the problem. usePrefix Namespaces for Separating Concerns by building a custom file reader component which has a simple interface for a unique purpose rather than using a general purpose no code solution - see The problem with no-code solutions.
Here’s a scenario:
A large lab needs to have a file reading component which can feed files from different customers based on the prefix of the file, i.e. some files start with
...
JJ99, others XYZ etc. depending on the source.
...
How can we make a super streamlined component which:
Matches the requirements
Is easy to implement
Simplifies operations
Expand |
---|
title | Build a custom configuration |
---|
|
See Custom Fields. We take the base File Reader and add Client ID List which will be a comma delimited list of the prefixes we want to filter on: Image Removed |
...
title | We need to modify the matching algorithm - what do we start with? |
---|
...
Let’s do it!
Expand |
---|
title | Use +FROM URL to import a custom version of the file reader component for this tutorial |
---|
|
This component generates some test files to make it easier to learn how to make a custom file reader. You can useCreate component +FROM URL to import the component. Copy paste the URL from here: Code Block |
---|
git@bitbucket.org:interfaceware/file_tutorial.git |
|
Expand |
---|
title | Click Edit on the component card, then MAKE A COPY AND EDIT to open the Translator editor |
---|
|
Refer to Edit a Component to see how it's done if you have not done this before. |
Expand |
---|
title | Examine the Custom Field configurations in the component in config.json |
---|
|
To simplify the tutorial we have set these up a ClientList with the filename prefix Ids. Click on the config.json and you should see: Image AddedSee Custom Fields to understand how this was created. |
Expand |
---|
title | Click on MatchRules.lua in the Project Tree 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: Code Block |
---|
| function MatchFile(FileName)
return true
end |
The file reader component is deliberately simple and uses /wiki/spaces/IXB/pages/3181903910 separation of concerns to make it more obvious how to modify the code to meet new needs. So this is what we are starting off with. We We need this function to return true when the matching criteria are met. https://bitbucket.org/interfaceware/fromfile/src/main/MatchRules.lua Code Block | --What file extensions do we match?
local FileExtensionMatchSet={
txt=true,
log=true,
hl7=true
}
|
Expand |
---|
title | Let's extract the filename using FILfilename() from the FIL Library, 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)
local Extn = FILextension(FileNametrace(JustFileName)
Extnreturn = Extn:lower()
return FileExtensionMatchSet[Extn]
endtrue
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 |
function IdListEdit MatchRules.lua to extract the prefixes from the custom fields |
|
Create a second function, APPidList, to extract the ClientList prefixes from the custom fields and update MatchFile to call APPidList. You can replace the contents of the MatchRules.lua file with this new code: Code Block |
---|
| function APPidList()
local IdList = component.fields()["Client Id ListClientList"]
forreturn iIdList
=end
1,
#IdList dofunction MatchFile(FileName)
local IdList[i] = IdList[i]:trimWSAPPidList()
end
end |
|
Expand |
---|
Expand |
---|
Expand |
---|
title | We need to get the list of prefixs |
---|
|
Code Block | function MatchFile(FileNameIdListcomponent.fields()["Client Id List"]
FILfilename(FileName)
trace(JustFileName)
return true
end |
Concepts used: |
Expand |
---|
title | Break the comma delimited string into a list to get each prefix Id |
---|
|
We can quickly do this by adding one line to AppidList after line 2: Code Block |
---|
| IdList = IdList:split(",") |
You should see something like: Image AddedConcepts used: |
Expand |
---|
title | Make a matching function which takes the prefix and sees if the filename starts with it |
---|
|
Create a third function, APPmatchPrefix, to determine if the filename matches the prefix. You can copy the code below: APPmatchPrefix(Prefix, FileName)
local | JustFileNameFILfilename(FileName)
for i = #IdList do
IdList[i]Part, Prefix)
return (Part == | local Id = IdList[i]:trimWS()
local Part = JustFileName:sub(1, #Id)
See the screenshot below and add a line to MatchFile to call and invoke AppmatchPrefix. Image AddedConcepts used: |
Expand |
---|
title | Now change the matching code in MatchFile() so we iterate through the prefix list |
---|
|
Let’s modify the code to go through the entire list of prefixes: Code Block |
---|
| for i = 1, #IdList do
if APPmatchPrefix(IdList[i], JustFileName) then
| trace(Id,Part)if (Part == Id) then trueend end
endAnd this is what you should see: Image AddedConcepts used: |
Expand |
---|
title | Make it super simple to see the status |
---|
| Image Removed
expandCommit your changes, alter the component to run on the new commit, and run it! |
|
Commit and Push Changes to Git and go to the component card for Choosing the code to run for your component. |
You’re done! The next steps are how you could further refine the code
Expand |
---|
title | Make the logging really intuitivethe configuration more robust by trimming the white space from the list of prefixes |
---|
|
This means refining the APPidList function. That would involve looping through the list and removing white space from each ID: Image AddedConcepts: |
Expand |
---|
title | Avoid the bottlenecks of waiting on development resources |
---|
| Image Removed
Expand |
---|
|
Expand |
---|
title | Now find the next bottleneck, fix it and rinse-repeat |
---|
|
Customize the logging using iguana.log* |
|
Add intuitive Custom Logging for your component to increase visibility into processing and adding meaningful messages to help with troubleshooting. You can see an example of this in main.lua on line 25: Code Block |
---|
| iguana.log("Polling every "..Polltime.." seconds"); |
Try it for yourself! See Concatenating strings for a quick explanation on the double-dot notation. |
Expand |
---|
title | Customize the status using component.setStatus{data="Text"} |
---|
|
Add Custom Status for your component to have it display real time updates at the bottom of the component card as its running. This component already creates custom status on lines 31-36 of main.lua. Try it for yourself! |
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.