Switch to unified view

a/src/main/java/net/timbusproject/extractors/modules/tavernaextractor/TavernaExtractor.java b/src/main/java/net/timbusproject/extractors/modules/tavernaextractor/TavernaExtractor.java
...
...
2177
            }
2177
            }
2178
        }
2178
        }
2179
2179
2180
    }
2180
    }
2181
2181
2182
    private Dataflow getDataflowRemote() throws EditException, OpenDataflowException, MalformedURLException, DeserializationException{
2182
    private Dataflow getDataflowRemote() throws TavernaExtractorException {
2183
2183
2184
        try {
2184
        try {
2185
2185
2186
            URL workflowURL = null;
2186
            URL workflowURL = null;
2187
            try {
2187
            try {
2188
                Session session = sshManager.createSession(15000);
2188
                Session session = sshManager.createSession(15000);
2189
                tavernaFile = sshManager.readFile(session, inputFileName.toString());
2189
                tavernaFile = sshManager.readFile(session, inputFileName.toString());
2190
            }
2190
            }
2191
            catch(SSHManagerException e){
2191
            catch(SSHManagerException e){
2192
                e.printStackTrace();
2192
                e.printStackTrace();
2193
                throw new TavernaExtractorException(e.getLocalizedMessage());
2193
            }
2194
            }
2194
2195
2195
            if (tavernaFile.exists()) {
2196
            if (tavernaFile.exists()) {
2196
                workflowURL = tavernaFile.toURI().toURL();
2197
                workflowURL = tavernaFile.toURI().toURL();
2197
            }
2198
            }
2198
2199
2199
            LOGGER.info( "Reading workflow from " + workflowURL);
2200
            LOGGER.info( "Reading workflow from " + workflowURL);
2200
            return openDataflow(workflowURL);
2201
            return openDataflow(workflowURL);
2201
        } catch (NullPointerException npe) {
2202
        } catch (NullPointerException | EditException | OpenDataflowException | MalformedURLException | DeserializationException e) {
2202
            npe.printStackTrace();
2203
            e.printStackTrace();
2203
            LOGGER.error( "ERROR reading workflow from [" + inputFileName + "]." + npe.getMessage());
2204
            LOGGER.error( "ERROR reading workflow from [" + inputFileName + "]." + e.getMessage());
2204
        }
2205
        }
2205
        return null;
2206
        return null;
2206
    }
2207
    }
2207
2208
2208
    private Dataflow getDataflowLocal() throws EditException, OpenDataflowException, MalformedURLException, DeserializationException{
2209
    private Dataflow getDataflowLocal() throws EditException, OpenDataflowException, MalformedURLException, DeserializationException{
...
...
2224
        }
2225
        }
2225
        return null;
2226
        return null;
2226
    }
2227
    }
2227
2228
2228
2229
2229
    private void saveRemote(IArchimateModel model) throws IOException{
2230
    private void saveRemote(IArchimateModel model) throws TavernaExtractorException {
2230
2231
2231
        // Set new file
2232
        // Set new file
2232
        File outFile = TavernaExtractor.getArchimateOutputPath().toFile();
2233
        File outFile = TavernaExtractor.getArchimateOutputPath().toFile();
2233
        model.setFile(outFile);
2234
        model.setFile(outFile);
2234
2235
2235
        // Set model version
2236
        // Set model version
2236
        model.setVersion(ModelVersion.VERSION);
2237
        model.setVersion(ModelVersion.VERSION);
2237
2238
2238
        //create tmp file
2239
        //create tmp file
2240
        Path outputTmp = null;
2241
        try{
2239
        Path outputTmp = Files.createTempFile("tavernaExtractor-",".output");
2242
            outputTmp = Files.createTempFile("tavernaExtractor-",".output");
2240
2243
2241
        // Adapted from {@link ArchiveManager#saveModelToXMLFile}
2244
            // Adapted from {@link ArchiveManager#saveModelToXMLFile}
2242
        ResourceSet resourceSet = ArchimateResourceFactory.createResourceSet();
2245
            ResourceSet resourceSet = ArchimateResourceFactory.createResourceSet();
2243
        Resource resource = resourceSet.createResource(URI.createFileURI(outputTmp.toAbsolutePath().toString()));
2246
            Resource resource = resourceSet.createResource(URI.createFileURI(outputTmp.toAbsolutePath().toString()));
2244
2247
2245
        resource.getContents().add(model);
2248
            resource.getContents().add(model);
2246
        resource.save(null);
2249
            resource.save(null);
2250
        }
2251
        catch(IOException e){
2252
            e.printStackTrace();
2253
            throw new TavernaExtractorException(e.getLocalizedMessage());
2254
        }
2247
2255
2248
        LOGGER.info( "Wrote model successfully to " + outFile.getAbsolutePath());
2256
        LOGGER.info( "Wrote model successfully to " + outFile.getAbsolutePath());
2249
2257
2250
        // copy temp file to remote host
2258
        // copy temp file to remote host
2251
        try {
2259
        try {
2252
            Session session = sshManager.createSession(15000);
2260
            Session session = sshManager.createSession(15000);
2253
            sshManager.sendFile(session, outputTmp.toString(), archimateOutputPath.toString());
2261
            sshManager.sendFile(session, outputTmp.toString(), archimateOutputPath.toString());
2254
        }
2262
        }
2255
        catch(SSHManagerException e){
2263
        catch(SSHManagerException e){
2256
            e.printStackTrace();
2264
            e.printStackTrace();
2265
            throw new TavernaExtractorException(e.getLocalizedMessage());
2266
        }
2267
2257
        }
2268
        try {
2258
2259
        //for the testbed, return file content as string representation
2269
            //for the testbed, return file content as string representation
2260
        convertedFileAsString = new String(Files.readAllBytes(outputTmp), StandardCharsets.UTF_8);
2270
            convertedFileAsString = new String(Files.readAllBytes(outputTmp), StandardCharsets.UTF_8);
2261
2271
2262
        // remove both temp files.
2272
            // remove both temp files.
2263
        Files.deleteIfExists(outputTmp);
2273
            Files.deleteIfExists(outputTmp);
2264
        Files.deleteIfExists(tavernaFile.toPath());
2274
            Files.deleteIfExists(tavernaFile.toPath());
2275
        }
2276
        catch(IOException e){
2277
            e.printStackTrace();
2278
            throw new TavernaExtractorException(e.getLocalizedMessage());
2279
        }
2265
    }
2280
    }
2266
2281
2267
    private void saveLocal(IArchimateModel model) throws IOException{
2282
    private void saveLocal(IArchimateModel model) throws IOException{
2268
2283
2269
        // Set new file
2284
        // Set new file