Migrate m = (Migrate) service.getPort(Migrate.class);
// create digital object that contains our sample object
DigitalObject dob = new DigitalObject.Builder( Content.byValue(sampleObject.getData().getData()) ).title("data").build();
FormatRegistry formatRegistry = FormatRegistryFactory.getFormatRegistry();
// create Planets URI from extension
URI sourceFormat = formatRegistry.createExtensionUri(sampleObject.getFormatInfo().getDefaultExtension());
URI targetFormat;
try {
targetFormat = new URI(action.getTargetFormat());
} catch (URISyntaxException e) {
throw new PlatoServiceException("Error in target format.", e);
}
List<Parameter> serviceParams = getParameters(action.getParamByName("settings"));
if (serviceParams.size() <= 0) {
serviceParams = null;
}
// perform migration
MigrateResult result = m.migrate(dob, sourceFormat, targetFormat, serviceParams);
MigrationResult migrationResult = new MigrationResult();
migrationResult.setSuccessful((result != null) && (result.getDigitalObject() != null));
if (migrationResult.isSuccessful()) {
migrationResult.setReport(String.format("Service %s successfully migrated object.", wsdlLocation));
} else {
migrationResult.setReport(String.format("Service %s failed migrating object. " + ((result==null)? "" : result.getReport()), wsdlLocation));
lastResult = migrationResult;
return true;
}
InputStream in = result.getDigitalObject().getContent().getInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] b = new byte[1024];
try {
while ((in.read(b)) != -1) {
out.write(b);
}
} catch (IOException e) {
throw new PlatoServiceException("Unable to read result data from service response.", e);
}
migrationResult.getMigratedObject().getData().setData(out.toByteArray());
String fullName = sampleObject.getFullname();
String ext;
try {
ext = formatRegistry.getFirstExtension(new URI(action.getTargetFormat()));
} catch (URISyntaxException e) {
ext = "";
}
// if we find an extension, cut if off ...