Parent: [038b56] (diff)

Child: [a88df0] (diff)

Download this file

Main.java    91 lines (77 with data), 3.2 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
package net.timbusproject.iermtoowl;
import net.timbusproject.iermtoowl.epc.EPCModel;
import net.timbusproject.iermtoowl.risks.BusinessProcess;
import net.timbusproject.iermtoowl.utils.EPCReader;
import net.timbusproject.iermtoowl.utils.OntologyMapper;
import net.timbusproject.iermtoowl.utils.RiskReader;
import org.apache.commons.cli.*;
import org.apache.commons.io.FileUtils;
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
import java.io.File;
import java.io.IOException;
/**
* Created by miguel on 25-06-2014.
*/
public class Main {
public static void main(String[] args) throws IOException, OWLOntologyStorageException, ParseException {
String riskPath = null;
String epcPath = null;
String[] imports = null;
String destinationPath = null;
Options options = new Options();
options.addOption("help", false, "Show all options");
options.addOption("h", false, "Show all options");
options.addOption("r", true, "Choose risk file");
options.addOption("e", true, "Choose EPC file");
options.addOption("d", true, "Choose destination file");
options.addOption(OptionBuilder.hasArg(true)
.isRequired(false)
.withDescription("Choose import file(s)")
.hasArgs()
.create("i"));
CommandLine cmd = new BasicParser().parse(options, args);
if (cmd.hasOption("h") || cmd.hasOption("help")) {
System.out.println("-r\tChoose risk file - Mandatory\n-e\tChoose EPC file - Mandatory\n-i\tChoose import file(s)\n-d\tChoose destination file");
System.exit(0);
}
if (cmd.hasOption("r"))
riskPath = cmd.getOptionValue("r");
if (cmd.hasOption("e"))
epcPath = cmd.getOptionValue("e");
if (cmd.hasOption("i")) {
imports = cmd.getOptionValues("i");
}
if (cmd.hasOption("d")) {
destinationPath = cmd.getOptionValue("d");
}
if (riskPath == null && epcPath == null){
System.out.println("No Risk or EPC file have been provided");
System.exit(0);
}
RiskReader riskReader = new RiskReader();
EPCReader epcReader = new EPCReader();
OntologyMapper mapper = new OntologyMapper();
BusinessProcess bp = null;
if (riskPath != null)
bp = riskReader.readFromFile(riskPath);
EPCModel epc = null;
if (epcPath != null)
epc = epcReader.readFromFile(epcPath, bp);
String owlString = mapper.run(bp, epc, imports);
File file;
if (destinationPath != null && !destinationPath.equals(""))
file = new File(destinationPath);
else
file = new File("outputTest.owl");
System.out.println("Writing output to file: " + file.getName() + "...");
FileUtils.writeStringToFile(file, owlString);
}
public static File fileHandler(String path) {
File file;
if (path.startsWith("/") || path.startsWith("~"))
file = new File(path);
else
file = new File(new File(System.getProperty("user.dir")), path);
return file;
}
}