Parent: [346c31] (diff)

Child: [0553f7] (diff)

Download this file

Main.java    223 lines (181 with data), 9.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
package net.timbusproject.extractors.modules.tavernaextractor;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map.Entry;
import java.util.Properties;
import net.timbusproject.extractors.modules.tavernaextractor.provenance.ProvenanceAccessClient;
import net.timbusproject.extractors.modules.tavernaextractor.provenance.ProvenanceAccessEntry;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
public class Main {
private static Logger LOGGER = LogManager.getLogger("Main");
private static boolean verbose = false;
public static void main(String[] args) {
LOGGER.setLevel(Level.INFO);
try {
CommandLineParser parser = new GnuParser();
HelpFormatter helpFormater = new HelpFormatter();
try {
CommandLine parse = parser.parse(createOptions(), args);
// Program started without any option
if (parse.getOptions().length <= 0) {
System.out.println("Incorrect arguments. ");
helpFormater.printHelp("TavernaExtractor", createOptions());
System.exit(1);
}
Properties props = Main.loadProperties();
String tavernaHome = props.getProperty("taverna.home");
String dotExeLocation = props.getProperty("dot.exe.location");
String tavernaT2DatabasePath = props.getProperty("taverna.t2Database.path");
// Convert Taverna2 WF to Archimate model
if (parse.hasOption("i") && parse.hasOption("o")) {
String archimateOutputPath = parse.getOptionValue("o");
String inputFileName = parse.getOptionValue("i");
if (parse.hasOption("v"))
verbose = true;
// setup the extractor
TavernaExtractor extractor = new TavernaExtractor(verbose);
extractor.setTavernaHome(Main.getTavernaHome(tavernaHome));
extractor.setArchimateOutputPath(Paths.get(archimateOutputPath));
extractor.setInputFileName(Paths.get(inputFileName));
extractor.setDotLocation(Paths.get(dotExeLocation));
extractor.process(false); //false = local execution
}
// List all provenance entries OR Running DROID identification
if (parse.hasOption("p")) {
ProvenanceAccessClient pac;
if (tavernaT2DatabasePath != null && !tavernaT2DatabasePath.isEmpty()) {
pac = new ProvenanceAccessClient(tavernaT2DatabasePath);
} else {
pac = new ProvenanceAccessClient();
}
System.out.println("===== [ID] | [Workflow Name (Timestamp)] ===== | "
+ pac.listAllWorkflowsReadable().size() + " entries found.");
for (Entry<Integer, ProvenanceAccessEntry> entry : pac.listAllWorkflowsReadable().entrySet()) {
System.out.println("[" + entry.getKey() + "] " + entry.getValue().printToConsole());
}
if (parse.getOptionValue("p") != null) {
String input = readLine("Your choice: ");
String filePath = parse.getOptionValue("p");
try {
Integer id = Integer.parseInt(input);
Path path = pac.processWorkflow(id, filePath);
System.out.println("Path to the tmp directory is: "+path.toString());
} catch (NumberFormatException e) {
System.out.println("Your input '" + input + "' was not a valid number. Process stopped.");
}
}
}
// Extend DSO with PRONOM information
if (parse.hasOption("ont") && parse.hasOption("r")) {
LOGGER.debug("Start extending ontology ...");
System.out.println("Start extending ontology ...");
File ontology = null;
File report = null;
String ontologyFilePath = parse.getOptionValue("ont");
String reportFilePath = parse.getOptionValue("r");
if (ontologyFilePath != null) {
ontology = new File(ontologyFilePath);
}
if (reportFilePath != null) {
report = new File(reportFilePath);
}
if (ontology.exists() && report.exists()) {
LOGGER.debug("ontology file = " + ontology.getAbsolutePath());
LOGGER.debug("report file = " + report.getAbsolutePath());
System.out.println("ontology file = " + ontology.getAbsolutePath());
System.out.println("report file = " + report.getAbsolutePath());
new ExtendedOWL().process(ontology, report);
} else {
LOGGER.error("ERROR: Can not find either onotoly file (" + ontologyFilePath + ") or ("
+ reportFilePath + ").");
System.out.println("ERROR: Can not find either onotoly file (" + ontologyFilePath + ") or ("
+ reportFilePath + ").");
}
}
} catch (ParseException exp) {
helpFormater.printHelp("TavernaExtractor", createOptions());
LOGGER.error("ERROR: Wrong usage:" + exp.getMessage());
exp.printStackTrace();
}
} catch (Exception e) {
LOGGER.error(e.getMessage());
// also print the error stack trace
if(verbose)
e.printStackTrace();
System.exit(1);
}
}
private static Options createOptions() {
Options options = new Options();
OptionBuilder.withDescription("Specifies the archimate (output) file.");
OptionBuilder.hasArg();
OptionBuilder.withLongOpt("output-file");
options.addOption(OptionBuilder.create("o"));
OptionBuilder.withDescription("Specifies the taverna t2flow (input) file.");
OptionBuilder.hasArg();
OptionBuilder.withLongOpt("input-file");
options.addOption(OptionBuilder.create("i"));
OptionBuilder.withDescription("Fetching provenance information from a workflow execution");
OptionBuilder.withArgName("\\path\\to\\copy\\provenance-trace");
OptionBuilder.hasArg();
OptionBuilder.withLongOpt("provenance");
options.addOption(OptionBuilder.create("p"));
OptionBuilder.withDescription("Ontology file");
OptionBuilder.withArgName("\\path\\to\\myOntology.owl");
OptionBuilder.hasArg();
OptionBuilder.withLongOpt("ontology-file");
options.addOption(OptionBuilder.create("ont"));
OptionBuilder.withDescription("DROID report file");
OptionBuilder.withArgName("\\path\\to\\myDroidCSVreportFile.droid.csv");
OptionBuilder.hasArg();
OptionBuilder.withLongOpt("reportFile");
options.addOption(OptionBuilder.create("r"));
OptionBuilder.withDescription("verbose mode one");
OptionBuilder.withLongOpt("verbose");
options.addOption(OptionBuilder.create("v"));
return options;
}
private static Path getTavernaHome(String tavernaHome){
// set default value in case of missing argument
if(tavernaHome == null){
return Paths.get(System.getProperty("user.home"),"taverna-2.4.0");
}
return Paths.get(tavernaHome);
}
// Due to a bug in eclipse
// from http://stackoverflow.com/questions/4203646/system-console-returns-null
private static String readLine(String format, Object... args) throws IOException {
if (System.console() != null) {
return System.console().readLine(format, args);
}
System.out.print(String.format(format, args));
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
return reader.readLine();
}
private static Properties loadProperties() {
Properties prop = new Properties();
try {
InputStream input = Main.class.getClassLoader().getResourceAsStream("TavernaExtractor.properties");
prop.load(input);
LOGGER.debug("Load properties successfully.");
} catch (IOException io) {
LOGGER.error(io.getMessage());
io.printStackTrace();
}
return prop;
}
}