Hi,
I'm doing some sample code to access a LiveReport from Java-based Web Services. Mainly doing this so I can document the methodology for a Techn Spec I'm writing (one of those dealies where I have to write the code in order to tell the dev team how to write the code).
Anyway, I constructed a small example to call a WebReport with a single argument, with these two methods:
/**
* This method added as sample code. It currently does nothing useful, but is included
* to help IPDFM development team access and parse results of a LiveReport.
*/
public void runLiveReport(long uid, long dataid) throws Exception{
// 1. Create a DataValue object of type IntegerValue.
// if input were a string, input would be a StringValue.
// and if input were a Date, it would be a DateValue
IntegerValue input = new IntegerValue();
// 2. set the value of the input
input.getValues().add(new Long(dataid));
// 3. (optional) set the UID of the input (only if there are more than one inputs)
input.setKey("inputLabel1");
// 4. Create a List object for the inputs
List<DataValue> inputs = new Vector<DataValue>();
inputs.add(input);
// 5. Run the report.
ReportResult result = getDocmanClient().runReport(uid, inputs );
// 6. Results into a List of Row objects
List<RowValue> rows = result.getContents();
for (RowValue row : rows) {
List<DataValue> data = row.getValues();
for (DataValue d : data) {
Object objVal = getDataValue(d);
System.out.println(d.getKey() + " = " + objVal.toString());
}
}
}
private Object getDataValue(DataValue d) {
Object retVal = null;
if (d instanceof IntegerValue) {
IntegerValue ival = (IntegerValue)d;
if (ival.getValues().size() > 0)
retVal = ival.getValues().get(0);
} else if (d instanceof DateValue) {
DateValue dateVal = (DateValue)d;
if (dateVal.getValues().size() > 0)
retVal = dateVal.getValues().get(0);
} else if (d instanceof StringValue) {
StringValue strVal = (StringValue)d;
if (strVal.getValues().size() > 0)
retVal = strVal.getValues().get(0);
}
if (retVal == null)
retVal = new String();
return retVal;
}
The above example is crude but it does work. And I built it with CWS for CS 16.0.4. My questions to OpenText:
1) When passing arguments, the DataValues in the List<DataValue> that is passed as an input to the report, what is the requirement to setting the key of the data value? With one arg, there seems to be no requirement. If you have multiples, do you need to concern yourself with the correct labels (ie inputLabel1, inputlabel2, etc) or does it take the inputs in the order in which they are loaded into your List object?
2) Is there a nice method to get the headers of your report? As it stands, it appears that you only can get the header from the key of the returned data values, i.e. while you're iterating through the rows. I'm looking at a way of encapsulating the report results to return them in something that includes the row iterator, and the list of headers, and return them in a way that you don't have to iterate through your results to get the headers, then iterate again (takes too long).
3) The IntegerValue, StringValue, DateValue, etc classes all encapsulate their data in a List<DataValue> object. If the column has a null value, this list has zero elements. I'm currently assuming it will only ever have 0 or 1 entries. Is that accurate, or is there a possibility of a report results where a row contains multiple values for a column and row? I can't see that happening, but I saw in the example that Appu kindly provided that he allowed for that possibility.
i.e. if I had IntegerValue iValue;
would the value of iValue.getValues().size() ever exceed 1?
Thanks
-Hugh