Compare commits
10 Commits
Feature/27
...
main
Author | SHA1 | Date |
---|---|---|
Biniam Abraha Masa | 0f68f57f71 | |
Biniam Abraha Masa | d00dc3d552 | |
Biniam Abraha Masa | 28862e6cf4 | |
Marco Procaccini | ac9f9219bd | |
Biniam Abraha Masa | 9a28194ef9 | |
Biniam Abraha Masa | f0eda78d17 | |
Biniam Abraha Masa | 835e4e8b9a | |
Biniam Abraha Masa | 7939e029e7 | |
Marco Procaccini | 964bd95c52 | |
Marco Procaccini | c1a12d6b5a |
13
.classpath
13
.classpath
|
@ -14,20 +14,8 @@
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="optional" value="true"/>
|
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
|
||||||
<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="test" value="true"/>
|
||||||
<attribute name="optional" 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"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
|
@ -36,5 +24,6 @@
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
eclipse.preferences.version=1
|
|
||||||
encoding//src/main/java=UTF-8
|
|
||||||
encoding//src/main/resources=UTF-8
|
|
||||||
encoding/<project>=UTF-8
|
|
|
@ -1,9 +1,17 @@
|
||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
org.eclipse.jdt.core.compiler.processAnnotations=disabled
|
org.eclipse.jdt.core.compiler.processAnnotations=disabled
|
||||||
org.eclipse.jdt.core.compiler.release=disabled
|
org.eclipse.jdt.core.compiler.release=disabled
|
||||||
org.eclipse.jdt.core.compiler.source=1.8
|
org.eclipse.jdt.core.compiler.source=1.8
|
||||||
|
|
|
@ -4,4 +4,3 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||||
|
|
||||||
## [v1.0.0-SNAPSHOT]
|
## [v1.0.0-SNAPSHOT]
|
||||||
- First commit with project structure
|
- First commit with project structure
|
||||||
- Branch Feature-27440
|
|
18
pom.xml
18
pom.xml
|
@ -3,12 +3,6 @@
|
||||||
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>
|
|
||||||
<groupId>org.gcube.tools</groupId>
|
|
||||||
<artifactId>maven-parent</artifactId>
|
|
||||||
<version>1.1.0</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<groupId>org.gcube.vremanagement</groupId>
|
<groupId>org.gcube.vremanagement</groupId>
|
||||||
<artifactId>vre-removed-publisher</artifactId>
|
<artifactId>vre-removed-publisher</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
@ -27,6 +21,12 @@
|
||||||
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||||
|
<artifactId>jackson-dataformat-xml</artifactId>
|
||||||
|
<version>2.13.3</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.core</groupId>
|
<groupId>org.gcube.core</groupId>
|
||||||
<artifactId>common-scope-maps</artifactId>
|
<artifactId>common-scope-maps</artifactId>
|
||||||
|
@ -62,7 +62,11 @@
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.opencsv</groupId>
|
||||||
|
<artifactId>opencsv</artifactId>
|
||||||
|
<version>5.5.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,53 +3,86 @@ package org.gcube.vremanagement;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// Create here the CSV and XML managers object to parse and sync the XML with the CSV file
|
try {
|
||||||
//CsvManager csvManager = new CsvManager("/home/biniam/eclipse-workspace/vre-removed-publisher/src/main/resources/updated_VREDecommisioned-240326.csv");
|
String csvFilePath = "src/main/resources/updated_VREDecommisioned-240326.csv";
|
||||||
String filePath = "src/main/resources";
|
String xmlFilePath = "src/main/resources/doc.xml";
|
||||||
String filename = "doc.xml";
|
|
||||||
XmlManager xmlManager = new XmlManager(filePath+File.separator+filename);
|
|
||||||
|
|
||||||
// Parse CSV and XML files
|
|
||||||
//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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
// Initialize managers
|
||||||
|
CsvManager csvManager = new CsvManager(csvFilePath);
|
||||||
|
XmlManager xmlManager = new XmlManager(xmlFilePath);
|
||||||
|
|
||||||
|
// Parse CSV and XML files
|
||||||
|
HashMap<String, Gateway> xmlMap = xmlManager.parse();
|
||||||
|
HashMap<String, Gateway> csvMap = csvManager.parseCsvToMap(csvFilePath);
|
||||||
|
putAll(xmlMap,csvMap);
|
||||||
|
|
||||||
|
|
||||||
}*/
|
//Merging csvMap into the xmlMap
|
||||||
// methods to query and print information
|
//Note that: in case of duplicate elements, the csvMap elements will overwrite the xmlMap
|
||||||
//xmlManager.getGatewaysInfo();
|
//this is ok for us because the csv elements are mode recent than xml element
|
||||||
xmlManager.getVosInfo("D4Science.org Detached Gateway");
|
//check this behaviour in the final xml doc
|
||||||
//xmlManager.findVo("D4Science.org Detached Gateway", "gCubeApps");
|
|
||||||
xmlManager.findVre("D4Science.org Detached Gateway", "D4OS", "CNROutreach");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
xmlManager.writeXml(xmlMap, "finalDoc.xml");
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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");
|
||||||
|
}
|
||||||
|
|
||||||
|
//This method checks duplicates and merge
|
||||||
|
public static void putAll(HashMap<String, Gateway> xmlMap, HashMap<String, Gateway> csvMap) {
|
||||||
|
for (String csvKey : csvMap.keySet()) {
|
||||||
|
Gateway csvGateway = csvMap.get(csvKey);
|
||||||
|
|
||||||
|
// Normalize the CSV gateway name
|
||||||
|
String csvGatewayNameNormalized = csvGateway.getName().toLowerCase();
|
||||||
|
XmlManager xmlManager = new XmlManager();
|
||||||
|
String csvgatewayName = xmlManager.extractGatewayName(csvGatewayNameNormalized);
|
||||||
|
// Check for duplicates by gateway name (case insensitive)
|
||||||
|
boolean foundDuplicate = false;
|
||||||
|
for (String xmlKey : xmlMap.keySet()) {
|
||||||
|
Gateway xmlGateway = xmlMap.get(xmlKey);
|
||||||
|
String xmlGatewayNameNormalized = xmlGateway.getName().toLowerCase();
|
||||||
|
|
||||||
|
if (xmlGatewayNameNormalized.equalsIgnoreCase(csvgatewayName)) {
|
||||||
|
// Merge VOs and VREs
|
||||||
|
for (Vos csvVos : csvGateway.getVosList()) {
|
||||||
|
Vos xmlVos = xmlGateway.getVosByName(csvVos.getName());
|
||||||
|
if (xmlVos != null) {
|
||||||
|
for (Vres csvVres : csvVos.getVresList()) {
|
||||||
|
if (xmlVos.getVresByName(csvVres.getName()) == null) {
|
||||||
|
xmlVos.addVres(csvVres);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
xmlGateway.addVos(csvVos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foundDuplicate = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no duplicate found, add the CSV gateway to the XML map
|
||||||
|
if (!foundDuplicate) {
|
||||||
|
xmlMap.put(csvKey, csvGateway);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,65 +1,77 @@
|
||||||
package org.gcube.vremanagement;
|
package org.gcube.vremanagement;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.util.HashMap;
|
||||||
import java.util.ArrayList;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.opencsv.CSVReader;
|
||||||
|
import com.opencsv.CSVReaderBuilder;
|
||||||
|
|
||||||
|
public class CsvManager {
|
||||||
|
private String csvFilePath;
|
||||||
|
private HashMap<String, Gateway> gatewayMap;
|
||||||
|
|
||||||
|
public CsvManager(String csvFilePath) {
|
||||||
import com.opencsv.CSVParser;
|
this.csvFilePath = csvFilePath;
|
||||||
|
this.gatewayMap = new HashMap<>();
|
||||||
|
|
||||||
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<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
@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);
|
|
||||||
}
|
|
||||||
System.out.println("CSV file parsed successfully.");
|
|
||||||
// Optionally, print the data here
|
|
||||||
System.out.println("Parsed CSV data: " + dataList);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update() {
|
|
||||||
// Implement update logic if needed
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void find() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void read() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
|
public HashMap<String, Gateway> parseCsvToMap(String csvFilePath) {
|
||||||
|
HashMap<String, Gateway> csvMap = new HashMap<>();
|
||||||
|
try {
|
||||||
|
FileReader filereader = new FileReader(csvFilePath);
|
||||||
|
CSVReader csvReader = new CSVReaderBuilder(filereader).withSkipLines(1).build();
|
||||||
|
|
||||||
|
List<String[]> allData = csvReader.readAll();
|
||||||
|
|
||||||
|
for (String[] row : allData) {
|
||||||
|
XmlManager xmlManager = new XmlManager();
|
||||||
|
String gatewayName = row[5];
|
||||||
|
String csvgatewayName = xmlManager.extractGatewayName(gatewayName)+ " Gateway";
|
||||||
|
String description = row[10];
|
||||||
|
String voName = row[4];
|
||||||
|
String vreName = row[3];
|
||||||
|
String manager = row[9];
|
||||||
|
String startDate = row[7];
|
||||||
|
String endDate = row[8];
|
||||||
|
|
||||||
|
|
||||||
|
Gateway gateway = csvMap.getOrDefault(csvgatewayName.toLowerCase(), new Gateway(csvgatewayName, description));
|
||||||
|
Vos vos = gateway.getVosByName(voName);
|
||||||
|
if (vos == null) {
|
||||||
|
vos = new Vos(voName, voName, voName);
|
||||||
|
gateway.addVos(vos);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vres vres = vos.getVresByName(vreName);
|
||||||
|
if (vres == null) {
|
||||||
|
vres = new Vres(vreName, vreName, description, manager, startDate, endDate);
|
||||||
|
vos.addVres(vres);
|
||||||
|
}
|
||||||
|
|
||||||
|
csvMap.put(csvgatewayName.toLowerCase(), gateway);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
csvReader.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return csvMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private String extractGatewayName(String gateways) {
|
||||||
public void write() {
|
if (gateways.startsWith("https://")) {
|
||||||
// TODO Auto-generated method stub
|
return gateways.substring(8, gateways.indexOf("."));
|
||||||
|
} else if (gateways.startsWith("http://")) {
|
||||||
|
return gateways.substring(7, gateways.indexOf("."));
|
||||||
|
} else {
|
||||||
|
return gateways; // fallback
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Other methods...
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,28 +3,28 @@ package org.gcube.vremanagement;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class Gateway {
|
public class Gateway {
|
||||||
private String name;
|
private String name;
|
||||||
private String description;
|
private String description;
|
||||||
private ArrayList<Vos>listOfVos;
|
private ArrayList<Vos>listOfVos;
|
||||||
public Gateway(String name, String description) {
|
public Gateway(String name, String description) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.listOfVos= new ArrayList<Vos>();
|
this.listOfVos= new ArrayList<Vos>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method to print gateway information
|
// Method to print gateway information
|
||||||
public void printInfo() {
|
public void printInfo() {
|
||||||
System.out.println("Gateway Name: " + name);
|
System.out.println("Gateway Name: " + name);
|
||||||
System.out.println("Gateway Description: " + description);
|
System.out.println("Gateway Description: " + description);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Vos> getVosList() {
|
public ArrayList<Vos> getVosList() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
@ -33,7 +33,14 @@ public class Gateway {
|
||||||
|
|
||||||
// In the Gateway class
|
// In the Gateway class
|
||||||
public void addVos(Vos vos) {
|
public void addVos(Vos vos) {
|
||||||
listOfVos.add(vos);
|
listOfVos.add(vos);
|
||||||
|
}
|
||||||
|
public Vos getVosByName(String name) {
|
||||||
|
for (Vos vos : listOfVos) {
|
||||||
|
if (vos.getName().equals(name)) {
|
||||||
|
return vos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,37 +4,51 @@ import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class Vos {
|
public class Vos {
|
||||||
private String key;
|
private String key;
|
||||||
private String name;
|
private String name;
|
||||||
private String scope;
|
private String scope;
|
||||||
private ArrayList<Vres>listOfVres;
|
private ArrayList<Vres>listOfVres;
|
||||||
public Vos(String key,String scope,String name) {
|
public Vos(String key,String scope,String name) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.scope = scope;
|
this.scope = scope;
|
||||||
this.listOfVres=new ArrayList<Vres>();
|
this.listOfVres=new ArrayList<Vres>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getKey() {
|
public Vos(String string, String vo) {
|
||||||
return key;
|
// TODO Auto-generated constructor stub
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getScope() {
|
public String getKey() {
|
||||||
return scope;
|
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);
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 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() {
|
public ArrayList<Vres> getVresList() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
@ -50,5 +64,12 @@ public class Vos {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
listOfVres.add(vres);
|
listOfVres.add(vres);
|
||||||
}
|
}
|
||||||
|
public Vres getVresByName(String name) {
|
||||||
|
for (Vres vres : listOfVres) {
|
||||||
|
if (vres.getName().equals(name)) {
|
||||||
|
return vres;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package org.gcube.vremanagement;
|
package org.gcube.vremanagement;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public interface VreRemPubInterface {
|
public interface VreRemPubInterface {
|
||||||
|
|
||||||
void parse(); //method used to parse the file (e.g., xml or csv) in a data structure
|
HashMap<String, Gateway> parse(); //method used to parse the file (e.g., xml or csv) in a data structure
|
||||||
void update(); //method used to update the file (e.g., xml or csv)
|
void update(); //method used to update the file (e.g., xml or csv)
|
||||||
//add here other common methods needed by both Csv and Xml Manager
|
//add here other common methods needed by both Csv and Xml Manager
|
||||||
void find();
|
void find();
|
||||||
|
|
|
@ -1,59 +1,65 @@
|
||||||
package org.gcube.vremanagement;
|
package org.gcube.vremanagement;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class Vres {
|
public class Vres {
|
||||||
private String key;
|
private String key;
|
||||||
private String name;
|
private String name;
|
||||||
private String description;
|
private String description;
|
||||||
private String manager;
|
private String manager;
|
||||||
private String startDate;
|
private String startDate;
|
||||||
private String endDate;
|
private String endDate;
|
||||||
|
|
||||||
public Vres(String key, String name, String description, String manager, String startDate, String endDate) {
|
public Vres(String key, String name, String description, String manager, String startDate, String endDate) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
this.startDate = startDate;
|
this.startDate = startDate;
|
||||||
this.endDate = endDate;
|
this.endDate = endDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vres() {
|
public Vres() {
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vres(String string, String vreNames) {
|
||||||
// TODO Auto-generated constructor stub
|
// TODO Auto-generated constructor stub
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getManager() {
|
public String getManager() {
|
||||||
return manager;
|
return manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStartDate() {
|
public String getStartDate() {
|
||||||
return startDate;
|
return startDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEndDate() {
|
public String getEndDate() {
|
||||||
return endDate;
|
return endDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method to print VRE information
|
// Method to print VRE information
|
||||||
public void printInfo() {
|
public void printInfo() {
|
||||||
System.out.println("VRE Key: " + key);
|
System.out.println("VRE Key: " + key);
|
||||||
System.out.println("VRE Name: " + name);
|
System.out.println("VRE Name: " + name);
|
||||||
System.out.println("VRE Description: " + description);
|
System.out.println("VRE Description: " + description);
|
||||||
System.out.println("VRE Manager: " + manager);
|
System.out.println("VRE Manager: " + manager);
|
||||||
System.out.println("VRE Start Date: " + startDate);
|
System.out.println("VRE Start Date: " + startDate);
|
||||||
System.out.println("VRE End Date: " + endDate);
|
System.out.println("VRE End Date: " + endDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getManagers() {
|
public String getManagers() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
@ -64,4 +70,25 @@ public class Vres {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
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
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.gcube.vremanagement;
|
package org.gcube.vremanagement;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -11,12 +12,20 @@ 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 javax.xml.transform.OutputKeys;
|
||||||
|
import javax.xml.transform.Transformer;
|
||||||
|
import javax.xml.transform.TransformerFactory;
|
||||||
|
import javax.xml.transform.dom.DOMSource;
|
||||||
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||||
|
|
||||||
public class XmlManager implements VreRemPubInterface {
|
public class XmlManager implements VreRemPubInterface {
|
||||||
private String filePath;
|
private String filePath;
|
||||||
private HashMap<String, Gateway> gatewaysMap;
|
private HashMap<String, Gateway> gatewaysMap;
|
||||||
|
@ -26,8 +35,12 @@ public class XmlManager implements VreRemPubInterface {
|
||||||
this.gatewaysMap = new HashMap<>();
|
this.gatewaysMap = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public XmlManager() {
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void parse() {
|
public HashMap<String, Gateway> parse() {
|
||||||
try {
|
try {
|
||||||
File xmlFile = new File(filePath);
|
File xmlFile = new File(filePath);
|
||||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||||
|
@ -46,8 +59,6 @@ public class XmlManager implements VreRemPubInterface {
|
||||||
String gatewayDescription = gatewayElement.getElementsByTagName("description").item(0)
|
String gatewayDescription = gatewayElement.getElementsByTagName("description").item(0)
|
||||||
.getTextContent().trim();
|
.getTextContent().trim();
|
||||||
|
|
||||||
//System.out.println("gateway name:"+gatewayName);
|
|
||||||
//System.out.println("Gateway descr:"+gatewayDescription);
|
|
||||||
Gateway gateway = new Gateway(gatewayName, gatewayDescription);
|
Gateway gateway = new Gateway(gatewayName, gatewayDescription);
|
||||||
|
|
||||||
// Find the <vos> element within the gateway entry
|
// Find the <vos> element within the gateway entry
|
||||||
|
@ -67,64 +78,47 @@ public class XmlManager implements VreRemPubInterface {
|
||||||
//getting vo
|
//getting vo
|
||||||
Vos vos = new Vos(voKey,voScope, voName);
|
Vos vos = new Vos(voKey,voScope, voName);
|
||||||
|
|
||||||
//vos.printInfo();
|
|
||||||
|
|
||||||
// Iterate on the vres..
|
// Find the <vres> element within the VO entry
|
||||||
//NodeList vreList = vosElement.getElementsByTagName("vres");
|
NodeList vresList = vosElement.getElementsByTagName("vres");
|
||||||
//
|
for (int l = 0; l < vresList.getLength(); l++) {
|
||||||
//for (int k = 0; k < vreList.getLength(); k++) {
|
Node vresNode = vresList.item(l);
|
||||||
// Node voNode = voList.item(k);
|
if (vresNode.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
// if (voNode.getNodeType() == Node.ELEMENT_NODE) {
|
Element vresElement = (Element) vresNode;
|
||||||
// Element voElement = (Element) voNode;
|
// 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);
|
||||||
|
|
||||||
|
|
||||||
// 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
|
// Add the Vos object to the gateway's vosList
|
||||||
gateway.addVos(vos);
|
gateway.addVos(vos);
|
||||||
//}
|
//}
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,14 +129,16 @@ public class XmlManager implements VreRemPubInterface {
|
||||||
//computeIfAbsent(gatewayName, k -> new ArrayList<>()).add(gateway);
|
//computeIfAbsent(gatewayName, k -> new ArrayList<>()).add(gateway);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return gatewaysMap;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
public void getGatewaysInfo() {
|
public void getGatewaysInfo() {
|
||||||
System.out.println("Name of the Gateway:");
|
System.out.println("Name of the Gateway:");
|
||||||
gatewaysMap.keySet().stream().filter(gatewayName -> gatewayName.endsWith("Gateway"))
|
gatewaysMap.keySet().stream().filter(gatewayName -> gatewayName.endsWith("Gateway"))
|
||||||
.forEach(System.out::println);
|
.forEach(System.out::println);
|
||||||
}
|
}
|
||||||
// Other methods...
|
// Other methods...
|
||||||
|
|
||||||
|
@ -166,9 +162,6 @@ public class XmlManager implements VreRemPubInterface {
|
||||||
// Implement write logic if needed
|
// Implement write logic if needed
|
||||||
}
|
}
|
||||||
|
|
||||||
//public HashMap<String, ArrayList<Gateway>> parseToHashMap() {
|
|
||||||
// return gatewaysMap;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
public void getVosInfo(String _gateway) {
|
public void getVosInfo(String _gateway) {
|
||||||
|
@ -180,7 +173,7 @@ public class XmlManager implements VreRemPubInterface {
|
||||||
ArrayList<Vos> vosList = gatewayItem.getVosList();
|
ArrayList<Vos> vosList = gatewayItem.getVosList();
|
||||||
if (vosList != null) {
|
if (vosList != null) {
|
||||||
for (Vos vos : vosList) {
|
for (Vos vos : vosList) {
|
||||||
vos.printInfo();
|
vos.printInfo();
|
||||||
//System.out.println("Name of VREs: ");
|
//System.out.println("Name of VREs: ");
|
||||||
//ArrayList<Vres> vresList = vos.getVresList();
|
//ArrayList<Vres> vresList = vos.getVresList();
|
||||||
//if (vresList != null && !vresList.isEmpty()) {
|
//if (vresList != null && !vresList.isEmpty()) {
|
||||||
|
@ -188,9 +181,9 @@ public class XmlManager implements VreRemPubInterface {
|
||||||
// vre.printInfo();
|
// vre.printInfo();
|
||||||
// }
|
// }
|
||||||
//} else {
|
//} else {
|
||||||
// System.out.println("No VREs found for this VOS.");
|
// System.out.println("No VREs found for this VOS.");
|
||||||
// }
|
// }
|
||||||
// System.out.println("----------------------------------------");
|
// System.out.println("----------------------------------------");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//System.out.println("No VOS found for this gateway.");
|
//System.out.println("No VOS found for this gateway.");
|
||||||
|
@ -207,14 +200,14 @@ public class XmlManager implements VreRemPubInterface {
|
||||||
{
|
{
|
||||||
Gateway gatewayItem = gatewaysMap.get(_gateway);
|
Gateway gatewayItem = gatewaysMap.get(_gateway);
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
ArrayList<Vos> vosList = gatewayItem.getVosList();
|
ArrayList<Vos> vosList = gatewayItem.getVosList();
|
||||||
if (vosList != null) {
|
if (vosList != null) {
|
||||||
for (Vos vos : vosList) {
|
for (Vos vos : vosList) {
|
||||||
if (vos.getName().equals(_vo)) {
|
if (vos.getName().equals(_vo)) {
|
||||||
found = true;
|
found = true;
|
||||||
System.out.println("VO info for " + _vo + " in " + _gateway + ":");
|
System.out.println("VO info for " + _vo + " in " + _gateway + ":");
|
||||||
System.out.println("Name of VOS: " + vos.getName());
|
System.out.println("Name of VOS: " + vos.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -227,38 +220,239 @@ public class XmlManager implements VreRemPubInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void findVre(String _gateway, String _vo, String _vre) {
|
public void findVre(String _gateway, String _vo, String _vre) {
|
||||||
//System.out.println("VRE Information for VO: " + _vo + " in Gateway:\n " + _gateway);
|
//System.out.println("VRE Information for VO: " + _vo + " in Gateway:\n " + _gateway);
|
||||||
boolean vreFound = false; // Flag to track if VRE exists
|
boolean vreFound = false; // Flag to track if VRE exists
|
||||||
//ArrayList<Gateway> gatewayList = gatewaysMap.get(_gateway);
|
//ArrayList<Gateway> gatewayList = gatewaysMap.get(_gateway);
|
||||||
|
|
||||||
if (gatewaysMap.containsKey(_gateway)) {
|
if (gatewaysMap.containsKey(_gateway)) {
|
||||||
|
|
||||||
Gateway gatewayItem = gatewaysMap.get(_gateway);
|
Gateway gatewayItem = gatewaysMap.get(_gateway);
|
||||||
ArrayList<Vos> vosList = gatewayItem.getVosList();
|
ArrayList<Vos> vosList = gatewayItem.getVosList();
|
||||||
if (vosList != null) {
|
if (vosList != null) {
|
||||||
for (Vos vos : vosList) {
|
for (Vos vos : vosList) {
|
||||||
if (vos.getName().equals(_vo)) {
|
if (vos.getName().equals(_vo)) {
|
||||||
ArrayList<Vres> vresList = vos.getVresList();
|
ArrayList<Vres> vresList = vos.getVresList();
|
||||||
if (vresList != null) {
|
if (vresList != null) {
|
||||||
for (Vres vre : vresList) {
|
for (Vres vre : vresList) {
|
||||||
if (vre.getName().equals(_vre)) {
|
if (vre.getName().equals(_vre)) {
|
||||||
// Print VRE information
|
// Print VRE information
|
||||||
vre.printInfo();
|
vre.printInfo();
|
||||||
vreFound = true; // Set flag to true
|
vreFound = true; // Set flag to true
|
||||||
// return; // Exit method after printing information
|
// return; // Exit method after printing information
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If execution reaches here and VRE not found, print message
|
// If execution reaches here and VRE not found, print message
|
||||||
if (!vreFound) {
|
if (!vreFound) {
|
||||||
System.out.println("VRE does not exist in the " + _vo + " of the " + _gateway);
|
System.out.println("VRE does not exist in the " + _vo + " of the " + _gateway);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HashMap<String, ArrayList<Gateway>> parseToHashMap() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public void writeXml(HashMap<String, Gateway> map, String outputXmlFilePath) throws Exception {
|
||||||
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
|
Document document = builder.newDocument();
|
||||||
|
|
||||||
|
// Create root element <genericResources>
|
||||||
|
Element genericResourcesElement = document.createElement("genericResources");
|
||||||
|
document.appendChild(genericResourcesElement);
|
||||||
|
|
||||||
|
// Create <Resource> element with version attribute
|
||||||
|
Element resourceElement = document.createElement("Resource");
|
||||||
|
resourceElement.setAttribute("version", "0.4.x");
|
||||||
|
genericResourcesElement.appendChild(resourceElement);
|
||||||
|
|
||||||
|
// Create <ID> element
|
||||||
|
Element idElement = document.createElement("ID");
|
||||||
|
idElement.appendChild(document.createTextNode("68322b8f-b916-44b9-9c93-bad8cceb9106"));
|
||||||
|
resourceElement.appendChild(idElement);
|
||||||
|
|
||||||
|
// Create <Type> element
|
||||||
|
Element typeElement = document.createElement("Type");
|
||||||
|
typeElement.appendChild(document.createTextNode("GenericResource"));
|
||||||
|
resourceElement.appendChild(typeElement);
|
||||||
|
|
||||||
|
// Create <Scopes> element
|
||||||
|
Element scopesElement = document.createElement("Scopes");
|
||||||
|
resourceElement.appendChild(scopesElement);
|
||||||
|
|
||||||
|
// Create <Scope> element within <Scopes>
|
||||||
|
Element scopeElement = document.createElement("Scope");
|
||||||
|
scopeElement.appendChild(document.createTextNode("/d4science.research-infrastructures.eu"));
|
||||||
|
scopesElement.appendChild(scopeElement);
|
||||||
|
|
||||||
|
// Create <Profile> element
|
||||||
|
Element profileElement = document.createElement("Profile");
|
||||||
|
resourceElement.appendChild(profileElement);
|
||||||
|
|
||||||
|
// Create <SecondaryType> element
|
||||||
|
Element secondaryTypeElement = document.createElement("SecondaryType");
|
||||||
|
secondaryTypeElement.appendChild(document.createTextNode("DetachedREs"));
|
||||||
|
profileElement.appendChild(secondaryTypeElement);
|
||||||
|
|
||||||
|
// Create <Name> element
|
||||||
|
Element nameElement = document.createElement("Name");
|
||||||
|
nameElement.appendChild(document.createTextNode("DetachedREsData"));
|
||||||
|
profileElement.appendChild(nameElement);
|
||||||
|
|
||||||
|
// Create <Description> element
|
||||||
|
Element descriptionElement1 = document.createElement("Description");
|
||||||
|
descriptionElement1.appendChild(document.createTextNode("Contains the information relating to dismissed Gateways, VOs and VREs."));
|
||||||
|
profileElement.appendChild(descriptionElement1);
|
||||||
|
|
||||||
|
// Create <Body> element
|
||||||
|
Element bodyElement = document.createElement("Body");
|
||||||
|
profileElement.appendChild(bodyElement);
|
||||||
|
|
||||||
|
// Create <detachedres> element
|
||||||
|
Element detachedResElement = document.createElement("detachedres");
|
||||||
|
bodyElement.appendChild(detachedResElement);
|
||||||
|
|
||||||
|
// Create <enabled> element within <detachedres>
|
||||||
|
Element enabledElement = document.createElement("enabled");
|
||||||
|
enabledElement.appendChild(document.createTextNode("true"));
|
||||||
|
detachedResElement.appendChild(enabledElement);
|
||||||
|
|
||||||
|
// Create <gateways> element within <detachedres>
|
||||||
|
Element gatewaysElement = document.createElement("gateways");
|
||||||
|
detachedResElement.appendChild(gatewaysElement);
|
||||||
|
|
||||||
|
int gatewayKey = -1;
|
||||||
|
|
||||||
|
// Iterate through the map entries to populate <entry> elements under <gateways>
|
||||||
|
for (Map.Entry<String, Gateway> entry : map.entrySet()) {
|
||||||
|
Gateway gateway = entry.getValue();
|
||||||
|
|
||||||
|
// Create <entry> element
|
||||||
|
Element entryElement = document.createElement("entry");
|
||||||
|
gatewaysElement.appendChild(entryElement);
|
||||||
|
|
||||||
|
// Create <key> element within <entry>
|
||||||
|
Element keyElement = document.createElement("key");
|
||||||
|
keyElement.appendChild(document.createTextNode(String.valueOf(gatewayKey)));
|
||||||
|
entryElement.appendChild(keyElement);
|
||||||
|
|
||||||
|
// Create <value> element within <entry>
|
||||||
|
Element valueElement = document.createElement("value");
|
||||||
|
entryElement.appendChild(valueElement);
|
||||||
|
|
||||||
|
// Create <scope> element within <value>
|
||||||
|
Element scopeValueElement = document.createElement("scope");
|
||||||
|
scopeValueElement.appendChild(document.createTextNode(String.valueOf(gatewayKey)));
|
||||||
|
valueElement.appendChild(scopeValueElement);
|
||||||
|
|
||||||
|
// Create <name> element within <value>
|
||||||
|
Element nameValueElement = document.createElement("name");
|
||||||
|
String gatewayName = extractGatewayName(gateway.getName());
|
||||||
|
nameValueElement.appendChild(document.createTextNode(gatewayName));
|
||||||
|
valueElement.appendChild(nameValueElement);
|
||||||
|
|
||||||
|
// Create <description> element within <value>
|
||||||
|
Element descriptionElement = document.createElement("description");
|
||||||
|
descriptionElement.appendChild(document.createTextNode("No description for gateway"));
|
||||||
|
valueElement.appendChild(descriptionElement);
|
||||||
|
|
||||||
|
Element vosElement = document.createElement("vos");
|
||||||
|
valueElement.appendChild(vosElement);
|
||||||
|
|
||||||
|
// Collect VREs under their respective VOs
|
||||||
|
Map<String, Element> voElements = new HashMap<>();
|
||||||
|
|
||||||
|
for (Vos vos : gateway.getVosList()) {
|
||||||
|
Element vosEntryElement;
|
||||||
|
Element vosValueElement;
|
||||||
|
if (voElements.containsKey(vos.getName())) {
|
||||||
|
vosEntryElement = voElements.get(vos.getName());
|
||||||
|
vosValueElement = (Element) vosEntryElement.getElementsByTagName("value").item(0);
|
||||||
|
} else {
|
||||||
|
vosEntryElement = document.createElement("entry");
|
||||||
|
vosElement.appendChild(vosEntryElement);
|
||||||
|
|
||||||
|
Element vosKeyElement = document.createElement("key");
|
||||||
|
vosKeyElement.appendChild(document.createTextNode("/d4science.research-infrastructures.eu/" + vos.getName()));
|
||||||
|
vosEntryElement.appendChild(vosKeyElement);
|
||||||
|
|
||||||
|
vosValueElement = document.createElement("value");
|
||||||
|
vosEntryElement.appendChild(vosValueElement);
|
||||||
|
|
||||||
|
Element vosScopeElement = document.createElement("scope");
|
||||||
|
vosScopeElement.appendChild(document.createTextNode("/d4science.research-infrastructures.eu/" + vos.getName()));
|
||||||
|
vosValueElement.appendChild(vosScopeElement);
|
||||||
|
|
||||||
|
Element vosNameElement = document.createElement("name");
|
||||||
|
vosNameElement.appendChild(document.createTextNode(vos.getName()));
|
||||||
|
vosValueElement.appendChild(vosNameElement);
|
||||||
|
|
||||||
|
voElements.put(vos.getName(), vosEntryElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
Element vresElement = document.createElement("vres");
|
||||||
|
vosValueElement.appendChild(vresElement);
|
||||||
|
|
||||||
|
for (Vres vres : vos.getVresList()) {
|
||||||
|
Element vresEntryElement = document.createElement("entry");
|
||||||
|
vresElement.appendChild(vresEntryElement);
|
||||||
|
|
||||||
|
Element vresKeyElement = document.createElement("key");
|
||||||
|
vresKeyElement.appendChild(document.createTextNode("/d4science.research-infrastructures.eu/" + vos.getName() + "/" + vres.getName()));
|
||||||
|
vresEntryElement.appendChild(vresKeyElement);
|
||||||
|
|
||||||
|
Element vresValueElement = document.createElement("value");
|
||||||
|
vresEntryElement.appendChild(vresValueElement);
|
||||||
|
|
||||||
|
Element vreScopeElement = document.createElement("scope");
|
||||||
|
vreScopeElement.appendChild(document.createTextNode("/d4science.research-infrastructures.eu/" + vos.getName() + "/" + vres.getName()));
|
||||||
|
vresValueElement.appendChild(vreScopeElement);
|
||||||
|
|
||||||
|
Element vresNameElement = document.createElement("name");
|
||||||
|
vresNameElement.appendChild(document.createTextNode(vres.getName()));
|
||||||
|
vresValueElement.appendChild(vresNameElement);
|
||||||
|
|
||||||
|
Element vresDescriptionElement = document.createElement("description");
|
||||||
|
vresDescriptionElement.appendChild(document.createTextNode(vres.getDescription()));
|
||||||
|
vresValueElement.appendChild(vresDescriptionElement);
|
||||||
|
|
||||||
|
Element vresManagerElement = document.createElement("managers");
|
||||||
|
vresManagerElement.appendChild(document.createTextNode(vres.getManager()));
|
||||||
|
vresValueElement.appendChild(vresManagerElement);
|
||||||
|
|
||||||
|
Element vresStartDateElement = document.createElement("startdate");
|
||||||
|
vresStartDateElement.appendChild(document.createTextNode(vres.getStartDate()));
|
||||||
|
vresValueElement.appendChild(vresStartDateElement);
|
||||||
|
|
||||||
|
Element vresEndDateElement = document.createElement("enddate");
|
||||||
|
vresEndDateElement.appendChild(document.createTextNode(vres.getEndDate()));
|
||||||
|
vresValueElement.appendChild(vresEndDateElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gatewayKey--;
|
||||||
|
}
|
||||||
|
|
||||||
|
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||||
|
Transformer transformer = transformerFactory.newTransformer();
|
||||||
|
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||||
|
DOMSource source = new DOMSource(document);
|
||||||
|
StreamResult result = new StreamResult(new File(outputXmlFilePath));
|
||||||
|
transformer.transform(source, result);
|
||||||
|
}
|
||||||
|
// Other methods...
|
||||||
|
public 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Other methods...
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?><genericResources>
|
||||||
<genericResources>
|
|
||||||
<Resource version="0.4.x">
|
<Resource version="0.4.x">
|
||||||
<ID>68322b8f-b916-44b9-9c93-bad8cceb9106</ID>
|
<ID>68322b8f-b916-44b9-9c93-bad8cceb9106</ID>
|
||||||
<Type>GenericResource</Type>
|
<Type>GenericResource</Type>
|
||||||
|
@ -1091,7 +1090,7 @@
|
||||||
</vos>
|
</vos>
|
||||||
</value>
|
</value>
|
||||||
</entry>
|
</entry>
|
||||||
</gateways>
|
</gateways>
|
||||||
</detachedres>
|
</detachedres>
|
||||||
</Body>
|
</Body>
|
||||||
</Profile>
|
</Profile>
|
||||||
|
|
Loading…
Reference in New Issue