From ad0aab62a6e6f64149bcbdbf055e939898f373b3 Mon Sep 17 00:00:00 2001 From: Prashakthi Date: Thu, 4 Aug 2016 09:28:23 +0530 Subject: [PATCH] Add files via upload removed warnings of javadoc(Taverna 982) --- SaveResultsHandler.java | 83 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 SaveResultsHandler.java diff --git a/SaveResultsHandler.java b/SaveResultsHandler.java new file mode 100644 index 0000000..05d4e88 --- /dev/null +++ b/SaveResultsHandler.java @@ -0,0 +1,83 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +package org.apache.taverna.commandline.data; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; + +import org.apache.taverna.databundle.DataBundles; + +/** + * Handles all recording of results as they are received by the {} or + * when the workflow enactment has completed. + * This includes saving as a Baclava Document, or storing individual results. + * + * @author Stuart Owen + */ +public class SaveResultsHandler { + + private final File outputDirectory; + + public SaveResultsHandler(File rootOutputDir) { + this.outputDirectory = rootOutputDir; + } + + /** + * Given the Data on an output port, saves the data on a disk in the + * output directory. + * + * @param portName + * @param data + * @throws IOException + */ + public void saveResultsForPort(String portName, Path data) throws IOException { + if (DataBundles.isList(data)) { + Path outputPath = outputDirectory.toPath().resolve(portName); + Files.createDirectories(outputPath); + saveList(DataBundles.getList(data), outputPath); + } else if (DataBundles.isError(data)) { + Files.copy(data, outputDirectory.toPath().resolve(portName + ".error")); + } else { + Files.copy(data, outputDirectory.toPath().resolve(portName)); + } + } + + private void saveList(List list, Path destination) throws IOException { + int index = 1; + for (Path data : list) { + if (data != null) { + if (DataBundles.isList(data)) { + Path outputPath = destination.resolve(String.valueOf(index)); + Files.createDirectories(outputPath); + saveList(DataBundles.getList(data), outputPath); + } else if (DataBundles.isError(data)) { + Files.copy(data, destination.resolve(String.valueOf(index) + ".error")); + } else { + Files.copy(data, destination.resolve(String.valueOf(index))); + } + } + index++; + } + } + +}