diff --git a/src/org/gcube/vremanagement/vremodeler/db/IStoDBUtil.java b/src/org/gcube/vremanagement/vremodeler/db/IStoDBUtil.java index 4556a02..faefcd0 100644 --- a/src/org/gcube/vremanagement/vremodeler/db/IStoDBUtil.java +++ b/src/org/gcube/vremanagement/vremodeler/db/IStoDBUtil.java @@ -16,16 +16,13 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathFactory; - 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; import org.gcube.common.core.informationsystem.client.ISClient; -import org.gcube.common.core.informationsystem.client.XMLResult; import org.gcube.common.core.informationsystem.client.queries.GCUBECSQuery; import org.gcube.common.core.informationsystem.client.queries.GCUBECollectionQuery; import org.gcube.common.core.informationsystem.client.queries.GCUBEGHNQuery; @@ -34,10 +31,8 @@ import org.gcube.common.core.informationsystem.client.queries.GCUBERIQuery; import org.gcube.common.core.informationsystem.client.queries.GCUBEServiceQuery; import org.gcube.common.core.resources.GCUBECS; import org.gcube.common.core.resources.GCUBECollection; -import org.gcube.common.core.resources.GCUBEGenericResource; import org.gcube.common.core.resources.GCUBEHostingNode; import org.gcube.common.core.resources.GCUBEMCollection; -import org.gcube.common.core.resources.GCUBEResource; import org.gcube.common.core.resources.GCUBERunningInstance; import org.gcube.common.core.resources.GCUBEService; import org.gcube.common.core.scope.GCUBEScope; @@ -56,8 +51,6 @@ import org.w3c.dom.Document; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; -import com.sun.org.apache.bcel.internal.generic.NEW; - /** * * @author lucio lelii CNR @@ -65,8 +58,6 @@ import com.sun.org.apache.bcel.internal.generic.NEW; */ public class IStoDBUtil { - //private static UUIDGen uuidMFGEN=UUIDGenFactory.getUUIDGen(); - private static GCUBELog logger = new GCUBELog(IStoDBUtil.class.getName()); private static UUIDGen uuidMFGEN= UUIDGenFactory.getUUIDGen(); @@ -115,82 +106,6 @@ public class IStoDBUtil { e.printStackTrace(); throw new GCUBEFault(e); } } - - - /* - private static String[] ParseTP(String[] tp){ - //logger.debug("ParseTP start"); - - String[] schemaNameURI=tp[1].split("="); - String lng="anylanguage"; - //logger.debug("MetadataFormatParsed: "+schemaNameURI[0]+ ", "+schemaNameURI[1]+", "+lng); - return new String[]{tp[0],schemaNameURI[0],schemaNameURI[1],lng}; - } - - - private static String ContainsControl(String[] item, ArrayList container){ - for(String[] cont: container){ - //logger.debug("MDFormat: "+cont[1]+" "+cont[2]); - //logger.debug("MDFormat: confr "+cont[1]+" "+cont[2]); - if((cont[1].compareTo(item[1])==0) && (cont[2].compareTo(item[2])==0)) //&& ((cont[3].compareTo("anylanguage")==0) || cont[3].compareTo(item[3])==0) - return cont[0]; - - } - //logger.debug("MDFormat: not yet present"); - return null; - } - */ - - - /* - private static String[][] parseResults(String results, String tag) throws RemoteException{ - - ArrayList returnedValues= new ArrayList(); - ArrayList tempArray; - - - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - - DocumentBuilder builder; - try { - builder = factory.newDocumentBuilder(); - - - StringReader reader = new StringReader(results); - InputSource source = new InputSource(reader); - Document domDoc; - domDoc = builder.parse(source); - Element child, subChild; - Element root= domDoc.getDocumentElement(); - NodeList childRoot= root.getElementsByTagName(tag); - if (childRoot.getLength()==0) return null; - for (int i=0; i(); - for (int k=0; k derivateMetadataFormatList= new ArrayList(); for (GCUBEMCollection col: collectionList ){ row= new ArrayList(4); - row.add(col.getID()); row.add(col.getName()); row.add(col.getDescription()); @@ -285,11 +199,7 @@ public class IStoDBUtil { logger.error("Error in getMFDerivate"+e); e.printStackTrace(); } - } - - - System.out.println(derivateMetadataFormatList.size()); //insert values in the database DBInterface.connect(); DBInterface.InsertInto("mdcollection", values); @@ -334,55 +244,42 @@ public class IStoDBUtil { List derivatedList= new ArrayList(); if (resList!=null && resList.length>0){ - System.out.println("resList is not null"); - XPath xpath= XPathFactory.newInstance().newXPath(); String schemaExpr="//TransformationProgram/Output[@name='TPOutput']/Schema/text()"; String languageExpr="//TransformationProgram/Output[@name='TPOutput']/Language[@isVariable='false']/text()"; String typeExpr="//TransformationProgram/Output[@name='TPOutput']/Type/text()"; String tpIdExpr="/Resource/ID/text()"; - Document doc; - - Transformer transformer = TransformerFactory.newInstance().newTransformer(); - transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); - - - - NodeList set; - StreamResult sr; - String tpId; + String tpId, transformationType,lng; + String[] schema; for(String res: resList){ doc= DocumentBuilderFactory.newInstance().newDocumentBuilder().parse( new InputSource(new StringReader(res))); - - set = (NodeList) xpath.evaluate(schemaExpr,doc, XPathConstants.NODESET); - sr = new StreamResult(new StringWriter()); - try {transformer.transform(new DOMSource(set.item(0)),sr);}catch(Exception ignore) {continue;} - if (sr.getWriter().toString().compareTo("collection")!=0){ - - set = (NodeList) xpath.evaluate(languageExpr,doc, XPathConstants.NODESET); - sr = new StreamResult(new StringWriter()); - try {transformer.transform(new DOMSource(set.item(0)),sr);}catch(Exception ignore) {continue;} - String[] schemas= sr.getWriter().toString().split("="); - - set = (NodeList) xpath.evaluate(tpIdExpr,doc, XPathConstants.NODESET); - sr = new StreamResult(new StringWriter()); - try {transformer.transform(new DOMSource(set.item(0)),sr);}catch(Exception ignore) {continue;} - tpId= sr.getWriter().toString(); - + //retrieving the TP type + transformationType=executeXpathOnDocument(typeExpr, doc).getWriter().toString(); + if (transformationType.compareTo("collection")==0){ + //retrieving the language + lng= executeXpathOnDocument(languageExpr, doc).getWriter().toString(); + //retrieving the Transformation program ID + tpId= executeXpathOnDocument(tpIdExpr, doc).getWriter().toString(); + //retrieving the schema + schema= executeXpathOnDocument(schemaExpr, doc).getWriter().toString().split("="); + + //creating the new MDFormat + boolean isLngAny= false; MetadataFormat mfTemp; - - set = (NodeList) xpath.evaluate(typeExpr,doc, XPathConstants.NODESET); - sr = new StreamResult(new StringWriter()); - try {transformer.transform(new DOMSource(set.item(0)),sr);}catch(Exception ignore) {continue;} - if (sr.getWriter().toString().compareTo("")==0) - mfTemp=new MetadataFormat(uuidMFGEN.nextUUID(), schemas[0], new URI(schemas[1]), "any"); - else - mfTemp=new MetadataFormat(uuidMFGEN.nextUUID(), schemas[0], new URI(schemas[1]), sr.getWriter().toString()); - + if (lng.compareTo("")==0){ + mfTemp=new MetadataFormat(uuidMFGEN.nextUUID(), schema[0], new URI(schema[1]), MetadataFormat.ANY_LANGUAGE); + isLngAny=true; + }else + mfTemp=new MetadataFormat(uuidMFGEN.nextUUID(), schema[0], new URI(schema[1]), lng); + + //if the MDFromat already exists use its id else it uses the new ID MFRelationDerivate mfRelTemp; - if (mdfList.contains(mfTemp)) - mfRelTemp =new MFRelationDerivate(col.getID(), mdfList.get(mdfList.indexOf(mfTemp)).getId(), tpId ); - else { + MetadataFormat existingMetadataFormat; + if (mdfList.contains(mfTemp)){ + existingMetadataFormat= mdfList.get(mdfList.indexOf(mfTemp)); + if (isLngAny) existingMetadataFormat.setLanguage(MetadataFormat.ANY_LANGUAGE); + mfRelTemp =new MFRelationDerivate(col.getID(), existingMetadataFormat.getId(), tpId ); + }else { mfRelTemp =new MFRelationDerivate(col.getID(), mfTemp.getId(), tpId ); mdfList.add(mfTemp); } @@ -391,7 +288,7 @@ public class IStoDBUtil { } } - }else System.out.println("resList is null"); + } return derivatedList; } @@ -557,180 +454,14 @@ public class IStoDBUtil { } - /* - public static void updateServices(EndpointReferenceType epr, ExtendedGSSCredential cred, String resourceID, int op) throws RemoteException { - switch (op){ - case 0: - { - String serviceUpdateQuery="for $SERVICE in collection(\"/db/Profiles/Service\")//Document/Data/child::*[local-name()='Profile']/DILIGENTResource where $SERVICE/UniqueID/string() eq '"+op+"' return {$SERVICE/UniqueID/string()}{$SERVICE/Profile/Name/string()}{$SERVICE/Profile/Class/string()}"; - String results=makeQueryDIS(epr, cred, serviceUpdateQuery); - String[][] resultsParsed= parseResults(results, "r"); - try{ - DBInterface.connect(); - DBInterface.InsertInto("relatedserviceid", resultsParsed, false); - }catch (SQLException e){//logger.error("error DB"); - e.printStackTrace(); throw new RemoteException(e.getMessage(),e); } - break; - } - case 1: - { - try{ - DBInterface.connect(); - DBInterface.ExecuteUpdate("Delete from relatedserviceid where id='"+resourceID+"'"); - }catch (SQLException e){//logger.error("error DB"); - e.printStackTrace(); throw new RemoteException(e.getMessage(),e); } - break; - } - } + private static StreamResult executeXpathOnDocument(String xpathString, Document doc) throws Exception{ + Transformer transformer = TransformerFactory.newInstance().newTransformer(); + transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); + XPath xpath= XPathFactory.newInstance().newXPath(); + NodeList set = (NodeList) xpath.evaluate(xpathString,doc, XPathConstants.NODESET); + StreamResult sr = new StreamResult(new StringWriter()); + try {transformer.transform(new DOMSource(set.item(0)),sr);}catch(Exception ignore) {} + return sr; } - - public static void updateCollection(EndpointReferenceType epr, ExtendedGSSCredential cred, String resourceID, int op) throws RemoteException { - switch (op){ - case 0: - { - String collectionQuery= "for $CollectionProfile in collection(\"/db/Profiles/Collection\")//Document/Data/child::*[local-name()='Profile']/DILIGENTResource where $CollectionProfile/Profile/IsUserCollection[string(@value) eq \"true\"] and $CollectionProfile/UniqueID/string() eq '"+resourceID+"' return {$CollectionProfile/UniqueID/string()}{$CollectionProfile/Profile/Name/string()}{$CollectionProfile/Profile/Description/string()}{$CollectionProfile/Profile/NumberOfMembers/string()}{$CollectionProfile/Profile/CreationTime/string()}{$CollectionProfile/Profile/LastUpdateTime/string()}"; - String results=makeQueryDIS(epr, cred, collectionQuery); - String[][] resultsParsed= parseResults(results, "r"); - - try{ - DBInterface.connect(); - DBInterface.InsertInto("collection", resultsParsed, false); - }catch (SQLException e){//logger.error("error updating collection on DB"); - e.printStackTrace(); throw new RemoteException(e.getMessage(),e); } - break; - } - case 1: - { - try{ - DBInterface.connect(); - DBInterface.ExecuteUpdate("Delete from collection where id='"+resourceID+"'"); - }catch (SQLException e){//logger.error("error updating collection on DB"); - e.printStackTrace(); throw new RemoteException(e.getMessage(),e); } - break; - } - } - } - - public static void updateDHN(EndpointReferenceType epr, ExtendedGSSCredential cred, String resourceID, int op) throws RemoteException { - switch (op){ - case 0: - { - String dhnQuery="for $DHN in collection(\"/db/Profiles/DHN\")//Document/Data/child::*[local-name()='Profile']/DILIGENTResource where ($DHN/Profile/DHNDescription/Type/string() eq 'Dynamic' or $DHN/Profile/DHNDescription/Type/string() eq 'SelfCleaning') and $DHN/UniqueID/string() eq '"+resourceID+"' return {$DHN/UniqueID/string()}{$DHN/Profile/DHNDescription/Name/string()}" + - "{$DHN/Profile/DHNDescription/SecurityEnabled/string(@value)}{$DHN/Profile/DHNDescription/Uptime/string()}{$DHN/Profile/DHNDescription/MainMemory/string(@VirtualAvailable)}{string($DHN/Profile/DHNDescription/MainMemory/string(@VirtualSize))}" + - "{$DHN/Profile/DHNDescription/LocalAvailableSpace/string()}{$DHN/Profile/Site/Location/string()}{$DHN/Profile/Site/Country/string()}{$DHN/Profile/Site/Domain/string()}"; - - String results=makeQueryDIS(epr, cred, dhnQuery); - String[][] resultsDHNParsed= parseResults(results, "r"); - ArrayList DNHRelatedRIArray= new ArrayList(); - - String RIQuery="for $RI in collection(\"/db/Profiles/RunningInstance\")//Document/Data/child::*[local-name()='Profile']/DILIGENTResource return {$RI/UniqueID/string()}{$RI/Profile/ServiceName/string()}"; - results=makeQueryDIS(epr, cred, RIQuery); - - String[][] resultsRIParsed= parseResults(results, "r"); - - String[] riID; - /* - try { - riID=DISHLSClient.getRunningInstanceManager(cred,epr).getAllRunningInstancesOnDHN(resourceID, cred, epr); - } catch (DISHLSClientException e) { - //logger.error("VDLModel: Error initializing DB with DHN and RI (DISHLSClient error)"); - throw new RemoteException("Error querying DIS-IP (DISHLSClient error)", e); - } catch (DISHLSCredentialException e) { - //logger.error("VDLModel: Error initializing DB with DHN and RI (Credential error)"); - throw new RemoteException("Error querying DIS-IP (Credential error)", e); - } - - - //retreiving related RIID with DHNID - String[] temp; - - for (String id: riID){ - temp=new String[2]; - temp[0]=resourceID; - temp[1]=id; - DNHRelatedRIArray.add(temp); - } - - try{ - DBInterface.connect(); - DBInterface.InsertInto("ghn", resultsDHNParsed, false); - DBInterface.InsertInto("runninginstance", resultsRIParsed, false); - DBInterface.InsertInto("ghnrelatedri", DNHRelatedRIArray.toArray(new String[0][0]), false); - }catch (SQLException e){//logger.error("error updating DHN on DB"); - e.printStackTrace(); throw new RemoteException(e.getMessage(),e); } - break; - } - case 1: - { - try{ - DBInterface.connect(); - DBInterface.ExecuteUpdate("Delete from dhn where id='"+resourceID+"'"); - DBInterface.ExecuteUpdate("Delete from dhnrelatedri where DHNID='"+resourceID+"'"); - }catch (SQLException e){//logger.error("error updating DHN on DB"); - e.printStackTrace(); throw new RemoteException(e.getMessage(),e); } - break; - } - } - } - - public static void updateCS(EndpointReferenceType epr, ExtendedGSSCredential cred, String resourceID, int op) throws RemoteException { - switch (op){ - case 0: - { - String csQuery= "for $CS in collection(\"/db/Profiles/CS\")//Document/Data/child::*[local-name()='Profile']/DILIGENTResource where $CS/UniqueID/string() eq '"+resourceID+"' return {$CS/UniqueID/string()}{$CS/Profile/ProcessName/string()}{$CS/Profile/Description/string()}"; - String results=makeQueryDIS(epr, cred, csQuery); - - String[][] resultsParsed= parseResults(results, "r"); - try{ - DBInterface.connect(); - DBInterface.InsertInto("cs", resultsParsed, false); - }catch (SQLException e){//logger.error("error updating CS on DB"); - e.printStackTrace(); throw new RemoteException(e.getMessage(),e); } - break; - } - case 1: - { - try{ - DBInterface.connect(); - DBInterface.ExecuteUpdate("Delete from cs where id='"+resourceID+"'"); - }catch (SQLException e){//logger.error("error updating CS on DB"); - e.printStackTrace(); throw new RemoteException(e.getMessage(),e); } - break; - } - } - } - - public static void updateRI(EndpointReferenceType epr, ExtendedGSSCredential cred, String resourceID, int op) throws RemoteException { - switch (op){ - case 0: - { - String RIQuery="for $RI in collection(\"/db/Profiles/RunningInstance\")//Document/Data/child::*[local-name()='Profile']/DILIGENTResource where $RI/UniqueID/string() eq '"+resourceID+"' return {$RI/UniqueID/string()}{$RI/Profile/ServiceName/string()}"; - String relatedDHNQuery="for $RI in collection(\"/db/Profiles/RunningInstance\")//Document/Data/child::*[local-name()='Profile']/DILIGENTResource where $RI/UniqueID/string() eq '"+resourceID+"' return {$RI/Profile/DHN/string(@UniqueID)}{$RI/UniqueID/string()}"; - String results=makeQueryDIS(epr, cred, RIQuery); - String resultsRelatedDhn=makeQueryDIS(epr, cred, relatedDHNQuery); - String[][] resultsRIParsed= parseResults(results, "r"); - String[][] resultRelatedDhn= parseResults(resultsRelatedDhn, "r"); - try{ - DBInterface.connect(); - DBInterface.InsertInto("runninginstance", resultsRIParsed, false); - DBInterface.InsertInto("dhnrelatedri", resultRelatedDhn, false); - }catch (SQLException e){//logger.error("error updating RI on DB"); - e.printStackTrace(); throw new RemoteException(e.getMessage(),e); } - break; - } - case 1: - { - try{ - DBInterface.connect(); - DBInterface.ExecuteUpdate("Delete from runninginstance where id='"+resourceID+"'"); - DBInterface.ExecuteUpdate("Delete from dhnrelatedri where RIID='"+resourceID+"'"); - }catch (SQLException e){//logger.error("error updating RI on DB"); - e.printStackTrace(); throw new RemoteException(e.getMessage(),e); } - break; - } - } - } - - */ } diff --git a/src/org/gcube/vremanagement/vremodeler/impl/ModelFactoryService.java b/src/org/gcube/vremanagement/vremodeler/impl/ModelFactoryService.java index 6adcb02..0942e1f 100644 --- a/src/org/gcube/vremanagement/vremodeler/impl/ModelFactoryService.java +++ b/src/org/gcube/vremanagement/vremodeler/impl/ModelFactoryService.java @@ -121,8 +121,7 @@ public class ModelFactoryService extends GCUBEStartupPortType{ try{ ResultSet res=DBInterface.queryDB("Select VRE.epr from VRE where VRE.id='"+request+"';"); EndpointReferenceType dlEpr; - - + if (res.next()){ StringReader stringReader = new StringReader(res.getString(1)); InputSource inputSource = new InputSource(stringReader); diff --git a/src/org/gcube/vremanagement/vremodeler/impl/util/MBrokerServiceHandler.java b/src/org/gcube/vremanagement/vremodeler/impl/util/MBrokerServiceHandler.java index 8cdfd7a..75ef36a 100644 --- a/src/org/gcube/vremanagement/vremodeler/impl/util/MBrokerServiceHandler.java +++ b/src/org/gcube/vremanagement/vremodeler/impl/util/MBrokerServiceHandler.java @@ -34,7 +34,7 @@ public abstract class MBrokerServiceHandler extends GCUBEServiceHandler getAsStringList(){ - return Arrays.asList(new String[]{super.getMetadataCollectionId(), super.getMetadataFormatId(), this.getMetadataFormatId()}); + return Arrays.asList(new String[]{super.getMetadataCollectionId(), super.getMetadataFormatId(), this.transformationProgramId}); } } diff --git a/src/org/gcube/vremanagement/vremodeler/impl/util/MetadataFormat.java b/src/org/gcube/vremanagement/vremodeler/impl/util/MetadataFormat.java index 4f3c1a7..0beb0eb 100644 --- a/src/org/gcube/vremanagement/vremodeler/impl/util/MetadataFormat.java +++ b/src/org/gcube/vremanagement/vremodeler/impl/util/MetadataFormat.java @@ -7,7 +7,7 @@ import org.gcube.common.core.utils.logging.GCUBELog; public class MetadataFormat implements Listable{ - + public final static String ANY_LANGUAGE="any"; private final static GCUBELog log= new GCUBELog(MetadataFormat.class.getName()); private String id; @@ -57,8 +57,10 @@ public class MetadataFormat implements Listable{ @Override public boolean equals(Object o){ MetadataFormat mf = (MetadataFormat)o; + boolean languageControl= mf.getLanguage().compareTo(ANY_LANGUAGE)==0 || this.getLanguage().compareTo(ANY_LANGUAGE)==0 || this.getLanguage().compareTo(mf.getLanguage())==0; + return ((this.name.compareTo(mf.getName())==0) && - (this.language.compareTo(mf.getLanguage())==0) && + (languageControl) && (this.schemaURI.compareTo(mf.getSchemaURI())==0)); }