Compare commits

...

4 Commits
main ... dev

8 changed files with 246 additions and 196 deletions

View File

@ -19,13 +19,6 @@
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>

View File

@ -62,7 +62,11 @@
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>5.5.2</version>
</dependency>

View File

@ -7,53 +7,34 @@ import java.util.HashMap;
public class App {
public static void main(String[] args) {
// Create here the CSV and XML managers object to parse and sync the XML with the CSV file
//CsvManager csvManager = new CsvManager("/home/biniam/eclipse-workspace/vre-removed-publisher/src/main/resources/updated_VREDecommisioned-240326.csv");
String filePath = "src/main/resources";
String filename = "doc.xml";
XmlManager xmlManager = new XmlManager(filePath+File.separator+filename);
String csvFilePath = "src/main/resources/updated_VREDecommisioned-240326.csv";
String xmlFilePath = "src/main/resources/doc.xml";
// Initialize managers
CsvManager csvManager = new CsvManager(csvFilePath);
XmlManager xmlManager = new XmlManager(xmlFilePath);
// Parse CSV and XML files
//csvManager.parse();
csvManager.parse();
xmlManager.parse();
// Parse XML to HashMap
// HashMap<String, ArrayList<Gateway>> gatewayMap = xmlManager.parseToHashMap();
/*for (String gatewayName: gatewayMap.keySet())
{
ArrayList<Gateway> listGateway = gatewayMap.get(gatewayName);
for (Gateway gate : listGateway)
{
System.out.println("Gateway name: "+gate.getName());
System.out.println("Gateway description: "+gate.getDescription());
ArrayList<Vos> vosList = gate.getVosList();
for (Vos voTemp: vosList)
{
ArrayList<Vres> vreList = voTemp.getVresList();
System.out.println("VO name:" +voTemp.getName());
System.out.println("VO description: "+voTemp.getDescription());
for(Vres vreTemp:vreList)
{
System.out.println("VRE name: "+vreTemp.getName());
System.out.println("Vre description: "+vreTemp.getDescription());
}
}
}
}*/
// methods to query and print information
// Merge CSV data into XML data structure
HashMap<String, ArrayList<Gateway>> mergedMap = mergeData(xmlManager.parseToHashMap(), csvManager.getGatewayMap());
// Write merged data to final XML
xmlManager.writeToXml("finalDoc.xml", mergedMap);
// Methods to query and print information
//xmlManager.getGatewaysInfo();
// xmlManager.getVosInfo("AGINFRAPlus Detached Gateway");
// xmlManager.getVosInfo("PARTHENOS Detached Gateway");
// xmlManager.getVosInfo("BlueBridge Gateway");
// xmlManager.getVosInfo("D4Science.org Detached Gateway");
// xmlManager.getVosInfo("EOSC-Secretariat Detached Gateway");
// xmlManager.findVo("BlueBridge Gateway", "FARM");
xmlManager.findVre("D4Science.org Detached Gateway", "D4OS", "CNROutreach");
//xmlManager.getVosInfo("D4Science.org Detached Gateway");
//xmlManager.findVo("D4Science.org Detached Gateway", "gCubeApps");
//xmlManager.findVre("D4Science.org Detached Gateway", "D4OS", "CNROutreach");
}
private static HashMap<String, ArrayList<Gateway>> mergeData(HashMap<String, ArrayList<Gateway>> xmlData, HashMap<String, ArrayList<Gateway>> csvData) {
// Implement merging logic here
// For simplicity, assume overwrite logic: CSV data overwrites XML data
// You may need to implement more complex merging based on your requirements
return csvData;
}
}

View File

@ -1,65 +1,88 @@
package org.gcube.vremanagement;
import java.io.BufferedReader;
import com.opencsv.CSVReader;
import com.opencsv.exceptions.CsvValidationException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
public class CsvManager {
private String csvFilePath;
private HashMap<String, ArrayList<Gateway>> gatewayMap;
import com.opencsv.CSVParser;
public class CsvManager implements VreRemPubInterface {
private String filePath;
private ArrayList<String[]> dataList;
public CsvManager(String filePath) {
this.filePath = filePath;
System.out.println("CSV manager created!");
this.dataList = new ArrayList<>();
public CsvManager(String csvFilePath) {
this.csvFilePath = csvFilePath;
this.gatewayMap = new HashMap<>();
}
@Override
public void parse() {
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
String line;
while ((line = br.readLine()) != null) {
String[] values = line.split(",");
dataList.add(values);
try (CSVReader reader = new CSVReader(new FileReader(csvFilePath))) {
String[] headers = reader.readNext(); // Read headers (optional, depending on usage)
String[] line;
while ((line = reader.readNext()) != null) {
String vreNames = line[0];
String vo = line[1];
String gateways = line[2];
String startTime = line[3];
String endTime = line[4];
String managers = line[5];
String description = line[6];
// Extract gateway name from URL
String gatewayName = extractGatewayName(gateways);
// Ensure gateway exists in the HashMap
Gateway gateway = gatewayMap.computeIfAbsent(gatewayName, k -> new ArrayList<>()).stream()
.findFirst().orElse(new Gateway(gatewayName, "Description of " + gatewayName + " gateway"));
// Ensure VO exists in the gateway's VOs list
Vos voObject = gateway.getVosList().stream()
.filter(voTemp -> voTemp.getName().equals(vo))
.findFirst().orElse(new Vos("/d4science.research-infrastructures.eu/" + vo, vo));
// Ensure VRE does not already exist (unique VRE names across all VOs and gateways)
boolean vreExists = voObject.getVresList().stream()
.anyMatch(vres -> vres.getName().equals(vreNames));
if (!vreExists) {
Vres vres = new Vres("/d4science.research-infrastructures.eu/" + vo + "/" + vreNames, vreNames);
vres.setDescription(description);
vres.setManagers(new ArrayList<String>() {{
add(managers);
}});
vres.setStartDate(startTime);
vres.setEndDate(endTime);
voObject.getVresList().add(vres);
}
if (!gateway.getVosList().contains(voObject)) {
gateway.getVosList().add(voObject);
}
if (!gatewayMap.containsKey(gatewayName)) {
gatewayMap.put(gatewayName, new ArrayList<Gateway>() {{
add(gateway);
}});
}
}
System.out.println("CSV file parsed successfully.");
// Optionally, print the data here
System.out.println("Parsed CSV data: " + dataList);
} catch (IOException e) {
} catch (IOException | CsvValidationException e) {
e.printStackTrace();
}
}
@Override
public void update() {
// Implement update logic if needed
public HashMap<String, ArrayList<Gateway>> getGatewayMap() {
return gatewayMap;
}
@Override
public void find() {
// TODO Auto-generated method stub
}
@Override
public void read() {
// TODO Auto-generated method stub
}
@Override
public void write() {
// TODO Auto-generated method stub
}
// Other methods...
private String extractGatewayName(String gateways) {
if (gateways.startsWith("https://")) {
return gateways.substring(8, gateways.indexOf("."));
} else if (gateways.startsWith("http://")) {
return gateways.substring(7, gateways.indexOf("."));
} else {
return gateways; // fallback
}
}
}

View File

@ -17,7 +17,12 @@ public class Vos {
}
public String getKey() {
public Vos(String string, String vo) {
// TODO Auto-generated constructor stub
}
public String getKey() {
return key;
}
@ -34,8 +39,17 @@ public class Vos {
System.out.println("VO Key: " + key);
System.out.println("VO Name: " + name);
System.out.println("VO Scope: " + scope);
System.out.println("VRES Names:");
if (!listOfVres.isEmpty()) {
for (Vres vres : listOfVres) {
System.out.println("VRES Name: " + vres.getName());
}
} else {
System.out.println("No VRES found for this VO.");
}
}
public ArrayList<Vres> getVresList() {
// TODO Auto-generated method stub
return listOfVres;

View File

@ -1,5 +1,7 @@
package org.gcube.vremanagement;
import java.util.ArrayList;
public class Vres {
private String key;
private String name;
@ -21,6 +23,10 @@ public class Vres {
// TODO Auto-generated constructor stub
}
public Vres(String string, String vreNames) {
// TODO Auto-generated constructor stub
}
public String getKey() {
return key;
}
@ -64,4 +70,24 @@ public class Vres {
// TODO Auto-generated method stub
return null;
}
public void setDescription(String description2) {
// TODO Auto-generated method stub
}
public void setManagers(ArrayList<String> arrayList) {
// TODO Auto-generated method stub
}
public void setStartDate(String startTime) {
// TODO Auto-generated method stub
}
public void setEndDate(String endTime) {
// TODO Auto-generated method stub
}
}

View File

@ -12,7 +12,6 @@ import java.util.stream.Collectors;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.commons.collections.bag.SynchronizedSortedBag;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@ -35,101 +34,107 @@ public class XmlManager implements VreRemPubInterface {
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(xmlFile);
doc.getDocumentElement().normalize();
NodeList gatewayList = doc.getElementsByTagName("gateways");
//NodeList gatewayList = gatewayNodes.item(0).getChildNodes();
NodeList gatewayNodes = doc.getElementsByTagName("gateways");
NodeList gatewayList = gatewayNodes.item(0).getChildNodes();
//iterate over gateways child
for(int k =0; k<gatewayList.getLength(); k++)
{
Node gatewayNodeT = gatewayList.item(k);
NodeList gatewayNodeTC = gatewayList.item(k).getChildNodes();
for(int kk=0; kk<gatewayNodeTC.getLength(); kk++)
{
Node gateTest = gatewayNodeTC.item(kk);
if(gateTest.getNodeType() == Node.ELEMENT_NODE)
{
Element gateTestElem = (Element)gateTest;
String gatewayName = gateTestElem.getElementsByTagName("name").item(0).getTextContent().trim();
String gatewayDescription = gateTestElem.getElementsByTagName("description").item(0)
.getTextContent().trim();
//System.out.println("Gate Name"+gatewayName);
Gateway gateway = new Gateway(gatewayName, gatewayDescription);
NodeList vosListT = gateTestElem.getElementsByTagName("vos");
for (int j = 0; j < vosListT.getLength(); j++) {
NodeList vosListC = vosListT.item(j).getChildNodes();
for (int jj=0; jj < vosListC.getLength();jj++)
{
for (int i = 0; i < gatewayList.getLength(); i++) {
Node gatewayNode = gatewayList.item(i);
if (gatewayNode.getNodeType() == Node.ELEMENT_NODE) {
Element gatewayElement = (Element) gatewayNode;
String gatewayName = gatewayElement.getElementsByTagName("name").item(0).getTextContent().trim();
String gatewayDescription = gatewayElement.getElementsByTagName("description").item(0)
.getTextContent().trim();
//System.out.println("gateway name:"+gatewayName);
//System.out.println("Gateway descr:"+gatewayDescription);
Gateway gateway = new Gateway(gatewayName, gatewayDescription);
// Find the <vos> element within the gateway entry
NodeList vosList = gatewayElement.getElementsByTagName("vos");
for (int j = 0; j < vosList.getLength(); j++) {
Node vosNode = vosList.item(j);
if (vosNode.getNodeType() == Node.ELEMENT_NODE) {
Element vosElement = (Element) vosNode;
Node vosListCE = vosListC.item(jj);
if (vosListCE.getNodeType() == Node.ELEMENT_NODE) {
Element vosElement = (Element) vosListCE;
String voKey = vosElement.getElementsByTagName("key").item(0).getTextContent().trim();
String voName = vosElement.getElementsByTagName("name").item(0).getTextContent().trim();
String voScope = vosElement.getElementsByTagName("scope").item(0).getTextContent().trim();
Vos vos = new Vos(voKey,voScope, voName);
//System.out.println("VO Name:"+voName);
NodeList vreListT = vosElement.getElementsByTagName("vres");
for (int x=0; x<vreListT.getLength();x++)
{
NodeList vreListC = vreListT.item(x).getChildNodes();
String voKey = vosElement.getElementsByTagName("key").item(0).getTextContent().trim();
String voName = vosElement.getElementsByTagName("name").item(0).getTextContent().trim();
String voScope = vosElement.getElementsByTagName("scope").item(0).getTextContent().trim();
//getting vo
Vos vos = new Vos(voKey,voScope, voName);
//vos.printInfo();
// Iterate on the vres..
//NodeList vreList = vosElement.getElementsByTagName("vres");
//
//for (int k = 0; k < vreList.getLength(); k++) {
// Node voNode = voList.item(k);
// if (voNode.getNodeType() == Node.ELEMENT_NODE) {
// Element voElement = (Element) voNode;
for(int xx=0; xx<vreListC.getLength();xx++)
{
Node vreListCE = vreListC.item(xx);
if(vreListCE.getNodeType()==Node.ELEMENT_NODE)
{
Element vreEntryElement = (Element) vreListCE;
String vreKey = vreEntryElement.getElementsByTagName("key").item(0)
.getTextContent().trim();
String vreName = vreEntryElement.getElementsByTagName("name")
.item(0).getTextContent().trim();
String vreDescription = vreEntryElement
.getElementsByTagName("description").item(0)
.getTextContent().trim();
String vreManager = vreEntryElement.getElementsByTagName("managers")
.item(0).getTextContent().trim();
String vreStartDate = vreEntryElement
.getElementsByTagName("startdate").item(0).getTextContent().trim();
String vreEndDate = vreEntryElement.getElementsByTagName("enddate")
.item(0).getTextContent().trim();
// String voName = voElement.getElementsByTagName("name").item(0).getTextContent().trim();
// String voScope = voElement.getElementsByTagName("scope").item(0).getTextContent().trim();
// String voKey = voElement.getElementsByTagName("key").item(0).getTextContent().trim();
// Create a new Vres object and add it to the Vos's vreList
Vres vres = new Vres(vreKey, vreName, vreDescription, vreManager,
vreStartDate, vreEndDate);
//System.out.println("VRE Name:"+vreName);
vos.addVres(vres);
// Create a new Vos object and add it to the gateway's vosList
// Vos vos = new Vos(voKey, voScope, voName);
// Find the <vres> element within the VO entry
NodeList vresList = vosElement.getElementsByTagName("vres");
for (int l = 0; l < vresList.getLength(); l++) {
Node vresNode = vresList.item(l);
if (vresNode.getNodeType() == Node.ELEMENT_NODE) {
Element vresElement = (Element) vresNode;
// Iterate through <entry> elements representing VREs within <vres>
NodeList vreEntryList = vresElement.getElementsByTagName("entry");
for (int m = 0; m < vreEntryList.getLength(); m++) {
Node vreEntryNode = vreEntryList.item(m);
if (vreEntryNode.getNodeType() == Node.ELEMENT_NODE) {
Element vreEntryElement = (Element) vreEntryNode;
String vreKey = vreEntryElement.getElementsByTagName("key").item(0)
.getTextContent().trim();
String vreName = vreEntryElement.getElementsByTagName("name")
.item(0).getTextContent().trim();
String vreDescription = vreEntryElement
.getElementsByTagName("description").item(0)
.getTextContent().trim();
String vreManager = vreEntryElement.getElementsByTagName("managers")
.item(0).getTextContent().trim();
String vreStartDate = vreEntryElement
.getElementsByTagName("startdate").item(0).getTextContent().trim();
String vreEndDate = vreEntryElement.getElementsByTagName("enddate")
.item(0).getTextContent().trim();
// Create a new Vres object and add it to the Vos's vreList
Vres vres = new Vres(vreKey, vreName, vreDescription, vreManager,
vreStartDate, vreEndDate);
vos.addVres(vres);
//vres.printInfo();
}
}
}
}
}
gateway.addVos(vos);
}
}
// Add the Vos object to the gateway's vosList
gateway.addVos(vos);
//}
//}
}
gatewaysMap.put(gatewayName, gateway);
//getting vo
}
// Store the gateway object in the gateways map
gatewaysMap.put(gatewayName, gateway);
//computeIfAbsent(gatewayName, k -> new ArrayList<>()).add(gateway);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
@ -173,10 +178,7 @@ public class XmlManager implements VreRemPubInterface {
Gateway gatewayItem = gatewaysMap.get(_gateway);
//Gateway gateway = gatewayList.get(0); // Get the first gateway with the specified name
ArrayList<Vos> vosList = gatewayItem.getVosList();
if (vosList != null) {
System.out.println("Num of VOs:"+vosList.size());
for (Vos vos : vosList) {
vos.printInfo();
//System.out.println("Name of VREs: ");
@ -191,7 +193,7 @@ public class XmlManager implements VreRemPubInterface {
// System.out.println("----------------------------------------");
}
} else {
System.out.println("No VOS found for this gateway.");
//System.out.println("No VOS found for this gateway.");
}
} else {
System.out.println("No gateways found with the name: " + _gateway);
@ -206,10 +208,8 @@ public class XmlManager implements VreRemPubInterface {
Gateway gatewayItem = gatewaysMap.get(_gateway);
boolean found = false;
ArrayList<Vos> vosList = gatewayItem.getVosList();
System.out.println("VO LIST length:"+ vosList.size());
if (vosList != null) {
for (Vos vos : vosList) {
System.out.println("VO: "+vos.getName());
if (vos.getName().equals(_vo)) {
found = true;
System.out.println("VO info for " + _vo + " in " + _gateway + ":");
@ -259,6 +259,16 @@ public class XmlManager implements VreRemPubInterface {
}
}
public HashMap<String, ArrayList<Gateway>> parseToHashMap() {
// TODO Auto-generated method stub
return null;
}
public void writeToXml(String string, HashMap<String, ArrayList<Gateway>> mergedMap) {
// TODO Auto-generated method stub
}
// Other methods...
}

View File

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<genericResources>
<?xml version="1.0" encoding="UTF-8" standalone="no"?><genericResources>
<Resource version="0.4.x">
<ID>68322b8f-b916-44b9-9c93-bad8cceb9106</ID>
<Type>GenericResource</Type>
@ -1091,7 +1090,7 @@
</vos>
</value>
</entry>
</gateways>
</gateways>
</detachedres>
</Body>
</Profile>