public WorkflowResult execute( DigitalObject dob ) {
// Invoke the service, timing it along the way:
boolean success = true;
String exceptionReport = "";
IdentifyResult identify = null;
long msBefore = 0, msAfter = 0;
msBefore = System.currentTimeMillis();
try {
identify = identifier.identify(dob,null);
} catch( Exception e ) {
success = false;
exceptionReport = "<p>Service Invocation Failed!<br/>" + e + "</p>";
}
msAfter = System.currentTimeMillis();
// Now prepare the result:
WorkflowResult wr = new WorkflowResult();
// Record this one-stage experiment:
ExecutionStageRecordImpl idStage = new ExecutionStageRecordImpl(null, STAGE_IDENTIFY);
wr.getStages().add( idStage );
// Record the endpoint of the service used for this stage. FIXME Can this be done more automatically, from above?
idStage.setEndpoint(identifierEndpoint);
List<MeasurementImpl> recs = idStage.getMeasurements();
recs.add(new MeasurementImpl(TecRegMockup.PROP_SERVICE_TIME, ""+((msAfter-msBefore)/1000.0) ));
// Now record
try {
if( success && identify.getTypes() != null && identify.getTypes().size() > 0 ) {
recs.add( new MeasurementImpl( TecRegMockup.PROP_SERVICE_EXECUTION_SUCEEDED, "true"));
collectIdentifyResults(recs, identify, dob);
wr.logReport(identify.getReport());
return wr;
}
} catch( Exception e ) {
exceptionReport += "<p>Failed with exception: "+e+"</p>";
}
// Build in a 'service failed' property.
recs.add( new MeasurementImpl( TecRegMockup.PROP_SERVICE_EXECUTION_SUCEEDED, "false"));
// Create a ServiceReport from the exception.
// TODO can we distinguish tool and install error here?
ServiceReport sr = new ServiceReport(Type.ERROR, Status.TOOL_ERROR,
"No info");
if (identify != null && identify.getReport() != null) {
String info = identify.getReport().toString();
sr = new ServiceReport(Type.ERROR, Status.TOOL_ERROR, info);
}
wr.logReport(sr);
return wr;