Compare commits

..

9 Commits

28 changed files with 450 additions and 51 deletions

0
.classpath Normal file → Executable file
View File

0
.gitignore vendored Normal file → Executable file
View File

0
.project Normal file → Executable file
View File

0
.settings/org.eclipse.core.resources.prefs Normal file → Executable file
View File

0
.settings/org.eclipse.jdt.apt.core.prefs Normal file → Executable file
View File

0
.settings/org.eclipse.jdt.core.prefs Normal file → Executable file
View File

0
.settings/org.eclipse.m2e.core.prefs Normal file → Executable file
View File

0
CHANGELOG.md Normal file → Executable file
View File

0
FUNDING.md Normal file → Executable file
View File

0
LICENSE.md Normal file → Executable file
View File

0
README.md Normal file → Executable file
View File

0
descriptor.xml Normal file → Executable file
View File

7
pom.xml Normal file → Executable file
View File

@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>org.gcube.tools</groupId> <groupId>org.gcube.tools</groupId>
<artifactId>maven-parent</artifactId> <artifactId>maven-parent</artifactId>
<version>1.1.0</version> <version>1.1.0</version>
@ -27,6 +27,11 @@
<dependencies> <dependencies>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-scope-maps</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.sun.xml.bind</groupId> <groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId> <artifactId>jaxb-impl</artifactId>

0
profile.xml Normal file → Executable file
View File

52
src/main/java/org/gcube/vremanagement/App.java Normal file → Executable file
View File

@ -1,15 +1,55 @@
package org.gcube.vremanagement; package org.gcube.vremanagement;
public class App{ import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
public static void main (String[] args) 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 // 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"); //CsvManager csvManager = new CsvManager("/home/biniam/eclipse-workspace/vre-removed-publisher/src/main/resources/updated_VREDecommisioned-240326.csv");
XmlManager xmlManager = new XmlManager("/home/biniam/eclipse-workspace/vre-removed-publisher/src/main/resources/doc.xml"); String filePath = "src/main/resources";
String filename = "doc.xml";
XmlManager xmlManager = new XmlManager(filePath+File.separator+filename);
// Parse CSV and XML files // Parse CSV and XML files
csvManager.parse(); //csvManager.parse();
xmlManager.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
//xmlManager.getGatewaysInfo();
xmlManager.getVosInfo("D4Science.org Detached Gateway");
//xmlManager.findVo("D4Science.org Detached Gateway", "gCubeApps");
xmlManager.findVre("D4Science.org Detached Gateway", "D4OS", "CNROutreach");
} }
} }

5
src/main/java/org/gcube/vremanagement/CsvManager.java Normal file → Executable file
View File

@ -6,6 +6,11 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import com.opencsv.CSVParser;
public class CsvManager implements VreRemPubInterface { public class CsvManager implements VreRemPubInterface {
private String filePath; private String filePath;
private ArrayList<String[]> dataList; private ArrayList<String[]> dataList;

View File

@ -0,0 +1,39 @@
package org.gcube.vremanagement;
import java.util.ArrayList;
public class Gateway {
private String name;
private String description;
private ArrayList<Vos>listOfVos;
public Gateway(String name, String description) {
this.name = name;
this.description = description;
this.listOfVos= new ArrayList<Vos>();
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
// Method to print gateway information
public void printInfo() {
System.out.println("Gateway Name: " + name);
System.out.println("Gateway Description: " + description);
}
public ArrayList<Vos> getVosList() {
// TODO Auto-generated method stub
return listOfVos;
}
// In the Gateway class
public void addVos(Vos vos) {
listOfVos.add(vos);
}
}

View File

@ -0,0 +1,54 @@
package org.gcube.vremanagement;
import java.util.ArrayList;
import java.util.HashMap;
public class Vos {
private String key;
private String name;
private String scope;
private ArrayList<Vres>listOfVres;
public Vos(String key,String scope,String name) {
this.key = key;
this.name = name;
this.scope = scope;
this.listOfVres=new ArrayList<Vres>();
}
public String getKey() {
return key;
}
public String getName() {
return name;
}
public String getScope() {
return scope;
}
// Method to print VO information
public void printInfo() {
System.out.println("VO Key: " + key);
System.out.println("VO Name: " + name);
System.out.println("VO Scope: " + scope);
}
public ArrayList<Vres> getVresList() {
// TODO Auto-generated method stub
return listOfVres;
}
public String getDescription() {
// TODO Auto-generated method stub
return null;
}
public void addVres(Vres vres) {
// TODO Auto-generated method stub
listOfVres.add(vres);
}
}

View File

View File

@ -0,0 +1,67 @@
package org.gcube.vremanagement;
public class Vres {
private String key;
private String name;
private String description;
private String manager;
private String startDate;
private String endDate;
public Vres(String key, String name, String description, String manager, String startDate, String endDate) {
this.key = key;
this.name = name;
this.description = description;
this.manager = manager;
this.startDate = startDate;
this.endDate = endDate;
}
public Vres() {
// TODO Auto-generated constructor stub
}
public String getKey() {
return key;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public String getManager() {
return manager;
}
public String getStartDate() {
return startDate;
}
public String getEndDate() {
return endDate;
}
// Method to print VRE information
public void printInfo() {
System.out.println("VRE Key: " + key);
System.out.println("VRE Name: " + name);
System.out.println("VRE Description: " + description);
System.out.println("VRE Manager: " + manager);
System.out.println("VRE Start Date: " + startDate);
System.out.println("VRE End Date: " + endDate);
}
public String getManagers() {
// TODO Auto-generated method stub
return manager;
}
public String getCatalogUrl() {
// TODO Auto-generated method stub
return null;
}
}

275
src/main/java/org/gcube/vremanagement/XmlManager.java Normal file → Executable file
View File

@ -1,75 +1,264 @@
package org.gcube.vremanagement; package org.gcube.vremanagement;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
public class XmlManager implements VreRemPubInterface { public class XmlManager implements VreRemPubInterface {
private String filePath; private String filePath;
private HashMap<String, Integer> tagCountMap; private HashMap<String, Gateway> gatewaysMap;
public XmlManager(String filePath) { public XmlManager(String filePath) {
this.filePath = filePath; this.filePath = filePath;
System.out.println("XML manager created!"); this.gatewaysMap = new HashMap<>();
this.tagCountMap = new HashMap<>(); }
}
@Override @Override
public void parse() { public void parse() {
try { try {
File xmlFile = new File(filePath); File xmlFile = new File(filePath);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(xmlFile); Document doc = dBuilder.parse(xmlFile);
doc.getDocumentElement().normalize(); doc.getDocumentElement().normalize();
NodeList nodeList = doc.getElementsByTagName("*"); // Get all elements NodeList gatewayNodes = doc.getElementsByTagName("gateways");
for (int i = 0; i < nodeList.getLength(); i++) { NodeList gatewayList = gatewayNodes.item(0).getChildNodes();
Node node = nodeList.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
String tagName = node.getNodeName();
// Update tag count in the HashMap
tagCountMap.put(tagName, tagCountMap.getOrDefault(tagName, 0) + 1);
}
}
System.out.println("XML file parsed successfully.");
// Optionally, print the tag count map here
System.out.println("Tag count map: " + tagCountMap);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override for (int i = 0; i < gatewayList.getLength(); i++) {
public void update() { Node gatewayNode = gatewayList.item(i);
// Implement update logic if needed 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();
// Other methods... //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;
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;
// 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 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();
}
}
}
}
// Add the Vos object to the gateway's vosList
gateway.addVos(vos);
//}
//}
}
}
// Store the gateway object in the gateways map
gatewaysMap.put(gatewayName, gateway);
//computeIfAbsent(gatewayName, k -> new ArrayList<>()).add(gateway);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void getGatewaysInfo() {
System.out.println("Name of the Gateway:");
gatewaysMap.keySet().stream().filter(gatewayName -> gatewayName.endsWith("Gateway"))
.forEach(System.out::println);
}
// Other methods...
@Override
public void update() {
// Implement update logic if needed
}
@Override @Override
public void find() { public void find() {
// TODO Auto-generated method stub // Implement find logic if needed
} }
@Override @Override
public void read() { public void read() {
// TODO Auto-generated method stub // Implement read logic if needed
} }
@Override @Override
public void write() { public void write() {
// TODO Auto-generated method stub // Implement write logic if needed
} }
// Other methods... //public HashMap<String, ArrayList<Gateway>> parseToHashMap() {
// return gatewaysMap;
// }
public void getVosInfo(String _gateway) {
System.out.println("VOs Information for Gateway: " + _gateway);
if (gatewaysMap.containsKey(_gateway)) {
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) {
for (Vos vos : vosList) {
vos.printInfo();
//System.out.println("Name of VREs: ");
//ArrayList<Vres> vresList = vos.getVresList();
//if (vresList != null && !vresList.isEmpty()) {
// for (Vres vre : vresList) {
// vre.printInfo();
// }
//} else {
// System.out.println("No VREs found for this VOS.");
// }
// System.out.println("----------------------------------------");
}
} else {
//System.out.println("No VOS found for this gateway.");
}
} else {
System.out.println("No gateways found with the name: " + _gateway);
}
}
// Method to find a VO within a gateway
public void findVo(String _gateway, String _vo) {
if (gatewaysMap.containsKey(_gateway))
{
Gateway gatewayItem = gatewaysMap.get(_gateway);
boolean found = false;
ArrayList<Vos> vosList = gatewayItem.getVosList();
if (vosList != null) {
for (Vos vos : vosList) {
if (vos.getName().equals(_vo)) {
found = true;
System.out.println("VO info for " + _vo + " in " + _gateway + ":");
System.out.println("Name of VOS: " + vos.getName());
}
}
}
if (!found) {
System.out.println("VO " + _vo + " not found in the gateway " + _gateway + ".");
}
} else {
System.out.println("Gateway " + _gateway + " not found.");
}
}
public void findVre(String _gateway, String _vo, String _vre) {
//System.out.println("VRE Information for VO: " + _vo + " in Gateway:\n " + _gateway);
boolean vreFound = false; // Flag to track if VRE exists
//ArrayList<Gateway> gatewayList = gatewaysMap.get(_gateway);
if (gatewaysMap.containsKey(_gateway)) {
Gateway gatewayItem = gatewaysMap.get(_gateway);
ArrayList<Vos> vosList = gatewayItem.getVosList();
if (vosList != null) {
for (Vos vos : vosList) {
if (vos.getName().equals(_vo)) {
ArrayList<Vres> vresList = vos.getVresList();
if (vresList != null) {
for (Vres vre : vresList) {
if (vre.getName().equals(_vre)) {
// Print VRE information
vre.printInfo();
vreFound = true; // Set flag to true
// return; // Exit method after printing information
}
}
}
}
}
}
}
// If execution reaches here and VRE not found, print message
if (!vreFound) {
System.out.println("VRE does not exist in the " + _vo + " of the " + _gateway);
}
}
// Other methods...
} }

0
src/main/resources/META-INF/maven/archetype.xml Normal file → Executable file
View File

0
src/main/resources/archetype-resources/pom.xml Normal file → Executable file
View File

View File

View File

0
src/main/resources/doc.xml Normal file → Executable file
View File

0
src/main/resources/logback-test.xml Normal file → Executable file
View File

0
src/main/resources/updated_VREDecommisioned-240326.csv Normal file → Executable file
View File

Can't render this file because it has a wrong number of fields in line 2.