This commit is contained in:
Lucio Lelii 2008-04-22 16:25:58 +00:00
parent 54cf2d00c2
commit b334f03771
1 changed files with 393 additions and 0 deletions

View File

@ -0,0 +1,393 @@
package org.gcube.vremanagement.vremodeler.impl;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.Hashtable;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.gcube.vremanagement.vremodeler.db.DBInterface;
/**
*
* @author lucio
*
*/
public class XMLUtil {
/**
* it creates the XML output for VDLGenerator
*
* @param res
* @return String
*/
protected static String PrepareCollectionXML(ResultSet res, ArrayList<String> relatedCollection){
StringBuilder temp= new StringBuilder();
String selectedString="false";
temp.append("<ResultSet>");
try{
while (res.next()){
selectedString= relatedCollection.contains(res.getString("ID")) ? "true" : "false";
temp.append("<Collection><ID>");
temp.append(res.getString(1));
temp.append("</ID><Name>");
temp.append(res.getString(2));
temp.append("</Name><Info><Description>");
temp.append(res.getString(3));
temp.append("</Description><NumberOfMembers>");
temp.append(res.getString(4));
temp.append("</NumberOfMembers><CreationTime>");
temp.append(res.getString(5));
temp.append("</CreationTime><LastUpdateTime>");
temp.append(res.getString(6));
temp.append("</LastUpdateTime></Info><Selected>");
temp.append(selectedString);
temp.append("</Selected></Collection>");
}
}catch(SQLException e){//logger.error("database error "+e.getMessage());
}
temp.append("</ResultSet>");
//logger.debug("VDLMODEL: request collection XML: "+temp);
return temp.toString();
}
protected static String PrepareDHNsXML(ResultSet res, ArrayList<String> relatedDHNs){
StringBuilder temp = new StringBuilder(),
runningInstancesString ;
ResultSet riRes;
String selectedString="false";
temp.append("<ResultSet>");
try{
while (res.next()){
selectedString= relatedDHNs.contains(res.getString("ID")) ? "true" : "false";
riRes= DBInterface.queryDB("select RI.id, RI.name from RUNNINGINSTANCE as RI, DHNRELATEDRI as REL where REL.DHNID='"+res.getString("ID")+"' and REL.RIID=RI.ID");
runningInstancesString= new StringBuilder();
while (riRes.next()){
runningInstancesString.append("<RunningInstance id=\"");
runningInstancesString.append(riRes.getString(1));
runningInstancesString.append("\" name=\"");
runningInstancesString.append(riRes.getString(2));
runningInstancesString.append("\" />");
}
temp.append("<DHN><ID>");
temp.append(res.getString(1));
temp.append("</ID><Host>");
temp.append(res.getString(2));
temp.append("</Host><Info><Security>");
temp.append(res.getString(3));
temp.append("</Security><UpTime>");
temp.append(res.getString(4));
temp.append("</UpTime><Memory><VirtualAvailable>");
temp.append(res.getString(5));
temp.append("</VirtualAvailable><VirtualSize>");
temp.append(res.getString(6));
temp.append("</VirtualSize><LocalAvailableSpace>");
temp.append(res.getString(7));
temp.append("</LocalAvailableSpace></Memory><Site><Location>");
temp.append(res.getString(8));
temp.append("</Location><Country>");
temp.append(res.getString(9));
temp.append("</Country><Domain>");
temp.append(res.getString(10));
temp.append("</Domain></Site><RunningInstances>");
temp.append(runningInstancesString);
temp.append("</RunningInstances><Libraries></Libraries></Info><Selected>");
temp.append(selectedString);
temp.append("</Selected></DHN>");
}
}catch(SQLException e){//logger.error("database error "+e.getMessage());
}
temp.append("</ResultSet>");
//logger.debug("VDLMODEL: request collection XML: "+temp);
return temp.toString();
}
/**
*
* @param res
* @return
*/
protected static String PrepareMCFormatXML(ResultSet resNative, ResultSet resDerivable, ResultSet allMF, Hashtable<String, ArrayList<String>> selectedMetadata){
Hashtable<String, ArrayList<String>> MDFHash= new Hashtable<String, ArrayList<String>>();
StringBuilder temp;
StringBuilder keyTemp=null;
StringBuilder totalMFList=new StringBuilder();
totalMFList.append("<MFL>");
ArrayList<String> tempArray;
try{
while (allMF.next())
{
temp= new StringBuilder();
temp.append("<Element><MFID>");
temp.append(allMF.getString(1));
temp.append("</MFID><MFName>");
temp.append(allMF.getString(2));
temp.append("</MFName><URI>");
temp.append(allMF.getString(3));
temp.append("</URI><Language>");
temp.append(allMF.getString(4));
temp.append("</Language></Element>");
totalMFList.append(temp);
}
totalMFList.append("</MFL>");
while(resNative.next()){
keyTemp= new StringBuilder();
keyTemp.append("<CollectionID>");
keyTemp.append(resNative.getString(1));
keyTemp.append("</CollectionID><Name>");
keyTemp.append(resNative.getString(2));
keyTemp.append("</Name><Description>");
keyTemp.append(resNative.getString(3));
keyTemp.append("</Description>");
temp= new StringBuilder();
temp.append("<MetadataFormat><Id>");
temp.append(resNative.getString(4));
if(selectedMetadata.isEmpty())
temp.append("</Id><Selectable>True</Selectable><Selected>True</Selected></MetadataFormat>");
else{
if((selectedMetadata.containsKey(resNative.getString(1))) && (selectedMetadata.get(resNative.getString(1)).contains(resNative.getString(4))))
temp.append("</Id><Selectable>True</Selectable><Selected>True</Selected></MetadataFormat>");
else
temp.append("</Id><Selectable>True</Selectable><Selected>False</Selected></MetadataFormat>");
}
//logger.debug("MDFProva: "+keyTemp+" "+temp);
if(MDFHash.get(keyTemp.toString())!=null) MDFHash.get(keyTemp).add(temp.toString());
else{
tempArray=new ArrayList<String>();
tempArray.add(temp.toString());
MDFHash.put(keyTemp.toString(), tempArray );
}
//logger.debug("MDFProva: Native "+MDFHash.get(keyTemp).size());
}
while(resDerivable.next()){
keyTemp= new StringBuilder();
keyTemp.append("<CollectionID>");
keyTemp.append(resDerivable.getString(1));
keyTemp.append("</CollectionID><Name>");
keyTemp.append(resDerivable.getString(2));
keyTemp.append("</Name><Description>");
keyTemp.append(resDerivable.getString(3));
keyTemp.append("</Description>");
temp= new StringBuilder();
temp.append("<MetadataFormat><Id>");
temp.append(resDerivable.getString(4));
if(selectedMetadata.isEmpty())
temp.append("</Id><Selectable>True</Selectable><Selected>False</Selected></MetadataFormat>");
else{
if((selectedMetadata.containsKey(resDerivable.getString(1))) && (selectedMetadata.get(resDerivable.getString(1)).contains(resDerivable.getString(4))))
temp.append("</Id><Selectable>True</Selectable><Selected>True</Selected></MetadataFormat>");
else
temp.append("</Id><Selectable>True</Selectable><Selected>False</Selected></MetadataFormat>");
}
//logger.debug("MDFProva: Derivable "+keyTemp+" "+temp);
if(MDFHash.get(keyTemp.toString())!=null) MDFHash.get(keyTemp.toString()).add(temp.toString());
else{
tempArray=new ArrayList<String>();
tempArray.add(temp.toString());
MDFHash.put(keyTemp.toString(), tempArray );
}
}
}catch(SQLException e){//logger.error("database error");
}
StringBuilder resultString= new StringBuilder();
resultString.append("<ResultSet>");
resultString.append(totalMFList);
resultString.append("<CollectionList>");
String key;
Enumeration<String> k=MDFHash.keys();
while (k.hasMoreElements()){
key= k.nextElement();
ArrayList<String> tempMD=MDFHash.get(key);
//logger.debug("ArrayProva"+tempMD.size());
resultString.append("<Collection>");
resultString.append(key);
resultString.append("<MetadataFormatList>");;
for (String obj: tempMD){
resultString.append(obj);
//logger.debug("ArrayProva "+obj);
}
resultString.append("</MetadataFormatList></Collection>");
}
resultString.append("</CollectionList></ResultSet>");
//logger.debug("VDLMODEL: request MCFormat XML "+resultString);
return resultString.toString();
}
/**
*
* @param resNative
* @param resDerivable
* @return
*/
protected static String PrepareQualityXML(){
StringBuilder qualityString=new StringBuilder();
qualityString.append("<ResultSet>");
qualityString.append("<Quality><DisplayName>Response Time</DisplayName><Description>This quality parameter indicates the importance of response time (i.e., the delay from a function request to the reception of the response) ");
qualityString.append("in selecting the resource (both in number and type) needed to satisfy the Digital Library definition criteria. E.g., the specification of a 100% response time will result in a maximization of the resources ");
qualityString.append("allocated as to minimise the response time. </Description><Multiple value=\"true\"/><CanBeEmpty value=\"false\"/><AllowedValues><Value default=\"true\" selected=\"false\">*</Value></AllowedValues></Quality>");
qualityString.append("<Quality><DisplayName>Robustness</DisplayName><Description>This quality parameter indicates the importance of robustness (i.e., the resilience to faults) in selecting the resource (both in number and type)");
qualityString.append(" needed to satisfy the Digital Library definition criteria. E.g., the specification of a 100% robustness will result in a maximisation of the resources allocated as to minimise service unavailability.</Description><Multiple ");
qualityString.append(" value=\"true\"/><CanBeEmpty value=\"false\"/><AllowedValues><Value default=\"true\" selected=\"false\">*</Value></AllowedValues></Quality>");
qualityString.append("<Quality><DisplayName>Scalability</DisplayName><Description>This quality parameter indicates the importance of scalability (i.e., the capability to increase Digital Library Capacity as much as needed) in selecting the resource ");
qualityString.append("(both in number and type) needed to satisfy the Digital Library definition criteria. E.g., the specification of a 100% scalability will result in a maximisztion of the resources allocated as to minimise the response time.</Description>");
qualityString.append("<Multiple value=\"true\"/><CanBeEmpty value=\"false\"/><AllowedValues><Value default=\"true\" selected=\"false\">*</Value></AllowedValues></Quality>");
qualityString.append("<Quality><DisplayName>Re-use</DisplayName><Description>This quality parameter indicates the willingness to re-use existing resources (running instances, indexes, etc.) across various Digital Libraries. The specified ");
qualityString.append("percentage represents the degree of re-use of existing assets in concretely implementing the Digital Library.</Description><Multiple value=\"true\"/><CanBeEmpty value=\"false\"/><AllowedValues><Value default=\"true\" selected=\"false\">*</Value></AllowedValues></Quality>");
qualityString.append("<Quality><DisplayName>Capacity</DisplayName><Description>This quality parameter indicates the importance of capacity (i.e., the amount of resources allocated to the Digital Library) in selecting the resource (both in number and type) ");
qualityString.append("needed to satisfy the Digital Library definition criteria. E.g., the specification of a 100% capacity will result in a maximization of the amount of resources allocated to the Digital Library.");
qualityString.append(" </Description><Multiple value=\"true\"/><CanBeEmpty value=\"false\"/><AllowedValues><Value default=\"true\" selected=\"false\">*</Value></AllowedValues></Quality>");
qualityString.append("<Quality><DisplayName>Security</DisplayName><Description>A true/false quality parameter indicates whether the operations have to be executed in a fully authorised and authenticated environment (true value) or ");
qualityString.append("not (false value)</Description><Multiple value=\"false\"/><CanBeEmpty value=\"false\"/><AllowedValues><Value default=\"true\" selected=\"false\">Yes</Value><Value default=\"false\" selected=\"false\">No</Value></AllowedValues></Quality>");
qualityString.append("</ResultSet>");
return qualityString.toString();
}
/**
*
*/
protected static String PrepareFunctionalityXML(ResultSet res, ArrayList<Integer> selectedFunct, ArrayList<String> selectedCS){
StringBuilder toReturn=new StringBuilder();
toReturn.append("<Resultset>");
try {
while(res.next()){
StringBuilder temp= new StringBuilder();
temp.append("<Functionality id=\"");
temp.append(res.getInt(1));
temp.append("\" name=\"");
temp.append(res.getString(2));
temp.append("\" ");
if (res.getInt(1)==10) temp.append(" enableCS=\"true\" ");
if(selectedFunct.contains(res.getInt(1))) temp.append("selected=\"true\">");
else {
temp.append("selected=\"false\">");
temp.append("<FunctionalityDescription>");
temp.append(res.getString(3));
temp.append("</FunctionalityDescription>");
}
ResultSet subFunctRes=DBInterface.queryDB("select * from FUNCTIONALITY where father='"+res.getInt(1)+"';");
while(subFunctRes.next()){
temp.append("<child>");
temp.append("<Functionality id=\"");
temp.append(subFunctRes.getInt(1));
temp.append("\" name=\"");
temp.append(subFunctRes.getString(2));
temp.append("\" ");
if(selectedFunct.contains(subFunctRes.getInt(1))) temp.append("selected=\"true\">");
else temp.append("selected=\"false\">");
temp.append("<FunctionalityDescription>");
temp.append(subFunctRes.getString(3));
temp.append("</FunctionalityDescription>");
temp.append("</Functionality></child>");
}
temp.append("</Functionality>");
toReturn.append(temp);
}
} catch (SQLException e) {
//logger.debug("VDLModelService: DB error preparing XML for Functionality");
}
try {
ResultSet csRes=DBInterface.queryDB("select * from cs;");
if (csRes.next()){
StringBuilder temp= new StringBuilder();
temp.append("<CS id=\"-1\" name=\"Workflows\" ");
//if(selectedFunct.contains(res.getInt(1))) temp+="selected=\"true\">";
//else
temp.append("selected=\"false\">");
temp.append("<CSDescription>This class of functions contains compound functions defined by aggregating existing functions in structured workflows as to deliver advanced features.</CSDescription>");
do{
temp.append("<child><CS id=\"");
temp.append(csRes.getString(1));
temp.append("\" name=\"");
temp.append(csRes.getString(2));
temp.append("\" ");
if(selectedCS.contains(csRes.getString(1))) temp.append("selected=\"true\">");
else temp.append("selected=\"false\">");
temp.append("<CSDescription>");
temp.append(csRes.getString(3));
temp.append("</CSDescription>");
temp.append("</CS></child>");
}while (csRes.next());
temp.append("</CS>");
toReturn.append(temp);
}
} catch (SQLException e) {
//logger.error("VDLModelService: DB error retreiving CS");
}
toReturn.append("</Resultset>");
//logger.debug(toReturn);
return toReturn.toString();
}
@SuppressWarnings("deprecation")
protected static String PrepareDLModelXML(ResultSet res) throws Exception{
StringBuilder toReturn=new StringBuilder();
if (res.next()){
toReturn.append("<Resultset><Name>");
toReturn.append(res.getString(2));
toReturn.append("</Name><Description>");
toReturn.append(res.getString(3));
toReturn.append("</Description><DLDesigner>");
toReturn.append(res.getString(4));
toReturn.append("</DLDesigner><DLManager>");
toReturn.append(res.getString(5));
toReturn.append("</DLManager><StartTime>");
toReturn.append(res.getDate(6).getTime());
toReturn.append("</StartTime><EndTime>");
toReturn.append(res.getDate(7).getTime());
toReturn.append("</EndTime></Resultset>");
}else{
Date dateFrom=new Date();
Date dateTo=new Date();
dateTo.setYear(dateTo.getYear()+1);
toReturn=new StringBuilder("<Resultset><Name></Name><Description></Description><DLDesigner></DLDesigner><DLManager></DLManager><StartTime>"+dateFrom.getTime()+"</StartTime><EndTime>"+dateTo.getTime()+"</EndTime></Resultset>");
}
return toReturn.toString();
}
protected static String PrepareAllDLsXML(ResultSet res) throws Exception{
StringBuilder toReturn=new StringBuilder();
toReturn.append("<ResultSet>");
while (res.next()){
toReturn.append("<DL><Name>");
toReturn.append(res.getString(1));
toReturn.append("</Name><Description>");
toReturn.append(res.getString(2));
toReturn.append("</Description><State>");
toReturn.append(res.getString(3));
toReturn.append("</State><EPR>");
toReturn.append(res.getString(4));
toReturn.append("</EPR></DL>");
}
toReturn.append("</ResultSet>");
return toReturn.toString();
}
}