@Test public void testMigrateUsingTempFiles() throws Exception { MigrateResult migrationResult = this.genericWrapper.migrate( getDigitalTestObject(), this.sourceFormatURI, this.destinationFormatURI, this.testParameters); Assert.assertEquals(ServiceReport.Status.SUCCESS, migrationResult .getReport().getStatus()); }
public MigrateResult migrate(DigitalObject sourceObject, URI sourceFormat, URI destinationFormat, List<Parameter> toolParameters) throws MigrationException, IOException { final MigrationPath migrationPath = migrationPaths .getMigrationPath(sourceFormat, destinationFormat); log.info("Found migrationpath from "+sourceFormat+" to "+destinationFormat); if (toolParameters == null){ log.info("Called with null parameters"); toolParameters = new ArrayList<Parameter>(); } log.info("Making workfolder for migration"); File workfolder = handleTempfiles(migrationPath); if (migrationPath.useTempSourceFile()){ log.info("Migrationpath uses temp source file, reading digital object into file"); handleTempSourceFile(migrationPath,sourceObject, workfolder); } if (migrationPath.useTempDestinationFile()){ log.info("Migrationpath uses temp destination path"); handleTempDestinationFile(migrationPath,workfolder); } List<String> command = migrationPath.getCommandLine(toolParameters); log.info("Command line found: "); log.info(command.toString()); InputStream processStandardInput = null; if (!migrationPath.useTempSourceFile()) { processStandardInput = sourceObject.getContent().getInputStream(); } else { } final ProcessRunner toolProcessRunner = new ProcessRunner(); ServiceReport serviceReport = executeToolProcess(toolProcessRunner, command, processStandardInput); if (serviceReport.getType() == Type.ERROR) { String message = "Failed migrating object with title '" + sourceObject.getTitle() + "' from format URI: " + sourceFormat + " to " + destinationFormat + " Standard output: " + toolProcessRunner.getProcessOutputAsString() + "\nStandard error output: " + toolProcessRunner.getProcessErrorAsString(); serviceReport = new ServiceReport(Type.ERROR, Status.TOOL_ERROR, message); return new MigrateResult(null, serviceReport); } if (migrationPath.useTempSourceFile()){ migrationPath.getTempSourceFile().getFile().delete(); } for (TempFile tempFile : migrationPath.getTempFileDeclarations()) { tempFile.getFile().delete(); } DigitalObject.Builder builder; if (migrationPath.useTempDestinationFile()){ File outputfile = migrationPath.getTempOutputFile().getFile(); if (returnByReference){ builder = new DigitalObject.Builder(Content.byReference(outputfile)); } else { builder = new DigitalObject.Builder(Content.byValue(outputfile)); outputfile.delete(); } String message = "Successfully migrated object with title '" + sourceObject.getTitle() + "' from format URI: " + sourceFormat + " to " + destinationFormat + " Standard output: " + toolProcessRunner.getProcessOutputAsString() + "\nStandard error output: " + toolProcessRunner.getProcessErrorAsString(); serviceReport = new ServiceReport(Type.INFO, Status.SUCCESS, message); } else { if (returnByReference){ builder = new DigitalObject.Builder(Content.byReference(toolProcessRunner.getProcessOutput())); } else{ builder = new DigitalObject.Builder(Content.byValue(toolProcessRunner.getProcessOutput())); } String message = "Successfully migrated object with title '" + sourceObject.getTitle() + "' from format URI: " + sourceFormat + " to " + destinationFormat + " Standard error output: " + toolProcessRunner.getProcessErrorAsString(); serviceReport = new ServiceReport(Type.INFO, Status.SUCCESS, message); } DigitalObject destinationObject = builder .format(destinationFormat) .build(); return new MigrateResult(destinationObject, serviceReport); }
GenericMigrationWrapper { public MigrateResult migrate(DigitalObject sourceObject, URI sourceFormat, URI destinationFormat, List<Parameter> toolParameters) throws MigrationException, IOException { final MigrationPath migrationPath = migrationPaths .getMigrationPath(sourceFormat, destinationFormat); log.info("Found migrationpath from "+sourceFormat+" to "+destinationFormat); if (toolParameters == null){ log.info("Called with null parameters"); toolParameters = new ArrayList<Parameter>(); } log.info("Making workfolder for migration"); File workfolder = handleTempfiles(migrationPath); if (migrationPath.useTempSourceFile()){ log.info("Migrationpath uses temp source file, reading digital object into file"); handleTempSourceFile(migrationPath,sourceObject, workfolder); } if (migrationPath.useTempDestinationFile()){ log.info("Migrationpath uses temp destination path"); handleTempDestinationFile(migrationPath,workfolder); } List<String> command = migrationPath.getCommandLine(toolParameters); log.info("Command line found: "); log.info(command.toString()); InputStream processStandardInput = null; if (!migrationPath.useTempSourceFile()) { processStandardInput = sourceObject.getContent().getInputStream(); } else { } final ProcessRunner toolProcessRunner = new ProcessRunner(); ServiceReport serviceReport = executeToolProcess(toolProcessRunner, command, processStandardInput); if (serviceReport.getType() == Type.ERROR) { String message = "Failed migrating object with title '" + sourceObject.getTitle() + "' from format URI: " + sourceFormat + " to " + destinationFormat + " Standard output: " + toolProcessRunner.getProcessOutputAsString() + "\nStandard error output: " + toolProcessRunner.getProcessErrorAsString(); serviceReport = new ServiceReport(Type.ERROR, Status.TOOL_ERROR, message); return new MigrateResult(null, serviceReport); } if (migrationPath.useTempSourceFile()){ migrationPath.getTempSourceFile().getFile().delete(); } for (TempFile tempFile : migrationPath.getTempFileDeclarations()) { tempFile.getFile().delete(); } DigitalObject.Builder builder; if (migrationPath.useTempDestinationFile()){ File outputfile = migrationPath.getTempOutputFile().getFile(); if (returnByReference){ builder = new DigitalObject.Builder(Content.byReference(outputfile)); } else { builder = new DigitalObject.Builder(Content.byValue(outputfile)); outputfile.delete(); } String message = "Successfully migrated object with title '" + sourceObject.getTitle() + "' from format URI: " + sourceFormat + " to " + destinationFormat + " Standard output: " + toolProcessRunner.getProcessOutputAsString() + "\nStandard error output: " + toolProcessRunner.getProcessErrorAsString(); serviceReport = new ServiceReport(Type.INFO, Status.SUCCESS, message); } else { if (returnByReference){ builder = new DigitalObject.Builder(Content.byReference(toolProcessRunner.getProcessOutput())); } else{ builder = new DigitalObject.Builder(Content.byValue(toolProcessRunner.getProcessOutput())); } String message = "Successfully migrated object with title '" + sourceObject.getTitle() + "' from format URI: " + sourceFormat + " to " + destinationFormat + " Standard error output: " + toolProcessRunner.getProcessErrorAsString(); serviceReport = new ServiceReport(Type.INFO, Status.SUCCESS, message); } DigitalObject destinationObject = builder .format(destinationFormat) .build(); return new MigrateResult(destinationObject, serviceReport); } }
GenericMigrationWrapper { public MigrateResult migrate(DigitalObject sourceObject, URI sourceFormat, URI destinationFormat, List<Parameter> toolParameters) throws MigrationException, IOException { final MigrationPath migrationPath = migrationPaths .getMigrationPath(sourceFormat, destinationFormat); log.info("Found migrationpath from "+sourceFormat+" to "+destinationFormat); if (toolParameters == null){ log.info("Called with null parameters"); toolParameters = new ArrayList<Parameter>(); } log.info("Making workfolder for migration"); File workfolder = handleTempfiles(migrationPath); if (migrationPath.useTempSourceFile()){ log.info("Migrationpath uses temp source file, reading digital object into file"); handleTempSourceFile(migrationPath,sourceObject, workfolder); } if (migrationPath.useTempDestinationFile()){ log.info("Migrationpath uses temp destination path"); handleTempDestinationFile(migrationPath,workfolder); } List<String> command = migrationPath.getCommandLine(toolParameters); log.info("Command line found: "); log.info(command.toString()); InputStream processStandardInput = null; if (!migrationPath.useTempSourceFile()) { processStandardInput = sourceObject.getContent().getInputStream(); } else { } final ProcessRunner toolProcessRunner = new ProcessRunner(); ServiceReport serviceReport = executeToolProcess(toolProcessRunner, command, processStandardInput); if (serviceReport.getType() == Type.ERROR) { String message = "Failed migrating object with title '" + sourceObject.getTitle() + "' from format URI: " + sourceFormat + " to " + destinationFormat + " Standard output: " + toolProcessRunner.getProcessOutputAsString() + "\nStandard error output: " + toolProcessRunner.getProcessErrorAsString(); serviceReport = new ServiceReport(Type.ERROR, Status.TOOL_ERROR, message); return new MigrateResult(null, serviceReport); } if (migrationPath.useTempSourceFile()){ migrationPath.getTempSourceFile().getFile().delete(); } for (TempFile tempFile : migrationPath.getTempFileDeclarations()) { tempFile.getFile().delete(); } DigitalObject.Builder builder; if (migrationPath.useTempDestinationFile()){ File outputfile = migrationPath.getTempOutputFile().getFile(); if (returnByReference){ builder = new DigitalObject.Builder(Content.byReference(outputfile)); } else { builder = new DigitalObject.Builder(Content.byValue(outputfile)); outputfile.delete(); } String message = "Successfully migrated object with title '" + sourceObject.getTitle() + "' from format URI: " + sourceFormat + " to " + destinationFormat + " Standard output: " + toolProcessRunner.getProcessOutputAsString() + "\nStandard error output: " + toolProcessRunner.getProcessErrorAsString(); serviceReport = new ServiceReport(Type.INFO, Status.SUCCESS, message); } else { if (returnByReference){ builder = new DigitalObject.Builder(Content.byReference(toolProcessRunner.getProcessOutput())); } else{ builder = new DigitalObject.Builder(Content.byValue(toolProcessRunner.getProcessOutput())); } String message = "Successfully migrated object with title '" + sourceObject.getTitle() + "' from format URI: " + sourceFormat + " to " + destinationFormat + " Standard error output: " + toolProcessRunner.getProcessErrorAsString(); serviceReport = new ServiceReport(Type.INFO, Status.SUCCESS, message); } DigitalObject destinationObject = builder .format(destinationFormat) .build(); return new MigrateResult(destinationObject, serviceReport); } GenericMigrationWrapper(Document configuration, String canonicalName); }
GenericMigrationWrapper { public MigrateResult migrate(DigitalObject sourceObject, URI sourceFormat, URI destinationFormat, List<Parameter> toolParameters) throws MigrationException, IOException { final MigrationPath migrationPath = migrationPaths .getMigrationPath(sourceFormat, destinationFormat); log.info("Found migrationpath from "+sourceFormat+" to "+destinationFormat); if (toolParameters == null){ log.info("Called with null parameters"); toolParameters = new ArrayList<Parameter>(); } log.info("Making workfolder for migration"); File workfolder = handleTempfiles(migrationPath); if (migrationPath.useTempSourceFile()){ log.info("Migrationpath uses temp source file, reading digital object into file"); handleTempSourceFile(migrationPath,sourceObject, workfolder); } if (migrationPath.useTempDestinationFile()){ log.info("Migrationpath uses temp destination path"); handleTempDestinationFile(migrationPath,workfolder); } List<String> command = migrationPath.getCommandLine(toolParameters); log.info("Command line found: "); log.info(command.toString()); InputStream processStandardInput = null; if (!migrationPath.useTempSourceFile()) { processStandardInput = sourceObject.getContent().getInputStream(); } else { } final ProcessRunner toolProcessRunner = new ProcessRunner(); ServiceReport serviceReport = executeToolProcess(toolProcessRunner, command, processStandardInput); if (serviceReport.getType() == Type.ERROR) { String message = "Failed migrating object with title '" + sourceObject.getTitle() + "' from format URI: " + sourceFormat + " to " + destinationFormat + " Standard output: " + toolProcessRunner.getProcessOutputAsString() + "\nStandard error output: " + toolProcessRunner.getProcessErrorAsString(); serviceReport = new ServiceReport(Type.ERROR, Status.TOOL_ERROR, message); return new MigrateResult(null, serviceReport); } if (migrationPath.useTempSourceFile()){ migrationPath.getTempSourceFile().getFile().delete(); } for (TempFile tempFile : migrationPath.getTempFileDeclarations()) { tempFile.getFile().delete(); } DigitalObject.Builder builder; if (migrationPath.useTempDestinationFile()){ File outputfile = migrationPath.getTempOutputFile().getFile(); if (returnByReference){ builder = new DigitalObject.Builder(Content.byReference(outputfile)); } else { builder = new DigitalObject.Builder(Content.byValue(outputfile)); outputfile.delete(); } String message = "Successfully migrated object with title '" + sourceObject.getTitle() + "' from format URI: " + sourceFormat + " to " + destinationFormat + " Standard output: " + toolProcessRunner.getProcessOutputAsString() + "\nStandard error output: " + toolProcessRunner.getProcessErrorAsString(); serviceReport = new ServiceReport(Type.INFO, Status.SUCCESS, message); } else { if (returnByReference){ builder = new DigitalObject.Builder(Content.byReference(toolProcessRunner.getProcessOutput())); } else{ builder = new DigitalObject.Builder(Content.byValue(toolProcessRunner.getProcessOutput())); } String message = "Successfully migrated object with title '" + sourceObject.getTitle() + "' from format URI: " + sourceFormat + " to " + destinationFormat + " Standard error output: " + toolProcessRunner.getProcessErrorAsString(); serviceReport = new ServiceReport(Type.INFO, Status.SUCCESS, message); } DigitalObject destinationObject = builder .format(destinationFormat) .build(); return new MigrateResult(destinationObject, serviceReport); } GenericMigrationWrapper(Document configuration, String canonicalName); MigrateResult migrate(DigitalObject sourceObject, URI sourceFormat,
                                 URI destinationFormat, List<Parameter> toolParameters); ServiceDescription describe(); }
GenericMigrationWrapper { public MigrateResult migrate(DigitalObject sourceObject, URI sourceFormat, URI destinationFormat, List<Parameter> toolParameters) throws MigrationException, IOException { final MigrationPath migrationPath = migrationPaths .getMigrationPath(sourceFormat, destinationFormat); log.info("Found migrationpath from "+sourceFormat+" to "+destinationFormat); if (toolParameters == null){ log.info("Called with null parameters"); toolParameters = new ArrayList<Parameter>(); } log.info("Making workfolder for migration"); File workfolder = handleTempfiles(migrationPath); if (migrationPath.useTempSourceFile()){ log.info("Migrationpath uses temp source file, reading digital object into file"); handleTempSourceFile(migrationPath,sourceObject, workfolder); } if (migrationPath.useTempDestinationFile()){ log.info("Migrationpath uses temp destination path"); handleTempDestinationFile(migrationPath,workfolder); } List<String> command = migrationPath.getCommandLine(toolParameters); log.info("Command line found: "); log.info(command.toString()); InputStream processStandardInput = null; if (!migrationPath.useTempSourceFile()) { processStandardInput = sourceObject.getContent().getInputStream(); } else { } final ProcessRunner toolProcessRunner = new ProcessRunner(); ServiceReport serviceReport = executeToolProcess(toolProcessRunner, command, processStandardInput); if (serviceReport.getType() == Type.ERROR) { String message = "Failed migrating object with title '" + sourceObject.getTitle() + "' from format URI: " + sourceFormat + " to " + destinationFormat + " Standard output: " + toolProcessRunner.getProcessOutputAsString() + "\nStandard error output: " + toolProcessRunner.getProcessErrorAsString(); serviceReport = new ServiceReport(Type.ERROR, Status.TOOL_ERROR, message); return new MigrateResult(null, serviceReport); } if (migrationPath.useTempSourceFile()){ migrationPath.getTempSourceFile().getFile().delete(); } for (TempFile tempFile : migrationPath.getTempFileDeclarations()) { tempFile.getFile().delete(); } DigitalObject.Builder builder; if (migrationPath.useTempDestinationFile()){ File outputfile = migrationPath.getTempOutputFile().getFile(); if (returnByReference){ builder = new DigitalObject.Builder(Content.byReference(outputfile)); } else { builder = new DigitalObject.Builder(Content.byValue(outputfile)); outputfile.delete(); } String message = "Successfully migrated object with title '" + sourceObject.getTitle() + "' from format URI: " + sourceFormat + " to " + destinationFormat + " Standard output: " + toolProcessRunner.getProcessOutputAsString() + "\nStandard error output: " + toolProcessRunner.getProcessErrorAsString(); serviceReport = new ServiceReport(Type.INFO, Status.SUCCESS, message); } else { if (returnByReference){ builder = new DigitalObject.Builder(Content.byReference(toolProcessRunner.getProcessOutput())); } else{ builder = new DigitalObject.Builder(Content.byValue(toolProcessRunner.getProcessOutput())); } String message = "Successfully migrated object with title '" + sourceObject.getTitle() + "' from format URI: " + sourceFormat + " to " + destinationFormat + " Standard error output: " + toolProcessRunner.getProcessErrorAsString(); serviceReport = new ServiceReport(Type.INFO, Status.SUCCESS, message); } DigitalObject destinationObject = builder .format(destinationFormat) .build(); return new MigrateResult(destinationObject, serviceReport); } GenericMigrationWrapper(Document configuration, String canonicalName); MigrateResult migrate(DigitalObject sourceObject, URI sourceFormat,
                                 URI destinationFormat, List<Parameter> toolParameters); ServiceDescription describe();  }