builder class and singleton implemented for the service. Documentation of the service that uses local csv files

This commit is contained in:
Marco Procaccini 2024-03-26 16:00:40 +01:00
parent c275b14df5
commit fa19680a85
3 changed files with 140 additions and 29 deletions

View File

@ -13,15 +13,16 @@ public class App {
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";
private static String InCsvFileName="VREDecommisioned-240326.csv";
private static String filePath="src/main/resources";
//Used for GooGle APis;
public static void main (String[] args)
{
try(VREQueryService updaterCSV = new VREQueryService(InCsvFile,skipLines);){
try(VREQueryService updaterCSV = new VREQueryService.VQSBuilder().setCSVFiles(filePath,InCsvFileName,skipLines).build())
{
String voIn="D4Research";
String vreName="FoodborneOutbreak";
updaterCSV.getVREInfoFromClient(scopeIn,voIn, vreName);

View File

@ -42,7 +42,11 @@ import org.gcube.vremanagement.vremodeler.utils.reports.DeployReport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Class that implement the methods to parse the CSV file produced by redmine,
* query the remote client to get additional information about the VREs contained in CSV
* like start time, end time and description and, finally, store the information in a new CSV file.
*/
public class VREQueryService implements AutoCloseable{
private File fileCSV;
@ -62,40 +66,88 @@ public class VREQueryService implements AutoCloseable{
private static final Logger logger = LoggerFactory.getLogger(VREQueryService.class);
private static VREQueryService VQSInstance;
public VREQueryService (String _InCsvPath, int _skipLines)
/**
* Private Class constructor that takes as input the path and the name of the CSV file to read,
* and the starting rows to skip inside the CSV file
*
* @param _filePath path of the CSV file produced by redmine to read
* @param _InCsvPath name of the CSV file produced by redmine to read
* @param _skipLines initial rows to skip in the CSV file
*/
private VREQueryService (String _filePath,String _InCsvPath, int _skipLines)
{
try {
String filePath = "src/test/resources";
String InFilePath = filePath+File.separator+ _InCsvPath;
OutFilePath = filePath+File.separator+"updated_"+_InCsvPath;
MissFilePath =filePath+File.separator+"missing_"+_InCsvPath;
fileCSV = new File(InFilePath);
if(!fileCSV.exists())
String InFilePath = _filePath+File.separator+ _InCsvPath;
this.OutFilePath = _filePath+File.separator+"updated_"+_InCsvPath;
this.MissFilePath =_filePath+File.separator+"missing_"+_InCsvPath;
this.fileCSV = new File(InFilePath);
if(!this.fileCSV.exists())
{
System.err.println("Input CSV File "+_InCsvPath+" does not exists in the path "+filePath+"!");
System.err.println("Input CSV File "+_InCsvPath+" does not exists in the path "+_filePath+"!");
System.exit(0);
}
logger.debug("file url path:" + fileCSV.getPath());
csvParser = new CSVParserBuilder().withSeparator(',').withIgnoreQuotations(true).build();
csvReader = new CSVReaderBuilder(new FileReader(fileCSV)).withSkipLines(_skipLines).withCSVParser(csvParser).build();
this.csvParser = new CSVParserBuilder().withSeparator(',').withIgnoreQuotations(true).build();
this.csvReader = new CSVReaderBuilder(new FileReader(fileCSV)).withSkipLines(_skipLines).withCSVParser(csvParser).build();
allRows = csvReader.readAll();
dateFormat = new SimpleDateFormat("MMM dd yyyy hh:mm a");
mapVres = new HashMap<>();
this.allRows = csvReader.readAll();
this.dateFormat = new SimpleDateFormat("MMM dd yyyy hh:mm a");
this.mapVres = new HashMap<>();
} catch(Exception e)
{ e.printStackTrace();};
}
/**
* Class builder
*/
public static class VQSBuilder{
private String filePath;
private String csvName;
private int toSkip;
public VQSBuilder setCSVFiles(String _filePath, String _csvName, int _toSkip)
{
this.filePath = _filePath;
this.csvName= _csvName;
this.toSkip = _toSkip;
return this;
}
public VREQueryService build() {
return new VREQueryService(filePath,csvName,toSkip);
}
}
/**
* Empty class constructor
*/
public VREQueryService() {}
public static VREQueryService getInstance() { return new VREQueryService();};
/**
* Singleton of the service
* @return
*/
public static synchronized VREQueryService getInstance() {
if(VQSInstance !=null)
return VQSInstance;
return new VREQueryService();};
/**
* Close metodo of the AutoCloseable interface
*/
public void close() throws IOException
{
if(csvReader !=null) { csvReader.close();}
@ -103,7 +155,11 @@ public class VREQueryService implements AutoCloseable{
if(csvMissWriter !=null) {csvMissWriter.close();}
}
/**
* Return all the VREs of a specific VO
* @param _scopeVO the VO to query
* @return list of all the VREs of a specific VO
*/
public List<Report> getReportVREs(String _scopeVO)
{
try {
@ -120,6 +176,12 @@ public class VREQueryService implements AutoCloseable{
}
/**
* Method that try to reduce the query number to the remote service.
* It save all the VREs of the specified VO in a hash map data structure
* @param _scopeList list of VOs
* @return hash map with key=VO, value = List of Vres of the VO
*/
public Map<String,List<List<Report>>> fillMapAllVREs(String[] _scopeList)
{
Map<String,List<List<Report>>> vreAllMap = new HashMap<>();
@ -144,6 +206,13 @@ public class VREQueryService implements AutoCloseable{
return vreAllMap;
}
/**
* Method that find a specific VRE name in a VO
* @param _scope
* @param _vo
* @param _vreName
* @return information of the VRE found or null
*/
public VREDescription findVREDescr(String _scope, String _vo, String _vreName)
{
@ -171,6 +240,11 @@ public class VREQueryService implements AutoCloseable{
}
/**
* Method that checks if a VRE is in the CSV file
* @param _vreName VRE name to find
* @return 0= not fount, 1=found
*/
public int isVREinCSVbyName(String _vreName)
{
@ -205,6 +279,12 @@ public class VREQueryService implements AutoCloseable{
* ROM[10] = Description
*/
/**
* Method used to integrate the VRE information contained in the redmine report
* with the information taken from the client (start time, end time, managers, description)
* It store the new information in a new CSV file.
* @param _scope
*/
public void updateCSVformCSVList(String _scope)
{
@ -256,6 +336,12 @@ public class VREQueryService implements AutoCloseable{
* ROW[10] = Description
*/
/**
* Method used to find the missing VRE Disposed in the redmine report across the specified VOs.
* It creates a new CSV file.
* @param _scope
* @param _voList
*/
public void missingVREinCSV(String _scope, String[] _voList)
{
@ -303,6 +389,14 @@ public class VREQueryService implements AutoCloseable{
}
/**
* Method used to retrieve information about a specific VRE of a specific VO
* In prints the main information of the VREs if found.
* @param _scope
* @param _vo VO that contains the VRE to find
* @param _vreName VRE name to find
* @return 0=not found, 1 found
*/
public int getVREInfoFromClient(String _scope, String _vo, String _vreName)
{
try {
@ -332,6 +426,15 @@ public class VREQueryService implements AutoCloseable{
}
/**
* Method used to update the end time of a removed VO on the remote service
* @param _scope
* @param _vo VO that contains the VRE to update
* @param _vreName VRE name to update
* @param _year end_time year
* @param _month end_time month
* @param _day end_time day
*/
public void updateEndTimeVRE(String _scope, String _vo, String _vreName, int _year, int _month, int _day )
{

View File

@ -20,19 +20,22 @@ class CsvUpdateTest {
private String[] listVOs= {"D4Research","gCubeApps","FARM","ParthenosVO","OpenAIRE"};
private String scopeIn = "/d4science.research-infrastructures.eu";
int skipLines = 3;
private String InCsvFile="VREDecommisioned-240326.csv";
private int skipLines = 3;
private String InCsvFileName="VREDecommisioned-240326.csv";
//Used for Google APIs remote update
private String vreSheet = "VREs";
private String missVreSheet="VREs-missing";
private String updateVreSheet = "VREs-extended-info";
//Used for GooGle APis;
String spreadID="1-_24RYwFHG5DuR-rrcmHDSz9pOqVHApBLhXiFLub9JA";
private String spreadID="1-_24RYwFHG5DuR-rrcmHDSz9pOqVHApBLhXiFLub9JA";
private String filePath = "src/test/resources";
@Test
void QueryClientVREInfoTest(){
try(VREQueryService updaterCSV = new VREQueryService(InCsvFile,skipLines)){
try(VREQueryService updaterCSV = new VREQueryService.VQSBuilder().setCSVFiles(filePath,InCsvFileName,skipLines).build())
{
String voIn="D4Research";
String vreName="FoodborneOutbreak";
logger.debug("Checking information about the VRE "+vreName+" in the VO:"+voIn);
@ -46,7 +49,8 @@ class CsvUpdateTest {
@Test
void UpdateLocalCSVTest() {
try(VREQueryService updaterCSV = new VREQueryService(InCsvFile,skipLines)){
try(VREQueryService updaterCSV = new VREQueryService.VQSBuilder().setCSVFiles(filePath,InCsvFileName,skipLines).build())
{
logger.debug("Updating VREs in a LOCAL CSV file");
updaterCSV.updateCSVformCSVList(scopeIn);
logger.debug("Update CSV done");
@ -58,7 +62,8 @@ class CsvUpdateTest {
@Test
void MissingLocalCSVTest(){
try(VREQueryService updaterCSV = new VREQueryService(InCsvFile,skipLines)){
try(VREQueryService updaterCSV = new VREQueryService.VQSBuilder().setCSVFiles(filePath,InCsvFileName,skipLines).build())
{
logger.debug("Getting missing VRE in a LOCAL CSV file");
updaterCSV.missingVREinCSV(scopeIn, listVOs);
logger.debug("Missing CSV done");
@ -72,7 +77,8 @@ class CsvUpdateTest {
@Disabled
@Test
void UpdateEndTimeVRETest(){
try(VREQueryService updaterCSV = new VREQueryService(InCsvFile,skipLines)){
try(VREQueryService updaterCSV = new VREQueryService.VQSBuilder().setCSVFiles(filePath,InCsvFileName,skipLines).build())
{
String voTimeIn="D4Research";
String vreTimeName="FoodborneOutbreak";
int yearIn=2024;
@ -129,7 +135,8 @@ class CsvUpdateTest {
int choice=0;
do {
try (VREQueryService updaterCSV = new VREQueryService(InCsvFile,skipLines)){
try(VREQueryService updaterCSV = new VREQueryService.VQSBuilder().setCSVFiles(filePath,InCsvFileName,skipLines).build())
{
logger.debug("Menu:");
logger.debug("1. Update VREs in a LOCAL CSV file");