use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.
the class PopulateDB method populateDummyData.
public static void populateDummyData(Context context) throws IOException {
//Reset inner references
cleanDummyLists();
for (String table : tables2populateDummy) {
Log.i(TAG, "Loading csv: " + table);
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(table)), SEPARATOR, QUOTECHAR);
String[] line;
while ((line = reader.readNext()) != null) {
switch(table) {
case ORG_UNIT_LEVEL_CSV:
OrgUnitLevel orgUnitLevel = new OrgUnitLevel();
orgUnitLevel.setName(line[1]);
orgUnitLevel.save();
orgUnitLevelList.put(Integer.valueOf(line[0]), orgUnitLevel);
break;
case ORG_UNIT_CSV:
OrgUnit orgUnit = new OrgUnit();
orgUnit.setUid(line[1]);
orgUnit.setName(line[2]);
orgUnit.setOrgUnit(Long.valueOf(line[3]));
orgUnit.setOrgUnitLevel(orgUnitLevelList.get(Integer.valueOf(line[4])));
orgUnit.save();
orgUnitList.put(Integer.valueOf(line[0]), orgUnit);
break;
}
}
reader.close();
}
//Free references since the maps are static
cleanDummyLists();
}
use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.
the class PopulateDB method addOptionAttributes.
public static void addOptionAttributes(Context context) throws IOException {
FileCsvs fileCsvs = new FileCsvs();
fileCsvs.saveCsvFromAssetsToFile(PopulateDB.OPTION_ATTRIBUTES_CSV);
fileCsvs.saveCsvFromAssetsToFile(PopulateDB.OPTIONS_CSV);
List<Option> options = Option.getAllOptions();
//Reset inner references
cleanInnerLists();
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(OPTION_ATTRIBUTES_CSV)), SEPARATOR, QUOTECHAR);
CSVReader readerOptions = new CSVReader(new InputStreamReader(context.openFileInput(OPTIONS_CSV)), SEPARATOR, QUOTECHAR);
//Remove bad optionAttributes.
Delete.tables(OptionAttribute.class);
String[] line;
//save new optionattributes
while ((line = reader.readNext()) != null) {
OptionAttribute optionAttribute = new OptionAttribute();
optionAttribute.setBackground_colour(line[1]);
optionAttribute.setPath(line[2]);
if (line.length > 3 && !line[3].equals("")) {
optionAttribute.setHorizontal_alignment(Integer.valueOf(line[3]));
} else {
optionAttribute.setHorizontal_alignment(OptionAttribute.DEFAULT_HORIZONTAL_ALIGNMENT);
}
if (line.length > 4 && !line[4].equals("")) {
optionAttribute.setVertical_alignment(Integer.valueOf(line[4]));
} else {
optionAttribute.setVertical_alignment(OptionAttribute.DEFAULT_VERTICAL_ALIGNMENT);
}
if (line.length > 5 && !line[5].equals("")) {
optionAttribute.setText_size(Integer.valueOf(line[5]));
} else {
optionAttribute.setText_size(Integer.parseInt(PreferencesState.getInstance().getContext().getResources().getString(R.string.default_option_text_size)));
}
if (line.length > 6 && !line[6].equals("")) {
optionAttribute.setDefaultOption(Integer.valueOf(line[6]));
} else {
optionAttribute.setDefaultOption(0);
}
optionAttribute.save();
optionAttributeList.put(Integer.valueOf(line[0]), optionAttribute);
}
line = null;
//Save new optionattributes for each question
while ((line = readerOptions.readNext()) != null) {
for (Option option : options) {
if (String.valueOf(option.getId_option()).equals(line[0])) {
if (!line[5].equals("")) {
option.setOptionAttribute(optionAttributeList.get(Integer.valueOf(line[5])));
option.save();
}
break;
}
}
}
reader.close();
}
use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.
the class PopulateDB method updateQuestions.
public static void updateQuestions(Context context) throws IOException {
List<Question> questions = Question.getAllQuestions();
//Reset inner references
cleanInnerLists();
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(QUESTIONS_CSV)), SEPARATOR, QUOTECHAR);
String[] line;
//Save new option name for each option
while ((line = reader.readNext()) != null) {
for (Question question : questions) {
if (String.valueOf(question.getId_question()).equals((line[0]))) {
question.setCode(line[1]);
question.setDe_name(line[2]);
question.setHelp_text(line[3]);
question.setForm_name(line[4]);
//Update necessary from migration22 in myanmar
question.setOutput(Integer.valueOf(line[12]));
//Update necessary from migration3
question.setTotalQuestions(Integer.valueOf(line[13]));
//Update necessary from migration4
question.setVisible(Integer.valueOf(line[14]));
//Update necessary from migration7
if (line.length > 15 && !line[15].equals("")) {
question.setPath(line[15]);
}
if (line.length > 16 && !line[16].equals("")) {
question.setCompulsory(Integer.valueOf(line[16]));
} else {
question.setCompulsory(Question.QUESTION_NOT_COMPULSORY);
}
question.save();
break;
}
}
}
reader.close();
}
use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.
the class UpdateDB method updateDrugCombination.
/**
* Method to Update drugCombination from csvs.
*
* @param context Needed to open the csvs.
* @throws IOException If there is a problem opening the csv.
*/
public static void updateDrugCombination(Context context, boolean updateCSV) throws IOException {
if (updateCSV) {
FileCsvs fileCsvs = new FileCsvs();
fileCsvs.saveCsvFromAssetsToFile(PopulateDB.DRUG_COMBINATIONS_CSV);
}
List<DrugCombination> drugCombinations = DrugCombination.getAllDrugCombination();
HashMap<Long, Drug> drugIds = RelationsIdCsvDB.getDrugIdRelationCsvDB(context);
HashMap<Long, Treatment> treatmentIds = RelationsIdCsvDB.getTreatmentIdRelationCsvDB(context);
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.DRUG_COMBINATIONS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] line;
int i = 0;
while ((line = reader.readNext()) != null) {
if (i < drugCombinations.size()) {
PopulateRow.populateDrugCombinations(line, drugIds, treatmentIds, drugCombinations.get(i)).save();
} else {
PopulateRow.populateDrugCombinations(line, drugIds, treatmentIds, null).insert();
}
}
}
use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.
the class UpdateDB method updateTabs.
/**
* Method to update the old tabs and add new ones from the csv. Use before insert all programs.
*
* @param context Needed to open the csv with the tabs.
* @throws IOException If there is a problem opening the csv.
*/
public static void updateTabs(Context context) throws IOException {
FileCsvs fileCsvs = new FileCsvs();
fileCsvs.saveCsvFromAssetsToFile(PopulateDB.TABS_CSV);
List<Tab> tabs = Tab.getAllTabs();
HashMap<Long, Program> programIds = RelationsIdCsvDB.getProgramIdRelationCsvDB(context);
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.TABS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] line;
int i = 0;
while ((line = reader.readNext()) != null) {
if (i < tabs.size()) {
PopulateRow.populateTab(line, programIds, tabs.get(i)).save();
} else {
PopulateRow.populateTab(line, programIds, null).insert();
}
i++;
}
}
Aggregations