1 | package org.medias.eccad.metier.extracteur; |
---|
2 | |
---|
3 | |
---|
4 | import org.apache.xmlrpc.client.XmlRpcClient; |
---|
5 | import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; |
---|
6 | import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory; |
---|
7 | import org.apache.xmlrpc.XmlRpcException; |
---|
8 | import org.medias.eccad.helpers.LoggerPerso; |
---|
9 | import org.medias.eccad.helpers.SpringBeanFactory; |
---|
10 | |
---|
11 | import java.io.IOException; |
---|
12 | import java.net.URL; |
---|
13 | |
---|
14 | |
---|
15 | public class Extract { |
---|
16 | |
---|
17 | private String result = null; |
---|
18 | public String getResult() { |
---|
19 | return result; |
---|
20 | } |
---|
21 | public void setResult(String result) { |
---|
22 | this.result = result; |
---|
23 | } |
---|
24 | |
---|
25 | private String getRequete(CritereExtractBean ef) { |
---|
26 | ExtracteurConfig configuration = (ExtracteurConfig) SpringBeanFactory.getXmlFactory().getBean("extracteur"); |
---|
27 | String xmlSchema = configuration.getSchema(); |
---|
28 | String requete ="<?xml version=\"1.0\"?>" ; |
---|
29 | requete +="<requete xmlns=\"http://www.mediasfrance.org\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\""+xmlSchema+"\">"; |
---|
30 | requete +="<idproduit>" + ef.getProduit() + "</idproduit>"; |
---|
31 | requete +="<idparametre>" + ef.getParametre() + "</idparametre>"; |
---|
32 | requete +="<dateDebut>" + ef.getDateDebut() + "</dateDebut>"; |
---|
33 | requete +="<dateFin>" + ef.getDateFin() + "</dateFin>"; |
---|
34 | requete +="<latMin>" + ef.getLatMin() + "</latMin>"; |
---|
35 | requete +="<latMax>" + ef.getLatMax() + "</latMax>"; |
---|
36 | requete +="<lonMin>" + ef.getLonMin() + "</lonMin>"; |
---|
37 | requete +="<lonMax>" + ef.getLonMax() + "</lonMax>"; |
---|
38 | requete +="<datafileformat>"+ef.getDataFileFormat()+"</datafileformat>"; |
---|
39 | requete +="<datafilecompress>"+ef.getDataFileCompress()+"</datafilecompress>"; |
---|
40 | requete +="<absent>" + ef.getAbsent() + "</absent>"; |
---|
41 | requete +="<separator>" + ef.getSeparator() + "</separator>"; |
---|
42 | requete +="<user>"; |
---|
43 | requete +="<nom>nom</nom>"; |
---|
44 | requete +="<prenom>prenom</prenom>"; |
---|
45 | requete +="<mail>"+ef.getMailUser()+"</mail>"; |
---|
46 | requete +="</user>"; |
---|
47 | requete +="</requete>"; |
---|
48 | return requete; |
---|
49 | } |
---|
50 | |
---|
51 | public void lanceExtract(String requete, String mode) throws IOException, XmlRpcException { |
---|
52 | XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); |
---|
53 | |
---|
54 | |
---|
55 | ExtracteurConfig configuration = (ExtracteurConfig) SpringBeanFactory.getXmlFactory().getBean("extracteur"); |
---|
56 | String urlCgi = configuration.getUrl(); |
---|
57 | |
---|
58 | |
---|
59 | //URL url = new URL("http://zeus/cgi-bin/eccad_extract.cgi"); |
---|
60 | URL url = new URL(urlCgi); |
---|
61 | config.setServerURL(url); |
---|
62 | //String xmlSchema = "./Schema_ECCAD1.xsd"; |
---|
63 | XmlRpcClient client = new XmlRpcClient(); |
---|
64 | client.setTransportFactory(new XmlRpcCommonsTransportFactory(client)); |
---|
65 | client.setConfig(config); |
---|
66 | |
---|
67 | Object[] params = new Object[]{requete,mode}; |
---|
68 | LoggerPerso.log(Extract.class, LoggerPerso.DEBUG, "extraction :: " + requete); |
---|
69 | String rslt = (String) client.execute("extract", params); |
---|
70 | LoggerPerso.log(Extract.class, LoggerPerso.DEBUG, "extraction result :: " + result); |
---|
71 | setResult(rslt); |
---|
72 | } |
---|
73 | |
---|
74 | public void lanceExtract(String requete) throws IOException, XmlRpcException { |
---|
75 | lanceExtract(requete, "extract"); |
---|
76 | } |
---|
77 | |
---|
78 | public void lanceExtract(CritereExtractBean ef) throws IOException, XmlRpcException { |
---|
79 | lanceExtract(getRequete(ef)); |
---|
80 | } |
---|
81 | |
---|
82 | public void lanceExtract(String emission, CritereExtractBean ef) throws IOException, XmlRpcException { |
---|
83 | emission = emission.replace("</requete>", ""); |
---|
84 | emission +="<datafileformat>"+ef.getDataFileFormat()+"</datafileformat>"; |
---|
85 | emission +="<datafilecompress>"+ef.getDataFileCompress()+"</datafilecompress>"; |
---|
86 | emission +="<absent>" + ef.getAbsent() + "</absent>"; |
---|
87 | emission +="<separator>" + ef.getSeparator() + "</separator>"; |
---|
88 | emission +="<userextract>"; |
---|
89 | emission +="<nomuser>nom</nomuser>"; |
---|
90 | emission +="<prenom>prenom</prenom>"; |
---|
91 | emission +="<mail>"+ef.getMailUser()+"</mail>"; |
---|
92 | emission +="</userextract>"; |
---|
93 | emission += "</requete>"; |
---|
94 | lanceExtract(emission, "extract"); |
---|
95 | } |
---|
96 | } |
---|