Create Custom Java Service

I am trying to create a generic Java Service that would takes a document as input and the output would be a propertySet. In my Java Service what would the code look like to take any document as input and loop over its elements to get the field and field value so I can create a propertyset?

If you are looking for the code for pipeline read/write then one of the easiest way is to create a dummy flow service with your required input/output structures and use
Tools–> Generate Code to Implement this service Selecting Java as the lang, it will generate the required lines of code to read/write the input structures and will copy the code to the memory that u can then paste it to ur java service.

I am looking for the code that will loop over the elements in a document to get the field and field value so I can create a propertyset.

Here is the solution to my problem if anyone is interested. The service takes a document as the input and the output is a propertySet.

//Convert document to PropertySet
// pipeline
IDataCursor pipelineCursor = pipeline.getCursor();
// Get document
Object document = IDataUtil.getIData( pipelineCursor, “document” );
IData doc = (IData)document;
IDataCursor docCursor = doc.getCursor();
String element = new String();
String value = new String();

Properties properties = new Properties();
docCursor.first();
while(docCursor.next()) // get name value pair for each element in the record
{
element = docCursor.getKey();
value = IDataUtil.getString(docCursor,element);
properties.setProperty(element, value);
}

docCursor.destroy();

pipelineCursor.destroy();
// pipeline
IDataCursor pipelineCursor_1 = pipeline.getCursor();
Object propertySet = new Object();
IDataUtil.put( pipelineCursor_1, “propertySet”, properties );
pipelineCursor_1.destroy();

2 Likes