--- a/src/main/java/net/timbusproject/extractors/modules/tavernaextractor/TavernaExtractor.java
+++ b/src/main/java/net/timbusproject/extractors/modules/tavernaextractor/TavernaExtractor.java
@@ -62,10 +62,7 @@
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.osgi.service.log.LogService;
import org.sbaresearch.licensecheck.LicenseCheck;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import uk.ac.bolton.archimate.editor.model.viewpoints.IViewpoint;
@@ -81,12 +78,17 @@
import javax.xml.xpath.*;
import java.awt.*;
import java.io.*;
+import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.*;
import java.util.List;
import java.util.Map.Entry;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
/**
* @author Rudolf Mayer (rmayer@sba-research.org)
@@ -175,11 +177,19 @@
private Dataflow dataflow;
private SSHManager sshManager;
- private Logger LOGGER = LoggerFactory.getLogger(TavernaExtractor.class);
-
- public TavernaExtractor(){}
+ private static Logger LOGGER = LogManager.getLogger("TavernaExtractor");
+
+ public TavernaExtractor(){
+ LOGGER.setLevel(Level.INFO);
+ }
public TavernaExtractor(boolean verbose) {
+
+ if (verbose) {
+ LOGGER.setLevel(Level.DEBUG);
+ } else {
+ LOGGER.setLevel(Level.INFO);
+ }
}
public TavernaExtractor(SSHManager sshManager) {
@@ -254,7 +264,10 @@
/*
* // Transform a Taverna (t2flow) file to an Archimate file ///////////////
*/
- public void process() throws EditException, OpenDataflowException, InvalidOptionException,
+
+ File tavernaFile = null;
+
+ public void process(boolean remote) throws EditException, OpenDataflowException, InvalidOptionException,
InvalidDataflowException, TokenOrderException, ReadInputException, DatabaseConfigurationException,
CMException, IOException, DeserializationException, IterationTypeMismatchException {
@@ -294,30 +307,11 @@
elementModelObjectMap = new HashMap<String, IDiagramModelArchimateObject>();
relations = new ArrayList<IRelationship>();
- File tavernaFile = null;
- try {
-
- URL workflowURL = null;
- try {
- Session session = sshManager.createSession(15000);
- tavernaFile = sshManager.readFile(session, inputFileName.toString());
- }
- catch(SSHManagerException e){
- e.printStackTrace();
- }
-
- if (tavernaFile.exists()) {
- workflowURL = tavernaFile.toURI().toURL();
- }
-
- LOGGER.info( "Reading workflow from " + workflowURL);
- System.out.println("Reading workflow from " + workflowURL);
- dataflow = openDataflow(workflowURL);
- } catch (NullPointerException npe) {
- npe.printStackTrace();
- LOGGER.error( "ERROR reading workflow from [" + inputFileName + "]." + npe.getMessage());
- return;
- }
+ if(remote)
+ dataflow = getDataflowRemote();
+ else
+ dataflow = getDataflowLocal();
+
// current classpath
String classpath = System.getProperty("java.class.path");
@@ -564,37 +558,10 @@
processDiagramObject.setBounds(padding, padding, outerBounds.getWidth() - padding * 2, outerBounds.getHeight()
- padding * 2);
- // Set new file
- File outFile = TavernaExtractor.getArchimateOutputPath().toFile();
- model.setFile(outFile);
-
- // Set model version
- model.setVersion(ModelVersion.VERSION);
-
- //create tmp file
- Path outputTmp = Files.createTempFile("tavernaExtractor-",".output");
-
- // Adapted from {@link ArchiveManager#saveModelToXMLFile}
- ResourceSet resourceSet = ArchimateResourceFactory.createResourceSet();
- Resource resource = resourceSet.createResource(URI.createFileURI(outputTmp.toAbsolutePath().toString()));
-
- resource.getContents().add(model);
- resource.save(null);
-
- LOGGER.info( "Wrote model successfully to " + outFile.getAbsolutePath());
-
- // copy temp file to remote host
- try {
- Session session = sshManager.createSession(15000);
- sshManager.sendFile(session, outputTmp.toString(), archimateOutputPath.toString());
- }
- catch(SSHManagerException e){
- e.printStackTrace();
- }
-
- // remove both temp files.
- Files.deleteIfExists(outputTmp);
- Files.deleteIfExists(tavernaFile.toPath());
+ if(remote)
+ saveRemote(model);
+ else
+ saveLocal(model);
}
public void processWebServiceActivity(IFolder businessFolder, IFolder infrastructureFolder,
@@ -2196,4 +2163,104 @@
}
}
+
+ private Dataflow getDataflowRemote() throws EditException, OpenDataflowException, MalformedURLException, DeserializationException{
+
+ try {
+
+ URL workflowURL = null;
+ try {
+ Session session = sshManager.createSession(15000);
+ tavernaFile = sshManager.readFile(session, inputFileName.toString());
+ }
+ catch(SSHManagerException e){
+ e.printStackTrace();
+ }
+
+ if (tavernaFile.exists()) {
+ workflowURL = tavernaFile.toURI().toURL();
+ }
+
+ LOGGER.info( "Reading workflow from " + workflowURL);
+ return openDataflow(workflowURL);
+ } catch (NullPointerException npe) {
+ npe.printStackTrace();
+ LOGGER.error( "ERROR reading workflow from [" + inputFileName + "]." + npe.getMessage());
+ }
+ return null;
+ }
+
+ private Dataflow getDataflowLocal() throws EditException, OpenDataflowException, MalformedURLException, DeserializationException{
+ try {
+ // try to load from classpath
+ URL workflowURL = getClass().getResource(inputFileName.toString());
+
+ if (workflowURL == null) { // if not successful, try opening file
+
+ File f = inputFileName.toFile();
+ if (f.exists()) {
+ workflowURL = f.toURI().toURL();
+ }
+ }
+ return openDataflow(workflowURL);
+ } catch (NullPointerException npe) {
+ npe.printStackTrace();
+ LOGGER.error("ERROR reading workflow from [" + inputFileName + "]." + npe.getMessage());
+ }
+ return null;
+ }
+
+
+ private void saveRemote(IArchimateModel model) throws IOException{
+
+ // Set new file
+ File outFile = TavernaExtractor.getArchimateOutputPath().toFile();
+ model.setFile(outFile);
+
+ // Set model version
+ model.setVersion(ModelVersion.VERSION);
+
+ //create tmp file
+ Path outputTmp = Files.createTempFile("tavernaExtractor-",".output");
+
+ // Adapted from {@link ArchiveManager#saveModelToXMLFile}
+ ResourceSet resourceSet = ArchimateResourceFactory.createResourceSet();
+ Resource resource = resourceSet.createResource(URI.createFileURI(outputTmp.toAbsolutePath().toString()));
+
+ resource.getContents().add(model);
+ resource.save(null);
+
+ LOGGER.info( "Wrote model successfully to " + outFile.getAbsolutePath());
+
+ // copy temp file to remote host
+ try {
+ Session session = sshManager.createSession(15000);
+ sshManager.sendFile(session, outputTmp.toString(), archimateOutputPath.toString());
+ }
+ catch(SSHManagerException e){
+ e.printStackTrace();
+ }
+
+ // remove both temp files.
+ Files.deleteIfExists(outputTmp);
+ Files.deleteIfExists(tavernaFile.toPath());
+ }
+
+ private void saveLocal(IArchimateModel model) throws IOException{
+
+ // Set new file
+ File outFile = TavernaExtractor.getArchimateOutputPath().toFile();
+ model.setFile(outFile);
+
+ // Set model version
+ model.setVersion(ModelVersion.VERSION);
+
+ // Adapted from {@link ArchiveManager#saveModelToXMLFile}
+ ResourceSet resourceSet = ArchimateResourceFactory.createResourceSet();
+ Resource resource = resourceSet.createResource(URI.createFileURI(outFile.getAbsolutePath()));
+ resource.getContents().add(model);
+ resource.save(null);
+
+ LOGGER.info("Wrote model successfully to " + outFile.getAbsolutePath());
+ }
}