Five Stars

logging Multiple Error Messages from within a tJava component.

Here is the situation.

I have a main job with 8 sub-jobs, each treating different types of files.

Each sub job does pretty well the same type of things, read an XML file, loads it into a database and creates a flat file from the database.

Some of those a Multi-Schema (parent-child) up to 4 levels.

All that works fine.

What I need now is to create a series of "business" validation rules and when a rule is triggered write an message.

There are about 100 various rules.

They are like:

If the sum of the gross weight at the line level is not the same at the one on the invoice reject the transaction and write error message.

If field A is empty but field B has a valid value then write the value of field B into field A.

etc...

 

The only way I can think of doing this is inside a big tJava.

The issue is how do I write the error messages as I go through the logic without getting out of the tJava component. Technically any number of business rules can be triggered.

I was thinking about a tBuffer, long string, hash array but how to I loop through any of them at the end to write to the DB?

 

Is there a best practice or simply good advise?

1 ACCEPTED SOLUTION

Accepted Solutions
Five Stars

Re: logging Multiple Error Messages from within a tJava component.

Ok - I found the answer and since no one answered then maybe no one knows so here it is;

 

I went into the code and examined how a tWarn component worked.

Copied the essential code and removed all compilation errors and code that did not change the outcome and boiled it down to these two lines!!

  

talendLogs_LOGS.addMessage("tJavaRow", "tJavaRow_1", 4, "Filename prefix is unknown  "+ context.currentXMLFile, 42);
talendLogs_LOGSProcess(globalMap);

 

 

Those who are familiar with the error log format will recognize the various parts and can easily adapt.

Hope this helps someone.

 

 

1 REPLY
Five Stars

Re: logging Multiple Error Messages from within a tJava component.

Ok - I found the answer and since no one answered then maybe no one knows so here it is;

 

I went into the code and examined how a tWarn component worked.

Copied the essential code and removed all compilation errors and code that did not change the outcome and boiled it down to these two lines!!

  

talendLogs_LOGS.addMessage("tJavaRow", "tJavaRow_1", 4, "Filename prefix is unknown  "+ context.currentXMLFile, 42);
talendLogs_LOGSProcess(globalMap);

 

 

Those who are familiar with the error log format will recognize the various parts and can easily adapt.

Hope this helps someone.