22
33
44
5- import httpdowload .JustForFun ;
6-
75import java .io .IOException ;
86import java .io .StringReader ;
97import java .io .StringWriter ;
108import java .io .Writer ;
11- import java .util .Arrays ;
12- import java .util .Date ;
139
1410import javax .xml .parsers .DocumentBuilder ;
1511import javax .xml .parsers .DocumentBuilderFactory ;
1612import javax .xml .parsers .ParserConfigurationException ;
1713
18- import org .apache .commons .lang3 .ArrayUtils ;
1914import org .codehaus .jackson .JsonProcessingException ;
20- import org .joda .time .DateTime ;
21- import org .joda .time .Hours ;
22- import org .joda .time .Years ;
2315import org .opensrp .util .FileCreator ;
2416import org .opensrp .util .JsonParser ;
2517import org .opensrp .util .NetClientGet ;
3325
3426import com .sun .org .apache .xml .internal .serialize .OutputFormat ;
3527import com .sun .org .apache .xml .internal .serialize .XMLSerializer ;
36- import com .sun .xml .internal .txw2 .Document ;
28+
29+ //import httpdowload.JustForFun;
3730
3831/**
3932 * @author muhammad.ahmed@ihsinformatics.com
4033 * Created on 17-September, 2015
4134 */
4235@ Service
4336public class XlsFormDownloaderService {
44- private NetClientGet netClientGet ;
45- private FileCreator fileCreator ;
46- private JsonParser jsonParser ;
47-
48- private byte [] formJson =null ;
49- public XlsFormDownloaderService () {
50- netClientGet =new NetClientGet ();
51- fileCreator =new FileCreator ();
52-
53- jsonParser =new JsonParser ();
54- }
37+ // private NetClientGet netClientGet;
38+ // private FileCreator fileCreator;
39+ // private JsonParser jsonParser;
40+ //
41+ // private byte[] formJson=null;
42+ // public XlsFormDownloaderService() {
43+ // netClientGet=new NetClientGet();
44+ // fileCreator=new FileCreator();
45+ //
46+ // jsonParser=new JsonParser();
47+ // }
5548
5649 public static void main (String [] args ) {
57- try {
58- new XlsFormDownloaderService ().downloadFormFiles ("D:\\ opensrpVaccinatorWkspc\\ forms" ,
59- "maimoonak" , "opensrp" , JustForFun .Form , "child_vaccination_enrollment" , "135187" );
60- //-------------------------
61- new XlsFormDownloaderService ().downloadFormFiles ("D:\\ opensrpVaccinatorWkspc\\ forms" ,
62- "maimoonak" , "opensrp" , JustForFun .Form , "child_vaccination_followup" , "135199" );
63- //---------------------------
64- new XlsFormDownloaderService ().downloadFormFiles ("D:\\ opensrpVaccinatorWkspc\\ forms" ,
65- "maimoonak" , "opensrp" , JustForFun .Form , "woman_tt_enrollement_form" , "135200" );
66- //----------------------------
67- new XlsFormDownloaderService ().downloadFormFiles ("D:\\ opensrpVaccinatorWkspc\\ forms" ,
68- "maimoonak" , "opensrp" , JustForFun .Form , "woman_tt_followup_form" , "135203" );
50+ // try {
51+ // new XlsFormDownloaderService().downloadFormFiles("D:\\opensrpVaccinatorWkspc\\forms",
52+ // "maimoonak", "opensrp", JustForFun.Form, "child_vaccination_enrollment", "135187");
53+ // //-------------------------
54+ // new XlsFormDownloaderService().downloadFormFiles("D:\\opensrpVaccinatorWkspc\\forms",
55+ // "maimoonak", "opensrp", JustForFun.Form, "child_vaccination_followup", "135199");
56+ // //---------------------------
57+ // new XlsFormDownloaderService().downloadFormFiles("D:\\opensrpVaccinatorWkspc\\forms",
58+ // "maimoonak", "opensrp", JustForFun.Form, "woman_tt_enrollement_form", "135200");
59+ // //----------------------------
60+ // new XlsFormDownloaderService().downloadFormFiles("D:\\opensrpVaccinatorWkspc\\forms",
61+ // "maimoonak", "opensrp", JustForFun.Form, "woman_tt_followup_form", "135203");
6962
7063 /*new XlsFormDownloaderService().downloadFormFiles("D:\\opensrpVaccinatorWkspc\\forms",
7164 "maimoonak", "opensrp", JustForFun.Form, "vaccine_stock_position", "115142");
@@ -77,9 +70,9 @@ public static void main(String[] args) {
7770
7871 new XlsFormDownloaderService().downloadFormFiles("D:\\opensrpVaccinatorWkspc\\forms",
7972 "maimoonak", "opensrp", JustForFun.Form, "offsite_woman_followup_form", "115135");*/
80- } catch (IOException e ) {
81- e .printStackTrace ();
82- }
73+ // } catch (IOException e) {
74+ // e.printStackTrace();
75+ // }
8376 }
8477
8578 public String formatXML (String input )
@@ -144,30 +137,32 @@ private org.w3c.dom.Document parseXmlFile(String in) {
144137
145138 public boolean downloadFormFiles (String directory ,String username ,String formPath , String password ,String formId , String formPk ) throws IOException {
146139
147- String xmlData =netClientGet .convertToString ("" , formPath , formId );
148- String modelData =netClientGet .getModel (xmlData );
149- String formData =fileCreator .prettyFormat (netClientGet .getForm (xmlData ));
150-
151- modelData =format (modelData );
152-
153- formData = formData .replaceAll ("selected\\ (" , "contains(" );
154- formData = formData .replaceAll ("<span.*lang=\" openmrs_code\" .*</span>" , "" );
155- formData = formData .replaceAll ("<option value=\" openmrs_code\" >openmrs_code</option>" , "" );
156-
157- formJson =netClientGet .downloadJson (username ,password , formPk );
158-
159- //formData=fileCreator.prettyFormat(formData);
160- System .out .println (getFormDefinition ());
161- fileCreator .createFile ("form_definition.json" , fileCreator .osDirectorySet (directory )+formId , getFormDefinition ().getBytes ());
162- return fileCreator .createFormFiles (fileCreator .osDirectorySet (directory )+formId , formId , formData .getBytes (), modelData .getBytes (), formJson );
140+ // String xmlData=netClientGet.convertToString("", formPath, formId);
141+ // String modelData=netClientGet.getModel(xmlData);
142+ // String formData=fileCreator.prettyFormat(netClientGet.getForm(xmlData));
143+ //
144+ // modelData=format(modelData);
145+ //
146+ // formData = formData.replaceAll("selected\\(", "contains(");
147+ // formData = formData.replaceAll("<span.*lang=\"openmrs_code\".*</span>", "");
148+ // formData = formData.replaceAll("<option value=\"openmrs_code\">openmrs_code</option>", "");
149+ //
150+ // formJson=netClientGet.downloadJson(username,password, formPk);
151+ //
152+ // //formData=fileCreator.prettyFormat(formData);
153+ // System.out.println(getFormDefinition());
154+ // fileCreator.createFile("form_definition.json", fileCreator.osDirectorySet(directory)+formId, getFormDefinition().getBytes());
155+ // return fileCreator.createFormFiles(fileCreator.osDirectorySet(directory)+formId, formId, formData.getBytes(), modelData.getBytes(), formJson);
156+ return false ;
163157 }
164158
165159 public String getFormDefinition () throws JsonProcessingException , IOException {
166- if (formJson ==null ){
167- return "Data not found on server . Please retry again !" ;
168-
169- }
170- return jsonParser .getFormDefinition (formJson );
160+ // if(formJson==null){
161+ // return "Data not found on server . Please retry again !";
162+ //
163+ // }
164+ // return jsonParser.getFormDefinition(formJson);
165+ return null ;
171166
172167 }
173168}
0 commit comments