REST as a validation mechanism

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
PointsWell
Posts: 1460
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

REST as a validation mechanism

Post by PointsWell »

I am currently looking at using a number of APIs to improve data quality and reduce data entry where possible.

For example UK banks use two identifying characteristics,
Sort Code - which identifies the bank and branch, and
Account Number - which identifies the account (obvs).

Now from the Sort Code you can evaluate a range of useful information, such as Name of the Bank, Address of the Bank and the Telephone number. But more interestingly you can identify the BIC / SWIFT code and then identify the IBAN, which then makes international payments easier (as all of EU use IBAN and a growing number of non EU countries).

So far so good, except that I'd like to dynamically add all of this information while the user is keying in the form. Why, would I do that if the information is all available elsewhere? Because the EICSD where it comes from is borne from EDI standards from mainframe times and sometimes will split a bank name or address in a less than optimal manner. Therefore I'd like to capture the data on the form while the user is keying it in allowing them to tidy up the single source of truth data.

The challenge:
You cannot REQUEST SERVICE from a business rule, which is essentially where you'd need to trigger it.

Does anyone have any suggestions as to how to make it call the API before the form is saved?
BenHayat
Posts: 2749
Joined: Thu Dec 23, 2010 5:48 am
Location: Fla, USA
Contact:

Re: REST as a validation mechanism

Post by BenHayat »

David, are these calls, cascading calls, meaning the user selection from one call affect the filtering on the next call?
If not, does it make sense to pre fetch them into a persistent or none-persistent tables before the form starts?
PointsWell
Posts: 1460
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

Re: REST as a validation mechanism

Post by PointsWell »

BenHayat wrote:David, are these calls, cascading calls, meaning the user selection from one call affect the filtering on the next call?
If not, does it make sense to pre fetch them into a persistent or none-persistent tables before the form starts?
I'm Sean

No I've not got that sophisticated yet. If you have the Sort Code then it should be populating everything from that. Essentially it is a single lookup to retrieve a json file of multiple records.
BenHayat
Posts: 2749
Joined: Thu Dec 23, 2010 5:48 am
Location: Fla, USA
Contact:

Re: REST as a validation mechanism

Post by BenHayat »

PointsWell wrote:
BenHayat wrote:David, are these calls, cascading calls, meaning the user selection from one call affect the filtering on the next call?
If not, does it make sense to pre fetch them into a persistent or none-persistent tables before the form starts?
I'm Sean

No I've not got that sophisticated yet. If you have the Sort Code then it should be populating everything from that. Essentially it is a single lookup to retrieve a json file of multiple records.
Sorry Sean, when you were talking about UK, I think we have a developer there by the name of David and I made the mistake.

If it is a one time call, I'd stage that form into two parts ( I know it would look cheesy, as we should be able to make REST calls in rules too). The first part to gather the code, save it in user object, run a process to save the data in a none-persistent object (be sure all this happens under the umbrella of ONE process, so the data will stay alive for your second form), then in the second form you can use the data object returned as drop down or however you want to use.
Not an elegant approach. but it might work.
ACDC
Posts: 1143
Joined: Sat Jun 30, 2007 5:03 pm
Location: California, USA

Re: REST as a validation mechanism

Post by ACDC »

The challenge:
You cannot REQUEST SERVICE from a business rule, which is essentially where you'd need to trigger it.
Is it not possible to start the REST process from an object rule that triggers the process. Also, have the object rule set to dynamic so it's triggered by some attribute recalculation on the form
PointsWell
Posts: 1460
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

Re: REST as a validation mechanism

Post by PointsWell »

ACDC wrote:
The challenge:
You cannot REQUEST SERVICE from a business rule, which is essentially where you'd need to trigger it.
Is it not possible to start the REST process from an object rule that triggers the process. Also, have the object rule set to dynamic so it's triggered by some attribute recalculation on the form
Nope. You can trigger a process to call the service but only on save and not dynamically.
ACDC
Posts: 1143
Joined: Sat Jun 30, 2007 5:03 pm
Location: California, USA

Re: REST as a validation mechanism

Post by ACDC »

Nope. You can trigger a process to call the service but only on save and not dynamically.
I seem to recall there was trick to do this, but now that I think of it, it may have been an Applicability rule on the form that i was thinking of
BobK
Posts: 545
Joined: Thu Jan 31, 2008 2:14 pm
Location: Cincinnati, Ohio, USA

Re: REST as a validation mechanism

Post by BobK »

PointsWell wrote: So far so good, except that I'd like to dynamically add all of this information while the user is keying in the form. Why, would I do that if the information is all available elsewhere? Because the EICSD where it comes from is borne from EDI standards from mainframe times and sometimes will split a bank name or address in a less than optimal manner. Therefore I'd like to capture the data on the form while the user is keying it in allowing them to tidy up the single source of truth data.
Ah, EDI such fond memories.

I said it before (see https://www.awareim.com/forum/viewtopic.php?f=1&t=10324) and I will say it again: you can use a java plug-in for this.

Yes, plug-ins require more work
Yes, if you do not know java, you have to find someone else to create it
Yes, if you do not know java and the plug-in needs to be changed sometime in the future, you have to hope the creator is still around.

but, barring a better solution, plug-ins work. From the post in the link above, I created a simple BSV and plug-in. The plug-in makes a REST call to validate a VAT and is executed from the BO rules and dynamically updates the form.
Bob
PointsWell
Posts: 1460
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

Re: REST as a validation mechanism

Post by PointsWell »

BobK wrote:
PointsWell wrote: So far so good, except that I'd like to dynamically add all of this information while the user is keying in the form. Why, would I do that if the information is all available elsewhere? Because the EICSD where it comes from is borne from EDI standards from mainframe times and sometimes will split a bank name or address in a less than optimal manner. Therefore I'd like to capture the data on the form while the user is keying it in allowing them to tidy up the single source of truth data.
Ah, EDI such fond memories.

I said it before (see https://www.awareim.com/forum/viewtopic.php?f=1&t=10324) and I will say it again: you can use a java plug-in for this.

Yes, plug-ins require more work
Yes, if you do not know java, you have to find someone else to create it
Yes, if you do not know java and the plug-in needs to be changed sometime in the future, you have to hope the creator is still around.

but, barring a better solution, plug-ins work. From the post in the link above, I created a simple BSV and plug-in. The plug-in makes a REST call to validate a VAT and is executed from the BO rules and dynamically updates the form.
Bunch of questions:

If you don’t speak Java, how long would you be looking at to figure it out?
Is it something that if you had a template or an existing example you could figure out?
Probably more but can’t think at the moment. Too early.
BobK
Posts: 545
Joined: Thu Jan 31, 2008 2:14 pm
Location: Cincinnati, Ohio, USA

Re: REST as a validation mechanism

Post by BobK »

PointsWell wrote: If you don’t speak Java, how long would you be looking at to figure it out?
Is it something that if you had a template or an existing example you could figure out?
Probably more but can’t think at the moment. Too early.
What is your background? Do you know any other computer languages?

I have a degree in computer science, but taught myself java. Mostly from "the really big index" https://docs.oracle.com/javase/tutorial ... index.html
There are also many other java tutorials and other information on the web.

I can give you the plug-in I created. It may not be the best tool for learning java, but it does have all the java methods required by AwareIM.
Bob
idpSteve
Posts: 201
Joined: Thu Jul 27, 2017 6:13 am
Location: Johannesburg, South Africa
Contact:

Re: REST as a validation mechanism

Post by idpSteve »

Hi Bob.

If you wouldn't mind I'd love to see your plugin too.
PointsWell
Posts: 1460
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

Re: REST as a validation mechanism

Post by PointsWell »

BobK wrote:
PointsWell wrote: If you don’t speak Java, how long would you be looking at to figure it out?
Is it something that if you had a template or an existing example you could figure out?
Probably more but can’t think at the moment. Too early.
What is your background? Do you know any other computer languages?

I have a degree in computer science, but taught myself java. Mostly from "the really big index" https://docs.oracle.com/javase/tutorial ... index.html
There are also many other java tutorials and other information on the web.

I can give you the plug-in I created. It may not be the best tool for learning java, but it does have all the java methods required by AwareIM.
I can read code and understand generally what is going on. I’ve managed to write a bit of JS in Wavemaker. It would be great if you could share an example as it would give me a gauge of whether I know what’s going on or whether it’s over my head.

Don’t tell my alma mater - I technically have a degree in IT but I tend to keep it a secret.
BobK
Posts: 545
Joined: Thu Jan 31, 2008 2:14 pm
Location: Cincinnati, Ohio, USA

Re: REST as a validation mechanism

Post by BobK »

Attached is my sample plug-in.
Read the included readme.txt file
Attachments
ValidateVAT.zip
(41.72 KiB) Downloaded 774 times
Bob
PointsWell
Posts: 1460
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

Re: REST as a validation mechanism

Post by PointsWell »

BobK wrote:Attached is my sample plug-in.
Read the included readme.txt file
Thanks Bob.

What you've sent me is straightforward and I can figure out what is going on here (i.e. I think I can crib it to use other needs)

So using the website's example this returns:

Code: Select all

=====================
{"valid":true,"database":"ok","format_valid":true,"query":"LU26375245","country_code":"LU","vat_number":"26375245","company_name":"AMAZON EUROPE CORE S.A R.L.","company_address":"5, RUE PLAETIS\nL-2338  LUXEMBOURG"}
=========================
Presumably to then consume the string output it is 'just' a matter of parsing out everything from that string? Or is there an easier way to use the JSON?
BobK
Posts: 545
Joined: Thu Jan 31, 2008 2:14 pm
Location: Cincinnati, Ohio, USA

Re: REST as a validation mechanism

Post by BobK »

Glad I could help.
PointsWell wrote:

Code: Select all

=====================
{"valid":true,"database":"ok","format_valid":true,"query":"LU26375245","country_code":"LU","vat_number":"26375245","company_name":"AMAZON EUROPE CORE S.A R.L.","company_address":"5, RUE PLAETIS\nL-2338  LUXEMBOURG"}
=========================
Presumably to then consume the string output it is 'just' a matter of parsing out everything from that string? Or is there an easier way to use the JSON?
Correct, you will have to parse the string returned from the service and I would do as much parsing in the plug-in as possible. There are several java libraries for parsing JSON that should help, search the web for: java json. Since functions can only return 1 field, you will have to do some parsing inside AwareIM.

This is how I would do it if you wanted to populate fields with company_name, company_address and country_code:
Change the plug-in to return a String instead of a Boolean then parse the string returned from the service to create a string like the following
"AMAZON EUROPE CORE S.A R.L. # 5, RUE PLAETIS\nL-2338 LUXEMBOURG # LU"
and return that to AwareIM

In AwareIM:
Change the call to the plug-in to
VAT.Temp=ValidateVAT(SystemSettings.AccessKey,VAT.VAT)
add the following rules and attributes to the VAT BO
VAT.Company=REPLACE_PATTERN(VAT.Temp, '#.*$' '') // removes the first # and everything after it
VAT.Country=REPLACE_PATTERN(VAT.Temp, '^.*#' '') // removes everything from the beginning to the last #
VAT.Address=REPLACE_PATTERN(REPLACE_PATTERN(VAT.Temp, '^.*?#' ''), '#.*$', '') // removes everything but the address in the middle

NOTE: I have not tested the regular expressions for the REPLACE_PATTERN, so they may need some tweaking.
Bob
Post Reply