*/
@SuppressWarnings("finally")
public WorkflowResult execute(DigitalObject dgoA) {
// document all general actions for this digital object
WorkflowResultItem wfResultItem = new WorkflowResultItem(
dgoA.getPermanentUri(),
WorkflowResultItem.GENERAL_WORKFLOW_ACTION,
System.currentTimeMillis(),
this.getWorkflowReportingLogger());
this.addWFResultItem(wfResultItem);
wfResultItem.addLogInfo("working on workflow template: "+this.getClass().getName());
wfResultItem.addLogInfo("workflow-instance id: "+this.getWorklowInstanceID());
// start executing on digital ObjectA
this.processingDigo = dgoA;
try {
// TODO Characterisation service
// TODO Validation service
// Identification service for data enrichment (e.g. mime type of output object)
String[] types = runIdentification(dgoA);
wfResultItem.addLogInfo("Completed identification. result" + Arrays.asList(types).toString());
// Extract metadata - will otherwise get lost between steps!
String metadata = "";
List<Metadata> mList = dgoA.getMetadata();
if ((mList != null) && (mList.size() > 0)) {
metadata = mList.get(0).getContent();
}
if (metadata == null) {
wfResultItem.addLogInfo("No metadata contained in DigitalObject!");
} else {
wfResultItem.addLogInfo("Extracted metadata: " + metadata);
}
// Migration service
wfResultItem.addLogInfo("STEP 2: Starting migration");
URI dgoBRef = runMigration(migrate, dgoA.getPermanentUri(), true);
wfResultItem.addLogInfo("Completed migration. URI: " + dgoBRef);
// Add migration resulting text to metadata
if (dgoBRef != null) {
try {
DataRegistry dataRegistry = DataRegistryFactory.getDataRegistry();
URI baseUri = new PDURI(dgoBRef.normalize()).formDataRegistryRootURI();
wfResultItem.addLogInfo("base URI " + baseUri);
DigitalObject obj = dataRegistry.getDigitalObjectManager(baseUri).retrieve(dgoBRef);
wfResultItem.addLogInfo("obj: " + obj.toString());
InputStream contentStream = obj.getContent().getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(contentStream));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = br.readLine()) != null) {
sb.append(line + "\n");
}
br.close();
String migrationResult = sb.toString();
wfResultItem.addLogInfo("Migrated file contents: " + migrationResult);
Metadata migrationMetadata = new Metadata(dgoA.getPermanentUri(), MIGRATION_METADATA, migrationResult);
dgoA = addMetadata(dgoA, migrationMetadata);
} catch (Exception e) {
wfResultItem.addLogInfo("migration error: " + e.getMessage());
}
}
// Insert in JCR repository
wfResultItem.addLogInfo("STEP 3: Insert in JCR repository. initial digital object: " + dgoA.toString());
// Manage the Digital Object Data Registry:
wfResultItem.addLogInfo("Initialize JCR repository instance.");
JcrDigitalObjectManagerImpl dodm =
(JcrDigitalObjectManagerImpl) JcrDigitalObjectManagerImpl.getInstance();
DigitalObject dgoB = dodm.store(PERMANENT_URI_PATH, dgoA, true);
wfResultItem.addLogInfo("Completed storing in JCR repository: " + dgoB.toString());
// Enrich digital object with metadata from characterization service
Metadata characterisationMetadata = new Metadata(dgoB.getPermanentUri(), CHARACTERISATION_METADATA, "testdata");
dgoB = addMetadata(dgoB, characterisationMetadata);
// Update digital object in JCR repository
wfResultItem.addLogInfo("STEP 4: Update digital object in JCR repository. initial digital object: " +
dgoB.toString());
dgoB = dodm.updateDigitalObject(dgoB, false);
wfResultItem.addLogInfo("Completed update in JCR repository. result digital object: " + dgoB.toString());
// TODO Send back to the initial repository
wfResultItem.addLogInfo("STEP 5: Send enriched digital object back to the initial repository ");
wfResultItem.addLogInfo("Completed sending of enriched digital object to the initial repository.");
wfResultItem.setEndTime(System.currentTimeMillis());
wfResultItem
.addLogInfo("Successfully completed workflow for digitalObject with permanent uri:"
+ processingDigo);
wfResultItem.setEndTime(System.currentTimeMillis());
} catch (Exception e) {
String err = "workflow execution error for digitalObject with permanent uri: " + processingDigo;
wfResultItem.addLogInfo(err + " " + e);
wfResultItem.setEndTime(System.currentTimeMillis());
}
return this.getWFResult();
}