@Test public void testMigrateUsingTempFiles() throws Exception { this.testParameters.add(new Parameter("mode", "complete")); MigrateResult migrationResult = this.genericWrapper.migrate( getDigitalTestObject(), this.sourceFormatURI, this.destinationFormatURI, this.testParameters); Assert.assertEquals(ServiceReport.Status.SUCCESS, migrationResult .getReport().getStatus()); }
@SuppressWarnings("boxing") public MigrateResult migrate(DigitalObject digitalObject, URI inputFormat, URI outputFormat, List<Parameter> toolParameters) throws MigrationException, ConfigurationException { final ServicePerformanceHelper servicePerformanceHelper = new ServicePerformanceHelper(); final Date migrationStartTime = new Date(); final MigrationPath migrationPath = this.migrationPaths.getMigrationPath( inputFormat, outputFormat); if (toolParameters == null) { this.log.warning("Called with null parameters. Assuming the caller ment" + " to call with an empty list."); toolParameters = new ArrayList<Parameter>(); } final Map<String, File> temporaryFileMappings = createTemporaryFiles(migrationPath); InputStream standardInputStream = null; final ToolIOProfile inputIOProfile = migrationPath .getToolInputProfile(); if (inputIOProfile.usePipedIO()) { standardInputStream = digitalObject.getContent().getInputStream(); } else { File inputTempFile = temporaryFileMappings.get(inputIOProfile .getCommandLineFileLabel()); DigitalObjectUtils.toFile(digitalObject, inputTempFile); } final PRCommandBuilder commandBuilder = new PRCommandBuilder( this.environmentParameters); final List<String> prCommand = commandBuilder.buildCommand( migrationPath, toolParameters, temporaryFileMappings); if (this.log.isLoggable(Level.INFO)) { String fullCommandLine = ""; for (String cmdfrag : prCommand) { fullCommandLine += cmdfrag + " "; } this.log.info("Executing command line: " + fullCommandLine); } final ProcessRunner toolProcessRunner = new ProcessRunner(); final boolean executionSuccessful = executeToolProcess( toolProcessRunner, prCommand, standardInputStream); final ToolIOProfile outputIOProfile = migrationPath .getToolOutputProfile(); if ((outputIOProfile.usePipedIO() == false) && executionSuccessful) { final String outputFileLabel = outputIOProfile .getCommandLineFileLabel(); for (String tempFileLabel : temporaryFileMappings.keySet()) { if (outputFileLabel.equals(tempFileLabel) == false) { temporaryFileMappings.get(tempFileLabel).delete(); } } } else { for (File tempFile : temporaryFileMappings.values()) { tempFile.delete(); } } if (executionSuccessful == false) { return buildMigrationResult(migrationPath, digitalObject, null, toolProcessRunner); } DigitalObject.Builder builder; final ParameterReader parameterReader = new ParameterReader( toolParameters); final boolean returnDataByReference = parameterReader .getBooleanParameter("returnByReference", true); final ToolIOProfile toolOutputProfile = migrationPath .getToolOutputProfile(); if (toolOutputProfile.usePipedIO() == false) { final File outputFile = temporaryFileMappings.get(toolOutputProfile .getCommandLineFileLabel()); if (returnDataByReference) { builder = new DigitalObject.Builder(Content .byReference(outputFile)); } else { builder = new DigitalObject.Builder(Content.byValue(outputFile)); outputFile.delete(); } } else { if (returnDataByReference) { builder = new DigitalObject.Builder(Content .byReference(toolProcessRunner.getProcessOutput())); } else { builder = new DigitalObject.Builder(Content .byValue(toolProcessRunner.getProcessOutput())); } } final double migrationDuration = new Date().getTime() - migrationStartTime.getTime(); builder.format(outputFormat); final Agent agent = new Agent(this.toolIdentifier, this.serviceDescription .getName(), this.serviceDescription.getType()); String eventSummary = "Migration carried out by executing the command line:"; for (String commandLineFragment : prCommand) { eventSummary += " " + commandLineFragment; } eventSummary += "\n\nThe migration service was called with these parameters:\n\n"; for (Parameter serviceParameter : toolParameters) { eventSummary += serviceParameter.getName() + " = " + serviceParameter.getValue() + "\n"; } servicePerformanceHelper.stop(); final DateFormat defaultDateFormat = DateFormat.getDateInstance(); final Event event = new Event(eventSummary, defaultDateFormat .format(migrationStartTime), migrationDuration, agent, servicePerformanceHelper.getPerformanceProperties()); builder.events(event); final DigitalObject resultObject = builder.build(); return buildMigrationResult(migrationPath, digitalObject, resultObject, toolProcessRunner); }
GenericMigrationWrapper { @SuppressWarnings("boxing") public MigrateResult migrate(DigitalObject digitalObject, URI inputFormat, URI outputFormat, List<Parameter> toolParameters) throws MigrationException, ConfigurationException { final ServicePerformanceHelper servicePerformanceHelper = new ServicePerformanceHelper(); final Date migrationStartTime = new Date(); final MigrationPath migrationPath = this.migrationPaths.getMigrationPath( inputFormat, outputFormat); if (toolParameters == null) { this.log.warning("Called with null parameters. Assuming the caller ment" + " to call with an empty list."); toolParameters = new ArrayList<Parameter>(); } final Map<String, File> temporaryFileMappings = createTemporaryFiles(migrationPath); InputStream standardInputStream = null; final ToolIOProfile inputIOProfile = migrationPath .getToolInputProfile(); if (inputIOProfile.usePipedIO()) { standardInputStream = digitalObject.getContent().getInputStream(); } else { File inputTempFile = temporaryFileMappings.get(inputIOProfile .getCommandLineFileLabel()); DigitalObjectUtils.toFile(digitalObject, inputTempFile); } final PRCommandBuilder commandBuilder = new PRCommandBuilder( this.environmentParameters); final List<String> prCommand = commandBuilder.buildCommand( migrationPath, toolParameters, temporaryFileMappings); if (this.log.isLoggable(Level.INFO)) { String fullCommandLine = ""; for (String cmdfrag : prCommand) { fullCommandLine += cmdfrag + " "; } this.log.info("Executing command line: " + fullCommandLine); } final ProcessRunner toolProcessRunner = new ProcessRunner(); final boolean executionSuccessful = executeToolProcess( toolProcessRunner, prCommand, standardInputStream); final ToolIOProfile outputIOProfile = migrationPath .getToolOutputProfile(); if ((outputIOProfile.usePipedIO() == false) && executionSuccessful) { final String outputFileLabel = outputIOProfile .getCommandLineFileLabel(); for (String tempFileLabel : temporaryFileMappings.keySet()) { if (outputFileLabel.equals(tempFileLabel) == false) { temporaryFileMappings.get(tempFileLabel).delete(); } } } else { for (File tempFile : temporaryFileMappings.values()) { tempFile.delete(); } } if (executionSuccessful == false) { return buildMigrationResult(migrationPath, digitalObject, null, toolProcessRunner); } DigitalObject.Builder builder; final ParameterReader parameterReader = new ParameterReader( toolParameters); final boolean returnDataByReference = parameterReader .getBooleanParameter("returnByReference", true); final ToolIOProfile toolOutputProfile = migrationPath .getToolOutputProfile(); if (toolOutputProfile.usePipedIO() == false) { final File outputFile = temporaryFileMappings.get(toolOutputProfile .getCommandLineFileLabel()); if (returnDataByReference) { builder = new DigitalObject.Builder(Content .byReference(outputFile)); } else { builder = new DigitalObject.Builder(Content.byValue(outputFile)); outputFile.delete(); } } else { if (returnDataByReference) { builder = new DigitalObject.Builder(Content .byReference(toolProcessRunner.getProcessOutput())); } else { builder = new DigitalObject.Builder(Content .byValue(toolProcessRunner.getProcessOutput())); } } final double migrationDuration = new Date().getTime() - migrationStartTime.getTime(); builder.format(outputFormat); final Agent agent = new Agent(this.toolIdentifier, this.serviceDescription .getName(), this.serviceDescription.getType()); String eventSummary = "Migration carried out by executing the command line:"; for (String commandLineFragment : prCommand) { eventSummary += " " + commandLineFragment; } eventSummary += "\n\nThe migration service was called with these parameters:\n\n"; for (Parameter serviceParameter : toolParameters) { eventSummary += serviceParameter.getName() + " = " + serviceParameter.getValue() + "\n"; } servicePerformanceHelper.stop(); final DateFormat defaultDateFormat = DateFormat.getDateInstance(); final Event event = new Event(eventSummary, defaultDateFormat .format(migrationStartTime), migrationDuration, agent, servicePerformanceHelper.getPerformanceProperties()); builder.events(event); final DigitalObject resultObject = builder.build(); return buildMigrationResult(migrationPath, digitalObject, resultObject, toolProcessRunner); } }
GenericMigrationWrapper { @SuppressWarnings("boxing") public MigrateResult migrate(DigitalObject digitalObject, URI inputFormat, URI outputFormat, List<Parameter> toolParameters) throws MigrationException, ConfigurationException { final ServicePerformanceHelper servicePerformanceHelper = new ServicePerformanceHelper(); final Date migrationStartTime = new Date(); final MigrationPath migrationPath = this.migrationPaths.getMigrationPath( inputFormat, outputFormat); if (toolParameters == null) { this.log.warning("Called with null parameters. Assuming the caller ment" + " to call with an empty list."); toolParameters = new ArrayList<Parameter>(); } final Map<String, File> temporaryFileMappings = createTemporaryFiles(migrationPath); InputStream standardInputStream = null; final ToolIOProfile inputIOProfile = migrationPath .getToolInputProfile(); if (inputIOProfile.usePipedIO()) { standardInputStream = digitalObject.getContent().getInputStream(); } else { File inputTempFile = temporaryFileMappings.get(inputIOProfile .getCommandLineFileLabel()); DigitalObjectUtils.toFile(digitalObject, inputTempFile); } final PRCommandBuilder commandBuilder = new PRCommandBuilder( this.environmentParameters); final List<String> prCommand = commandBuilder.buildCommand( migrationPath, toolParameters, temporaryFileMappings); if (this.log.isLoggable(Level.INFO)) { String fullCommandLine = ""; for (String cmdfrag : prCommand) { fullCommandLine += cmdfrag + " "; } this.log.info("Executing command line: " + fullCommandLine); } final ProcessRunner toolProcessRunner = new ProcessRunner(); final boolean executionSuccessful = executeToolProcess( toolProcessRunner, prCommand, standardInputStream); final ToolIOProfile outputIOProfile = migrationPath .getToolOutputProfile(); if ((outputIOProfile.usePipedIO() == false) && executionSuccessful) { final String outputFileLabel = outputIOProfile .getCommandLineFileLabel(); for (String tempFileLabel : temporaryFileMappings.keySet()) { if (outputFileLabel.equals(tempFileLabel) == false) { temporaryFileMappings.get(tempFileLabel).delete(); } } } else { for (File tempFile : temporaryFileMappings.values()) { tempFile.delete(); } } if (executionSuccessful == false) { return buildMigrationResult(migrationPath, digitalObject, null, toolProcessRunner); } DigitalObject.Builder builder; final ParameterReader parameterReader = new ParameterReader( toolParameters); final boolean returnDataByReference = parameterReader .getBooleanParameter("returnByReference", true); final ToolIOProfile toolOutputProfile = migrationPath .getToolOutputProfile(); if (toolOutputProfile.usePipedIO() == false) { final File outputFile = temporaryFileMappings.get(toolOutputProfile .getCommandLineFileLabel()); if (returnDataByReference) { builder = new DigitalObject.Builder(Content .byReference(outputFile)); } else { builder = new DigitalObject.Builder(Content.byValue(outputFile)); outputFile.delete(); } } else { if (returnDataByReference) { builder = new DigitalObject.Builder(Content .byReference(toolProcessRunner.getProcessOutput())); } else { builder = new DigitalObject.Builder(Content .byValue(toolProcessRunner.getProcessOutput())); } } final double migrationDuration = new Date().getTime() - migrationStartTime.getTime(); builder.format(outputFormat); final Agent agent = new Agent(this.toolIdentifier, this.serviceDescription .getName(), this.serviceDescription.getType()); String eventSummary = "Migration carried out by executing the command line:"; for (String commandLineFragment : prCommand) { eventSummary += " " + commandLineFragment; } eventSummary += "\n\nThe migration service was called with these parameters:\n\n"; for (Parameter serviceParameter : toolParameters) { eventSummary += serviceParameter.getName() + " = " + serviceParameter.getValue() + "\n"; } servicePerformanceHelper.stop(); final DateFormat defaultDateFormat = DateFormat.getDateInstance(); final Event event = new Event(eventSummary, defaultDateFormat .format(migrationStartTime), migrationDuration, agent, servicePerformanceHelper.getPerformanceProperties()); builder.events(event); final DigitalObject resultObject = builder.build(); return buildMigrationResult(migrationPath, digitalObject, resultObject, toolProcessRunner); } GenericMigrationWrapper(Document configuration,
	    Configuration environmentSettings, String toolIdentifier); }
GenericMigrationWrapper { @SuppressWarnings("boxing") public MigrateResult migrate(DigitalObject digitalObject, URI inputFormat, URI outputFormat, List<Parameter> toolParameters) throws MigrationException, ConfigurationException { final ServicePerformanceHelper servicePerformanceHelper = new ServicePerformanceHelper(); final Date migrationStartTime = new Date(); final MigrationPath migrationPath = this.migrationPaths.getMigrationPath( inputFormat, outputFormat); if (toolParameters == null) { this.log.warning("Called with null parameters. Assuming the caller ment" + " to call with an empty list."); toolParameters = new ArrayList<Parameter>(); } final Map<String, File> temporaryFileMappings = createTemporaryFiles(migrationPath); InputStream standardInputStream = null; final ToolIOProfile inputIOProfile = migrationPath .getToolInputProfile(); if (inputIOProfile.usePipedIO()) { standardInputStream = digitalObject.getContent().getInputStream(); } else { File inputTempFile = temporaryFileMappings.get(inputIOProfile .getCommandLineFileLabel()); DigitalObjectUtils.toFile(digitalObject, inputTempFile); } final PRCommandBuilder commandBuilder = new PRCommandBuilder( this.environmentParameters); final List<String> prCommand = commandBuilder.buildCommand( migrationPath, toolParameters, temporaryFileMappings); if (this.log.isLoggable(Level.INFO)) { String fullCommandLine = ""; for (String cmdfrag : prCommand) { fullCommandLine += cmdfrag + " "; } this.log.info("Executing command line: " + fullCommandLine); } final ProcessRunner toolProcessRunner = new ProcessRunner(); final boolean executionSuccessful = executeToolProcess( toolProcessRunner, prCommand, standardInputStream); final ToolIOProfile outputIOProfile = migrationPath .getToolOutputProfile(); if ((outputIOProfile.usePipedIO() == false) && executionSuccessful) { final String outputFileLabel = outputIOProfile .getCommandLineFileLabel(); for (String tempFileLabel : temporaryFileMappings.keySet()) { if (outputFileLabel.equals(tempFileLabel) == false) { temporaryFileMappings.get(tempFileLabel).delete(); } } } else { for (File tempFile : temporaryFileMappings.values()) { tempFile.delete(); } } if (executionSuccessful == false) { return buildMigrationResult(migrationPath, digitalObject, null, toolProcessRunner); } DigitalObject.Builder builder; final ParameterReader parameterReader = new ParameterReader( toolParameters); final boolean returnDataByReference = parameterReader .getBooleanParameter("returnByReference", true); final ToolIOProfile toolOutputProfile = migrationPath .getToolOutputProfile(); if (toolOutputProfile.usePipedIO() == false) { final File outputFile = temporaryFileMappings.get(toolOutputProfile .getCommandLineFileLabel()); if (returnDataByReference) { builder = new DigitalObject.Builder(Content .byReference(outputFile)); } else { builder = new DigitalObject.Builder(Content.byValue(outputFile)); outputFile.delete(); } } else { if (returnDataByReference) { builder = new DigitalObject.Builder(Content .byReference(toolProcessRunner.getProcessOutput())); } else { builder = new DigitalObject.Builder(Content .byValue(toolProcessRunner.getProcessOutput())); } } final double migrationDuration = new Date().getTime() - migrationStartTime.getTime(); builder.format(outputFormat); final Agent agent = new Agent(this.toolIdentifier, this.serviceDescription .getName(), this.serviceDescription.getType()); String eventSummary = "Migration carried out by executing the command line:"; for (String commandLineFragment : prCommand) { eventSummary += " " + commandLineFragment; } eventSummary += "\n\nThe migration service was called with these parameters:\n\n"; for (Parameter serviceParameter : toolParameters) { eventSummary += serviceParameter.getName() + " = " + serviceParameter.getValue() + "\n"; } servicePerformanceHelper.stop(); final DateFormat defaultDateFormat = DateFormat.getDateInstance(); final Event event = new Event(eventSummary, defaultDateFormat .format(migrationStartTime), migrationDuration, agent, servicePerformanceHelper.getPerformanceProperties()); builder.events(event); final DigitalObject resultObject = builder.build(); return buildMigrationResult(migrationPath, digitalObject, resultObject, toolProcessRunner); } GenericMigrationWrapper(Document configuration,
	    Configuration environmentSettings, String toolIdentifier); ServiceDescription describe(); @SuppressWarnings("boxing") MigrateResult migrate(DigitalObject digitalObject, URI inputFormat,
	    URI outputFormat, List<Parameter> toolParameters); }
GenericMigrationWrapper { @SuppressWarnings("boxing") public MigrateResult migrate(DigitalObject digitalObject, URI inputFormat, URI outputFormat, List<Parameter> toolParameters) throws MigrationException, ConfigurationException { final ServicePerformanceHelper servicePerformanceHelper = new ServicePerformanceHelper(); final Date migrationStartTime = new Date(); final MigrationPath migrationPath = this.migrationPaths.getMigrationPath( inputFormat, outputFormat); if (toolParameters == null) { this.log.warning("Called with null parameters. Assuming the caller ment" + " to call with an empty list."); toolParameters = new ArrayList<Parameter>(); } final Map<String, File> temporaryFileMappings = createTemporaryFiles(migrationPath); InputStream standardInputStream = null; final ToolIOProfile inputIOProfile = migrationPath .getToolInputProfile(); if (inputIOProfile.usePipedIO()) { standardInputStream = digitalObject.getContent().getInputStream(); } else { File inputTempFile = temporaryFileMappings.get(inputIOProfile .getCommandLineFileLabel()); DigitalObjectUtils.toFile(digitalObject, inputTempFile); } final PRCommandBuilder commandBuilder = new PRCommandBuilder( this.environmentParameters); final List<String> prCommand = commandBuilder.buildCommand( migrationPath, toolParameters, temporaryFileMappings); if (this.log.isLoggable(Level.INFO)) { String fullCommandLine = ""; for (String cmdfrag : prCommand) { fullCommandLine += cmdfrag + " "; } this.log.info("Executing command line: " + fullCommandLine); } final ProcessRunner toolProcessRunner = new ProcessRunner(); final boolean executionSuccessful = executeToolProcess( toolProcessRunner, prCommand, standardInputStream); final ToolIOProfile outputIOProfile = migrationPath .getToolOutputProfile(); if ((outputIOProfile.usePipedIO() == false) && executionSuccessful) { final String outputFileLabel = outputIOProfile .getCommandLineFileLabel(); for (String tempFileLabel : temporaryFileMappings.keySet()) { if (outputFileLabel.equals(tempFileLabel) == false) { temporaryFileMappings.get(tempFileLabel).delete(); } } } else { for (File tempFile : temporaryFileMappings.values()) { tempFile.delete(); } } if (executionSuccessful == false) { return buildMigrationResult(migrationPath, digitalObject, null, toolProcessRunner); } DigitalObject.Builder builder; final ParameterReader parameterReader = new ParameterReader( toolParameters); final boolean returnDataByReference = parameterReader .getBooleanParameter("returnByReference", true); final ToolIOProfile toolOutputProfile = migrationPath .getToolOutputProfile(); if (toolOutputProfile.usePipedIO() == false) { final File outputFile = temporaryFileMappings.get(toolOutputProfile .getCommandLineFileLabel()); if (returnDataByReference) { builder = new DigitalObject.Builder(Content .byReference(outputFile)); } else { builder = new DigitalObject.Builder(Content.byValue(outputFile)); outputFile.delete(); } } else { if (returnDataByReference) { builder = new DigitalObject.Builder(Content .byReference(toolProcessRunner.getProcessOutput())); } else { builder = new DigitalObject.Builder(Content .byValue(toolProcessRunner.getProcessOutput())); } } final double migrationDuration = new Date().getTime() - migrationStartTime.getTime(); builder.format(outputFormat); final Agent agent = new Agent(this.toolIdentifier, this.serviceDescription .getName(), this.serviceDescription.getType()); String eventSummary = "Migration carried out by executing the command line:"; for (String commandLineFragment : prCommand) { eventSummary += " " + commandLineFragment; } eventSummary += "\n\nThe migration service was called with these parameters:\n\n"; for (Parameter serviceParameter : toolParameters) { eventSummary += serviceParameter.getName() + " = " + serviceParameter.getValue() + "\n"; } servicePerformanceHelper.stop(); final DateFormat defaultDateFormat = DateFormat.getDateInstance(); final Event event = new Event(eventSummary, defaultDateFormat .format(migrationStartTime), migrationDuration, agent, servicePerformanceHelper.getPerformanceProperties()); builder.events(event); final DigitalObject resultObject = builder.build(); return buildMigrationResult(migrationPath, digitalObject, resultObject, toolProcessRunner); } GenericMigrationWrapper(Document configuration,
	    Configuration environmentSettings, String toolIdentifier); ServiceDescription describe(); @SuppressWarnings("boxing") MigrateResult migrate(DigitalObject digitalObject, URI inputFormat,
	    URI outputFormat, List<Parameter> toolParameters);  }