mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-10 05:13:38 +00:00
127 lines
5.1 KiB
Java
127 lines
5.1 KiB
Java
import java.io.*;
|
|
|
|
import javax.xml.parsers.DocumentBuilder;
|
|
import javax.xml.parsers.DocumentBuilderFactory;
|
|
|
|
import org.w3c.dom.Document;
|
|
import org.w3c.dom.Element;
|
|
import org.w3c.dom.Node;
|
|
import org.w3c.dom.NodeList;
|
|
|
|
public class GenerateCodeCenterDashboard {
|
|
|
|
private static void usage() {
|
|
System.out.println("Input Parameters:" );
|
|
System.out.println("Folder path\\name - Location and folder name where all Code Center xml files are stored\n" +
|
|
"File path\\name - location and filename to store the dashboard summary html report ");
|
|
System.out.println("");
|
|
|
|
}
|
|
|
|
/**********************************************************************************
|
|
*
|
|
* @param xml file generated by GetAssociateAndValidateResult script
|
|
* @return HTML String
|
|
*********************************************************************************/
|
|
public String getCodeCenterResult(File file) {
|
|
try {
|
|
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
|
DocumentBuilder db = dbf.newDocumentBuilder();
|
|
//System.out.println("Exists: " + file.getName() + " " + file.exists());
|
|
if (file.exists()) {
|
|
Document doc = db.parse(file);
|
|
|
|
|
|
|
|
NodeList appList = doc.getElementsByTagName("Application");
|
|
Node appName = appList.item(0);
|
|
Element appElement = (Element) appName;
|
|
|
|
NodeList validList = doc.getElementsByTagName("ValidationStatus");
|
|
Node validNode = validList.item(0);
|
|
Element validElement = (Element) validNode;
|
|
|
|
NodeList approveList = doc.getElementsByTagName("ApprovedStatus");
|
|
Node approveNode = approveList.item(0);
|
|
Element approveElement = (Element) approveNode;
|
|
|
|
|
|
String prj_str = "<tr><td style='text-align: center;'>" + appElement.getTextContent() + "</td>";
|
|
if (validElement.getTextContent().equals("PASSED"))
|
|
prj_str = prj_str + "<td style='text-align: center;'>" + validElement.getTextContent() + "</td>";
|
|
else
|
|
prj_str = prj_str + "<td style='text-align: center;': bgcolor=gold> <b> <font color=red>" + validElement.getTextContent() + "</td>";
|
|
|
|
if (approveElement.getTextContent().equals("APPROVED"))
|
|
prj_str = prj_str + "<td style='text-align: center;'>" + approveElement.getTextContent() + "</td></tr>";
|
|
else
|
|
prj_str = prj_str + "<td style='text-align: center;': bgcolor=gold> <b> <font color=red>" + approveElement.getTextContent() + "</td></tr>";
|
|
|
|
|
|
return prj_str;
|
|
}
|
|
} catch (Exception e) {
|
|
System.out.println(e);
|
|
}
|
|
return "Error!! Parsing XML reports";
|
|
}
|
|
|
|
/***********************************************************************************
|
|
* main()
|
|
* @param args
|
|
***********************************************************************************/
|
|
public static void main(String[] args)
|
|
{
|
|
|
|
if (args.length < 2) {
|
|
System.err.println("Not enough parameters!");
|
|
usage();
|
|
System.exit(-1);
|
|
}
|
|
|
|
GenerateCodeCenterDashboard parser = new GenerateCodeCenterDashboard();
|
|
String filename;
|
|
File folder = new File( args[0] );
|
|
File[] listOfFiles = folder.listFiles();
|
|
String html_content = "";
|
|
String OSName = null;
|
|
String delimiter = null;
|
|
OSName = System.getProperty("os.name");
|
|
if (OSName.contains("Windows")) delimiter = "\\";
|
|
else delimiter = "/";
|
|
|
|
for (int i = 0; i < listOfFiles.length; i++)
|
|
{
|
|
if (listOfFiles[i].isFile())
|
|
{
|
|
filename = folder.getPath() + delimiter + listOfFiles[i].getName();
|
|
//System.out.println("File: " + filename);
|
|
if (filename.endsWith(".xml") || filename.endsWith(".XML"))
|
|
{
|
|
File filehandle = new File(filename);
|
|
String prj_str = parser.getCodeCenterResult( filehandle );
|
|
html_content = html_content + prj_str;
|
|
}
|
|
}
|
|
}
|
|
|
|
File f = new File(args[1]);
|
|
try {
|
|
BufferedWriter bw = new BufferedWriter(new FileWriter(f));
|
|
bw.write( "<html><body>"
|
|
+ "<h1> <span style='text-align:center;font-weight:bold'> Code Center Summary </span></h1>"
|
|
+ "<table border='2px'>"
|
|
+ "<tr style='background-color: rgb(240, 240, 240);'>"
|
|
+ "<th style='border-left: 1px solid;'> Code Center Application </th>"
|
|
+ "<th style='border-left: 1px solid;'> Validation Status </th>"
|
|
+ "<th style='border-left: 1px solid;'> Approval Status </th>"
|
|
+ "</tr>"
|
|
+ html_content + "</table></body></html>" ) ;
|
|
|
|
bw.close();
|
|
} catch (Exception e) {
|
|
System.out.println(e);
|
|
}
|
|
}
|
|
}
|