//group related wfResult items per input digital objects
Map<URI,List<WorkflowResultItem>> structuredResults = this.getAllWFResultItemsPerInputDigo(weeWFResult);
//FIXME AL: We still need to crate empty executionRecords for the items that weren't processed by the wee (e.g. expSetup.getInputData and compare to the log)
for(URI inputDigoURI : structuredResults.keySet()){
int actionCounter = 0;
ExecutionRecordImpl execRecord = new ExecutionRecordImpl(batchRecord);
//the input Digo for all this information is about
// FIXME This appears to be the resolved URI, not the proper Planets DR URI:
execRecord.setDigitalObjectReferenceCopy(inputDigoURI+"");
Properties p = new Properties();
//iterate over the results and document the migration action - all other information goes into properties.
for(WorkflowResultItem wfResultItem : structuredResults.get(inputDigoURI)){
//1. check if this record was about the migration action
String action = wfResultItem.getSActionIdentifier();
if(action.startsWith(WorkflowResultItem.SERVICE_ACTION_MIGRATION)){
URI outputDigoRef = wfResultItem.getOutputDigitalObjectRef();
if(outputDigoRef!=null){
//DigitalObject outputDigo = dataRegistry.retrieve(outputDigoRef);
//1.a download the ResultDigo into the TB and store it's reference - if it's the final migration producing the output object
if(action.equals(WorkflowResultItem.SERVICE_ACTION_FINAL_MIGRATION)){
//documenting the final output object
URI tbUri = execRecord.setDigitalObjectResult(outputDigoRef, exp);
//FIXME: currently not possible to mix DIGO and PROPERTY result:
p.put(ExecutionRecordImpl.RESULT_PROPERTY_URI, tbUri.toString());
}
else{
//1.b documenting the interim results in a multi-migration-workflow
//DataHandler dh = new DataHandlerImpl();
//URI tbUri = dh.storeDigitalObject(outputDigo, exp);
p.put(ExecutionRecordImpl.RESULT_PROPERTY_INTERIM_RESULT_URI+"["+actionCounter+"]", outputDigoRef.toString());
}
Calendar start = new GregorianCalendar();
start.setTimeInMillis(wfResultItem.getStartTime());
execRecord.setStartDate(start);
Calendar end = new GregorianCalendar();
end.setTimeInMillis(wfResultItem.getEndTime());
execRecord.setEndDate(end);
}
}
//1b. every service action gets persisted as a stage record
ExecutionStageRecordImpl stageRecord = fillInExecutionStageRecord(wfResultItem,actionCounter,execRecord,action,exp.getEntityID());
execRecord.getStages().add(stageRecord);
//2. or about some general reporting information
if(action.startsWith(WorkflowResultItem.GENERAL_WORKFLOW_ACTION)){
execRecord.setReportLog(this.parseReportLog(wfResultItem));
}
//3. document all other metadata for actions: identification, etc. as properties over all actions
try{
this.updateProperties(actionCounter, p, wfResultItem);
}catch(Exception e){
log.error("processing WEEBatchExperiment: Problems crating execution record properties for a workflowResultItem "+e);
}
actionCounter++;
}
try {
execRecord.setPropertiesListResult(p);
} catch (IOException e) {
log.debug("processing WEEBatchExperiment: Problem adding properties to executionRecord: "+e);
}
//got all information - now add the record for this inputDigo