git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vre-management/VREModeler@7461 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
ebf29c1293
commit
7da88c776a
|
@ -2,7 +2,6 @@
|
|||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/GCORELIBS"/>
|
||||
<classpathentry kind="lib" path="/home/lucio/gCore/lib/org.gcube.vremanagement.vremodeler.stubs.jar"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/GCORELIB"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.sql.Statement;
|
|||
import java.util.List;
|
||||
import org.gcube.common.core.faults.GCUBEFault;
|
||||
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||
import org.gcube.vremanagement.vremodeler.impl.util.Listable;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -72,6 +73,50 @@ public class DBInterface {
|
|||
}
|
||||
|
||||
|
||||
public static synchronized void insertIntoListable(String table, List<? extends Listable> values) throws GCUBEFault {
|
||||
|
||||
if (values==null) throw new GCUBEFault();
|
||||
Statement st = null;
|
||||
|
||||
try{
|
||||
st = conn.createStatement(); // statement objects can be reused with
|
||||
}catch(SQLException e){//logger.error("error creating SQL statement");
|
||||
throw new GCUBEFault(e);}
|
||||
|
||||
StringBuffer insertQuery;
|
||||
|
||||
|
||||
for (Listable row: values)
|
||||
{
|
||||
|
||||
insertQuery=new StringBuffer();
|
||||
insertQuery.append("INSERT INTO ").append(table.toUpperCase()).append(" VALUES(");
|
||||
try{
|
||||
|
||||
|
||||
for(String value: row.getAsStringList()){
|
||||
insertQuery.append("'").append(value.replaceAll("'", " ")).append("',");
|
||||
}
|
||||
|
||||
insertQuery.deleteCharAt(insertQuery.length()-1).append(");");
|
||||
logger.trace("Query for inserting in hsqldb "+insertQuery);
|
||||
|
||||
st.executeUpdate(insertQuery.toString()); // run the query
|
||||
}catch(SQLException e){logger.error("HSQLDB ERROR: Problem inserting data "+e.getMessage()+" -- "+ insertQuery);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
catch(Exception e){
|
||||
logger.error("VDLModelService error: Problem inserting data "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
try{
|
||||
st.close();
|
||||
}catch(SQLException e){logger.error("error closing SQL statement");
|
||||
throw new GCUBEFault(e);}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,9 +3,13 @@ package org.gcube.vremanagement.vremodeler.db;
|
|||
import java.rmi.RemoteException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
/*import org.apache.axis.components.uuid.UUIDGen;
|
||||
import org.apache.axis.components.uuid.UUIDGenFactory;*/
|
||||
import org.apache.axis.components.uuid.UUIDGen;
|
||||
import org.apache.axis.components.uuid.UUIDGenFactory;
|
||||
import org.apache.axis.message.addressing.EndpointReferenceType;
|
||||
import org.gcube.common.core.contexts.GHNContext;
|
||||
import org.gcube.common.core.faults.GCUBEFault;
|
||||
|
@ -24,6 +28,8 @@ import org.gcube.common.core.resources.GCUBERunningInstance;
|
|||
import org.gcube.common.core.resources.GCUBEService;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||
import org.gcube.vremanagement.vremodeler.impl.util.MFRelationNative;
|
||||
import org.gcube.vremanagement.vremodeler.impl.util.MetadataFormat;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -36,6 +42,8 @@ public class IStoDBUtil {
|
|||
|
||||
private static GCUBELog logger = new GCUBELog(IStoDBUtil.class.getName());
|
||||
|
||||
private static UUIDGen uuidMFGEN= UUIDGenFactory.getUUIDGen();
|
||||
|
||||
private static ISClient queryClient;
|
||||
/**
|
||||
* Initialize all database tables
|
||||
|
@ -217,157 +225,49 @@ public class IStoDBUtil {
|
|||
//preparing collectionList to insert
|
||||
//table declaration:
|
||||
//MDCOLLECTION(ID VARCHAR NOT NULL PRIMARY KEY,NAME VARCHAR,DESCRIPTION VARCHAR,RELATEDCOLLECTIONID VARCHAR NOT NULL)
|
||||
String uuid;
|
||||
MetadataFormat mf;
|
||||
List<List<String>> values = new ArrayList<List<String>>(collectionList.size());
|
||||
List<String> row;
|
||||
List<MetadataFormat> metadataFormatList= new ArrayList<MetadataFormat>();
|
||||
List<MFRelationNative> nativeMetadataFormatList= new ArrayList<MFRelationNative>();
|
||||
|
||||
for (GCUBEMCollection col: collectionList ){
|
||||
row= new ArrayList<String>(4);
|
||||
|
||||
row.add(col.getID());
|
||||
row.add(col.getName());
|
||||
row.add(col.getDescription());
|
||||
row.add(col.getRelCollection().getCollectionID());
|
||||
values.add(row);
|
||||
|
||||
//adding the native metadataformat
|
||||
uuid=uuidMFGEN.nextUUID();
|
||||
mf= new MetadataFormat(uuid, col.getMetaFormat().getName(), col.getMetaFormat().getSchemaURI(), col.getMetaFormat().getLanguage());
|
||||
if (!metadataFormatList.contains(mf)){
|
||||
metadataFormatList.add(mf);
|
||||
nativeMetadataFormatList.add(new MFRelationNative(col.getID(), mf.getId() ));
|
||||
}else nativeMetadataFormatList.add(new MFRelationNative(col.getID(), metadataFormatList.get(metadataFormatList.indexOf(mf)).getId()));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//insert the values in the database
|
||||
DBInterface.connect();
|
||||
DBInterface.InsertInto("mdcollection", values);
|
||||
DBInterface.insertIntoListable("mdformat", metadataFormatList );
|
||||
DBInterface.insertIntoListable("nativemdf", nativeMetadataFormatList);
|
||||
|
||||
|
||||
}
|
||||
}catch (SQLException e){logger.error("VDLModel: DB error "+e.getMessage());
|
||||
throw new GCUBEFault(e); }
|
||||
|
||||
|
||||
|
||||
ArrayList<String[]> MDFormatArray=new ArrayList<String[]>();
|
||||
ArrayList<String[]> MDNativeArray=new ArrayList<String[]>();
|
||||
ArrayList<String[]> MDDerivableArray=new ArrayList<String[]>();
|
||||
String[][] resultsParsed= parseResults(results, "r");
|
||||
String uuid;
|
||||
String metadataFormatQuery;
|
||||
String[] singleNativeMDF;
|
||||
String[] singleDerivableMDF;
|
||||
|
||||
|
||||
for(String[] singleColl: resultsParsed)
|
||||
{
|
||||
//generate the uid for MetadataFormat
|
||||
uuid=uuidMFGEN.nextUUID();
|
||||
String existID;
|
||||
//retriving the metadataFormat for the current MDCollection
|
||||
|
||||
metadataFormatQuery="for $MetadataFormat in collection(\"/db/Profiles/MetadataCollection\")//Document/Data/child::*[local-name()='Profile']/DILIGENTResource where $MetadataFormat/UniqueID/string() eq '"+singleColl[0]+"' return <r><id>"+uuid+"</id><Name>{$MetadataFormat/Profile/MetadataFormat/Name/string()}</Name><SchemaURI>{$MetadataFormat/Profile/MetadataFormat/SchemaURI/string()}</SchemaURI><lng>{$MetadataFormat/Profile/MetadataFormat/Language/string()}</lng></r>";
|
||||
results=makeQueryDIS(epr, cred, metadataFormatQuery);
|
||||
String[][] resultsMDFParsed= parseResults(results, "r");
|
||||
if((existID=ContainsControl(resultsMDFParsed[0], MDFormatArray))==null)
|
||||
{
|
||||
MDFormatArray.add(resultsMDFParsed[0]);
|
||||
existID=uuid;
|
||||
}
|
||||
//keep the CollectionID and the MDFID to insert into NAtiveMDF
|
||||
singleNativeMDF=new String[3];
|
||||
singleNativeMDF[0]=singleColl[0];
|
||||
singleNativeMDF[1]=existID;
|
||||
singleNativeMDF[2]=singleColl[3]; //i need it to evaluate doble results
|
||||
MDNativeArray.add(singleNativeMDF);
|
||||
|
||||
/*
|
||||
//Retrive Derivable MDF
|
||||
if (brokerConnected){
|
||||
try{
|
||||
FindPossibleTransformationPrograms request= new FindPossibleTransformationPrograms();
|
||||
TPIOType tpin= TPIOType.fromParams("collection", resultsMDFParsed[0][3],resultsMDFParsed[0][1]+"="+resultsMDFParsed[0][2] , "");
|
||||
request.setInputFormat(tpin.toXMLString());
|
||||
request.setOutputFormat(null);
|
||||
FindPossibleTransformationProgramsResponse response=metadataBroker.findPossibleTransformationPrograms(request);
|
||||
String[] tp=response.getTransformationProgram();
|
||||
String[] parsedTP;
|
||||
logger.debug("VDLModel Derivable : "+tp.length);
|
||||
for(String singleTP: tp){
|
||||
try{
|
||||
logger.debug("MDF Derivable : Single tp is parsing ");
|
||||
parsedTP=ParseTP(singleTP);
|
||||
if (parsedTP!=null){
|
||||
String temp;
|
||||
//temp will contains the MDF id if it exists
|
||||
if((temp=ContainsControl(parsedTP, MDFormatArray))==null){
|
||||
logger.debug("MDF Derivable : not exist ");
|
||||
// if it doesn't exists, insert it into database else
|
||||
//add it only on DerivableMDF with MDFuid
|
||||
uuid=uuidMFGEN.nextUUID();
|
||||
parsedTP[0]=uuid;
|
||||
MDFormatArray.add(parsedTP);
|
||||
MDDerivableArray.add(new String[]{singleColl[0], uuid, "nothing"});
|
||||
}else{
|
||||
MDDerivableArray.add(new String[]{singleColl[0], temp , "nothing"});
|
||||
logger.debug("MDF Derivable : exist ");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}catch(Exception e) {logger.error("error in Derivable MDF parsing "+e.getMessage()); e.printStackTrace();}
|
||||
}
|
||||
}catch (Exception e1){logger.error("error retreiving metadataBroker "+e1.getMessage());
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
//trying to parse TransformationProgram from DIS-IC
|
||||
existID=null;
|
||||
String queryDerivableMDF="";
|
||||
try{
|
||||
queryDerivableMDF="for $tp in collection(\"/db/Profiles/TransformationProgram\")//Document/Data/child::*[local-name()='Profile']/DILIGENTResource where $tp/Profile/TransformationProgram/Input/Type/string() eq 'collection' and $tp/Profile/TransformationProgram/Input/Schema/string() eq '"+resultsMDFParsed[0][1]+"="+resultsMDFParsed[0][2]+"' and $tp/Profile/TransformationProgram/Output/Type/string() eq 'collection' return " +
|
||||
"<r><id>{$tp/UniqueID/string()}</id><SchemaName>{$tp/Profile/TransformationProgram/Output/Schema/string()}</SchemaName><lng>anylanguage</lng></r>";
|
||||
results=makeQueryDIS(epr, cred, queryDerivableMDF);
|
||||
String[][] resultsDerivableMDFParsed= parseResults(results, "r");
|
||||
for (String[] singleMDFDerived: resultsDerivableMDFParsed){
|
||||
try{
|
||||
String tpID=singleMDFDerived[0];
|
||||
uuid=uuidMFGEN.nextUUID();
|
||||
singleMDFDerived[0]=uuid;
|
||||
String[] parsedTP=ParseTP(singleMDFDerived);
|
||||
if((existID=ContainsControl(parsedTP, MDFormatArray))==null)
|
||||
{
|
||||
MDFormatArray.add(parsedTP);
|
||||
existID=uuid;
|
||||
}
|
||||
|
||||
singleDerivableMDF=new String[4];
|
||||
singleDerivableMDF[0]=singleColl[0];
|
||||
singleDerivableMDF[1]=existID;
|
||||
singleDerivableMDF[2]=tpID;
|
||||
singleDerivableMDF[3]=singleColl[3];
|
||||
MDDerivableArray.add(singleDerivableMDF);
|
||||
}catch(Exception e1){//logger.error("VDLModel: error parsing derivable");
|
||||
e1.printStackTrace();}
|
||||
|
||||
}
|
||||
}catch(Exception e){//logger.error("VDLModel: error retriving Derivable MDF for collection "+singleColl[0]);
|
||||
e.printStackTrace();}
|
||||
|
||||
}
|
||||
|
||||
//da cambiare (scandaloso)
|
||||
ArrayList<String[]> tempRemove= new ArrayList<String[]>();
|
||||
for(String[] tempDeriv:MDDerivableArray ){
|
||||
for (String[] tempNative: MDNativeArray){
|
||||
if (tempDeriv[3].compareTo(tempNative[2])==0 && (tempDeriv[1].compareTo(tempNative[1])==0)){
|
||||
tempRemove.add(tempDeriv);
|
||||
//logger.debug("removed Doubled value");
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String[] toRemove:tempRemove ) MDDerivableArray.remove(toRemove);
|
||||
|
||||
try{
|
||||
DBInterface.connect();
|
||||
DBInterface.InsertInto("mdcollection", resultsParsed, false);
|
||||
DBInterface.InsertInto("mdformat", MDFormatArray.toArray(new String[0][0]), false);
|
||||
DBInterface.InsertInto("nativemdf", MDNativeArray.toArray(new String[0][0]), true);
|
||||
DBInterface.InsertInto("derivablemdf",MDDerivableArray.toArray(new String[0][0]), true);
|
||||
}catch (SQLException e){//logger.error("error DB");
|
||||
e.printStackTrace(); throw new RemoteException(e.getMessage(),e); }
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
@ -303,7 +303,7 @@ public class ModelerService {
|
|||
}
|
||||
|
||||
|
||||
return XMLUtil.PrepareMCFormatXML(null, null, null, selectedMetadataStructure);
|
||||
return XMLUtil.PrepareMCFormatXML(totalMF, resNative, resDerivable, selectedMetadataStructure);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue