From c275b14df512963bce4a8582628868ed65dc2cfa Mon Sep 17 00:00:00 2001 From: Marco Procaccini Date: Tue, 26 Mar 2024 14:43:20 +0100 Subject: [PATCH] autocloseable implemented and app.java creted for the standalone version --- .../java/org/gcube/vremanagement/App.java | 41 +++++++++++++++++++ .../gcube/vremanagement/VREQueryService.java | 18 ++++---- .../gcube/vremanagement/CsvUpdateTest.java | 35 ++++++++++++---- 3 files changed, 75 insertions(+), 19 deletions(-) create mode 100644 src/main/java/org/gcube/vremanagement/App.java diff --git a/src/main/java/org/gcube/vremanagement/App.java b/src/main/java/org/gcube/vremanagement/App.java new file mode 100644 index 0000000..613035e --- /dev/null +++ b/src/main/java/org/gcube/vremanagement/App.java @@ -0,0 +1,41 @@ +package org.gcube.vremanagement; + +import java.io.IOException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class App { + + private static Logger logger = LoggerFactory + .getLogger(App.class); + + private static String[] listVOs= {"D4Research","gCubeApps","FARM","ParthenosVO","OpenAIRE"}; + private static String scopeIn = "/d4science.research-infrastructures.eu"; + private static int skipLines = 3; + private static String InCsvFile="VREDecommisioned-240326.csv"; + //Used for GooGle APis; + + + public static void main (String[] args) + { + + try(VREQueryService updaterCSV = new VREQueryService(InCsvFile,skipLines);){ + + String voIn="D4Research"; + String vreName="FoodborneOutbreak"; + updaterCSV.getVREInfoFromClient(scopeIn,voIn, vreName); + + logger.debug("Updating VREs in a LOCAL CSV file"); + updaterCSV.updateCSVformCSVList(scopeIn); + logger.debug("Update CSV done"); + + logger.debug("Getting missing VRE in a LOCAL CSV file"); + updaterCSV.missingVREinCSV(scopeIn, listVOs); + logger.debug("Missing CSV done"); + + }catch (IOException e) + {e.printStackTrace();}; + + } +} \ No newline at end of file diff --git a/src/main/java/org/gcube/vremanagement/VREQueryService.java b/src/main/java/org/gcube/vremanagement/VREQueryService.java index e0f7044..7a8353c 100644 --- a/src/main/java/org/gcube/vremanagement/VREQueryService.java +++ b/src/main/java/org/gcube/vremanagement/VREQueryService.java @@ -43,7 +43,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class VREQueryService { +public class VREQueryService implements AutoCloseable{ private File fileCSV; private File outFileCSV; @@ -65,7 +65,7 @@ public class VREQueryService { - public VREQueryService(String _InCsvPath, int _skipLines) + public VREQueryService (String _InCsvPath, int _skipLines) { try { String filePath = "src/test/resources"; @@ -95,19 +95,15 @@ public class VREQueryService { public static VREQueryService getInstance() { return new VREQueryService();}; - - protected void finalize() throws Throwable + + public void close() throws IOException { - try { - csvReader.close(); - }finally { - super.finalize(); - } + if(csvReader !=null) { csvReader.close();} + if(csvWriter !=null) { csvWriter.close();} + if(csvMissWriter !=null) {csvMissWriter.close();} } - - public List getReportVREs(String _scopeVO) { try { diff --git a/src/test/java/org/gcube/vremanagement/CsvUpdateTest.java b/src/test/java/org/gcube/vremanagement/CsvUpdateTest.java index a51c18e..10ce90e 100644 --- a/src/test/java/org/gcube/vremanagement/CsvUpdateTest.java +++ b/src/test/java/org/gcube/vremanagement/CsvUpdateTest.java @@ -1,6 +1,7 @@ package org.gcube.vremanagement; -import static org.junit.jupiter.api.Assertions.*; + +import java.io.IOException; import java.util.InputMismatchException; import java.util.Scanner; @@ -30,41 +31,59 @@ class CsvUpdateTest { @Test void QueryClientVREInfoTest(){ - VREQueryService updaterCSV = new VREQueryService(InCsvFile,skipLines); + + try(VREQueryService updaterCSV = new VREQueryService(InCsvFile,skipLines)){ String voIn="D4Research"; String vreName="FoodborneOutbreak"; + logger.debug("Checking information about the VRE "+vreName+" in the VO:"+voIn); updaterCSV.getVREInfoFromClient(scopeIn,voIn, vreName); + }catch(IOException e) + { + e.printStackTrace(); + } } @Test void UpdateLocalCSVTest() { - VREQueryService updaterCSV = new VREQueryService(InCsvFile,skipLines); + try(VREQueryService updaterCSV = new VREQueryService(InCsvFile,skipLines)){ logger.debug("Updating VREs in a LOCAL CSV file"); updaterCSV.updateCSVformCSVList(scopeIn); logger.debug("Update CSV done"); + }catch(IOException e) + { + e.printStackTrace(); + } } @Test void MissingLocalCSVTest(){ - VREQueryService updaterCSV = new VREQueryService(InCsvFile,skipLines); + try(VREQueryService updaterCSV = new VREQueryService(InCsvFile,skipLines)){ logger.debug("Getting missing VRE in a LOCAL CSV file"); updaterCSV.missingVREinCSV(scopeIn, listVOs); logger.debug("Missing CSV done"); + }catch(IOException e) + { + e.printStackTrace(); + } } @Disabled @Test void UpdateEndTimeVRETest(){ - + try(VREQueryService updaterCSV = new VREQueryService(InCsvFile,skipLines)){ String voTimeIn="D4Research"; String vreTimeName="FoodborneOutbreak"; int yearIn=2024; int monthIn=2; //Months start from zero int dayIn=21; - VREQueryService updaterCSV = new VREQueryService(InCsvFile,skipLines); + updaterCSV.updateEndTimeVRE(scopeIn, voTimeIn, vreTimeName, yearIn,monthIn, dayIn); + }catch(IOException e) + { + e.printStackTrace(); + } } @@ -110,7 +129,7 @@ class CsvUpdateTest { int choice=0; do { - VREQueryService updaterCSV = new VREQueryService(InCsvFile,skipLines); + try (VREQueryService updaterCSV = new VREQueryService(InCsvFile,skipLines)){ logger.debug("Menu:"); logger.debug("1. Update VREs in a LOCAL CSV file"); @@ -121,7 +140,7 @@ class CsvUpdateTest { logger.debug("6. Update Missing VRES in a Remore Google Sheet"); logger.debug("7. Exit"); logger.debug("Choice:"); - try { + choice = scanner.nextInt(); scanner.nextLine();