Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

Commit

Permalink
Fix: Build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
James Maina committed Oct 25, 2016
1 parent 78cc42d commit ad54d13
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand All @@ -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)
Expand Down Expand Up @@ -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;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.List;
import java.util.Map;

import org.joda.time.DateTime;
import org.json.JSONException;
import org.json.JSONObject;
import org.opensrp.common.AllConstants;
Expand Down Expand Up @@ -139,7 +140,7 @@ public FormSubmission convert(FormSubmissionDTO submission) {
}
catch(Exception e){
e.printStackTrace();
ErrorTrace errorTrace=new ErrorTrace(new Date(), "Parse Exception", "", e.getStackTrace().toString(), "Unsolved", formSubmission.formName());
ErrorTrace errorTrace=new ErrorTrace(new DateTime(), "Parse Exception", "", e.getStackTrace().toString(), "Unsolved", formSubmission.formName());
errorTrace.setRecordId(formSubmission.instanceId());
errorTraceService.addError(errorTrace);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
scheduler.startJob(formSchedule);
//scheduler.startJob(anmReportScheduler);
//scheduler.startJob(mctsReportScheduler);
scheduler.startJob(openmrsScheduleSyncerScheduler);
// scheduler.startJob(openmrsScheduleSyncerScheduler);
scheduler.startJob(atomfeedSchedule);
scheduler.startJob(encounterSchedule);

Expand Down

0 comments on commit ad54d13

Please sign in to comment.