Skip to content

Commit

Permalink
Check if the selected output file already exists
Browse files Browse the repository at this point in the history
Fix for Issue #8: #8.
  • Loading branch information
Irina Balaur committed Mar 14, 2019
1 parent 0771f5c commit aacd377
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
22 changes: 16 additions & 6 deletions src/main/java/fr/eisbm/GRAPHML2SBGNML/GraphML2SBGNML.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,30 @@ public static void main(String[] args) {
public static void convert(String szInputFileName) {

try {
long start = System.currentTimeMillis();
String xml = new String(Files.readAllBytes(FileSystems.getDefault().getPath(szInputFileName)));
String szOutSBGNFile = szInputFileName.replace(".graphml", "").concat(".sbgn");

//if the output file already exists, it will be overwritten during the current conversion step
if((new File(szOutSBGNFile)).exists())
{
System.out.println("The selected output file exists and it will be overwritten during the current conversion step." );
}

boolean bConversion = false;
if (xml.contains(ConverterDefines.COM_YWORKS_SBGN_PROCESS)) {
GraphML2PD pdConverter = new GraphML2PD();
bConversion = pdConverter.parseGraphMLFile(szInputFileName, szOutSBGNFile);
} else {
} /*else {
GraphML2AF afConverter = new GraphML2AF();
bConversion = afConverter.parseGraphMLFile(szInputFileName, szOutSBGNFile);
}
if (bConversion) {
String szSBGNv02FileName = szInputFileName.replace(".graphml", "-SBGNv02.sbgn");
transformToSBGN02.transformToSBGNv02(szOutSBGNFile, szSBGNv02FileName);
}
}*/

long end = System.currentTimeMillis();
// finding the time difference and converting it into seconds
float sec = (end - start) / 1000F;
System.out.println(sec + " seconds");

System.out.println(szInputFileName + "\t " + bConversion);

} catch (IOException e) {
Expand Down
29 changes: 17 additions & 12 deletions src/main/java/fr/eisbm/GRAPHML2SBGNML/SBGNML2GraphML.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,35 @@ public static void main(String[] args) {
}

public static void convert(String szInputFileName) {

long start = System.currentTimeMillis();
SBGNML2GraphML sg = new SBGNML2GraphML();
String szOutFileName = szInputFileName.substring(0, szInputFileName.indexOf(".")).concat("_generated.graphml");

//if the output file already exists, it will be overwritten during the current conversion step
if((new File(szOutFileName)).exists())
{
System.out.println("The selected output file exists and it will be overwritten during the current conversion step." );
}

sg.parseSBGNFile(szInputFileName, szOutFileName);

String szSBGNv02FileName = szOutFileName.replace(".graphml", "-SBGNv02.sbgn");
transformToSBGN02.transformToSBGNv02(szInputFileName, szSBGNv02FileName);
long end = System.currentTimeMillis();
// finding the time difference and converting it into seconds
float sec = (end - start) / 1000F;
System.out.println(sec + " seconds");
}

public void parseSBGNFile(String szInSBGNFileName, String szOutGraphMLFileName) {
// Now read from "f" and put the result in "sbgn"
Sbgn sbgn;
try {
sbgn = Utils.readFromFile(szInSBGNFileName);

if(((org.sbgn.bindings.Map) sbgn.getMap()).getLanguage().equals("process description"))
{

if (((org.sbgn.bindings.Map) sbgn.getMap()).getLanguage().equals("process description")) {
PD2GraphML pdConverter = new PD2GraphML();
pdConverter.parseSBGNFile( szInSBGNFileName, szOutGraphMLFileName);
}
else if(((org.sbgn.bindings.Map) sbgn.getMap()).getLanguage().equals("activity flow"))
{
pdConverter.parseSBGNFile(szInSBGNFileName, szOutGraphMLFileName);
} else if (((org.sbgn.bindings.Map) sbgn.getMap()).getLanguage().equals("activity flow")) {
AF2GraphML afConverter = new AF2GraphML();
afConverter.parseSBGNFile(szInSBGNFileName, szOutGraphMLFileName);
afConverter.parseSBGNFile(szInSBGNFileName, szOutGraphMLFileName);
}
} catch (JAXBException e) {
e.printStackTrace();
Expand Down

0 comments on commit aacd377

Please sign in to comment.