Skip to main content
16-Pearl
March 14, 2022
Question

BLOB de-serialize and extract workflow variable - improve performance

  • March 14, 2022
  • 1 reply
  • 1062 views

Hi,

Can anyone suggest how to improve the performance of this Java Method?

I'm using it in query builder to get the value of workflow variables from WorkItem.blob$context.

Originally I used two separate methods which were nested to first deserialize then extract the variable with another custom method.

After I combined the two methods into one as suggested here the report is faster, but I feel it could still be improved further.

 

deserialize2.png

 

 

package ext.tools;

import wt.util.WTException;
import java.io.ObjectInputStream;
import java.io.IOException;
import wt.pom.DatastoreException;
import java.io.InputStream;
import java.sql.Blob;
import wt.method.RemoteMethodServer;
import wt.pds.PDSEncoder;

public class BLOBConversionHelper {
 //pass in a BLOB (Object o) and Workflow Variable name (String s)
 //returns the value of the workflow variable (int)
 public static int getValueFromBLOB(final Object o, final String s) throws WTException {
 // deserizlize method similar to wt.pds.ConversionHelper
 Object object = null;
 if (RemoteMethodServer.ServerFlag) {
 ObjectInputStream objectInputStream = null;
 PDSEncoder encoder = null;
 try {
 encoder = PDSEncoder.getEncoder();
 if (o instanceof String) {
 objectInputStream = encoder.setInput((String)o);
 }
 else {
 InputStream binaryStream = null;
 if (o instanceof Blob) {
 binaryStream = ((Blob)o).getBinaryStream();
 }
 else if (o instanceof InputStream) {
 binaryStream = (InputStream)o;
 }
 if (binaryStream != null) {
 objectInputStream = encoder.setInput(binaryStream);
 }
 }
 if (objectInputStream != null) {
 object = objectInputStream.readObject();
 }
 }
 catch (Exception ex) {
 throw new DatastoreException(ex);
 }
 finally {
 if (objectInputStream != null) {
 try {
 objectInputStream.close();
 }
 catch (IOException ex2) {}
 }
 PDSEncoder.freeEncoder(encoder);
 }
 }

		//find the comma after the variable name and the next comma after
		//the split the string
		//convert the string to an int
		int val;
		int indexOfs = object.toString().indexOf(s);
		int indexOfcomma = object.toString().indexOf(",", indexOfs);
		int indexOfEndcomma = object.toString().indexOf(",", (indexOfcomma + 1));
		String checkNull = object.toString().substring((indexOfcomma + 2),(indexOfcomma + 6));
			
		if (checkNull.equals("null")){
			val = 0;
		} else {		
			try {
				val = Integer.valueOf(object.toString().substring((indexOfcomma + 2),indexOfEndcomma));
			} catch (NumberFormatException ex) {
				ex.printStackTrace();
				val = 99999;
			}
		}
			
		return val;
		
 }
	
}

 

 

Example of the deserialzed BLOB before extracting the variable:

The code searches the de-serialised blob for a string like the variable name, then the next commas, then gets the substring using the position of the comma either side either side of the value.

deserialize3.png

Basically I think what I'm asking is how do I address these [(),,]

1 reply

18-Opal
March 22, 2022

Not sure exactly for format you want the WorkItem attributes display to look like but here goes.

 

The image below show a report with a column for each attribute and a third column that has all attributes from the WorkItem in a single cell.

Take your pick.  Both styles use Java Method and only about 10 lines of code. Report runs pretty quickly.

d_graham_1-1647982009245.png