fixing parse bug method - needs to be completed

This commit is contained in:
Marco Procaccini 2024-05-14 08:54:39 +02:00
parent 9fab28f37f
commit c1a12d6b5a
2 changed files with 102 additions and 11 deletions

View File

@ -47,9 +47,13 @@ public class App {
}*/
// 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");
//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");
}
}

View File

@ -12,6 +12,7 @@ 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;
@ -34,19 +35,94 @@ public class XmlManager implements VreRemPubInterface {
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(xmlFile);
doc.getDocumentElement().normalize();
NodeList gatewayNodes = doc.getElementsByTagName("gateways");
NodeList gatewayList = doc.getElementsByTagName("gateways");
//NodeList gatewayList = gatewayNodes.item(0).getChildNodes();
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();
for (int i = 0; i < gatewayList.getLength(); i++) {
Node gatewayNode = gatewayList.item(i);
System.out.println("Gate Name"+gatewayName);
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++)
{
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();
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();
for(int xx=0; xx<vreListC.getLength();xx++)
{
Node vreListCE = vreListC.item(xx);
if(vreListCE.getNodeType()==Node.ELEMENT_NODE)
{
Element vreElem = (Element) vreListCE;
String vreName = vreElem.getElementsByTagName("name")
.item(0).getTextContent().trim();
System.out.println("VRE Name:"+vreName);
}
}
}
}
}
}
//getting vo
}
}
//iterate over gateways
if (gatewayNodeT.getNodeType() == Node.ELEMENT_NODE) {
Element gatewayItemE = (Element) gatewayNodeT;
NodeList gatewayListE = gatewayItemE.getElementsByTagName("entry");
for (int i = 0; i < 0; i++) {
Node gatewayNode = gatewayListE.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 name:"+gatewayName);
//System.out.println("Gateway descr:"+gatewayDescription);
Gateway gateway = new Gateway(gatewayName, gatewayDescription);
@ -64,6 +140,7 @@ public class XmlManager implements VreRemPubInterface {
String voName = vosElement.getElementsByTagName("name").item(0).getTextContent().trim();
String voScope = vosElement.getElementsByTagName("scope").item(0).getTextContent().trim();
System.out.println("VO Name:"+voName);
//getting vo
Vos vos = new Vos(voKey,voScope, voName);
@ -114,6 +191,8 @@ public class XmlManager implements VreRemPubInterface {
// 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);
//vres.printInfo();
@ -133,8 +212,14 @@ public class XmlManager implements VreRemPubInterface {
gatewaysMap.put(gatewayName, gateway);
//computeIfAbsent(gatewayName, k -> new ArrayList<>()).add(gateway);
//break;
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
@ -208,8 +293,10 @@ 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 + ":");