This commit is contained in:
Lucio Lelii 2009-02-12 18:17:37 +00:00
parent 184dd653e3
commit 9db3293917
5 changed files with 114 additions and 60 deletions

View File

@ -78,7 +78,7 @@ public class IStoDBUtil {
logger.debug("initialization: metadata");
insertCS(scope);
logger.debug("initialization: CS");
insertServices(scope);
//insertServices(scope);
insertGHN(scope);
logger.debug("initialization: GHN");
logger.info("Database Initialized!!");

View File

@ -17,6 +17,7 @@ import org.gcube.vremanagement.vremodeler.db.DBInterface;
import org.gcube.vremanagement.vremodeler.impl.thread.DeployVRE;
import org.gcube.vremanagement.vremodeler.impl.util.GCUBECollection;
import org.gcube.vremanagement.vremodeler.impl.util.MetadataFormat;
import org.gcube.vremanagement.vremodeler.impl.util.ModelerCollection;
import org.gcube.vremanagement.vremodeler.impl.util.XMLUtil;
import org.gcube.vremanagement.vremodeler.stubs.CheckStatusResponse;
import org.gcube.vremanagement.vremodeler.stubs.CollectionArray;
@ -255,21 +256,21 @@ public class ModelerService {
*/
public String getMetadataRelatedToCollection(VOID var) throws GCUBEFault {
Hashtable<GCUBECollection, List<MetadataFormat>> nativeMetadataFormat;
Hashtable<GCUBECollection, List<MetadataFormat>> selectedMetadataFormat;
Hashtable<ModelerCollection, List<MetadataFormat>> nativeMetadataFormat;
Hashtable<ModelerCollection, List<MetadataFormat>> selectedMetadataFormat;
try{
DBInterface.connect();
//retrieve all possible metadataformat for the selected collection
nativeMetadataFormat= new Hashtable<GCUBECollection, List<MetadataFormat>>();
ResultSet allPossibleMDF= DBInterface.queryDB("select rel.collid, mdf.id, mdf.name, mdf.schemauri, mf.language, coll.name, coll.description from COLLECTION as coll, VRERELATEDCOLLECTION as rel, MDCOLLECTION as mcoll, METADATAFORMAT as mdf where VRERELATEDCOLLECTION.vreid='"+getResource().getId()+"' and mcoll.relatedcollectionid=rel.collid and mdf.id=native.mdfid and native.mdcollid=mcoll.id and coll.id=rel.collid;");
nativeMetadataFormat= new Hashtable<ModelerCollection, List<MetadataFormat>>();
ResultSet allPossibleMDF= DBInterface.queryDB("select rel.collid, mdf.id, mdf.name, mdf.schemauri, mdf.language, coll.name, coll.description from COLLECTION as coll, VRERELATEDCOLLECTION as rel, MDCOLLECTION as mcoll, MDFORMAT as mdf, NATIVEMDF as native where rel.vreid='"+getResource().getId()+"' and mcoll.relatedcollectionid=rel.collid and mdf.id=native.mdfid and native.mdcollid=mcoll.id and coll.id=rel.collid;");
while (allPossibleMDF.next()){
GCUBECollection collection= new GCUBECollection(allPossibleMDF.getString(1), allPossibleMDF.getString(7), allPossibleMDF.getString(6) );
ModelerCollection collection= new ModelerCollection(allPossibleMDF.getString(1), allPossibleMDF.getString(7), allPossibleMDF.getString(6) );
MetadataFormat mf= new MetadataFormat(allPossibleMDF.getString(2), allPossibleMDF.getString(3), new URI(allPossibleMDF.getString(4)), allPossibleMDF.getString(5));
if (nativeMetadataFormat.containsKey(collection))
if (nativeMetadataFormat.containsKey(collection)){
nativeMetadataFormat.get(collection).add(mf);
else {
}else {
ArrayList<MetadataFormat> keyList=new ArrayList<MetadataFormat>();
keyList.add(mf);
nativeMetadataFormat.put(collection, keyList);
@ -278,10 +279,10 @@ public class ModelerService {
//retrieving selected metadaformat
//hashtable <collectionId, MetadataFormat>
selectedMetadataFormat= new Hashtable<GCUBECollection, List<MetadataFormat>>();
ResultSet selectedFormat= DBInterface.queryDB("select rel.collid, mf.id, mf.name, mf.schemauri, mf.language , coll.name, coll.description from COLLECTION as coll, VRERELATEDMETADATAFORMAT as rel, METADATAFORMAT as mf where mf.id=rel.mfid and vreid='"+getResource().getId()+"' and coll.id=rel.collid;");
selectedMetadataFormat= new Hashtable<ModelerCollection, List<MetadataFormat>>();
ResultSet selectedFormat= DBInterface.queryDB("select rel.collid, mf.id, mf.name, mf.schemauri, mf.language , coll.name, coll.description from COLLECTION as coll, VRERELATEDMETADATAFORMAT as rel, MDFORMAT as mf where mf.id=rel.mfid and rel.vreid='"+getResource().getId()+"' and coll.id=rel.collid;");
while (selectedFormat.next()){
GCUBECollection collection= new GCUBECollection(selectedFormat.getString(1), selectedFormat.getString(7), selectedFormat.getString(6));
ModelerCollection collection= new ModelerCollection(selectedFormat.getString(1), selectedFormat.getString(7), selectedFormat.getString(6));
MetadataFormat mf= new MetadataFormat(selectedFormat.getString(2), selectedFormat.getString(3), new URI(selectedFormat.getString(4)), selectedFormat.getString(5));
if (selectedMetadataFormat.containsKey(collection))
selectedMetadataFormat.get(collection).add(mf);

View File

@ -22,7 +22,8 @@ public class ServiceContext extends GCUBEServiceContext{
protected void onReady() throws Exception{
try{
logger.info("ready event invoked on " + this.getName());
IStoDBUtil.initDB(ServiceContext.getContext().getStartScopes()[0].isInfrastructure()? ServiceContext.getContext().getStartScopes()[1]: ServiceContext.getContext().getStartScopes()[0]);
ServiceContext.getContext().setScope(ServiceContext.getContext().getStartScopes()[0].isInfrastructure()? ServiceContext.getContext().getStartScopes()[1]: ServiceContext.getContext().getStartScopes()[0]);
IStoDBUtil.initDB(ServiceContext.getContext().getStartScopes()[0].isInfrastructure()? ServiceContext.getContext().getStartScopes()[1]: ServiceContext.getContext().getStartScopes()[0]);
ModelerContext.getPortTypeContext().getWSHome().checkResourceScope();
}catch (Exception e){
this.setStatus(Status.FAILED, true);

View File

@ -0,0 +1,53 @@
package org.gcube.vremanagement.vremodeler.impl.util;
public class ModelerCollection {
private String id;
private String name;
private String description;
public ModelerCollection(String id, String description, String name){
this.id= id;
this.description= description;
this.name= name;
}
public String getId(){
return this.id;
}
public String getName(){
return this.name;
}
public String getDescription(){
return this.description;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ModelerCollection other = (ModelerCollection) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
}

View File

@ -4,6 +4,7 @@ import java.io.StringWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Enumeration;
import java.util.Hashtable;
@ -134,12 +135,19 @@ public class XMLUtil {
return docToString(doc);
}
private static <T> List<T> getDistinctObjects(Collection<T> list){
List<T> tmpList= new ArrayList<T>();
for (T el: list)
if (!tmpList.contains(el)) tmpList.add(el);
return tmpList;
}
/**
*
* @param res
* @return
*/
public static String PrepareMCFormatXML(Hashtable<GCUBECollection, List<MetadataFormat>> nativeMetadataFormat, Hashtable<GCUBECollection, List<MetadataFormat>> selectedMetadataFormat){
public static String PrepareMCFormatXML(Hashtable<ModelerCollection, List<MetadataFormat>> nativeMetadataFormat, Hashtable<ModelerCollection, List<MetadataFormat>> selectedMetadataFormat){
Document doc= null;
try {
@ -148,59 +156,63 @@ public class XMLUtil {
logger.error("Error creating XML Message");
e1.printStackTrace();
}
Hashtable<String, Couple<Element, ArrayList<Element>>> MDFHash= new Hashtable<String, Couple<Element, ArrayList<Element>>>();
//Hashtable<String, Couple<Element, ArrayList<Element>>> MDFHash= new Hashtable<String, Couple<Element, ArrayList<Element>>>();
List<MetadataFormat> mdflistMultiple= new ArrayList<MetadataFormat>();
for (List<MetadataFormat> mftmpList: nativeMetadataFormat.values())
mdflistMultiple.addAll(mftmpList);
List<MetadataFormat> totalMDF= getDistinctObjects(mdflistMultiple);
Element collectionListEl= doc.createElement("CollectionList");
Element mflEl= doc.createElement("MFL");
ArrayList<Element> tempArray;
try{
while (allMF.next())
for (MetadataFormat mf: totalMDF)
{
Element elementEl=addElements(doc, "Element", new Element[]{
createTextElement(doc, "MFID", allMF.getString(1)),
createTextElement(doc, "MFName", allMF.getString(2)),
createTextElement(doc, "URI", allMF.getString(3)),
createTextElement(doc, "Language", allMF.getString(4))
createTextElement(doc, "MFID", mf.getId()),
createTextElement(doc, "MFName", mf.getName()),
createTextElement(doc, "URI", mf.getSchemaURI().toString()),
createTextElement(doc, "Language", mf.getLanguage())
});
mflEl.appendChild(elementEl);
}
//setting the native MDF
while(resNative.next()){
Element tmpKeyEl= addElements(doc, "Collection", new Element[]{
createTextElement(doc,"CollectionID" , resNative.getString(1)),
createTextElement(doc,"Name" , resNative.getString(2)),
createTextElement(doc,"Description" , resNative.getString(3))
for(ModelerCollection key: nativeMetadataFormat.keySet()){
System.out.println(key.getId());
Element collectionEl= addElements(doc, "Collection", new Element[]{
createTextElement(doc,"CollectionID" , key.getId()),
createTextElement(doc,"Name" , key.getName()),
createTextElement(doc,"Description" , key.getDescription())
});
Element tmpEl;
if(selectedMetadata.isEmpty() || (selectedMetadata.containsKey(resNative.getString(1))) && (selectedMetadata.get(resNative.getString(1)).contains(resNative.getString(4))) )
tmpEl= addElements(doc, "MetadataFormat", new Element[]{
createTextElement(doc, "Id", resNative.getString(4)),
for(MetadataFormat mf: nativeMetadataFormat.get(key)){
Element tmpEl;
if(selectedMetadataFormat.isEmpty() || ((selectedMetadataFormat.get(key)!=null) && selectedMetadataFormat.get(key).contains(mf))){
tmpEl= addElements(doc, "MetadataFormat", new Element[]{
createTextElement(doc, "Id", mf.getId()),
createTextElement(doc, "Selectable", "True"),
createTextElement(doc, "Selected", "True"),
});
else{
tmpEl= addElements(doc, "MetadataFormat", new Element[]{
createTextElement(doc, "Id", resNative.getString(4)),
createTextElement(doc, "Selectable", "True"),
createTextElement(doc, "Selected", "False"),
});
}else {
tmpEl= addElements(doc, "MetadataFormat", new Element[]{
createTextElement(doc, "Id", mf.getId()),
createTextElement(doc, "Selectable", "True"),
createTextElement(doc, "Selected", "False"),
});
}
collectionEl.appendChild(tmpEl);
}
//logger.debug("MDFProva: "+keyTemp+" "+temp);
if(MDFHash.contains(resNative.getString(1))) MDFHash.get(resNative.getString(1)).second.add(tmpEl);
else{
tempArray=new ArrayList<Element>();
tempArray.add(tmpEl);
MDFHash.put(resNative.getString(1), new Couple<Element, ArrayList<Element>>(tmpKeyEl, tempArray) );
}
//logger.debug("MDFProva: Native "+MDFHash.get(keyTemp).size());
collectionListEl.appendChild(collectionEl);
}
//setting the derivable MDF
/* TODO: when metadataBroker will be ready for transformation
/* TODO: when metadataBroker will be ready for transformations
* while(resDerivable.next()){
Element tmpKeyEl= addElements(doc, "Collection", new Element[]{
createTextElement(doc,"CollectionID" , resDerivable.getString(1)),
@ -231,24 +243,11 @@ public class XMLUtil {
}
}
*/
}catch(SQLException e){logger.error("hsqldb error");
e.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}
Element collectionListEl= doc.createElement("CollectionList");
String key;
Enumeration<String> k=MDFHash.keys();
while (k.hasMoreElements()){
key= k.nextElement();
Couple<Element, ArrayList<Element>> tempMD=MDFHash.get(key);
//logger.debug("ArrayProva"+tempMD.size());
tempMD.first.appendChild(addElements(doc, "MetadataFormatList", tempMD.second.toArray(new Element[0])));
collectionListEl.appendChild(tempMD.first);
}
doc.appendChild(addElements(doc, "ResultSet", new Element[]{mflEl, collectionListEl}));
//logger.debug("VDLMODEL: request MCFormat XML "+resultString);
return docToString(doc);