eu.planets_project.pp.plato.services.crib_integration.tu_client.MigrationResult migrationResult = migrationBroker.convert(representationObject, urlArr);
/*
* collect migration results
*/
MigrationResult result = new MigrationResult();
lastResult = result;
/*
* if the migration was successful is indicated by two flags:
* "process::availability" and "process::stability"
* - which are float values (!)
*/
Criterion[] criteria = migrationResult.getReport().getCriteria();
double availability = Double.parseDouble(getCriterion(criteria, "process::availability"));
double stability = Double.parseDouble(getCriterion(criteria, "process::stability"));
result.setSuccessful((availability > 0.0) && (stability > 0.0));
if (!result.isSuccessful()) {
result.setReport(String.format("Service '%s' failed to migrate sample '%s'.", action.getShortname() , sampleObject.getFullname()));//+ getCriterion(criteria, "message::reason"));
log.debug(String.format("Service '%s' failed to migrate sample '%s': %s", action.getShortname(), sampleObject.getFullname(), getCriterion(criteria, "message::reason")));
return true;
} else {
result.setReport(String.format("Migrated object '%s' to format '%s'. Completed at %s.",
sampleObject.getFullname(), action.getTargetFormat(), migrationResult.getReport().getDatetime()));
}
result.getMigratedObject().getData().setData(migrationResult.getRepresentation().getFiles()[0].getBitstream().clone());
/*
* message::filename contains the name of the source-file, NOT the migrated
*/
String filename = migrationResult.getRepresentation().getFiles()[0].getFilename();
/*
* if filename is missing, use name from the source object (without extension)
*/
if ((filename == null) || "".equals(filename)) {
filename = sampleObject.getFullname();
int bodyEnd = filename.lastIndexOf(".");
if (bodyEnd >= 0)
filename = filename.substring(0, bodyEnd);
}
result.getMigratedObject().setFullname(filename);
int bodyEnd;
/*
* CRiB does not provide forther information about the format of the migrated object,
* therfore the file extension of the migrated object is derived from the action's target formats
*/
bodyEnd = filename.lastIndexOf(".");
if ((bodyEnd < 0) &&
((result.getTargetFormat().getDefaultExtension() == null) ||
"".equals(result.getTargetFormat().getDefaultExtension()))) {
FormatInfo targetFormat = new FormatInfo();
setFormatFromCRiBID(action.getTargetFormat(), targetFormat);
result.setTargetFormat(targetFormat);
filename = filename + "." + result.getTargetFormat().getDefaultExtension();
result.getMigratedObject().setFullname(filename);
result.getMigratedObject().getFormatInfo().assignValues(targetFormat);
}
lastResult = result;
return true;
} catch (NumberFormatException e) {
throw new PlatoServiceException("Migration failed, CRiB returned an invalid result.", e);