use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.
the class TreatmentTable method getNotTreatmentLines.
private List<String[]> getNotTreatmentLines(String filename) throws IOException {
List<String[]> lines = new ArrayList<>();
CSVReader reader = new CSVReader(new InputStreamReader(mContext.openFileInput(filename)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] line;
while ((line = reader.readNext()) != null) {
lines.add(line);
}
return lines;
}
use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.
the class UpdateDB method updateTranslations.
public static void updateTranslations(Context context, boolean updateCsv) throws IOException {
if (updateCsv) {
FileCsvs fileCsvs = new FileCsvs();
fileCsvs.saveCsvFromAssetsToFile(PopulateDB.TRANSLATION_CSV);
}
List<Translation> translations = Translation.getAllTranslations();
HashMap<Long, StringKey> stringKeyFK = RelationsIdCsvDB.getStringKeyIdRelationCsvDB(context);
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.TRANSLATION_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] line;
int i = 0;
while ((line = reader.readNext()) != null) {
if (i < translations.size()) {
PopulateRow.populateTranslation(line, stringKeyFK, translations.get(i)).save();
} else {
PopulateRow.populateTranslation(line, stringKeyFK, null).insert();
}
i++;
}
}
use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.
the class UpdateDB method updateAnswers.
/**
* Method to update the old answers and add new ones.
*
* @param context Needed to open the csv with the answers.
* @throws IOException If there is a problem opening the csv.
*/
public static void updateAnswers(Context context) throws IOException {
FileCsvs fileCsvs = new FileCsvs();
fileCsvs.saveCsvFromAssetsToFile(PopulateDB.ANSWERS_CSV);
List<Answer> answers = Answer.getAllAnswers();
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.ANSWERS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] line;
//Save new answers
int i = 0;
while ((line = reader.readNext()) != null) {
if (i < answers.size()) {
PopulateRow.populateAnswer(line, answers.get(i)).save();
} else {
PopulateRow.populateAnswer(line, null).insert();
}
i++;
}
}
use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.
the class UpdateDB method updateTreatments.
/**
* Method to update treatments from csvs.
*
* @param context Needed to open the csvs.
* @throws IOException If there is a problem opening the csv.
*/
public static void updateTreatments(Context context, boolean updateCSV) throws IOException {
if (updateCSV) {
FileCsvs fileCsvs = new FileCsvs();
fileCsvs.saveCsvFromAssetsToFile(PopulateDB.TREATMENT_CSV);
}
List<Treatment> treatments = Treatment.getAllTreatments();
HashMap<Long, Organisation> organisationIds = RelationsIdCsvDB.getOrganisationIdRelationCsvDB(context);
HashMap<Long, StringKey> stringKeyIds = RelationsIdCsvDB.getStringKeyIdRelationCsvDB(context);
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.TREATMENT_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] line;
int i = 0;
while ((line = reader.readNext()) != null) {
if (i < treatments.size()) {
PopulateRow.populateTreatments(line, organisationIds, stringKeyIds, treatments.get(i)).save();
} else {
PopulateRow.populateTreatments(line, organisationIds, stringKeyIds, null).insert();
}
i++;
}
}
use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.
the class UpdateDB method insertLastLines.
public static void insertLastLines(int numeberLines, Context context) throws IOException {
HashMap<Long, Answer> answersIds = RelationsIdCsvDB.getAnswerFKRelationCsvDB(context);
HashMap<Long, OptionAttribute> optionAttributeIds = RelationsIdCsvDB.getOptionAttributeIdRelationCsvDB(context);
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.OPTIONS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
List<String[]> lines = reader.readAll();
for (int i = lines.size() - numeberLines - 1; i < lines.size(); i++) {
PopulateRow.populateOption(lines.get(i), answersIds, optionAttributeIds, null).insert();
}
}
Aggregations