Java service to check Null values in a document List

we have a requirement, where i need to check a document which contains documentLists as well in side and almost 50 fields,if any value is missing,i need to write a message with missing field to a Flatfile.

if 4 or 5 fields, we can check using branch step…but out 0f 50 fields if some 20 fields are missing, then i need to collect all the 20 fields and write a message to flatfile with all the details…

can any one suggest me how can i do this…??

You may want to consider making a single service that returns “true” if its input is null. Then you should have a MAP step in a second service that takes each input and using the previous service as a transformer, gets the value and populates a String List. Then you can loop over the String List and if the number of “true” values is over your threshold, you can take action. Good day.

Yemi Bedu

Thanks!! if you have some sample…can you share it…

Hi Prashanth,
I have coded the below and tested it, it should give you all the fields that are either null or empty. You have to import java.util.ArrayList.

[highlight=java]IDataCursor pipelineCursor = pipeline.getCursor();
IData inDoc = IDataUtil.getIData(pipelineCursor,“inDoc”);
IDataCursor inDocCursor = inDoc.getCursor();
IData inList = IDataUtil.getIDataArray(inDocCursor,“inList”);
IData outList = new IData[inList.length];
ArrayList errorArrList = new ArrayList();

for (int i=0; i<inList.length; i++){
IDataCursor inListCursor = inList[i].getCursor();
outList[i] = IDataFactory.create();
IDataCursor outListCursor = outList[i].getCursor();
String key = inListCursor.getKey();
String value = (String) inListCursor.getValue();
if(value == null || value.trim().equals(“”)){
String errorStrList = new String [errorArrList.size()];
IDataUtil.put(outListCursor, “errorList”, errorStrList);
if(outList != null){
IDataUtil.put(pipelineCursor, “outList”, outList);

Thanks alot!!

can you export that service and send…its not working…i tried.

Hi Prasanth,
I have attached the package here. It’s created using version 7.1.2.

Thanks (6.81 KB)

By “if any value is missing” you mean that the document contains all the values even if there are null ? or that missing values are not present in the document ?

In the second way you can’t just loop over the document because the values are not present…

An other approach is to define constraints in the properties of the values in your document: “required → true and allow null → false” where you want to check for missing values.
Then use the “WmPublic/pub.schema:validate” service to validate your doc with the “conformsTo” option with the name of your doc.
You can get the missing values with the “error” document created.