This repository has been archived by the owner on Jan 21, 2021. It is now read-only.
forked from SEL-Columbia/dristhi
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
James Maina
committed
Oct 25, 2016
1 parent
78cc42d
commit ad54d13
Showing
3 changed files
with
54 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,24 +2,16 @@ | |
|
||
|
||
|
||
import httpdowload.JustForFun; | ||
|
||
import java.io.IOException; | ||
import java.io.StringReader; | ||
import java.io.StringWriter; | ||
import java.io.Writer; | ||
import java.util.Arrays; | ||
import java.util.Date; | ||
|
||
import javax.xml.parsers.DocumentBuilder; | ||
import javax.xml.parsers.DocumentBuilderFactory; | ||
import javax.xml.parsers.ParserConfigurationException; | ||
|
||
import org.apache.commons.lang3.ArrayUtils; | ||
import org.codehaus.jackson.JsonProcessingException; | ||
import org.joda.time.DateTime; | ||
import org.joda.time.Hours; | ||
import org.joda.time.Years; | ||
import org.opensrp.util.FileCreator; | ||
import org.opensrp.util.JsonParser; | ||
import org.opensrp.util.NetClientGet; | ||
|
@@ -33,39 +25,40 @@ | |
|
||
import com.sun.org.apache.xml.internal.serialize.OutputFormat; | ||
import com.sun.org.apache.xml.internal.serialize.XMLSerializer; | ||
import com.sun.xml.internal.txw2.Document; | ||
|
||
//import httpdowload.JustForFun; | ||
|
||
/** | ||
* @author [email protected] | ||
* Created on 17-September, 2015 | ||
*/ | ||
@Service | ||
public class XlsFormDownloaderService { | ||
private NetClientGet netClientGet; | ||
private FileCreator fileCreator; | ||
private JsonParser jsonParser; | ||
|
||
private byte[] formJson=null; | ||
public XlsFormDownloaderService() { | ||
netClientGet=new NetClientGet(); | ||
fileCreator=new FileCreator(); | ||
|
||
jsonParser=new JsonParser(); | ||
} | ||
// private NetClientGet netClientGet; | ||
// private FileCreator fileCreator; | ||
// private JsonParser jsonParser; | ||
// | ||
// private byte[] formJson=null; | ||
// public XlsFormDownloaderService() { | ||
// netClientGet=new NetClientGet(); | ||
// fileCreator=new FileCreator(); | ||
// | ||
// jsonParser=new JsonParser(); | ||
// } | ||
|
||
public static void main(String[] args) { | ||
try { | ||
new XlsFormDownloaderService().downloadFormFiles("D:\\opensrpVaccinatorWkspc\\forms", | ||
"maimoonak", "opensrp", JustForFun.Form, "child_vaccination_enrollment", "135187"); | ||
//------------------------- | ||
new XlsFormDownloaderService().downloadFormFiles("D:\\opensrpVaccinatorWkspc\\forms", | ||
"maimoonak", "opensrp", JustForFun.Form, "child_vaccination_followup", "135199"); | ||
//--------------------------- | ||
new XlsFormDownloaderService().downloadFormFiles("D:\\opensrpVaccinatorWkspc\\forms", | ||
"maimoonak", "opensrp", JustForFun.Form, "woman_tt_enrollement_form", "135200"); | ||
//---------------------------- | ||
new XlsFormDownloaderService().downloadFormFiles("D:\\opensrpVaccinatorWkspc\\forms", | ||
"maimoonak", "opensrp", JustForFun.Form, "woman_tt_followup_form", "135203"); | ||
// try { | ||
// new XlsFormDownloaderService().downloadFormFiles("D:\\opensrpVaccinatorWkspc\\forms", | ||
// "maimoonak", "opensrp", JustForFun.Form, "child_vaccination_enrollment", "135187"); | ||
// //------------------------- | ||
// new XlsFormDownloaderService().downloadFormFiles("D:\\opensrpVaccinatorWkspc\\forms", | ||
// "maimoonak", "opensrp", JustForFun.Form, "child_vaccination_followup", "135199"); | ||
// //--------------------------- | ||
// new XlsFormDownloaderService().downloadFormFiles("D:\\opensrpVaccinatorWkspc\\forms", | ||
// "maimoonak", "opensrp", JustForFun.Form, "woman_tt_enrollement_form", "135200"); | ||
// //---------------------------- | ||
// new XlsFormDownloaderService().downloadFormFiles("D:\\opensrpVaccinatorWkspc\\forms", | ||
// "maimoonak", "opensrp", JustForFun.Form, "woman_tt_followup_form", "135203"); | ||
|
||
/*new XlsFormDownloaderService().downloadFormFiles("D:\\opensrpVaccinatorWkspc\\forms", | ||
"maimoonak", "opensrp", JustForFun.Form, "vaccine_stock_position", "115142"); | ||
|
@@ -77,9 +70,9 @@ public static void main(String[] args) { | |
new XlsFormDownloaderService().downloadFormFiles("D:\\opensrpVaccinatorWkspc\\forms", | ||
"maimoonak", "opensrp", JustForFun.Form, "offsite_woman_followup_form", "115135");*/ | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
// } catch (IOException e) { | ||
// e.printStackTrace(); | ||
// } | ||
} | ||
|
||
public String formatXML(String input) | ||
|
@@ -144,30 +137,32 @@ private org.w3c.dom.Document parseXmlFile(String in) { | |
|
||
public boolean downloadFormFiles(String directory,String username ,String formPath, String password,String formId, String formPk) throws IOException{ | ||
|
||
String xmlData=netClientGet.convertToString("", formPath, formId); | ||
String modelData=netClientGet.getModel(xmlData); | ||
String formData=fileCreator.prettyFormat(netClientGet.getForm(xmlData)); | ||
|
||
modelData=format(modelData); | ||
|
||
formData = formData.replaceAll("selected\\(", "contains("); | ||
formData = formData.replaceAll("<span.*lang=\"openmrs_code\".*</span>", ""); | ||
formData = formData.replaceAll("<option value=\"openmrs_code\">openmrs_code</option>", ""); | ||
|
||
formJson=netClientGet.downloadJson(username,password, formPk); | ||
|
||
//formData=fileCreator.prettyFormat(formData); | ||
System.out.println(getFormDefinition()); | ||
fileCreator.createFile("form_definition.json", fileCreator.osDirectorySet(directory)+formId, getFormDefinition().getBytes()); | ||
return fileCreator.createFormFiles(fileCreator.osDirectorySet(directory)+formId, formId, formData.getBytes(), modelData.getBytes(), formJson); | ||
// String xmlData=netClientGet.convertToString("", formPath, formId); | ||
// String modelData=netClientGet.getModel(xmlData); | ||
// String formData=fileCreator.prettyFormat(netClientGet.getForm(xmlData)); | ||
// | ||
// modelData=format(modelData); | ||
// | ||
// formData = formData.replaceAll("selected\\(", "contains("); | ||
// formData = formData.replaceAll("<span.*lang=\"openmrs_code\".*</span>", ""); | ||
// formData = formData.replaceAll("<option value=\"openmrs_code\">openmrs_code</option>", ""); | ||
// | ||
// formJson=netClientGet.downloadJson(username,password, formPk); | ||
// | ||
// //formData=fileCreator.prettyFormat(formData); | ||
// System.out.println(getFormDefinition()); | ||
// fileCreator.createFile("form_definition.json", fileCreator.osDirectorySet(directory)+formId, getFormDefinition().getBytes()); | ||
// return fileCreator.createFormFiles(fileCreator.osDirectorySet(directory)+formId, formId, formData.getBytes(), modelData.getBytes(), formJson); | ||
return false; | ||
} | ||
|
||
public String getFormDefinition() throws JsonProcessingException, IOException{ | ||
if(formJson==null){ | ||
return "Data not found on server . Please retry again !"; | ||
|
||
} | ||
return jsonParser.getFormDefinition(formJson); | ||
// if(formJson==null){ | ||
// return "Data not found on server . Please retry again !"; | ||
// | ||
// } | ||
// return jsonParser.getFormDefinition(formJson); | ||
return null; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters