|
a/src/main/java/net/timbusproject/extractors/modules/tavernaextractor/TavernaExtractor.java |
|
b/src/main/java/net/timbusproject/extractors/modules/tavernaextractor/TavernaExtractor.java |
|
... |
|
... |
60 |
import org.dom4j.DocumentException;
|
60 |
import org.dom4j.DocumentException;
|
61 |
import org.dom4j.DocumentHelper;
|
61 |
import org.dom4j.DocumentHelper;
|
62 |
import org.eclipse.emf.common.util.URI;
|
62 |
import org.eclipse.emf.common.util.URI;
|
63 |
import org.eclipse.emf.ecore.resource.Resource;
|
63 |
import org.eclipse.emf.ecore.resource.Resource;
|
64 |
import org.eclipse.emf.ecore.resource.ResourceSet;
|
64 |
import org.eclipse.emf.ecore.resource.ResourceSet;
|
65 |
import org.osgi.service.log.LogService;
|
|
|
66 |
import org.sbaresearch.licensecheck.LicenseCheck;
|
65 |
import org.sbaresearch.licensecheck.LicenseCheck;
|
67 |
import org.slf4j.Logger;
|
|
|
68 |
import org.slf4j.LoggerFactory;
|
|
|
69 |
import org.w3c.dom.NodeList;
|
66 |
import org.w3c.dom.NodeList;
|
70 |
import org.xml.sax.SAXException;
|
67 |
import org.xml.sax.SAXException;
|
71 |
import uk.ac.bolton.archimate.editor.model.viewpoints.IViewpoint;
|
68 |
import uk.ac.bolton.archimate.editor.model.viewpoints.IViewpoint;
|
72 |
import uk.ac.bolton.archimate.model.*;
|
69 |
import uk.ac.bolton.archimate.model.*;
|
73 |
import uk.ac.bolton.archimate.model.impl.BusinessEvent;
|
70 |
import uk.ac.bolton.archimate.model.impl.BusinessEvent;
|
|
... |
|
... |
79 |
import javax.xml.parsers.DocumentBuilderFactory;
|
76 |
import javax.xml.parsers.DocumentBuilderFactory;
|
80 |
import javax.xml.parsers.ParserConfigurationException;
|
77 |
import javax.xml.parsers.ParserConfigurationException;
|
81 |
import javax.xml.xpath.*;
|
78 |
import javax.xml.xpath.*;
|
82 |
import java.awt.*;
|
79 |
import java.awt.*;
|
83 |
import java.io.*;
|
80 |
import java.io.*;
|
|
|
81 |
import java.net.MalformedURLException;
|
84 |
import java.net.URL;
|
82 |
import java.net.URL;
|
85 |
import java.nio.file.*;
|
83 |
import java.nio.file.*;
|
86 |
import java.nio.file.attribute.BasicFileAttributes;
|
84 |
import java.nio.file.attribute.BasicFileAttributes;
|
87 |
import java.util.*;
|
85 |
import java.util.*;
|
88 |
import java.util.List;
|
86 |
import java.util.List;
|
89 |
import java.util.Map.Entry;
|
87 |
import java.util.Map.Entry;
|
|
|
88 |
|
|
|
89 |
import org.apache.log4j.Level;
|
|
|
90 |
import org.apache.log4j.LogManager;
|
|
|
91 |
import org.apache.log4j.Logger;
|
90 |
|
92 |
|
91 |
/**
|
93 |
/**
|
92 |
* @author Rudolf Mayer (rmayer@sba-research.org)
|
94 |
* @author Rudolf Mayer (rmayer@sba-research.org)
|
93 |
* @author Marco Unterberger (munterberger@sba-research.org)
|
95 |
* @author Marco Unterberger (munterberger@sba-research.org)
|
94 |
*/
|
96 |
*/
|
|
... |
|
... |
173 |
private IApplicationFunction callWebServiceApplicationFunction = null;
|
175 |
private IApplicationFunction callWebServiceApplicationFunction = null;
|
174 |
private IApplicationFunction callToolInvocationFunction = null;
|
176 |
private IApplicationFunction callToolInvocationFunction = null;
|
175 |
|
177 |
|
176 |
private Dataflow dataflow;
|
178 |
private Dataflow dataflow;
|
177 |
private SSHManager sshManager;
|
179 |
private SSHManager sshManager;
|
178 |
private Logger LOGGER = LoggerFactory.getLogger(TavernaExtractor.class);
|
180 |
private static Logger LOGGER = LogManager.getLogger("TavernaExtractor");
|
179 |
|
181 |
|
180 |
public TavernaExtractor(){}
|
182 |
public TavernaExtractor(){
|
|
|
183 |
LOGGER.setLevel(Level.INFO);
|
|
|
184 |
}
|
181 |
|
185 |
|
182 |
public TavernaExtractor(boolean verbose) {
|
186 |
public TavernaExtractor(boolean verbose) {
|
|
|
187 |
|
|
|
188 |
if (verbose) {
|
|
|
189 |
LOGGER.setLevel(Level.DEBUG);
|
|
|
190 |
} else {
|
|
|
191 |
LOGGER.setLevel(Level.INFO);
|
|
|
192 |
}
|
183 |
}
|
193 |
}
|
184 |
|
194 |
|
185 |
public TavernaExtractor(SSHManager sshManager) {
|
195 |
public TavernaExtractor(SSHManager sshManager) {
|
186 |
this.sshManager = sshManager;
|
196 |
this.sshManager = sshManager;
|
187 |
}
|
197 |
}
|
|
... |
|
... |
252 |
}
|
262 |
}
|
253 |
|
263 |
|
254 |
/*
|
264 |
/*
|
255 |
* // Transform a Taverna (t2flow) file to an Archimate file ///////////////
|
265 |
* // Transform a Taverna (t2flow) file to an Archimate file ///////////////
|
256 |
*/
|
266 |
*/
|
|
|
267 |
|
|
|
268 |
File tavernaFile = null;
|
|
|
269 |
|
257 |
public void process() throws EditException, OpenDataflowException, InvalidOptionException,
|
270 |
public void process(boolean remote) throws EditException, OpenDataflowException, InvalidOptionException,
|
258 |
InvalidDataflowException, TokenOrderException, ReadInputException, DatabaseConfigurationException,
|
271 |
InvalidDataflowException, TokenOrderException, ReadInputException, DatabaseConfigurationException,
|
259 |
CMException, IOException, DeserializationException, IterationTypeMismatchException {
|
272 |
CMException, IOException, DeserializationException, IterationTypeMismatchException {
|
260 |
|
273 |
|
261 |
LOGGER.info( "Start Taverna Extractor ...");
|
274 |
LOGGER.info( "Start Taverna Extractor ...");
|
262 |
|
275 |
|
|
... |
|
... |
292 |
|
305 |
|
293 |
nodeElements = new ArrayList<IArchimateElement>();
|
306 |
nodeElements = new ArrayList<IArchimateElement>();
|
294 |
elementModelObjectMap = new HashMap<String, IDiagramModelArchimateObject>();
|
307 |
elementModelObjectMap = new HashMap<String, IDiagramModelArchimateObject>();
|
295 |
relations = new ArrayList<IRelationship>();
|
308 |
relations = new ArrayList<IRelationship>();
|
296 |
|
309 |
|
297 |
File tavernaFile = null;
|
310 |
if(remote)
|
298 |
try {
|
|
|
299 |
|
|
|
300 |
URL workflowURL = null;
|
|
|
301 |
try {
|
|
|
302 |
Session session = sshManager.createSession(15000);
|
|
|
303 |
tavernaFile = sshManager.readFile(session, inputFileName.toString());
|
|
|
304 |
}
|
|
|
305 |
catch(SSHManagerException e){
|
|
|
306 |
e.printStackTrace();
|
|
|
307 |
}
|
|
|
308 |
|
|
|
309 |
if (tavernaFile.exists()) {
|
|
|
310 |
workflowURL = tavernaFile.toURI().toURL();
|
|
|
311 |
}
|
|
|
312 |
|
|
|
313 |
LOGGER.info( "Reading workflow from " + workflowURL);
|
|
|
314 |
System.out.println("Reading workflow from " + workflowURL);
|
|
|
315 |
dataflow = openDataflow(workflowURL);
|
311 |
dataflow = getDataflowRemote();
|
316 |
} catch (NullPointerException npe) {
|
|
|
317 |
npe.printStackTrace();
|
|
|
318 |
LOGGER.error( "ERROR reading workflow from [" + inputFileName + "]." + npe.getMessage());
|
|
|
319 |
return;
|
|
|
320 |
}
|
312 |
else
|
|
|
313 |
dataflow = getDataflowLocal();
|
|
|
314 |
|
321 |
|
315 |
|
322 |
// current classpath
|
316 |
// current classpath
|
323 |
String classpath = System.getProperty("java.class.path");
|
317 |
String classpath = System.getProperty("java.class.path");
|
324 |
String[] classpathEntries = classpath.split(File.pathSeparator);
|
318 |
String[] classpathEntries = classpath.split(File.pathSeparator);
|
325 |
List<String> cleanClasspathEntries = cleanedClasspath(Arrays.asList(classpathEntries));
|
319 |
List<String> cleanClasspathEntries = cleanedClasspath(Arrays.asList(classpathEntries));
|
|
... |
|
... |
562 |
+ padding, outerBounds.getHeight() + 10);
|
556 |
+ padding, outerBounds.getHeight() + 10);
|
563 |
IDiagramModelArchimateObject processDiagramObject = elementModelObjectMap.get(parentProcessWorkflow.getId());
|
557 |
IDiagramModelArchimateObject processDiagramObject = elementModelObjectMap.get(parentProcessWorkflow.getId());
|
564 |
processDiagramObject.setBounds(padding, padding, outerBounds.getWidth() - padding * 2, outerBounds.getHeight()
|
558 |
processDiagramObject.setBounds(padding, padding, outerBounds.getWidth() - padding * 2, outerBounds.getHeight()
|
565 |
- padding * 2);
|
559 |
- padding * 2);
|
566 |
|
560 |
|
567 |
// Set new file
|
561 |
if(remote)
|
568 |
File outFile = TavernaExtractor.getArchimateOutputPath().toFile();
|
562 |
saveRemote(model);
|
569 |
model.setFile(outFile);
|
|
|
570 |
|
|
|
571 |
// Set model version
|
|
|
572 |
model.setVersion(ModelVersion.VERSION);
|
|
|
573 |
|
|
|
574 |
//create tmp file
|
|
|
575 |
Path outputTmp = Files.createTempFile("tavernaExtractor-",".output");
|
|
|
576 |
|
|
|
577 |
// Adapted from {@link ArchiveManager#saveModelToXMLFile}
|
|
|
578 |
ResourceSet resourceSet = ArchimateResourceFactory.createResourceSet();
|
|
|
579 |
Resource resource = resourceSet.createResource(URI.createFileURI(outputTmp.toAbsolutePath().toString()));
|
|
|
580 |
|
|
|
581 |
resource.getContents().add(model);
|
|
|
582 |
resource.save(null);
|
|
|
583 |
|
|
|
584 |
LOGGER.info( "Wrote model successfully to " + outFile.getAbsolutePath());
|
|
|
585 |
|
|
|
586 |
// copy temp file to remote host
|
|
|
587 |
try {
|
|
|
588 |
Session session = sshManager.createSession(15000);
|
|
|
589 |
sshManager.sendFile(session, outputTmp.toString(), archimateOutputPath.toString());
|
|
|
590 |
}
|
563 |
else
|
591 |
catch(SSHManagerException e){
|
564 |
saveLocal(model);
|
592 |
e.printStackTrace();
|
|
|
593 |
}
|
|
|
594 |
|
|
|
595 |
// remove both temp files.
|
|
|
596 |
Files.deleteIfExists(outputTmp);
|
|
|
597 |
Files.deleteIfExists(tavernaFile.toPath());
|
|
|
598 |
}
|
565 |
}
|
599 |
|
566 |
|
600 |
public void processWebServiceActivity(IFolder businessFolder, IFolder infrastructureFolder,
|
567 |
public void processWebServiceActivity(IFolder businessFolder, IFolder infrastructureFolder,
|
601 |
IFolder applicationFolder, IFolder relationsFolder, IApplicationComponent workflowApplicationComponent,
|
568 |
IFolder applicationFolder, IFolder relationsFolder, IApplicationComponent workflowApplicationComponent,
|
602 |
HashMap<Processor, IBusinessProcess> processorProcessMap,
|
569 |
HashMap<Processor, IBusinessProcess> processorProcessMap,
|
|
... |
|
... |
2194 |
}
|
2161 |
}
|
2195 |
}
|
2162 |
}
|
2196 |
}
|
2163 |
}
|
2197 |
|
2164 |
|
2198 |
}
|
2165 |
}
|
|
|
2166 |
|
|
|
2167 |
private Dataflow getDataflowRemote() throws EditException, OpenDataflowException, MalformedURLException, DeserializationException{
|
|
|
2168 |
|
|
|
2169 |
try {
|
|
|
2170 |
|
|
|
2171 |
URL workflowURL = null;
|
|
|
2172 |
try {
|
|
|
2173 |
Session session = sshManager.createSession(15000);
|
|
|
2174 |
tavernaFile = sshManager.readFile(session, inputFileName.toString());
|
|
|
2175 |
}
|
|
|
2176 |
catch(SSHManagerException e){
|
|
|
2177 |
e.printStackTrace();
|
|
|
2178 |
}
|
|
|
2179 |
|
|
|
2180 |
if (tavernaFile.exists()) {
|
|
|
2181 |
workflowURL = tavernaFile.toURI().toURL();
|
|
|
2182 |
}
|
|
|
2183 |
|
|
|
2184 |
LOGGER.info( "Reading workflow from " + workflowURL);
|
|
|
2185 |
return openDataflow(workflowURL);
|
|
|
2186 |
} catch (NullPointerException npe) {
|
|
|
2187 |
npe.printStackTrace();
|
|
|
2188 |
LOGGER.error( "ERROR reading workflow from [" + inputFileName + "]." + npe.getMessage());
|
|
|
2189 |
}
|
|
|
2190 |
return null;
|
|
|
2191 |
}
|
|
|
2192 |
|
|
|
2193 |
private Dataflow getDataflowLocal() throws EditException, OpenDataflowException, MalformedURLException, DeserializationException{
|
|
|
2194 |
try {
|
|
|
2195 |
// try to load from classpath
|
|
|
2196 |
URL workflowURL = getClass().getResource(inputFileName.toString());
|
|
|
2197 |
|
|
|
2198 |
if (workflowURL == null) { // if not successful, try opening file
|
|
|
2199 |
|
|
|
2200 |
File f = inputFileName.toFile();
|
|
|
2201 |
if (f.exists()) {
|
|
|
2202 |
workflowURL = f.toURI().toURL();
|
|
|
2203 |
}
|
|
|
2204 |
}
|
|
|
2205 |
return openDataflow(workflowURL);
|
|
|
2206 |
} catch (NullPointerException npe) {
|
|
|
2207 |
npe.printStackTrace();
|
|
|
2208 |
LOGGER.error("ERROR reading workflow from [" + inputFileName + "]." + npe.getMessage());
|
|
|
2209 |
}
|
|
|
2210 |
return null;
|
|
|
2211 |
}
|
|
|
2212 |
|
|
|
2213 |
|
|
|
2214 |
private void saveRemote(IArchimateModel model) throws IOException{
|
|
|
2215 |
|
|
|
2216 |
// Set new file
|
|
|
2217 |
File outFile = TavernaExtractor.getArchimateOutputPath().toFile();
|
|
|
2218 |
model.setFile(outFile);
|
|
|
2219 |
|
|
|
2220 |
// Set model version
|
|
|
2221 |
model.setVersion(ModelVersion.VERSION);
|
|
|
2222 |
|
|
|
2223 |
//create tmp file
|
|
|
2224 |
Path outputTmp = Files.createTempFile("tavernaExtractor-",".output");
|
|
|
2225 |
|
|
|
2226 |
// Adapted from {@link ArchiveManager#saveModelToXMLFile}
|
|
|
2227 |
ResourceSet resourceSet = ArchimateResourceFactory.createResourceSet();
|
|
|
2228 |
Resource resource = resourceSet.createResource(URI.createFileURI(outputTmp.toAbsolutePath().toString()));
|
|
|
2229 |
|
|
|
2230 |
resource.getContents().add(model);
|
|
|
2231 |
resource.save(null);
|
|
|
2232 |
|
|
|
2233 |
LOGGER.info( "Wrote model successfully to " + outFile.getAbsolutePath());
|
|
|
2234 |
|
|
|
2235 |
// copy temp file to remote host
|
|
|
2236 |
try {
|
|
|
2237 |
Session session = sshManager.createSession(15000);
|
|
|
2238 |
sshManager.sendFile(session, outputTmp.toString(), archimateOutputPath.toString());
|
|
|
2239 |
}
|
|
|
2240 |
catch(SSHManagerException e){
|
|
|
2241 |
e.printStackTrace();
|
|
|
2242 |
}
|
|
|
2243 |
|
|
|
2244 |
// remove both temp files.
|
|
|
2245 |
Files.deleteIfExists(outputTmp);
|
|
|
2246 |
Files.deleteIfExists(tavernaFile.toPath());
|
|
|
2247 |
}
|
|
|
2248 |
|
|
|
2249 |
private void saveLocal(IArchimateModel model) throws IOException{
|
|
|
2250 |
|
|
|
2251 |
// Set new file
|
|
|
2252 |
File outFile = TavernaExtractor.getArchimateOutputPath().toFile();
|
|
|
2253 |
model.setFile(outFile);
|
|
|
2254 |
|
|
|
2255 |
// Set model version
|
|
|
2256 |
model.setVersion(ModelVersion.VERSION);
|
|
|
2257 |
|
|
|
2258 |
// Adapted from {@link ArchiveManager#saveModelToXMLFile}
|
|
|
2259 |
ResourceSet resourceSet = ArchimateResourceFactory.createResourceSet();
|
|
|
2260 |
Resource resource = resourceSet.createResource(URI.createFileURI(outFile.getAbsolutePath()));
|
|
|
2261 |
resource.getContents().add(model);
|
|
|
2262 |
resource.save(null);
|
|
|
2263 |
|
|
|
2264 |
LOGGER.info("Wrote model successfully to " + outFile.getAbsolutePath());
|
|
|
2265 |
}
|
2199 |
}
|
2266 |
}
|