autocloseable implemented and app.java creted for the standalone version

This commit is contained in:
Marco Procaccini 2024-03-26 14:43:20 +01:00
parent 75052f92a9
commit c275b14df5
3 changed files with 75 additions and 19 deletions

View File

@ -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();};
}
}

View File

@ -43,7 +43,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
public class VREQueryService { public class VREQueryService implements AutoCloseable{
private File fileCSV; private File fileCSV;
private File outFileCSV; private File outFileCSV;
@ -65,7 +65,7 @@ public class VREQueryService {
public VREQueryService(String _InCsvPath, int _skipLines) public VREQueryService (String _InCsvPath, int _skipLines)
{ {
try { try {
String filePath = "src/test/resources"; String filePath = "src/test/resources";
@ -95,19 +95,15 @@ public class VREQueryService {
public static VREQueryService getInstance() { return new VREQueryService();}; public static VREQueryService getInstance() { return new VREQueryService();};
protected void finalize() throws Throwable public void close() throws IOException
{ {
try { if(csvReader !=null) { csvReader.close();}
csvReader.close(); if(csvWriter !=null) { csvWriter.close();}
}finally { if(csvMissWriter !=null) {csvMissWriter.close();}
super.finalize();
}
} }
public List<Report> getReportVREs(String _scopeVO) public List<Report> getReportVREs(String _scopeVO)
{ {
try { try {

View File

@ -1,6 +1,7 @@
package org.gcube.vremanagement; package org.gcube.vremanagement;
import static org.junit.jupiter.api.Assertions.*;
import java.io.IOException;
import java.util.InputMismatchException; import java.util.InputMismatchException;
import java.util.Scanner; import java.util.Scanner;
@ -30,41 +31,59 @@ class CsvUpdateTest {
@Test @Test
void QueryClientVREInfoTest(){ void QueryClientVREInfoTest(){
VREQueryService updaterCSV = new VREQueryService(InCsvFile,skipLines);
try(VREQueryService updaterCSV = new VREQueryService(InCsvFile,skipLines)){
String voIn="D4Research"; String voIn="D4Research";
String vreName="FoodborneOutbreak"; String vreName="FoodborneOutbreak";
logger.debug("Checking information about the VRE "+vreName+" in the VO:"+voIn);
updaterCSV.getVREInfoFromClient(scopeIn,voIn, vreName); updaterCSV.getVREInfoFromClient(scopeIn,voIn, vreName);
}catch(IOException e)
{
e.printStackTrace();
}
} }
@Test @Test
void UpdateLocalCSVTest() { void UpdateLocalCSVTest() {
VREQueryService updaterCSV = new VREQueryService(InCsvFile,skipLines); try(VREQueryService updaterCSV = new VREQueryService(InCsvFile,skipLines)){
logger.debug("Updating VREs in a LOCAL CSV file"); logger.debug("Updating VREs in a LOCAL CSV file");
updaterCSV.updateCSVformCSVList(scopeIn); updaterCSV.updateCSVformCSVList(scopeIn);
logger.debug("Update CSV done"); logger.debug("Update CSV done");
}catch(IOException e)
{
e.printStackTrace();
}
} }
@Test @Test
void MissingLocalCSVTest(){ 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"); logger.debug("Getting missing VRE in a LOCAL CSV file");
updaterCSV.missingVREinCSV(scopeIn, listVOs); updaterCSV.missingVREinCSV(scopeIn, listVOs);
logger.debug("Missing CSV done"); logger.debug("Missing CSV done");
}catch(IOException e)
{
e.printStackTrace();
}
} }
@Disabled @Disabled
@Test @Test
void UpdateEndTimeVRETest(){ void UpdateEndTimeVRETest(){
try(VREQueryService updaterCSV = new VREQueryService(InCsvFile,skipLines)){
String voTimeIn="D4Research"; String voTimeIn="D4Research";
String vreTimeName="FoodborneOutbreak"; String vreTimeName="FoodborneOutbreak";
int yearIn=2024; int yearIn=2024;
int monthIn=2; //Months start from zero int monthIn=2; //Months start from zero
int dayIn=21; int dayIn=21;
VREQueryService updaterCSV = new VREQueryService(InCsvFile,skipLines);
updaterCSV.updateEndTimeVRE(scopeIn, voTimeIn, vreTimeName, yearIn,monthIn, dayIn); updaterCSV.updateEndTimeVRE(scopeIn, voTimeIn, vreTimeName, yearIn,monthIn, dayIn);
}catch(IOException e)
{
e.printStackTrace();
}
} }
@ -110,7 +129,7 @@ class CsvUpdateTest {
int choice=0; int choice=0;
do { do {
VREQueryService updaterCSV = new VREQueryService(InCsvFile,skipLines); try (VREQueryService updaterCSV = new VREQueryService(InCsvFile,skipLines)){
logger.debug("Menu:"); logger.debug("Menu:");
logger.debug("1. Update VREs in a LOCAL CSV file"); 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("6. Update Missing VRES in a Remore Google Sheet");
logger.debug("7. Exit"); logger.debug("7. Exit");
logger.debug("Choice:"); logger.debug("Choice:");
try {
choice = scanner.nextInt(); choice = scanner.nextInt();
scanner.nextLine(); scanner.nextLine();