git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vre-management/VREModeler@7769 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
9f15d6c7af
commit
8c9328e299
|
@ -1,12 +1,21 @@
|
|||
package org.gcube.vremanagement.vremodeler.db;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.net.URI;
|
||||
import java.rmi.RemoteException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.transform.OutputKeys;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
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;
|
||||
|
||||
|
@ -43,6 +52,8 @@ import org.gcube.vremanagement.vremodeler.impl.util.MBrokerServiceHandler;
|
|||
import org.gcube.vremanagement.vremodeler.impl.util.MFRelationDerivate;
|
||||
import org.gcube.vremanagement.vremodeler.impl.util.MFRelationNative;
|
||||
import org.gcube.vremanagement.vremodeler.impl.util.MetadataFormat;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.NEW;
|
||||
|
@ -247,7 +258,7 @@ public class IStoDBUtil {
|
|||
List<String> row;
|
||||
List<MetadataFormat> metadataFormatList= new ArrayList<MetadataFormat>();
|
||||
List<MFRelationNative> nativeMetadataFormatList= new ArrayList<MFRelationNative>();
|
||||
|
||||
List<MFRelationDerivate> derivateMetadataFormatList= new ArrayList<MFRelationDerivate>();
|
||||
for (GCUBEMCollection col: collectionList ){
|
||||
row= new ArrayList<String>(4);
|
||||
|
||||
|
@ -269,9 +280,9 @@ public class IStoDBUtil {
|
|||
|
||||
try {
|
||||
ServiceContext.getContext().setScope(scope);
|
||||
getMFDerivate(metadataFormatList, col);
|
||||
derivateMetadataFormatList.addAll(getMFDerivate(metadataFormatList, col));
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error in getMFDerivate");
|
||||
logger.error("Error in getMFDerivate"+e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
@ -284,6 +295,7 @@ public class IStoDBUtil {
|
|||
DBInterface.InsertInto("mdcollection", values);
|
||||
DBInterface.insertIntoListable("mdformat", metadataFormatList );
|
||||
DBInterface.insertIntoListable("nativemdf", nativeMetadataFormatList);
|
||||
DBInterface.insertIntoListable("derivablemdf", derivateMetadataFormatList );
|
||||
|
||||
|
||||
}
|
||||
|
@ -292,12 +304,14 @@ public class IStoDBUtil {
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static List<MFRelationDerivate> getMFDerivate(List<MetadataFormat> mdfList, GCUBEMCollection col ) throws Exception{
|
||||
|
||||
MBrokerServiceHandler<List<GCUBEGenericResource>, MetadataFormat> sHandler= new MBrokerServiceHandler<List<GCUBEGenericResource>,MetadataFormat >(){
|
||||
MBrokerServiceHandler<String[], MetadataFormat> sHandler= new MBrokerServiceHandler<String[],MetadataFormat >(){
|
||||
|
||||
@Override
|
||||
protected List<GCUBEGenericResource> makeCall(MetadataBrokerPortType mbportType) throws Exception {
|
||||
protected String[] makeCall(MetadataBrokerPortType mbportType) throws Exception {
|
||||
FindPossibleTransformationPrograms fptp= new FindPossibleTransformationPrograms();
|
||||
MetadataBrokerFormat mbInFormat= new MetadataBrokerFormat();
|
||||
mbInFormat.setType("collection");
|
||||
|
@ -308,44 +322,74 @@ public class IStoDBUtil {
|
|||
MetadataBrokerFormat mbOutFormat= new MetadataBrokerFormat();
|
||||
mbOutFormat.setType("collection");
|
||||
fptp.setOutputFormat(mbOutFormat);
|
||||
|
||||
List<GCUBEGenericResource> genericRes= new ArrayList<GCUBEGenericResource>();
|
||||
GCUBEGenericResource gen;
|
||||
if (mbportType==null) System.out.println("the MetadataBroker portType is null");
|
||||
|
||||
FindPossibleTransformationProgramsResponse tpRes= mbportType.findPossibleTransformationPrograms(fptp);
|
||||
if (tpRes==null){
|
||||
System.out.println("the result is null");
|
||||
return new ArrayList<GCUBEGenericResource>();
|
||||
}
|
||||
String[] tpArray = tpRes.getTransformationProgram();
|
||||
if (tpArray== null){
|
||||
System.out.println("the array is null");
|
||||
return new ArrayList<GCUBEGenericResource>();
|
||||
}
|
||||
|
||||
for (String res:tpArray){
|
||||
gen= GHNContext.getImplementation(GCUBEGenericResource.class);
|
||||
gen.load(new StringReader(res));
|
||||
genericRes.add(gen);
|
||||
}
|
||||
return genericRes;
|
||||
return tpRes.getTransformationProgram();
|
||||
}
|
||||
};
|
||||
|
||||
sHandler.setHandled(new GCUBEServiceClientImpl());
|
||||
sHandler.setParameter(mdfList.get(mdfList.size()-1));
|
||||
sHandler.run();
|
||||
List<GCUBEGenericResource> resList=sHandler.getReturnValue();
|
||||
String[] resList=sHandler.getReturnValue();
|
||||
|
||||
XPathFactory factory = XPathFactory.newInstance();
|
||||
XPath xpath= factory.newXPath();
|
||||
XPathExpression schemaExpr=xpath.compile("/TransformationProgram/Output[@Name='TPOutput']/Schema/text()");
|
||||
XPathExpression languageExpr=xpath.compile("/TransformationProgram/Output[@Name='TPOutput']/Language[@isVariable]/text()");
|
||||
for(GCUBEGenericResource res: resList){
|
||||
System.out.println(schemaExpr.evaluate(new InputSource(new StringReader(res.getBody()))));
|
||||
System.out.println(languageExpr.evaluate(new InputSource(new StringReader(res.getBody()))));
|
||||
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");
|
||||
|
||||
List<MFRelationDerivate> derivatedList= new ArrayList<MFRelationDerivate>();
|
||||
|
||||
NodeList set;
|
||||
StreamResult sr;
|
||||
String tpId;
|
||||
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();
|
||||
|
||||
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());
|
||||
|
||||
MFRelationDerivate mfRelTemp;
|
||||
if (mdfList.contains(mfTemp))
|
||||
mfRelTemp =new MFRelationDerivate(col.getID(), mdfList.get(mdfList.indexOf(mfTemp)).getId(), tpId );
|
||||
else {
|
||||
mfRelTemp =new MFRelationDerivate(col.getID(), mfTemp.getId(), tpId );
|
||||
mdfList.add(mfTemp);
|
||||
}
|
||||
return null;
|
||||
|
||||
derivatedList.add(mfRelTemp);
|
||||
|
||||
}
|
||||
}
|
||||
return derivatedList;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue